Skip to content

Commit a4b55e1

Browse files
committed
ADD: PRAGMA ignore_check_constraints
1 parent 37d3ff3 commit a4b55e1

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ Boolean values can be one of:
7979
| 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) |
82+
| 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) |
8283
| Mutex Locking | `_mutex` | <ul><li>no</li><li>full</li></ul> | Specify mutex mode. |
8384
| Recursive Triggers | `_recursive_triggers` \| `_rt` | `boolean` | For more information see [PRAGMA recursive_triggers](https://www.sqlite.org/pragma.html#pragma_recursive_triggers) |
8485
| 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) |

sqlite3.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,10 @@ func errorString(err Error) string {
816816
// _foreign_keys=Boolean | _fk=Boolean
817817
// Enable or disable enforcement of foreign keys.
818818
//
819+
// _ignore_check_constraints=Boolean
820+
// This pragma enables or disables the enforcement of CHECK constraints.
821+
// The default setting is off, meaning that CHECK constraints are enforced by default.
822+
//
819823
// _recursive_triggers=Boolean | _rt=Boolean
820824
// Enable or disable recursive triggers.
821825
//
@@ -840,6 +844,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
840844
busyTimeout := 5000
841845
caseSensitiveLike := -1
842846
deferForeignKeys := -1
847+
ignoreCheckConstraints := -1
843848
foreignKeys := -1
844849
recursiveTriggers := -1
845850

@@ -983,6 +988,21 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
983988
}
984989
}
985990

991+
// Ignore CHECK Constrains (_ignore_check_constraints)
992+
//
993+
// https://www.sqlite.org/pragma.html#pragma_ignore_check_constraints
994+
//
995+
if val := params.Get("_ignore_check_constraints"); val != "" {
996+
switch strings.ToLower(val) {
997+
case "0", "no", "false", "off":
998+
ignoreCheckConstraints = 0
999+
case "1", "yes", "true", "on":
1000+
ignoreCheckConstraints = 1
1001+
default:
1002+
return nil, fmt.Errorf("Invalid _ignore_check_constraints: %v, expecting boolean value of '0 1 false true no yes off on'", val)
1003+
}
1004+
}
1005+
9861006
// Recursive Triggers (_recursive_triggers)
9871007
//
9881008
// https://www.sqlite.org/pragma.html#pragma_recursive_triggers
@@ -1071,6 +1091,14 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
10711091
}
10721092
}
10731093

1094+
// Ignore CHECK Constraints
1095+
if ignoreCheckConstraints > -1 {
1096+
if err := exec(fmt.Sprintf("PRAGMA ignore_check_constraints = %d;", ignoreCheckConstraints)); err != nil {
1097+
C.sqlite3_close_v2(db)
1098+
return nil, err
1099+
}
1100+
}
1101+
10741102
// Recursive Triggers
10751103
if recursiveTriggers > -1 {
10761104
if err := exec(fmt.Sprintf("PRAGMA recursive_triggers = %d;", recursiveTriggers)); err != nil {

0 commit comments

Comments
 (0)