diff options
author | Gert-Jan Timmer <gjr.timmer@gmail.com> | 2018-05-29 13:29:06 +0200 |
---|---|---|
committer | Gert-Jan Timmer <gjr.timmer@gmail.com> | 2018-05-29 13:29:06 +0200 |
commit | 764e391156b04640da0150bc4b1f11003b93d2a4 (patch) | |
tree | 7db085e74983db1f6511660c9ac5145afcf746ca | |
parent | Add: Documentation for opening as Immutable (diff) | |
download | golite-764e391156b04640da0150bc4b1f11003b93d2a4.tar.gz golite-764e391156b04640da0150bc4b1f11003b93d2a4.tar.xz |
ADD: PRAGMA query_only
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | sqlite3.go | 27 |
2 files changed, 28 insertions, 0 deletions
@@ -85,6 +85,7 @@ Boolean values can be one of: | Locking Mode | `_locking` | <ul><li>NORMAL</li><li>EXCLUSIVE</li></ul> | For more information see [PRAGMA locking_mode](https://www.sqlite.org/pragma.html#pragma_locking_mode) | | Mode | `mode` | <ul><li>ro</li><li>rw</li><li>rwc</li><li>memory</li></ul> | Access Mode of the database. For more information see [SQLite Open](https://www.sqlite.org/c3ref/open.html) | | Mutex Locking | `_mutex` | <ul><li>no</li><li>full</li></ul> | 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` | <ul><li>shared</li><li>private</li></ul> | 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. | @@ -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 { |