diff --git a/src/common/core/InnerDatabase.cpp b/src/common/core/InnerDatabase.cpp index dc27c07d6..7cfd94a8a 100644 --- a/src/common/core/InnerDatabase.cpp +++ b/src/common/core/InnerDatabase.cpp @@ -247,11 +247,6 @@ void InnerDatabase::setLiteModeEnable(bool enable) close([&] { m_liteModeEnable = enable; CommonCore::shared().enableAutoCheckpoint(this, !m_liteModeEnable); - auto config = m_configs.find(BasicConfigName); - WCTAssert(config != m_configs.end()); - BasicConfig *basicConfig - = static_cast(config->value().get()); - basicConfig->setLiteModeEnable(m_liteModeEnable); }); } } @@ -387,7 +382,7 @@ bool InnerDatabase::setupHandle(HandleType type, InnerHandle *handle) handle->setTag(getTag()); handle->setType(type); - handle->setHasJournal(!m_liteModeEnable); + handle->setLiteModeEnable(m_liteModeEnable); handle->setFullSQLTraceEnable(m_fullSQLTrace); handle->setBusyTraceEnable(CommonCore::shared().isBusyTraceEnable()); HandleSlot slot = slotOfHandleType(type); diff --git a/src/common/core/config/BasicConfig.cpp b/src/common/core/config/BasicConfig.cpp index d2600f401..387efc201 100644 --- a/src/common/core/config/BasicConfig.cpp +++ b/src/common/core/config/BasicConfig.cpp @@ -33,7 +33,6 @@ namespace WCDB { BasicConfig::BasicConfig() : Config() -, m_liteModeEnable(false) , m_getJournalMode(StatementPragma().pragma(Pragma::journalMode())) , m_enableCheckPointFullfsync( StatementPragma().pragma(Pragma::checkpointFullfsync()).to(true)) @@ -56,7 +55,7 @@ bool BasicConfig::invoke(InnerHandle* handle) if (!handle->isReadonly()) { handle->setWALFilePersist(true); succeed = lazySetJournalMode(handle); - if (!m_liteModeEnable) { + if (!handle->liteModeEnable()) { succeed = succeed && handle->execute(m_enableCheckPointFullfsync); } else { succeed = succeed && handle->execute(m_disableFullSync); @@ -68,11 +67,6 @@ bool BasicConfig::invoke(InnerHandle* handle) return succeed; } -void BasicConfig::setLiteModeEnable(bool enable) -{ - m_liteModeEnable = enable; -} - #pragma mark - Journal Mode bool BasicConfig::lazySetJournalMode(InnerHandle* handle) { @@ -85,7 +79,7 @@ bool BasicConfig::lazySetJournalMode(InnerHandle* handle) continue; } succeed = true; - if (!m_liteModeEnable) { + if (!handle->liteModeEnable()) { if (!journalMode.value().caseInsensitiveEqual("WAL")) { if (!handle->canWriteMainDB()) { succeed = false; diff --git a/src/common/core/config/BasicConfig.hpp b/src/common/core/config/BasicConfig.hpp index 009237702..029ec5d87 100644 --- a/src/common/core/config/BasicConfig.hpp +++ b/src/common/core/config/BasicConfig.hpp @@ -35,7 +35,6 @@ class BasicConfig final : public Config { ~BasicConfig() override; bool invoke(InnerHandle* handle) override final; - void setLiteModeEnable(bool enable); #pragma mark - Journal Mode protected: @@ -46,7 +45,6 @@ class BasicConfig final : public Config { bool setJournalMode(InnerHandle* handle, const UnsafeStringView& mode); private: - bool m_liteModeEnable = false; const StatementPragma m_getJournalMode; #pragma mark - FullFsync diff --git a/src/common/core/sqlite/AbstractHandle.cpp b/src/common/core/sqlite/AbstractHandle.cpp index 5e1784b1f..d024ecc66 100644 --- a/src/common/core/sqlite/AbstractHandle.cpp +++ b/src/common/core/sqlite/AbstractHandle.cpp @@ -37,7 +37,7 @@ AbstractHandle::AbstractHandle() : m_handle(nullptr) , m_customOpenFlag(0) , m_tag(Tag::invalid()) -, m_hasJournal(true) +, m_enableLiteMode(false) , m_transactionLevel(0) , m_transactionError(TransactionError::Allowed) , m_cacheTransactionError(TransactionError::Allowed) @@ -199,9 +199,14 @@ bool AbstractHandle::canWriteMainDB() return m_customOpenFlag & SQLITE_OPEN_READWRITE; } -void AbstractHandle::setHasJournal(bool hasJournal) +void AbstractHandle::setLiteModeEnable(bool enable) { - m_hasJournal = hasJournal; + m_enableLiteMode = enable; +} + +bool AbstractHandle::liteModeEnable() const +{ + return m_enableLiteMode; } int AbstractHandle::getChanges() @@ -573,7 +578,7 @@ bool AbstractHandle::commitTransaction() void AbstractHandle::rollbackTransaction() { - if (!m_hasJournal) { + if (m_enableLiteMode) { notifyError(Error::Code::Misuse, "", "Can not execute rollback in a database without rollback journal."); commitTransaction(); return; diff --git a/src/common/core/sqlite/AbstractHandle.hpp b/src/common/core/sqlite/AbstractHandle.hpp index 334cdd531..d6f77f912 100644 --- a/src/common/core/sqlite/AbstractHandle.hpp +++ b/src/common/core/sqlite/AbstractHandle.hpp @@ -77,7 +77,8 @@ class AbstractHandle : public ErrorProne { void enableWriteMainDB(bool enable); bool canWriteMainDB(); - void setHasJournal(bool hasJournal); + void setLiteModeEnable(bool enable); + bool liteModeEnable() const; long long getLastInsertedRowID(); // const char *getErrorMessage(); @@ -97,7 +98,7 @@ class AbstractHandle : public ErrorProne { protected: int m_customOpenFlag; Tag m_tag; - bool m_hasJournal = true; + bool m_enableLiteMode = false; #pragma mark - Statement public: