Bitcoin Core 31.99.0
P2P Digital Currency
Public Member Functions | Public Attributes | Protected Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
wallet::SQLiteDatabase Class Reference

An instance of this class represents one SQLite3 database. More...

#include <sqlite.h>

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

Public Member Functions

 SQLiteDatabase ()=delete
 
 SQLiteDatabase (const fs::path &dir_path, const fs::path &file_path, const DatabaseOptions &options)
 Create DB handle to real database. More...
 
 ~SQLiteDatabase ()
 
bool Verify (bilingual_str &error)
 
void Open () override
 Open the database if it is not already opened. More...
 
void Close () override
 Close the database. More...
 
bool Rewrite () override
 Rewrite the entire database on disk. More...
 
bool Backup (const std::string &dest) const override
 Back up the entire database to a file. More...
 
std::string Filename () override
 Return path to main database file for logs and error messages. More...
 
std::vector< fs::pathFiles () override
 Return paths to all database created files. More...
 
std::string Format () override
 
std::unique_ptr< DatabaseBatchMakeBatch () override
 Make a SQLiteBatch connected to this database. More...
 
bool HasActiveTxn ()
 Return true if there is an on-going txn in this connection. More...
 
- Public Member Functions inherited from wallet::WalletDatabase
 WalletDatabase ()=default
 Create dummy DB handle. More...
 
virtual ~WalletDatabase ()=default
 
virtual void Open ()=0
 Open the database if it is not already opened. More...
 
virtual bool Rewrite ()=0
 Rewrite the entire database on disk. More...
 
virtual bool Backup (const std::string &strDest) const =0
 Back up the entire database to a file. More...
 
virtual void Close ()=0
 Flush to the database file and close the database. More...
 
virtual std::string Filename ()=0
 Return path to main database file for logs and error messages. More...
 
virtual std::vector< fs::pathFiles ()=0
 Return paths to all database created files. More...
 
virtual std::string Format ()=0
 
virtual std::unique_ptr< DatabaseBatchMakeBatch ()=0
 Make a DatabaseBatch connected to this database. More...
 

Public Attributes

std::binary_semaphore m_write_semaphore
 
sqlite3 * m_db {nullptr}
 
bool m_use_unsafe_sync
 
- Public Attributes inherited from wallet::WalletDatabase
std::atomic< int > m_refcount {0}
 Counts the number of active database users to be sure that the database is not closed while someone is using it. More...
 

Protected Member Functions

 SQLiteDatabase (const fs::path &dir_path, const fs::path &file_path, const DatabaseOptions &options, int additional_flags)
 

Private Member Functions

void Cleanup () noexcept EXCLUSIVE_LOCKS_REQUIRED(!g_sqlite_mutex)
 
void Open (int additional_flags)
 

Static Private Member Functions

static int g_sqlite_count GUARDED_BY (g_sqlite_mutex)
 

Private Attributes

const fs::path m_dir_path
 
const std::string m_file_path
 

Static Private Attributes

static Mutex g_sqlite_mutex
 This mutex protects SQLite initialization and shutdown. More...
 

Detailed Description

An instance of this class represents one SQLite3 database.

Definition at line 103 of file sqlite.h.

Constructor & Destructor Documentation

◆ SQLiteDatabase() [1/3]

wallet::SQLiteDatabase::SQLiteDatabase ( const fs::path dir_path,
const fs::path file_path,
const DatabaseOptions options,
int  additional_flags 
)
protected

Definition at line 118 of file sqlite.cpp.

Here is the call graph for this function:

◆ SQLiteDatabase() [2/3]

wallet::SQLiteDatabase::SQLiteDatabase ( )
delete

◆ SQLiteDatabase() [3/3]

wallet::SQLiteDatabase::SQLiteDatabase ( const fs::path dir_path,
const fs::path file_path,
const DatabaseOptions options 
)

Create DB handle to real database.

Definition at line 114 of file sqlite.cpp.

◆ ~SQLiteDatabase()

wallet::SQLiteDatabase::~SQLiteDatabase ( )

Definition at line 171 of file sqlite.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ Backup()

bool wallet::SQLiteDatabase::Backup ( const std::string &  dest) const
overridevirtual

Back up the entire database to a file.

