| QxOrm 1.2.5 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 ** 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_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
    00059 namespace qx {
    00060 namespace dao {
    00061
    00062 namespace detail {
    00063 class IxDao_Helper;
    00064 template <class T> struct QxDao_Count;
    00065 template <class T> struct QxDao_FetchById;
    00066 template <class T> struct QxDao_FetchById_WithRelation;
    00067 template <class T> struct QxDao_FetchAll;
    00068 template <class T> struct QxDao_FetchAll_WithRelation;
    00069 template <class T> struct QxDao_Insert;
    00070 template <class T> struct QxDao_Insert_WithRelation;
    00071 template <class T> struct QxDao_Update;
    00072 template <class T> struct QxDao_Update_Optimized;
    00073 template <class T> struct QxDao_Update_WithRelation;
    00074 template <class T> struct QxDao_Save;
    00075 template <class T> struct QxDao_Save_WithRelation;
    00076 template <class T> struct QxDao_DeleteById;
    00077 template <class T> struct QxDao_DeleteAll;
    00078 template <class T> struct QxDao_Exist;
    00079 template <class T> struct QxDao_CreateTable;
    00080 template <class T> struct QxDao_Trigger;
    00081 template <class T> struct QxDao_ExecuteQuery;
    00082 } // namespace detail
    00083
    00093 template <class T>
    00094 inline long count(const qx::QxSqlQuery & query = qx::QxSqlQuery(), QSqlDatabase * pDatabase = NULL)
    00095 { return qx::dao::detail::QxDao_Count<T>::count(query, pDatabase); }
    00096
    00107 template <class T>
    00108 inline QSqlError count(long & lCount, const qx::QxSqlQuery & query = qx::QxSqlQuery(), QSqlDatabase * pDatabase = NULL)
    00109 { return qx::dao::detail::QxDao_Count<T>::count(lCount, query, pDatabase); }
    00110
    00121 template <class T>
    00122 inline QSqlError insert(T & t, QSqlDatabase * pDatabase = NULL)
    00123 { return qx::dao::detail::QxDao_Insert<T>::insert(t, pDatabase); }
    00124
    00137 template <class T>
    00138 inline QSqlError save(T & t, QSqlDatabase * pDatabase = NULL)
    00139 { return qx::dao::detail::QxDao_Save<T>::save(t, pDatabase); }
    00140
    00154 template <class T>
    00155 inline QSqlError delete_by_id(T & t, QSqlDatabase * pDatabase = NULL)
    00156 { return qx::dao::detail::QxDao_DeleteById<T>::deleteById(t, pDatabase, true); }
    00157
    00168 template <class T>
    00169 inline QSqlError destroy_by_id(T & t, QSqlDatabase * pDatabase = NULL)
    00170 { return qx::dao::detail::QxDao_DeleteById<T>::deleteById(t, pDatabase, false); }
    00171
    00184 template <class T>
    00185 inline QSqlError delete_all(QSqlDatabase * pDatabase = NULL)
    00186 { return qx::dao::detail::QxDao_DeleteAll<T>::deleteAll("", pDatabase, true); }
    00187
    00197 template <class T>
    00198 inline QSqlError destroy_all(QSqlDatabase * pDatabase = NULL)
    00199 { return qx::dao::detail::QxDao_DeleteAll<T>::deleteAll("", pDatabase, false); }
    00200
    00214 template <class T>
    00215 inline QSqlError delete_by_query(const qx::QxSqlQuery & query, QSqlDatabase * pDatabase = NULL)
    00216 { return qx::dao::detail::QxDao_DeleteAll<T>::deleteAll(query, pDatabase, true); }
    00217
    00228 template <class T>
    00229 inline QSqlError destroy_by_query(const qx::QxSqlQuery & query, QSqlDatabase * pDatabase = NULL)
    00230 { return qx::dao::detail::QxDao_DeleteAll<T>::deleteAll(query, pDatabase, false); }
    00231
    00241 template <class T>
    00242 inline QSqlError create_table(QSqlDatabase * pDatabase = NULL)
    00243 { return qx::dao::detail::QxDao_CreateTable<T>::createTable(pDatabase); }
    00244
    00255 template <class T>
    00256 inline qx_bool exist(T & t, QSqlDatabase * pDatabase = NULL)
    00257 { return qx::dao::detail::QxDao_Exist<T>::exist(t, pDatabase); }
    00258
    00270 template <class T>
    00271 inline QSqlError fetch_by_id_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00272 { return qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById(relation, t, pDatabase); }
    00273
    00285 template <class T>
    00286 inline QSqlError fetch_by_id_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00287 { return qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById(relation, t, pDatabase); }
    00288
    00299 template <class T>
    00300 inline QSqlError fetch_by_id_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL)
    00301 { return qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById("*", t, pDatabase); }
    00302
    00314 template <class T>
    00315 inline QSqlError fetch_all_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00316 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, "", t, pDatabase); }
    00317
    00329 template <class T>
    00330 inline QSqlError fetch_all_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00331 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, "", t, pDatabase); }
    00332
    00343 template <class T>
    00344 inline QSqlError fetch_all_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL)
    00345 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll("*", "", t, pDatabase); }
    00346
    00359 template <class T>
    00360 inline QSqlError fetch_by_query_with_relation(const QString & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00361 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, query, t, pDatabase); }
    00362
    00375 template <class T>
    00376 inline QSqlError fetch_by_query_with_relation(const QStringList & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00377 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, query, t, pDatabase); }
    00378
    00390 template <class T>
    00391 inline QSqlError fetch_by_query_with_all_relation(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00392 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll("*", query, t, pDatabase); }
    00393
    00405 template <class T>
    00406 inline QSqlError insert_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00407 { return qx::dao::detail::QxDao_Insert_WithRelation<T>::insert(relation, t, pDatabase); }
    00408
    00420 template <class T>
    00421 inline QSqlError insert_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00422 { return qx::dao::detail::QxDao_Insert_WithRelation<T>::insert(relation, t, pDatabase); }
    00423
    00434 template <class T>
    00435 inline QSqlError insert_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL)
    00436 { return qx::dao::detail::QxDao_Insert_WithRelation<T>::insert("*", t, pDatabase); }
    00437
    00449 template <class T>
    00450 inline QSqlError update_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00451 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, "", t, pDatabase); }
    00452
    00465 template <class T>
    00466 inline QSqlError update_by_query_with_relation(const QString & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00467 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, query, t, pDatabase); }
    00468
    00480 template <class T>
    00481 inline QSqlError update_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00482 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, "", t, pDatabase); }
    00483
    00496 template <class T>
    00497 inline QSqlError update_by_query_with_relation(const QStringList & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00498 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, query, t, pDatabase); }
    00499
    00510 template <class T>
    00511 inline QSqlError update_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL)
    00512 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update("*", "", t, pDatabase); }
    00513
    00525 template <class T>
    00526 inline QSqlError update_by_query_with_all_relation(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00527 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update("*", query, t, pDatabase); }
    00528
    00542 template <class T>
    00543 inline QSqlError save_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00544 { return qx::dao::detail::QxDao_Save_WithRelation<T>::save(relation, t, pDatabase); }
    00545
    00559 template <class T>
    00560 inline QSqlError save_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00561 { return qx::dao::detail::QxDao_Save_WithRelation<T>::save(relation, t, pDatabase); }
    00562
    00575 template <class T>
    00576 inline QSqlError save_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL)
    00577 { return qx::dao::detail::QxDao_Save_WithRelation<T>::save("*", t, pDatabase); }
    00578
    00590 template <class T>
    00591 inline QSqlError fetch_by_id(T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList())
    00592 { return qx::dao::detail::QxDao_FetchById<T>::fetchById(t, pDatabase, columns); }
    00593
    00605 template <class T>
    00606 inline QSqlError fetch_all(T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList())
    00607 { return qx::dao::detail::QxDao_FetchAll<T>::fetchAll("", t, pDatabase, columns); }
    00608
    00621 template <class T>
    00622 inline QSqlError fetch_by_query(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList())
    00623 { return qx::dao::detail::QxDao_FetchAll<T>::fetchAll(query, t, pDatabase, columns); }
    00624
    00636 template <class T>
    00637 inline QSqlError update(T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList())
    00638 { return qx::dao::detail::QxDao_Update<T>::update("", t, pDatabase, columns); }
    00639
    00652 template <class T>
    00653 inline QSqlError update_by_query(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList())
    00654 { return qx::dao::detail::QxDao_Update<T>::update(query, t, pDatabase, columns); }
    00655
    00666 template <class T>
    00667 inline QSqlError update_optimized(qx::dao::ptr<T> & ptr, QSqlDatabase * pDatabase = NULL)
    00668 { return qx::dao::detail::QxDao_Update_Optimized<T>::update_optimized("", ptr, pDatabase); }
    00669
    00681 template <class T>
    00682 inline QSqlError update_optimized_by_query(const qx::QxSqlQuery & query, qx::dao::ptr<T> & ptr, QSqlDatabase * pDatabase = NULL)
    00683 { return qx::dao::detail::QxDao_Update_Optimized<T>::update_optimized(query, ptr, pDatabase); }
    00684
    00693 template <class T>
    00694 inline QSqlError execute_query(qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00695 { return qx::dao::detail::QxDao_ExecuteQuery<T>::executeQuery(query, t, pDatabase); }
    00696
    00701 template <class T>
    00702 inline void on_before_insert(T * t, qx::dao::detail::IxDao_Helper * dao)
    00703 { qx::dao::detail::QxDao_Trigger<T>::onBeforeInsert(t, dao); }
    00704
    00709 template <class T>
    00710 inline void on_before_update(T * t, qx::dao::detail::IxDao_Helper * dao)
    00711 { qx::dao::detail::QxDao_Trigger<T>::onBeforeUpdate(t, dao); }
    00712
    00717 template <class T>
    00718 inline void on_before_delete(T * t, qx::dao::detail::IxDao_Helper * dao)
    00719 { qx::dao::detail::QxDao_Trigger<T>::onBeforeDelete(t, dao); }
    00720
    00725 template <class T>
    00726 inline void on_before_fetch(T * t, qx::dao::detail::IxDao_Helper * dao)
    00727 { qx::dao::detail::QxDao_Trigger<T>::onBeforeFetch(t, dao); }
    00728
    00733 template <class T>
    00734 inline void on_after_insert(T * t, qx::dao::detail::IxDao_Helper * dao)
    00735 { qx::dao::detail::QxDao_Trigger<T>::onAfterInsert(t, dao); }
    00736
    00741 template <class T>
    00742 inline void on_after_update(T * t, qx::dao::detail::IxDao_Helper * dao)
    00743 { qx::dao::detail::QxDao_Trigger<T>::onAfterUpdate(t, dao); }
    00744
    00749 template <class T>
    00750 inline void on_after_delete(T * t, qx::dao::detail::IxDao_Helper * dao)
    00751 { qx::dao::detail::QxDao_Trigger<T>::onAfterDelete(t, dao); }
    00752
    00757 template <class T>
    00758 inline void on_after_fetch(T * t, qx::dao::detail::IxDao_Helper * dao)
    00759 { qx::dao::detail::QxDao_Trigger<T>::onAfterFetch(t, dao); }
    00760
    00761 } // namespace dao
    00762 } // namespace qx
    00763
    00764 #endif // _QX_DAO_H_