sqlite3_create_and_check_table package
Module contents
Helper functions for ensuring that SQL tables are created with the expected columns.
- sqlite3_create_and_check_table.create_and_check_table(cur, create_table_sql, drop=False)[source]
Ensure that a table is created according to the given table creation SQL statement.
- Parameters:
cur – An SQLite database cursor.
create_table_sql – An SQL statement to create a table.
drop – If True, drop existing tables that do not match the given table creation statement, else raise ValueError on mismatch.
- Raises:
ValueError – A table with the same name exists but does not match the given SQL creation statement, i.e. the columns do not match.
- sqlite3_create_and_check_table.dict_factory(cursor, row)[source]
Row factory for dicts.
- Parameters:
cursor – The database cursor.
row – The row data.
- Returns:
A dict with the row data.
- sqlite3_create_and_check_table.dict_factory_cursor(cursor)[source]
Conext manager for temporarily using a dict row factory.
- Parameters:
cursor – The database cursor.
- Returns:
A cursor with the row factory temporary set to dict_factory. When the context exits, the cursor’s previous row factory will be restored.
- sqlite3_create_and_check_table.get_name_and_expected_create_table_sql(create_table_sql)[source]
Create a table in temporary in-memory database using the given SQL statement and get the table’s name and sql statement from the resulting sqlite_master table.
- Parameters:
create_table_sql – An SQL statement to create a table.
- Returns:
The name of the created table and the resulting SQL statement in the sqlite_master table.