![]() |
QxOrm
1.4.7
C++ Object Relational Mapping library
|
00001 /**************************************************************************** 00002 ** 00003 ** https://www.qxorm.com/ 00004 ** Copyright (C) 2013 Lionel Marty (contact@qxorm.com) 00005 ** 00006 ** This file is part of the QxOrm library 00007 ** 00008 ** This software is provided 'as-is', without any express or implied 00009 ** warranty. In no event will the authors be held liable for any 00010 ** damages arising from the use of this software 00011 ** 00012 ** Commercial Usage 00013 ** Licensees holding valid commercial QxOrm licenses may use this file in 00014 ** accordance with the commercial license agreement provided with the 00015 ** Software or, alternatively, in accordance with the terms contained in 00016 ** a written agreement between you and Lionel Marty 00017 ** 00018 ** GNU General Public License Usage 00019 ** Alternatively, this file may be used under the terms of the GNU 00020 ** General Public License version 3.0 as published by the Free Software 00021 ** Foundation and appearing in the file 'license.gpl3.txt' included in the 00022 ** packaging of this file. Please review the following information to 00023 ** ensure the GNU General Public License version 3.0 requirements will be 00024 ** met : http://www.gnu.org/copyleft/gpl.html 00025 ** 00026 ** If you are unsure which license is appropriate for your use, or 00027 ** if you have questions regarding the use of this file, please contact : 00028 ** contact@qxorm.com 00029 ** 00030 ****************************************************************************/ 00031 00032 #ifndef _QX_DAO_THROWABLE_H_ 00033 #define _QX_DAO_THROWABLE_H_ 00034 00035 #ifdef _MSC_VER 00036 #pragma once 00037 #endif 00038 00046 #include <QxDao/QxDao.h> 00047 #include <QxDao/QxSqlError.h> 00048 00049 namespace qx { 00050 namespace dao { 00051 00056 namespace throwable { 00057 00059 00070 template <class T> 00071 inline void count(long & lCount, const qx::QxSqlQuery & query = qx::QxSqlQuery(), QSqlDatabase * pDatabase = NULL) 00072 { QSqlError err = qx::dao::detail::QxDao_Count<T>::count(lCount, query, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00073 00085 template <class T> 00086 inline void count_with_relation(long & lCount, const QStringList & relation, const qx::QxSqlQuery & query = qx::QxSqlQuery(), QSqlDatabase * pDatabase = NULL) 00087 { QSqlError err = qx::dao::detail::QxDao_Count_WithRelation<T>::count(lCount, relation, query, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00088 00099 template <class T> 00100 inline void insert(T & t, QSqlDatabase * pDatabase = NULL) 00101 { QSqlError err = qx::dao::detail::QxDao_Insert<T>::insert(t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00102 00115 template <class T> 00116 inline void save(T & t, QSqlDatabase * pDatabase = NULL) 00117 { QSqlError err = qx::dao::detail::QxDao_Save<T>::save(t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00118 00132 template <class T> 00133 inline void delete_by_id(T & t, QSqlDatabase * pDatabase = NULL) 00134 { QSqlError err = qx::dao::detail::QxDao_DeleteById<T>::deleteById(t, pDatabase, true); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00135 00146 template <class T> 00147 inline void destroy_by_id(T & t, QSqlDatabase * pDatabase = NULL) 00148 { QSqlError err = qx::dao::detail::QxDao_DeleteById<T>::deleteById(t, pDatabase, false); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00149 00162 template <class T> 00163 inline void delete_all(QSqlDatabase * pDatabase = NULL) 00164 { QSqlError err = qx::dao::detail::QxDao_DeleteAll<T>::deleteAll("", pDatabase, true); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00165 00175 template <class T> 00176 inline void destroy_all(QSqlDatabase * pDatabase = NULL) 00177 { QSqlError err = qx::dao::detail::QxDao_DeleteAll<T>::deleteAll("", pDatabase, false); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00178 00192 template <class T> 00193 inline void delete_by_query(const qx::QxSqlQuery & query, QSqlDatabase * pDatabase = NULL) 00194 { QSqlError err = qx::dao::detail::QxDao_DeleteAll<T>::deleteAll(query, pDatabase, true); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00195 00206 template <class T> 00207 inline void destroy_by_query(const qx::QxSqlQuery & query, QSqlDatabase * pDatabase = NULL) 00208 { QSqlError err = qx::dao::detail::QxDao_DeleteAll<T>::deleteAll(query, pDatabase, false); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00209 00219 template <class T> 00220 inline void create_table(QSqlDatabase * pDatabase = NULL) 00221 { QSqlError err = qx::dao::detail::QxDao_CreateTable<T>::createTable(pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00222 00234 template <class T> 00235 inline void fetch_by_id_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL) 00236 { QSqlError err = qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById(relation, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00237 00249 template <class T> 00250 inline void fetch_by_id_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL) 00251 { QSqlError err = qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById(relation, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00252 00263 template <class T> 00264 inline void fetch_by_id_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL) 00265 { QSqlError err = qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById("*", t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00266 00278 template <class T> 00279 inline void fetch_all_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL) 00280 { QSqlError err = qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, "", t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00281 00293 template <class T> 00294 inline void fetch_all_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL) 00295 { QSqlError err = qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, "", t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00296 00307 template <class T> 00308 inline void fetch_all_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL) 00309 { QSqlError err = qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll("*", "", t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00310 00323 template <class T> 00324 inline void fetch_by_query_with_relation(const QString & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL) 00325 { QSqlError err = qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, query, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00326 00339 template <class T> 00340 inline void fetch_by_query_with_relation(const QStringList & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL) 00341 { QSqlError err = qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, query, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00342 00354 template <class T> 00355 inline void fetch_by_query_with_all_relation(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL) 00356 { QSqlError err = qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll("*", query, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00357 00369 template <class T> 00370 inline void insert_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL) 00371 { QSqlError err = qx::dao::detail::QxDao_Insert_WithRelation<T>::insert(relation, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00372 00384 template <class T> 00385 inline void insert_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL) 00386 { QSqlError err = qx::dao::detail::QxDao_Insert_WithRelation<T>::insert(relation, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00387 00398 template <class T> 00399 inline void insert_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL) 00400 { QSqlError err = qx::dao::detail::QxDao_Insert_WithRelation<T>::insert("*", t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00401 00413 template <class T> 00414 inline void update_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL) 00415 { QSqlError err = qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, "", t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00416 00429 template <class T> 00430 inline void update_by_query_with_relation(const QString & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL) 00431 { QSqlError err = qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, query, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00432 00444 template <class T> 00445 inline void update_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL) 00446 { QSqlError err = qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, "", t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00447 00460 template <class T> 00461 inline void update_by_query_with_relation(const QStringList & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL) 00462 { QSqlError err = qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, query, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00463 00474 template <class T> 00475 inline void update_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL) 00476 { QSqlError err = qx::dao::detail::QxDao_Update_WithRelation<T>::update("*", "", t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00477 00489 template <class T> 00490 inline void update_by_query_with_all_relation(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL) 00491 { QSqlError err = qx::dao::detail::QxDao_Update_WithRelation<T>::update("*", query, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00492 00506 template <class T> 00507 inline void save_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL) 00508 { QSqlError err = qx::dao::detail::QxDao_Save_WithRelation<T>::save(relation, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00509 00523 template <class T> 00524 inline void save_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL) 00525 { QSqlError err = qx::dao::detail::QxDao_Save_WithRelation<T>::save(relation, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00526 00539 template <class T> 00540 inline void save_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL) 00541 { QSqlError err = qx::dao::detail::QxDao_Save_WithRelation<T>::save("*", t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00542 00562 template <class T> 00563 inline 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) 00564 { QSqlError err = qx::dao::detail::QxDao_Save_WithRelation_Recursive<T>::save(t, eSaveMode, pDatabase, pRelationParams); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00565 00577 template <class T> 00578 inline void fetch_by_id(T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList()) 00579 { QSqlError err = qx::dao::detail::QxDao_FetchById<T>::fetchById(t, pDatabase, columns); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00580 00592 template <class T> 00593 inline void fetch_all(T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList()) 00594 { QSqlError err = qx::dao::detail::QxDao_FetchAll<T>::fetchAll("", t, pDatabase, columns); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00595 00608 template <class T> 00609 inline void fetch_by_query(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList()) 00610 { QSqlError err = qx::dao::detail::QxDao_FetchAll<T>::fetchAll(query, t, pDatabase, columns); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00611 00623 template <class T> 00624 inline void update(T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList()) 00625 { QSqlError err = qx::dao::detail::QxDao_Update<T>::update("", t, pDatabase, columns); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00626 00639 template <class T> 00640 inline void update_by_query(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList()) 00641 { QSqlError err = qx::dao::detail::QxDao_Update<T>::update(query, t, pDatabase, columns); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00642 00653 template <class T> 00654 inline void update_optimized(qx::dao::ptr<T> & ptr, QSqlDatabase * pDatabase = NULL) 00655 { QSqlError err = qx::dao::detail::QxDao_Update_Optimized<T>::update_optimized("", ptr, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00656 00668 template <class T> 00669 inline void update_optimized_by_query(const qx::QxSqlQuery & query, qx::dao::ptr<T> & ptr, QSqlDatabase * pDatabase = NULL) 00670 { QSqlError err = qx::dao::detail::QxDao_Update_Optimized<T>::update_optimized(query, ptr, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00671 00680 template <class T> 00681 inline void execute_query(qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL) 00682 { QSqlError err = qx::dao::detail::QxDao_ExecuteQuery<T>::executeQuery(query, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00683 00684 inline void call_query(qx::QxSqlQuery & query, QSqlDatabase * pDatabase = NULL) 00685 { QSqlError err = qx::dao::call_query(query, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00686 00688 00689 } // namespace throwable 00690 } // namespace dao 00691 } // namespace qx 00692 00693 #endif // _QX_DAO_THROWABLE_H_