dodo  0.0.1
A C++ library to create containerized Linux services
dodo::persist::sqlite::Database Class Reference

A STL friendly wrapper around the great sqlite3. More...

#include <sqlite.hpp>

Collaboration diagram for dodo::persist::sqlite::Database:

Public Member Functions

 Database (const std::string &filename, WaitHandler handler=0)
 Constructor with explicit wait handler. More...
 
 ~Database ()
 Destructor. More...
 
void beginExclusiveTransaction ()
 Begin an exclusive transaction. More...
 
void beginImmediateTransaction ()
 Begin an immediate transaction. More...
 
void beginTransaction ()
 Begin a transaction. More...
 
void checkPointFull ()
 Issue a full checpoint. More...
 
void checkPointPassive ()
 Issue a passive checpoint. More...
 
void checkPointTruncate ()
 Issue a (WAL) truncate checpoint. More...
 
void commit ()
 Commit a transaction. More...
 
void createSavepoint (const std::string &sp)
 Create a named savepoint. More...
 
void disableForeignKeys ()
 Disable foreign key constraints. More...
 
void enableForeignKeys ()
 Enable foreign key constraints. More...
 
void enableTriggers ()
 Enable triggers. More...
 
sqlite3 * getDB () const
 Return database handle. More...
 
std::string getFileName () const
 Return the database filename. More...
 
int getUserVersion () const
 get the current user_version pragma (a user defined database schema version) More...
 
int64_t lastInsertRowid () const
 Get the rowid of the last inserted row. More...
 
void releaseMemory ()
 Have SQLite attempt to release a much memory as possible. More...
 
void releaseSavepoint (const std::string &sp)
 Release a savepoint. More...
 
void rollback ()
 Rollback a transaction. More...
 
void rollback (const std::string &sp)
 Rollback to a savepoint. More...
 
void setUserVersion (int version)
 set the user_version pragma More...
 

Static Public Member Functions

static int64_t memHighWater ()
 Get memory highwater by the SQLite library. More...
 
static int64_t memUsed ()
 Get memory in use by the SQLite library. More...
 
static int64_t softHeapLimit (int64_t limit)
 Set the SQLite soft heap limit - ask SQLite to strive to limit its memory use (caching). More...
 

Protected Attributes

sqlite3 * database_
 The SQLite database handle. More...
 

Detailed Description

A STL friendly wrapper around the great sqlite3.

A few extension functions are added for use in SQL

  • power(double x,double y) gives base x to the power y (x^y)
  • floor(double x) gives the nearest integer downwards
  • ceil(double x) gives the nearest integer upwards

Definition at line 52 of file sqlite.hpp.

Constructor & Destructor Documentation

◆ Database()

dodo::persist::sqlite::Database::Database ( const std::string &  filename,
WaitHandler  handler = 0 
)

Constructor with explicit wait handler.

Parameters
filenamethe database filename
handlerthe wait handler

Definition at line 131 of file sqlite.cpp.

References database_, dodo::persist::sqlite::sqlite_ext_ceil(), dodo::persist::sqlite::sqlite_ext_floor(), dodo::persist::sqlite::sqlite_ext_log2(), dodo::persist::sqlite::sqlite_ext_pow(), and throw_Exception.

Here is the call graph for this function:

◆ ~Database()

dodo::persist::sqlite::Database::~Database ( )

Destructor.

Definition at line 194 of file sqlite.cpp.

References database_.

Member Function Documentation

◆ beginExclusiveTransaction()

void dodo::persist::sqlite::Database::beginExclusiveTransaction ( )

Begin an exclusive transaction.

See also
https://sqlite.org/lang_transaction.html

Definition at line 239 of file sqlite.cpp.

References dodo::persist::sqlite::DDL::execute(), and dodo::persist::sqlite::Statement::prepare().

Here is the call graph for this function:

◆ beginImmediateTransaction()

void dodo::persist::sqlite::Database::beginImmediateTransaction ( )

Begin an immediate transaction.

See also
https://sqlite.org/lang_transaction.html

Definition at line 231 of file sqlite.cpp.

References dodo::persist::sqlite::DDL::execute(), and dodo::persist::sqlite::Statement::prepare().

Here is the call graph for this function:

◆ beginTransaction()

void dodo::persist::sqlite::Database::beginTransaction ( )

Begin a transaction.

See also
https://sqlite.org/lang_transaction.html

Definition at line 223 of file sqlite.cpp.

References dodo::persist::sqlite::DDL::execute(), and dodo::persist::sqlite::Statement::prepare().

Here is the call graph for this function:

◆ checkPointFull()

void dodo::persist::sqlite::Database::checkPointFull ( )

Issue a full checpoint.

Definition at line 295 of file sqlite.cpp.

References database_, and throw_Exception.

Referenced by dodo::persist::KVStore::checkpoint().

Here is the caller graph for this function:

◆ checkPointPassive()

void dodo::persist::sqlite::Database::checkPointPassive ( )

Issue a passive checpoint.

Definition at line 304 of file sqlite.cpp.

References database_, and throw_Exception.

◆ checkPointTruncate()

void dodo::persist::sqlite::Database::checkPointTruncate ( )

Issue a (WAL) truncate checpoint.

Definition at line 313 of file sqlite.cpp.

