Skip to content

Commit 4857d60

Browse files
committed
Fix: Connection DSN Keys
* Conform keys to match PRAGMA * UPD: README * Fix error of _auto_vacuum * Fix error of _case_sensitive_like * Fix error of _locking_mode * Fix error of _secure_delete
1 parent 24cbd40 commit 4857d60

File tree

2 files changed

+44
-15
lines changed

2 files changed

+44
-15
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ Boolean values can be one of:
7474

7575
| Name | Key | Value(s) | Description |
7676
|------|-----|----------|-------------|
77-
| Auto Vacuum | `_vacuum` | <ul><li>`0` \| `none`</li><li>`1` \| `full`</li><li>`2` \| `incremental`</li></ul> | For more information see [PRAGMA auto_vacuum](https://www.sqlite.org/pragma.html#pragma_auto_vacuum) |
77+
| Auto Vacuum | `_auto_vacuum` \| `_vacuum` | <ul><li>`0` \| `none`</li><li>`1` \| `full`</li><li>`2` \| `incremental`</li></ul> | For more information see [PRAGMA auto_vacuum](https://www.sqlite.org/pragma.html#pragma_auto_vacuum) |
7878
| 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) |
79-
| Case Sensitive LIKE | `_cslike` | `boolean` | For more information see [PRAGMA case_sensitive_like](https://www.sqlite.org/pragma.html#pragma_case_sensitive_like) |
79+
| Case Sensitive LIKE | `_case_sensitive_like` \| `_cslike` | `boolean` | For more information see [PRAGMA case_sensitive_like](https://www.sqlite.org/pragma.html#pragma_case_sensitive_like) |
8080
| Defer Foreign Keys | `_defer_foreign_keys` \| `_defer_fk` | `boolean` | For more information see [PRAGMA defer_foreign_keys](https://www.sqlite.org/pragma.html#pragma_defer_foreign_keys) |
8181
| Foreign Keys | `_foreign_keys` \| `_fk` | `boolean` | For more information see [PRAGMA foreign_keys](https://www.sqlite.org/pragma.html#pragma_foreign_keys) |
8282
| Ignore CHECK Constraints | `_ignore_check_constraints` | `boolean` | For more information see [PRAGMA ignore_check_constraints](https://www.sqlite.org/pragma.html#pragma_ignore_check_constraints) |
8383
| Immutable | `immutable` | `boolean` | For more information see [Immutable](https://www.sqlite.org/c3ref/open.html) |
84-
| Journal Mode | `_journal` | <ul><li>DELETE</li><li>TRUNCATE</li><li>PERSIST</li><li>MEMORY</li><li>WAL</li><li>OFF</li></ul> | For more information see [PRAGMA journal_mode](https://www.sqlite.org/pragma.html#pragma_journal_mode) |
85-
| 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) |
84+
| Journal Mode | `_journal_mode` \| `_journal` | <ul><li>DELETE</li><li>TRUNCATE</li><li>PERSIST</li><li>MEMORY</li><li>WAL</li><li>OFF</li></ul> | For more information see [PRAGMA journal_mode](https://www.sqlite.org/pragma.html#pragma_journal_mode) |
85+
| 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) |
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. |
8888
| Query Only | `_query_only` | `boolean` | For more information see [PRAGMA query_only](https://www.sqlite.org/pragma.html#pragma_query_only) |

sqlite3.go

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,8 @@ func errorString(err Error) string {
838838
// _busy_timeout=XXX"| _timeout=XXX
839839
// Specify value for sqlite3_busy_timeout.
840840
//
841-
// _cslike=Boolean
841+
// _case_sensitive_like=Boolean | _cslike=Boolean
842+
// https://www.sqlite.org/pragma.html#pragma_case_sensitive_like
842843
// Default or disabled the LIKE operation is case-insensitive.
843844
// When enabling this options behaviour of LIKE will become case-sensitive.
844845
//
@@ -852,11 +853,11 @@ func errorString(err Error) string {
852853
// This pragma enables or disables the enforcement of CHECK constraints.
853854
// The default setting is off, meaning that CHECK constraints are enforced by default.
854855
//
855-
// _journal=MODE
856+
// _journal_mode=MODE | _journal=MODE
856857
// Set journal mode for the databases associated with the current connection.
857858
// https://www.sqlite.org/pragma.html#pragma_journal_mode
858859
//
859-
// _locking=X
860+
// _locking_mode=X | _locking=X
860861
// Sets the database connection locking-mode.
861862
// The locking-mode is either NORMAL or EXCLUSIVE.
862863
// https://www.sqlite.org/pragma.html#pragma_locking_mode
@@ -958,7 +959,14 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
958959
//
959960
// https://www.sqlite.org/pragma.html#pragma_auto_vacuum
960961
//
961-
if val := params.Get("_vacuum"); val != "" {
962+
pkey = "" // Reset pkey
963+
if _, ok := params["_auto_vacuum"]; ok {
964+
pkey = "_auto_vacuum"
965+
}
966+
if _, ok := params["_vacuum"]; ok {
967+
pkey = "_vacuum"
968+
}
969+
if val := params.Get(pkey); val != "" {
962970
switch strings.ToLower(val) {
963971
case "0", "none":
964972
autoVacuum = 0
@@ -967,7 +975,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
967975
case "2", "incremental":
968976
autoVacuum = 2
969977
default:
970-
return nil, fmt.Errorf("Invalid _vacuum: %v", val)
978+
return nil, fmt.Errorf("Invalid _auto_vacuum: %v, expecting value of '0 NONE 1 FULL 2 INCREMENTAL'", val)
971979
}
972980
}
973981

@@ -994,14 +1002,21 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
9941002
//
9951003
// https://www.sqlite.org/pragma.html#pragma_case_sensitive_like
9961004
//
997-
if val := params.Get("_cslike"); val != "" {
1005+
pkey = "" // Reset pkey
1006+
if _, ok := params["_case_sensitive_like"]; ok {
1007+
pkey = "_case_sensitive_like"
1008+
}
1009+
if _, ok := params["_cslike"]; ok {
1010+
pkey = "_cslike"
1011+
}
1012+
if val := params.Get(pkey); val != "" {
9981013
switch strings.ToLower(val) {
9991014
case "0", "no", "false", "off":
10001015
caseSensitiveLike = 0
10011016
case "1", "yes", "true", "on":
10021017
caseSensitiveLike = 1
10031018
default:
1004-
return nil, fmt.Errorf("Invalid _cslike: %v, expecting boolean value of '0 1 false true no yes off on'", val)
1019+
return nil, fmt.Errorf("Invalid _case_sensitive_like: %v, expecting boolean value of '0 1 false true no yes off on'", val)
10051020
}
10061021
}
10071022

@@ -1064,11 +1079,18 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
10641079
}
10651080
}
10661081

1067-
// Journal Mode (_journal)
1082+
// Journal Mode (_journal_mode | _journal)
10681083
//
10691084
// https://www.sqlite.org/pragma.html#pragma_journal_mode
10701085
//
1071-
if val := params.Get("_journal"); val != "" {
1086+
pkey = "" // Reset pkey
1087+
if _, ok := params["_journal_mode"]; ok {
1088+
pkey = "_journal_mode"
1089+
}
1090+
if _, ok := params["_journal"]; ok {
1091+
pkey = "_journal"
1092+
}
1093+
if val := params.Get(pkey); val != "" {
10721094
switch strings.ToUpper(val) {
10731095
case "DELETE", "TRUNCATE", "PERSIST", "MEMORY", "OFF":
10741096
journalMode = strings.ToUpper(val)
@@ -1087,12 +1109,19 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
10871109
//
10881110
// https://www.sqlite.org/pragma.html#pragma_locking_mode
10891111
//
1112+
pkey = "" // Reset pkey
1113+
if _, ok := params["_locking_mode"]; ok {
1114+
pkey = "_locking_mode"
1115+
}
1116+
if _, ok := params["_locking"]; ok {
1117+
pkey = "_locking"
1118+
}
10901119
if val := params.Get("_locking"); val != "" {
10911120
switch strings.ToUpper(val) {
10921121
case "NORMAL", "EXCLUSIVE":
10931122
lockingMode = strings.ToUpper(val)
10941123
default:
1095-
return nil, fmt.Errorf("Invalid _locking: %v, expecting value of 'NORMAL EXCLUSIVE", val)
1124+
return nil, fmt.Errorf("Invalid _locking_mode: %v, expecting value of 'NORMAL EXCLUSIVE", val)
10961125
}
10971126
}
10981127

@@ -1146,7 +1175,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
11461175
case "fast":
11471176
secureDelete = "FAST"
11481177
default:
1149-
return nil, fmt.Errorf("Invalid _recursive_triggers: %v, expecting boolean value of '0 1 false true no yes off on'", val)
1178+
return nil, fmt.Errorf("Invalid _secure_delete: %v, expecting boolean value of '0 1 false true no yes off on'", val)
11501179
}
11511180
}
11521181

0 commit comments

Comments
 (0)