From f087cd79b247059a4d002baa6c3a1e3f574093e5 Mon Sep 17 00:00:00 2001 From: Gert-Jan Timmer Date: Tue, 29 May 2018 11:53:36 +0200 Subject: [PATCH] Update Busy Timeout PRAGMA ADD: multiple key --- README.md | 18 +++++++++--------- sqlite3.go | 11 ++++++++++- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 652d8e7..e890c0d 100644 --- a/README.md +++ b/README.md @@ -74,15 +74,15 @@ Boolean values can be one of: | Name | Key | Value(s) | Description | |------|-----|----------|-------------| -| Auto Vacuum | _vacuum | | For more information see [PRAGMA auto_vacuum](https://www.sqlite.org/pragma.html#pragma_auto_vacuum) | -| Busy Timeout | _busy_timeout | `int` | Specify value for sqlite3_busy_timeout. For more information see [PRAGMA busy_timeout](https://www.sqlite.org/pragma.html#pragma_busy_timeout) | -| Case Sensitive LIKE | _cslike | `boolean` | For more information see [PRAGMA case_sensitive_like](https://www.sqlite.org/pragma.html#pragma_case_sensitive_like) | -| Foreign Keys | _foreign_keys | `boolean` | For more information see [PRAGMA foreign_keys](https://www.sqlite.org/pragma.html#pragma_foreign_keys) | -| Mutex Locking | _mutex | | Specify mutex mode. | -| Recursive Triggers | _recursive_triggers | `boolean` | For more information see [PRAGMA recursive_triggers](https://www.sqlite.org/pragma.html#pragma_recursive_triggers) | -| Shared-Cache Mode | cache | | Set cache mode for more information see [sqlite.org](https://www.sqlite.org/sharedcache.html) | -| Time Zone Location | _loc | auto | Specify location of time format. | -| Transaction Lock | _txlock | | Specify locking behavior for transactions. | +| Auto Vacuum | `_vacuum` | | For more information see [PRAGMA auto_vacuum](https://www.sqlite.org/pragma.html#pragma_auto_vacuum) | +| Busy Timeout | `_busy_timeout` \| `_timeout` | `int` | Specify value for sqlite3_busy_timeout. For more information see [PRAGMA busy_timeout](https://www.sqlite.org/pragma.html#pragma_busy_timeout) | +| Case Sensitive LIKE | `_cslike` | `boolean` | For more information see [PRAGMA case_sensitive_like](https://www.sqlite.org/pragma.html#pragma_case_sensitive_like) | +| Foreign Keys | `_foreign_keys` | `boolean` | For more information see [PRAGMA foreign_keys](https://www.sqlite.org/pragma.html#pragma_foreign_keys) | +| Mutex Locking | `_mutex` | | Specify mutex mode. | +| Recursive Triggers | `_recursive_triggers` | `boolean` | For more information see [PRAGMA recursive_triggers](https://www.sqlite.org/pragma.html#pragma_recursive_triggers) | +| Shared-Cache Mode | `cache` | | Set cache mode for more information see [sqlite.org](https://www.sqlite.org/sharedcache.html) | +| Time Zone Location | `_loc` | auto | Specify location of time format. | +| Transaction Lock | `_txlock` | | Specify locking behavior for transactions. | ## DSN Examples diff --git a/sqlite3.go b/sqlite3.go index d64411d..aa45559 100644 --- a/sqlite3.go +++ b/sqlite3.go @@ -825,6 +825,8 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) { return nil, errors.New("sqlite library was not compiled for thread-safe operation") } + var pkey string + // Options var loc *time.Location mutex := C.int(C.SQLITE_OPEN_FULLMUTEX) @@ -903,7 +905,13 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) { // // https://www.sqlite.org/pragma.html#pragma_busy_timeout // - if val := params.Get("_busy_timeout"); val != "" { + if _, ok := params["_busy_timeout"]; ok { + pkey = "_busy_timeout" + } + if _, ok := params["_timeout"]; ok { + pkey = "_timeout" + } + if val := params.Get(pkey); val != "" { iv, err := strconv.ParseInt(val, 10, 64) if err != nil { return nil, fmt.Errorf("Invalid _busy_timeout: %v: %v", val, err) @@ -930,6 +938,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) { // // https://www.sqlite.org/pragma.html#pragma_foreign_keys // + if val := params.Get("_foreign_keys"); val != "" { switch strings.ToLower(val) { case "0", "no", "false", "off":