QxOrm  1.4.3
C++ Object Relational Mapping library
IxSqlElement.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 _IX_SQL_ELEMENT_H_
00033 #define _IX_SQL_ELEMENT_H_
00034 
00035 #ifdef _MSC_VER
00036 #pragma once
00037 #endif
00038 
00046 #ifdef _QX_ENABLE_BOOST_SERIALIZATION
00047 #include <boost/serialization/serialization.hpp>
00048 #include <boost/serialization/split_free.hpp>
00049 #include <boost/serialization/version.hpp>
00050 #include <boost/serialization/nvp.hpp>
00051 #endif // _QX_ENABLE_BOOST_SERIALIZATION
00052 
00053 #include <QtCore/qdatastream.h>
00054 
00055 #ifndef _QX_NO_JSON
00056 #include <QtCore/qjsonvalue.h>
00057 #endif // _QX_NO_JSON
00058 
00059 #include <QtSql/qsqlquery.h>
00060 
00061 #include <QxDao/QxSqlGenerator/IxSqlGenerator.h>
00062 
00063 #include <QxSerialize/Qt/QxSerialize_QList.h>
00064 #include <QxSerialize/Qt/QxSerialize_QStringList.h>
00065 #include <QxSerialize/Qt/QxSerialize_QVariant.h>
00066 
00067 #include <QxConvert/QxConvert.h>
00068 
00069 namespace qx {
00070 namespace dao {
00071 namespace detail {
00072 class IxSqlElement;
00073 } // namespace detail
00074 } // namespace dao
00075 } // namespace qx
00076 
00077 QX_DLL_EXPORT QDataStream & operator<< (QDataStream & stream, const qx::dao::detail::IxSqlElement & t) BOOST_USED;
00078 QX_DLL_EXPORT QDataStream & operator>> (QDataStream & stream, qx::dao::detail::IxSqlElement & t) BOOST_USED;
00079 
00080 #ifndef _QX_NO_JSON
00081 namespace qx {
00082 namespace cvt {
00083 namespace detail {
00084 template <> struct QxConvert_ToJson< qx::dao::detail::IxSqlElement >;
00085 template <> struct QxConvert_FromJson< qx::dao::detail::IxSqlElement >;
00086 QX_DLL_EXPORT QJsonValue QxConvert_ToJson_Helper(const qx::dao::detail::IxSqlElement & t, const QString & format) BOOST_USED;
00087 QX_DLL_EXPORT qx_bool QxConvert_FromJson_Helper(const QJsonValue & j, qx::dao::detail::IxSqlElement & t, const QString & format) BOOST_USED;
00088 } // namespace detail
00089 } // namespace cvt
00090 } // namespace qx
00091 #endif // _QX_NO_JSON
00092 
00093 namespace qx {
00094 namespace dao {
00095 namespace detail {
00096 
00101 class QX_DLL_EXPORT IxSqlElement
00102 {
00103 
00104    friend QDataStream & ::operator<< (QDataStream & stream, const qx::dao::detail::IxSqlElement & t);
00105    friend QDataStream & ::operator>> (QDataStream & stream, qx::dao::detail::IxSqlElement & t);
00106 
00107 #ifndef _QX_NO_JSON
00108    friend struct qx::cvt::detail::QxConvert_ToJson< qx::dao::detail::IxSqlElement >;
00109    friend struct qx::cvt::detail::QxConvert_FromJson< qx::dao::detail::IxSqlElement >;
00110    friend QJsonValue qx::cvt::detail::QxConvert_ToJson_Helper(const qx::dao::detail::IxSqlElement & t, const QString & format);
00111    friend qx_bool qx::cvt::detail::QxConvert_FromJson_Helper(const QJsonValue & j, qx::dao::detail::IxSqlElement & t, const QString & format);
00112 #endif // _QX_NO_JSON
00113 
00114 public:
00115 
00116    enum type_class { _no_type, _sql_compare, _sql_element_temp, _sql_expression, _sql_free_text, 
00117                      _sql_in, _sql_is_between, _sql_is_null, _sql_limit, _sql_sort };
00118 
00119 protected:
00120 
00121    int               m_iIndex;            
00122    QStringList       m_lstColumns;        
00123    QStringList       m_lstKeys;           
00124    QList<QVariant>   m_lstValues;         
00125    IxSqlGenerator *  m_pSqlGenerator;     
00126 
00127 public:
00128 
00129    IxSqlElement(int index);
00130    virtual ~IxSqlElement();
00131 
00132    void setColumn(const QString & column);
00133    void setColumns(const QStringList & columns);
00134    void setValue(const QVariant & val);
00135    void setValues(const QVariantList & values);
00136 
00137    virtual IxSqlElement::type_class getTypeClass() const = 0;
00138 
00139    virtual QString toString() const = 0;
00140    virtual void resolve(QSqlQuery & query) const = 0;
00141    virtual void postProcess(QString & sql) const = 0;
00142 
00143    virtual void clone(IxSqlElement * other);
00144 
00145 #ifdef _QX_ENABLE_BOOST_SERIALIZATION
00146    template <class Archive>
00147    void qxSave(Archive & ar) const
00148    {
00149       QString sExtraSettings = getExtraSettings();
00150       ar << boost::serialization::make_nvp("index", m_iIndex);
00151       ar << boost::serialization::make_nvp("list_columns", m_lstColumns);
00152       ar << boost::serialization::make_nvp("list_keys", m_lstKeys);
00153       ar << boost::serialization::make_nvp("list_values", m_lstValues);
00154       ar << boost::serialization::make_nvp("extra_settings", sExtraSettings);
00155    }
00156 #endif // _QX_ENABLE_BOOST_SERIALIZATION
00157 
00158 #ifdef _QX_ENABLE_BOOST_SERIALIZATION
00159    template <class Archive>
00160    void qxLoad(Archive & ar)
00161    {
00162       QString sExtraSettings;
00163       ar >> boost::serialization::make_nvp("index", m_iIndex);
00164       ar >> boost::serialization::make_nvp("list_columns", m_lstColumns);
00165       ar >> boost::serialization::make_nvp("list_keys", m_lstKeys);
00166       ar >> boost::serialization::make_nvp("list_values", m_lstValues);
00167       ar >> boost::serialization::make_nvp("extra_settings", sExtraSettings);
00168       setExtraSettings(sExtraSettings);
00169    }
00170 #endif // _QX_ENABLE_BOOST_SERIALIZATION
00171 
00172 protected:
00173 
00174    void updateKeys();
00175 
00176    virtual QString getExtraSettings() const = 0;
00177    virtual void setExtraSettings(const QString & s) = 0;
00178 
00179 };
00180 
00181 typedef qx_shared_ptr<IxSqlElement> IxSqlElement_ptr;
00182 
00183 QX_DLL_EXPORT IxSqlElement_ptr create_sql_element(IxSqlElement::type_class e) BOOST_USED;
00184 
00185 } // namespace detail
00186 } // namespace dao
00187 } // namespace qx
00188 
00189 #endif // _IX_SQL_ELEMENT_H_