diff options
author | EuAndreh <eu@euandre.org> | 2024-10-30 06:54:34 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2024-10-30 06:54:34 -0300 |
commit | b2e1a5ccae8e0f1f1c9ce00c0f5434924251e5ff (patch) | |
tree | 97f40468aab2750e78f4f2c50ed225b06e96a820 | |
parent | .gitignore: Normalize according to other go projects (diff) | |
download | golite-b2e1a5ccae8e0f1f1c9ce00c0f5434924251e5ff.tar.gz golite-b2e1a5ccae8e0f1f1c9ce00c0f5434924251e5ff.tar.xz |
src/golite.go: Use IMMEDIATE transaction for db.Begin()
-rw-r--r-- | src/golite.go | 2 | ||||
-rw-r--r-- | tests/golite.go | 10 |
2 files changed, 9 insertions, 3 deletions
diff --git a/src/golite.go b/src/golite.go index da95c18..7153766 100644 --- a/src/golite.go +++ b/src/golite.go @@ -1623,7 +1623,7 @@ func (c *SQLiteConn) Begin() (driver.Tx, error) { } func (c *SQLiteConn) begin(ctx context.Context) (driver.Tx, error) { - if _, err := c.exec(ctx, "BEGIN", nil); err != nil { + if _, err := c.exec(ctx, "BEGIN IMMEDIATE", nil); err != nil { return nil, err } return &SQLiteTx{c}, nil diff --git a/tests/golite.go b/tests/golite.go index c51c1f3..2c7fe6c 100644 --- a/tests/golite.go +++ b/tests/golite.go @@ -54,6 +54,7 @@ func testBackup(t *testing.T, testRowCount int, usePerPageSteps bool) { t.Fatal("Failed to open the source database:", err) } defer srcDb.Close() + err = srcDb.Ping() if err != nil { t.Fatal("Failed to connect to the source database:", err) @@ -66,6 +67,7 @@ func testBackup(t *testing.T, testRowCount int, usePerPageSteps bool) { t.Fatal("Failed to open the destination database:", err) } defer destDb.Close() + err = destDb.Ping() if err != nil { t.Fatal("Failed to connect to the destination database:", err) @@ -75,10 +77,12 @@ func testBackup(t *testing.T, testRowCount int, usePerPageSteps bool) { if len(driverConns) != 2 { t.Fatalf("Expected 2 driver connections, but found %v.", len(driverConns)) } + srcDbDriverConn := driverConns[0] if srcDbDriverConn == nil { t.Fatal("The source database driver connection is nil.") } + destDbDriverConn := driverConns[1] if destDbDriverConn == nil { t.Fatal("The destination database driver connection is nil.") @@ -94,13 +98,15 @@ func testBackup(t *testing.T, testRowCount int, usePerPageSteps bool) { if err != nil { t.Fatal("Failed to begin a transaction when populating the source database:", err) } - _, err = srcDb.Exec("CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT)") + + _, err = tx.Exec("CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT)") if err != nil { tx.Rollback() t.Fatal("Failed to create the source database \"test\" table:", err) } + for id := 0; id < testRowCount; id++ { - _, err = srcDb.Exec("INSERT INTO test (id, value) VALUES (?, ?)", id, generateTestData(id)) + _, err = tx.Exec("INSERT INTO test (id, value) VALUES (?, ?)", id, generateTestData(id)) if err != nil { tx.Rollback() t.Fatal("Failed to insert a row into the source database \"test\" table:", err) |