Constructors, destructors, and relevant private fields for SQLiteDatabase/Batch

This commit is contained in:
Andrew Chow committed 2020-10-14 11:28:17 -04:00
1 parent ca8b7e04ab
commit 5a488b3d77
2 files changed
+16

No files matched your search

+11
View File
@@ -4,6 +4,7 @@
#include <wallet/sqlite.h> #include <wallet/sqlite.h>
#include <logging.h>
#include <util/memory.h> #include <util/memory.h>
#include <util/strencodings.h> #include <util/strencodings.h>
#include <util/translation.h> #include <util/translation.h>
@@ -17,10 +18,15 @@ static const char* const DATABASE_FILENAME = "wallet.dat";
SQLiteDatabase::SQLiteDatabase(const fs::path& dir_path, const fs::path& file_path, bool mock) SQLiteDatabase::SQLiteDatabase(const fs::path& dir_path, const fs::path& file_path, bool mock)
: WalletDatabase(), m_mock(mock), m_dir_path(dir_path.string()), m_file_path(file_path.string()) : WalletDatabase(), m_mock(mock), m_dir_path(dir_path.string()), m_file_path(file_path.string())
{ {
LogPrintf("Using SQLite Version %s\n", SQLiteDatabaseVersion());
LogPrintf("Using wallet %s\n", m_dir_path);
Open();
} }
SQLiteDatabase::~SQLiteDatabase() SQLiteDatabase::~SQLiteDatabase()
{ {
Close();
} }
void SQLiteDatabase::Open() void SQLiteDatabase::Open()
@@ -46,6 +52,11 @@ std::unique_ptr<DatabaseBatch> SQLiteDatabase::MakeBatch(bool flush_on_close)
return nullptr; return nullptr;
} }
SQLiteBatch::SQLiteBatch(SQLiteDatabase& database)
: m_database(database)
{
}
void SQLiteBatch::Close() void SQLiteBatch::Close()
{ {
} }
+5
View File
@@ -7,6 +7,8 @@
#include <wallet/db.h> #include <wallet/db.h>
#include <sqlite3.h>
struct bilingual_str; struct bilingual_str;
class SQLiteDatabase; class SQLiteDatabase;
@@ -23,6 +25,7 @@ private:
public: public:
explicit SQLiteBatch(SQLiteDatabase& database); explicit SQLiteBatch(SQLiteDatabase& database);
~SQLiteBatch() override { Close(); }
/* No-op. See commeng on SQLiteDatabase::Flush */ /* No-op. See commeng on SQLiteDatabase::Flush */
void Flush() override {} void Flush() override {}
@@ -91,6 +94,8 @@ public:
/** Make a SQLiteBatch connected to this database */ /** Make a SQLiteBatch connected to this database */
std::unique_ptr<DatabaseBatch> MakeBatch(bool flush_on_close = true) override; std::unique_ptr<DatabaseBatch> MakeBatch(bool flush_on_close = true) override;
sqlite3* m_db{nullptr};
}; };
bool ExistsSQLiteDatabase(const fs::path& path); bool ExistsSQLiteDatabase(const fs::path& path);