[Table Cloning]
- SQLite doesn't allow to modify contraints of tables therefore a
workaround to do so is to recreate the table from scratch.
The old table is therefore cloned and the values are copied tot he newly
created table.
The cloning is done through the CREATE statement specifying the type of
every column in order to keep it unchanged. If we were to clone and
populate the table in one line using query "CREATE TABLE IF NOT EXISTS
clone AS SELECT * FROM original", we might incur in a data type change.
For example DATE columns are converted to NUM column in the clone table.
The cloned table is populated using the INSERT statememnt and then the
old table can be deleted.
A new table with the desired contraints is then created and populated
one line at a time or in one query.
[MainDb]
- Catch soci exception in the init or updateSchema function and
pass them on to the calling function to be handled.
- Make MainDb::isInitialized() return FALSE if the database
initialization failed
- In AbstractDb::connect(), catch soci exception and reset DB session if
they are of type invalid_staement or constraint_violation as an attempt to reconnect to the database won't fix the issue.
- After initializing the database, clean up clone tables in a separate
SQL statemment to avoid the following error
'sqlite3_statement_backend::loadOne: disk I/O error while executing "<statement>"'
[MainDbTester]
- Verify that the database has been correctly initialized
- Do not attempt to retrieve data if the database has not been correctly
initialized