QxOrm 1.4.9
C++ Object Relational Mapping library
Loading...
Searching...
No Matches
QxSqlRelationParams.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 _QX_SQL_RELATION_PARAMS_H_
33#define _QX_SQL_RELATION_PARAMS_H_
34
35#ifdef _MSC_VER
36#pragma once
37#endif
38
46#include <QtSql/qsqldatabase.h>
47#include <QtSql/qsqlquery.h>
48
49#include <QxDao/QxSqlJoin.h>
50#include <QxDao/QxSqlSaveMode.h>
51
53
54namespace qx {
55
56class QxSqlRelationLinked;
57class IxSqlQueryBuilder;
58class IxSqlRelation;
59
65{
66
67public:
68
69 typedef std::shared_ptr<QxSqlRelationLinked> type_relation_linked_ptr;
70 typedef QHash<QString, type_relation_linked_ptr> type_lst_relation_linked;
71
72protected:
73
74 QVariant m_vId;
75 long m_lIndex;
77 long m_lOffset;
78 QString * m_sql;
80 QSqlQuery * m_query;
81 QSqlDatabase * m_database;
82 void * m_pOwner;
85 QString m_sTableAlias;
88 QSet<void *> m_lstRecursiveItems;
89 QPair<QSet<QString>, long> * m_pColumns;
94
95public:
96
98 QxSqlRelationParams(long lIndex, long lOffset, QString * sql, IxSqlQueryBuilder * builder, QSqlQuery * query, void * pOwner, const QVariant & vId = QVariant(), qx::QxCollection<QString, QVariantList> * pLstExecBatch = NULL);
100
101 inline QVariant id() const { return m_vId; }
102 inline long index() const { return m_lIndex; }
103 inline long indexOwner() const { return m_lIndexOwner; }
104 inline long offset() const { return m_lOffset; }
105 inline QString & sql() { qAssert(m_sql); return (* m_sql); }
106 inline const QString & sql() const { qAssert(m_sql); return (* m_sql); }
107 inline QSqlQuery & query() { qAssert(m_query); return (* m_query); }
108 inline const QSqlQuery & query() const { qAssert(m_query); return (* m_query); }
109 inline QSqlDatabase & database() { qAssert(m_database); return (* m_database); }
110 inline const QSqlDatabase & database() const { qAssert(m_database); return (* m_database); }
111 inline IxSqlQueryBuilder & builder() { qAssert(m_builder); return (* m_builder); }
112 inline const IxSqlQueryBuilder & builder() const { qAssert(m_builder); return (* m_builder); }
113 inline void * owner() const { return m_pOwner; }
114 inline qx::dao::sql_join::join_type joinType() const { return m_eJoinType; }
115 inline type_lst_relation_linked * relationX() const { return m_pRelationX; }
116 inline QString getTableAlias() const { return m_sTableAlias; }
117 inline qx::dao::save_mode::e_save_mode saveMode() const { return m_eSaveMode; }
118 inline bool recursiveMode() const { return m_bRecursiveMode; }
119 inline bool existRecursiveItem(void * p) const { return m_lstRecursiveItems.contains(p); }
120 inline QSet<QString> getColumns() const { return (m_pColumns ? m_pColumns->first : QSet<QString>()); }
121 inline bool checkColumns(const QString & s) const { return (! m_pColumns || m_pColumns->first.isEmpty() || m_pColumns->first.contains(s)); }
122 inline long getColumnsCount() const { return (m_pColumns ? m_pColumns->first.count() : 0); }
123 inline long getColumnsOffset() const { return (m_pColumns ? m_pColumns->second : 0); }
124 inline QString getCustomAlias() const { return m_sCustomAlias; }
125 inline QString getCustomAliasOwner() const { return m_sCustomAliasOwner; }
126 inline qx::QxCollection<QString, QVariantList> * getLstExecBatch() const { return m_pLstExecBatch; }
127 inline bool isDistinct() const { return m_bIsDistinct; }
128
129 inline void setId(const QVariant & vId) { m_vId = vId; }
130 inline void setIndex(long lIndex) { m_lIndex = lIndex; }
131 inline void setIndexOwner(long lIndex) { m_lIndexOwner = lIndex; }
132 inline void setOffset(long lOffset) { m_lOffset = lOffset; }
133 inline void setSql(QString * sql) { m_sql = sql; }
134 inline void setQuery(QSqlQuery * query) { m_query = query; }
135 inline void setDatabase(QSqlDatabase * database) { m_database = database; }
136 inline void setOwner(void * pOwner) { m_pOwner = pOwner; }
137 inline void setJoinType(qx::dao::sql_join::join_type e) { m_eJoinType = e; }
138 inline void setRelationX(type_lst_relation_linked * p) { m_pRelationX = p; }
139 inline void setTableAlias(const QString & s) { m_sTableAlias = s; }
140 inline void setSaveMode(qx::dao::save_mode::e_save_mode e) { m_eSaveMode = e; }
141 inline void setRecursiveMode(bool b) { m_bRecursiveMode = b; }
142 inline void insertRecursiveItem(void * p) { if (p) { m_lstRecursiveItems.insert(p); } }
143 inline void setColumns(QPair<QSet<QString>, long> * p) { m_pColumns = p; }
144 inline void setColumnsOffset(long l) { if (m_pColumns) { m_pColumns->second = l; } }
145 inline void setCustomAlias(const QString & s) { m_sCustomAlias = s; }
146 inline void setCustomAliasOwner(const QString & s) { m_sCustomAliasOwner = s; }
147 inline void setLstExecBatch(qx::QxCollection<QString, QVariantList> * p) { m_pLstExecBatch = p; }
149
150};
151
152} // namespace qx
153
154#endif // _QX_SQL_RELATION_PARAMS_H_
QxOrm thread-safe container (keep insertion order + quick access by index + quick access by key)
#define qAssert(x)
Definition QxMacro.h:52
#define QX_DLL_EXPORT
Definition QxMacro.h:182
Define how to join 2 tables into SQL query (LEFT OUTER JOIN, INNER JOIN, etc...)
To improve performance, if you know that you are just inserting or updating items in database.
qx::IxSqlQueryBuilder : common interface to build SQL queries to communicate with database
qx::QxCollection<Key, Value> : QxOrm thread-safe container (keep insertion order + quick access by in...
qx::QxSqlRelationParams : define list of parameters to transfer to relationships to manage SQL querie...
const QSqlQuery & query() const
QString m_sCustomAliasOwner
Custom SQL table alias owner instead of generating a new one automatically.
void setCustomAliasOwner(const QString &s)
qx::dao::sql_join::join_type joinType() const
const IxSqlQueryBuilder & builder() const
IxSqlQueryBuilder & builder()
void setRelationX(type_lst_relation_linked *p)
void setDatabase(QSqlDatabase *database)
QHash< QString, type_relation_linked_ptr > type_lst_relation_linked
void setIndexOwner(long lIndex)
virtual ~QxSqlRelationParams()
type_lst_relation_linked * m_pRelationX
Current list of relations used by qx::QxSqlRelationLinked class.
QString * m_sql
Current SQL query.
std::shared_ptr< QxSqlRelationLinked > type_relation_linked_ptr
void setTableAlias(const QString &s)
bool m_bRecursiveMode
Recursive mode to iterate over each level of relationship.
QPair< QSet< QString >, long > * m_pColumns
List of relation columns to fetch (syntax : my_relation { column_1, column_2, etc....
QSet< QString > getColumns() const
bool m_bIsDistinct
SQL query of type SELECT DISTINCT.
QSqlDatabase * m_database
Current SQL database connexion.
IxSqlQueryBuilder * m_builder
Current SQL query builder.
const QSqlDatabase & database() const
QString m_sCustomAlias
Custom SQL table alias instead of generating a new one automatically.
QSqlQuery * m_query
Current SQL query connected to database.
bool checkColumns(const QString &s) const
void setColumns(QPair< QSet< QString >, long > *p)
qx::QxCollection< QString, QVariantList > * m_pLstExecBatch
List of data to send to database when QSqlQuery::execBatch() method is used.
void setCustomAlias(const QString &s)
void setBuilder(IxSqlQueryBuilder *builder)
qx::dao::save_mode::e_save_mode saveMode() const
QString m_sTableAlias
Current SQL table alias : useful for relationships defined in base class.
qx::dao::sql_join::join_type m_eJoinType
Current join type to build SQL query : LEFT OUTER JOIN, INNER JOIN, etc...
void setQuery(QSqlQuery *query)
const QString & sql() const
QString getCustomAliasOwner() const
QSet< void * > m_lstRecursiveItems
Used by recursive process to avoid infinite loop.
void setJoinType(qx::dao::sql_join::join_type e)
void setLstExecBatch(qx::QxCollection< QString, QVariantList > *p)
QxSqlRelationParams(long lIndex, long lOffset, QString *sql, IxSqlQueryBuilder *builder, QSqlQuery *query, void *pOwner, const QVariant &vId=QVariant(), qx::QxCollection< QString, QVariantList > *pLstExecBatch=NULL)
void * m_pOwner
Owner to current object to resolve input/output.
bool existRecursiveItem(void *p) const
qx::dao::save_mode::e_save_mode m_eSaveMode
Used to improve performance, if you know that you are just inserting or updating items in database.
qx::QxCollection< QString, QVariantList > * getLstExecBatch() const
type_lst_relation_linked * relationX() const
long m_lIndex
Current SQL relation index.
void setSaveMode(qx::dao::save_mode::e_save_mode e)
QVariant m_vId
Current id.
long m_lOffset
Current SQL query offset.
long m_lIndexOwner
Current SQL relation owner index.
void setId(const QVariant &vId)
Root namespace for all QxOrm library features.