Skip to content

fix: validate --csv-table-name and fix hex-encoded error message#1025

Open
standard-librarian wants to merge 1 commit into
tursodatabase:mainfrom
standard-librarian:fix/csv-table-name-validation
Open

fix: validate --csv-table-name and fix hex-encoded error message#1025
standard-librarian wants to merge 1 commit into
tursodatabase:mainfrom
standard-librarian:fix/csv-table-name-validation

Conversation

@standard-librarian
Copy link
Copy Markdown

@standard-librarian standard-librarian commented Mar 20, 2026

Summary

  • Adds upfront validation that --csv-table-name is a valid unquoted SQL identifier (must start with a letter or underscore, contain only letters, digits, and underscores). This prevents silent data loss on newer sqlite3 (≥3.37) where a hyphenated name is accepted but inaccessible without quoting in every query.
  • Fixes the stderr format verb in importCSVIntoSQLite from %x (hex) to %s so sqlite3 error messages are human-readable on older sqlite3 versions (≤3.36) that reject the name outright.

Test plan

  • go test ./internal/cmd/... -run TestValidateCSVTableName — 9 table-driven cases covering valid names, hyphen, digit prefix, empty string, spaces, and dots
  • turso db create --from-csv file.csv --csv-table-name some-table → clear error: invalid --csv-table-name "some-table": must start with a letter or underscore...
  • turso db create --from-csv file.csv --csv-table-name some_table → succeeds as before

Closes #810

Adds upfront validation that --csv-table-name is a valid unquoted SQL
identifier (starts with a letter or underscore, contains only letters,
digits, and underscores). This prevents silent data loss on newer sqlite3
(≥3.37) and cryptic hex error output on older versions.

Also fixes the stderr format verb in importCSVIntoSQLite from %x (hex)
to %s so sqlite3 error messages are human-readable.

Closes tursodatabase#810
@standard-librarian
Copy link
Copy Markdown
Author

Hey @penberg, wdyt about this one? Adds upfront validation for --csv-table-name to prevent silent data loss with hyphenated names on newer sqlite3 (≥3.37), and fixes the %x → %s format verb so error messages are readable on older versions too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Better error handling in csv table name

1 participant