Bitcoin Core  27.99.0
P2P Digital Currency
Public Member Functions | Private Member Functions | Private Attributes | List of all members
wallet::SQLiteBatch Class Reference

RAII class that provides access to a WalletDatabase. More...

#include <sqlite.h>

Inheritance diagram for wallet::SQLiteBatch:
[legend]
Collaboration diagram for wallet::SQLiteBatch:
[legend]

Public Member Functions

 SQLiteBatch (SQLiteDatabase &database)
 
 ~SQLiteBatch () override
 
void SetExecHandler (std::unique_ptr< SQliteExecHandler > &&handler)
 
void Flush () override
 
void Close () override
 
std::unique_ptr< DatabaseCursorGetNewCursor () override
 
std::unique_ptr< DatabaseCursorGetNewPrefixCursor (Span< const std::byte > prefix) override
 
bool TxnBegin () override
 
bool TxnCommit () override
 
bool TxnAbort () override
 
- Public Member Functions inherited from wallet::DatabaseBatch
 DatabaseBatch ()
 
virtual ~DatabaseBatch ()
 
 DatabaseBatch (const DatabaseBatch &)=delete
 
DatabaseBatchoperator= (const DatabaseBatch &)=delete
 
template<typename K , typename T >
bool Read (const K &key, T &value)
 
template<typename K , typename T >
bool Write (const K &key, const T &value, bool fOverwrite=true)
 
template<typename K >
bool Erase (const K &key)
 
template<typename K >
bool Exists (const K &key)
 

Private Member Functions

void SetupSQLStatements ()
 
bool ExecStatement (sqlite3_stmt *stmt, Span< const std::byte > blob)
 
bool ReadKey (DataStream &&key, DataStream &value) override
 
bool WriteKey (DataStream &&key, DataStream &&value, bool overwrite=true) override
 
bool EraseKey (DataStream &&key) override
 
bool HasKey (DataStream &&key) override
 
bool ErasePrefix (Span< const std::byte > prefix) override
 

Private Attributes

SQLiteDatabasem_database
 
std::unique_ptr< SQliteExecHandlerm_exec_handler {std::make_unique<SQliteExecHandler>()}
 
sqlite3_stmt * m_read_stmt {nullptr}
 
sqlite3_stmt * m_insert_stmt {nullptr}
 
sqlite3_stmt * m_overwrite_stmt {nullptr}
 
sqlite3_stmt * m_delete_stmt {nullptr}
 
sqlite3_stmt * m_delete_prefix_stmt {nullptr}
 
bool m_txn {false}
 Whether this batch has started a database transaction and whether it owns SQLiteDatabase::m_write_semaphore. More...
 

Detailed Description

RAII class that provides access to a WalletDatabase.

Definition at line 49 of file sqlite.h.

Constructor & Destructor Documentation

◆ SQLiteBatch()

wallet::SQLiteBatch::SQLiteBatch ( SQLiteDatabase database)
explicit

Definition at line 401 of file sqlite.cpp.

Here is the call graph for this function:

◆ ~SQLiteBatch()

wallet::SQLiteBatch::~SQLiteBatch ( )
inlineoverride

Definition at line 84 of file sqlite.h.

Here is the call graph for this function:

Member Function Documentation

◆ Close()

void wallet::SQLiteBatch::Close ( )
overridevirtual

Implements wallet::DatabaseBatch.

Definition at line 410 of file sqlite.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ EraseKey()

bool wallet::SQLiteBatch::EraseKey ( DataStream &&  key)
overrideprivatevirtual

Implements wallet::DatabaseBatch.

Definition at line 542 of file sqlite.cpp.

Here is the call graph for this function:

◆ ErasePrefix()

bool wallet::SQLiteBatch::ErasePrefix ( Span< const std::byte >  prefix)
overrideprivatevirtual

Implements wallet::DatabaseBatch.

Definition at line 547 of file sqlite.cpp.

Here is the call graph for this function:

◆ ExecStatement()

bool wallet::SQLiteBatch::ExecStatement ( sqlite3_stmt *  stmt,
Span< const std::byte >  blob 
)
private

Definition at line 518 of file sqlite.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Flush()

void wallet::SQLiteBatch::Flush ( )
inlineoverridevirtual

Implements wallet::DatabaseBatch.

Definition at line 89 of file sqlite.h.

◆ GetNewCursor()

