Skip to content

Commit

Permalink
Fix Open() journal mode regression
Browse files Browse the repository at this point in the history
[why]
see mattn#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.
  • Loading branch information
azavorotnii committed Sep 23, 2019
1 parent d3c6909 commit c4a8658
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions sqlite3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c4a8658

Please sign in to comment.