Skip to content

Commit f087cd7

Browse files
committed
Update Busy Timeout PRAGMA
ADD: multiple key
1 parent 9523755 commit f087cd7

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

README.md

Lines changed: 9 additions & 9 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) |
78-
| Busy Timeout | _busy_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) |
80-
| Foreign Keys | _foreign_keys | `boolean` | For more information see [PRAGMA foreign_keys](https://www.sqlite.org/pragma.html#pragma_foreign_keys) |
81-
| Mutex Locking | _mutex | <ul><li>no</li><li>full</li></ul> | Specify mutex mode. |
82-
| Recursive Triggers | _recursive_triggers | `boolean` | For more information see [PRAGMA recursive_triggers](https://www.sqlite.org/pragma.html#pragma_recursive_triggers) |
83-
| 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) |
84-
| Time Zone Location | _loc | auto | Specify location of time format. |
85-
| Transaction Lock | _txlock | <ul><li>immediate</li><li>deferred</li><li>exclusive</li></ul> | Specify locking behavior for transactions. |
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) |
78+
| 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) |
80+
| Foreign Keys | `_foreign_keys` | `boolean` | For more information see [PRAGMA foreign_keys](https://www.sqlite.org/pragma.html#pragma_foreign_keys) |
81+
| Mutex Locking | `_mutex` | <ul><li>no</li><li>full</li></ul> | Specify mutex mode. |
82+
| Recursive Triggers | `_recursive_triggers` | `boolean` | For more information see [PRAGMA recursive_triggers](https://www.sqlite.org/pragma.html#pragma_recursive_triggers) |
83+
| 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) |
84+
| Time Zone Location | `_loc` | auto | Specify location of time format. |
85+
| Transaction Lock | `_txlock` | <ul><li>immediate</li><li>deferred</li><li>exclusive</li></ul> | Specify locking behavior for transactions. |
8686

8787
## DSN Examples
8888

sqlite3.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,8 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
825825
return nil, errors.New("sqlite library was not compiled for thread-safe operation")
826826
}
827827

828+
var pkey string
829+
828830
// Options
829831
var loc *time.Location
830832
mutex := C.int(C.SQLITE_OPEN_FULLMUTEX)
@@ -903,7 +905,13 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
903905
//
904906
// https://www.sqlite.org/pragma.html#pragma_busy_timeout
905907
//
906-
if val := params.Get("_busy_timeout"); val != "" {
908+
if _, ok := params["_busy_timeout"]; ok {
909+
pkey = "_busy_timeout"
910+
}
911+
if _, ok := params["_timeout"]; ok {
912+
pkey = "_timeout"
913+
}
914+
if val := params.Get(pkey); val != "" {
907915
iv, err := strconv.ParseInt(val, 10, 64)
908916
if err != nil {
909917
return nil, fmt.Errorf("Invalid _busy_timeout: %v: %v", val, err)
@@ -930,6 +938,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
930938
//
931939
// https://www.sqlite.org/pragma.html#pragma_foreign_keys
932940
//
941+
933942
if val := params.Get("_foreign_keys"); val != "" {
934943
switch strings.ToLower(val) {
935944
case "0", "no", "false", "off":

0 commit comments

Comments
 (0)