sqlite – Interact with SQLite databases#

This library provides an interface to the sqlite3 Python module. With this, you can open databases, and execute SQL commands on it.

Warning

This library is in development, and its API and usage is not stable. Use it under your own risk. Proofs of this are:

  • A warnings.warn at the beginning of the Python module (unfortunately, the warning is suppressed by importlib while loading the module)

  • A warning in the development tests

Functions#

open_database(path)#
Parameters

path – The database file name.

This function generates a connection with the database path. It also creates a cursor to execute the SQL commands.

Note

The keyword :memory: can be used as path to open a database in the memory.

Warning

If you open a database, while you have another connection with unsaved changes, the changes will be lost, and the previous database will be closed.

close_database()#

This closes everything on the database (connection, cursor and memory data).

Warning

If you have unsaved changes on the database, this function will delete them. They won’t be saved.

Before closing a database, get sure to run the commit_changes function (see below).

commit_changes()#

This function saves every unsaved change to the database. Get sure to run this before closing the file or exiting from the program!

execute_sql(cmd)#
Parameters

cmd – The SQL command.

Run a single line of SQL commands, that are passed to the cursor. The changes will wait for a commit_changes() call to save the changes caused by the command.