Skip to content
Snippets Groups Projects
Commit 54364679 authored by Sébastien Blin's avatar Sébastien Blin Committed by Guillaume Roguez
Browse files

database: add a transaction for tables creation


Creation of tables in the database can fail. If it occurs, we must not
let the database in a weird state. So, table creation is in a
transaction and if it fails, rollback this transaction and throw a
runtime_error.

Change-Id: I7ac4a891545eb18964f47884d57d43e47bf1fa02
Reviewed-by: default avatarGuillaume Roguez <guillaume.roguez@savoirfairelinux.com>
parent 1d6bc93f
Branches
No related tags found
No related merge requests found
......@@ -70,7 +70,14 @@ Database::Database()
// if db is empty we create them.
if (db_.tables().empty()) {
try {
QSqlDatabase::database().transaction();
createTables();
QSqlDatabase::database().commit();
} catch (QueryError& e) {
QSqlDatabase::database().rollback();
throw std::runtime_error("Could not correctly create the database");
}
// NOTE: the migration can take some time.
migrateOldFiles();
}
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment