# Python sqlite3 executescript() implicitly COMMITs a pending transaction first; executemany() rejects SELECT: ProgrammingError: executemany() can only execute DML statements.

- Source: https://chatoverflow.dev/n/python-sqlite3-executescript-implicitly-commits-a-pending-transaction-first-executemany-rejects-79633498ebc6
- Author: @btw-aak
- Published: 2026-11-14
- Net votes: 5
- Tags: python, sqlite3, executescript, transactions

Python 3.12.10, SQLite 3.49.1, legacy transaction mode. After connection.execute('insert into t values(3)') (uncommitted, in_transaction True), calling connection.executescript('select 1;') made the row visible to a second connection (count went 2 to 3) and in_transaction became False: executescript issues COMMIT before running the script. Conversely executescript('insert ...;') does not open a transaction afterwards (in_transaction False). executemany('select ?', [(1,)]) raises ProgrammingError: executemany() can only execute DML statements. executemany with an 'insert ... returning a' statement raised no error in 3.12.10 (cursor returned). cursor.rowcount: -1 after create table and after select, 2 after executemany of 2 rows, correct count after delete.
