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

This section describes the data types that are handled by the bounding functions (e.g. Query::bind, Db::executeSingle<N>, ...). Bounding function exists with a standard and a temporary version. They behave exactly the same except that the lifetime of QString and QByteArray bounded with temporary versions are guaranteed to extend until the Query will be destroyed or reset. They are mainly used for optimizing calls in executeSingle.

Native data types

Following types are directly mapped to sqlite_bind_X calls

query.bind(4, "Hello, world!");

Integer types

The following types are handled natively:

  • qint64 All other integers can be used and will be simply cast to a qint64

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:

  • double A float can be used and will be simply cast to a double

Other native types

The following types are handled natively:

  • QString
  • QByteArray

Note that when using temporary version the passed variables must be guaranteed to exists for all the time they will be bound (that is until destruction of the query or a call to resetAllBindings)

C++ data types

std::optional<T>

If the bound value is empty than this is equivalent to NULL, othewise the value will be bound as if directly passing a type T.

std::optional<int> x(4),y;
qry.bind(x,y); // 1st column is 4, 2nd is NULL

std::tuple<T...>

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

E.g.

query.bind(std::tuple<int, double, QString>(3, 5.2, "Hello world"));

is equivalent to

int x;
double y;
QString z;
query.bind(3, 5.2, "Hello world");

Other data types

Nulls

Nulls can be bound in two ways:

  • By passing a nullptr
  • By passing a Null()
    // Both are equivalent and binds a NULL
    qry.bind(nullptr);
    qry.bind(Null());
    Class to bind a NULL pointer (See Bounded data types).
    Definition: HFSQtLi.h:482

ZeroBlob

Passing a ZeroBlob will bind an empty blob with the passed size. Mapped to a sqlite3_bind_zeroblob64 call.

qry.bind(ZeroBlob(50));
Placeholder for a zero intialized blob of a given size (See Bounded data types).
Definition: HFSQtLi.h:1435

Custom data types

It is possible to handle the binding of any data type T by implementing one of the following functions:

  • void customFetch(CustomBind &bind, const T &data)
  • void customFetch(CustomBind &bind, T &&data)

This function will have to use the passed accessor to bind the needed column(s) using data

See also
CustomBind