| QxOrm 1.2.4 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 ** http://sourceforge.net/projects/qxorm/
    00005 ** Original file by Lionel Marty
    00006 **
    00007 ** This file is part of the QxOrm library
    00008 **
    00009 ** This software is provided 'as-is', without any express or implied
    00010 ** warranty. In no event will the authors be held liable for any
    00011 ** damages arising from the use of this software.
    00012 **
    00013 ** GNU Lesser General Public License Usage
    00014 ** This file must be used under the terms of the GNU Lesser
    00015 ** General Public License version 2.1 as published by the Free Software
    00016 ** Foundation and appearing in the file 'license.lgpl.txt' included in the
    00017 ** packaging of this file.  Please review the following information to
    00018 ** ensure the GNU Lesser General Public License version 2.1 requirements
    00019 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    00020 **
    00021 ** If you have questions regarding the use of this file, please contact :
    00022 ** contact@qxorm.com
    00023 **
    00024 ****************************************************************************/
    00025
    00026 #ifndef _QX_DAO_H_
    00027 #define _QX_DAO_H_
    00028
    00029 #ifdef _MSC_VER
    00030 #pragma once
    00031 #endif
    00032
    00040 #include <QtSql/qsqldatabase.h>
    00041 #include <QtSql/qsqlquery.h>
    00042 #include <QtSql/qsqlrecord.h>
    00043 #include <QtSql/qsqlfield.h>
    00044 #include <QtSql/qsqlerror.h>
    00045 #include <QtSql/qsqldriver.h>
    00046
    00047 #include <QxCommon/QxBool.h>
    00048
    00049 #include <QxDao/QxSoftDelete.h>
    00050 #include <QxDao/QxDaoPointer.h>
    00051 #include <QxDao/QxSqlQuery.h>
    00052
    00053 namespace qx {
    00054 namespace dao {
    00055
    00056 namespace detail {
    00057 class IxDao_Helper;
    00058 template <class T> struct QxDao_Count;
    00059 template <class T> struct QxDao_FetchById;
    00060 template <class T> struct QxDao_FetchById_WithRelation;
    00061 template <class T> struct QxDao_FetchAll;
    00062 template <class T> struct QxDao_FetchAll_WithRelation;
    00063 template <class T> struct QxDao_Insert;
    00064 template <class T> struct QxDao_Insert_WithRelation;
    00065 template <class T> struct QxDao_Update;
    00066 template <class T> struct QxDao_Update_Optimized;
    00067 template <class T> struct QxDao_Update_WithRelation;
    00068 template <class T> struct QxDao_Save;
    00069 template <class T> struct QxDao_Save_WithRelation;
    00070 template <class T> struct QxDao_DeleteById;
    00071 template <class T> struct QxDao_DeleteAll;
    00072 template <class T> struct QxDao_Exist;
    00073 template <class T> struct QxDao_CreateTable;
    00074 template <class T> struct QxDao_Trigger;
    00075 template <class T> struct QxDao_ExecuteQuery;
    00076 } // namespace detail
    00077
    00087 template <class T>
    00088 inline long count(const qx::QxSqlQuery & query = qx::QxSqlQuery(), QSqlDatabase * pDatabase = NULL)
    00089 { return qx::dao::detail::QxDao_Count<T>::count(query, pDatabase); }
    00090
    00101 template <class T>
    00102 inline QSqlError count(long & lCount, const qx::QxSqlQuery & query = qx::QxSqlQuery(), QSqlDatabase * pDatabase = NULL)
    00103 { return qx::dao::detail::QxDao_Count<T>::count(lCount, query, pDatabase); }
    00104
    00115 template <class T>
    00116 inline QSqlError insert(T & t, QSqlDatabase * pDatabase = NULL)
    00117 { return qx::dao::detail::QxDao_Insert<T>::insert(t, pDatabase); }
    00118
    00131 template <class T>
    00132 inline QSqlError save(T & t, QSqlDatabase * pDatabase = NULL)
    00133 { return qx::dao::detail::QxDao_Save<T>::save(t, pDatabase); }
    00134
    00148 template <class T>
    00149 inline QSqlError delete_by_id(T & t, QSqlDatabase * pDatabase = NULL)
    00150 { return qx::dao::detail::QxDao_DeleteById<T>::deleteById(t, pDatabase, true); }
    00151
    00162 template <class T>
    00163 inline QSqlError destroy_by_id(T & t, QSqlDatabase * pDatabase = NULL)
    00164 { return qx::dao::detail::QxDao_DeleteById<T>::deleteById(t, pDatabase, false); }
    00165
    00178 template <class T>
    00179 inline QSqlError delete_all(QSqlDatabase * pDatabase = NULL)
    00180 { return qx::dao::detail::QxDao_DeleteAll<T>::deleteAll("", pDatabase, true); }
    00181
    00191 template <class T>
    00192 inline QSqlError destroy_all(QSqlDatabase * pDatabase = NULL)
    00193 { return qx::dao::detail::QxDao_DeleteAll<T>::deleteAll("", pDatabase, false); }
    00194
    00208 template <class T>
    00209 inline QSqlError delete_by_query(const qx::QxSqlQuery & query, QSqlDatabase * pDatabase = NULL)
    00210 { return qx::dao::detail::QxDao_DeleteAll<T>::deleteAll(query, pDatabase, true); }
    00211
    00222 template <class T>
    00223 inline QSqlError destroy_by_query(const qx::QxSqlQuery & query, QSqlDatabase * pDatabase = NULL)
    00224 { return qx::dao::detail::QxDao_DeleteAll<T>::deleteAll(query, pDatabase, false); }
    00225
    00235 template <class T>
    00236 inline QSqlError create_table(QSqlDatabase * pDatabase = NULL)
    00237 { return qx::dao::detail::QxDao_CreateTable<T>::createTable(pDatabase); }
    00238
    00249 template <class T>
    00250 inline qx_bool exist(T & t, QSqlDatabase * pDatabase = NULL)
    00251 { return qx::dao::detail::QxDao_Exist<T>::exist(t, pDatabase); }
    00252
    00264 template <class T>
    00265 inline QSqlError fetch_by_id_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00266 { return qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById(relation, t, pDatabase); }
    00267
    00279 template <class T>
    00280 inline QSqlError fetch_by_id_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00281 { return qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById(relation, t, pDatabase); }
    00282
    00293 template <class T>
    00294 inline QSqlError fetch_by_id_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL)
    00295 { return qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById("*", t, pDatabase); }
    00296
    00308 template <class T>
    00309 inline QSqlError fetch_all_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00310 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, "", t, pDatabase); }
    00311
    00323 template <class T>
    00324 inline QSqlError fetch_all_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00325 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, "", t, pDatabase); }
    00326
    00337 template <class T>
    00338 inline QSqlError fetch_all_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL)
    00339 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll("*", "", t, pDatabase); }
    00340
    00353 template <class T>
    00354 inline QSqlError fetch_by_query_with_relation(const QString & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00355 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, query, t, pDatabase); }
    00356
    00369 template <class T>
    00370 inline QSqlError fetch_by_query_with_relation(const QStringList & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00371 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, query, t, pDatabase); }
    00372
    00384 template <class T>
    00385 inline QSqlError fetch_by_query_with_all_relation(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00386 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll("*", query, t, pDatabase); }
    00387
    00399 template <class T>
    00400 inline QSqlError insert_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00401 { return qx::dao::detail::QxDao_Insert_WithRelation<T>::insert(relation, t, pDatabase); }
    00402
    00414 template <class T>
    00415 inline QSqlError insert_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00416 { return qx::dao::detail::QxDao_Insert_WithRelation<T>::insert(relation, t, pDatabase); }
    00417
    00428 template <class T>
    00429 inline QSqlError insert_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL)
    00430 { return qx::dao::detail::QxDao_Insert_WithRelation<T>::insert("*", t, pDatabase); }
    00431
    00443 template <class T>
    00444 inline QSqlError update_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00445 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, "", t, pDatabase); }
    00446
    00459 template <class T>
    00460 inline QSqlError update_by_query_with_relation(const QString & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00461 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, query, t, pDatabase); }
    00462
    00474 template <class T>
    00475 inline QSqlError update_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00476 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, "", t, pDatabase); }
    00477
    00490 template <class T>
    00491 inline QSqlError update_by_query_with_relation(const QStringList & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00492 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, query, t, pDatabase); }
    00493
    00504 template <class T>
    00505 inline QSqlError update_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL)
    00506 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update("*", "", t, pDatabase); }
    00507
    00519 template <class T>
    00520 inline QSqlError update_by_query_with_all_relation(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00521 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update("*", query, t, pDatabase); }
    00522
    00536 template <class T>
    00537 inline QSqlError save_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00538 { return qx::dao::detail::QxDao_Save_WithRelation<T>::save(relation, t, pDatabase); }
    00539
    00553 template <class T>
    00554 inline QSqlError save_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00555 { return qx::dao::detail::QxDao_Save_WithRelation<T>::save(relation, t, pDatabase); }
    00556
    00569 template <class T>
    00570 inline QSqlError save_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL)
    00571 { return qx::dao::detail::QxDao_Save_WithRelation<T>::save("*", t, pDatabase); }
    00572
    00584 template <class T>
    00585 inline QSqlError fetch_by_id(T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList())
    00586 { return qx::dao::detail::QxDao_FetchById<T>::fetchById(t, pDatabase, columns); }
    00587
    00599 template <class T>
    00600 inline QSqlError fetch_all(T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList())
    00601 { return qx::dao::detail::QxDao_FetchAll<T>::fetchAll("", t, pDatabase, columns); }
    00602
    00615 template <class T>
    00616 inline QSqlError fetch_by_query(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList())
    00617 { return qx::dao::detail::QxDao_FetchAll<T>::fetchAll(query, t, pDatabase, columns); }
    00618
    00630 template <class T>
    00631 inline QSqlError update(T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList())
    00632 { return qx::dao::detail::QxDao_Update<T>::update("", t, pDatabase, columns); }
    00633
    00646 template <class T>
    00647 inline QSqlError update_by_query(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList())
    00648 { return qx::dao::detail::QxDao_Update<T>::update(query, t, pDatabase, columns); }
    00649
    00660 template <class T>
    00661 inline QSqlError update_optimized(qx::dao::ptr<T> & ptr, QSqlDatabase * pDatabase = NULL)
    00662 { return qx::dao::detail::QxDao_Update_Optimized<T>::update_optimized("", ptr, pDatabase); }
    00663
    00675 template <class T>
    00676 inline QSqlError update_optimized_by_query(const qx::QxSqlQuery & query, qx::dao::ptr<T> & ptr, QSqlDatabase * pDatabase = NULL)
    00677 { return qx::dao::detail::QxDao_Update_Optimized<T>::update_optimized(query, ptr, pDatabase); }
    00678
    00687 template <class T>
    00688 inline QSqlError execute_query(qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00689 { return qx::dao::detail::QxDao_ExecuteQuery<T>::executeQuery(query, t, pDatabase); }
    00690
    00695 template <class T>
    00696 inline void on_before_insert(T * t, qx::dao::detail::IxDao_Helper * dao)
    00697 { qx::dao::detail::QxDao_Trigger<T>::onBeforeInsert(t, dao); }
    00698
    00703 template <class T>
    00704 inline void on_before_update(T * t, qx::dao::detail::IxDao_Helper * dao)
    00705 { qx::dao::detail::QxDao_Trigger<T>::onBeforeUpdate(t, dao); }
    00706
    00711 template <class T>
    00712 inline void on_before_delete(T * t, qx::dao::detail::IxDao_Helper * dao)
    00713 { qx::dao::detail::QxDao_Trigger<T>::onBeforeDelete(t, dao); }
    00714
    00719 template <class T>
    00720 inline void on_before_fetch(T * t, qx::dao::detail::IxDao_Helper * dao)
    00721 { qx::dao::detail::QxDao_Trigger<T>::onBeforeFetch(t, dao); }
    00722
    00727 template <class T>
    00728 inline void on_after_insert(T * t, qx::dao::detail::IxDao_Helper * dao)
    00729 { qx::dao::detail::QxDao_Trigger<T>::onAfterInsert(t, dao); }
    00730
    00735 template <class T>
    00736 inline void on_after_update(T * t, qx::dao::detail::IxDao_Helper * dao)
    00737 { qx::dao::detail::QxDao_Trigger<T>::onAfterUpdate(t, dao); }
    00738
    00743 template <class T>
    00744 inline void on_after_delete(T * t, qx::dao::detail::IxDao_Helper * dao)
    00745 { qx::dao::detail::QxDao_Trigger<T>::onAfterDelete(t, dao); }
    00746
    00751 template <class T>
    00752 inline void on_after_fetch(T * t, qx::dao::detail::IxDao_Helper * dao)
    00753 { qx::dao::detail::QxDao_Trigger<T>::onAfterFetch(t, dao); }
    00754
    00755 } // namespace dao
    00756 } // namespace qx
    00757
    00758 #endif // _QX_DAO_H_