| QxOrm 1.2.3 C++ Object Relational Mapping library

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

QxSqlQuery.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_SQL_QUERY_H_
    00027 #define _QX_SQL_QUERY_H_
    00028
    00029 #ifdef _MSC_VER
    00030 #pragma once
    00031 #endif
    00032
    00040 #include <QtSql/qsqlquery.h>
    00041
    00042 #include <QxCollection/QxCollection.h>
    00043
    00044 #include <QxDao/QxSqlElement/QxSqlElement.h>
    00045
    00046 namespace qx {
    00047
    00156 class QX_DLL_EXPORT QxSqlQuery
    00157 {
    00158
    00159 protected:
    00160
    00161    QString                                   m_sQuery;
    00162    QxCollection<QString, QVariant>           m_lstValue;
    00163    qx::dao::detail::IxSqlElement_ptr         m_pSqlElementTemp;
    00164    QList<qx::dao::detail::IxSqlElement_ptr>  m_lstSqlElement;
    00165    int                                       m_iSqlElementIndex;
    00166    int                                       m_iParenthesisCount;
    00167    bool                                      m_bDistinct;
    00168
    00169 public:
    00170
    00171    QxSqlQuery() : m_iSqlElementIndex(0), m_iParenthesisCount(0), m_bDistinct(false) { ; }
    00172    QxSqlQuery(const QString & sQuery) : m_sQuery(sQuery), m_iSqlElementIndex(0), m_iParenthesisCount(0), m_bDistinct(false) { ; }
    00173    QxSqlQuery(const char * sQuery) : m_sQuery(sQuery), m_iSqlElementIndex(0), m_iParenthesisCount(0), m_bDistinct(false) { ; }
    00174    virtual ~QxSqlQuery() { ; }
    00175
    00176    QString query();
    00177    bool isEmpty() const;
    00178    bool isDistinct() const;
    00179    void clear();
    00180    void resolve(QSqlQuery & query) const;
    00181    void postProcess(QString & sql) const;
    00182
    00183    QxSqlQuery & query(const QString & sQuery);
    00184    QxSqlQuery & bind(const QVariant & vValue);
    00185    QxSqlQuery & bind(const QString & sKey, const QVariant & vValue);
    00186
    00187 private:
    00188
    00189 #ifndef NDEBUG
    00190    void verifyQuery() const;
    00191 #else
    00192    inline void verifyQuery() const { ; }
    00193 #endif // NDEBUG
    00194
    00195 public:
    00196
    00197    /* -- All methods to build SQL query using C++ syntax -- */
    00198
    00199    QxSqlQuery & distinct();
    00200
    00201    QxSqlQuery & where(const QString & column);
    00202    QxSqlQuery & where_OpenParenthesis(const QString & column);
    00203    QxSqlQuery & and_(const QString & column);
    00204    QxSqlQuery & and_OpenParenthesis(const QString & column);
    00205    QxSqlQuery & or_(const QString & column);
    00206    QxSqlQuery & or_OpenParenthesis(const QString & column);
    00207
    00208    QxSqlQuery & openParenthesis();
    00209    QxSqlQuery & closeParenthesis();
    00210
    00211    QxSqlQuery & orderAsc(const QStringList & columns);
    00212    QxSqlQuery & orderAsc(const QString & col1);
    00213    QxSqlQuery & orderAsc(const QString & col1, const QString & col2);
    00214    QxSqlQuery & orderAsc(const QString & col1, const QString & col2, const QString & col3);
    00215    QxSqlQuery & orderAsc(const QString & col1, const QString & col2, const QString & col3, const QString & col4);
    00216    QxSqlQuery & orderAsc(const QString & col1, const QString & col2, const QString & col3, const QString & col4, const QString & col5);
    00217    QxSqlQuery & orderAsc(const QString & col1, const QString & col2, const QString & col3, const QString & col4, const QString & col5, const QString & col6);
    00218    QxSqlQuery & orderAsc(const QString & col1, const QString & col2, const QString & col3, const QString & col4, const QString & col5, const QString & col6, const QString & col7);
    00219    QxSqlQuery & orderAsc(const QString & col1, const QString & col2, const QString & col3, const QString & col4, const QString & col5, const QString & col6, const QString & col7, const QString & col8);
    00220    QxSqlQuery & orderAsc(const QString & col1, const QString & col2, const QString & col3, const QString & col4, const QString & col5, const QString & col6, const QString & col7, const QString & col8, const QString & col9);
    00221
    00222    QxSqlQuery & orderDesc(const QStringList & columns);
    00223    QxSqlQuery & orderDesc(const QString & col1);
    00224    QxSqlQuery & orderDesc(const QString & col1, const QString & col2);
    00225    QxSqlQuery & orderDesc(const QString & col1, const QString & col2, const QString & col3);
    00226    QxSqlQuery & orderDesc(const QString & col1, const QString & col2, const QString & col3, const QString & col4);
    00227    QxSqlQuery & orderDesc(const QString & col1, const QString & col2, const QString & col3, const QString & col4, const QString & col5);
    00228    QxSqlQuery & orderDesc(const QString & col1, const QString & col2, const QString & col3, const QString & col4, const QString & col5, const QString & col6);
    00229    QxSqlQuery & orderDesc(const QString & col1, const QString & col2, const QString & col3, const QString & col4, const QString & col5, const QString & col6, const QString & col7);
    00230    QxSqlQuery & orderDesc(const QString & col1, const QString & col2, const QString & col3, const QString & col4, const QString & col5, const QString & col6, const QString & col7, const QString & col8);
    00231    QxSqlQuery & orderDesc(const QString & col1, const QString & col2, const QString & col3, const QString & col4, const QString & col5, const QString & col6, const QString & col7, const QString & col8, const QString & col9);
    00232
    00233    QxSqlQuery & groupBy(const QStringList & columns);
    00234    QxSqlQuery & groupBy(const QString & col1);
    00235    QxSqlQuery & groupBy(const QString & col1, const QString & col2);
    00236    QxSqlQuery & groupBy(const QString & col1, const QString & col2, const QString & col3);
    00237    QxSqlQuery & groupBy(const QString & col1, const QString & col2, const QString & col3, const QString & col4);
    00238    QxSqlQuery & groupBy(const QString & col1, const QString & col2, const QString & col3, const QString & col4, const QString & col5);
    00239    QxSqlQuery & groupBy(const QString & col1, const QString & col2, const QString & col3, const QString & col4, const QString & col5, const QString & col6);
    00240    QxSqlQuery & groupBy(const QString & col1, const QString & col2, const QString & col3, const QString & col4, const QString & col5, const QString & col6, const QString & col7);
    00241    QxSqlQuery & groupBy(const QString & col1, const QString & col2, const QString & col3, const QString & col4, const QString & col5, const QString & col6, const QString & col7, const QString & col8);
    00242    QxSqlQuery & groupBy(const QString & col1, const QString & col2, const QString & col3, const QString & col4, const QString & col5, const QString & col6, const QString & col7, const QString & col8, const QString & col9);
    00243
    00244    QxSqlQuery & limit(int rowsCount, int startRow = 0);
    00245
    00246    QxSqlQuery & like(const QString & val);
    00247    QxSqlQuery & notLike(const QString & val);
    00248    QxSqlQuery & startsWith(const QString & val);
    00249    QxSqlQuery & endsWith(const QString & val);
    00250    QxSqlQuery & containsString(const QString & val);
    00251
    00252    QxSqlQuery & isEqualTo(const QVariant & val);
    00253    QxSqlQuery & isNotEqualTo(const QVariant & val);
    00254    QxSqlQuery & isGreaterThan(const QVariant & val);
    00255    QxSqlQuery & isGreaterThanOrEqualTo(const QVariant & val);
    00256    QxSqlQuery & isLessThan(const QVariant & val);
    00257    QxSqlQuery & isLessThanOrEqualTo(const QVariant & val);
    00258
    00259    QxSqlQuery & in(const QVariantList & values);
    00260    QxSqlQuery & in(const QVariant & val1);
    00261    QxSqlQuery & in(const QVariant & val1, const QVariant & val2);
    00262    QxSqlQuery & in(const QVariant & val1, const QVariant & val2, const QVariant & val3);
    00263    QxSqlQuery & in(const QVariant & val1, const QVariant & val2, const QVariant & val3, const QVariant & val4);
    00264    QxSqlQuery & in(const QVariant & val1, const QVariant & val2, const QVariant & val3, const QVariant & val4, const QVariant & val5);
    00265    QxSqlQuery & in(const QVariant & val1, const QVariant & val2, const QVariant & val3, const QVariant & val4, const QVariant & val5, const QVariant & val6);
    00266    QxSqlQuery & in(const QVariant & val1, const QVariant & val2, const QVariant & val3, const QVariant & val4, const QVariant & val5, const QVariant & val6, const QVariant & val7);
    00267    QxSqlQuery & in(const QVariant & val1, const QVariant & val2, const QVariant & val3, const QVariant & val4, const QVariant & val5, const QVariant & val6, const QVariant & val7, const QVariant & val8);
    00268    QxSqlQuery & in(const QVariant & val1, const QVariant & val2, const QVariant & val3, const QVariant & val4, const QVariant & val5, const QVariant & val6, const QVariant & val7, const QVariant & val8, const QVariant & val9);
    00269
    00270    QxSqlQuery & notIn(const QVariantList & values);
    00271    QxSqlQuery & notIn(const QVariant & val1);
    00272    QxSqlQuery & notIn(const QVariant & val1, const QVariant & val2);
    00273    QxSqlQuery & notIn(const QVariant & val1, const QVariant & val2, const QVariant & val3);
    00274    QxSqlQuery & notIn(const QVariant & val1, const QVariant & val2, const QVariant & val3, const QVariant & val4);
    00275    QxSqlQuery & notIn(const QVariant & val1, const QVariant & val2, const QVariant & val3, const QVariant & val4, const QVariant & val5);
    00276    QxSqlQuery & notIn(const QVariant & val1, const QVariant & val2, const QVariant & val3, const QVariant & val4, const QVariant & val5, const QVariant & val6);
    00277    QxSqlQuery & notIn(const QVariant & val1, const QVariant & val2, const QVariant & val3, const QVariant & val4, const QVariant & val5, const QVariant & val6, const QVariant & val7);
    00278    QxSqlQuery & notIn(const QVariant & val1, const QVariant & val2, const QVariant & val3, const QVariant & val4, const QVariant & val5, const QVariant & val6, const QVariant & val7, const QVariant & val8);
    00279    QxSqlQuery & notIn(const QVariant & val1, const QVariant & val2, const QVariant & val3, const QVariant & val4, const QVariant & val5, const QVariant & val6, const QVariant & val7, const QVariant & val8, const QVariant & val9);
    00280
    00281    QxSqlQuery & in_Select(const QString & sql);
    00282    QxSqlQuery & notIn_Select(const QString & sql);
    00283
    00284    QxSqlQuery & isNull();
    00285    QxSqlQuery & isNotNull();
    00286
    00287    QxSqlQuery & isBetween(const QVariant & val1, const QVariant & val2);
    00288    QxSqlQuery & isNotBetween(const QVariant & val1, const QVariant & val2);
    00289
    00290    QxSqlQuery & freeText(const QString & text);
    00291
    00292 private:
    00293
    00294    QxSqlQuery & addSqlExpression(const QString & column, qx::dao::detail::QxSqlExpression::type type);
    00295    QxSqlQuery & addSqlCompare(const QVariant & val, qx::dao::detail::QxSqlCompare::type type);
    00296    QxSqlQuery & addSqlSort(const QStringList & columns, qx::dao::detail::QxSqlSort::type type);
    00297    QxSqlQuery & addSqlIn(const QVariantList & values, qx::dao::detail::QxSqlIn::type type);
    00298    QxSqlQuery & addSqlIsNull(qx::dao::detail::QxSqlIsNull::type type);
    00299    QxSqlQuery & addSqlIsBetween(const QVariant & val1, const QVariant & val2, qx::dao::detail::QxSqlIsBetween::type type);
    00300
    00301 };
    00302
    00303 } // namespace qx
    00304
    00305 typedef qx::QxSqlQuery qx_query;
    00306
    00307 #endif // _QX_SQL_QUERY_H_