From cf13b8b542cd6eb3c0cf73a2428a7a825dc6252e Mon Sep 17 00:00:00 2001 From: Jeffrey Armstrong Date: Mon, 2 Jan 2023 12:14:29 -0500 Subject: Calls to step_now, which are almost always inserts or updates, will now retry 20 times with sleep states if a busy result is reported by the db. --- captain/sqlite.f90 | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'captain') diff --git a/captain/sqlite.f90 b/captain/sqlite.f90 index f9bc5b4..8a7d672 100644 --- a/captain/sqlite.f90 +++ b/captain/sqlite.f90 @@ -152,6 +152,12 @@ implicit none integer(c_int)::sqlite3_column_type end function sqlite3_column_type + function sqlite3_sleep(ms) bind(c, name='sqlite3_sleep') + use iso_c_binding + integer(kind=c_int), value::ms + integer(kind=c_int)::sqlite3_sleep + end function sqlite3_sleep + end interface type :: sqlite3_stmt @@ -327,8 +333,21 @@ contains class(sqlite3_stmt), intent(inout)::self integer::ignored - - ignored = sqlite3_step(self%stmt) + integer::passes + + ignored = SQLITE_BUSY + passes = 0 + do while(ignored == SQLITE_BUSY .and. passes <= 20) + + passes = passes + 1 + + ! Sleep while busy... + if(passes > 1) then + ignored = sqlite3_sleep(100) + end if + + ignored = sqlite3_step(self%stmt) + end do end subroutine stmt_step_ignore -- cgit v1.2.3