Skip to content

Commit 3e28ea5

Browse files
authored
fix: explicitly use -list now that sqlite3 defaults to table output (#1029)
the newest sqlite3 CLI release outputs `table` view by default, breaking our parsing expectations. This PR fixes this
2 parents 97ce938 + c466647 commit 3e28ea5

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

internal/cmd/db_create_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func TestGetReservedBytes(t *testing.T) {
230230
tmpDir := t.TempDir()
231231
dbPath := filepath.Join(tmpDir, "test.db")
232232

233-
cmd := exec.Command("sqlite3", dbPath, "CREATE TABLE test (id INTEGER);")
233+
cmd := exec.Command("sqlite3", "-list", dbPath, "CREATE TABLE test (id INTEGER);")
234234
if err := cmd.Run(); err != nil {
235235
t.Fatalf("failed to create test database: %v", err)
236236
}
@@ -255,12 +255,12 @@ func TestValidateReservedBytesAllCiphers(t *testing.T) {
255255
tmpDir := t.TempDir()
256256
dbPath := filepath.Join(tmpDir, "test.db")
257257

258-
cmd := exec.Command("sqlite3", dbPath, "CREATE TABLE test (id INTEGER);")
258+
cmd := exec.Command("sqlite3", "-list", dbPath, "CREATE TABLE test (id INTEGER);")
259259
if err := cmd.Run(); err != nil {
260260
t.Fatalf("failed to create test database: %v", err)
261261
}
262262

263-
cmd = exec.Command("sqlite3", dbPath,
263+
cmd = exec.Command("sqlite3", "-list", dbPath,
264264
fmt.Sprintf(".filectrl reserve_bytes %d", expectedBytes),
265265
"VACUUM;")
266266
if err := cmd.Run(); err != nil {
@@ -300,12 +300,12 @@ func TestCipherReservedBytesCrossValidation(t *testing.T) {
300300
tmpDir := t.TempDir()
301301
dbPath := filepath.Join(tmpDir, "test.db")
302302

303-
cmd := exec.Command("sqlite3", dbPath, "CREATE TABLE test (id INTEGER);")
303+
cmd := exec.Command("sqlite3", "-list", dbPath, "CREATE TABLE test (id INTEGER);")
304304
if err := cmd.Run(); err != nil {
305305
t.Fatalf("failed to create test database: %v", err)
306306
}
307307

308-
cmd = exec.Command("sqlite3", dbPath,
308+
cmd = exec.Command("sqlite3", "-list", dbPath,
309309
fmt.Sprintf(".filectrl reserve_bytes %d", tt.wrongBytes),
310310
"VACUUM;")
311311
if err := cmd.Run(); err != nil {

internal/cmd/group_flag.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func checkIfDump(filename string) (bool, error) {
222222

223223
// getReservedBytes retrieves the current reserved bytes setting from a SQLite database
224224
func getReservedBytes(dbPath string) (int, error) {
225-
output, err := exec.Command("sqlite3", dbPath, ".filectrl reserve_bytes").CombinedOutput()
225+
output, err := exec.Command("sqlite3", "-list", dbPath, ".filectrl reserve_bytes").CombinedOutput()
226226
if err != nil {
227227
return 0, fmt.Errorf("failed to get reserved bytes: %w", err)
228228
}
@@ -295,7 +295,7 @@ func sqliteFileIntegrityChecks(file string, cipher string) error {
295295
if flags.Debug() {
296296
log.Printf("Checking database settings...")
297297
}
298-
output, err := exec.Command("sqlite3", file, ".mode line",
298+
output, err := exec.Command("sqlite3", "-list", file, ".mode line",
299299
"select journal_mode as j, page_size as p, auto_vacuum as a, encoding as e from pragma_journal_mode, pragma_page_size, pragma_auto_vacuum, pragma_encoding;").CombinedOutput()
300300
if err != nil {
301301

@@ -340,7 +340,7 @@ func sqliteFileIntegrityChecks(file string, cipher string) error {
340340
}
341341

342342
func runQuickCheck(file string) error {
343-
cmd := exec.Command("sqlite3", file, "pragma quick_check;")
343+
cmd := exec.Command("sqlite3", "-list", file, "pragma quick_check;")
344344
if err := cmd.Run(); err != nil {
345345
return fmt.Errorf("integrity check failed: %w", err)
346346
}
@@ -405,7 +405,7 @@ func checkSQLiteAvailable() error {
405405
}
406406

407407
func checkSQLiteFile(file string) error {
408-
output, err := exec.Command("sqlite3", file, "pragma quick_check;").CombinedOutput()
408+
output, err := exec.Command("sqlite3", "-list", file, "pragma quick_check;").CombinedOutput()
409409

410410
execErr := &exec.ExitError{}
411411
if errors.As(err, &execErr) && execErr.ExitCode() == 26 {
@@ -428,7 +428,7 @@ func createTempFile() (*os.File, error) {
428428

429429
func dumpSQLiteDatabase(database string, dump *os.File) error {
430430
stdErr := &bytes.Buffer{}
431-
cmd := exec.Command("sqlite3", database, ".dump")
431+
cmd := exec.Command("sqlite3", "-list", database, ".dump")
432432
cmd.Stdout = dump
433433
cmd.Stderr = stdErr
434434

internal/cmd/group_flag_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func createTestDatabase(t *testing.T, sizeBytes int) string {
2222
dbPath := filepath.Join(tmpDir, "test.db")
2323

2424
// Create database with correct settings for Turso
25-
cmd := exec.Command("sqlite3", dbPath,
25+
cmd := exec.Command("sqlite3", "-list", dbPath,
2626
"PRAGMA page_size=4096;",
2727
"PRAGMA journal_mode=WAL;",
2828
"CREATE TABLE data (id INTEGER PRIMARY KEY, blob BLOB);")
@@ -36,7 +36,7 @@ func createTestDatabase(t *testing.T, sizeBytes int) string {
3636
numRows = 1
3737
}
3838
for i := 0; i < numRows; i++ {
39-
cmd = exec.Command("sqlite3", dbPath,
39+
cmd = exec.Command("sqlite3", "-list", dbPath,
4040
fmt.Sprintf("INSERT INTO data (blob) VALUES (randomblob(%d));", rowSize))
4141
require.NoError(t, cmd.Run())
4242
}

0 commit comments

Comments
 (0)