QxOrm 1.1.8
C++ Object Relational Mapping library
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 struct 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 } // namespace detail
00076 
00085 template <class T>
00086 inline long count(QSqlDatabase * pDatabase)
00087 { return qx::dao::detail::QxDao_Count<T>::count("", pDatabase); }
00088 
00098 template <class T>
00099 inline long count(const qx::QxSqlQuery & query, QSqlDatabase * pDatabase)
00100 { return qx::dao::detail::QxDao_Count<T>::count(query, pDatabase); }
00101 
00112 template <class T>
00113 inline QSqlError fetch_by_id(T & t, QSqlDatabase * pDatabase)
00114 { return qx::dao::detail::QxDao_FetchById<T>::fetchById(t, pDatabase, QStringList()); }
00115 
00126 template <class T>
00127 inline QSqlError fetch_all(T & t, QSqlDatabase * pDatabase)
00128 { return qx::dao::detail::QxDao_FetchAll<T>::fetchAll("", t, pDatabase, QStringList()); }
00129 
00141 template <class T>
00142 inline QSqlError fetch_by_query(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase)
00143 { return qx::dao::detail::QxDao_FetchAll<T>::fetchAll(query, t, pDatabase, QStringList()); }
00144 
00155 template <class T>
00156 inline QSqlError insert(T & t, QSqlDatabase * pDatabase)
00157 { return qx::dao::detail::QxDao_Insert<T>::insert(t, pDatabase); }
00158 
00169 template <class T>
00170 inline QSqlError update(T & t, QSqlDatabase * pDatabase)
00171 { return qx::dao::detail::QxDao_Update<T>::update("", t, pDatabase, QStringList()); }
00172 
00184 template <class T>
00185 inline QSqlError update_by_query(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase)
00186 { return qx::dao::detail::QxDao_Update<T>::update(query, t, pDatabase, QStringList()); }
00187 
00200 template <class T>
00201 inline QSqlError save(T & t, QSqlDatabase * pDatabase)
00202 { return qx::dao::detail::QxDao_Save<T>::save(t, pDatabase); }
00203 
00217 template <class T>
00218 inline QSqlError delete_by_id(T & t, QSqlDatabase * pDatabase)
00219 { return qx::dao::detail::QxDao_DeleteById<T>::deleteById(t, pDatabase, true); }
00220 
00231 template <class T>
00232 inline QSqlError destroy_by_id(T & t, QSqlDatabase * pDatabase)
00233 { return qx::dao::detail::QxDao_DeleteById<T>::deleteById(t, pDatabase, false); }
00234 
00247 template <class T>
00248 inline QSqlError delete_all(QSqlDatabase * pDatabase)
00249 { return qx::dao::detail::QxDao_DeleteAll<T>::deleteAll("", pDatabase, true); }
00250 
00260 template <class T>
00261 inline QSqlError destroy_all(QSqlDatabase * pDatabase)
00262 { return qx::dao::detail::QxDao_DeleteAll<T>::deleteAll("", pDatabase, false); }
00263 
00277 template <class T>
00278 inline QSqlError delete_by_query(const qx::QxSqlQuery & query, QSqlDatabase * pDatabase)
00279 { return qx::dao::detail::QxDao_DeleteAll<T>::deleteAll(query, pDatabase, true); }
00280 
00291 template <class T>
00292 inline QSqlError destroy_by_query(const qx::QxSqlQuery & query, QSqlDatabase * pDatabase)
00293 { return qx::dao::detail::QxDao_DeleteAll<T>::deleteAll(query, pDatabase, false); }
00294 
00304 template <class T>
00305 inline QSqlError create_table(QSqlDatabase * pDatabase)
00306 { return qx::dao::detail::QxDao_CreateTable<T>::createTable(pDatabase); }
00307 
00318 template <class T>
00319 inline qx_bool exist(T & t, QSqlDatabase * pDatabase)
00320 { return qx::dao::detail::QxDao_Exist<T>::exist(t, pDatabase); }
00321 
00333 template <class T>
00334 inline QSqlError fetch_by_id_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase)
00335 { return qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById(relation, t, pDatabase); }
00336 
00348 template <class T>
00349 inline QSqlError fetch_by_id_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase)
00350 { return qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById(relation, t, pDatabase); }
00351 
00362 template <class T>
00363 inline QSqlError fetch_by_id_with_all_relation(T & t, QSqlDatabase * pDatabase)
00364 { return qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById("*", t, pDatabase); }
00365 
00377 template <class T>
00378 inline QSqlError fetch_all_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase)
00379 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, "", t, pDatabase); }
00380 
00392 template <class T>
00393 inline QSqlError fetch_all_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase)
00394 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, "", t, pDatabase); }
00395 
00406 template <class T>
00407 inline QSqlError fetch_all_with_all_relation(T & t, QSqlDatabase * pDatabase)
00408 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll("*", "", t, pDatabase); }
00409 
00422 template <class T>
00423 inline QSqlError fetch_by_query_with_relation(const QString & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase)
00424 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, query, t, pDatabase); }
00425 
00438 template <class T>
00439 inline QSqlError fetch_by_query_with_relation(const QStringList & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase)
00440 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, query, t, pDatabase); }
00441 
00453 template <class T>
00454 inline QSqlError fetch_by_query_with_all_relation(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase)
00455 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll("*", query, t, pDatabase); }
00456 
00468 template <class T>
00469 inline QSqlError insert_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase)
00470 { return qx::dao::detail::QxDao_Insert_WithRelation<T>::insert(relation, t, pDatabase); }
00471 
00483 template <class T>
00484 inline QSqlError insert_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase)
00485 { return qx::dao::detail::QxDao_Insert_WithRelation<T>::insert(relation, t, pDatabase); }
00486 
00497 template <class T>
00498 inline QSqlError insert_with_all_relation(T & t, QSqlDatabase * pDatabase)
00499 { return qx::dao::detail::QxDao_Insert_WithRelation<T>::insert("*", t, pDatabase); }
00500 
00512 template <class T>
00513 inline QSqlError update_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase)
00514 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, "", t, pDatabase); }
00515 
00528 template <class T>
00529 inline QSqlError update_by_query_with_relation(const QString & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase)
00530 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, query, t, pDatabase); }
00531 
00543 template <class T>
00544 inline QSqlError update_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase)
00545 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, "", t, pDatabase); }
00546 
00559 template <class T>
00560 inline QSqlError update_by_query_with_relation(const QStringList & relation, const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase)
00561 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, query, t, pDatabase); }
00562 
00573 template <class T>
00574 inline QSqlError update_with_all_relation(T & t, QSqlDatabase * pDatabase)
00575 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update("*", "", t, pDatabase); }
00576 
00588 template <class T>
00589 inline QSqlError update_by_query_with_all_relation(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase)
00590 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update("*", query, t, pDatabase); }
00591 
00605 template <class T>
00606 inline QSqlError save_with_relation(const QString & relation, T & t, QSqlDatabase * pDatabase)
00607 { return qx::dao::detail::QxDao_Save_WithRelation<T>::save(relation, t, pDatabase); }
00608 
00622 template <class T>
00623 inline QSqlError save_with_relation(const QStringList & relation, T & t, QSqlDatabase * pDatabase)
00624 { return qx::dao::detail::QxDao_Save_WithRelation<T>::save(relation, t, pDatabase); }
00625 
00638 template <class T>
00639 inline QSqlError save_with_all_relation(T & t, QSqlDatabase * pDatabase)
00640 { return qx::dao::detail::QxDao_Save_WithRelation<T>::save("*", t, pDatabase); }
00641 
00649 template <class T>
00650 inline long count()
00651 { return qx::dao::detail::QxDao_Count<T>::count("", NULL); }
00652 
00661 template <class T>
00662 inline long count(const qx::QxSqlQuery & query)
00663 { return qx::dao::detail::QxDao_Count<T>::count(query, NULL); }
00664 
00674 template <class T>
00675 inline QSqlError fetch_by_id(T & t)
00676 { return qx::dao::detail::QxDao_FetchById<T>::fetchById(t, NULL, QStringList()); }
00677 
00687 template <class T>
00688 inline QSqlError fetch_all(T & t)
00689 { return qx::dao::detail::QxDao_FetchAll<T>::fetchAll("", t, NULL, QStringList()); }
00690 
00701 template <class T>
00702 inline QSqlError fetch_by_query(const qx::QxSqlQuery & query, T & t)
00703 { return qx::dao::detail::QxDao_FetchAll<T>::fetchAll(query, t, NULL, QStringList()); }
00704 
00714 template <class T>
00715 inline QSqlError insert(T & t)
00716 { return qx::dao::detail::QxDao_Insert<T>::insert(t, NULL); }
00717 
00727 template <class T>
00728 inline QSqlError update(T & t)
00729 { return qx::dao::detail::QxDao_Update<T>::update("", t, NULL, QStringList()); }
00730 
00741 template <class T>
00742 inline QSqlError update_by_query(const qx::QxSqlQuery & query, T & t)
00743 { return qx::dao::detail::QxDao_Update<T>::update(query, t, NULL, QStringList()); }
00744 
00756 template <class T>
00757 inline QSqlError save(T & t)
00758 { return qx::dao::detail::QxDao_Save<T>::save(t, NULL); }
00759 
00772 template <class T>
00773 inline QSqlError delete_by_id(T & t)
00774 { return qx::dao::detail::QxDao_DeleteById<T>::deleteById(t, NULL, true); }
00775 
00785 template <class T>
00786 inline QSqlError destroy_by_id(T & t)
00787 { return qx::dao::detail::QxDao_DeleteById<T>::deleteById(t, NULL, false); }
00788 
00800 template <class T>
00801 inline QSqlError delete_all()
00802 { return qx::dao::detail::QxDao_DeleteAll<T>::deleteAll("", NULL, true); }
00803 
00812 template <class T>
00813 inline QSqlError destroy_all()
00814 { return qx::dao::detail::QxDao_DeleteAll<T>::deleteAll("", NULL, false); }
00815 
00828 template <class T>
00829 inline QSqlError delete_by_query(const qx::QxSqlQuery & query)
00830 { return qx::dao::detail::QxDao_DeleteAll<T>::deleteAll(query, NULL, true); }
00831 
00841 template <class T>
00842 inline QSqlError destroy_by_query(const qx::QxSqlQuery & query)
00843 { return qx::dao::detail::QxDao_DeleteAll<T>::deleteAll(query, NULL, false); }
00844 
00853 template <class T>
00854 inline QSqlError create_table()
00855 { return qx::dao::detail::QxDao_CreateTable<T>::createTable(NULL); }
00856 
00866 template <class T>
00867 inline qx_bool exist(T & t)
00868 { return qx::dao::detail::QxDao_Exist<T>::exist(t, NULL); }
00869 
00881 template <class T>
00882 inline QSqlError fetch_by_id(T & t, QSqlDatabase * pDatabase, const QStringList & columns)
00883 { return qx::dao::detail::QxDao_FetchById<T>::fetchById(t, pDatabase, columns); }
00884 
00896 template <class T>
00897 inline QSqlError fetch_all(T & t, QSqlDatabase * pDatabase, const QStringList & columns)
00898 { return qx::dao::detail::QxDao_FetchAll<T>::fetchAll("", t, pDatabase, columns); }
00899 
00912 template <class T>
00913 inline QSqlError fetch_by_query(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase, const QStringList & columns)
00914 { return qx::dao::detail::QxDao_FetchAll<T>::fetchAll(query, t, pDatabase, columns); }
00915 
00927 template <class T>
00928 inline QSqlError update(T & t, QSqlDatabase * pDatabase, const QStringList & columns)
00929 { return qx::dao::detail::QxDao_Update<T>::update("", t, pDatabase, columns); }
00930 
00943 template <class T>
00944 inline QSqlError update_by_query(const qx::QxSqlQuery & query, T & t, QSqlDatabase * pDatabase, const QStringList & columns)
00945 { return qx::dao::detail::QxDao_Update<T>::update(query, t, pDatabase, columns); }
00946 
00956 template <class T>
00957 inline QSqlError update_optimized(qx::dao::ptr<T> & ptr)
00958 { return qx::dao::detail::QxDao_Update_Optimized<T>::update_optimized("", ptr, NULL); }
00959 
00970 template <class T>
00971 inline QSqlError update_optimized_by_query(const qx::QxSqlQuery & query, qx::dao::ptr<T> & ptr)
00972 { return qx::dao::detail::QxDao_Update_Optimized<T>::update_optimized(query, ptr, NULL); }
00973 
00984 template <class T>
00985 inline QSqlError update_optimized(qx::dao::ptr<T> & ptr, QSqlDatabase * pDatabase)
00986 { return qx::dao::detail::QxDao_Update_Optimized<T>::update_optimized("", ptr, pDatabase); }
00987 
00999 template <class T>
01000 inline QSqlError update_optimized_by_query(const qx::QxSqlQuery & query, qx::dao::ptr<T> & ptr, QSqlDatabase * pDatabase)
01001 { return qx::dao::detail::QxDao_Update_Optimized<T>::update_optimized(query, ptr, pDatabase); }
01002 
01013 template <class T>
01014 inline QSqlError fetch_by_id_with_relation(const QString & relation, T & t)
01015 { return qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById(relation, t, NULL); }
01016 
01027 template <class T>
01028 inline QSqlError fetch_by_id_with_relation(const QStringList & relation, T & t)
01029 { return qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById(relation, t, NULL); }
01030 
01040 template <class T>
01041 inline QSqlError fetch_by_id_with_all_relation(T & t)
01042 { return qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById("*", t, NULL); }
01043 
01054 template <class T>
01055 inline QSqlError fetch_all_with_relation(const QString & relation, T & t)
01056 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, "", t, NULL); }
01057 
01068 template <class T>
01069 inline QSqlError fetch_all_with_relation(const QStringList & relation, T & t)
01070 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, "", t, NULL); }
01071 
01081 template <class T>
01082 inline QSqlError fetch_all_with_all_relation(T & t)
01083 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll("*", "", t, NULL); }
01084 
01096 template <class T>
01097 inline QSqlError fetch_by_query_with_relation(const QString & relation, const qx::QxSqlQuery & query, T & t)
01098 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, query, t, NULL); }
01099 
01111 template <class T>
01112 inline QSqlError fetch_by_query_with_relation(const QStringList & relation, const qx::QxSqlQuery & query, T & t)
01113 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, query, t, NULL); }
01114 
01125 template <class T>
01126 inline QSqlError fetch_by_query_with_all_relation(const qx::QxSqlQuery & query, T & t)
01127 { return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll("*", query, t, NULL); }
01128 
01139 template <class T>
01140 inline QSqlError insert_with_relation(const QString & relation, T & t)
01141 { return qx::dao::detail::QxDao_Insert_WithRelation<T>::insert(relation, t, NULL); }
01142 
01153 template <class T>
01154 inline QSqlError insert_with_relation(const QStringList & relation, T & t)
01155 { return qx::dao::detail::QxDao_Insert_WithRelation<T>::insert(relation, t, NULL); }
01156 
01166 template <class T>
01167 inline QSqlError insert_with_all_relation(T & t)
01168 { return qx::dao::detail::QxDao_Insert_WithRelation<T>::insert("*", t, NULL); }
01169 
01180 template <class T>
01181 inline QSqlError update_with_relation(const QString & relation, T & t)
01182 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, "", t, NULL); }
01183 
01195 template <class T>
01196 inline QSqlError update_by_query_with_relation(const QString & relation, const qx::QxSqlQuery & query, T & t)
01197 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, query, t, NULL); }
01198 
01209 template <class T>
01210 inline QSqlError update_with_relation(const QStringList & relation, T & t)
01211 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, "", t, NULL); }
01212 
01224 template <class T>
01225 inline QSqlError update_by_query_with_relation(const QStringList & relation, const qx::QxSqlQuery & query, T & t)
01226 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, query, t, NULL); }
01227 
01237 template <class T>
01238 inline QSqlError update_with_all_relation(T & t)
01239 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update("*", "", t, NULL); }
01240 
01251 template <class T>
01252 inline QSqlError update_by_query_with_all_relation(const qx::QxSqlQuery & query, T & t)
01253 { return qx::dao::detail::QxDao_Update_WithRelation<T>::update("*", query, t, NULL); }
01254 
01267 template <class T>
01268 inline QSqlError save_with_relation(const QString & relation, T & t)
01269 { return qx::dao::detail::QxDao_Save_WithRelation<T>::save(relation, t, NULL); }
01270 
01283 template <class T>
01284 inline QSqlError save_with_relation(const QStringList & relation, T & t)
01285 { return qx::dao::detail::QxDao_Save_WithRelation<T>::save(relation, t, NULL); }
01286 
01298 template <class T>
01299 inline QSqlError save_with_all_relation(T & t)
01300 { return qx::dao::detail::QxDao_Save_WithRelation<T>::save("*", t, NULL); }
01301 
01306 template <class T>
01307 inline void on_before_insert(T * t, qx::dao::detail::IxDao_Helper * dao)
01308 { qx::dao::detail::QxDao_Trigger<T>::onBeforeInsert(t, dao); }
01309 
01314 template <class T>
01315 inline void on_before_update(T * t, qx::dao::detail::IxDao_Helper * dao)
01316 { qx::dao::detail::QxDao_Trigger<T>::onBeforeUpdate(t, dao); }
01317 
01322 template <class T>
01323 inline void on_before_delete(T * t, qx::dao::detail::IxDao_Helper * dao)
01324 { qx::dao::detail::QxDao_Trigger<T>::onBeforeDelete(t, dao); }
01325 
01330 template <class T>
01331 inline void on_after_insert(T * t, qx::dao::detail::IxDao_Helper * dao)
01332 { qx::dao::detail::QxDao_Trigger<T>::onAfterInsert(t, dao); }
01333 
01338 template <class T>
01339 inline void on_after_update(T * t, qx::dao::detail::IxDao_Helper * dao)
01340 { qx::dao::detail::QxDao_Trigger<T>::onAfterUpdate(t, dao); }
01341 
01346 template <class T>
01347 inline void on_after_delete(T * t, qx::dao::detail::IxDao_Helper * dao)
01348 { qx::dao::detail::QxDao_Trigger<T>::onAfterDelete(t, dao); }
01349 
01350 } // namespace dao
01351 } // namespace qx
01352 
01353 #endif // _QX_DAO_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines