HFSQtLi 0.0.1
A Qt/C++ wrapper for SQLite3.
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
HFSQtLi::Db Class Reference

Class that gives access to a SQLite connection (struct sqlite3). More...

#include <HFSQtLi.h>

Public Member Functions

bool isOk () const
 isOk Check the status of the last operation on database More...
 
int error () const
 error Check the error code from last operation on database More...
 
QString errorMsg () const
 
Query * query (const char *queryStr, bool persistent=true, bool keepErrorMessage=true)
 query Creates a new query More...
 
QSharedPointer< Query > queryRef (const char *queryStr, bool persistent=true, bool keepErrorMessage=true)
 query Creates a new query More...
 
Commands query execution

The following function allows easy operation on any query that returns no row (e.g. CREATE TABLE or DELETE). See Query::executeCommand.

template<typename... Args>
int execute (const QString &query, Args &&... args)
 Executes a query returning no rows. See Query::executeCommand. More...
 
template<typename... Args>
int execute (QString *error, const QString &query, Args &&... args)
 Executes a query returning no rows, optionally returning the error message generated. See Query::executeCommand. More...
 
Single row query execution

The following function allows easy operation on any query that returns one and only one row. They perform in one operation binding of parameters, a step on first row, fetching the data of the row and a second step to check the query effetively returned only one row.

Note
All the function in this group will return an error if the query returns no row or more than one row.
template<typename... Args>
int executeSingleAll (const QString &query, Args &&... args)
 Execute a query returning just one row and fetches all of the returned data. More...
 
template<int I, typename... Args>
int executeSingleAll (const QString &query, Args &&... args)
 Execute a query returning just one row and fetches all of the returned data. More...
 
template<int I, typename... Args>
int executeSingleAll (QString *error, const QString &query, Args &&... args)
 Execute a query returning just one row and fetches all of the returned data. More...
 

Static Public Member Functions

static Db * open (const QString &filename, QIODevice::OpenMode flags=QIODevice::ReadWrite, QString *errorMsg=nullptr, const char *zVfs=nullptr)
 open Opens a database More...
 

Protected Member Functions

 Db (const QString &filename, QIODevice::OpenMode flags=QIODevice::ReadWrite, const char *zVfs=NULL)
 

Protected Attributes

sqlite3 * m_db
 
std::atomic_int m_queryCount
 
int m_openError
 
QString m_openErrorMsg
 

Friends

class Query
 
class Helper::BlobData
 

Detailed Description

Class that gives access to a SQLite connection (struct sqlite3).

No public constructor is available, instance of the class must be created via Db::open.

Member Function Documentation

◆ error()

int Db::error ( ) const

error Check the error code from last operation on database

Returns
SQLITE error code

◆ execute() [1/2]

template<typename... Args>
int HFSQtLi::Db::execute ( const QString &  query,
Args &&...  args 
)
inline

Executes a query returning no rows. See Query::executeCommand.

Returns
0 on failure, 1+number of bound parameters on success

◆ execute() [2/2]

template<typename... Args>
int HFSQtLi::Db::execute ( QString *  error,
const QString &  query,
Args &&...  args 
)
inline

Executes a query returning no rows, optionally returning the error message generated. See Query::executeCommand.

Returns
0 on failure, 1+number of bound parameters on success

◆ executeSingleAll() [1/3]

template<typename... Args>
int HFSQtLi::Db::executeSingleAll ( const QString &  query,
Args &&...  args 
)
inline

Execute a query returning just one row and fetches all of the returned data.

Parameters
INumber of parameters to bind
strictTrue if the data of the types should be checked
argsFirst I arguments are the values to bind (see Bounded data types), the ones after that are references to data to retrive (see Fetched data types)
Returns
0 on error, 1+number of fetched columns on success
Warning
Data is bound in temporary mode and resetBindings() is called before returning
Parameters
queryA string containing the query to execute

◆ executeSingleAll() [2/3]

template<int I, typename... Args>
int HFSQtLi::Db::executeSingleAll ( const QString &  query,
Args &&...  args 
)
inline

Execute a query returning just one row and fetches all of the returned data.

Parameters
INumber of parameters to bind
strictTrue if the data of the types should be checked
argsFirst I arguments are the values to bind (see Bounded data types), the ones after that are references to data to retrive (see Fetched data types)
Returns
0 on error, 1+number of fetched columns on success
Warning
Data is bound in temporary mode and resetBindings() is called before returning
Parameters
queryA string containing the query to execute

◆ executeSingleAll() [3/3]

template<int I, typename... Args>
int HFSQtLi::Db::executeSingleAll ( QString *  error,
const QString &  query,
Args &&...  args 
)

Execute a query returning just one row and fetches all of the returned data.

Parameters
INumber of parameters to bind
strictTrue if the data of the types should be checked
argsFirst I arguments are the values to bind (see Bounded data types), the ones after that are references to data to retrive (see Fetched data types)
Returns
0 on error, 1+number of fetched columns on success
Warning
Data is bound in temporary mode and resetBindings() is called before returning
Parameters
errorAn optional pointer to a string to fill with the error message.
queryA string containing the query to execute

◆ isOk()

bool Db::isOk ( ) const

isOk Check the status of the last operation on database

Returns
True if last error is SQLITE_OK

◆ open()

Db * Db::open ( const QString &  filename,
QIODevice::OpenMode  flags = QIODevice::ReadWrite,
QString *  errorMsg = nullptr,
const char *  zVfs = nullptr 
)
static

open Opens a database

Parameters
filenamePath to filename to open
Anor between flags QIODevice::ReadWrite for a read/write database and QIODevice::Append to open only an existing database
errorMsgPointer to a string that will be filled with error message in case of error
zVfsVirtual file system to open (See SQLite documentation)
Returns
A pointer to the opened database in case of success

◆ query()

Query * Db::query ( const char *  queryStr,
bool  persistent = true,
bool  keepErrorMessage = true 
)

query Creates a new query

Parameters
queryStrQuery string
persistentOptimize persistent queries
keepErrorMessageTrue if error message returned should be stored
Returns
The prepared query on success

◆ queryRef()

QSharedPointer< Query > HFSQtLi::Db::queryRef ( const char *  queryStr,
bool  persistent = true,
bool  keepErrorMessage = true 
)
inline

query Creates a new query

Parameters
queryStrQuery string
persistentOptimize persistent queries
keepErrorMessageTrue if error message returned should be stored
Returns
The prepared query on success

queryRef Same as Db::query but returns a shared pointer


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