From 764e391156b04640da0150bc4b1f11003b93d2a4 Mon Sep 17 00:00:00 2001 From: Gert-Jan Timmer Date: Tue, 29 May 2018 13:29:06 +0200 Subject: [PATCH] ADD: PRAGMA query_only --- README.md | 1 + sqlite3.go | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/README.md b/README.md index addd874..02e5b25 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,7 @@ Boolean values can be one of: | Locking Mode | `_locking` | | For more information see [PRAGMA locking_mode](https://www.sqlite.org/pragma.html#pragma_locking_mode) | | Mode | `mode` | | Access Mode of the database. For more information see [SQLite Open](https://www.sqlite.org/c3ref/open.html) | | Mutex Locking | `_mutex` | | Specify mutex mode. | +| Query Only | `_query_only` | `boolean` | For more information see [PRAGMA query_only](https://www.sqlite.org/pragma.html#pragma_query_only) | | Recursive Triggers | `_recursive_triggers` \| `_rt` | `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. | diff --git a/sqlite3.go b/sqlite3.go index 3e2d2e3..c9a6bfe 100644 --- a/sqlite3.go +++ b/sqlite3.go @@ -856,6 +856,9 @@ func errorString(err Error) string { // The locking-mode is either NORMAL or EXCLUSIVE. // https://www.sqlite.org/pragma.html#pragma_locking_mode // +// _query_only=Boolean +// The query_only pragma prevents all changes to database files when enabled. +// // _recursive_triggers=Boolean | _rt=Boolean // Enable or disable recursive triggers. // @@ -884,6 +887,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) { ignoreCheckConstraints := -1 journalMode := "DELETE" lockingMode := "NORMAL" + queryOnly := -1 recursiveTriggers := -1 pos := strings.IndexRune(dsn, '?') @@ -1068,6 +1072,21 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) { } } + // Query Only (_query_only) + // + // https://www.sqlite.org/pragma.html#pragma_query_only + // + if val := params.Get("_query_only"); val != "" { + switch strings.ToLower(val) { + case "0", "no", "false", "off": + queryOnly = 0 + case "1", "yes", "true", "on": + queryOnly = 1 + default: + return nil, fmt.Errorf("Invalid _query_only: %v, expecting boolean value of '0 1 false true no yes off on'", val) + } + } + // Recursive Triggers (_recursive_triggers) // // https://www.sqlite.org/pragma.html#pragma_recursive_triggers @@ -1179,6 +1198,14 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) { return nil, err } + // Query Only + if queryOnly > 0 { + if err := exec(fmt.Sprintf("PRAGMA query_only = %d;", queryOnly)); err != nil { + C.sqlite3_close_v2(db) + return nil, err + } + } + // Recursive Triggers if recursiveTriggers > -1 { if err := exec(fmt.Sprintf("PRAGMA recursive_triggers = %d;", recursiveTriggers)); err != nil {