db_execute_file()
Run every statement in a .sql file, in order.
Statements end at a ; outside quotes and comments (and PostgreSQL $$ quotes).
SQLite trigger bodies stay whole. SQL Server files are split into batches at lines that
hold only GO, as sqlcmd does. MySQL's client-side DELIMITER command is not
supported.
Usage
db_execute_file(
connection: Connection | str,
path: str | Path,
transaction: bool = True,
) -> int
Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| connection required | Connection | str |
An open connection from |
|
| path required | str | Path |
The |
|
| transaction | bool | True |
Run the whole file in one transaction, so a failure leaves the database as it was. MySQL commits schema changes (CREATE, ALTER, DROP) at once whatever the client does. Pass False for statements that cannot run in a transaction, such as PostgreSQL's |
Value
The number of statements (or SQL Server batches) run.
Raises
FrameworkError: The file is missing, the connection is read-only, or a statement failed. The message names the statement's number and line.