aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Peterson <danp@danp.net>2021-10-25 12:08:40 -0300
committerGitHub <noreply@github.com>2021-10-26 00:08:40 +0900
commit3bb6941859daeb47b7003156db3de7c3224116f2 (patch)
treeb0643b50602194fb17cd35456d37708c227a5fbd
parentTest on 1.17 (diff)
downloadgolite-3bb6941859daeb47b7003156db3de7c3224116f2.tar.gz
golite-3bb6941859daeb47b7003156db3de7c3224116f2.tar.xz
sqlite3.go: use PRAGMA to set busy_timeout (#910)
The busy_timeout pragma was added in sqlite 3.7.15 as an alternative to calling sqlite3_busy_timeout directly: https://sqlite.org/pragma.html#pragma_busy_timeout While there's no functional change here, using the pragma does align setting busy_timeout with other settings and removes the special case for calling sqlite3_busy_timeout directly.
-rw-r--r--sqlite3.go12
1 files changed, 6 insertions, 6 deletions
diff --git a/sqlite3.go b/sqlite3.go
index 5982f8e..b2c524b 100644
--- a/sqlite3.go
+++ b/sqlite3.go
@@ -1415,12 +1415,6 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
return nil, errors.New("sqlite succeeded without returning a database")
}
- rv = C.sqlite3_busy_timeout(db, C.int(busyTimeout))
- if rv != C.SQLITE_OK {
- C.sqlite3_close_v2(db)
- return nil, Error{Code: ErrNo(rv)}
- }
-
exec := func(s string) error {
cs := C.CString(s)
rv := C.sqlite3_exec(db, cs, nil, nil, nil)
@@ -1431,6 +1425,12 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
return nil
}
+ // Busy timeout
+ if err := exec(fmt.Sprintf("PRAGMA busy_timeout = %d;", busyTimeout)); err != nil {
+ C.sqlite3_close_v2(db)
+ return nil, err
+ }
+
// USER AUTHENTICATION
//
// User Authentication is always performed even when