QxOrm 1.4.9
C++ Object Relational Mapping library
Loading...
Searching...
No Matches
IxSqlElement.h
Go to the documentation of this file.
1/****************************************************************************
2**
3** https://www.qxorm.com/
4** Copyright (C) 2013 Lionel Marty (contact@qxorm.com)
5**
6** This file is part of the QxOrm library
7**
8** This software is provided 'as-is', without any express or implied
9** warranty. In no event will the authors be held liable for any
10** damages arising from the use of this software
11**
12** Commercial Usage
13** Licensees holding valid commercial QxOrm licenses may use this file in
14** accordance with the commercial license agreement provided with the
15** Software or, alternatively, in accordance with the terms contained in
16** a written agreement between you and Lionel Marty
17**
18** GNU General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU
20** General Public License version 3.0 as published by the Free Software
21** Foundation and appearing in the file 'license.gpl3.txt' included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU General Public License version 3.0 requirements will be
24** met : http://www.gnu.org/copyleft/gpl.html
25**
26** If you are unsure which license is appropriate for your use, or
27** if you have questions regarding the use of this file, please contact :
28** contact@qxorm.com
29**
30****************************************************************************/
31
32#ifndef _IX_SQL_ELEMENT_H_
33#define _IX_SQL_ELEMENT_H_
34
35#ifdef _MSC_VER
36#pragma once
37#endif
38
46#ifdef _QX_ENABLE_BOOST_SERIALIZATION
47#include <boost/serialization/serialization.hpp>
48#include <boost/serialization/split_free.hpp>
49#include <boost/serialization/nvp.hpp>
50#endif // _QX_ENABLE_BOOST_SERIALIZATION
51
52#include <QtCore/qdatastream.h>
53
54#ifndef _QX_NO_JSON
55#include <QtCore/qjsonvalue.h>
56#endif // _QX_NO_JSON
57
58#include <QtSql/qsqlquery.h>
59
61
63
67
68#include <QxConvert/QxConvert.h>
69
70namespace qx {
71namespace dao {
72namespace detail {
73class IxSqlElement;
74} // namespace detail
75} // namespace dao
76} // namespace qx
77
78QX_DLL_EXPORT QDataStream & operator<< (QDataStream & stream, const qx::dao::detail::IxSqlElement & t) QX_USED;
79QX_DLL_EXPORT QDataStream & operator>> (QDataStream & stream, qx::dao::detail::IxSqlElement & t) QX_USED;
80
81#ifndef _QX_NO_JSON
82namespace qx {
83namespace cvt {
84namespace detail {
85template <> struct QxConvert_ToJson< qx::dao::detail::IxSqlElement >;
86template <> struct QxConvert_FromJson< qx::dao::detail::IxSqlElement >;
87QX_DLL_EXPORT QJsonValue QxConvert_ToJson_Helper(const qx::dao::detail::IxSqlElement & t, const QString & format) QX_USED;
88QX_DLL_EXPORT qx_bool QxConvert_FromJson_Helper(const QJsonValue & j, qx::dao::detail::IxSqlElement & t, const QString & format) QX_USED;
89} // namespace detail
90} // namespace cvt
91} // namespace qx
92#endif // _QX_NO_JSON
93
94namespace qx {
95namespace dao {
96namespace detail {
97
103{
104
105 friend QX_DLL_EXPORT QDataStream & ::operator<< (QDataStream & stream, const qx::dao::detail::IxSqlElement & t);
106 friend QX_DLL_EXPORT QDataStream & ::operator>> (QDataStream & stream, qx::dao::detail::IxSqlElement & t);
107
108#ifndef _QX_NO_JSON
110 friend struct qx::cvt::detail::QxConvert_FromJson< qx::dao::detail::IxSqlElement >;
111 friend QX_DLL_EXPORT QJsonValue qx::cvt::detail::QxConvert_ToJson_Helper(const qx::dao::detail::IxSqlElement & t, const QString & format);
112 friend QX_DLL_EXPORT qx_bool qx::cvt::detail::QxConvert_FromJson_Helper(const QJsonValue & j, qx::dao::detail::IxSqlElement & t, const QString & format);
113#endif // _QX_NO_JSON
114
115public:
116
117 enum type_class { _no_type, _sql_compare, _sql_element_temp, _sql_expression, _sql_free_text,
118 _sql_in, _sql_is_between, _sql_is_null, _sql_limit, _sql_sort, _sql_embed_query };
119
120protected:
121
123 QStringList m_lstColumns;
124 QStringList m_lstKeys;
125 QList<QVariant> m_lstValues;
127
128public:
129
130 IxSqlElement(int index);
131 virtual ~IxSqlElement();
132
133 void setColumn(const QString & column);
134 void setColumns(const QStringList & columns);
135 void setValue(const QVariant & val);
136 void setValues(const QVariantList & values);
137
139
140 virtual QString toString() const = 0;
141 virtual void resolve(QSqlQuery & query, qx::QxCollection<QString, QVariantList> * pLstExecBatch = NULL) const = 0;
142 virtual void postProcess(QString & sql) const = 0;
143
144 virtual void clone(IxSqlElement * other);
145
146#ifdef _QX_ENABLE_BOOST_SERIALIZATION
147 template <class Archive>
148 void qxSave(Archive & ar) const
149 {
150 QString sExtraSettings = getExtraSettings();
151 ar << boost::serialization::make_nvp("index", m_iIndex);
152 ar << boost::serialization::make_nvp("list_columns", m_lstColumns);
153 ar << boost::serialization::make_nvp("list_keys", m_lstKeys);
154 ar << boost::serialization::make_nvp("list_values", m_lstValues);
155 ar << boost::serialization::make_nvp("extra_settings", sExtraSettings);
156 }
157#endif // _QX_ENABLE_BOOST_SERIALIZATION
158
159#ifdef _QX_ENABLE_BOOST_SERIALIZATION
160 template <class Archive>
161 void qxLoad(Archive & ar)
162 {
163 QString sExtraSettings;
164 ar >> boost::serialization::make_nvp("index", m_iIndex);
165 ar >> boost::serialization::make_nvp("list_columns", m_lstColumns);
166 ar >> boost::serialization::make_nvp("list_keys", m_lstKeys);
167 ar >> boost::serialization::make_nvp("list_values", m_lstValues);
168 ar >> boost::serialization::make_nvp("extra_settings", sExtraSettings);
169 setExtraSettings(sExtraSettings);
170 }
171#endif // _QX_ENABLE_BOOST_SERIALIZATION
172
173protected:
174
176
177 virtual QString getExtraSettings() const = 0;
178 virtual void setExtraSettings(const QString & s) = 0;
179
180};
181
182typedef std::shared_ptr<IxSqlElement> IxSqlElement_ptr;
183
185
186} // namespace detail
187} // namespace dao
188} // namespace qx
189
190#endif // _IX_SQL_ELEMENT_H_
QX_DLL_EXPORT QDataStream & operator>>(QDataStream &stream, qx::dao::detail::IxSqlElement &t) QX_USED
QX_DLL_EXPORT QDataStream & operator<<(QDataStream &stream, const qx::dao::detail::IxSqlElement &t) QX_USED
Common interface for all SQL generators to build SQL query specific for each database.
QxOrm thread-safe container (keep insertion order + quick access by index + quick access by key)
qx::cvt : namespace to provide global functions to convert any kind of objects to/from QString and QV...
#define QX_USED
Definition QxMacro.h:244
#define QX_DLL_EXPORT
Definition QxMacro.h:182
qx_bool : boolean type with code and description message when an error occured
Definition QxBool.h:71
qx::QxCollection<Key, Value> : QxOrm thread-safe container (keep insertion order + quick access by in...
qx::dao::detail::IxSqlElement : common interface for all SQL elements to build SQL query
void setColumns(const QStringList &columns)
void setValue(const QVariant &val)
void setColumn(const QString &column)
void qxSave(Archive &ar) const
virtual void resolve(QSqlQuery &query, qx::QxCollection< QString, QVariantList > *pLstExecBatch=NULL) const =0
QStringList m_lstColumns
List of columns associated to SQL element.
virtual void clone(IxSqlElement *other)
int m_iIndex
Index of SQL element to build unique string.
QStringList m_lstKeys
List of keys associated to SQL element.
void setValues(const QVariantList &values)
IxSqlGenerator * m_pSqlGenerator
SQL generator to build SQL query specific for each database.
virtual void postProcess(QString &sql) const =0
virtual QString getExtraSettings() const =0
virtual IxSqlElement::type_class getTypeClass() const =0
virtual QString toString() const =0
QList< QVariant > m_lstValues
List of values associated to SQL element.
virtual void setExtraSettings(const QString &s)=0
qx::dao::detail::IxSqlGenerator : common interface for all SQL generators to build SQL query specific...
QX_DLL_EXPORT QJsonValue QxConvert_ToJson_Helper(const qx::dao::detail::IxSqlElement &t, const QString &format) QX_USED
QX_DLL_EXPORT qx_bool QxConvert_FromJson_Helper(const QJsonValue &j, qx::dao::detail::IxSqlElement &t, const QString &format) QX_USED
std::shared_ptr< IxSqlElement > IxSqlElement_ptr
QX_DLL_EXPORT IxSqlElement_ptr create_sql_element(IxSqlElement::type_class e) QX_USED
Root namespace for all QxOrm library features.