QxOrm 1.1.6
C++ Object Relational Mapping library
IxSqlQueryBuilder.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 _IX_SQL_QUERY_BUILDER_H_
00027 #define _IX_SQL_QUERY_BUILDER_H_
00028 
00029 #ifdef _MSC_VER
00030 #pragma once
00031 #endif
00032 
00040 #include <QxDataMember/IxDataMemberX.h>
00041 
00042 #include <QxDao/IxSqlRelation.h>
00043 
00044 namespace qx {
00045 
00050 class QX_DLL_EXPORT IxSqlQueryBuilder
00051 {
00052 
00053 public:
00054 
00055    typedef QPair<QString, QString> type_id;
00056    typedef QHash<type_id, void *> type_ptr_by_id;
00057    typedef boost::shared_ptr<type_ptr_by_id> type_ptr_by_id_ptr;
00058    typedef QList<type_ptr_by_id_ptr> type_lst_ptr_by_id;
00059    typedef boost::shared_ptr<type_lst_ptr_by_id> type_lst_ptr_by_id_ptr;
00060 
00061 protected:
00062 
00063    QxCollection<QString, IxDataMember *> * m_lstDataMemberPtr;    
00064    IxSqlRelationX * m_lstSqlRelationPtr;                          
00065    IxDataMember * m_pDataMemberId;                                
00066    QString m_sSqlQuery;                                           
00067    QString m_sTableName;                                          
00068    QString m_sHashRelation;                                       
00069    bool m_bCartesianProduct;                                      
00070    type_lst_ptr_by_id_ptr m_pIdX;                                 
00071 
00072 public:
00073 
00074    IxSqlQueryBuilder() : m_lstDataMemberPtr(NULL), m_lstSqlRelationPtr(NULL), m_pDataMemberId(NULL), m_bCartesianProduct(false) { ; }
00075    IxSqlQueryBuilder(const QString & sql) : m_lstDataMemberPtr(NULL), m_lstSqlRelationPtr(NULL), m_pDataMemberId(NULL), m_sSqlQuery(sql), m_bCartesianProduct(false) { ; }
00076    virtual ~IxSqlQueryBuilder() = 0;
00077 
00078    inline QxCollection<QString, IxDataMember *> * getLstDataMember() const    { return m_lstDataMemberPtr; }
00079    inline IxSqlRelationX * getLstRelation() const                             { return m_lstSqlRelationPtr; }
00080 
00081    inline void setSqlQuery(const QString & sql)          { m_sSqlQuery = sql; }
00082    inline void setHashRelation(const QString & s)        { m_sHashRelation = s; }
00083    inline void setCartesianProduct(bool b)               { m_bCartesianProduct = b; }
00084    inline QString getSqlQuery() const                    { return m_sSqlQuery; }
00085    inline QString getHashRelation() const                { return m_sHashRelation; }
00086    inline QString table() const                          { return m_sTableName; }
00087    inline bool getCartesianProduct() const               { return m_bCartesianProduct; }
00088    inline long getDataCount() const                      { return (m_lstDataMemberPtr ? m_lstDataMemberPtr->count() : 0); }
00089    inline long getRelationCount() const                  { return (m_lstSqlRelationPtr ? m_lstSqlRelationPtr->count() : 0); }
00090    inline IxDataMember * getDataId() const               { return m_pDataMemberId; }
00091    inline IxDataMember * nextData(long & l) const        { if ((! m_lstDataMemberPtr) || (l < 0) || (l >= m_lstDataMemberPtr->count())) { return NULL; }; ++l; return m_lstDataMemberPtr->getByIndex(l - 1); }
00092    inline IxSqlRelation * nextRelation(long & l) const   { if ((! m_lstSqlRelationPtr) || (l < 0) || (l >= m_lstSqlRelationPtr->count())) { return NULL; }; ++l; return m_lstSqlRelationPtr->getByIndex(l - 1); }
00093 
00094    void displaySqlQuery(int time_ms = -1) const;
00095    bool insertIdX(long lIndex, const QVariant & idOwner, const QVariant & idData, void * ptr);
00096    void * existIdX(long lIndex, const QVariant & idOwner, const QVariant & idData);
00097 
00098    virtual void init() = 0;
00099    virtual IxDataMemberX * getDataMemberX() const = 0;
00100 
00101    virtual IxSqlQueryBuilder & count() = 0;
00102    virtual IxSqlQueryBuilder & exist() = 0;
00103    virtual IxSqlQueryBuilder & fetchAll() = 0;
00104    virtual IxSqlQueryBuilder & fetchById() = 0;
00105    virtual IxSqlQueryBuilder & insert() = 0;
00106    virtual IxSqlQueryBuilder & update() = 0;
00107    virtual IxSqlQueryBuilder & deleteAll() = 0;
00108    virtual IxSqlQueryBuilder & deleteById() = 0;
00109    virtual IxSqlQueryBuilder & createTable() = 0;
00110 
00111    virtual IxSqlQueryBuilder & fetchAll(const QStringList & columns) = 0;
00112    virtual IxSqlQueryBuilder & fetchById(const QStringList & columns) = 0;
00113    virtual IxSqlQueryBuilder & update(const QStringList & columns) = 0;
00114 
00115    virtual IxSqlQueryBuilder & fetchAll_WithRelation(IxSqlRelationX * pRelationX) = 0;
00116    virtual IxSqlQueryBuilder & fetchById_WithRelation(IxSqlRelationX * pRelationX) = 0;
00117 
00118 private:
00119 
00120    void initIdX();
00121 
00122 };
00123 
00124 typedef boost::shared_ptr<IxSqlQueryBuilder> IxSqlQueryBuilder_ptr;
00125 
00126 } // namespace qx
00127 
00128 #endif // _IX_SQL_QUERY_BUILDER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines