CSV import fixes

- Fix not being able to create table while importing
    * The behavior now aligns with SQLite so that if the table already
      exists, all the rows are treated as data. If the table doesn't exist,
      the first row is treated as the header from which column names for the
      new table are populated.
- Insert in batches instead of one at a time
This commit is contained in:
Jussi Saurio
2025-07-15 13:18:30 +03:00
parent beaf393476
commit cc47bfba02
4 changed files with 280 additions and 72 deletions

View File

@@ -228,6 +228,30 @@ def test_import_csv_skip():
shell.quit()
def test_import_csv_create_table_from_header():
shell = TestTursoShell()
shell.run_test("open-memory", ".open :memory:", "")
# Import CSV with header - should create table automatically
shell.run_test(
"import-csv-create-table",
".import --csv ./testing/test_files/test_w_header.csv auto_table",
"",
)
# Verify table was created with correct column names
shell.run_test(
"verify-auto-table-schema",
".schema auto_table",
"CREATE TABLE auto_table (id, interesting_number, interesting_string);",
)
# Verify data was imported correctly (header row excluded)
shell.run_test(
"verify-auto-table-data",
"select * from auto_table;",
"1|2.0|String'1\n3|4.0|String2",
)
shell.quit()
def test_table_patterns():
shell = TestTursoShell()
shell.run_test("tables-pattern", ".tables us%", "users")
@@ -304,6 +328,7 @@ def main():
test_import_csv()
test_import_csv_verbose()
test_import_csv_skip()
test_import_csv_create_table_from_header()
test_table_patterns()
test_update_with_limit()
test_update_with_limit_and_offset()