![]() And thus we could the view the current intermediate state and decide for rollback (or commit nevertheless) > list(conn.execute('SELECT * FROM test')) OperationalError: near "FNORD": syntax error > conn.executescript("BEGIN UPDATE TEST SET i = 1 FNORD COMMIT""") And this interaction shows step by step whats going on: > list(conn.execute('SELECT * FROM test')) So with executescript() we better use a explicit BEGIN (just as your inital schema creation script did for the "raw" mode sqlite command line tool). This also means that without a "BEGIN" inside the script executescript() works without a transaction, and thus no rollback option upon error or otherwise. ![]() Therefor it just commits a potentially pending auto-commit transactions at start, before "going raw". context manager) but forwards the script rather raw. Sqlite3 module's non-standard conn_or_cursor.executescript() doesn't take part in the (default) auto-commit mode (and so doesn't work normally with the with conn. context manager doing auto-commit OR rollback - except for protected read-modify-write transactions, which are explained at the end of this answer. execute()'s work as expected with the comfortable default auto-commit mode and the with conn.
0 Comments
Leave a Reply. |