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.
This commit is contained in:
Andrii Zavorotnii 2019-09-23 14:50:49 -07:00
parent d3c690956b
commit c4a8658099
1 changed files with 6 additions and 5 deletions

View File

@ -1000,7 +1000,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
deferForeignKeys := -1 deferForeignKeys := -1
foreignKeys := -1 foreignKeys := -1
ignoreCheckConstraints := -1 ignoreCheckConstraints := -1
journalMode := "DELETE" var journalMode string
lockingMode := "NORMAL" lockingMode := "NORMAL"
queryOnly := -1 queryOnly := -1
recursiveTriggers := -1 recursiveTriggers := -1
@ -1571,11 +1571,12 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
} }
// Journal Mode // Journal Mode
// Because default Journal Mode is DELETE this PRAGMA can always be executed. if journalMode != "" {
if err := exec(fmt.Sprintf("PRAGMA journal_mode = %s;", journalMode)); err != nil { if err := exec(fmt.Sprintf("PRAGMA journal_mode = %s;", journalMode)); err != nil {
C.sqlite3_close_v2(db) C.sqlite3_close_v2(db)
return nil, err return nil, err
} }
}
// Locking Mode // Locking Mode
// Because the default is NORMAL and this is not changed in this package // Because the default is NORMAL and this is not changed in this package