mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-05-15 16:33:52 +02:00
walletdb: Remove m_mock from SQLiteDatabase
This commit is contained in:
@@ -111,8 +111,12 @@ static void SetPragma(sqlite3* db, const std::string& key, const std::string& va
|
||||
Mutex SQLiteDatabase::g_sqlite_mutex;
|
||||
int SQLiteDatabase::g_sqlite_count = 0;
|
||||
|
||||
SQLiteDatabase::SQLiteDatabase(const fs::path& dir_path, const fs::path& file_path, const DatabaseOptions& options, bool mock)
|
||||
: WalletDatabase(), m_mock(mock), m_dir_path(dir_path), m_file_path(fs::PathToString(file_path)), m_write_semaphore(1), m_use_unsafe_sync(options.use_unsafe_sync)
|
||||
SQLiteDatabase::SQLiteDatabase(const fs::path& dir_path, const fs::path& file_path, const DatabaseOptions& options)
|
||||
: SQLiteDatabase(dir_path, file_path, options, /*additional_flags=*/0)
|
||||
{}
|
||||
|
||||
SQLiteDatabase::SQLiteDatabase(const fs::path& dir_path, const fs::path& file_path, const DatabaseOptions& options, int additional_flags)
|
||||
: WalletDatabase(), m_dir_path(dir_path), m_file_path(fs::PathToString(file_path)), m_write_semaphore(1), m_use_unsafe_sync(options.use_unsafe_sync)
|
||||
{
|
||||
{
|
||||
LOCK(g_sqlite_mutex);
|
||||
@@ -135,7 +139,7 @@ SQLiteDatabase::SQLiteDatabase(const fs::path& dir_path, const fs::path& file_pa
|
||||
}
|
||||
|
||||
try {
|
||||
Open();
|
||||
Open(additional_flags);
|
||||
} catch (const std::runtime_error&) {
|
||||
// If open fails, cleanup this object and rethrow the exception
|
||||
Cleanup();
|
||||
@@ -243,13 +247,15 @@ bool SQLiteDatabase::Verify(bilingual_str& error)
|
||||
|
||||
void SQLiteDatabase::Open()
|
||||
{
|
||||
int flags = SQLITE_OPEN_FULLMUTEX | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
|
||||
if (m_mock) {
|
||||
flags |= SQLITE_OPEN_MEMORY; // In memory database for mock db
|
||||
}
|
||||
Open(/*additional_flags*/0);
|
||||
}
|
||||
|
||||
void SQLiteDatabase::Open(int additional_flags)
|
||||
{
|
||||
int flags = SQLITE_OPEN_FULLMUTEX | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | additional_flags;
|
||||
|
||||
if (m_db == nullptr) {
|
||||
if (!m_mock) {
|
||||
if (!(flags & SQLITE_OPEN_MEMORY)) {
|
||||
TryCreateDirectories(m_dir_path);
|
||||
}
|
||||
int ret = sqlite3_open_v2(m_file_path.c_str(), &m_db, flags, nullptr);
|
||||
|
||||
Reference in New Issue
Block a user