| QxOrm 1.4.1 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 #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_FetchById;
    00068 template <class T> struct QxDao_FetchById_WithRelation;
    00069 template <class T> struct QxDao_FetchAll;
    00070 template <class T> struct QxDao_FetchAll_WithRelation;
    00071 template <class T> struct QxDao_Insert;
    00072 template <class T> struct QxDao_Insert_WithRelation;
    00073 template <class T> struct QxDao_Update;
    00074 template <class T> struct QxDao_Update_Optimized;
    00075 template <class T> struct QxDao_Update_WithRelation;
    00076 template <class T> struct QxDao_Save;
    00077 template <class T> struct QxDao_Save_WithRelation;
    00078 template <class T> struct QxDao_Save_WithRelation_Recursive;
    00079 template <class T> struct QxDao_DeleteById;
    00080 template <class T> struct QxDao_DeleteAll;
    00081 template <class T> struct QxDao_Exist;
    00082 template <class T> struct QxDao_CreateTable;
    00083 template <class T> struct QxDao_Trigger;
    00084 template <class T> struct QxDao_ExecuteQuery;
    00085 } // namespace detail
    00086
    00096 template <class T>
    00097 inline long count(const qx::QxSqlQuery & query = qx::QxSqlQuery(), QSqlDatabase * pDatabase = NULL)
    00098 { return qx::dao::detail::QxDao_Count<T>::count(query, pDatabase); }
    00099
    00110 template <class T>
    00111 inline QSqlError count(long & lCount, const qx::QxSqlQuery & query = qx::QxSqlQuery(), QSqlDatabase * pDatabase = NULL)
    00112 { return qx::dao::detail::QxDao_Count<T>::count(lCount, query, pDatabase); }
    00113
    00124 template <class T>
    00125 inline QSqlError insert(T & t, QSqlDatabase * pDatabase = NULL)
    00126 { return qx::dao::detail::QxDao_Insert<T>::insert(t, pDatabase); }
    00127
    00140 template <class T>
    00141 inline QSqlError save(T & t, QSqlDatabase * pDatabase = NULL)
    00142 { return qx::dao::detail::QxDao_Save<T>::save(t, pDatabase); }
    00143
    00157 template <class T>
    00158 inline QSqlError delete_by_id(T & t, QSqlDatabase * pDatabase = NULL)
    00159 { return qx::dao::detail::QxDao_DeleteById<T>::deleteById(t, pDatabase, true); }
    00160
    00171 template <class T>
    00172 inline QSqlError destroy_by_id(T & t, QSqlDatabase * pDatabase = NULL)
    00173 { return qx::dao::detail::QxDao_DeleteById<T>::deleteById(t, pDatabase, false); }
    00174
    00187 template <class T>
    00188 inline QSqlError delete_all(QSqlDatabase * pDatabase = NULL)
    00189 { return qx::dao::detail::QxDao_DeleteAll<T>::deleteAll("", pDatabase, true); }
    00190
    00200 template <class T>
    00201 inline QSqlError destroy_all(QSqlDatabase * pDatabase = NULL)
    00202 { return qx::dao::detail::QxDao_DeleteAll<T>::deleteAll("", pDatabase, false); }
    00203
    00217 template <class T>
    00218 inline QSqlError delete_by_query(const qx::QxSqlQuery & query, QSqlDatabase * pDatabase = NULL)
    00219 { return qx::dao::detail::QxDao_DeleteAll<T>::deleteAll(query, pDatabase, true); }
    00220
    00231 template <class T>
    00232 inline QSqlError destroy_by_query(const qx::QxSqlQuery & query, QSqlDatabase * pDatabase = NULL)
    00233 { return qx::dao::detail::QxDao_DeleteAll<T>::deleteAll(query, pDatabase, false); }
    00234
    00244 template <class T>
    00245 inline QSqlError create_table(QSqlDatabase * pDatabase = NULL)
    00246 { return qx::dao::detail::QxDao_CreateTable<T>::createTable(pDatabase); }
    00247
    00258 template <class T>
    00259 inline qx_bool exist(T & t, QSqlDatabase * pDatabase = NULL)
    00260 { return qx::dao::detail::QxDao_Exist<T>::exist(t, pDatabase); }
    00261
    00273 template <class T>
    00274 inline QSqlError fetch_by_id_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00275 { return qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById(relation, t, pDatabase); }
    00276
    00288 template <class T>
    00289 inline QSqlError fetch_by_id_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00290 { return qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById(relation, t, pDatabase); }
    00291
    00302 template <class T>
    00303 inline QSqlError fetch_by_id_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL)
    00304 { return qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById("*", t, pDatabase); }
    00305
    00317 template <class T>
    00318 inline QSqlError fetch_all_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00319 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, "", t, pDatabase); }
    00320
    00332 template <class T>
    00333 inline QSqlError fetch_all_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00334 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, "", t, pDatabase); }
    00335
    00346 template <class T>
    00347 inline QSqlError fetch_all_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL)
    00348 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll("*", "", t, pDatabase); }
    00349
    00362 template <class T>
    00363 inline QSqlError fetch_by_query_with_relation(const QString & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00364 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, query, t, pDatabase); }
    00365
    00378 template <class T>
    00379 inline QSqlError fetch_by_query_with_relation(const QStringList & 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
    00393 template <class T>
    00394 inline QSqlError fetch_by_query_with_all_relation(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00395 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll("*", query, t, pDatabase); }
    00396
    00408 template <class T>
    00409 inline QSqlError insert_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00410 { return qx::dao::detail::QxDao_Insert_WithRelation<T>::insert(relation, t, pDatabase); }
    00411
    00423 template <class T>
    00424 inline QSqlError insert_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00425 { return qx::dao::detail::QxDao_Insert_WithRelation<T>::insert(relation, t, pDatabase); }
    00426
    00437 template <class T>
    00438 inline QSqlError insert_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL)
    00439 { return qx::dao::detail::QxDao_Insert_WithRelation<T>::insert("*", t, pDatabase); }
    00440
    00452 template <class T>
    00453 inline QSqlError update_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00454 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, "", t, pDatabase); }
    00455
    00468 template <class T>
    00469 inline QSqlError update_by_query_with_relation(const QString & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00470 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, query, t, pDatabase); }
    00471
    00483 template <class T>
    00484 inline QSqlError update_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00485 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, "", t, pDatabase); }
    00486
    00499 template <class T>
    00500 inline QSqlError update_by_query_with_relation(const QStringList & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00501 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, query, t, pDatabase); }
    00502
    00513 template <class T>
    00514 inline QSqlError update_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL)
    00515 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update("*", "", t, pDatabase); }
    00516
    00528 template <class T>
    00529 inline QSqlError update_by_query_with_all_relation(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00530 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update("*", query, t, pDatabase); }
    00531
    00545 template <class T>
    00546 inline QSqlError save_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00547 { return qx::dao::detail::QxDao_Save_WithRelation<T>::save(relation, t, pDatabase); }
    00548
    00562 template <class T>
    00563 inline QSqlError save_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase = NULL)
    00564 { return qx::dao::detail::QxDao_Save_WithRelation<T>::save(relation, t, pDatabase); }
    00565
    00578 template <class T>
    00579 inline QSqlError save_with_all_relation(T & t, QSqlDatabase * pDatabase = NULL)
    00580 { return qx::dao::detail::QxDao_Save_WithRelation<T>::save("*", t, pDatabase); }
    00581
    00601 template <class T>
    00602 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)
    00603 { return qx::dao::detail::QxDao_Save_WithRelation_Recursive<T>::save(t, eSaveMode, pDatabase, pRelationParams); }
    00604
    00616 template <class T>
    00617 inline QSqlError fetch_by_id(T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList())
    00618 { return qx::dao::detail::QxDao_FetchById<T>::fetchById(t, pDatabase, columns); }
    00619
    00631 template <class T>
    00632 inline QSqlError fetch_all(T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList())
    00633 { return qx::dao::detail::QxDao_FetchAll<T>::fetchAll("", t, pDatabase, columns); }
    00634
    00647 template <class T>
    00648 inline QSqlError fetch_by_query(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList())
    00649 { return qx::dao::detail::QxDao_FetchAll<T>::fetchAll(query, t, pDatabase, columns); }
    00650
    00662 template <class T>
    00663 inline QSqlError update(T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList())
    00664 { return qx::dao::detail::QxDao_Update<T>::update("", t, pDatabase, columns); }
    00665
    00678 template <class T>
    00679 inline QSqlError update_by_query(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL, const QStringList & columns = QStringList())
    00680 { return qx::dao::detail::QxDao_Update<T>::update(query, t, pDatabase, columns); }
    00681
    00692 template <class T>
    00693 inline QSqlError update_optimized(qx::dao::ptr<T> & ptr, QSqlDatabase * pDatabase = NULL)
    00694 { return qx::dao::detail::QxDao_Update_Optimized<T>::update_optimized("", ptr, pDatabase); }
    00695
    00707 template <class T>
    00708 inline QSqlError update_optimized_by_query(const qx::QxSqlQuery & query, qx::dao::ptr<T> & ptr, QSqlDatabase * pDatabase = NULL)
    00709 { return qx::dao::detail::QxDao_Update_Optimized<T>::update_optimized(query, ptr, pDatabase); }
    00710
    00719 template <class T>
    00720 inline QSqlError execute_query(qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase = NULL)
    00721 { return qx::dao::detail::QxDao_ExecuteQuery<T>::executeQuery(query, t, pDatabase); }
    00722
    00727 template <class T>
    00728 inline void on_before_insert(T * t, qx::dao::detail::IxDao_Helper * dao)
    00729 { qx::dao::detail::QxDao_Trigger<T>::onBeforeInsert(t, dao); }
    00730
    00735 template <class T>
    00736 inline void on_before_update(T * t, qx::dao::detail::IxDao_Helper * dao)
    00737 { qx::dao::detail::QxDao_Trigger<T>::onBeforeUpdate(t, dao); }
    00738
    00743 template <class T>
    00744 inline void on_before_delete(T * t, qx::dao::detail::IxDao_Helper * dao)
    00745 { qx::dao::detail::QxDao_Trigger<T>::onBeforeDelete(t, dao); }
    00746
    00751 template <class T>
    00752 inline void on_before_fetch(T * t, qx::dao::detail::IxDao_Helper * dao)
    00753 { qx::dao::detail::QxDao_Trigger<T>::onBeforeFetch(t, dao); }
    00754
    00759 template <class T>
    00760 inline void on_after_insert(T * t, qx::dao::detail::IxDao_Helper * dao)
    00761 { qx::dao::detail::QxDao_Trigger<T>::onAfterInsert(t, dao); }
    00762
    00767 template <class T>
    00768 inline void on_after_update(T * t, qx::dao::detail::IxDao_Helper * dao)
    00769 { qx::dao::detail::QxDao_Trigger<T>::onAfterUpdate(t, dao); }
    00770
    00775 template <class T>
    00776 inline void on_after_delete(T * t, qx::dao::detail::IxDao_Helper * dao)
    00777 { qx::dao::detail::QxDao_Trigger<T>::onAfterDelete(t, dao); }
    00778
    00783 template <class T>
    00784 inline void on_after_fetch(T * t, qx::dao::detail::IxDao_Helper * dao)
    00785 { qx::dao::detail::QxDao_Trigger<T>::onAfterFetch(t, dao); }
    00786
    00787 } // namespace dao
    00788 } // namespace qx
    00789
    00790 #endif // _QX_DAO_H_