Implements wallet::WalletDatabase.

Reimplemented in wallet::MockableSQLiteDatabase.

Definition at line 349 of file sqlite.cpp.

◆ Cleanup()

void wallet::SQLiteDatabase::Cleanup ( )
privatenoexcept

Definition at line 176 of file sqlite.cpp.

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

◆ Close()

void wallet::SQLiteDatabase::Close ( )
overridevirtual

Close the database.

Implements wallet::WalletDatabase.

Definition at line 376 of file sqlite.cpp.

Here is the caller graph for this function:

◆ Filename()

std::string wallet::SQLiteDatabase::Filename ( )
inlineoverridevirtual

Return path to main database file for logs and error messages.

Implements wallet::WalletDatabase.

Reimplemented in wallet::MockableSQLiteDatabase.

Definition at line 153 of file sqlite.h.

Here is the caller graph for this function:

◆ Files()

std::vector< fs::path > wallet::SQLiteDatabase::Files ( )
inlineoverridevirtual

Return paths to all database created files.

Implements wallet::WalletDatabase.

Reimplemented in wallet::MockableSQLiteDatabase.

Definition at line 155 of file sqlite.h.

Here is the call graph for this function:

◆ Format()

std::string wallet::SQLiteDatabase::Format ( )
inlineoverridevirtual

Implements wallet::WalletDatabase.

Reimplemented in wallet::MockableSQLiteDatabase.

Definition at line 162 of file sqlite.h.

◆ GUARDED_BY()

static int g_sqlite_count wallet::SQLiteDatabase::GUARDED_BY ( g_sqlite_mutex  )
staticprivate

◆ HasActiveTxn()

bool wallet::SQLiteDatabase::HasActiveTxn ( )

Return true if there is an on-going txn in this connection.

Definition at line 385 of file sqlite.cpp.

Here is the caller graph for this function:

◆ MakeBatch()

std::unique_ptr< DatabaseBatch > wallet::SQLiteDatabase::MakeBatch ( )
overridevirtual

Make a SQLiteBatch connected to this database.

Implements wallet::WalletDatabase.

Reimplemented in wallet::MockableSQLiteDatabase.

Definition at line 396 of file sqlite.cpp.

◆ Open() [1/2]

void wallet::SQLiteDatabase::Open ( )
overridevirtual

Open the database if it is not already opened.

Implements wallet::WalletDatabase.

Definition at line 248 of file sqlite.cpp.

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

◆ Open() [2/2]

void wallet::SQLiteDatabase::Open ( int  additional_flags)
private

Definition at line 253 of file sqlite.cpp.

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

◆ Rewrite()

bool wallet::SQLiteDatabase::Rewrite ( )
overridevirtual

Rewrite the entire database on disk.

Implements wallet::WalletDatabase.

Definition at line 342 of file sqlite.cpp.

◆ Verify()

bool wallet::SQLiteDatabase::Verify ( bilingual_str error)

Definition at line 191 of file sqlite.cpp.

Here is the call graph for this function:

Member Data Documentation

◆ g_sqlite_mutex

Mutex wallet::SQLiteDatabase::g_sqlite_mutex
staticprivate

This mutex protects SQLite initialization and shutdown.

sqlite3_config() and sqlite3_shutdown() are not thread-safe (sqlite3_initialize() is). Concurrent threads that execute SQLiteDatabase::SQLiteDatabase() should have just one of them do the init and the rest wait for it to complete before all can proceed.

Definition at line 116 of file sqlite.h.

◆ m_db

sqlite3* wallet::SQLiteDatabase::m_db {nullptr}

Definition at line 170 of file sqlite.h.

◆ m_dir_path

const fs::path wallet::SQLiteDatabase::m_dir_path
private

Definition at line 106 of file sqlite.h.

◆ m_file_path

const std::string wallet::SQLiteDatabase::m_file_path
private

Definition at line 108 of file sqlite.h.

◆ m_use_unsafe_sync

bool wallet::SQLiteDatabase::m_use_unsafe_sync

Definition at line 171 of file sqlite.h.

◆ m_write_semaphore

std::binary_semaphore wallet::SQLiteDatabase::m_write_semaphore

Definition at line 136 of file sqlite.h.


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