fix retry logic around conn.step, updates #66

This commit is contained in:
Jan Mercl
2021-09-14 16:20:20 +02:00
parent e1d8d213c1
commit e3be4b029c
2 changed files with 74 additions and 4 deletions

View File

@@ -11,6 +11,7 @@ import (
"context"
"database/sql"
"database/sql/driver"
"errors"
"fmt"
"io"
"math"
@@ -872,12 +873,17 @@ func (c *conn) changes() (int, error) {
func (c *conn) step(pstmt uintptr) (int, error) {
for {
switch rc := sqlite3.Xsqlite3_step(c.tls, pstmt); rc {
case sqliteLockedSharedcache, sqlite3.SQLITE_BUSY:
case sqliteLockedSharedcache:
if err := c.retry(pstmt); err != nil {
return sqlite3.SQLITE_LOCKED, err
}
default:
case
sqlite3.SQLITE_DONE,
sqlite3.SQLITE_ROW:
return int(rc), nil
default:
return int(rc), errors.New(ErrorCodeString[int(rc)])
}
}
}
@@ -1135,7 +1141,7 @@ func (c *conn) prepareV2(zSQL *uintptr) (pstmt uintptr, err error) {
case sqlite3.SQLITE_OK:
*zSQL = *(*uintptr)(unsafe.Pointer(pptail))
return *(*uintptr)(unsafe.Pointer(ppstmt)), nil
case sqliteLockedSharedcache, sqlite3.SQLITE_BUSY:
case sqliteLockedSharedcache:
if err := c.retry(0); err != nil {
return 0, err
}