ADD: PRAGMA ignore_check_constraints

fix-635
Gert-Jan Timmer 2018-05-29 12:19:46 +02:00
parent 37d3ff3d86
commit a4b55e1a40
2 changed files with 29 additions and 0 deletions

View File

@ -79,6 +79,7 @@ Boolean values can be one of:
| Case Sensitive LIKE | `_cslike` | `boolean` | For more information see [PRAGMA case_sensitive_like](https://www.sqlite.org/pragma.html#pragma_case_sensitive_like) |
| 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) |
| Foreign Keys | `_foreign_keys` \| `_fk` | `boolean` | For more information see [PRAGMA foreign_keys](https://www.sqlite.org/pragma.html#pragma_foreign_keys) |
| 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) |
| Mutex Locking | `_mutex` | <ul><li>no</li><li>full</li></ul> | Specify mutex mode. |
| Recursive Triggers | `_recursive_triggers` \| `_rt` | `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) |

View File

@ -816,6 +816,10 @@ func errorString(err Error) string {
// _foreign_keys=Boolean | _fk=Boolean
// Enable or disable enforcement of foreign keys.
//
// _ignore_check_constraints=Boolean
// This pragma enables or disables the enforcement of CHECK constraints.
// The default setting is off, meaning that CHECK constraints are enforced by default.
//
// _recursive_triggers=Boolean | _rt=Boolean
// Enable or disable recursive triggers.
//
@ -840,6 +844,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
busyTimeout := 5000
caseSensitiveLike := -1
deferForeignKeys := -1
ignoreCheckConstraints := -1
foreignKeys := -1
recursiveTriggers := -1
@ -983,6 +988,21 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
}
}
// Ignore CHECK Constrains (_ignore_check_constraints)
//
// https://www.sqlite.org/pragma.html#pragma_ignore_check_constraints
//
if val := params.Get("_ignore_check_constraints"); val != "" {
switch strings.ToLower(val) {
case "0", "no", "false", "off":
ignoreCheckConstraints = 0
case "1", "yes", "true", "on":
ignoreCheckConstraints = 1
default:
return nil, fmt.Errorf("Invalid _ignore_check_constraints: %v, expecting boolean value of '0 1 false true no yes off on'", val)
}
}
// Recursive Triggers (_recursive_triggers)
//
// https://www.sqlite.org/pragma.html#pragma_recursive_triggers
@ -1071,6 +1091,14 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
}
}
// Ignore CHECK Constraints
if ignoreCheckConstraints > -1 {
if err := exec(fmt.Sprintf("PRAGMA ignore_check_constraints = %d;", ignoreCheckConstraints)); err != nil {
C.sqlite3_close_v2(db)
return nil, err
}
}
// Recursive Triggers
if recursiveTriggers > -1 {
if err := exec(fmt.Sprintf("PRAGMA recursive_triggers = %d;", recursiveTriggers)); err != nil {