| QxOrm 1.4.8 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
    00140 template <class T>
    00141 inline QSqlError insert(T & t, QSqlDatabase * pDatabase = NULL)
    00142 { return qx::dao::detail::QxDao_Insert<T>::insert(t, pDatabase); }
    00143
    00156 template <class T>
    00157 inline QSqlError save(T & t, QSqlDatabase * pDatabase = NULL)
    00158 { return qx::dao::detail::QxDao_Save<T>::save(t, pDatabase); }
    00159
    00173 template <class T>
    00174 inline QSqlError delete_by_id(T & t, QSqlDatabase * pDatabase = NULL)
    00175 { return qx::dao::detail::QxDao_DeleteById<T>::deleteById(t, pDatabase, true); }
    00176
    00187 template <class T>
    00188 inline QSqlError destroy_by_id(T & t, QSqlDatabase * pDatabase = NULL)
    00189 { return qx::dao::detail::QxDao_DeleteById<T>::deleteById(t, pDatabase, false); }
    00190
    00203 template <class T>
    00204 inline QSqlError delete_all(QSqlDatabase * pDatabase = NULL)
    00205 { return qx::dao::detail::QxDao_DeleteAll<T>::deleteAll("", pDatabase, true); }
    00206
    00216 template <class T>
    00217 inline QSqlError destroy_all(QSqlDatabase * pDatabase = NULL)
    00218 { return qx::dao::detail::QxDao_DeleteAll<T>::deleteAll("", pDatabase, false); }
    00219
    00233 template <class T>
    00234 inline QSqlError delete_by_query(const qx::QxSqlQuery & query, QSqlDatabase * pDatabase = NULL)
    00235 { return qx::dao::detail::QxDao_DeleteAll<T>::deleteAll(query, pDatabase, true); }
    00236
    00247 template <class T>
    00248 inline QSqlError destroy_by_query(const qx::QxSqlQuery & query, QSqlDatabase * pDatabase = NULL)
    00249 { return qx::dao::detail::QxDao_DeleteAll<T>::deleteAll(query, pDatabase, false); }
    00250
    00260 template <class T>
    00261 inline QSqlError create_table(QSqlDatabase * pDatabase = NULL)
    00262 { return qx::dao::detail::QxDao_CreateTable<T>::createTable(pDatabase); }
    00263
    00274 template <class T>
    00275 inline qx_bool exist(T & t, QSqlDatabase * pDatabase = NULL)
    00276 { return qx::dao::detail::QxDao_Exist<T>::exist(t, pDatabase); }
    00277
    00289 template <class T>
    00290 inline QSqlError fetch_by_id_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00291 { return qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById(relation, t, pDatabase); }
    00292
    00304 template <class T>
    00305 inline QSqlError fetch_by_id_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00306 { return qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById(relation, t, pDatabase); }
    00307
    00318 template <class T>
    00319 inline QSqlError fetch_by_id_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL)
    00320 { return qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById("*", t, pDatabase); }
    00321
    00333 template <class T>
    00334 inline QSqlError fetch_all_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00335 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, "", t, pDatabase); }
    00336
    00348 template <class T>
    00349 inline QSqlError fetch_all_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00350 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, "", t, pDatabase); }
    00351
    00362 template <class T>
    00363 inline QSqlError fetch_all_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL)
    00364 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll("*", "", t, pDatabase); }
    00365
    00378 template <class T>
    00379 inline QSqlError fetch_by_query_with_relation(const QString & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00380 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, query, t, pDatabase); }
    00381
    00394 template <class T>
    00395 inline QSqlError fetch_by_query_with_relation(const QStringList & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00396 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, query, t, pDatabase); }
    00397
    00409 template <class T>
    00410 inline QSqlError fetch_by_query_with_all_relation(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00411 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll("*", query, t, pDatabase); }
    00412
    00424 template <class T>
    00425 inline QSqlError insert_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00426 { return qx::dao::detail::QxDao_Insert_WithRelation<T>::insert(relation, t, pDatabase); }
    00427
    00439 template <class T>
    00440 inline QSqlError insert_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00441 { return qx::dao::detail::QxDao_Insert_WithRelation<T>::insert(relation, t, pDatabase); }
    00442
    00453 template <class T>
    00454 inline QSqlError insert_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL)
    00455 { return qx::dao::detail::QxDao_Insert_WithRelation<T>::insert("*", t, pDatabase); }
    00456
    00468 template <class T>
    00469 inline QSqlError update_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00470 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, "", t, pDatabase); }
    00471
    00484 template <class T>
    00485 inline QSqlError update_by_query_with_relation(const QString & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00486 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, query, t, pDatabase); }
    00487
    00499 template <class T>
    00500 inline QSqlError update_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00501 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, "", t, pDatabase); }
    00502
    00515 template <class T>
    00516 inline QSqlError update_by_query_with_relation(const QStringList & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00517 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, query, t, pDatabase); }
    00518
    00529 template <class T>
    00530 inline QSqlError update_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL)
    00531 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update("*", "", t, pDatabase); }
    00532
    00544 template <class T>
    00545 inline QSqlError update_by_query_with_all_relation(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00546 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update("*", query, t, pDatabase); }
    00547
    00561 template <class T>
    00562 inline QSqlError save_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00563 { return qx::dao::detail::QxDao_Save_WithRelation<T>::save(relation, t, pDatabase); }
    00564
    00578 template <class T>
    00579 inline QSqlError save_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00580 { return qx::dao::detail::QxDao_Save_WithRelation<T>::save(relation, t, pDatabase); }
    00581
    00594 template <class T>
    00595 inline QSqlError save_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL)
    00596 { return qx::dao::detail::QxDao_Save_WithRelation<T>::save("*", t, pDatabase); }
    00597
    00617 template <class T>
    00618 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)
    00619 { return qx::dao::detail::QxDao_Save_WithRelation_Recursive<T>::save(t, eSaveMode, pDatabase, pRelationParams); }
    00620
    00632 template <class T>
    00633 inline QSqlError fetch_by_id(T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList())
    00634 { return qx::dao::detail::QxDao_FetchById<T>::fetchById(t, pDatabase, columns); }
    00635
    00647 template <class T>
    00648 inline QSqlError fetch_all(T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList())
    00649 { return qx::dao::detail::QxDao_FetchAll<T>::fetchAll("", t, pDatabase, columns); }
    00650
    00663 template <class T>
    00664 inline QSqlError fetch_by_query(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList())
    00665 { return qx::dao::detail::QxDao_FetchAll<T>::fetchAll(query, t, pDatabase, columns); }
    00666
    00678 template <class T>
    00679 inline QSqlError update(T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList())
    00680 { return qx::dao::detail::QxDao_Update<T>::update("", t, pDatabase, columns); }
    00681
    00694 template <class T>
    00695 inline QSqlError update_by_query(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList())
    00696 { return qx::dao::detail::QxDao_Update<T>::update(query, t, pDatabase, columns); }
    00697
    00708 template <class T>
    00709 inline QSqlError update_optimized(qx::dao::ptr<T> & ptr, QSqlDatabase * pDatabase = NULL)
    00710 { return qx::dao::detail::QxDao_Update_Optimized<T>::update_optimized("", ptr, pDatabase); }
    00711
    00723 template <class T>
    00724 inline QSqlError update_optimized_by_query(const qx::QxSqlQuery & query, qx::dao::ptr<T> & ptr, QSqlDatabase * pDatabase = NULL)
    00725 { return qx::dao::detail::QxDao_Update_Optimized<T>::update_optimized(query, ptr, pDatabase); }
    00726
    00735 template <class T>
    00736 inline QSqlError execute_query(qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00737 { return qx::dao::detail::QxDao_ExecuteQuery<T>::executeQuery(query, t, pDatabase); }
    00738
    00743 template <class T>
    00744 inline void on_before_insert(T * t, qx::dao::detail::IxDao_Helper * dao)
    00745 { qx::dao::detail::QxDao_Trigger<T>::onBeforeInsert(t, dao); }
    00746
    00751 template <class T>
    00752 inline void on_before_update(T * t, qx::dao::detail::IxDao_Helper * dao)
    00753 { qx::dao::detail::QxDao_Trigger<T>::onBeforeUpdate(t, dao); }
    00754
    00759 template <class T>
    00760 inline void on_before_delete(T * t, qx::dao::detail::IxDao_Helper * dao)
    00761 { qx::dao::detail::QxDao_Trigger<T>::onBeforeDelete(t, dao); }
    00762
    00767 template <class T>
    00768 inline void on_before_fetch(T * t, qx::dao::detail::IxDao_Helper * dao)
    00769 { qx::dao::detail::QxDao_Trigger<T>::onBeforeFetch(t, dao); }
    00770
    00775 template <class T>
    00776 inline void on_after_insert(T * t, qx::dao::detail::IxDao_Helper * dao)
    00777 { qx::dao::detail::QxDao_Trigger<T>::onAfterInsert(t, dao); }
    00778
    00783 template <class T>
    00784 inline void on_after_update(T * t, qx::dao::detail::IxDao_Helper * dao)
    00785 { qx::dao::detail::QxDao_Trigger<T>::onAfterUpdate(t, dao); }
    00786
    00791 template <class T>
    00792 inline void on_after_delete(T * t, qx::dao::detail::IxDao_Helper * dao)
    00793 { qx::dao::detail::QxDao_Trigger<T>::onAfterDelete(t, dao); }
    00794
    00799 template <class T>
    00800 inline void on_after_fetch(T * t, qx::dao::detail::IxDao_Helper * dao)
    00801 { qx::dao::detail::QxDao_Trigger<T>::onAfterFetch(t, dao); }
    00802
    00803 } // namespace dao
    00804 } // namespace qx
    00805
    00806 #endif // _QX_DAO_H_