Changeset View
Changeset View
Standalone View
Standalone View
src/KDbQuerySchema_p.h
Show All 24 Lines | |||||
25 | #include "KDbQuerySchema.h" | 25 | #include "KDbQuerySchema.h" | ||
26 | 26 | | |||
27 | #include <QBitArray> | 27 | #include <QBitArray> | ||
28 | #include <QWeakPointer> | 28 | #include <QWeakPointer> | ||
29 | 29 | | |||
30 | class KDbConnection; | 30 | class KDbConnection; | ||
31 | 31 | | |||
32 | //! @internal | 32 | //! @internal | ||
33 | class Q_DECL_HIDDEN KDbQuerySchema::Private | 33 | class KDbQuerySchemaPrivate | ||
34 | { | 34 | { | ||
35 | Q_DECLARE_TR_FUNCTIONS(KDbQuerySchema) | 35 | Q_DECLARE_TR_FUNCTIONS(KDbQuerySchema) | ||
36 | public: | 36 | public: | ||
37 | explicit Private(KDbQuerySchema* q, Private* copy = nullptr); | 37 | explicit KDbQuerySchemaPrivate(KDbQuerySchema* q, KDbQuerySchemaPrivate* copy = nullptr); | ||
38 | 38 | | |||
39 | ~Private(); | 39 | ~KDbQuerySchemaPrivate(); | ||
40 | 40 | | |||
41 | //! @return a new query that's associated with @a conn. Used internally, e.g. by the parser. | 41 | //! @return a new query that's associated with @a conn. Used internally, e.g. by the parser. | ||
42 | //! Uses an internal KDbQuerySchema(KDbConnection*) ctor. | 42 | //! Uses an internal KDbQuerySchema(KDbConnection*) ctor. | ||
43 | static KDbQuerySchema* createQuery(KDbConnection *conn); | 43 | static KDbQuerySchema* createQuery(KDbConnection *conn); | ||
44 | 44 | | |||
45 | void clear(); | 45 | void clear(); | ||
46 | 46 | | |||
47 | void clearCachedData(); | 47 | void clearCachedData(); | ||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | |||||
94 | KDbTableSchema *masterTable; | 94 | KDbTableSchema *masterTable; | ||
95 | 95 | | |||
96 | /*! List of tables used in this query */ | 96 | /*! List of tables used in this query */ | ||
97 | QList<KDbTableSchema*> tables; | 97 | QList<KDbTableSchema*> tables; | ||
98 | 98 | | |||
99 | KDbField *fakeRecordIdField; //! used to mark a place for record Id | 99 | KDbField *fakeRecordIdField; //! used to mark a place for record Id | ||
100 | KDbQueryColumnInfo *fakeRecordIdCol; //! used to mark a place for record Id | 100 | KDbQueryColumnInfo *fakeRecordIdCol; //! used to mark a place for record Id | ||
101 | 101 | | |||
102 | //! Connection on which this query operates | | |||
103 | //! @todo use equivalent of QPointer<KDbConnection> | | |||
104 | KDbConnection* conn; | | |||
105 | | ||||
106 | protected: | 102 | protected: | ||
107 | void tryRegenerateExprAliases(); | 103 | void tryRegenerateExprAliases(); | ||
108 | 104 | | |||
109 | void setColumnAliasInternal(int position, const QString& alias); | 105 | void setColumnAliasInternal(int position, const QString& alias); | ||
110 | 106 | | |||
111 | /*! Used to mapping columns to its aliases for this query */ | 107 | /*! Used to mapping columns to its aliases for this query */ | ||
112 | QHash<int, QString> columnAliases; | 108 | QHash<int, QString> columnAliases; | ||
113 | 109 | | |||
Show All 11 Lines | 116 | public: | |||
125 | int maxIndexWithAlias; | 121 | int maxIndexWithAlias; | ||
126 | 122 | | |||
127 | /*! Used to store visibility flag for every field */ | 123 | /*! Used to store visibility flag for every field */ | ||
128 | QBitArray visibility; | 124 | QBitArray visibility; | ||
129 | 125 | | |||
130 | /*! List of asterisks defined for this query */ | 126 | /*! List of asterisks defined for this query */ | ||
131 | KDbField::List asterisks; | 127 | KDbField::List asterisks; | ||
132 | 128 | | |||
133 | /*! Temporary field vector for using in fieldsExpanded() */ | | |||
134 | KDbQueryColumnInfo::Vector *fieldsExpanded; | | |||
135 | | ||||
136 | /*! Like fieldsExpanded but only visible column infos; infos are not owned. */ | | |||
137 | KDbQueryColumnInfo::Vector *visibleFieldsExpanded; | | |||
138 | | ||||
139 | /*! Temporary field vector containing internal fields used for lookup columns. */ | | |||
140 | KDbQueryColumnInfo::Vector *internalFields; | | |||
141 | | ||||
142 | /*! Temporary, used to cache sum of expanded fields and internal fields (+record Id) used for lookup columns. | | |||
143 | Contains not auto-deleted items.*/ | | |||
144 | KDbQueryColumnInfo::Vector *fieldsExpandedWithInternalAndRecordId; | | |||
145 | | ||||
146 | /*! Like fieldsExpandedWithInternalAndRecordId but only contains visible column infos; infos are not owned.*/ | | |||
147 | KDbQueryColumnInfo::Vector *visibleFieldsExpandedWithInternalAndRecordId; | | |||
148 | | ||||
149 | /*! Temporary, used to cache sum of expanded fields and internal fields used for lookup columns. | | |||
150 | Contains not auto-deleted items.*/ | | |||
151 | KDbQueryColumnInfo::Vector *fieldsExpandedWithInternal; | | |||
152 | | ||||
153 | /*! Like fieldsExpandedWithInternal but only contains visible column infos; infos are not owned.*/ | | |||
154 | KDbQueryColumnInfo::Vector *visibleFieldsExpandedWithInternal; | | |||
155 | | ||||
156 | /*! A list of fields for ORDER BY section. @see KDbQuerySchema::orderByColumnList(). */ | 129 | /*! A list of fields for ORDER BY section. @see KDbQuerySchema::orderByColumnList(). */ | ||
157 | KDbOrderByColumnList* orderByColumnList; | 130 | KDbOrderByColumnList* orderByColumnList; | ||
158 | 131 | | |||
159 | /*! A cache for autoIncrementFields(). */ | 132 | /*! A cache for autoIncrementFields(). */ | ||
160 | KDbQueryColumnInfo::List *autoincFields; | 133 | KDbQueryColumnInfo::List *autoincFields; | ||
161 | 134 | | |||
162 | /*! A cache for autoIncrementSqlFieldsList(). */ | 135 | /*! A cache for autoIncrementSqlFieldsList(). */ | ||
163 | KDbEscapedString autoIncrementSqlFieldsList; | 136 | KDbEscapedString autoIncrementSqlFieldsList; | ||
164 | QWeakPointer<const KDbDriver> lastUsedDriverForAutoIncrementSQLFieldsList; | 137 | QWeakPointer<const KDbDriver> lastUsedDriverForAutoIncrementSQLFieldsList; | ||
165 | 138 | | |||
166 | /*! A hash for fast lookup of query columns' order (unexpanded version). */ | | |||
167 | QHash<KDbQueryColumnInfo*, int> *columnsOrder; | | |||
168 | | ||||
169 | /*! A hash for fast lookup of query columns' order (unexpanded version without asterisks). */ | | |||
170 | QHash<KDbQueryColumnInfo*, int> *columnsOrderWithoutAsterisks; | | |||
171 | | ||||
172 | /*! A hash for fast lookup of query columns' order. | | |||
173 | This is exactly opposite information compared to vector returned | | |||
174 | by fieldsExpanded() */ | | |||
175 | QHash<KDbQueryColumnInfo*, int> *columnsOrderExpanded; | | |||
176 | | ||||
177 | /*! order of PKEY fields (e.g. for updateRecord() ) */ | 139 | /*! order of PKEY fields (e.g. for updateRecord() ) */ | ||
178 | QVector<int> *pkeyFieldsOrder; | 140 | QVector<int> *pkeyFieldsOrder; | ||
179 | 141 | | |||
180 | /*! number of PKEY fields within the query */ | 142 | /*! number of PKEY fields within the query */ | ||
181 | int pkeyFieldCount; | 143 | int pkeyFieldCount; | ||
182 | 144 | | |||
183 | /*! Forced (predefined) raw SQL statement */ | 145 | /*! Forced (predefined) raw SQL statement */ | ||
184 | KDbEscapedString sql; | 146 | KDbEscapedString sql; | ||
Show All 16 Lines | |||||
201 | - second coulmn is not specially bound (othertable.x isn't ambiguous) | 163 | - second coulmn is not specially bound (othertable.x isn't ambiguous) | ||
202 | - third column is bound to table 1 "t2" | 164 | - third column is bound to table 1 "t2" | ||
203 | */ | 165 | */ | ||
204 | QVector<int> tablesBoundToColumns; | 166 | QVector<int> tablesBoundToColumns; | ||
205 | 167 | | |||
206 | /*! WHERE expression */ | 168 | /*! WHERE expression */ | ||
207 | KDbExpression whereExpr; | 169 | KDbExpression whereExpr; | ||
208 | 170 | | |||
171 | /*! Set by insertField(): true, if aliases for expression columns should | ||||
172 | be generated on next columnAlias() call. */ | ||||
173 | bool regenerateExprAliases; | ||||
174 | | ||||
175 | //! Points to connection recently used for caching | ||||
176 | //! @todo use equivalent of QPointer<KDbConnection> | ||||
177 | KDbConnection *recentConnection = nullptr; | ||||
178 | }; | ||||
179 | | ||||
180 | //! Information about expanded fields for a single query schema, used for caching | ||||
181 | class KDbQuerySchemaFieldsExpanded | ||||
182 | { | ||||
183 | public: | ||||
184 | inline KDbQuerySchemaFieldsExpanded() | ||||
185 | { | ||||
186 | } | ||||
187 | | ||||
188 | inline ~KDbQuerySchemaFieldsExpanded() | ||||
189 | { | ||||
190 | qDeleteAll(fieldsExpanded); | ||||
191 | qDeleteAll(internalFields); | ||||
192 | } | ||||
193 | | ||||
194 | /*! Temporary field vector for using in fieldsExpanded() */ | ||||
195 | KDbQueryColumnInfo::Vector fieldsExpanded; | ||||
196 | | ||||
197 | /*! Like fieldsExpanded but only visible column infos; infos are not owned. */ | ||||
198 | KDbQueryColumnInfo::Vector visibleFieldsExpanded; | ||||
199 | | ||||
200 | /*! Temporary field vector containing internal fields used for lookup columns. */ | ||||
201 | KDbQueryColumnInfo::Vector internalFields; | ||||
202 | | ||||
203 | /*! Temporary, used to cache sum of expanded fields and internal fields (+record Id) used for lookup columns. | ||||
204 | Contains not auto-deleted items.*/ | ||||
205 | KDbQueryColumnInfo::Vector fieldsExpandedWithInternalAndRecordId; | ||||
206 | | ||||
207 | /*! Like fieldsExpandedWithInternalAndRecordId but only contains visible column infos; infos are not owned.*/ | ||||
208 | KDbQueryColumnInfo::Vector visibleFieldsExpandedWithInternalAndRecordId; | ||||
209 | | ||||
210 | /*! Temporary, used to cache sum of expanded fields and internal fields used for lookup columns. | ||||
211 | Contains not auto-deleted items.*/ | ||||
212 | KDbQueryColumnInfo::Vector fieldsExpandedWithInternal; | ||||
213 | | ||||
214 | /*! Like fieldsExpandedWithInternal but only contains visible column infos; infos are not owned.*/ | ||||
215 | KDbQueryColumnInfo::Vector visibleFieldsExpandedWithInternal; | ||||
216 | | ||||
217 | /*! A hash for fast lookup of query columns' order (unexpanded version). */ | ||||
218 | QHash<KDbQueryColumnInfo*, int> columnsOrder; | ||||
219 | | ||||
220 | /*! A hash for fast lookup of query columns' order (unexpanded version without asterisks). */ | ||||
221 | QHash<KDbQueryColumnInfo*, int> columnsOrderWithoutAsterisks; | ||||
222 | | ||||
223 | /*! A hash for fast lookup of query columns' order. | ||||
224 | This is exactly opposite information compared to vector returned | ||||
225 | by fieldsExpanded() */ | ||||
226 | QHash<KDbQueryColumnInfo*, int> columnsOrderExpanded; | ||||
227 | | ||||
209 | QHash<QString, KDbQueryColumnInfo*> columnInfosByNameExpanded; | 228 | QHash<QString, KDbQueryColumnInfo*> columnInfosByNameExpanded; | ||
210 | 229 | | |||
211 | QHash<QString, KDbQueryColumnInfo*> columnInfosByName; //!< Same as columnInfosByNameExpanded but asterisks are skipped | 230 | QHash<QString, KDbQueryColumnInfo*> columnInfosByName; //!< Same as columnInfosByNameExpanded but asterisks are skipped | ||
212 | 231 | | |||
213 | //! field schemas created for multiple joined columns like a||' '||b||' '||c | 232 | //! field schemas created for multiple joined columns like a||' '||b||' '||c | ||
214 | KDbField::List *ownedVisibleColumns; | 233 | KDbField::List ownedVisibleColumns; | ||
215 | | ||||
216 | /*! Set by insertField(): true, if aliases for expression columns should | | |||
217 | be generated on next columnAlias() call. */ | | |||
218 | bool regenerateExprAliases; | | |||
219 | }; | 234 | }; | ||
220 | 235 | | |||
221 | //! @return identifier string @a name escaped using @a conn connection and type @a escapingType | 236 | //! @return identifier string @a name escaped using @a conn connection and type @a escapingType | ||
222 | QString escapeIdentifier(const QString& name, KDbConnection *conn, | 237 | QString escapeIdentifier(const QString& name, KDbConnection *conn, | ||
223 | KDb::IdentifierEscapingType escapingType); | 238 | KDb::IdentifierEscapingType escapingType); | ||
224 | 239 | | |||
225 | #endif | 240 | #endif |