Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/sqlite.h
// Copyright (c) 2020 The Bitcoin Core developers | // Copyright (c) 2020 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_WALLET_SQLITE_H | #ifndef BITCOIN_WALLET_SQLITE_H | ||||
#define BITCOIN_WALLET_SQLITE_H | #define BITCOIN_WALLET_SQLITE_H | ||||
#include <wallet/db.h> | #include <wallet/db.h> | ||||
#include <sqlite3.h> | |||||
struct bilingual_str; | struct bilingual_str; | ||||
class SQLiteDatabase; | class SQLiteDatabase; | ||||
/** RAII class that provides access to a WalletDatabase */ | /** RAII class that provides access to a WalletDatabase */ | ||||
class SQLiteBatch : public DatabaseBatch { | class SQLiteBatch : public DatabaseBatch { | ||||
private: | private: | ||||
SQLiteDatabase &m_database; | // FIXME: uncomment m_database when it is used in commit a0de833 | ||||
// SQLiteDatabase &m_database; | |||||
bool ReadKey(CDataStream &&key, CDataStream &value) override; | bool ReadKey(CDataStream &&key, CDataStream &value) override; | ||||
bool WriteKey(CDataStream &&key, CDataStream &&value, | bool WriteKey(CDataStream &&key, CDataStream &&value, | ||||
bool overwrite = true) override; | bool overwrite = true) override; | ||||
bool EraseKey(CDataStream &&key) override; | bool EraseKey(CDataStream &&key) override; | ||||
bool HasKey(CDataStream &&key) override; | bool HasKey(CDataStream &&key) override; | ||||
public: | public: | ||||
explicit SQLiteBatch(SQLiteDatabase &database); | explicit SQLiteBatch(SQLiteDatabase &database); | ||||
~SQLiteBatch() override { Close(); } | |||||
/** No-op. See comment on SQLiteDatabase::Flush */ | /** No-op. See comment on SQLiteDatabase::Flush */ | ||||
void Flush() override {} | void Flush() override {} | ||||
void Close() override; | void Close() override; | ||||
bool StartCursor() override; | bool StartCursor() override; | ||||
bool ReadAtCursor(CDataStream &key, CDataStream &value, | bool ReadAtCursor(CDataStream &key, CDataStream &value, | ||||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | public: | ||||
void IncrementUpdateCounter() override { ++nUpdateCounter; } | void IncrementUpdateCounter() override { ++nUpdateCounter; } | ||||
std::string Filename() override { return m_file_path; } | std::string Filename() override { return m_file_path; } | ||||
/** Make a SQLiteBatch connected to this database */ | /** Make a SQLiteBatch connected to this database */ | ||||
std::unique_ptr<DatabaseBatch> | std::unique_ptr<DatabaseBatch> | ||||
MakeBatch(bool flush_on_close = true) override; | MakeBatch(bool flush_on_close = true) override; | ||||
sqlite3 *m_db{nullptr}; | |||||
}; | }; | ||||
bool ExistsSQLiteDatabase(const fs::path &path); | bool ExistsSQLiteDatabase(const fs::path &path); | ||||
std::unique_ptr<SQLiteDatabase> | std::unique_ptr<SQLiteDatabase> | ||||
MakeSQLiteDatabase(const fs::path &path, const DatabaseOptions &options, | MakeSQLiteDatabase(const fs::path &path, const DatabaseOptions &options, | ||||
DatabaseStatus &status, bilingual_str &error); | DatabaseStatus &status, bilingual_str &error); | ||||
std::string SQLiteDatabaseVersion(); | std::string SQLiteDatabaseVersion(); | ||||
#endif // BITCOIN_WALLET_SQLITE_H | #endif // BITCOIN_WALLET_SQLITE_H |