sqlite3.Connection.row_factory

row_factory You can change this attribute to a callable that accepts the cursor and the original row as a tuple and will return the real result row. This way, you can implement more advanced ways of returning results, such as returning an object that can also access columns by name. Example: import sqlite3 def dict_factory(cursor, row): d = {} for idx, col in enumerate(cursor.description): d[col[0]] = row[idx] return d con = sqlite3.connect(":memory:") con.row_factory =

sqlite3.Connection.set_progress_handler()

set_progress_handler(handler, n) This routine registers a callback. The callback is invoked for every n instructions of the SQLite virtual machine. This is useful if you want to get called from SQLite during long-running operations, for example to update a GUI. If you want to clear any previously installed progress handler, call the method with None for handler.

sqlite3.Connection.set_trace_callback()

set_trace_callback(trace_callback) Registers trace_callback to be called for each SQL statement that is actually executed by the SQLite backend. The only argument passed to the callback is the statement (as string) that is being executed. The return value of the callback is ignored. Note that the backend does not only run statements passed to the Cursor.execute() methods. Other sources include the transaction management of the Python module and the execution of triggers defined in the curren

sqlite3.Connection.rollback()

rollback() This method rolls back any changes to the database since the last call to commit().

sqlite3.Connection.isolation_level

isolation_level Get or set the current isolation level. None for autocommit mode or one of “DEFERRED”, “IMMEDIATE” or “EXCLUSIVE”. See section Controlling Transactions for a more detailed explanation.

sqlite3.Connection.executescript()

executescript(sql_script) This is a nonstandard shortcut that creates a cursor object by calling the cursor() method, calls the cursor’s executescript() method with the given sql_script, and returns the cursor.

sqlite3.Connection.iterdump()

iterdump() Returns an iterator to dump the database in an SQL text format. Useful when saving an in-memory database for later restoration. This function provides the same capabilities as the .dump command in the sqlite3 shell. Example: # Convert file existing_db.db to SQL dump file dump.sql import sqlite3 con = sqlite3.connect('existing_db.db') with open('dump.sql', 'w') as f: for line in con.iterdump(): f.write('%s\n' % line)

sqlite3.Connection.interrupt()

interrupt() You can call this method from a different thread to abort any queries that might be executing on the connection. The query will then abort and the caller will get an exception.

sqlite3.Connection.in_transaction

in_transaction True if a transaction is active (there are uncommitted changes), False otherwise. Read-only attribute. New in version 3.2.

sqlite3.Connection.executemany()

executemany(sql[, parameters]) This is a nonstandard shortcut that creates a cursor object by calling the cursor() method, calls the cursor’s executemany() method with the parameters given, and returns the cursor.