Clang: Add busy timeout handler to database

You use now a busy timeout of one second. This is preventing the throwing
of a exception for a busy time under one second.

Change-Id: Iae800a525ad009b594c29883ffb243c1be8b3874
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
Marco Bubke
2018-03-28 17:55:14 +02:00
parent 5870905db6
commit 68c1140d27
8 changed files with 59 additions and 10 deletions

View File

@@ -105,7 +105,6 @@ void DatabaseBackend::open(Utils::SmallStringView databaseFilePath, OpenMode mod
checkDatabaseCouldBeOpened(resultCode);
registerBusyHandler();
registerRankingFunction();
cacheTextEncoding();
}
@@ -212,7 +211,9 @@ void DatabaseBackend::closeWithoutException()
void DatabaseBackend::registerBusyHandler()
{
sqlite3_busy_handler(sqliteDatabaseHandle(), &busyHandlerCallback, nullptr);
int resultCode = sqlite3_busy_handler(sqliteDatabaseHandle(), &busyHandlerCallback, nullptr);
checkIfBusyTimeoutWasSet(resultCode);
}
void DatabaseBackend::registerRankingFunction()
@@ -326,6 +327,12 @@ void DatabaseBackend::checkIfLogCouldBeCheckpointed(int resultCode)
throwException("SqliteDatabaseBackend::checkpointFullWalLog: WAL log could not be checkpointed!");
}
void DatabaseBackend::checkIfBusyTimeoutWasSet(int resultCode)
{
if (resultCode != SQLITE_OK)
throwException("SqliteDatabaseBackend::setBusyTimeout: Busy timeout cannot be set!");
}
namespace {
template<std::size_t Size>
int indexOfPragma(Utils::SmallStringView pragma, const Utils::SmallStringView (&pragmas)[Size])
@@ -395,6 +402,11 @@ int DatabaseBackend::openMode(OpenMode mode)
return sqliteMode;
}
void DatabaseBackend::setBusyTimeout(std::chrono::milliseconds timeout)
{
sqlite3_busy_timeout(m_databaseHandle, int(timeout.count()));
}
void DatabaseBackend::throwExceptionStatic(const char *whatHasHappens)
{
throw Exception(whatHasHappens);