std::unique_ptr< DatabaseCursor > wallet::SQLiteBatch::GetNewCursor ( )
overridevirtual

Implements wallet::DatabaseBatch.

Definition at line 596 of file sqlite.cpp.

◆ GetNewPrefixCursor()

std::unique_ptr< DatabaseCursor > wallet::SQLiteBatch::GetNewPrefixCursor ( Span< const std::byte >  prefix)
overridevirtual

Implements wallet::DatabaseBatch.

Definition at line 611 of file sqlite.cpp.

Here is the call graph for this function:

◆ HasKey()

bool wallet::SQLiteBatch::HasKey ( DataStream &&  key)
overrideprivatevirtual

Implements wallet::DatabaseBatch.

Definition at line 552 of file sqlite.cpp.

Here is the call graph for this function:

◆ ReadKey()

bool wallet::SQLiteBatch::ReadKey ( DataStream &&  key,
DataStream value 
)
overrideprivatevirtual

Implements wallet::DatabaseBatch.

Definition at line 459 of file sqlite.cpp.

Here is the call graph for this function:

◆ SetExecHandler()

void wallet::SQLiteBatch::SetExecHandler ( std::unique_ptr< SQliteExecHandler > &&  handler)
inline

Definition at line 86 of file sqlite.h.

◆ SetupSQLStatements()

void wallet::SQLiteBatch::SetupSQLStatements ( )
private

Definition at line 151 of file sqlite.cpp.

Here is the caller graph for this function:

◆ TxnAbort()

bool wallet::SQLiteBatch::TxnAbort ( )
overridevirtual

Implements wallet::DatabaseBatch.

Definition at line 682 of file sqlite.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TxnBegin()

bool wallet::SQLiteBatch::TxnBegin ( )
overridevirtual

Implements wallet::DatabaseBatch.

Definition at line 653 of file sqlite.cpp.

Here is the call graph for this function:

◆ TxnCommit()

bool wallet::SQLiteBatch::TxnCommit ( )
overridevirtual

Implements wallet::DatabaseBatch.

Definition at line 668 of file sqlite.cpp.

Here is the call graph for this function:

◆ WriteKey()

bool wallet::SQLiteBatch::WriteKey ( DataStream &&  key,
DataStream &&  value,
bool  overwrite = true 
)
overrideprivatevirtual

Implements wallet::DatabaseBatch.

Definition at line 485 of file sqlite.cpp.

Here is the call graph for this function:

Member Data Documentation

◆ m_database

SQLiteDatabase& wallet::SQLiteBatch::m_database
private

Definition at line 52 of file sqlite.h.

◆ m_delete_prefix_stmt

sqlite3_stmt* wallet::SQLiteBatch::m_delete_prefix_stmt {nullptr}
private

Definition at line 59 of file sqlite.h.

◆ m_delete_stmt

sqlite3_stmt* wallet::SQLiteBatch::m_delete_stmt {nullptr}
private

Definition at line 58 of file sqlite.h.

◆ m_exec_handler

std::unique_ptr<SQliteExecHandler> wallet::SQLiteBatch::m_exec_handler {std::make_unique<SQliteExecHandler>()}
private

Definition at line 53 of file sqlite.h.

◆ m_insert_stmt

sqlite3_stmt* wallet::SQLiteBatch::m_insert_stmt {nullptr}
private

Definition at line 56 of file sqlite.h.

◆ m_overwrite_stmt

sqlite3_stmt* wallet::SQLiteBatch::m_overwrite_stmt {nullptr}
private

Definition at line 57 of file sqlite.h.

◆ m_read_stmt

sqlite3_stmt* wallet::SQLiteBatch::m_read_stmt {nullptr}
private

Definition at line 55 of file sqlite.h.

◆ m_txn

bool wallet::SQLiteBatch::m_txn {false}
private

Whether this batch has started a database transaction and whether it owns SQLiteDatabase::m_write_semaphore.

If the batch starts a db tx, it acquires the semaphore and sets this to true, keeping the semaphore until the transaction ends to prevent other batch objects from writing to the database.

If this batch did not start a transaction, the semaphore is acquired transiently when writing and m_txn is not set.

m_txn is different from HasActiveTxn() as it is only true when this batch has started the transaction, not just when any batch has started a transaction.

Definition at line 71 of file sqlite.h.


The documentation for this class was generated from the following files: