Test files › Source code › schema.sql
Sample SQL file (schema)
A DDL and DML script with constraints, an index, a view, a transaction and dollar-free string literals.
↓ Download schema.sql| Filename | schema.sql |
| Format | SQL |
| Size | 1.0 KB (1,062 bytes) |
| MIME type | application/sql |
| SHA-256 | 412fbe6c0646cda5a0829b7672578ab400a98d1e2a9d166a43a3d1492ac16593 |
What this file catchesSQL splitters that break statements on every semicolon. The semicolons inside string literals and the comment here are the ones that make a naive split produce invalid fragments.
Handle it in code
Each snippet below was run against this exact file with Python 3.14.4 and Node 24.15.0 when this page was built, and the output shown is what it printed.
Python
Splitting a script on every semicolon breaks on semicolons inside strings, comments and triggers. sqlite3.complete_statement knows the grammar, so feed it lines until it says a statement is complete.
import sqlite3
statements, current = [], ""
with open("schema.sql", encoding="utf-8") as f:
for line in f:
current += line
if sqlite3.complete_statement(current):
statements.append(current.strip())
current = ""
db = sqlite3.connect(":memory:", isolation_level=None) # the script manages its own transaction
for s in statements:
db.execute(s)
made = db.execute("SELECT type, name FROM sqlite_master WHERE name NOT LIKE 'sqlite_%' ORDER BY type, name").fetchall()
print(len(statements), "statements, all executed")
print(", ".join(f"{kind} {name}" for kind, name in made))Run against this file, it prints: 8 statements, all executed
index idx_users_email, table orders, table users, view order_totals
Related guides and tools
Download & verify
curl -fsSL -o "schema.sql" "https://files.hexaqa.com/code/schema.sql"
curl -fsSL "https://files.hexaqa.com/code/schema.sql" | sha256sum
# expect: 412fbe6c0646cda5a0829b7672578ab400a98d1e2a9d166a43a3d1492ac16593