Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 764e391

Browse files
ADD: PRAGMA query_only
1 parent 9e79299 commit 764e391

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Boolean values can be one of:
8585
| 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) |
8686
| 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) |
8787
| Mutex Locking | `_mutex` | <ul><li>no</li><li>full</li></ul> | Specify mutex mode. |
88+
| Query Only | `_query_only` | `boolean` | For more information see [PRAGMA query_only](https://www.sqlite.org/pragma.html#pragma_query_only) |
8889
| Recursive Triggers | `_recursive_triggers` \| `_rt` | `boolean` | For more information see [PRAGMA recursive_triggers](https://www.sqlite.org/pragma.html#pragma_recursive_triggers) |
8990
| 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) |
9091
| Time Zone Location | `_loc` | auto | Specify location of time format. |

‎sqlite3.go‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,9 @@ func errorString(err Error) string {
856856
// The locking-mode is either NORMAL or EXCLUSIVE.
857857
// https://www.sqlite.org/pragma.html#pragma_locking_mode
858858
//
859+
// _query_only=Boolean
860+
// The query_only pragma prevents all changes to database files when enabled.
861+
//
859862
// _recursive_triggers=Boolean | _rt=Boolean
860863
// Enable or disable recursive triggers.
861864
//
@@ -884,6 +887,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
884887
ignoreCheckConstraints := -1
885888
journalMode := "DELETE"
886889
lockingMode := "NORMAL"
890+
queryOnly := -1
887891
recursiveTriggers := -1
888892

889893
pos := strings.IndexRune(dsn, '?')
@@ -1068,6 +1072,21 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
10681072
}
10691073
}
10701074

1075+
// Query Only (_query_only)
1076+
//
1077+
// https://www.sqlite.org/pragma.html#pragma_query_only
1078+
//
1079+
if val := params.Get("_query_only"); val != "" {
1080+
switch strings.ToLower(val) {
1081+
case "0", "no", "false", "off":
1082+
queryOnly = 0
1083+
case "1", "yes", "true", "on":
1084+
queryOnly = 1
1085+
default:
1086+
return nil, fmt.Errorf("Invalid _query_only: %v, expecting boolean value of '0 1 false true no yes off on'", val)
1087+
}
1088+
}
1089+
10711090
// Recursive Triggers (_recursive_triggers)
10721091
//
10731092
// https://www.sqlite.org/pragma.html#pragma_recursive_triggers
@@ -1179,6 +1198,14 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
11791198
return nil, err
11801199
}
11811200

1201+
// Query Only
1202+
if queryOnly > 0 {
1203+
if err := exec(fmt.Sprintf("PRAGMA query_only = %d;", queryOnly)); err != nil {
1204+
C.sqlite3_close_v2(db)
1205+
return nil, err
1206+
}
1207+
}
1208+
11821209
// Recursive Triggers
11831210
if recursiveTriggers > -1 {
11841211
if err := exec(fmt.Sprintf("PRAGMA recursive_triggers = %d;", recursiveTriggers)); err != nil {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /