QxOrm
1.5.0
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 00100 template <class T> 00101 inline void insert(T & t, QSqlDatabase * pDatabase = NULL, bool bUseExecBatch = false) 00102 { QSqlError err = qx::dao::detail::QxDao_Insert<T>::insert(t, pDatabase, bUseExecBatch); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00103 00116 template <class T> 00117 inline void save(T & t, QSqlDatabase * pDatabase = NULL) 00118 { QSqlError err = qx::dao::detail::QxDao_Save<T>::save(t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00119 00134 template <class T> 00135 inline void delete_by_id(T & t, QSqlDatabase * pDatabase = NULL, bool bUseExecBatch = false) 00136 { QSqlError err = qx::dao::detail::QxDao_DeleteById<T>::deleteById(t, pDatabase, true, bUseExecBatch); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00137 00149 template <class T> 00150 inline void destroy_by_id(T & t, QSqlDatabase * pDatabase = NULL, bool bUseExecBatch = false) 00151 { QSqlError err = qx::dao::detail::QxDao_DeleteById<T>::deleteById(t, pDatabase, false, bUseExecBatch); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00152 00165 template <class T> 00166 inline void delete_all(QSqlDatabase * pDatabase = NULL) 00167 { QSqlError err = qx::dao::detail::QxDao_DeleteAll<T>::deleteAll("", pDatabase, true); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00168 00178 template <class T> 00179 inline void destroy_all(QSqlDatabase * pDatabase = NULL) 00180 { QSqlError err = qx::dao::detail::QxDao_DeleteAll<T>::deleteAll("", pDatabase, false); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00181 00195 template <class T> 00196 inline void delete_by_query(const qx::QxSqlQuery & query, QSqlDatabase * pDatabase = NULL) 00197 { QSqlError err = qx::dao::detail::QxDao_DeleteAll<T>::deleteAll(query, pDatabase, true); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00198 00209 template <class T> 00210 inline void destroy_by_query(const qx::QxSqlQuery & query, QSqlDatabase * pDatabase = NULL) 00211 { QSqlError err = qx::dao::detail::QxDao_DeleteAll<T>::deleteAll(query, pDatabase, false); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00212 00222 template <class T> 00223 inline void create_table(QSqlDatabase * pDatabase = NULL) 00224 { QSqlError err = qx::dao::detail::QxDao_CreateTable<T>::createTable(pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00225 00237 template <class T> 00238 inline void fetch_by_id_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL) 00239 { QSqlError err = qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById(relation, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00240 00252 template <class T> 00253 inline void fetch_by_id_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL) 00254 { QSqlError err = qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById(relation, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00255 00266 template <class T> 00267 inline void fetch_by_id_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL) 00268 { QSqlError err = qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById("*", t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00269 00281 template <class T> 00282 inline void fetch_all_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL) 00283 { QSqlError err = qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, "", t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00284 00296 template <class T> 00297 inline void fetch_all_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL) 00298 { QSqlError err = qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, "", t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00299 00310 template <class T> 00311 inline void fetch_all_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL) 00312 { QSqlError err = qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll("*", "", t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00313 00326 template <class T> 00327 inline void fetch_by_query_with_relation(const QString & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL) 00328 { QSqlError err = qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, query, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00329 00342 template <class T> 00343 inline void fetch_by_query_with_relation(const QStringList & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL) 00344 { QSqlError err = qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, query, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00345 00357 template <class T> 00358 inline void fetch_by_query_with_all_relation(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL) 00359 { QSqlError err = qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll("*", query, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00360 00372 template <class T> 00373 inline void insert_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL) 00374 { QSqlError err = qx::dao::detail::QxDao_Insert_WithRelation<T>::insert(relation, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00375 00387 template <class T> 00388 inline void insert_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL) 00389 { QSqlError err = qx::dao::detail::QxDao_Insert_WithRelation<T>::insert(relation, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00390 00401 template <class T> 00402 inline void insert_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL) 00403 { QSqlError err = qx::dao::detail::QxDao_Insert_WithRelation<T>::insert("*", t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00404 00416 template <class T> 00417 inline void update_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL) 00418 { QSqlError err = qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, "", t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00419 00432 template <class T> 00433 inline void update_by_query_with_relation(const QString & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL) 00434 { QSqlError err = qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, query, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00435 00447 template <class T> 00448 inline void update_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL) 00449 { QSqlError err = qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, "", t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00450 00463 template <class T> 00464 inline void update_by_query_with_relation(const QStringList & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL) 00465 { QSqlError err = qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, query, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00466 00477 template <class T> 00478 inline void update_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL) 00479 { QSqlError err = qx::dao::detail::QxDao_Update_WithRelation<T>::update("*", "", t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00480 00492 template <class T> 00493 inline void update_by_query_with_all_relation(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL) 00494 { QSqlError err = qx::dao::detail::QxDao_Update_WithRelation<T>::update("*", query, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00495 00509 template <class T> 00510 inline void save_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL) 00511 { QSqlError err = qx::dao::detail::QxDao_Save_WithRelation<T>::save(relation, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00512 00526 template <class T> 00527 inline void save_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL) 00528 { QSqlError err = qx::dao::detail::QxDao_Save_WithRelation<T>::save(relation, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00529 00542 template <class T> 00543 inline void save_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL) 00544 { QSqlError err = qx::dao::detail::QxDao_Save_WithRelation<T>::save("*", t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00545 00565 template <class T> 00566 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) 00567 { QSqlError err = qx::dao::detail::QxDao_Save_WithRelation_Recursive<T>::save(t, eSaveMode, pDatabase, pRelationParams); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00568 00580 template <class T> 00581 inline void fetch_by_id(T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList()) 00582 { QSqlError err = qx::dao::detail::QxDao_FetchById<T>::fetchById(t, pDatabase, columns); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00583 00595 template <class T> 00596 inline void fetch_all(T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList()) 00597 { QSqlError err = qx::dao::detail::QxDao_FetchAll<T>::fetchAll("", t, pDatabase, columns); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00598 00611 template <class T> 00612 inline void fetch_by_query(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList()) 00613 { QSqlError err = qx::dao::detail::QxDao_FetchAll<T>::fetchAll(query, t, pDatabase, columns); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00614 00627 template <class T> 00628 inline void update(T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList(), bool bUseExecBatch = false) 00629 { QSqlError err = qx::dao::detail::QxDao_Update<T>::update("", t, pDatabase, columns, bUseExecBatch); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00630 00644 template <class T> 00645 inline void update_by_query(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList(), bool bUseExecBatch = false) 00646 { QSqlError err = qx::dao::detail::QxDao_Update<T>::update(query, t, pDatabase, columns, bUseExecBatch); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00647 00659 template <class T> 00660 inline void update_optimized(qx::dao::ptr<T> & ptr, QSqlDatabase * pDatabase = NULL, bool bUseExecBatch = false) 00661 { QSqlError err = qx::dao::detail::QxDao_Update_Optimized<T>::update_optimized("", ptr, pDatabase, bUseExecBatch); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00662 00675 template <class T> 00676 inline void update_optimized_by_query(const qx::QxSqlQuery & query, qx::dao::ptr<T> & ptr, QSqlDatabase * pDatabase = NULL, bool bUseExecBatch = false) 00677 { QSqlError err = qx::dao::detail::QxDao_Update_Optimized<T>::update_optimized(query, ptr, pDatabase, bUseExecBatch); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00678 00687 template <class T> 00688 inline void execute_query(qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL) 00689 { QSqlError err = qx::dao::detail::QxDao_ExecuteQuery<T>::executeQuery(query, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00690 00691 inline void call_query(qx::QxSqlQuery & query, QSqlDatabase * pDatabase = NULL) 00692 { QSqlError err = qx::dao::call_query(query, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } } 00693 00695 00696 } // namespace throwable 00697 } // namespace dao 00698 } // namespace qx 00699 00700 #endif // _QX_DAO_THROWABLE_H_