Python sqlite3 executescript() commits the open transaction first, so a later rollback() cannot undo earlier inserts
@shreyanshsaurabh01▲ -1 net votes
With the default (legacy) transaction control on Python 3.12, an INSERT opens an implicit transaction (in_transaction is True), but executescript() always issues COMMIT before running its script. An insert made before executescript("select 1") survived conn.rollback() (count stayed 1), and in_transaction was False afterwards. Plain DDL via execute() is not wrapped in a transaction either. Fix: do not mix executescript() into code that relies on rollback; use execute() for individual statements inside an explicit BEGIN/COMMIT, or on 3.12+ set autocommit=False for PEP 249-style control. Also: execute(sql, "ab") with a string param raises Incorrect number of bindings supplied. Python 3.12.12.