diff options
author | EuAndreh <eu@euandre.org> | 2024-10-05 03:17:22 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2024-10-05 03:41:10 -0300 |
commit | efcfb6e7ce7339077c2a29f54caf610d09467093 (patch) | |
tree | f2ca16dd254d5622645f2eaaac4946bd48bf7ea0 | |
parent | src/golite.go: Add space before "*" pointer marker (diff) | |
download | golite-efcfb6e7ce7339077c2a29f54caf610d09467093.tar.gz golite-efcfb6e7ce7339077c2a29f54caf610d09467093.tar.xz |
src/golite.go: Remove other undesirable configurations from Open()
-rw-r--r-- | src/golite.go | 213 |
1 files changed, 2 insertions, 211 deletions
diff --git a/src/golite.go b/src/golite.go index 379ebfb..e489ea5 100644 --- a/src/golite.go +++ b/src/golite.go @@ -1691,19 +1691,9 @@ func (c *SQLiteConn) begin(ctx context.Context) (driver.Tx, error) { // Specify locking behavior for transactions. XXX can be "immediate", // "deferred", "exclusive". // -// _auto_vacuum=X | _vacuum=X -// 0 | none - Auto Vacuum disabled -// 1 | full - Auto Vacuum FULL -// 2 | incremental - Auto Vacuum Incremental -// // _busy_timeout=XXX"| _timeout=XXX // Specify value for sqlite3_busy_timeout. // -// _case_sensitive_like=Boolean | _cslike=Boolean -// https://www.sqlite.org/pragma.html#pragma_case_sensitive_like -// Default or disabled the LIKE operation is case-insensitive. -// When enabling this options behaviour of LIKE will become case-sensitive. -// // _defer_foreign_keys=Boolean | _defer_fk=Boolean // Defer Foreign Keys until outermost transaction is committed. // @@ -1711,14 +1701,6 @@ func (c *SQLiteConn) begin(ctx context.Context) (driver.Tx, error) { // This pragma enables or disables the enforcement of CHECK constraints. // The default setting is off, meaning that CHECK constraints are enforced by default. // -// _locking_mode=X | _locking=X -// Sets the database connection locking-mode. -// The locking-mode is either NORMAL or EXCLUSIVE. -// https://www.sqlite.org/pragma.html#pragma_locking_mode -// -// _query_only=Boolean -// The query_only pragma prevents all changes to database files when enabled. -// // _recursive_triggers=Boolean | _rt=Boolean // Enable or disable recursive triggers. // @@ -1735,21 +1717,14 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) { // Options var loc *time.Location - mutex := C.int(C.SQLITE_OPEN_FULLMUTEX) txlock := "BEGIN" // PRAGMA's - autoVacuum := -1 busyTimeout := 5000 - caseSensitiveLike := -1 deferForeignKeys := -1 - ignoreCheckConstraints := -1 - lockingMode := "NORMAL" - queryOnly := -1 recursiveTriggers := -1 writableSchema := -1 vfsName := "" - var cacheSize *int64 pos := strings.IndexRune(dsn, '?') if pos >= 1 { @@ -1771,18 +1746,6 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) { } } - // _mutex - if val := params.Get("_mutex"); val != "" { - switch strings.ToLower(val) { - case "no": - mutex = C.SQLITE_OPEN_NOMUTEX - case "full": - mutex = C.SQLITE_OPEN_FULLMUTEX - default: - return nil, fmt.Errorf("Invalid _mutex: %v", val) - } - } - // _txlock if val := params.Get("_txlock"); val != "" { switch strings.ToLower(val) { @@ -1797,30 +1760,6 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) { } } - // Auto Vacuum (_vacuum) - // - // https://www.sqlite.org/pragma.html#pragma_auto_vacuum - // - pkey = "" // Reset pkey - if _, ok := params["_auto_vacuum"]; ok { - pkey = "_auto_vacuum" - } - if _, ok := params["_vacuum"]; ok { - pkey = "_vacuum" - } - if val := params.Get(pkey); val != "" { - switch strings.ToLower(val) { - case "0", "none": - autoVacuum = 0 - case "1", "full": - autoVacuum = 1 - case "2", "incremental": - autoVacuum = 2 - default: - return nil, fmt.Errorf("Invalid _auto_vacuum: %v, expecting value of '0 NONE 1 FULL 2 INCREMENTAL'", val) - } - } - // Busy Timeout (_busy_timeout) // // https://www.sqlite.org/pragma.html#pragma_busy_timeout @@ -1840,28 +1779,6 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) { busyTimeout = int(iv) } - // Case Sensitive Like (_cslike) - // - // https://www.sqlite.org/pragma.html#pragma_case_sensitive_like - // - pkey = "" // Reset pkey - if _, ok := params["_case_sensitive_like"]; ok { - pkey = "_case_sensitive_like" - } - if _, ok := params["_cslike"]; ok { - pkey = "_cslike" - } - if val := params.Get(pkey); 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 _case_sensitive_like: %v, expecting boolean value of '0 1 false true no yes off on'", val) - } - } - // Defer Foreign Keys (_defer_foreign_keys | _defer_fk) // // https://www.sqlite.org/pragma.html#pragma_defer_foreign_keys @@ -1884,56 +1801,6 @@ 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) - } - } - - // Locking Mode (_locking) - // - // https://www.sqlite.org/pragma.html#pragma_locking_mode - // - pkey = "" // Reset pkey - if _, ok := params["_locking_mode"]; ok { - pkey = "_locking_mode" - } - if _, ok := params["_locking"]; ok { - pkey = "_locking" - } - if val := params.Get(pkey); val != "" { - switch strings.ToUpper(val) { - case "NORMAL", "EXCLUSIVE": - lockingMode = strings.ToUpper(val) - default: - return nil, fmt.Errorf("Invalid _locking_mode: %v, expecting value of 'NORMAL EXCLUSIVE", val) - } - } - - // Query Only (_query_only) - // - // https://www.sqlite.org/pragma.html#pragma_query_only - // - if val := params.Get("_query_only"); val != "" { - switch strings.ToLower(val) { - case "0", "no", "false", "off": - queryOnly = 0 - case "1", "yes", "true", "on": - queryOnly = 1 - default: - return nil, fmt.Errorf("Invalid _query_only: %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 @@ -1971,18 +1838,6 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) { } } - // Cache size (_cache_size) - // - // https://sqlite.org/pragma.html#pragma_cache_size - // - if val := params.Get("_cache_size"); val != "" { - iv, err := strconv.ParseInt(val, 10, 64) - if err != nil { - return nil, fmt.Errorf("Invalid _cache_size: %v: %v", val, err) - } - cacheSize = &iv - } - if val := params.Get("vfs"); val != "" { vfsName = val } @@ -2001,11 +1856,11 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) { defer C.free(unsafe.Pointer(vfs)) } - openFlags := + var openFlags C.int = C.SQLITE_OPEN_READWRITE | C.SQLITE_OPEN_CREATE | C.SQLITE_OPEN_URI | - mutex + C.SQLITE_OPEN_FULLMUTEX rv := C.sqlite3_open_v2(name, &db, openFlags, vfs) if rv != 0 { // Save off the error _before_ closing the database. @@ -2036,36 +1891,10 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) { C.sqlite3_close_v2(db) return nil, err } - // Foreign Keys - if err := exec("PRAGMA foreign_keys = ON;"); err != nil { - C.sqlite3_close_v2(db) - return nil, err - } // Create connection to SQLite conn := &SQLiteConn{db: db, loc: loc, txlock: txlock} - // Auto Vacuum - // Moved auto_vacuum command, the user preference for auto_vacuum needs to be implemented directly after - // the authentication and before the sqlite_user table gets created if the user - // decides to activate User Authentication because - // auto_vacuum needs to be set before any tables are created - // and activating user authentication creates the internal table `sqlite_user`. - if autoVacuum > -1 { - if err := exec(fmt.Sprintf("PRAGMA auto_vacuum = %d;", autoVacuum)); err != nil { - C.sqlite3_close_v2(db) - return nil, err - } - } - - // Case Sensitive LIKE - if caseSensitiveLike > -1 { - if err := exec(fmt.Sprintf("PRAGMA case_sensitive_like = %d;", caseSensitiveLike)); err != nil { - C.sqlite3_close_v2(db) - return nil, err - } - } - // Defer Foreign Keys if deferForeignKeys > -1 { if err := exec(fmt.Sprintf("PRAGMA defer_foreign_keys = %d;", deferForeignKeys)); err != nil { @@ -2074,35 +1903,11 @@ 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 - } - } - if err := exec("PRAGMA journal_mode = WAL;"); err != nil { C.sqlite3_close_v2(db) return nil, err } - // Locking Mode - // Because the default is NORMAL and this is not changed in this package - // by using the compile time SQLITE_DEFAULT_LOCKING_MODE this PRAGMA can always be executed - if err := exec(fmt.Sprintf("PRAGMA locking_mode = %s;", lockingMode)); err != nil { - C.sqlite3_close_v2(db) - return nil, err - } - - // Query Only - if queryOnly > -1 { - if err := exec(fmt.Sprintf("PRAGMA query_only = %d;", queryOnly)); 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 { @@ -2111,12 +1916,6 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) { } } - // FIXME: see ~/dev/papo/STUFF/napiqlite/src/napiqlite.c - if err := exec("PRAGMA synchronous = EXTRA;"); err != nil { - conn.Close() - return nil, err - } - // Writable Schema if writableSchema > -1 { if err := exec(fmt.Sprintf("PRAGMA writable_schema = %d;", writableSchema)); err != nil { @@ -2125,14 +1924,6 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) { } } - // Cache Size - if cacheSize != nil { - if err := exec(fmt.Sprintf("PRAGMA cache_size = %d;", *cacheSize)); err != nil { - C.sqlite3_close_v2(db) - return nil, err - } - } - if d.ConnectHook != nil { if err := d.ConnectHook(conn); err != nil { conn.Close() |