aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/golite.go219
-rw-r--r--tests/golite.go288
2 files changed, 41 insertions, 466 deletions
diff --git a/src/golite.go b/src/golite.go
index be02de6..62bbeb5 100644
--- a/src/golite.go
+++ b/src/golite.go
@@ -1128,7 +1128,6 @@ type SQLiteConn struct {
mu sync.Mutex
db *C.sqlite3
loc *time.Location
- txlock string
funcs []*functionInfo
aggregators []*aggInfo
}
@@ -1623,7 +1622,7 @@ func (c *SQLiteConn) Begin() (driver.Tx, error) {
}
func (c *SQLiteConn) begin(ctx context.Context) (driver.Tx, error) {
- if _, err := c.exec(ctx, c.txlock, nil); err != nil {
+ if _, err := c.exec(ctx, "BEGIN", nil); err != nil {
return nil, err
}
return &SQLiteTx{c}, nil
@@ -1646,15 +1645,6 @@ func (c *SQLiteConn) begin(ctx context.Context) (driver.Tx, error) {
// :memory:
// file::memory:
//
-// mode
-// Access mode of the database.
-// https://www.sqlite.org/c3ref/open.html
-// Values:
-// - ro
-// - rw
-// - rwc
-// - memory
-//
// cache
// SQLite Shared-Cache Mode
// https://www.sqlite.org/sharedcache.html
@@ -1662,61 +1652,13 @@ func (c *SQLiteConn) begin(ctx context.Context) (driver.Tx, error) {
// - shared
// - private
//
-// immutable=Boolean
-// The immutable parameter is a boolean query parameter that indicates
-// that the database file is stored on read-only media. When immutable is set,
-// SQLite assumes that the database file cannot be changed,
-// even by a process with higher privilege,
-// and so the database is opened read-only and all locking and change detection is disabled.
-// Caution: Setting the immutable property on a database file that
-// does in fact change can result in incorrect query results and/or SQLITE_CORRUPT errors.
-//
// go-sqlite3 adds the following query parameters to those used by SQLite:
//
// _loc=XXX
// Specify location of time format. It's possible to specify "auto".
-//
-// _mutex=XXX
-// Specify mutex mode. XXX can be "no", "full".
-//
-// _txlock=XXX
-// Specify locking behavior for transactions. XXX can be "immediate",
-// "deferred", "exclusive".
-//
-// _busy_timeout=XXX"| _timeout=XXX
-// Specify value for sqlite3_busy_timeout.
-//
-// _defer_foreign_keys=Boolean | _defer_fk=Boolean
-// Defer Foreign Keys until outermost transaction is committed.
-//
-// _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.
-//
-// _writable_schema=Boolean
-// When this pragma is on, the SQLITE_MASTER tables in which database
-// can be changed using ordinary UPDATE, INSERT, and DELETE statements.
-// Warning: misuse of this pragma can easily result in a corrupt database file.
func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
- if C.sqlite3_threadsafe() == 0 {
- return nil, errors.New("sqlite library was not compiled for thread-safe operation")
- }
-
- var pkey string
-
// Options
var loc *time.Location
- txlock := "BEGIN"
-
- // PRAGMA's
- busyTimeout := 5000
- deferForeignKeys := -1
- recursiveTriggers := -1
- writableSchema := -1
- vfsName := ""
pos := strings.IndexRune(dsn, '?')
if pos >= 1 {
@@ -1738,102 +1680,6 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
}
}
- // _txlock
- if val := params.Get("_txlock"); val != "" {
- switch strings.ToLower(val) {
- case "immediate":
- txlock = "BEGIN IMMEDIATE"
- case "exclusive":
- txlock = "BEGIN EXCLUSIVE"
- case "deferred":
- txlock = "BEGIN"
- default:
- return nil, fmt.Errorf("Invalid _txlock: %v", val)
- }
- }
-
- // Busy Timeout (_busy_timeout)
- //
- // https://www.sqlite.org/pragma.html#pragma_busy_timeout
- //
- pkey = "" // Reset pkey
- if _, ok := params["_busy_timeout"]; ok {
- pkey = "_busy_timeout"
- }
- if _, ok := params["_timeout"]; ok {
- pkey = "_timeout"
- }
- if val := params.Get(pkey); val != "" {
- iv, err := strconv.ParseInt(val, 10, 64)
- if err != nil {
- return nil, fmt.Errorf("Invalid _busy_timeout: %v: %v", val, err)
- }
- busyTimeout = int(iv)
- }
-
- // Defer Foreign Keys (_defer_foreign_keys | _defer_fk)
- //
- // https://www.sqlite.org/pragma.html#pragma_defer_foreign_keys
- //
- pkey = "" // Reset pkey
- if _, ok := params["_defer_foreign_keys"]; ok {
- pkey = "_defer_foreign_keys"
- }
- if _, ok := params["_defer_fk"]; ok {
- pkey = "_defer_fk"
- }
- if val := params.Get(pkey); val != "" {
- switch strings.ToLower(val) {
- case "0", "no", "false", "off":
- deferForeignKeys = 0
- case "1", "yes", "true", "on":
- deferForeignKeys = 1
- default:
- return nil, fmt.Errorf("Invalid _defer_foreign_keys: %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
- //
- pkey = "" // Reset pkey
- if _, ok := params["_recursive_triggers"]; ok {
- pkey = "_recursive_triggers"
- }
- if _, ok := params["_rt"]; ok {
- pkey = "_rt"
- }
- if val := params.Get(pkey); val != "" {
- switch strings.ToLower(val) {
- case "0", "no", "false", "off":
- recursiveTriggers = 0
- case "1", "yes", "true", "on":
- recursiveTriggers = 1
- default:
- return nil, fmt.Errorf("Invalid _recursive_triggers: %v, expecting boolean value of '0 1 false true no yes off on'", val)
- }
- }
-
- // Writable Schema (_writeable_schema)
- //
- // https://www.sqlite.org/pragma.html#pragma_writeable_schema
- //
- if val := params.Get("_writable_schema"); val != "" {
- switch strings.ToLower(val) {
- case "0", "no", "false", "off":
- writableSchema = 0
- case "1", "yes", "true", "on":
- writableSchema = 1
- default:
- return nil, fmt.Errorf("Invalid _writable_schema: %v, expecting boolean value of '0 1 false true no yes off on'", val)
- }
- }
-
- if val := params.Get("vfs"); val != "" {
- vfsName = val
- }
-
if !strings.HasPrefix(dsn, "file:") {
dsn = dsn[:pos]
}
@@ -1842,18 +1688,13 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
var db *C.sqlite3
name := C.CString(dsn)
defer C.free(unsafe.Pointer(name))
- var vfs *C.char
- if vfsName != "" {
- vfs = C.CString(vfsName)
- defer C.free(unsafe.Pointer(vfs))
- }
var openFlags C.int =
- C.SQLITE_OPEN_READWRITE |
+ C.SQLITE_OPEN_READWRITE | // FIXME: fails if RO FS?
C.SQLITE_OPEN_CREATE |
C.SQLITE_OPEN_URI |
C.SQLITE_OPEN_FULLMUTEX
- rv := C.sqlite3_open_v2(name, &db, openFlags, vfs)
+ rv := C.sqlite3_open_v2(name, &db, openFlags, nil)
if rv != 0 {
// Save off the error _before_ closing the database.
// This is safe even if db is nil.
@@ -1867,54 +1708,21 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
return nil, errors.New("sqlite succeeded without returning a database")
}
- exec := func(s string) error {
- cs := C.CString(s)
- rv := C.sqlite3_exec(db, cs, nil, nil, nil)
- C.free(unsafe.Pointer(cs))
- if rv != C.SQLITE_OK {
- return lastError(db)
- }
- return nil
- }
-
- // FIXME: these should be compiled into SQLite
- // Busy timeout
- if err := exec(fmt.Sprintf("PRAGMA busy_timeout = %d;", busyTimeout)); err != nil {
+ const setup = `
+ PRAGMA journal_mode = WAL;
+ PRAGMA busy_timeout = 10000;
+ `
+ setupCStr := C.CString(setup)
+ defer C.free(unsafe.Pointer(setupCStr))
+ rv = C.sqlite3_exec(db, setupCStr, nil, nil, nil)
+ if rv != C.SQLITE_OK {
+ err := lastError(db)
C.sqlite3_close_v2(db)
return nil, err
}
// Create connection to SQLite
- conn := &SQLiteConn{db: db, loc: loc, txlock: txlock}
-
- // Defer Foreign Keys
- if deferForeignKeys > -1 {
- if err := exec(fmt.Sprintf("PRAGMA defer_foreign_keys = %d;", deferForeignKeys)); 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
- }
-
- // Recursive Triggers
- if recursiveTriggers > -1 {
- if err := exec(fmt.Sprintf("PRAGMA recursive_triggers = %d;", recursiveTriggers)); err != nil {
- C.sqlite3_close_v2(db)
- return nil, err
- }
- }
-
- // Writable Schema
- if writableSchema > -1 {
- if err := exec(fmt.Sprintf("PRAGMA writable_schema = %d;", writableSchema)); err != nil {
- C.sqlite3_close_v2(db)
- return nil, err
- }
- }
+ conn := &SQLiteConn{db: db, loc: loc}
if d.ConnectHook != nil {
if err := d.ConnectHook(conn); err != nil {
@@ -1922,6 +1730,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
return nil, err
}
}
+
runtime.SetFinalizer(conn, (*SQLiteConn).Close)
return conn, nil
}
diff --git a/tests/golite.go b/tests/golite.go
index 1dc01c4..3f09878 100644
--- a/tests/golite.go
+++ b/tests/golite.go
@@ -474,11 +474,6 @@ func TestExtendedErrorCodes_ForeignKey(t *testing.T) {
}
defer db.Close()
- _, err = db.Exec("PRAGMA foreign_keys=ON;")
- if err != nil {
- t.Errorf("PRAGMA foreign_keys=ON: %v", err)
- }
-
_, err = db.Exec(`CREATE TABLE Foo (
id INTEGER PRIMARY KEY AUTOINCREMENT,
value INTEGER NOT NULL,
@@ -519,11 +514,6 @@ func TestExtendedErrorCodes_NotNull(t *testing.T) {
}
defer db.Close()
- _, err = db.Exec("PRAGMA foreign_keys=ON;")
- if err != nil {
- t.Errorf("PRAGMA foreign_keys=ON: %v", err)
- }
-
_, err = db.Exec(`CREATE TABLE Foo (
id INTEGER PRIMARY KEY AUTOINCREMENT,
value INTEGER NOT NULL,
@@ -574,11 +564,6 @@ func TestExtendedErrorCodes_Unique(t *testing.T) {
}
defer db.Close()
- _, err = db.Exec("PRAGMA foreign_keys=ON;")
- if err != nil {
- t.Errorf("PRAGMA foreign_keys=ON: %v", err)
- }
-
_, err = db.Exec(`CREATE TABLE Foo (
id INTEGER PRIMARY KEY AUTOINCREMENT,
value INTEGER NOT NULL,
@@ -1022,17 +1007,17 @@ func doTestOpenContext(t *testing.T, url string) (string, error) {
}
}()
- ctx, cancel := context.WithTimeout(context.Background(), 55*time.Second)
+ ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
err = db.PingContext(ctx)
cancel()
if err != nil {
return "ping error:", err
}
- ctx, cancel = context.WithTimeout(context.Background(), 55*time.Second)
+ ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
_, err = db.ExecContext(ctx, "drop table foo")
cancel()
- ctx, cancel = context.WithTimeout(context.Background(), 55*time.Second)
+ ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
_, err = db.ExecContext(ctx, "create table foo (id integer)")
cancel()
if err != nil {
@@ -1042,70 +1027,35 @@ func doTestOpenContext(t *testing.T, url string) (string, error) {
return "", nil
}
-func TestOpenContext(t *testing.T) {
- cases := map[string]bool{
- "file:openctx1?mode=memory&cache=shared": true,
- "file:openctx2?mode=memory&cache=shared&_txlock=immediate": true,
- "file:openctx3?mode=memory&cache=shared&_txlock=deferred": true,
- "file:openctx4?mode=memory&cache=shared&_txlock=exclusive": true,
- "file:openctx5?mode=memory&cache=shared&_txlock=bogus": false,
- }
- for option, expectedPass := range cases {
- result, err := doTestOpenContext(t, option)
- if result == "" {
- if !expectedPass {
- errmsg := fmt.Sprintf("_txlock error not caught at dbOpen with option: %s", option)
- t.Fatal(errmsg)
- }
- } else if expectedPass {
- if err == nil {
- t.Fatal(result)
- } else {
- t.Fatal(result, err)
- }
- }
- }
-}
-
func TestFileCopyTruncate(t *testing.T) {
var err error
tempFilename := TempFilename(t)
-
- defer func() {
- err = os.Remove(tempFilename)
- if err != nil {
- t.Error("temp file remove error:", err)
- }
- }()
+ defer os.Remove(tempFilename)
db, err := sql.Open("golite", tempFilename)
if err != nil {
t.Fatal("open error:", err)
}
+ defer db.Close()
- defer func() {
- err = db.Close()
- if err != nil {
- t.Error("db close error:", err)
- }
- }()
-
+ if true {
_, err = db.Exec("PRAGMA journal_mode = delete;")
if err != nil {
t.Fatal("journal_mode delete:", err)
}
+ }
- ctx, cancel := context.WithTimeout(context.Background(), 55*time.Second)
+ ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
err = db.PingContext(ctx)
cancel()
if err != nil {
t.Fatal("ping error:", err)
}
- ctx, cancel = context.WithTimeout(context.Background(), 55*time.Second)
+ ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
_, err = db.ExecContext(ctx, "drop table foo")
cancel()
- ctx, cancel = context.WithTimeout(context.Background(), 55*time.Second)
+ ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
_, err = db.ExecContext(ctx, "create table foo (id integer)")
cancel()
if err != nil {
@@ -1120,17 +1070,12 @@ func TestFileCopyTruncate(t *testing.T) {
}
var f *os.File
- f, err = os.Create(tempFilename + "-db-copy")
+ copyFilename := tempFilename + "-db-copy"
+ f, err = os.Create(copyFilename)
if err != nil {
t.Fatal("create file error:", err)
}
-
- defer func() {
- err = os.Remove(tempFilename + "-db-copy")
- if err != nil {
- t.Error("temp file moved remove error:", err)
- }
- }()
+ defer os.Remove(copyFilename)
_, err = f.Write(data)
if err != nil {
@@ -1153,21 +1098,21 @@ func TestFileCopyTruncate(t *testing.T) {
}
// test db after file truncate
- ctx, cancel = context.WithTimeout(context.Background(), 55*time.Second)
+ ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
err = db.PingContext(ctx)
cancel()
if err != nil {
t.Fatal("ping error:", err)
}
- ctx, cancel = context.WithTimeout(context.Background(), 55*time.Second)
+ ctx, cancel = context.WithTimeout(context.Background(), 5*time.Millisecond)
_, err = db.ExecContext(ctx, "drop table foo")
cancel()
if err == nil {
t.Fatal("drop table no error")
}
- ctx, cancel = context.WithTimeout(context.Background(), 55*time.Second)
+ ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
_, err = db.ExecContext(ctx, "create table foo (id integer)")
cancel()
if err != nil {
@@ -1180,33 +1125,27 @@ func TestFileCopyTruncate(t *testing.T) {
}
// test copied file
- db, err = sql.Open("golite", tempFilename+"-db-copy")
+ db, err = sql.Open("golite", copyFilename)
if err != nil {
t.Fatal("open error:", err)
}
+ defer db.Close()
- defer func() {
- err = db.Close()
- if err != nil {
- t.Error("db close error:", err)
- }
- }()
-
- ctx, cancel = context.WithTimeout(context.Background(), 55*time.Second)
+ ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
err = db.PingContext(ctx)
cancel()
if err != nil {
t.Fatal("ping error:", err)
}
- ctx, cancel = context.WithTimeout(context.Background(), 55*time.Second)
+ ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
_, err = db.ExecContext(ctx, "drop table foo")
cancel()
if err != nil {
t.Fatal("drop table error:", err)
}
- ctx, cancel = context.WithTimeout(context.Background(), 55*time.Second)
+ ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
_, err = db.ExecContext(ctx, "create table foo (id integer)")
cancel()
if err != nil {
@@ -1392,113 +1331,6 @@ type preUpdateHookDataForTest struct {
newRow []any
}
-/*
-func TestPreUpdateHook(t *testing.T) {
- var events []preUpdateHookDataForTest
-
- sql.Register("sqlite3_PreUpdateHook", &SQLiteDriver{
- ConnectHook: func(conn *SQLiteConn) error {
- conn.RegisterPreUpdateHook(func(data SQLitePreUpdateData) {
- eval := -1
- oldRow := []any{eval}
- if data.Op != SQLITE_INSERT {
- err := data.Old(oldRow...)
- if err != nil {
- t.Fatalf("Unexpected error calling SQLitePreUpdateData.Old: %v", err)
- }
- }
-
- eval2 := -1
- newRow := []any{eval2}
- if data.Op != SQLITE_DELETE {
- err := data.New(newRow...)
- if err != nil {
- t.Fatalf("Unexpected error calling SQLitePreUpdateData.New: %v", err)
- }
- }
-
- // tests dest bound checks in loop
- var tooSmallRow []any
- if data.Op != SQLITE_INSERT {
- err := data.Old(tooSmallRow...)
- if err != nil {
- t.Fatalf("Unexpected error calling SQLitePreUpdateData.Old: %v", err)
- }
- if len(tooSmallRow) != 0 {
- t.Errorf("Expected tooSmallRow to be empty, got: %v", tooSmallRow)
- }
- }
-
- events = append(events, preUpdateHookDataForTest{
- databaseName: data.DatabaseName,
- tableName: data.TableName,
- count: data.Count(),
- op: data.Op,
- oldRow: oldRow,
- newRow: newRow,
- })
- })
- return nil
- },
- })
-
- db, err := sql.Open("sqlite3_PreUpdateHook", ":memory:")
- if err != nil {
- t.Fatal("Failed to open database:", err)
- }
- defer db.Close()
-
- statements := []string{
- "create table foo (id integer primary key)",
- "insert into foo values (9)",
- "update foo set id = 99 where id = 9",
- "delete from foo where id = 99",
- }
- for _, statement := range statements {
- _, err = db.Exec(statement)
- if err != nil {
- t.Fatalf("Unable to prepare test data [%v]: %v", statement, err)
- }
- }
-
- if len(events) != 3 {
- t.Errorf("Events should be 3 entries, got: %d", len(events))
- }
-
- if events[0].op != SQLITE_INSERT {
- t.Errorf("Op isn't as expected: %v", events[0].op)
- }
-
- if events[1].op != SQLITE_UPDATE {
- t.Errorf("Op isn't as expected: %v", events[1].op)
- }
-
- if events[1].count != 1 {
- t.Errorf("Expected event row 1 to have 1 column, had: %v", events[1].count)
- }
-
- newRow_0_0 := events[0].newRow[0].(int64)
- if newRow_0_0 != 9 {
- t.Errorf("Expected event row 0 new column 0 to be == 9, got: %v", newRow_0_0)
- }
-
- oldRow_1_0 := events[1].oldRow[0].(int64)
- if oldRow_1_0 != 9 {
- t.Errorf("Expected event row 1 old column 0 to be == 9, got: %v", oldRow_1_0)
- }
-
- newRow_1_0 := events[1].newRow[0].(int64)
- if newRow_1_0 != 99 {
- t.Errorf("Expected event row 1 new column 0 to be == 99, got: %v", newRow_1_0)
- }
-
- oldRow_2_0 := events[2].oldRow[0].(int64)
- if oldRow_2_0 != 99 {
- t.Errorf("Expected event row 1 new column 0 to be == 99, got: %v", oldRow_2_0)
- }
-}
-*/
-
func TestSerializeDeserialize(t *testing.T) {
// Connect to the source database.
srcDb, err := sql.Open(driverName, "file:src?mode=memory&cache=shared")
@@ -1527,7 +1359,7 @@ func TestSerializeDeserialize(t *testing.T) {
if err != nil {
t.Fatal("Failed to create table in source database:", err)
}
- _, err = srcDb.Exec(`INSERT INTO foo(name) VALUES("alice")`)
+ _, err = srcDb.Exec(`INSERT INTO foo(name) VALUES('alice')`)
if err != nil {
t.Fatal("Failed to insert data into source database", err)
}
@@ -1587,7 +1419,7 @@ func TestSerializeDeserialize(t *testing.T) {
func TestUnlockNotify(t *testing.T) {
tempFilename := TempFilename(t)
defer os.Remove(tempFilename)
- dsn := fmt.Sprintf("file:%s?cache=shared&mode=memory&_busy_timeout=%d", tempFilename, 500)
+ dsn := fmt.Sprintf("file:%s?cache=shared&mode=memory", tempFilename)
db, err := sql.Open("golite", dsn)
if err != nil {
t.Fatal("Failed to open database:", err)
@@ -1647,7 +1479,7 @@ func TestUnlockNotify(t *testing.T) {
func TestUnlockNotifyMany(t *testing.T) {
tempFilename := TempFilename(t)
defer os.Remove(tempFilename)
- dsn := fmt.Sprintf("file:%s?cache=shared&mode=memory&_busy_timeout=%d", tempFilename, 500)
+ dsn := fmt.Sprintf("file:%s?cache=shared&mode=memory", tempFilename)
db, err := sql.Open("golite", dsn)
if err != nil {
t.Fatal("Failed to open database:", err)
@@ -1713,7 +1545,7 @@ func TestUnlockNotifyMany(t *testing.T) {
func TestUnlockNotifyDeadlock(t *testing.T) {
tempFilename := TempFilename(t)
defer os.Remove(tempFilename)
- dsn := fmt.Sprintf("file:%s?cache=shared&mode=memory&_busy_timeout=%d", tempFilename, 500)
+ dsn := fmt.Sprintf("file:%s?cache=shared&mode=memory", tempFilename)
db, err := sql.Open("golite", dsn)
if err != nil {
t.Fatal("Failed to open database:", err)
@@ -1833,31 +1665,6 @@ func doTestOpen(t *testing.T, url string) (string, error) {
return "", nil
}
-func TestOpen(t *testing.T) {
- cases := map[string]bool{
- "file:open1?mode=memory&cache=shared": true,
- "file:open1?mode=memory&cache=shared&_txlock=immediate": true,
- "file:open1?mode=memory&cache=shared&_txlock=deferred": true,
- "file:open1?mode=memory&cache=shared&_txlock=exclusive": true,
- "file:open1?mode=memory&cache=shared&_txlock=bogus": false,
- }
- for option, expectedPass := range cases {
- result, err := doTestOpen(t, option)
- if result == "" {
- if !expectedPass {
- errmsg := fmt.Sprintf("_txlock error not caught at dbOpen with option: %s", option)
- t.Fatal(errmsg)
- }
- } else if expectedPass {
- if err == nil {
- t.Fatal(result)
- } else {
- t.Fatal(result, err)
- }
- }
- }
-}
-
func TestOpenWithVFS(t *testing.T) {
{
uri := fmt.Sprintf("file:%s?mode=memory&vfs=hello", t.Name())
@@ -2004,35 +1811,6 @@ func TestDeferredForeignKey(t *testing.T) {
os.Remove(fname)
}
-func TestRecursiveTriggers(t *testing.T) {
- cases := map[string]bool{
- "?_recursive_triggers=1": true,
- "?_recursive_triggers=0": false,
- }
- for option, want := range cases {
- fname := TempFilename(t)
- uri := "file:" + fname + option + "&mode=memory"
- db, err := sql.Open("golite", uri)
- if err != nil {
- os.Remove(fname)
- t.Errorf("sql.Open(\"sqlite3\", %q): %v", uri, err)
- continue
- }
- var enabled bool
- err = db.QueryRow("PRAGMA recursive_triggers;").Scan(&enabled)
- db.Close()
- os.Remove(fname)
- if err != nil {
- t.Errorf("query recursive_triggers for %s: %v", uri, err)
- continue
- }
- if enabled != want {
- t.Errorf("\"PRAGMA recursive_triggers;\" for %q = %t; want %t", uri, enabled, want)
- continue
- }
- }
-}
-
func TestClose(t *testing.T) {
db, err := sql.Open("golite", ":memory:")
if err != nil {
@@ -2630,12 +2408,6 @@ func TestWAL(t *testing.T) {
}
defer db.Close()
- if _, err = db.Exec("PRAGMA journal_mode=WAL;"); err != nil {
- t.Fatal("Failed to Exec PRAGMA journal_mode:", err)
- }
- if _, err = db.Exec("PRAGMA locking_mode=EXCLUSIVE;"); err != nil {
- t.Fatal("Failed to Exec PRAGMA locking_mode:", err)
- }
if _, err = db.Exec("CREATE TABLE test (id SERIAL, user TEXT NOT NULL, name TEXT NOT NULL);"); err != nil {
t.Fatal("Failed to Exec CREATE TABLE:", err)
}
@@ -3371,10 +3143,7 @@ func TestSetFileControlInt(t *testing.T) {
}
defer db.Close()
- // Set to WAL mode & write a page.
- if _, err := db.Exec(`PRAGMA journal_mode = wal`); err != nil {
- t.Fatal("Failed to set journal mode:", err)
- } else if _, err := db.Exec(`CREATE TABLE t (x)`); err != nil {
+ if _, err := db.Exec(`CREATE TABLE t (x)`); err != nil {
t.Fatal("Failed to create table:", err)
}
if err := db.Close(); err != nil {
@@ -3544,7 +3313,7 @@ var tdb *TestDB
func initializeTestDB(t testing.TB) {
tempFilename := TempFilename(t)
- d, err := sql.Open("golite", tempFilename+"?_busy_timeout=99999&mode=memory&cache=shared")
+ d, err := sql.Open("golite", tempFilename+"?mode=memory&cache=shared")
if err != nil {
os.Remove(tempFilename)
t.Fatal(err)
@@ -3862,19 +3631,16 @@ func MainTest() {
{ "TestQueryRowContextCancel", TestQueryRowContextCancel },
{ "TestQueryRowContextCancelParallel", TestQueryRowContextCancelParallel },
{ "TestExecCancel", TestExecCancel },
- { "TestOpenContext", TestOpenContext },
{ "TestFileCopyTruncate", TestFileCopyTruncate },
{ "TestColumnTableName", TestColumnTableName },
{ "TestFTS3", TestFTS3 },
{ "TestFTS4", TestFTS4 },
{ "TestMathFunctions", TestMathFunctions },
{ "TestSerializeDeserialize", TestSerializeDeserialize },
- { "TestOpen", TestOpen },
{ "TestOpenWithVFS", TestOpenWithVFS },
{ "TestOpenNoCreate", TestOpenNoCreate },
{ "TestReadonly", TestReadonly },
{ "TestDeferredForeignKey", TestDeferredForeignKey },
- { "TestRecursiveTriggers", TestRecursiveTriggers },
{ "TestClose", TestClose },
{ "TestInsert", TestInsert },
{ "TestUpsert", TestUpsert },