Skip to content

Commit 9523755

Browse files
committed
ADD: PRAGMA case_sensitive_like
ADD: Comments UPD: README
1 parent efc41bc commit 9523755

File tree

2 files changed

+51
-11
lines changed

2 files changed

+51
-11
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,11 @@ Boolean values can be one of:
7575
| Name | Key | Value(s) | Description |
7676
|------|-----|----------|-------------|
7777
| 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. |
79-
| Foreign Keys | _foreign_keys | `boolean` | Enable or disable enforcement of foreign keys. |
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) |
8081
| Mutex Locking | _mutex | <ul><li>no</li><li>full</li></ul> | Specify mutex mode. |
81-
| Recursive Triggers | _recursive_triggers | `boolean` | Enable or disable recursive triggers. |
82+
| Recursive Triggers | _recursive_triggers | `boolean` | For more information see [PRAGMA recursive_triggers](https://www.sqlite.org/pragma.html#pragma_recursive_triggers) |
8283
| 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) |
8384
| Time Zone Location | _loc | auto | Specify location of time format. |
8485
| Transaction Lock | _txlock | <ul><li>immediate</li><li>deferred</li><li>exclusive</li></ul> | Specify locking behavior for transactions. |

sqlite3.go

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -806,10 +806,14 @@ func errorString(err Error) string {
806806
// _busy_timeout=XXX
807807
// Specify value for sqlite3_busy_timeout.
808808
//
809-
// _foreign_keys=X
809+
// _cslike=Boolean
810+
// Default or disabled the LIKE operation is case-insensitive.
811+
// When enabling this options behaviour of LIKE will become case-sensitive.
812+
//
813+
// _foreign_keys=Boolean
810814
// Enable or disable enforcement of foreign keys. X can be 1 or 0.
811815
//
812-
// _recursive_triggers=X
816+
// _recursive_triggers=Boolean
813817
// Enable or disable recursive triggers. X can be 1 or 0.
814818
//
815819
// _vacuum=X
@@ -829,6 +833,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
829833
// PRAGMA's
830834
autoVacuum := -1
831835
busyTimeout := 5000
836+
caseSensitiveLike := -1
832837
foreignKeys := -1
833838
recursiveTriggers := -1
834839

@@ -877,7 +882,10 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
877882
}
878883
}
879884

880-
// auto_vacuum
885+
// Auto Vacuum (_vacuum)
886+
//
887+
// https://www.sqlite.org/pragma.html#pragma_auto_vacuum
888+
//
881889
if val := params.Get("_vacuum"); val != "" {
882890
switch strings.ToLower(val) {
883891
case "0", "none":
@@ -891,7 +899,10 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
891899
}
892900
}
893901

894-
// _busy_timeout
902+
// Busy Timeout (_busy_timeout)
903+
//
904+
// https://www.sqlite.org/pragma.html#pragma_busy_timeout
905+
//
895906
if val := params.Get("_busy_timeout"); val != "" {
896907
iv, err := strconv.ParseInt(val, 10, 64)
897908
if err != nil {
@@ -900,27 +911,48 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
900911
busyTimeout = int(iv)
901912
}
902913

903-
// _foreign_keys
914+
// Case Sensitive Like (_cslike)
915+
//
916+
// https://www.sqlite.org/pragma.html#pragma_case_sensitive_like
917+
//
918+
if val := params.Get("_cslike"); val != "" {
919+
switch strings.ToLower(val) {
920+
case "0", "no", "false", "off":
921+
caseSensitiveLike = 0
922+
case "1", "yes", "true", "on":
923+
caseSensitiveLike = 1
924+
default:
925+
return nil, fmt.Errorf("Invalid _cslike: %v, expecting boolean value of '0 1 false true no yes off on'", val)
926+
}
927+
}
928+
929+
// Foreign Keys (_foreign_keys)
930+
//
931+
// https://www.sqlite.org/pragma.html#pragma_foreign_keys
932+
//
904933
if val := params.Get("_foreign_keys"); val != "" {
905934
switch strings.ToLower(val) {
906935
case "0", "no", "false", "off":
907936
foreignKeys = 0
908937
case "1", "yes", "true", "on":
909938
foreignKeys = 1
910939
default:
911-
return nil, fmt.Errorf("Invalid _foreign_keys: %v", val)
940+
return nil, fmt.Errorf("Invalid _foreign_keys: %v, expecting boolean value of '0 1 false true no yes off on'", val)
912941
}
913942
}
914943

915-
// _recursive_triggers
944+
// Recursive Triggers (_recursive_triggers)
945+
//
946+
// https://www.sqlite.org/pragma.html#pragma_recursive_triggers
947+
//
916948
if val := params.Get("_recursive_triggers"); val != "" {
917949
switch strings.ToLower(val) {
918950
case "0", "no", "false", "off":
919951
recursiveTriggers = 0
920952
case "1", "yes", "true", "on":
921953
recursiveTriggers = 1
922954
default:
923-
return nil, fmt.Errorf("Invalid _recursive_triggers: %v", val)
955+
return nil, fmt.Errorf("Invalid _recursive_triggers: %v, expecting boolean value of '0 1 false true no yes off on'", val)
924956
}
925957
}
926958

@@ -966,6 +998,13 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
966998
}
967999
}
9681000

1001+
if caseSensitiveLike > -1 {
1002+
if err := exec(fmt.Sprintf("PRAGMA case_sensitive_like = %d;", caseSensitiveLike)); err != nil {
1003+
C.sqlite3_close_v2(db)
1004+
return nil, err
1005+
}
1006+
}
1007+
9691008
// Forgein Keys
9701009
if foreignKeys > -1 {
9711010
if err := exec(fmt.Sprintf("PRAGMA foreign_keys = %d;", foreignKeys)); err != nil {

0 commit comments

Comments
 (0)