From 83383a8117d0cf62f57d70d13126576e2b7bf5f6 Mon Sep 17 00:00:00 2001 From: "andrew (from workstation)" Date: Fri, 13 Dec 2019 21:48:05 +0100 Subject: [PATCH] support for :memory: path --- tddb/td/db/SqliteDb.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/tddb/td/db/SqliteDb.cpp b/tddb/td/db/SqliteDb.cpp index 76e15ee7..469a5391 100644 --- a/tddb/td/db/SqliteDb.cpp +++ b/tddb/td/db/SqliteDb.cpp @@ -50,17 +50,22 @@ SqliteDb::~SqliteDb() = default; Status SqliteDb::init(CSlice path, bool *was_created) { // If database does not exist, delete all other files which may left // from older database - bool is_db_exists = stat(path).is_ok(); - if (!is_db_exists) { - TRY_STATUS(destroy(path)); + + if (path != ":memory:") { + bool is_db_exists = stat(path).is_ok(); + + if (!is_db_exists) { + TRY_STATUS(destroy(path)); + } + + if (was_created != nullptr) { + *was_created = !is_db_exists; + } } - if (was_created != nullptr) { - *was_created = !is_db_exists; - } sqlite3 *db; CHECK(sqlite3_threadsafe() != 0); - int rc = sqlite3_open_v2(path.c_str(), &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE /*| SQLITE_OPEN_SHAREDCACHE*/, + int rc = sqlite3_open_v2(path.c_str(), &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_SHAREDCACHE, nullptr); if (rc != SQLITE_OK) { auto res = Status::Error(PSLICE() << "Failed to open database: " << detail::RawSqliteDb::last_error(db));