forked from mirror/go-sqlite3
ADD: PRAGMA query_only
This commit is contained in:
parent
9e79299c09
commit
764e391156
|
@ -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) |
|
| 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) |
|
| 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. |
|
| 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) |
|
| 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) |
|
| 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. |
|
| Time Zone Location | `_loc` | auto | Specify location of time format. |
|
||||||
|
|
27
sqlite3.go
27
sqlite3.go
|
@ -856,6 +856,9 @@ func errorString(err Error) string {
|
||||||
// The locking-mode is either NORMAL or EXCLUSIVE.
|
// The locking-mode is either NORMAL or EXCLUSIVE.
|
||||||
// https://www.sqlite.org/pragma.html#pragma_locking_mode
|
// 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
|
// _recursive_triggers=Boolean | _rt=Boolean
|
||||||
// Enable or disable recursive triggers.
|
// Enable or disable recursive triggers.
|
||||||
//
|
//
|
||||||
|
@ -884,6 +887,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
|
||||||
ignoreCheckConstraints := -1
|
ignoreCheckConstraints := -1
|
||||||
journalMode := "DELETE"
|
journalMode := "DELETE"
|
||||||
lockingMode := "NORMAL"
|
lockingMode := "NORMAL"
|
||||||
|
queryOnly := -1
|
||||||
recursiveTriggers := -1
|
recursiveTriggers := -1
|
||||||
|
|
||||||
pos := strings.IndexRune(dsn, '?')
|
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)
|
// Recursive Triggers (_recursive_triggers)
|
||||||
//
|
//
|
||||||
// https://www.sqlite.org/pragma.html#pragma_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
|
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
|
// Recursive Triggers
|
||||||
if recursiveTriggers > -1 {
|
if recursiveTriggers > -1 {
|
||||||
if err := exec(fmt.Sprintf("PRAGMA recursive_triggers = %d;", recursiveTriggers)); err != nil {
|
if err := exec(fmt.Sprintf("PRAGMA recursive_triggers = %d;", recursiveTriggers)); err != nil {
|
||||||
|
|
Loading…
Reference in New Issue