HFSQtLi 0.0.1
A Qt/C++ wrapper for SQLite3.
Fetched data types

This section describes the data types that are handled by the fetching functions (e.g. Query::step, Db::executeSingle, ...). Fetching a data type comes in two flavors: standard and strict. The strict mode checks for the type and range of retrived column to be compatible before fetching the data. If anything does not match an error will be returned by the corresponding call. The standard mode on the other hand just calls the API of the requested column type without performings any checks.

Native data types

Following types are directly mapped to sqlite_column_X calls

int x;
double y;
db->executeSingleAll("SELECT 3, 4.5", x, y); // x is 3, y is 4.5

Integer types

The following types are handled natively:

  • qint8
  • quint8
  • qint16
  • quint16
  • qint32
  • quint32
  • qint64
  • quint64

If retriving in strict mode the retrived column is checked to be of integer type and the range of the destination type is checked (e.g. fetching 129 in a qint8 will give an error).

Note: as SQLite stores only 64 bit signed integers the results of operations on 64 bit unsigned with the most signficant bit set is undefined

Floating point

The following types are handled natively:

  • float
  • double

In strict mode the column is checked to be a floating point. Also the float version checks that absolute value of retrived column is not between float_max and infinite (not inclusive)

Other native types

The following types are handled natively:

  • QString
  • QByteArray

Text and blob data can be read respectively with QString and QByteArray

C++ data types

std::optional<T>

If the fetched column is NULL the result is cleared, othewise the value will be read as if the type T was read diredtly.

std::optional<int> x,y;
db->executeSingleAll("SELECT NULL, 3", x, y); // x is empty, y is 3

std::tuple<T...>

If the fetched data is a tuple then the data is retrived as if each element of the tuple was retrived consecutevely.

E.g.

std::tuple<int, double, QString> value;
query.step(value);

is equivalent to

int x;
double y;
QString z;
query.step(x, y, z);

Other data types

Unused

Passing an Unused<N> parameters will consume N columns without fetching any data. No error will be returned except for checking the number of fetched columns.

int x, y;
db->executeSingleAll("SELECT 1,2,3,4", x, Unused<2>, y); // x is 1, y is 4

Call

Passing a Call<T...>(f) parameter allows fetching data of type T... and call the corresponding function after the data is fetched.

See also
Call

Blob

Passing a Blob to a column will behave differently depending on the column type.

  • If column is a blob then the Blob::setDatabase, Blob::table and Blob::setColumn will be called with the matching values of retrived column
  • If column is an integer Blob::setRowId will be called. Passing a reference to a Blob in a column that is not a blob or integer gives an error in strict mode and is a no-op in standard mode

Custom data types

It is possible to handle the fetching of any data type T by implementing a function

void customFetch(CustomFetch &fetch, T &data)

This function will have to use the passed accessor to retrive the needed column(s) and set data

See also
CustomFetch