References database_, and throw_Exception.

◆ commit()

void dodo::persist::sqlite::Database::commit ( )

Commit a transaction.

Definition at line 247 of file sqlite.cpp.

References dodo::persist::sqlite::DDL::execute(), and dodo::persist::sqlite::Statement::prepare().

Referenced by dodo::persist::KVStore::commitTransaction().

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

◆ createSavepoint()

void dodo::persist::sqlite::Database::createSavepoint ( const std::string &  sp)

Create a named savepoint.

Parameters
spthe savepoint name
See also
release, rollback

Definition at line 263 of file sqlite.cpp.

References dodo::persist::sqlite::DDL::execute(), and dodo::persist::sqlite::Statement::prepare().

Here is the call graph for this function:

◆ disableForeignKeys()

void dodo::persist::sqlite::Database::disableForeignKeys ( )

Disable foreign key constraints.

Definition at line 207 of file sqlite.cpp.

References database_, and throw_Exception.

◆ enableForeignKeys()

void dodo::persist::sqlite::Database::enableForeignKeys ( )

Enable foreign key constraints.

Definition at line 199 of file sqlite.cpp.

References database_, and throw_Exception.

◆ enableTriggers()

void dodo::persist::sqlite::Database::enableTriggers ( )

Enable triggers.

Definition at line 215 of file sqlite.cpp.

References database_, and throw_Exception.

◆ getDB()

sqlite3* dodo::persist::sqlite::Database::getDB ( ) const
inline

Return database handle.

Returns
the sqlite3 database handle.

Definition at line 128 of file sqlite.hpp.

References database_.

Referenced by dodo::persist::sqlite::Statement::Statement().

Here is the caller graph for this function:

◆ getFileName()

std::string dodo::persist::sqlite::Database::getFileName ( ) const
inline

Return the database filename.

Returns
The file name.

Definition at line 122 of file sqlite.hpp.

References database_.

◆ getUserVersion()

int dodo::persist::sqlite::Database::getUserVersion ( ) const

get the current user_version pragma (a user defined database schema version)

Returns
The user version.

Definition at line 334 of file sqlite.cpp.

References database_, dodo::persist::sqlite::Query::getInt(), dodo::persist::sqlite::Statement::prepare(), dodo::persist::sqlite::Query::step(), and throw_Exception.

Here is the call graph for this function:

◆ lastInsertRowid()

int64_t dodo::persist::sqlite::Database::lastInsertRowid ( ) const

Get the rowid of the last inserted row.

Returns
The last rowid

Definition at line 287 of file sqlite.cpp.

References database_, and throw_Exception.

◆ memHighWater()

static int64_t dodo::persist::sqlite::Database::memHighWater ( )
inlinestatic

Get memory highwater by the SQLite library.

Returns
The max memory ever used.

Definition at line 154 of file sqlite.hpp.

◆ memUsed()

static int64_t dodo::persist::sqlite::Database::memUsed ( )
inlinestatic

Get memory in use by the SQLite library.

Returns
the amount of memory used.

Definition at line 146 of file sqlite.hpp.

◆ releaseMemory()

void dodo::persist::sqlite::Database::releaseMemory ( )

Have SQLite attempt to release a much memory as possible.

Definition at line 344 of file sqlite.cpp.

References database_.

◆ releaseSavepoint()

void dodo::persist::sqlite::Database::releaseSavepoint ( const std::string &  sp)

Release a savepoint.

Parameters
spthe savepoint name

Definition at line 271 of file sqlite.cpp.

References dodo::persist::sqlite::DDL::execute(), and dodo::persist::sqlite::Statement::prepare().

Here is the call graph for this function:

◆ rollback() [1/2]

void dodo::persist::sqlite::Database::rollback ( )

Rollback a transaction.

Definition at line 255 of file sqlite.cpp.

References dodo::persist::sqlite::DDL::execute(), and dodo::persist::sqlite::Statement::prepare().

Referenced by dodo::persist::KVStore::rollbackTransaction().

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

◆ rollback() [2/2]

void dodo::persist::sqlite::Database::rollback ( const std::string &  sp)

Rollback to a savepoint.

Parameters
spthe savepoint name

Definition at line 279 of file sqlite.cpp.

References dodo::persist::sqlite::DDL::execute(), and dodo::persist::sqlite::Statement::prepare().

Here is the call graph for this function:

◆ setUserVersion()

void dodo::persist::sqlite::Database::setUserVersion ( int  version)

set the user_version pragma

Parameters
versionThe user version to set.

Definition at line 326 of file sqlite.cpp.

References dodo::persist::sqlite::DDL::execute(), and dodo::persist::sqlite::Statement::prepare().

Here is the call graph for this function:

◆ softHeapLimit()

static int64_t dodo::persist::sqlite::Database::softHeapLimit ( int64_t  limit)
inlinestatic

Set the SQLite soft heap limit - ask SQLite to strive to limit its memory use (caching).

A value of 0 disables the limit.

Parameters
limitThe limit to set.
Returns
The previous soft heap limit.
See also
https://www.sqlite.org/c3ref/hard_heap_limit64.html

Definition at line 198 of file sqlite.hpp.

Field Documentation

◆ database_

sqlite3* dodo::persist::sqlite::Database::database_
protected

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