Commit 755f4dbf authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

MediaLibrary: Delete and recreate all tables in the same transaction

Fix #399

(cherry picked from commit 5a0ff489

)
Signed-off-by: Hugo Beauzée-Luyssen's avatarHugo Beauzée-Luyssen <hugo@beauzee.fr>
parent 265a7d36
......@@ -380,12 +380,8 @@ bool MediaLibrary::createAllTables()
void MediaLibrary::deleteAllTables( sqlite::Connection* dbConn )
{
auto tables = sqlite::Tools::listTables( dbConn );
assert( sqlite::Transaction::isInProgress() == false );
sqlite::Connection::WeakDbContext ctx{ dbConn };
auto t = dbConn->newTransaction();
for ( const auto& table : tables )
sqlite::Tools::executeRequest( dbConn, "DROP TABLE " + table );
t->commit();
}
void MediaLibrary::createAllTriggers()
......@@ -1443,9 +1439,10 @@ InitializeResult MediaLibrary::updateDatabaseModel( unsigned int previousVersion
bool MediaLibrary::recreateDatabase()
{
sqlite::Connection::DisableForeignKeyContext ctx{ m_dbConnection.get() };
auto t = m_dbConnection->newTransaction();
deleteAllTables( m_dbConnection.get() );
sqlite::Statement::FlushStatementCache();
auto t = m_dbConnection->newTransaction();
Settings::createTable( m_dbConnection.get() );
if ( createAllTables() == false )
return false;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment