diff options
author | Gert-Jan Timmer <gjr.timmer@gmail.com> | 2018-05-29 13:55:31 +0200 |
---|---|---|
committer | Gert-Jan Timmer <gjr.timmer@gmail.com> | 2018-05-29 13:55:31 +0200 |
commit | cb041405c6e3989fea4ead50b90a4bc7e75d5ab5 (patch) | |
tree | aeda2e7ed8cf0d8152dd82b84138146458bd4bc8 /sqlite3.go | |
parent | Add: Copyright for additional Features (diff) | |
download | golite-cb041405c6e3989fea4ead50b90a4bc7e75d5ab5.tar.gz golite-cb041405c6e3989fea4ead50b90a4bc7e75d5ab5.tar.xz |
ADD: PRAGMA synchronous
Diffstat (limited to 'sqlite3.go')
-rw-r--r-- | sqlite3.go | 41 |
1 files changed, 40 insertions, 1 deletions
@@ -866,6 +866,10 @@ func errorString(err Error) string { // When secure_delete is on, SQLite overwrites deleted content with zeros. // https://www.sqlite.org/pragma.html#pragma_secure_delete // +// _synchronous=X | _sync=X +// Change the setting of the "synchronous" flag. +// https://www.sqlite.org/pragma.html#pragma_synchronous +// // _vacuum=X // 0 | none - Auto Vacuum disabled // 1 | full - Auto Vacuum FULL @@ -894,6 +898,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) { queryOnly := -1 recursiveTriggers := -1 secureDelete := "DEFAULT" + synchronousMode := "NORMAL" pos := strings.IndexRune(dsn, '?') if pos >= 1 { @@ -1057,8 +1062,14 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) { // if val := params.Get("_journal"); val != "" { switch strings.ToUpper(val) { - case "DELETE", "TRUNCATE", "PERSIST", "MEMORY", "WAL", "OFF": + case "DELETE", "TRUNCATE", "PERSIST", "MEMORY", "OFF": + journalMode = strings.ToUpper(val) + case "WAL": journalMode = strings.ToUpper(val) + + // For WAL Mode set Synchronous Mode to 'NORMAL' + // See https://www.sqlite.org/pragma.html#pragma_synchronous + synchronousMode = "NORMAL" default: return nil, fmt.Errorf("Invalid _journal: %v, expecting value of 'DELETE TRUNCATE PERSIST MEMORY WAL OFF'", val) } @@ -1131,6 +1142,26 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) { } } + // Synchronous Mode (_synchronous | _sync) + // + // https://www.sqlite.org/pragma.html#pragma_synchronous + // + pkey = "" // Reset pkey + if _, ok := params["_synchronous"]; ok { + pkey = "_synchronous" + } + if _, ok := params["_sync"]; ok { + pkey = "_sync" + } + if val := params.Get(pkey); val != "" { + switch strings.ToUpper(val) { + case "0", "OFF", "1", "NORMAL", "2", "FULL", "3", "EXTRA": + synchronousMode = strings.ToUpper(val) + default: + return nil, fmt.Errorf("Invalid _synchronous: %v, expecting value of '0 OFF 1 NORMAL 2 FULL 3 EXTRA'", val) + } + } + if !strings.HasPrefix(dsn, "file:") { dsn = dsn[:pos] } @@ -1248,6 +1279,14 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) { } } + // Synchronous Mode + // + // Because default is NORMAL this statement is always executed + if err := exec(fmt.Sprintf("PRAGMA synchronous = %s;", synchronousMode)); err != nil { + C.sqlite3_close_v2(db) + return nil, err + } + conn := &SQLiteConn{db: db, loc: loc, txlock: txlock} if len(d.Extensions) > 0 { |