| QxOrm 1.4.9 C++ Object Relational Mapping library

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

- File List
- File Members

QxDao.h
Go to the documentation of this file.

    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_H_
    00033 #define _QX_DAO_H_
    00034
    00035 #ifdef _MSC_VER
    00036 #pragma once
    00037 #endif
    00038
    00046 #include <QtSql/qsqldatabase.h>
    00047 #include <QtSql/qsqlquery.h>
    00048 #include <QtSql/qsqlrecord.h>
    00049 #include <QtSql/qsqlfield.h>
    00050 #include <QtSql/qsqlerror.h>
    00051 #include <QtSql/qsqldriver.h>
    00052
    00053 #include <QxCommon/QxBool.h>
    00054
    00055 #include <QxDao/QxSoftDelete.h>
    00056 #include <QxDao/QxDaoPointer.h>
    00057 #include <QxDao/QxSqlQuery.h>
    00058 #include <QxDao/QxSqlSaveMode.h>
    00059
    00060 namespace qx {
    00061 class QxSqlRelationParams;
    00062 namespace dao {
    00063
    00064 namespace detail {
    00065 class IxDao_Helper;
    00066 template <class T> struct QxDao_Count;
    00067 template <class T> struct QxDao_Count_WithRelation;
    00068 template <class T> struct QxDao_FetchById;
    00069 template <class T> struct QxDao_FetchById_WithRelation;
    00070 template <class T> struct QxDao_FetchAll;
    00071 template <class T> struct QxDao_FetchAll_WithRelation;
    00072 template <class T> struct QxDao_Insert;
    00073 template <class T> struct QxDao_Insert_WithRelation;
    00074 template <class T> struct QxDao_Update;
    00075 template <class T> struct QxDao_Update_Optimized;
    00076 template <class T> struct QxDao_Update_WithRelation;
    00077 template <class T> struct QxDao_Save;
    00078 template <class T> struct QxDao_Save_WithRelation;
    00079 template <class T> struct QxDao_Save_WithRelation_Recursive;
    00080 template <class T> struct QxDao_DeleteById;
    00081 template <class T> struct QxDao_DeleteAll;
    00082 template <class T> struct QxDao_Exist;
    00083 template <class T> struct QxDao_CreateTable;
    00084 template <class T> struct QxDao_Trigger;
    00085 template <class T> struct QxDao_ExecuteQuery;
    00086 } // namespace detail
    00087
    00097 template <class T>
    00098 inline long count(const qx::QxSqlQuery & query = qx::QxSqlQuery(), QSqlDatabase * pDatabase = NULL)
    00099 { return qx::dao::detail::QxDao_Count<T>::count(query, pDatabase); }
    00100
    00111 template <class T>
    00112 inline QSqlError count(long & lCount, const qx::QxSqlQuery & query = qx::QxSqlQuery(), QSqlDatabase * pDatabase = NULL)
    00113 { return qx::dao::detail::QxDao_Count<T>::count(lCount, query, pDatabase); }
    00114
    00126 template <class T>
    00127 inline QSqlError count_with_relation(long & lCount, const QStringList & relation, const qx::QxSqlQuery & query = qx::QxSqlQuery(), QSqlDatabase * pDatabase = NULL)
    00128 { return qx::dao::detail::QxDao_Count_WithRelation<T>::count(lCount, relation, query, pDatabase); }
    00129
    00141 template <class T>
    00142 inline QSqlError insert(T & t, QSqlDatabase * pDatabase = NULL, bool bUseExecBatch = false)
    00143 { return qx::dao::detail::QxDao_Insert<T>::insert(t, pDatabase, bUseExecBatch); }
    00144
    00157 template <class T>
    00158 inline QSqlError save(T & t, QSqlDatabase * pDatabase = NULL)
    00159 { return qx::dao::detail::QxDao_Save<T>::save(t, pDatabase); }
    00160
    00175 template <class T>
    00176 inline QSqlError delete_by_id(T & t, QSqlDatabase * pDatabase = NULL, bool bUseExecBatch = false)
    00177 { return qx::dao::detail::QxDao_DeleteById<T>::deleteById(t, pDatabase, true, bUseExecBatch); }
    00178
    00190 template <class T>
    00191 inline QSqlError destroy_by_id(T & t, QSqlDatabase * pDatabase = NULL, bool bUseExecBatch = false)
    00192 { return qx::dao::detail::QxDao_DeleteById<T>::deleteById(t, pDatabase, false, bUseExecBatch); }
    00193
    00206 template <class T>
    00207 inline QSqlError delete_all(QSqlDatabase * pDatabase = NULL)
    00208 { return qx::dao::detail::QxDao_DeleteAll<T>::deleteAll("", pDatabase, true); }
    00209
    00219 template <class T>
    00220 inline QSqlError destroy_all(QSqlDatabase * pDatabase = NULL)
    00221 { return qx::dao::detail::QxDao_DeleteAll<T>::deleteAll("", pDatabase, false); }
    00222
    00236 template <class T>
    00237 inline QSqlError delete_by_query(const qx::QxSqlQuery & query, QSqlDatabase * pDatabase = NULL)
    00238 { return qx::dao::detail::QxDao_DeleteAll<T>::deleteAll(query, pDatabase, true); }
    00239
    00250 template <class T>
    00251 inline QSqlError destroy_by_query(const qx::QxSqlQuery & query, QSqlDatabase * pDatabase = NULL)
    00252 { return qx::dao::detail::QxDao_DeleteAll<T>::deleteAll(query, pDatabase, false); }
    00253
    00263 template <class T>
    00264 inline QSqlError create_table(QSqlDatabase * pDatabase = NULL)
    00265 { return qx::dao::detail::QxDao_CreateTable<T>::createTable(pDatabase); }
    00266
    00277 template <class T>
    00278 inline qx_bool exist(T & t, QSqlDatabase * pDatabase = NULL)
    00279 { return qx::dao::detail::QxDao_Exist<T>::exist(t, pDatabase); }
    00280
    00292 template <class T>
    00293 inline QSqlError fetch_by_id_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00294 { return qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById(relation, t, pDatabase); }
    00295
    00307 template <class T>
    00308 inline QSqlError fetch_by_id_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00309 { return qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById(relation, t, pDatabase); }
    00310
    00321 template <class T>
    00322 inline QSqlError fetch_by_id_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL)
    00323 { return qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById("*", t, pDatabase); }
    00324
    00336 template <class T>
    00337 inline QSqlError fetch_all_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00338 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, "", t, pDatabase); }
    00339
    00351 template <class T>
    00352 inline QSqlError fetch_all_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00353 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, "", t, pDatabase); }
    00354
    00365 template <class T>
    00366 inline QSqlError fetch_all_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL)
    00367 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll("*", "", t, pDatabase); }
    00368
    00381 template <class T>
    00382 inline QSqlError fetch_by_query_with_relation(const QString & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00383 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, query, t, pDatabase); }
    00384
    00397 template <class T>
    00398 inline QSqlError fetch_by_query_with_relation(const QStringList & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00399 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, query, t, pDatabase); }
    00400
    00412 template <class T>
    00413 inline QSqlError fetch_by_query_with_all_relation(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00414 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll("*", query, t, pDatabase); }
    00415
    00427 template <class T>
    00428 inline QSqlError insert_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00429 { return qx::dao::detail::QxDao_Insert_WithRelation<T>::insert(relation, t, pDatabase); }
    00430
    00442 template <class T>
    00443 inline QSqlError insert_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00444 { return qx::dao::detail::QxDao_Insert_WithRelation<T>::insert(relation, t, pDatabase); }
    00445
    00456 template <class T>
    00457 inline QSqlError insert_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL)
    00458 { return qx::dao::detail::QxDao_Insert_WithRelation<T>::insert("*", t, pDatabase); }
    00459
    00471 template <class T>
    00472 inline QSqlError update_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00473 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, "", t, pDatabase); }
    00474
    00487 template <class T>
    00488 inline QSqlError update_by_query_with_relation(const QString & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00489 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, query, t, pDatabase); }
    00490
    00502 template <class T>
    00503 inline QSqlError update_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00504 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, "", t, pDatabase); }
    00505
    00518 template <class T>
    00519 inline QSqlError update_by_query_with_relation(const QStringList & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00520 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, query, t, pDatabase); }
    00521
    00532 template <class T>
    00533 inline QSqlError update_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL)
    00534 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update("*", "", t, pDatabase); }
    00535
    00547 template <class T>
    00548 inline QSqlError update_by_query_with_all_relation(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00549 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update("*", query, t, pDatabase); }
    00550
    00564 template <class T>
    00565 inline QSqlError save_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00566 { return qx::dao::detail::QxDao_Save_WithRelation<T>::save(relation, t, pDatabase); }
    00567
    00581 template <class T>
    00582 inline QSqlError save_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00583 { return qx::dao::detail::QxDao_Save_WithRelation<T>::save(relation, t, pDatabase); }
    00584
    00597 template <class T>
    00598 inline QSqlError save_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL)
    00599 { return qx::dao::detail::QxDao_Save_WithRelation<T>::save("*", t, pDatabase); }
    00600
    00620 template <class T>
    00621 inline 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)
    00622 { return qx::dao::detail::QxDao_Save_WithRelation_Recursive<T>::save(t, eSaveMode, pDatabase, pRelationParams); }
    00623
    00635 template <class T>
    00636 inline QSqlError fetch_by_id(T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList())
    00637 { return qx::dao::detail::QxDao_FetchById<T>::fetchById(t, pDatabase, columns); }
    00638
    00650 template <class T>
    00651 inline QSqlError fetch_all(T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList())
    00652 { return qx::dao::detail::QxDao_FetchAll<T>::fetchAll("", t, pDatabase, columns); }
    00653
    00666 template <class T>
    00667 inline QSqlError fetch_by_query(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList())
    00668 { return qx::dao::detail::QxDao_FetchAll<T>::fetchAll(query, t, pDatabase, columns); }
    00669
    00682 template <class T>
    00683 inline QSqlError update(T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList(), bool bUseExecBatch = false)
    00684 { return qx::dao::detail::QxDao_Update<T>::update("", t, pDatabase, columns, bUseExecBatch); }
    00685
    00699 template <class T>
    00700 inline QSqlError update_by_query(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList(), bool bUseExecBatch = false)
    00701 { return qx::dao::detail::QxDao_Update<T>::update(query, t, pDatabase, columns, bUseExecBatch); }
    00702
    00714 template <class T>
    00715 inline QSqlError update_optimized(qx::dao::ptr<T> & ptr, QSqlDatabase * pDatabase = NULL, bool bUseExecBatch = false)
    00716 { return qx::dao::detail::QxDao_Update_Optimized<T>::update_optimized("", ptr, pDatabase, bUseExecBatch); }
    00717
    00730 template <class T>
    00731 inline QSqlError update_optimized_by_query(const qx::QxSqlQuery & query, qx::dao::ptr<T> & ptr, QSqlDatabase * pDatabase = NULL, bool bUseExecBatch = false)
    00732 { return qx::dao::detail::QxDao_Update_Optimized<T>::update_optimized(query, ptr, pDatabase, bUseExecBatch); }
    00733
    00742 template <class T>
    00743 inline QSqlError execute_query(qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00744 { return qx::dao::detail::QxDao_ExecuteQuery<T>::executeQuery(query, t, pDatabase); }
    00745
    00750 template <class T>
    00751 inline void on_before_insert(T * t, qx::dao::detail::IxDao_Helper * dao)
    00752 { qx::dao::detail::QxDao_Trigger<T>::onBeforeInsert(t, dao); }
    00753
    00758 template <class T>
    00759 inline void on_before_update(T * t, qx::dao::detail::IxDao_Helper * dao)
    00760 { qx::dao::detail::QxDao_Trigger<T>::onBeforeUpdate(t, dao); }
    00761
    00766 template <class T>
    00767 inline void on_before_delete(T * t, qx::dao::detail::IxDao_Helper * dao)
    00768 { qx::dao::detail::QxDao_Trigger<T>::onBeforeDelete(t, dao); }
    00769
    00774 template <class T>
    00775 inline void on_before_fetch(T * t, qx::dao::detail::IxDao_Helper * dao)
    00776 { qx::dao::detail::QxDao_Trigger<T>::onBeforeFetch(t, dao); }
    00777
    00782 template <class T>
    00783 inline void on_after_insert(T * t, qx::dao::detail::IxDao_Helper * dao)
    00784 { qx::dao::detail::QxDao_Trigger<T>::onAfterInsert(t, dao); }
    00785
    00790 template <class T>
    00791 inline void on_after_update(T * t, qx::dao::detail::IxDao_Helper * dao)
    00792 { qx::dao::detail::QxDao_Trigger<T>::onAfterUpdate(t, dao); }
    00793
    00798 template <class T>
    00799 inline void on_after_delete(T * t, qx::dao::detail::IxDao_Helper * dao)
    00800 { qx::dao::detail::QxDao_Trigger<T>::onAfterDelete(t, dao); }
    00801
    00806 template <class T>
    00807 inline void on_after_fetch(T * t, qx::dao::detail::IxDao_Helper * dao)
    00808 { qx::dao::detail::QxDao_Trigger<T>::onAfterFetch(t, dao); }
    00809
    00810 } // namespace dao
    00811 } // namespace qx
    00812
    00813 #endif // _QX_DAO_H_