ADD: PRAGMA case_sensitive_like

ADD: Comments
UPD: README
This commit is contained in:
Gert-Jan Timmer 2018-05-29 11:46:53 +02:00
parent efc41bcd27
commit 95237557d2
2 changed files with 51 additions and 11 deletions

View File

@ -75,10 +75,11 @@ Boolean values can be one of:
| Name | Key | Value(s) | Description | | Name | Key | Value(s) | Description |
|------|-----|----------|-------------| |------|-----|----------|-------------|
| 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) | | 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) |
| Busy Timeout | _busy_timeout | `int` | Specify value for sqlite3_busy_timeout. | | 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) |
| Foreign Keys | _foreign_keys | `boolean` | Enable or disable enforcement of foreign keys. | | Case Sensitive LIKE | _cslike | `boolean` | For more information see [PRAGMA case_sensitive_like](https://www.sqlite.org/pragma.html#pragma_case_sensitive_like) |
| Foreign Keys | _foreign_keys | `boolean` | For more information see [PRAGMA foreign_keys](https://www.sqlite.org/pragma.html#pragma_foreign_keys) |
| 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. |
| Recursive Triggers | _recursive_triggers | `boolean` | Enable or disable recursive triggers. | | Recursive Triggers | _recursive_triggers | `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. |
| Transaction Lock | _txlock | <ul><li>immediate</li><li>deferred</li><li>exclusive</li></ul> | Specify locking behavior for transactions. | | Transaction Lock | _txlock | <ul><li>immediate</li><li>deferred</li><li>exclusive</li></ul> | Specify locking behavior for transactions. |

View File

@ -806,10 +806,14 @@ func errorString(err Error) string {
// _busy_timeout=XXX // _busy_timeout=XXX
// Specify value for sqlite3_busy_timeout. // Specify value for sqlite3_busy_timeout.
// //
// _foreign_keys=X // _cslike=Boolean
// Default or disabled the LIKE operation is case-insensitive.
// When enabling this options behaviour of LIKE will become case-sensitive.
//
// _foreign_keys=Boolean
// Enable or disable enforcement of foreign keys. X can be 1 or 0. // Enable or disable enforcement of foreign keys. X can be 1 or 0.
// //
// _recursive_triggers=X // _recursive_triggers=Boolean
// Enable or disable recursive triggers. X can be 1 or 0. // Enable or disable recursive triggers. X can be 1 or 0.
// //
// _vacuum=X // _vacuum=X
@ -829,6 +833,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
// PRAGMA's // PRAGMA's
autoVacuum := -1 autoVacuum := -1
busyTimeout := 5000 busyTimeout := 5000
caseSensitiveLike := -1
foreignKeys := -1 foreignKeys := -1
recursiveTriggers := -1 recursiveTriggers := -1
@ -877,7 +882,10 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
} }
} }
// auto_vacuum // Auto Vacuum (_vacuum)
//
// https://www.sqlite.org/pragma.html#pragma_auto_vacuum
//
if val := params.Get("_vacuum"); val != "" { if val := params.Get("_vacuum"); val != "" {
switch strings.ToLower(val) { switch strings.ToLower(val) {
case "0", "none": case "0", "none":
@ -891,7 +899,10 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
} }
} }
// _busy_timeout // Busy Timeout (_busy_timeout)
//
// https://www.sqlite.org/pragma.html#pragma_busy_timeout
//
if val := params.Get("_busy_timeout"); val != "" { if val := params.Get("_busy_timeout"); val != "" {
iv, err := strconv.ParseInt(val, 10, 64) iv, err := strconv.ParseInt(val, 10, 64)
if err != nil { if err != nil {
@ -900,7 +911,25 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
busyTimeout = int(iv) busyTimeout = int(iv)
} }
// _foreign_keys // Case Sensitive Like (_cslike)
//
// https://www.sqlite.org/pragma.html#pragma_case_sensitive_like
//
if val := params.Get("_cslike"); val != "" {
switch strings.ToLower(val) {
case "0", "no", "false", "off":
caseSensitiveLike = 0
case "1", "yes", "true", "on":
caseSensitiveLike = 1
default:
return nil, fmt.Errorf("Invalid _cslike: %v, expecting boolean value of '0 1 false true no yes off on'", val)
}
}
// Foreign Keys (_foreign_keys)
//
// https://www.sqlite.org/pragma.html#pragma_foreign_keys
//
if val := params.Get("_foreign_keys"); val != "" { if val := params.Get("_foreign_keys"); val != "" {
switch strings.ToLower(val) { switch strings.ToLower(val) {
case "0", "no", "false", "off": case "0", "no", "false", "off":
@ -908,11 +937,14 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
case "1", "yes", "true", "on": case "1", "yes", "true", "on":
foreignKeys = 1 foreignKeys = 1
default: default:
return nil, fmt.Errorf("Invalid _foreign_keys: %v", val) return nil, fmt.Errorf("Invalid _foreign_keys: %v, expecting boolean value of '0 1 false true no yes off on'", val)
} }
} }
// _recursive_triggers // Recursive Triggers (_recursive_triggers)
//
// https://www.sqlite.org/pragma.html#pragma_recursive_triggers
//
if val := params.Get("_recursive_triggers"); val != "" { if val := params.Get("_recursive_triggers"); val != "" {
switch strings.ToLower(val) { switch strings.ToLower(val) {
case "0", "no", "false", "off": case "0", "no", "false", "off":
@ -920,7 +952,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
case "1", "yes", "true", "on": case "1", "yes", "true", "on":
recursiveTriggers = 1 recursiveTriggers = 1
default: default:
return nil, fmt.Errorf("Invalid _recursive_triggers: %v", val) return nil, fmt.Errorf("Invalid _recursive_triggers: %v, expecting boolean value of '0 1 false true no yes off on'", val)
} }
} }
@ -966,6 +998,13 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
} }
} }
if caseSensitiveLike > -1 {
if err := exec(fmt.Sprintf("PRAGMA case_sensitive_like = %d;", caseSensitiveLike)); err != nil {
C.sqlite3_close_v2(db)
return nil, err
}
}
// Forgein Keys // Forgein Keys
if foreignKeys > -1 { if foreignKeys > -1 {
if err := exec(fmt.Sprintf("PRAGMA foreign_keys = %d;", foreignKeys)); err != nil { if err := exec(fmt.Sprintf("PRAGMA foreign_keys = %d;", foreignKeys)); err != nil {