Commit 7062ef24 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

sqlite: Connection: Flush all connections after removing all tables

Should fix #405
parent 9339f900
Pipeline #180525 passed with stages
in 6 minutes and 5 seconds
......@@ -1475,6 +1475,12 @@ bool MediaLibrary::recreateDatabase()
if ( m_settings.load() == false )
return false;
t->commit();
/*
* Now that we removed all the tables, flush all the connections to avoid
* Database is locked errors.
* See https://www.sqlite.org/c3ref/close.html
*/
m_dbConnection->flushAll();
/*
* We just delete all tables but this won't invoke the thumbnails deletion
......
......@@ -259,6 +259,13 @@ const std::string&Connection::dbPath() const
return m_dbPath;
}
void Connection::flushAll()
{
Statement::FlushStatementCache();
std::unique_lock<compat::Mutex> lock( m_connMutex );
m_conns.clear();
}
std::shared_ptr<Connection> Connection::connect( const std::string& dbPath )
{
// Use a wrapper to allow make_shared to use the private Connection ctor
......
......@@ -90,6 +90,7 @@ public:
bool checkSchemaIntegrity();
bool checkForeignKeysIntegrity();
const std::string& dbPath() const;
void flushAll();
static std::shared_ptr<Connection> connect( const std::string& dbPath );
......
......@@ -254,6 +254,7 @@ class MediaLibraryTester : public MediaLibrary
deleteAllTriggers( m_dbConnection.get() );
deleteAllTables( dbConn );
t->commit();
m_dbConnection->flushAll();
}
};
}
......@@ -871,6 +872,7 @@ void MediaLibraryResumeTest::onDbConnectionReady( sqlite::Connection *dbConn )
deleteAllTriggers( m_dbConnection.get() );
deleteAllTables( dbConn );
t->commit();
m_dbConnection->flushAll();
}
parser::Parser* MediaLibraryResumeTest::getParser() const
......
......@@ -54,6 +54,7 @@ void MediaLibraryTester::onDbConnectionReady( sqlite::Connection* dbConn )
deleteAllTriggers( m_dbConnection.get() );
deleteAllTables( dbConn );
t->commit();
m_dbConnection->flushAll();
}
std::shared_ptr<Media> MediaLibraryTester::media( int64_t id )
......
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