QxOrm 1.4.9
C++ Object Relational Mapping library
Loading...
Searching...
No Matches
QxDaoThrowable.h
Go to the documentation of this file.
1/****************************************************************************
2**
3** https://www.qxorm.com/
4** Copyright (C) 2013 Lionel Marty (contact@qxorm.com)
5**
6** This file is part of the QxOrm library
7**
8** This software is provided 'as-is', without any express or implied
9** warranty. In no event will the authors be held liable for any
10** damages arising from the use of this software
11**
12** Commercial Usage
13** Licensees holding valid commercial QxOrm licenses may use this file in
14** accordance with the commercial license agreement provided with the
15** Software or, alternatively, in accordance with the terms contained in
16** a written agreement between you and Lionel Marty
17**
18** GNU General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU
20** General Public License version 3.0 as published by the Free Software
21** Foundation and appearing in the file 'license.gpl3.txt' included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU General Public License version 3.0 requirements will be
24** met : http://www.gnu.org/copyleft/gpl.html
25**
26** If you are unsure which license is appropriate for your use, or
27** if you have questions regarding the use of this file, please contact :
28** contact@qxorm.com
29**
30****************************************************************************/
31
32#ifndef _QX_DAO_THROWABLE_H_
33#define _QX_DAO_THROWABLE_H_
34
35#ifdef _MSC_VER
36#pragma once
37#endif
38
46#include <QxDao/QxDao.h>
47#include <QxDao/QxSqlError.h>
48
49namespace qx {
50namespace dao {
51
56namespace throwable {
57
59
70template <class T>
71inline void count(long & lCount, const qx::QxSqlQuery & query = qx::QxSqlQuery(), QSqlDatabase * pDatabase = NULL)
72{ QSqlError err = qx::dao::detail::QxDao_Count<T>::count(lCount, query, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
73
85template <class T>
86inline void count_with_relation(long & lCount, const QStringList & relation, const qx::QxSqlQuery & query = qx::QxSqlQuery(), QSqlDatabase * pDatabase = NULL)
87{ QSqlError err = qx::dao::detail::QxDao_Count_WithRelation<T>::count(lCount, relation, query, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
88
100template <class T>
101inline void insert(T & t, QSqlDatabase * pDatabase = NULL, bool bUseExecBatch = false)
102{ QSqlError err = qx::dao::detail::QxDao_Insert<T>::insert(t, pDatabase, bUseExecBatch); if (err.isValid()) { throw qx::dao::sql_error(err); } }
103
116template <class T>
117inline void save(T & t, QSqlDatabase * pDatabase = NULL)
118{ QSqlError err = qx::dao::detail::QxDao_Save<T>::save(t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
119
134template <class T>
135inline void delete_by_id(T & t, QSqlDatabase * pDatabase = NULL, bool bUseExecBatch = false)
136{ QSqlError err = qx::dao::detail::QxDao_DeleteById<T>::deleteById(t, pDatabase, true, bUseExecBatch); if (err.isValid()) { throw qx::dao::sql_error(err); } }
137
149template <class T>
150inline void destroy_by_id(T & t, QSqlDatabase * pDatabase = NULL, bool bUseExecBatch = false)
151{ QSqlError err = qx::dao::detail::QxDao_DeleteById<T>::deleteById(t, pDatabase, false, bUseExecBatch); if (err.isValid()) { throw qx::dao::sql_error(err); } }
152
165template <class T>
166inline void delete_all(QSqlDatabase * pDatabase = NULL)
167{ QSqlError err = qx::dao::detail::QxDao_DeleteAll<T>::deleteAll("", pDatabase, true); if (err.isValid()) { throw qx::dao::sql_error(err); } }
168
178template <class T>
179inline void destroy_all(QSqlDatabase * pDatabase = NULL)
180{ QSqlError err = qx::dao::detail::QxDao_DeleteAll<T>::deleteAll("", pDatabase, false); if (err.isValid()) { throw qx::dao::sql_error(err); } }
181
195template <class T>
196inline void delete_by_query(const qx::QxSqlQuery & query, QSqlDatabase * pDatabase = NULL)
197{ QSqlError err = qx::dao::detail::QxDao_DeleteAll<T>::deleteAll(query, pDatabase, true); if (err.isValid()) { throw qx::dao::sql_error(err); } }
198
209template <class T>
210inline void destroy_by_query(const qx::QxSqlQuery & query, QSqlDatabase * pDatabase = NULL)
211{ QSqlError err = qx::dao::detail::QxDao_DeleteAll<T>::deleteAll(query, pDatabase, false); if (err.isValid()) { throw qx::dao::sql_error(err); } }
212
222template <class T>
223inline void create_table(QSqlDatabase * pDatabase = NULL)
224{ QSqlError err = qx::dao::detail::QxDao_CreateTable<T>::createTable(pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
225
237template <class T>
238inline void fetch_by_id_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL)
239{ QSqlError err = qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById(relation, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
240
252template <class T>
253inline void fetch_by_id_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL)
254{ QSqlError err = qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById(relation, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
255
266template <class T>
267inline void fetch_by_id_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL)
268{ QSqlError err = qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById("*", t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
269
281template <class T>
282inline void fetch_all_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL)
283{ QSqlError err = qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, "", t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
284
296template <class T>
297inline void fetch_all_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL)
298{ QSqlError err = qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, "", t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
299
310template <class T>
311inline void fetch_all_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL)
312{ QSqlError err = qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll("*", "", t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
313
326template <class T>
327inline void fetch_by_query_with_relation(const QString & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
328{ QSqlError err = qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, query, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
329
342template <class T>
343inline void fetch_by_query_with_relation(const QStringList & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
344{ QSqlError err = qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, query, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
345
357template <class T>
358inline void fetch_by_query_with_all_relation(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
359{ QSqlError err = qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll("*", query, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
360
372template <class T>
373inline void insert_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL)
374{ QSqlError err = qx::dao::detail::QxDao_Insert_WithRelation<T>::insert(relation, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
375
387template <class T>
388inline void insert_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL)
389{ QSqlError err = qx::dao::detail::QxDao_Insert_WithRelation<T>::insert(relation, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
390
401template <class T>
402inline void insert_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL)
403{ QSqlError err = qx::dao::detail::QxDao_Insert_WithRelation<T>::insert("*", t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
404
416template <class T>
417inline void update_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL)
418{ QSqlError err = qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, "", t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
419
432template <class T>
433inline void update_by_query_with_relation(const QString & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
434{ QSqlError err = qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, query, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
435
447template <class T>
448inline void update_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL)
449{ QSqlError err = qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, "", t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
450
463template <class T>
464inline void update_by_query_with_relation(const QStringList & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
465{ QSqlError err = qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, query, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
466
477template <class T>
478inline void update_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL)
479{ QSqlError err = qx::dao::detail::QxDao_Update_WithRelation<T>::update("*", "", t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
480
492template <class T>
493inline void update_by_query_with_all_relation(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
494{ QSqlError err = qx::dao::detail::QxDao_Update_WithRelation<T>::update("*", query, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
495
509template <class T>
510inline void save_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL)
511{ QSqlError err = qx::dao::detail::QxDao_Save_WithRelation<T>::save(relation, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
512
526template <class T>
527inline void save_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL)
528{ QSqlError err = qx::dao::detail::QxDao_Save_WithRelation<T>::save(relation, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
529
542template <class T>
543inline void save_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL)
544{ QSqlError err = qx::dao::detail::QxDao_Save_WithRelation<T>::save("*", t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
545
565template <class T>
566inline void save_with_relation_recursive(T & t, qx::dao::save_mode::e_save_mode eSaveMode = qx::dao::save_mode::e_check_insert_or_update, QSqlDatabase * pDatabase = NULL, qx::QxSqlRelationParams * pRelationParams = NULL)
567{ QSqlError err = qx::dao::detail::QxDao_Save_WithRelation_Recursive<T>::save(t, eSaveMode, pDatabase, pRelationParams); if (err.isValid()) { throw qx::dao::sql_error(err); } }
568
580template <class T>
581inline void fetch_by_id(T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList())
582{ QSqlError err = qx::dao::detail::QxDao_FetchById<T>::fetchById(t, pDatabase, columns); if (err.isValid()) { throw qx::dao::sql_error(err); } }
583
595template <class T>
596inline void fetch_all(T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList())
597{ QSqlError err = qx::dao::detail::QxDao_FetchAll<T>::fetchAll("", t, pDatabase, columns); if (err.isValid()) { throw qx::dao::sql_error(err); } }
598
611template <class T>
612inline void fetch_by_query(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList())
613{ QSqlError err = qx::dao::detail::QxDao_FetchAll<T>::fetchAll(query, t, pDatabase, columns); if (err.isValid()) { throw qx::dao::sql_error(err); } }
614
627template <class T>
628inline void update(T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList(), bool bUseExecBatch = false)
629{ QSqlError err = qx::dao::detail::QxDao_Update<T>::update("", t, pDatabase, columns, bUseExecBatch); if (err.isValid()) { throw qx::dao::sql_error(err); } }
630
644template <class T>
645inline void update_by_query(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList(), bool bUseExecBatch = false)
646{ QSqlError err = qx::dao::detail::QxDao_Update<T>::update(query, t, pDatabase, columns, bUseExecBatch); if (err.isValid()) { throw qx::dao::sql_error(err); } }
647
659template <class T>
660inline void update_optimized(qx::dao::ptr<T> & ptr, QSqlDatabase * pDatabase = NULL, bool bUseExecBatch = false)
661{ QSqlError err = qx::dao::detail::QxDao_Update_Optimized<T>::update_optimized("", ptr, pDatabase, bUseExecBatch); if (err.isValid()) { throw qx::dao::sql_error(err); } }
662
675template <class T>
676inline void update_optimized_by_query(const qx::QxSqlQuery & query, qx::dao::ptr<T> & ptr, QSqlDatabase * pDatabase = NULL, bool bUseExecBatch = false)
677{ QSqlError err = qx::dao::detail::QxDao_Update_Optimized<T>::update_optimized(query, ptr, pDatabase, bUseExecBatch); if (err.isValid()) { throw qx::dao::sql_error(err); } }
678
687template <class T>
688inline void execute_query(qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
689{ QSqlError err = qx::dao::detail::QxDao_ExecuteQuery<T>::executeQuery(query, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
690
691inline void call_query(qx::QxSqlQuery & query, QSqlDatabase * pDatabase = NULL)
692{ QSqlError err = qx::dao::call_query(query, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
693
695
696} // namespace throwable
697} // namespace dao
698} // namespace qx
699
700#endif // _QX_DAO_THROWABLE_H_
Provide template functions to map C++ class registered into QxOrm context with table database (ORM - ...
Define a SQL error exception and retrieve QSqlError type of Qt library.
qx::QxSqlQuery : define a user SQL query added to default SQL query builded by QxOrm library,...
Definition QxSqlQuery.h:245
qx::QxSqlRelationParams : define list of parameters to transfer to relationships to manage SQL querie...
qx::dao::ptr<T> : provide a classic smart-pointer (like boost::shared_ptr<T> or QSharedPointer<T>) wi...
qx::dao::sql_error : define a SQL error exception and retrieve QSqlError type of Qt library
Definition QxSqlError.h:61
QSqlError destroy_all(QSqlDatabase *pDatabase=NULL)
Destroy all lines of a table (database) mapped to a C++ class T (registered into QxOrm context),...
Definition QxDao.h:220
QSqlError execute_query(qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase=NULL)
Execute a custom SQL query or a stored procedure, all columns that can be mapped to the instance of t...
Definition QxDao.h:743
QSqlError update_with_all_relation(T &t, QSqlDatabase *pDatabase=NULL)
Update an element and all its relationships (or a list of elements + all relationships) into database...
Definition QxDao.h:533
QSqlError save(T &t, QSqlDatabase *pDatabase=NULL)
Insert (if no exist) or update (if already exist) an element or a list of elements into database.
Definition QxDao.h:158
QSqlError update_with_relation(const QString &relation, T &t, QSqlDatabase *pDatabase=NULL)
Update an element and its relationships (or a list of elements + relationships) into database.
Definition QxDao.h:472
QSqlError update_by_query_with_all_relation(const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase=NULL)
Update an element and all its relationships (or a list of elements + all relationships) into database...
Definition QxDao.h:548
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...
Definition QxDao.h:636
QSqlError fetch_by_query_with_relation(const QString &relation, const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase=NULL)
Fetch a list of objects (retrieve all elements and properties associated) of type T (container regist...
Definition QxDao.h:382
QX_DLL_EXPORT QSqlError call_query(qx::QxSqlQuery &query, QSqlDatabase *pDatabase=NULL)
qx::dao::call_query function can be used to call a custom SQL query or a stored procedure
QSqlError fetch_by_id_with_relation(const QString &relation, T &t, QSqlDatabase *pDatabase=NULL)
Fetch an object t (retrieve all its properties) of type T (registered into QxOrm context) mapped to a...
Definition QxDao.h:293
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...
Definition QxDao.h:176
QSqlError insert_with_all_relation(T &t, QSqlDatabase *pDatabase=NULL)
Insert an element and all its relationships (or a list of elements + all relationships) into database...
Definition QxDao.h:457
QSqlError save_with_relation(const QString &relation, T &t, QSqlDatabase *pDatabase=NULL)
Insert (if no exist) or update (if already exist) an element and its relationships (or a list of elem...
Definition QxDao.h:565
QSqlError insert_with_relation(const QString &relation, T &t, QSqlDatabase *pDatabase=NULL)
Insert an element and its relationships (or a list of elements + relationships) into database.
Definition QxDao.h:428
QSqlError insert(T &t, QSqlDatabase *pDatabase=NULL, bool bUseExecBatch=false)
Insert an element or a list of elements into database.
Definition QxDao.h:142
QSqlError destroy_by_query(const qx::QxSqlQuery &query, QSqlDatabase *pDatabase=NULL)
Destroy all lines of a table (database) mapped to a C++ class T (registered into QxOrm context) and f...
Definition QxDao.h:251
QSqlError save_with_all_relation(T &t, QSqlDatabase *pDatabase=NULL)
Insert (if no exist) or update (if already exist) an element and all its relationships (or a list of ...
Definition QxDao.h:598
QSqlError delete_all(QSqlDatabase *pDatabase=NULL)
Delete all lines of a table (database) mapped to a C++ class T (registered into QxOrm context)
Definition QxDao.h:207
QSqlError update_by_query(const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase=NULL, const QStringList &columns=QStringList(), bool bUseExecBatch=false)
Update an element or a list of elements into database (adding a user SQL query to the default SQL que...
Definition QxDao.h:700
QSqlError fetch_by_query(const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase=NULL, const QStringList &columns=QStringList())
Fetch a list of objects (retrieve all elements and properties associated) of type T (container regist...
Definition QxDao.h:667
QSqlError update_by_query_with_relation(const QString &relation, const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase=NULL)
Update an element and its relationships (or a list of elements + relationships) into database (adding...
Definition QxDao.h:488
QSqlError update(T &t, QSqlDatabase *pDatabase=NULL, const QStringList &columns=QStringList(), bool bUseExecBatch=false)
Update an element or a list of elements into database.
Definition QxDao.h:683
QSqlError fetch_all(T &t, QSqlDatabase *pDatabase=NULL, const QStringList &columns=QStringList())
Fetch a list of objects (retrieve all elements and properties associated) of type T (container regist...
Definition QxDao.h:651
QSqlError update_optimized_by_query(const qx::QxSqlQuery &query, qx::dao::ptr< T > &ptr, QSqlDatabase *pDatabase=NULL, bool bUseExecBatch=false)
Update only modified fields/properties of an element or a list of elements into database (using is di...
Definition QxDao.h:731
QSqlError fetch_by_query_with_all_relation(const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase=NULL)
Fetch a list of objects (retrieve all elements and properties + all relationships associated) of type...
Definition QxDao.h:413
QSqlError delete_by_query(const qx::QxSqlQuery &query, QSqlDatabase *pDatabase=NULL)
Delete all lines of a table (database) mapped to a C++ class T (registered into QxOrm context) and fi...
Definition QxDao.h:237
QSqlError update_optimized(qx::dao::ptr< T > &ptr, QSqlDatabase *pDatabase=NULL, bool bUseExecBatch=false)
Update only modified fields/properties of an element or a list of elements into database (using is di...
Definition QxDao.h:715
QSqlError create_table(QSqlDatabase *pDatabase=NULL)
Create a table into database (with all columns) mapped to a C++ class T (registered into QxOrm contex...
Definition QxDao.h:264
QSqlError count_with_relation(long &lCount, const QStringList &relation, const qx::QxSqlQuery &query=qx::QxSqlQuery(), QSqlDatabase *pDatabase=NULL)
Return the number of lines in the table (database) mapped to the C++ class T (registered into QxOrm c...
Definition QxDao.h:127
QSqlError fetch_all_with_relation(const QString &relation, T &t, QSqlDatabase *pDatabase=NULL)
Fetch a list of objects (retrieve all elements and properties associated) of type T (container regist...
Definition QxDao.h:337
QSqlError save_with_relation_recursive(T &t, qx::dao::save_mode::e_save_mode eSaveMode=qx::dao::save_mode::e_check_insert_or_update, QSqlDatabase *pDatabase=NULL, qx::QxSqlRelationParams *pRelationParams=NULL)
Insert (if no exist) or update (if already exist) recursively an element and all levels of relationsh...
Definition QxDao.h:621
long count(const qx::QxSqlQuery &query=qx::QxSqlQuery(), QSqlDatabase *pDatabase=NULL)
Return the number of lines in the table (database) mapped to the C++ class T (registered into QxOrm c...
Definition QxDao.h:98
QSqlError fetch_by_id_with_all_relation(T &t, QSqlDatabase *pDatabase=NULL)
Fetch an object t (retrieve all its properties and relationships) of type T (registered into QxOrm co...
Definition QxDao.h:322
QSqlError destroy_by_id(T &t, QSqlDatabase *pDatabase=NULL, bool bUseExecBatch=false)
Destroy a line (or list of lines) of a table (database) mapped to a C++ object of type T (registered ...
Definition QxDao.h:191
QSqlError fetch_all_with_all_relation(T &t, QSqlDatabase *pDatabase=NULL)
Fetch a list of objects (retrieve all elements and properties + all relationships associated) of type...
Definition QxDao.h:366
Root namespace for all QxOrm library features.