Skip to content

Commit 5a488b3

Browse files
committed
Constructors, destructors, and relevant private fields for SQLiteDatabase/Batch
1 parent ca8b7e0 commit 5a488b3

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/wallet/sqlite.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <wallet/sqlite.h>
66

7+
#include <logging.h>
78
#include <util/memory.h>
89
#include <util/strencodings.h>
910
#include <util/translation.h>
@@ -17,10 +18,15 @@ static const char* const DATABASE_FILENAME = "wallet.dat";
1718
SQLiteDatabase::SQLiteDatabase(const fs::path& dir_path, const fs::path& file_path, bool mock)
1819
: WalletDatabase(), m_mock(mock), m_dir_path(dir_path.string()), m_file_path(file_path.string())
1920
{
21+
LogPrintf("Using SQLite Version %s\n", SQLiteDatabaseVersion());
22+
LogPrintf("Using wallet %s\n", m_dir_path);
23+
24+
Open();
2025
}
2126

2227
SQLiteDatabase::~SQLiteDatabase()
2328
{
29+
Close();
2430
}
2531

2632
void SQLiteDatabase::Open()
@@ -46,6 +52,11 @@ std::unique_ptr<DatabaseBatch> SQLiteDatabase::MakeBatch(bool flush_on_close)
4652
return nullptr;
4753
}
4854

55+
SQLiteBatch::SQLiteBatch(SQLiteDatabase& database)
56+
: m_database(database)
57+
{
58+
}
59+
4960
void SQLiteBatch::Close()
5061
{
5162
}

src/wallet/sqlite.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#include <wallet/db.h>
99

10+
#include <sqlite3.h>
11+
1012
struct bilingual_str;
1113
class SQLiteDatabase;
1214

@@ -23,6 +25,7 @@ class SQLiteBatch : public DatabaseBatch
2325

2426
public:
2527
explicit SQLiteBatch(SQLiteDatabase& database);
28+
~SQLiteBatch() override { Close(); }
2629

2730
/* No-op. See commeng on SQLiteDatabase::Flush */
2831
void Flush() override {}
@@ -91,6 +94,8 @@ class SQLiteDatabase : public WalletDatabase
9194

9295
/** Make a SQLiteBatch connected to this database */
9396
std::unique_ptr<DatabaseBatch> MakeBatch(bool flush_on_close = true) override;
97+
98+
sqlite3* m_db{nullptr};
9499
};
95100

96101
bool ExistsSQLiteDatabase(const fs::path& path);

0 commit comments

Comments
 (0)