This section describes the helpers exposed by the SqliteTools.h
header
Row
This class simplifies accessing a row from the database, and is used by all entities classes to construct an instance based on a database record.
This helpers can either be used to extract some specific columns at a given index (using the Row::load(uint32_t idx)
accessor, or can be used to extract columns one after another using the Row::extract()
accessor.
All accessors are templated and expect to be provided the type of the column being accessed.
In addition this class exposes a few accessors to provide insight about the number of column in the row.
It also exposes a comparison operator with nullptr_t
which is expected to be used when iterating over rows in a result set:
Row sqliteRow;
while ( ( sqliteRow = stmt.row() ) != nullptr )
{
...
}
Statement
This class essentially wraps the raw sqlite3_stmt
types and provides automatic management for a compiled statement.
It also contains a statements cache and the entry point for place holders bindings.
When a Statement
gets constructed, its constructor will attempt to fetch an already compiled statement for that request. If it hasn't been compiled yet, it will do so and cache the resulting compiled statement in its cache for later use.
Tools
This class is responsible for creating or fetching the entities from the database, and connects the Statement
& Row
helpers together.
It provides the following operations:
-
fetchAll
which fetches N entities from the database, based on the provided request. -
fetchOne
will fetch a single entity from the database -
executeRequest
executes a request and performs no particular check or treatment. -
executeDelete
will execute a deletion request by invokingexecuteRequest
but returnsfalse
if a sporadic error is detected. -
executeUpdate
is identical toexecuteDelete
but is provided as a self-documenting accessor, should the user want to execute anUPDATE
instead of aDELETE
-
executeInsert
executes an insertion request and returns the newly created row primary key, or 0 in case of error. -
checkTriggerStatement
ensures that a trigger statement in database is the same as the provided one. This is used to ensure migrations are correctly executed -
checkIndexStatement
does the same ascheckTriggerStatement
but for indexes. -
checkTableSchem
ensures a table schema in database is the expected one. This is also used to ensure migrations were successful. -
listTables
will list all known tables from the database, excluding sqlite's internal tables -
sanitizePattern
provides a minimal escaping for search patterns
Please bear in mind that no check is performed on the actual request, meaning that you can pass a SELECT ...
request to executeDelete
, but the prototypes ensure that you will not be able to do anything meaningful with the results.
The fetch & executeXXXX helpers will also acquire a read or write context respectively if no context was opened for the calling thread (see https://code.videolan.org/videolan/medialibrary/-/wikis/doc/sqlite/Thread-model)