db.iterdump() method uses sqlite-dump if available

This commit is contained in:
Simon Willison 2023-06-25 15:29:00 -07:00
commit 31bde41baf
8 changed files with 55 additions and 8 deletions

View file

@ -135,7 +135,8 @@ def test_analyze_column(db_to_analyze, column, extra_kwargs, expected):
def db_to_analyze_path(db_to_analyze, tmpdir):
path = str(tmpdir / "test.db")
db = sqlite3.connect(path)
db.executescript("\n".join(db_to_analyze.conn.iterdump()))
sql = "\n".join(db_to_analyze.iterdump())
db.executescript(sql)
return path

View file

@ -164,9 +164,9 @@ def test_memory_dump(extra_args):
input="id,name\n1,Cleo\n2,Bants",
)
assert result.exit_code == 0
assert result.output.strip() == (
expected = (
"BEGIN TRANSACTION;\n"
'CREATE TABLE "stdin" (\n'
'CREATE TABLE IF NOT EXISTS "stdin" (\n'
" [id] INTEGER,\n"
" [name] TEXT\n"
");\n"
@ -176,6 +176,9 @@ def test_memory_dump(extra_args):
"CREATE VIEW t AS select * from [stdin];\n"
"COMMIT;"
)
# Using sqlite-dump it won't have IF NOT EXISTS
expected_alternative = expected.replace("IF NOT EXISTS ", "")
assert result.output.strip() in (expected, expected_alternative)
@pytest.mark.parametrize("extra_args", ([], ["select 1"]))