QxOrm 1.4.9
C++ Object Relational Mapping library
Loading...
Searching...
No Matches
IxSqlQueryBuilder.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_QUERY_BUILDER_H_
33#define _IX_SQL_QUERY_BUILDER_H_
34
35#ifdef _MSC_VER
36#pragma once
37#endif
38
47
48#include <QxDao/IxSqlRelation.h>
49#include <QxDao/QxSoftDelete.h>
51
52namespace qx {
53namespace dao {
54namespace detail {
55
56class IxDao_Helper;
57
58} // namespace detail
59} // namespace dao
60} // namespace qx
61
62namespace qx {
63
69{
70
71private:
72
73 struct IxSqlQueryBuilderImpl;
74 std::unique_ptr<IxSqlQueryBuilderImpl> m_pImpl;
75
76public:
77
79 virtual ~IxSqlQueryBuilder() = 0;
80
86
87 void setHashRelation(const QString & s);
88 void setCartesianProduct(bool b);
89 QString getSqlQuery() const;
90 QString getHashRelation() const;
91 QString table() const;
93 bool getCartesianProduct() const;
94 long getDataCount() const;
95 long getRelationCount() const;
97 IxDataMember * nextData(long & l) const;
98 IxSqlRelation * nextRelation(long & l) const;
99 QString & getCurrentBuildingSql() const;
100
101 void initIdX(long lAllRelationCount);
102 bool insertIdX(long lIndex, const QVariant & idOwner, const QVariant & idData, void * ptr);
103 void * existIdX(long lIndex, const QVariant & idOwner, const QVariant & idData);
104 void setSqlQuery(const QString & sql, const QString & key = QString());
105 void addSqlQueryAlias(const QString & sql, const QString & sqlAlias);
107 void replaceSqlQueryAlias(QString & sql) const;
108
109 virtual void init();
110 virtual void clone(const IxSqlQueryBuilder & other);
111 virtual IxSqlQueryBuilder & buildSql(const QStringList & columns = QStringList(), QxSqlRelationLinked * pRelationX = NULL) = 0;
112
113 static QString addSqlCondition(const QString & sql) { return (sql.contains(" WHERE ") ? " AND " : " WHERE "); }
114
115 static void sql_CreateTable(QString & sql, IxSqlQueryBuilder & builder);
116 static void sql_DeleteById(QString & sql, IxSqlQueryBuilder & builder, bool bSoftDelete);
117 static void sql_Exist(QString & sql, IxSqlQueryBuilder & builder);
118 static void sql_FetchAll(QString & sql, IxSqlQueryBuilder & builder);
119 static void sql_FetchAll(QString & sql, IxSqlQueryBuilder & builder, const QStringList & columns);
120 static void sql_FetchAll_WithRelation(qx::QxSqlRelationLinked * pRelationX, QString & sql, IxSqlQueryBuilder & builder);
121 static void sql_FetchById(QString & sql, IxSqlQueryBuilder & builder);
122 static void sql_FetchById(QString & sql, IxSqlQueryBuilder & builder, const QStringList & columns);
123 static void sql_FetchById_WithRelation(qx::QxSqlRelationLinked * pRelationX, QString & sql, IxSqlQueryBuilder & builder);
124 static void sql_Insert(QString & sql, IxSqlQueryBuilder & builder);
125 static void sql_Update(QString & sql, IxSqlQueryBuilder & builder);
126 static void sql_Update(QString & sql, IxSqlQueryBuilder & builder, const QStringList & columns);
127 static void sql_Count_WithRelation(qx::QxSqlRelationLinked * pRelationX, QString & sql, IxSqlQueryBuilder & builder);
128
129 static void resolveOutput_FetchAll(void * t, QSqlQuery & query, IxSqlQueryBuilder & builder);
130 static void resolveOutput_FetchAll(void * t, QSqlQuery & query, IxSqlQueryBuilder & builder, const QStringList & columns);
131 static void resolveOutput_FetchAll_WithRelation(qx::QxSqlRelationLinked * pRelationX, void * t, QSqlQuery & query, IxSqlQueryBuilder & builder);
132
133 static void resolveInput_Insert(void * t, QSqlQuery & query, IxSqlQueryBuilder & builder);
134 static void resolveInput_Update(void * t, QSqlQuery & query, IxSqlQueryBuilder & builder);
135 static void resolveInput_Update(void * t, QSqlQuery & query, IxSqlQueryBuilder & builder, const QStringList & columns);
136 static void resolveInput_DeleteById(void * t, QSqlQuery & query, IxSqlQueryBuilder & builder);
137
138protected:
139
140 bool verifyColumns(const QStringList & columns) const QX_USED;
141
142 bool isInitDone() const;
144 const QxSoftDelete & softDelete() const;
147 bool findSqlQuery(const QString & key);
148 bool findSqlAlias(const QString & key);
149 void insertSqlAlias(const QString & key);
150
151};
152
153typedef std::shared_ptr<IxSqlQueryBuilder> IxSqlQueryBuilder_ptr;
154
155} // namespace qx
156
157#include <QxDao/IxDao_Helper.h>
158
159#endif // _IX_SQL_QUERY_BUILDER_H_
Helper class to communicate with database.
Common interface for a list of IxDataMember class properties registered into QxOrm context (for examp...
Common interface for all relationships defined between 2 classes (or between 2 tables in database)
#define QX_USED
Definition QxMacro.h:244
#define QX_DLL_EXPORT
Definition QxMacro.h:182
Soft delete (or logical delete) behavior to update a row into database (flag it as deleted) instead o...
Hierarchy of relationships to build SQL query.
qx::IxDataMember : common interface for all class properties registered into QxOrm context
qx::IxDataMemberX : common interface for a list of IxDataMember class properties registered into QxOr...
qx::IxSqlQueryBuilder : common interface to build SQL queries to communicate with database
virtual IxSqlQueryBuilder & buildSql(const QStringList &columns=QStringList(), QxSqlRelationLinked *pRelationX=NULL)=0
bool getCartesianProduct() const
virtual void init()
void insertSqlAlias(const QString &key)
virtual ~IxSqlQueryBuilder()=0
QString getHashRelation() const
QxSoftDelete & softDelete()
static void sql_FetchAll(QString &sql, IxSqlQueryBuilder &builder, const QStringList &columns)
bool getAddAutoIncrementIdToUpdateQuery() const
static void sql_Count_WithRelation(qx::QxSqlRelationLinked *pRelationX, QString &sql, IxSqlQueryBuilder &builder)
static QString addSqlCondition(const QString &sql)
IxDataMember * nextData(long &l) const
static void sql_Insert(QString &sql, IxSqlQueryBuilder &builder)
long getDataCount() const
static void sql_Update(QString &sql, IxSqlQueryBuilder &builder)
static void sql_FetchAll_WithRelation(qx::QxSqlRelationLinked *pRelationX, QString &sql, IxSqlQueryBuilder &builder)
const QxSoftDelete & softDelete() const
static void sql_FetchById(QString &sql, IxSqlQueryBuilder &builder, const QStringList &columns)
void setHashRelation(const QString &s)
void addSqlQueryAlias(const QString &sql, const QString &sqlAlias)
bool isInitDone() const
static void resolveOutput_FetchAll(void *t, QSqlQuery &query, IxSqlQueryBuilder &builder)
static void resolveOutput_FetchAll(void *t, QSqlQuery &query, IxSqlQueryBuilder &builder, const QStringList &columns)
QxSoftDelete getSoftDelete() const
qx::dao::detail::IxDao_Helper * getDaoHelper() const
IxDataMember * getDataId() const
void setDataMemberX(IxDataMemberX *p)
static void resolveInput_Update(void *t, QSqlQuery &query, IxSqlQueryBuilder &builder, const QStringList &columns)
static void resolveOutput_FetchAll_WithRelation(qx::QxSqlRelationLinked *pRelationX, void *t, QSqlQuery &query, IxSqlQueryBuilder &builder)
IxSqlRelation * nextRelation(long &l) const
std::unique_ptr< IxSqlQueryBuilderImpl > m_pImpl
Private implementation idiom.
long getRelationCount() const
QString table() const
virtual void clone(const IxSqlQueryBuilder &other)
static void sql_FetchById_WithRelation(qx::QxSqlRelationLinked *pRelationX, QString &sql, IxSqlQueryBuilder &builder)
static void sql_DeleteById(QString &sql, IxSqlQueryBuilder &builder, bool bSoftDelete)
void initIdX(long lAllRelationCount)
QString & getCurrentBuildingSql() const
bool findSqlQuery(const QString &key)
void setSoftDelete(const QxSoftDelete &o)
void * existIdX(long lIndex, const QVariant &idOwner, const QVariant &idData)
static void sql_CreateTable(QString &sql, IxSqlQueryBuilder &builder)
static void sql_FetchAll(QString &sql, IxSqlQueryBuilder &builder)
void replaceSqlQueryAlias(QString &sql) const
QString getSqlQuery() const
void setSqlQuery(const QString &sql, const QString &key=QString())
static void sql_FetchById(QString &sql, IxSqlQueryBuilder &builder)
static void sql_Exist(QString &sql, IxSqlQueryBuilder &builder)
static void resolveInput_Insert(void *t, QSqlQuery &query, IxSqlQueryBuilder &builder)
void setCartesianProduct(bool b)
bool insertIdX(long lIndex, const QVariant &idOwner, const QVariant &idData, void *ptr)
static void sql_Update(QString &sql, IxSqlQueryBuilder &builder, const QStringList &columns)
bool verifyColumns(const QStringList &columns) const QX_USED
QxCollection< QString, IxDataMember * > * getLstDataMember() const
static void resolveInput_DeleteById(void *t, QSqlQuery &query, IxSqlQueryBuilder &builder)
IxSqlRelationX * getLstRelation() const
static void resolveInput_Update(void *t, QSqlQuery &query, IxSqlQueryBuilder &builder)
bool findSqlAlias(const QString &key)
IxDataMemberX * getDataMemberX() const
void setDaoHelper(qx::dao::detail::IxDao_Helper *p)
qx::IxSqlRelation : common interface for all relationships defined between 2 classes (or between 2 ta...
qx::QxCollection<Key, Value> : QxOrm thread-safe container (keep insertion order + quick access by in...
qx::QxSoftDelete : soft delete (or logical delete) behavior to update a row into database (flag it as...
qx::QxSqlRelationLinked : hierarchy of relationships to build SQL query
qx::dao::detail::IxDao_Helper : helper class to communicate with database
Root namespace for all QxOrm library features.
std::shared_ptr< IxSqlQueryBuilder > IxSqlQueryBuilder_ptr