|
| QxSession () |
|
| QxSession (const QSqlDatabase &database) |
|
| QxSession (const QSqlDatabase &database, bool bOpenTransaction) |
|
| QxSession (const QSqlDatabase &database, bool bOpenTransaction, bool bThrowable, bool bAutoRollbackWhenDestroyed=false) |
|
virtual | ~QxSession () |
|
bool | isThrowable () const |
|
bool | isOpened () const |
|
bool | isValid () const |
|
bool | isAutoRollbackWhenDestroyed () const |
|
void | setAutoRollbackWhenDestroyed (bool b) |
|
QSqlError | firstError () const |
|
QSqlError | lastError () const |
|
QList< QSqlError > | allErrors () const |
|
const QSqlDatabase * | database () const |
|
QSqlDatabase * | database () |
|
bool | open () |
|
bool | close () |
|
bool | commit () |
|
bool | rollback () |
|
QxSession & | operator+= (const QSqlError &err) |
|
void | ignoreSoftDelete (bool bIgnoreSoftDelete=true, const QStringList &classesToIgnore=QStringList()) |
|
bool | checkIgnoreSoftDelete (const QString &classKey) const |
|
QString | getIgnoreSoftDeleteHash () const |
|
template<class T > |
long | count (const qx::QxSqlQuery &query=qx::QxSqlQuery()) |
|
template<class T > |
QSqlError | count (long &lCount, const qx::QxSqlQuery &query=qx::QxSqlQuery()) |
|
template<class T > |
T * | fetchById (const QVariant &id, const QStringList &columns=QStringList(), const QStringList &relation=QStringList()) |
|
template<class T > |
QSqlError | fetchById (T &t, const QStringList &columns=QStringList(), const QStringList &relation=QStringList()) |
|
template<class T > |
QSqlError | fetchAll (T &t, const QStringList &columns=QStringList(), const QStringList &relation=QStringList()) |
|
template<class T > |
QSqlError | fetchByQuery (const qx::QxSqlQuery &query, T &t, const QStringList &columns=QStringList(), const QStringList &relation=QStringList()) |
|
template<class T > |
QSqlError | insert (T &t, const QStringList &relation=QStringList(), bool bUseExecBatch=false) |
|
template<class T > |
QSqlError | update (T &t, const qx::QxSqlQuery &query=qx::QxSqlQuery(), const QStringList &columns=QStringList(), const QStringList &relation=QStringList(), bool bUseExecBatch=false) |
|
template<class T > |
QSqlError | save (T &t, const QStringList &relation=QStringList()) |
|
template<class T > |
QSqlError | deleteById (const QVariant &id) |
|
template<class T > |
QSqlError | deleteById (T &t, bool bUseExecBatch=false) |
|
template<class T > |
QSqlError | deleteAll () |
|
template<class T > |
QSqlError | deleteByQuery (const qx::QxSqlQuery &query) |
|
template<class T > |
QSqlError | destroyById (const QVariant &id) |
|
template<class T > |
QSqlError | destroyById (T &t, bool bUseExecBatch=false) |
|
template<class T > |
QSqlError | destroyAll () |
|
template<class T > |
QSqlError | destroyByQuery (const qx::QxSqlQuery &query) |
|
template<class T > |
QSqlError | executeQuery (qx::QxSqlQuery &query, T &t) |
|
QSqlError | callQuery (qx::QxSqlQuery &query) |
|
template<class T > |
qx_bool | exist (T &t) |
|
qx::QxSession : define a session to manage automatically database transactions (using C++ RAII)
A database transaction is a sequence of operations performed as a single logical unit of work. If no errors occurred during the execution of the transaction then the system commits the transaction. If an error occurs during the transaction, or if the user specifies a rollback operation, the data manipulations within the transaction are not persisted to the database.
The qx::QxSession class of QxOrm library is designed to manage automatically database transactions (using C++ RAII) :
{
if (! session.
isValid()) { qDebug(
"[QxOrm] session error : '%s'", qPrintable(session.
firstError().text())); }
}
qx::QxSession : define a session to manage automatically database transactions (using C++ RAII)
const QSqlDatabase * database() const
QSqlError firstError() const
QSqlError fetch_by_id(T &t, QSqlDatabase *pDatabase=NULL, const QStringList &columns=QStringList())
Fetch an object t (retrieve all its properties) of type T (registered into QxOrm context) mapped to a...
QSqlError delete_by_id(T &t, QSqlDatabase *pDatabase=NULL, bool bUseExecBatch=false)
Delete a line (or list of lines) of a table (database) mapped to a C++ object of type T (registered i...
QSqlError insert(T &t, QSqlDatabase *pDatabase=NULL, bool bUseExecBatch=false)
Insert an element or a list of elements into database.
QSqlError update(T &t, QSqlDatabase *pDatabase=NULL, const QStringList &columns=QStringList(), bool bUseExecBatch=false)
Update an element or a list of elements into database.
Note : a session can throw a qx::dao::sql_error exception when a SQL error occured (by default, there is no exception). You can setup this feature using :
Other note : don't forget to pass the session database connexion to each qx::dao::xxx functions (using session.database() method). Moreover, you can manage your own database connexion (from a connexion pool for example) using constructor of qx::QxSession class.
qx::QxSession class provides also persistent methods (CRUD) to make easier to write C++ code. Here is the same example using methods of qx::QxSession class instead of functions into namespace qx::dao :
{
if (! session.
isValid()) { qDebug(
"[QxOrm] session error : '%s'", qPrintable(session.
firstError().text())); }
}
QSqlError deleteById(const QVariant &id)
T * fetchById(const QVariant &id, const QStringList &columns=QStringList(), const QStringList &relation=QStringList())
QSqlError update(T &t, const qx::QxSqlQuery &query=qx::QxSqlQuery(), const QStringList &columns=QStringList(), const QStringList &relation=QStringList(), bool bUseExecBatch=false)
QSqlError insert(T &t, const QStringList &relation=QStringList(), bool bUseExecBatch=false)
Definition at line 118 of file QxSession.h.