forked from qt-creator/qt-creator
Sqlite: Open Sqlite by default in exclusive locking mode
There are no extra files for the WAL in the excusive locking mode and it can be even faster because the logging is happening on the heap. Change-Id: I59d75dd2aa95d802ba67c8534a5cd8ab32a343df Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -433,6 +433,20 @@ const char *toText(Operation operation)
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
const char *toText(LockingMode lockingMode)
|
||||
{
|
||||
switch (lockingMode) {
|
||||
case LockingMode::Default:
|
||||
return "Default";
|
||||
case LockingMode::Normal:
|
||||
return "Normal";
|
||||
case LockingMode::Exclusive:
|
||||
return "Exclusive";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
} // namespace
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const SessionChangeSet &changeset)
|
||||
@@ -455,6 +469,11 @@ std::ostream &operator<<(std::ostream &out, const SessionChangeSet &changeset)
|
||||
return out;
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, LockingMode lockingMode)
|
||||
{
|
||||
return out << toText(lockingMode);
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, Operation operation)
|
||||
{
|
||||
return out << toText(operation);
|
||||
|
||||
@@ -69,11 +69,13 @@ class Value;
|
||||
class ValueView;
|
||||
class SessionChangeSet;
|
||||
enum class Operation : char;
|
||||
enum class LockingMode : char;
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const Value &value);
|
||||
std::ostream &operator<<(std::ostream &out, const ValueView &value);
|
||||
std::ostream &operator<<(std::ostream &out, Operation operation);
|
||||
std::ostream &operator<<(std::ostream &out, const SessionChangeSet &changeset);
|
||||
std::ostream &operator<<(std::ostream &out, LockingMode lockingMode);
|
||||
|
||||
namespace SessionChangeSetInternal {
|
||||
class ConstIterator;
|
||||
|
||||
@@ -111,6 +111,39 @@ TEST_F(SqliteDatabase, SetJournalMode)
|
||||
ASSERT_THAT(database.journalMode(), JournalMode::Memory);
|
||||
}
|
||||
|
||||
TEST_F(SqliteDatabase, LockingModeIsByDefaultExlusive)
|
||||
{
|
||||
ASSERT_THAT(database.lockingMode(), Sqlite::LockingMode::Exclusive);
|
||||
}
|
||||
|
||||
TEST_F(SqliteDatabase, CreateDatabaseWithLockingModeNormal)
|
||||
{
|
||||
Utils::PathString path{Utils::TemporaryDirectory::masterDirectoryPath()
|
||||
+ "/database_exclusive_locked.db"};
|
||||
|
||||
Sqlite::Database database{path, JournalMode::Wal, Sqlite::LockingMode::Normal};
|
||||
|
||||
ASSERT_THAT(database.lockingMode(), Sqlite::LockingMode::Normal);
|
||||
}
|
||||
|
||||
TEST_F(SqliteDatabase, ExclusivelyLockedDatabaseIsLockedForSecondConnection)
|
||||
{
|
||||
Utils::PathString path{Utils::TemporaryDirectory::masterDirectoryPath()
|
||||
+ "/database_exclusive_locked.db"};
|
||||
Sqlite::Database database{path};
|
||||
|
||||
ASSERT_THROW(Sqlite::Database database2{path}, Sqlite::StatementIsBusy);
|
||||
}
|
||||
|
||||
TEST_F(SqliteDatabase, NormalLockedDatabaseCanBeReopened)
|
||||
{
|
||||
Utils::PathString path{Utils::TemporaryDirectory::masterDirectoryPath()
|
||||
+ "/database_exclusive_locked.db"};
|
||||
Sqlite::Database database{path, JournalMode::Wal, Sqlite::LockingMode::Normal};
|
||||
|
||||
ASSERT_NO_THROW((Sqlite::Database{path, JournalMode::Wal, Sqlite::LockingMode::Normal}));
|
||||
}
|
||||
|
||||
TEST_F(SqliteDatabase, SetOpenlMode)
|
||||
{
|
||||
database.setOpenMode(OpenMode::ReadOnly);
|
||||
|
||||
Reference in New Issue
Block a user