| QxOrm 1.4.1 C++ Object Relational Mapping library

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

QxDaoThrowable.h
Go to the documentation of this file.

    00001 /****************************************************************************
    00002 **
    00003 ** http://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
    00084 template <class T>
    00085 inline void insert(T & t, QSqlDatabase * pDatabase = NULL)
    00086 { QSqlError err = qx::dao::detail::QxDao_Insert<T>::insert(t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
    00087
    00100 template <class T>
    00101 inline void save(T & t, QSqlDatabase * pDatabase = NULL)
    00102 { QSqlError err = qx::dao::detail::QxDao_Save<T>::save(t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
    00103
    00117 template <class T>
    00118 inline void delete_by_id(T & t, QSqlDatabase * pDatabase = NULL)
    00119 { QSqlError err = qx::dao::detail::QxDao_DeleteById<T>::deleteById(t, pDatabase, true); if (err.isValid()) { throw qx::dao::sql_error(err); } }
    00120
    00131 template <class T>
    00132 inline void destroy_by_id(T & t, QSqlDatabase * pDatabase = NULL)
    00133 { QSqlError err = qx::dao::detail::QxDao_DeleteById<T>::deleteById(t, pDatabase, false); if (err.isValid()) { throw qx::dao::sql_error(err); } }
    00134
    00147 template <class T>
    00148 inline void delete_all(QSqlDatabase * pDatabase = NULL)
    00149 { QSqlError err = qx::dao::detail::QxDao_DeleteAll<T>::deleteAll("", pDatabase, true); if (err.isValid()) { throw qx::dao::sql_error(err); } }
    00150
    00160 template <class T>
    00161 inline void destroy_all(QSqlDatabase * pDatabase = NULL)
    00162 { QSqlError err = qx::dao::detail::QxDao_DeleteAll<T>::deleteAll("", pDatabase, false); if (err.isValid()) { throw qx::dao::sql_error(err); } }
    00163
    00177 template <class T>
    00178 inline void delete_by_query(const qx::QxSqlQuery & query, QSqlDatabase * pDatabase = NULL)
    00179 { QSqlError err = qx::dao::detail::QxDao_DeleteAll<T>::deleteAll(query, pDatabase, true); if (err.isValid()) { throw qx::dao::sql_error(err); } }
    00180
    00191 template <class T>
    00192 inline void destroy_by_query(const qx::QxSqlQuery & query, QSqlDatabase * pDatabase = NULL)
    00193 { QSqlError err = qx::dao::detail::QxDao_DeleteAll<T>::deleteAll(query, pDatabase, false); if (err.isValid()) { throw qx::dao::sql_error(err); } }
    00194
    00204 template <class T>
    00205 inline void create_table(QSqlDatabase * pDatabase = NULL)
    00206 { QSqlError err = qx::dao::detail::QxDao_CreateTable<T>::createTable(pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
    00207
    00219 template <class T>
    00220 inline void fetch_by_id_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00221 { QSqlError err = qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById(relation, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
    00222
    00234 template <class T>
    00235 inline void fetch_by_id_with_relation(const QStringList & 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
    00248 template <class T>
    00249 inline void fetch_by_id_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL)
    00250 { QSqlError err = qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById("*", t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
    00251
    00263 template <class T>
    00264 inline void fetch_all_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00265 { QSqlError err = qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, "", t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
    00266
    00278 template <class T>
    00279 inline void fetch_all_with_relation(const QStringList & 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
    00292 template <class T>
    00293 inline void fetch_all_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL)
    00294 { QSqlError err = qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll("*", "", t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
    00295
    00308 template <class T>
    00309 inline void fetch_by_query_with_relation(const QString & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00310 { QSqlError err = qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, query, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
    00311
    00324 template <class T>
    00325 inline void fetch_by_query_with_relation(const QStringList & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00326 { QSqlError err = qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, query, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
    00327
    00339 template <class T>
    00340 inline void fetch_by_query_with_all_relation(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00341 { QSqlError err = qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll("*", query, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
    00342
    00354 template <class T>
    00355 inline void insert_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00356 { QSqlError err = qx::dao::detail::QxDao_Insert_WithRelation<T>::insert(relation, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
    00357
    00369 template <class T>
    00370 inline void insert_with_relation(const QStringList & 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
    00383 template <class T>
    00384 inline void insert_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL)
    00385 { QSqlError err = qx::dao::detail::QxDao_Insert_WithRelation<T>::insert("*", t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
    00386
    00398 template <class T>
    00399 inline void update_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00400 { QSqlError err = qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, "", t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
    00401
    00414 template <class T>
    00415 inline void update_by_query_with_relation(const QString & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00416 { QSqlError err = qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, query, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
    00417
    00429 template <class T>
    00430 inline void update_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00431 { QSqlError err = qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, "", t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
    00432
    00445 template <class T>
    00446 inline void update_by_query_with_relation(const QStringList & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00447 { QSqlError err = qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, query, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
    00448
    00459 template <class T>
    00460 inline void update_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL)
    00461 { QSqlError err = qx::dao::detail::QxDao_Update_WithRelation<T>::update("*", "", t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
    00462
    00474 template <class T>
    00475 inline void update_by_query_with_all_relation(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00476 { QSqlError err = qx::dao::detail::QxDao_Update_WithRelation<T>::update("*", query, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
    00477
    00491 template <class T>
    00492 inline void save_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00493 { QSqlError err = qx::dao::detail::QxDao_Save_WithRelation<T>::save(relation, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
    00494
    00508 template <class T>
    00509 inline void save_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00510 { QSqlError err = qx::dao::detail::QxDao_Save_WithRelation<T>::save(relation, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
    00511
    00524 template <class T>
    00525 inline void save_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL)
    00526 { QSqlError err = qx::dao::detail::QxDao_Save_WithRelation<T>::save("*", t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
    00527
    00547 template <class T>
    00548 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)
    00549 { QSqlError err = qx::dao::detail::QxDao_Save_WithRelation_Recursive<T>::save(t, eSaveMode, pDatabase, pRelationParams); if (err.isValid()) { throw qx::dao::sql_error(err); } }
    00550
    00562 template <class T>
    00563 inline void fetch_by_id(T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList())
    00564 { QSqlError err = qx::dao::detail::QxDao_FetchById<T>::fetchById(t, pDatabase, columns); if (err.isValid()) { throw qx::dao::sql_error(err); } }
    00565
    00577 template <class T>
    00578 inline void fetch_all(T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList())
    00579 { QSqlError err = qx::dao::detail::QxDao_FetchAll<T>::fetchAll("", t, pDatabase, columns); if (err.isValid()) { throw qx::dao::sql_error(err); } }
    00580
    00593 template <class T>
    00594 inline void fetch_by_query(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList())
    00595 { QSqlError err = qx::dao::detail::QxDao_FetchAll<T>::fetchAll(query, t, pDatabase, columns); if (err.isValid()) { throw qx::dao::sql_error(err); } }
    00596
    00608 template <class T>
    00609 inline void update(T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList())
    00610 { QSqlError err = qx::dao::detail::QxDao_Update<T>::update("", t, pDatabase, columns); if (err.isValid()) { throw qx::dao::sql_error(err); } }
    00611
    00624 template <class T>
    00625 inline void update_by_query(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList())
    00626 { QSqlError err = qx::dao::detail::QxDao_Update<T>::update(query, t, pDatabase, columns); if (err.isValid()) { throw qx::dao::sql_error(err); } }
    00627
    00638 template <class T>
    00639 inline void update_optimized(qx::dao::ptr<T> & ptr, QSqlDatabase * pDatabase = NULL)
    00640 { QSqlError err = qx::dao::detail::QxDao_Update_Optimized<T>::update_optimized("", ptr, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
    00641
    00653 template <class T>
    00654 inline void update_optimized_by_query(const qx::QxSqlQuery & query, qx::dao::ptr<T> & ptr, QSqlDatabase * pDatabase = NULL)
    00655 { QSqlError err = qx::dao::detail::QxDao_Update_Optimized<T>::update_optimized(query, ptr, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
    00656
    00665 template <class T>
    00666 inline void execute_query(qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00667 { QSqlError err = qx::dao::detail::QxDao_ExecuteQuery<T>::executeQuery(query, t, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
    00668
    00669 inline void call_query(qx::QxSqlQuery & query, QSqlDatabase * pDatabase = NULL)
    00670 { QSqlError err = qx::dao::call_query(query, pDatabase); if (err.isValid()) { throw qx::dao::sql_error(err); } }
    00671
    00673
    00674 } // namespace throwable
    00675 } // namespace dao
    00676 } // namespace qx
    00677
    00678 #endif // _QX_DAO_THROWABLE_H_