Bitcoin Core  22.99.0
P2P Digital Currency
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
SQLiteDatabase Class Reference

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

#include <sqlite.h>

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

Public Member Functions

 SQLiteDatabase ()=delete
 
 SQLiteDatabase (const fs::path &dir_path, const fs::path &file_path, bool mock=false)
 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...
 
void AddRef () override
 Indicate the a new database user has began using the database. More...
 
void RemoveRef () override
 Indicate that database user has stopped using the database and that it could be flushed or closed. More...
 
bool Rewrite (const char *skip=nullptr) 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...
 
void Flush () override
 No-ops. More...
 
bool PeriodicFlush () override
 
void ReloadDbEnv () override
 
void IncrementUpdateCounter () override
 
std::string Filename () override
 Return path to main database file for logs and error messages. More...
 
std::string Format () override
 
std::unique_ptr< DatabaseBatchMakeBatch (bool flush_on_close=true) override
 Make a SQLiteBatch connected to this database. More...
 
- Public Member Functions inherited from WalletDatabase
 WalletDatabase ()
 Create dummy DB handle. More...
 
virtual ~WalletDatabase ()
 

Public Attributes

sqlite3 * m_db {nullptr}
 
- Public Attributes inherited from 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...
 
std::atomic< unsigned int > nUpdateCounter
 
unsigned int nLastSeen
 
unsigned int nLastFlushed
 
int64_t nLastWalletUpdate
 

Private Member Functions

void Cleanup () noexcept
 

Private Attributes

const bool m_mock {false}
 
const std::string m_dir_path
 
const std::string m_file_path
 

Detailed Description

An instance of this class represents one SQLite3 database.

Definition at line 55 of file sqlite.h.

Constructor & Destructor Documentation

◆ SQLiteDatabase() [1/2]

SQLiteDatabase::SQLiteDatabase ( )
delete

◆ SQLiteDatabase() [2/2]

SQLiteDatabase::SQLiteDatabase ( const fs::path dir_path,
const fs::path file_path,
bool  mock = false 
)

Create DB handle to real database.

Definition at line 69 of file sqlite.cpp.

Here is the call graph for this function:

◆ ~SQLiteDatabase()

SQLiteDatabase::~SQLiteDatabase ( )

Definition at line 125 of file sqlite.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ AddRef()

void SQLiteDatabase::AddRef ( )
inlineoverridevirtual

Indicate the a new database user has began using the database.

Increments m_refcount

Implements WalletDatabase.

Definition at line 83 of file sqlite.h.

Here is the call graph for this function:

◆ Backup()

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

Back up the entire database to a file.

Implements WalletDatabase.

Definition at line 292 of file sqlite.cpp.

◆ Cleanup()

void SQLiteDatabase::Cleanup ( )
privatenoexcept

Definition at line 130 of file sqlite.cpp.

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

◆ Close()

void SQLiteDatabase::Close ( )
overridevirtual

Close the database.

Implements WalletDatabase.

Definition at line 319 of file sqlite.cpp.

Here is the caller graph for this function:

◆ Filename()

std::string SQLiteDatabase::Filename ( )
inlineoverridevirtual

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

Implements WalletDatabase.

Definition at line 107 of file sqlite.h.

◆ Flush()

void SQLiteDatabase::Flush ( )
inlineoverridevirtual

No-ops.

SQLite always flushes everything to the database file after each transaction (each Read/Write/Erase that we do is its own transaction unless we called TxnBegin) so there is no need to have Flush or Periodic Flush.

There is no DB env to reload, so ReloadDbEnv has nothing to do

Implements WalletDatabase.

Definition at line 101 of file sqlite.h.

◆ Format()

std::string SQLiteDatabase::Format ( )
inlineoverridevirtual

Implements WalletDatabase.

Definition at line 108 of file sqlite.h.

◆ IncrementUpdateCounter()

void SQLiteDatabase::IncrementUpdateCounter ( )
inlineoverridevirtual

Implements WalletDatabase.

Definition at line 105 of file sqlite.h.

◆ MakeBatch()

std::unique_ptr< DatabaseBatch > SQLiteDatabase::MakeBatch ( bool  flush_on_close = true)
overridevirtual

Make a SQLiteBatch connected to this database.

Implements WalletDatabase.

Definition at line 328 of file sqlite.cpp.

◆ Open()

void SQLiteDatabase::Open ( )
overridevirtual

Open the database if it is not already opened.

Implements WalletDatabase.

Definition at line 200 of file sqlite.cpp.

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

◆ PeriodicFlush()

bool SQLiteDatabase::PeriodicFlush ( )
inlineoverridevirtual

Implements WalletDatabase.

Definition at line 102 of file sqlite.h.

◆ ReloadDbEnv()

void SQLiteDatabase::ReloadDbEnv ( )
inlineoverridevirtual

Implements WalletDatabase.

Definition at line 103 of file sqlite.h.

◆ RemoveRef()

void SQLiteDatabase::RemoveRef ( )
inlineoverridevirtual

Indicate that database user has stopped using the database and that it could be flushed or closed.

Decrement m_refcount

Implements WalletDatabase.

Definition at line 84 of file sqlite.h.

Here is the call graph for this function:

◆ Rewrite()

bool SQLiteDatabase::Rewrite ( const char *  skip = nullptr)
overridevirtual

Rewrite the entire database on disk.

Implements WalletDatabase.

Definition at line 285 of file sqlite.cpp.

◆ Verify()

bool SQLiteDatabase::Verify ( bilingual_str error)

Definition at line 143 of file sqlite.cpp.

Here is the call graph for this function:

Member Data Documentation

◆ m_db

sqlite3* SQLiteDatabase::m_db {nullptr}

Definition at line 113 of file sqlite.h.

◆ m_dir_path

const std::string SQLiteDatabase::m_dir_path
private

Definition at line 60 of file sqlite.h.

◆ m_file_path

const std::string SQLiteDatabase::m_file_path
private

Definition at line 62 of file sqlite.h.

◆ m_mock

const bool SQLiteDatabase::m_mock {false}
private

Definition at line 58 of file sqlite.h.


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