From c4a8658099ed0e92fabcdcd47331dc6a1cebb1f5 Mon Sep 17 00:00:00 2001 From: Andrii Zavorotnii Date: Mon, 23 Sep 2019 14:50:49 -0700 Subject: [PATCH 1/2] Fix Open() journal mode regression [why] see https://github.com/mattn/go-sqlite3/issues/607 SQLite default journal mode is DELETE, but forcing it on open causes "database is locked" if other connection exists with WAL mode, for example. [how] Don't set DELETE mode if not set in DSN explicitly. [testing] Run tests in my project where WAL mode is used. --- sqlite3.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/sqlite3.go b/sqlite3.go index 4000173..19f107a 100644 --- a/sqlite3.go +++ b/sqlite3.go @@ -1000,7 +1000,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) { deferForeignKeys := -1 foreignKeys := -1 ignoreCheckConstraints := -1 - journalMode := "DELETE" + var journalMode string lockingMode := "NORMAL" queryOnly := -1 recursiveTriggers := -1 @@ -1571,10 +1571,11 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) { } // Journal Mode - // Because default Journal Mode is DELETE this PRAGMA can always be executed. - if err := exec(fmt.Sprintf("PRAGMA journal_mode = %s;", journalMode)); err != nil { - C.sqlite3_close_v2(db) - return nil, err + if journalMode != "" { + if err := exec(fmt.Sprintf("PRAGMA journal_mode = %s;", journalMode)); err != nil { + C.sqlite3_close_v2(db) + return nil, err + } } // Locking Mode From 27d3ed467ce851ce42445bf05c495629a766914f Mon Sep 17 00:00:00 2001 From: Andrii Zavorotnii Date: Mon, 23 Sep 2019 14:57:24 -0700 Subject: [PATCH 2/2] Fix typo in "_locking_mode" DSN handling --- sqlite3.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlite3.go b/sqlite3.go index 19f107a..9eec636 100644 --- a/sqlite3.go +++ b/sqlite3.go @@ -1232,7 +1232,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) { if _, ok := params["_locking"]; ok { pkey = "_locking" } - if val := params.Get("_locking"); val != "" { + if val := params.Get(pkey); val != "" { switch strings.ToUpper(val) { case "NORMAL", "EXCLUSIVE": lockingMode = strings.ToUpper(val)