mirror of
https://github.com/hanzoai/dbx.git
synced 2026-10-30 18:40:28 +00:00
DefaultSQLiteConnect wrote its pragmas by hand in modernc's `_pragma=NAME(VALUE)` form. This package names the driver "sqlite" and imports none, so it inherits whichever the consumer registered — and the cgo backend does not recognise that spelling and drops it silently, opening with journal_mode `delete` and foreign keys off while the DSN asked for WAL and ON. sqlite.PragmaDSN emits the form the linked backend reads. sync_test.go registered modernc directly, so the test binary held two drivers claiming the name "sqlite" and died at init before any test ran. It opens the same door the package does now. The new test opens a real file and asks the database what it got: the string is what differs between backends, so a string assertion would pass on the build that ignores it.
33 lines
968 B
Go
33 lines
968 B
Go
package dbx
|
|
|
|
import (
|
|
"database/sql"
|
|
"path/filepath"
|
|
"testing")
|
|
|
|
// TestSQLiteDSNAppliesThePragmas opens a real file and asks the database what it
|
|
// got. The DSN string is exactly what differs between the two backends — each
|
|
// ignores the other's spelling — so asserting on the string would pass on the
|
|
// build that ignores it.
|
|
func TestSQLiteDSNAppliesThePragmas(t *testing.T) {
|
|
db, err := sql.Open("sqlite", sqliteDSN(filepath.Join(t.TempDir(), "t.db")))
|
|
if err != nil {
|
|
t.Fatalf("open: %v", err)
|
|
}
|
|
defer func() { _ = db.Close() }()
|
|
|
|
for _, c := range []struct{ pragma, want string }{
|
|
{"journal_mode", "wal"},
|
|
{"foreign_keys", "1"},
|
|
{"busy_timeout", "10000"},
|
|
} {
|
|
var got string
|
|
if err := db.QueryRow("PRAGMA " + c.pragma).Scan(&got); err != nil {
|
|
t.Fatalf("PRAGMA %s: %v", c.pragma, err)
|
|
}
|
|
if got != c.want {
|
|
t.Errorf("%s = %q, want %q — the DSN asked for it and the backend did not take it", c.pragma, got, c.want)
|
|
}
|
|
}
|
|
}
|