diff options
author | Jeffrey Armstrong <jeff@approximatrix.com> | 2023-01-02 12:14:29 -0500 |
---|---|---|
committer | Jeffrey Armstrong <jeff@approximatrix.com> | 2023-01-02 12:14:29 -0500 |
commit | cf13b8b542cd6eb3c0cf73a2428a7a825dc6252e (patch) | |
tree | 0f7e79bfbdbcc004d642f34c1c751e146e34f148 /captain | |
parent | 462715e11037739722457e48084a73daa9e5d889 (diff) | |
download | levitating-cf13b8b542cd6eb3c0cf73a2428a7a825dc6252e.tar.gz levitating-cf13b8b542cd6eb3c0cf73a2428a7a825dc6252e.zip |
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.
Diffstat (limited to 'captain')
-rw-r--r-- | captain/sqlite.f90 | 23 |
1 files changed, 21 insertions, 2 deletions
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 |