Administration of the database and all concerning settings. More...
#include <KompexSQLiteDatabase.h>
Public Member Functions | |
SQLiteDatabase () | |
SQLiteDatabase (const char *filename, int flags, const char *zVfs) | |
SQLiteDatabase (const std::string &filename, int flags, const char *zVfs) | |
SQLiteDatabase (const wchar_t *filename) | |
virtual | ~SQLiteDatabase () |
Destructor. | |
void | Open (const char *filename, int flags, const char *zVfs) |
void | Open (const std::string &filename, int flags, const char *zVfs) |
void | Open (const wchar_t *filename) |
void | Close () |
Closes a connection to a SQLite database file. | |
sqlite3 * | GetDatabaseHandle () const |
Returns the SQLite db handle. | |
int | GetLibVersionNumber () const |
Returns the versionnumber of sqlite. | |
int | GetDatabaseChanges () const |
int | GetTotalDatabaseChanges () const |
void | InterruptDatabaseOperation () const |
int | GetAutoCommit () const |
void | ActivateTracing () const |
void | ActivateProfiling () const |
void | SetSoftHeapLimit (int heapLimit) const |
int | ReleaseMemory (int bytesOfMemory) const |
long long | GetMemoryUsage () const |
GetMemoryUsed() returns the number of bytes of memory currently outstanding (malloced but not freed). | |
long long | GetMemoryHighwaterMark (bool resetFlag=false) const |
void | MoveDatabaseToMemory () |
void | SaveDatabaseFromMemoryToFile (const std::string &filename="") |
long long | GetLastInsertRowId () const |
bool | IsDatabaseReadOnly () |
void | ReleaseMemory () |
This function attempts to free as much heap memory as possible from the database connection. | |
Static Protected Member Functions | |
static void | TraceOutput (void *ptr, const char *sql) |
Callback function for ActivateTracing() [sqlite3_trace]. | |
static void | ProfileOutput (void *ptr, const char *sql, sqlite3_uint64 time) |
Callback function for ActivateProfiling() [sqlite3_profile]. | |
static int | ProcessDDLRow (void *db, int nColumns, char **values, char **columns) |
Build and modify the structure of your tables and other objects in the memory database. | |
static int | ProcessDMLRow (void *db, int nColumns, char **values, char **columns) |
Insert all data from the origin database into the memory database. | |
Private Attributes | |
struct sqlite3 * | mDatabaseHandle |
SQLite db handle. | |
std::string | mDatabaseFilename |
Database filename. | |
bool | mIsMemoryDatabaseActive |
Is the database currently stored in memory? |
Administration of the database and all concerning settings.
Kompex::SQLiteDatabase::SQLiteDatabase | ( | ) |
Default constructor.
Closes automatically the connection to a SQLite database file.
Kompex::SQLiteDatabase::SQLiteDatabase | ( | const char * | filename, |
int | flags, | ||
const char * | zVfs | ||
) |
Overloaded constructor.
Opens a connection to a SQLite database file.
filename | Database filename (UTF-8) |
flags | Flags SQLITE_OPEN_READONLY The database is opened in read-only mode. If the database does not already exist, an error is returned. SQLITE_OPEN_READWRITE The database is opened for reading and writing if possible, or reading only if the file is write protected by the operating system. In either case the database must already exist, otherwise an error is returned. SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE The database is opened for reading and writing, and is creates it if it does not already exist. |
zVfs | Name of VFS module to use NULL for default |
Kompex::SQLiteDatabase::SQLiteDatabase | ( | const std::string & | filename, |
int | flags, | ||
const char * | zVfs | ||
) |
Overloaded constructor.
Opens a connection to a SQLite database file.
filename | Database filename (UTF-8) |
flags | Flags SQLITE_OPEN_READONLY The database is opened in read-only mode. If the database does not already exist, an error is returned. SQLITE_OPEN_READWRITE The database is opened for reading and writing if possible, or reading only if the file is write protected by the operating system. In either case the database must already exist, otherwise an error is returned. SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE The database is opened for reading and writing, and is creates it if it does not already exist. |
zVfs | Name of VFS module to use NULL for default |
Kompex::SQLiteDatabase::SQLiteDatabase | ( | const wchar_t * | filename ) |
Overloaded constructor.
Opens a connection to a SQLite database file.
filename | Database filename (UTF-16) |
Kompex::SQLiteDatabase::~SQLiteDatabase | ( | ) | [virtual] |
Destructor.
void Kompex::SQLiteDatabase::ActivateProfiling | ( | ) | const [inline] |
Profile() is invoked as each SQL statement finishes.
The profile callback contains the original statement text
and an estimate of wall-clock time of how long that statement took to run.
Note: time in ns
Output: std::cout
void Kompex::SQLiteDatabase::ActivateTracing | ( | ) | const [inline] |
Trace() is invoked at various times when a SQL statement is being run by FetchRow(), SqlStatement() or ExecuteAndFree().
The callback returns a UTF-8 rendering of the SQL statement text as the statement first begins executing.
Output: std::cout
void Kompex::SQLiteDatabase::Close | ( | ) |
Closes a connection to a SQLite database file.
int Kompex::SQLiteDatabase::GetAutoCommit | ( | ) | const [inline] |
Returns non-zero or zero if the given database connection is or is not in autocommit mode, respectively.
Autocommit mode is on by default. Autocommit mode is disabled by a BEGIN statement.
Autocommit mode is re-enabled by a COMMIT or ROLLBACK.
int Kompex::SQLiteDatabase::GetDatabaseChanges | ( | ) | const [inline] |
Returns the number of database rows that were changed or inserted or deleted
by the most recently completed SQL statement.
sqlite3* Kompex::SQLiteDatabase::GetDatabaseHandle | ( | ) | const [inline] |
Returns the SQLite db handle.
long long Kompex::SQLiteDatabase::GetLastInsertRowId | ( | ) | const [inline] |
This function returns the rowid of the most recent successful INSERT into the database.
If no successful INSERTs have ever occurred on that database connection, zero is returned.
What is the rowid?
Each entry in a SQLite table has a unique 64-bit signed integer key called the "rowid".
The rowid is always available as an undeclared column named ROWID, OID or _ROWID_ as long as
those names are not also used by explicitly declared columns. If the table has a column
of type INTEGER PRIMARY KEY then that column is another alias for the rowid.
int Kompex::SQLiteDatabase::GetLibVersionNumber | ( | ) | const [inline] |
Returns the versionnumber of sqlite.
long long Kompex::SQLiteDatabase::GetMemoryHighwaterMark | ( | bool | resetFlag = false ) |
const [inline] |
GetMemoryHighwaterMark() returns the maximum value of used bytes since the high-water mark was last reset.
resetFlag | The memory high-water mark is reset to the current value of GetMemoryUsage() if resetFlag is true. value returned by GetMemoryHighwaterMark(true) is the high-water mark prior to the reset. |
long long Kompex::SQLiteDatabase::GetMemoryUsage | ( | ) | const [inline] |
GetMemoryUsed() returns the number of bytes of memory currently outstanding (malloced but not freed).
int Kompex::SQLiteDatabase::GetTotalDatabaseChanges | ( | ) | const [inline] |
Returns the total number of row changes caused by INSERT, UPDATE or DELETE statements
since the database connection was opened. The count includes all changes from all trigger contexts.
However, the count does not include changes used to implement REPLACE constraints,
do rollbacks or ABORT processing, or DROP table processing.
The changes are counted as soon as the statement that makes them is completed.
void Kompex::SQLiteDatabase::InterruptDatabaseOperation | ( | ) | const [inline] |
Causes any pending database operation to abort and return at its earliest opportunity.
This routine is typically called in response to a user action such as pressing "Cancel"
or Ctrl-C where the user wants a long query operation to halt immediately.
bool Kompex::SQLiteDatabase::IsDatabaseReadOnly | ( | ) |
This function returns true if the database was opened in read-only mode an false if the
database was opened in read/write mode.
void Kompex::SQLiteDatabase::MoveDatabaseToMemory | ( | ) |
Move the whole database into memory.
Please pay attention, that after a call of MoveDatabaseToMemory() all sql statements are executed into memory.
i.e. that all changes will be lost after closing the database! Hint: this method can only be used for databases which were openend with a UTF8 filename
void Kompex::SQLiteDatabase::Open | ( | const std::string & | filename, |
int | flags, | ||
const char * | zVfs | ||
) |
Opens a connection to a SQLite database file. Shut down existing database handle, if one exist.
filename | Database filename (UTF-8) |
flags | Flags SQLITE_OPEN_READONLY The database is opened in read-only mode. If the database does not already exist, an error is returned. SQLITE_OPEN_READWRITE The database is opened for reading and writing if possible, or reading only if the file is write protected by the operating system. In either case the database must already exist, otherwise an error is returned. SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE The database is opened for reading and writing, and is creates it if it does not already exist. |
zVfs | Name of VFS module to use NULL for default |
void Kompex::SQLiteDatabase::Open | ( | const char * | filename, |
int | flags, | ||
const char * | zVfs | ||
) |
Opens a connection to a SQLite database file.
Shut down existing database handle, if one exist.
filename | Database filename (UTF-8) |
flags | Flags SQLITE_OPEN_READONLY The database is opened in read-only mode. If the database does not already exist, an error is returned. SQLITE_OPEN_READWRITE The database is opened for reading and writing if possible, or reading only if the file is write protected by the operating system. In either case the database must already exist, otherwise an error is returned. SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE The database is opened for reading and writing, and is creates it if it does not already exist. |
zVfs | Name of VFS module to use NULL for default |
void Kompex::SQLiteDatabase::Open | ( | const wchar_t * | filename ) |
Opens a connection to a SQLite database file.
Shut down existing database handle, if one exist.
filename | Database filename (UTF-16) |
int Kompex::SQLiteDatabase::ProcessDDLRow | ( | void * | db, |
int | nColumns, | ||
char ** | values, | ||
char ** | columns | ||
) | [static, protected] |
Build and modify the structure of your tables and other objects in the memory database.
int Kompex::SQLiteDatabase::ProcessDMLRow | ( | void * | db, |
int | nColumns, | ||
char ** | values, | ||
char ** | columns | ||
) | [static, protected] |
Insert all data from the origin database into the memory database.
void Kompex::SQLiteDatabase::ProfileOutput | ( | void * | ptr, |
const char * | sql, | ||
sqlite3_uint64 | time | ||
) | [static, protected] |
Callback function for ActivateProfiling() [sqlite3_profile].
int Kompex::SQLiteDatabase::ReleaseMemory | ( | int | bytesOfMemory ) | const [inline] |
The ReleaseMemory() interface attempts to free N bytes of heap memory by deallocating
non-essential memory allocations held by the database library.
Memory used to cache database pages to improve performance is an example of non-essential memory.
ReleaseMemory() returns the number of bytes actually freed, which might be more or less than the amount requested.
bytesOfMemory | Memory in bytes, which should be freed |
void Kompex::SQLiteDatabase::ReleaseMemory | ( | ) | [inline] |
This function attempts to free as much heap memory as possible from the database connection.
void Kompex::SQLiteDatabase::SaveDatabaseFromMemoryToFile | ( | const std::string & | filename = "" ) |
Takes a snapshot of a database which is located in memory and saves it to a database file.
filename | Filename for the new database file to which the snapshot will be saved. When you leave the filename blank, you will overwrite your origin file database. |
void Kompex::SQLiteDatabase::SetSoftHeapLimit | ( | int | heapLimit ) | const [inline] |
The SetSoftHeapLimit() interface places a "soft" limit on the amount of heap memory that may be allocated by SQLite.
If an internal allocation is requested that would exceed the soft heap limit, sqlite3_release_memory()
is invoked one or more times to free up some space before the allocation is performed. The limit is called "soft", because if sqlite3_release_memory() cannot free sufficient memory to prevent the limit from being exceeded,
the memory is allocated anyway and the current operation proceeds. A negative or zero value for heapLimit means that there is no soft heap limit and sqlite3_release_memory()
will only be called when memory is exhausted. The default value for the soft heap limit is zero.
heapLimit | Heap limit in bytes. |
void Kompex::SQLiteDatabase::TraceOutput | ( | void * | ptr, |
const char * | sql | ||
) | [static, protected] |
Callback function for ActivateTracing() [sqlite3_trace].
std::string Kompex::SQLiteDatabase::mDatabaseFilename [private] |
Database filename.
struct sqlite3* Kompex::SQLiteDatabase::mDatabaseHandle [private] |
SQLite db handle.
bool Kompex::SQLiteDatabase::mIsMemoryDatabaseActive [private] |
Is the database currently stored in memory?