bindings/python: Start transaction implicitly in execute()

We need to start transaction implicitly in execute() for DML statements
to make sure first transaction is actually started.

Fixes #2002
This commit is contained in:
Pekka Enberg
2025-07-09 09:56:45 +03:00
parent 6faa07505c
commit 5216e67d53
2 changed files with 28 additions and 0 deletions

View File

@@ -93,6 +93,15 @@ impl Cursor {
Ok::<(), anyhow::Error>(())
})?;
if stmt_is_dml && self.conn.conn.get_auto_commit() {
self.conn.conn.execute("BEGIN").map_err(|e| {
PyErr::new::<OperationalError, _>(format!(
"Failed to start transaction after DDL: {:?}",
e
))
})?;
}
// For DDL and DML statements,
// we need to execute the statement immediately
if stmt_is_ddl || stmt_is_dml || stmt_is_tx {