|
1 /* |
|
2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Constructs SQL clauses for object find* |
|
15 */ |
|
16 |
|
17 #ifndef __MDSFINDSQLCLAUSE_H__ |
|
18 #define __MDSFINDSQLCLAUSE_H__ |
|
19 |
|
20 #include <e32base.h> |
|
21 #include <badesca.h> |
|
22 |
|
23 #include "mdccommon.h" |
|
24 #include "mdssqliteconnection.h" |
|
25 |
|
26 // FORWARD DECLARATIONS |
|
27 class CMdCSerializationBuffer; |
|
28 class CMdsSchema; |
|
29 class CMdsNamespaceDef; |
|
30 class CMdsObjectDef; |
|
31 class CMdsClauseBuffer; |
|
32 class CMdsPropertyDef; |
|
33 class TMdCSearchCriteria; |
|
34 class TMdCRelationCondition; |
|
35 |
|
36 // CLASS DECLARATION |
|
37 /** |
|
38 * CMdSFindSqlClause. |
|
39 * Class constructs SQL search clauses. |
|
40 */ |
|
41 class CMdSFindSqlClause : public CBase |
|
42 //public MMdSFindCriteria |
|
43 { |
|
44 private: |
|
45 enum TAppendIn |
|
46 { |
|
47 EAppendInFalse, |
|
48 EAppendInTrue, |
|
49 EAppendInRelationLeft, |
|
50 EAppendInRelationRight |
|
51 }; |
|
52 |
|
53 enum TRangeValueType |
|
54 { |
|
55 EInt32RangeValue, |
|
56 EUint32RangeValue, |
|
57 EInt64RangeValue |
|
58 }; |
|
59 |
|
60 public: // Constructors and destructor |
|
61 |
|
62 /** |
|
63 * NewL. |
|
64 * Two-phased constructor. |
|
65 * @param aSchema reference to metadata server's internal schema. |
|
66 * @return Pointer to created CMdSFindEngine object. |
|
67 */ |
|
68 static CMdSFindSqlClause* NewL(CMdsSchema& aSchema); |
|
69 |
|
70 /** |
|
71 * NewLC. |
|
72 * Two-phased constructor. |
|
73 * @param aSchema reference to metadata server's internal schema. |
|
74 * @return Pointer to created CMdSManipulationEngine object. |
|
75 */ |
|
76 static CMdSFindSqlClause* NewLC(CMdsSchema& aSchema); |
|
77 |
|
78 /** |
|
79 * Destructor. |
|
80 */ |
|
81 virtual ~CMdSFindSqlClause(); |
|
82 |
|
83 private: // Private constructors |
|
84 |
|
85 /** |
|
86 * CMdSSqlClause. |
|
87 * C++ default constructor. |
|
88 * @param aSchema reference to metadata server's internal schema. |
|
89 */ |
|
90 CMdSFindSqlClause(CMdsSchema& aSchema); |
|
91 |
|
92 /** |
|
93 * ConstructL. |
|
94 * 2nd phase constructor. |
|
95 */ |
|
96 void ConstructL(); |
|
97 |
|
98 public: // Public functions |
|
99 |
|
100 /** |
|
101 * Constructs criteria the LONG way. ALL criteria and rule params |
|
102 * are taken in account. |
|
103 * @param aSerializedCriteria search criteria in serialized form. |
|
104 * @param aUserLevel |
|
105 */ |
|
106 void CreateL( |
|
107 CMdCSerializationBuffer& aSerializedCriteria, |
|
108 TUserLevel aUserLevel ); |
|
109 |
|
110 /** |
|
111 * Returns the decoded value as some kind of textual description |
|
112 * @return search clause as TDesC8 descriptor |
|
113 */ |
|
114 const TDesC& AsTextL() const; |
|
115 |
|
116 /** |
|
117 * Returns constructed variable stack. |
|
118 * @return clause variables. |
|
119 */ |
|
120 RRowData& Variables(); |
|
121 |
|
122 /** |
|
123 * Returns constructed result row stack. |
|
124 * @return clause variables. |
|
125 */ |
|
126 RRowData& ResultRow(); |
|
127 |
|
128 /** |
|
129 * Returns limit count. |
|
130 * @return limit. |
|
131 */ |
|
132 TUint32 Limit(); |
|
133 |
|
134 /** |
|
135 * Does SQL clause include freetext count and total length |
|
136 * @return SQL clause includes freetext count and total length |
|
137 */ |
|
138 TBool IncludesFreetexts(); |
|
139 |
|
140 /** |
|
141 * Returns object query's object definition. |
|
142 * @return Object definition if query is object query else NULL. |
|
143 */ |
|
144 CMdsObjectDef* ObjectDef(); |
|
145 |
|
146 /** |
|
147 * Returns object query's property denitions used in property filter. |
|
148 * @return Object definition if query is object query else NULL. |
|
149 */ |
|
150 RPointerArray<CMdsPropertyDef>& PropertyFilters(); |
|
151 |
|
152 /** |
|
153 * Returns query's namespace definition. |
|
154 * @return Namespace definition if NULL query buffer is corrupted. |
|
155 */ |
|
156 CMdsNamespaceDef* NamespaceDef(); |
|
157 |
|
158 /** |
|
159 * Returns query type. |
|
160 * @return Query type |
|
161 */ |
|
162 TQueryType QueryType(); |
|
163 |
|
164 /** |
|
165 * Returns query result mode. |
|
166 * @return Query result mode |
|
167 */ |
|
168 TQueryResultMode ResultMode(); |
|
169 |
|
170 /** |
|
171 * Returns query freetext array |
|
172 * @return freetext array |
|
173 */ |
|
174 RPointerArray<HBufC>& QueryFreeText(); |
|
175 |
|
176 /** |
|
177 * Result objects are not locked |
|
178 * @return object locking status |
|
179 */ |
|
180 TBool NoObjectLocking(); |
|
181 |
|
182 private: // Private functions |
|
183 |
|
184 /** |
|
185 * appends an array of OR'ed aColumn=ID conditions. |
|
186 * @param aColumn A column of variable set where id is appended |
|
187 * @param aSet container of item ids |
|
188 */ |
|
189 void AppendArrayL( /*const TDesC& aColumn, const RArray<TItemId>& aSet*/ ); |
|
190 |
|
191 void AppendPropertyFiltersL( TBool aDistinct = EFalse ); |
|
192 |
|
193 /** |
|
194 * Creates "SELECT column list FROM table name" SQL clause query |
|
195 * based on iType. |
|
196 */ |
|
197 void AppendSelectStatementL(); |
|
198 |
|
199 /** |
|
200 * Creates "SELECT count(*) FROM table name" SQL clause query |
|
201 * based on iType. |
|
202 */ |
|
203 void AppendSelectCountStatementL(); |
|
204 |
|
205 /** |
|
206 * Creates "SELECT * FROM table name" SQL clause query |
|
207 * based on iType. |
|
208 */ |
|
209 void AppendSelectAllFromEventStatementL(); |
|
210 |
|
211 void AppendSelectAllFromRelationStatementL(); |
|
212 |
|
213 void AppendSelectEventItemStatementL(); |
|
214 |
|
215 void AppendSelectRealtionItemStatementL(); |
|
216 |
|
217 /** |
|
218 * Creates "SELECT DISTINCT "wanted property's column" FROM table name" |
|
219 * SQL clause query based on iType. |
|
220 */ |
|
221 void AppendSelectDistinctStatementL(); |
|
222 |
|
223 void AppendSelectObjectItemStatementL(); |
|
224 |
|
225 void AppendSelectObjectIdStatementL(); |
|
226 |
|
227 void AppendFromForObjectL(); |
|
228 |
|
229 void AppendFromForEventL(); |
|
230 |
|
231 void AppendFromForRelationL(); |
|
232 |
|
233 /** |
|
234 * Creates "WHERE(...)" |
|
235 */ |
|
236 void AppendWhereStatementL(); |
|
237 |
|
238 /** |
|
239 * Helper which creates "SELECT statement for object query. |
|
240 */ |
|
241 void AppendSelectForObjectL(); |
|
242 |
|
243 /** |
|
244 * Helper which creates "SELECT statement for relation query. |
|
245 * @param aRules find rules |
|
246 */ |
|
247 void AppendSelectForRelationL( /*const TMdCFolder& aRules*/ ); |
|
248 |
|
249 /** |
|
250 * Helper which creates "SELECT statement for event query. |
|
251 * @param aRules find rules |
|
252 */ |
|
253 void AppendSelectForEventL( /*const TMdCFolder& aRules*/ ); |
|
254 |
|
255 /** |
|
256 * Help method for where clause parsing and is used recursively. |
|
257 */ |
|
258 void WhereStatementL(); |
|
259 |
|
260 void ConditionStatementL(TBool aNegated = EFalse, TAppendIn aAppendIdIn = EAppendInTrue); |
|
261 |
|
262 void AppendObjectIdL(); |
|
263 |
|
264 void AppendIdInL(); |
|
265 |
|
266 /** |
|
267 * Help method for appending logic condition. |
|
268 * @param aNegated is condition negated |
|
269 */ |
|
270 void AppendLogicConditionL(TBool aNegated, TAppendIn aAppendIdIn = EAppendInTrue); |
|
271 |
|
272 /** |
|
273 * Help method for appending object condition. |
|
274 * @param aNegated is condition negated |
|
275 */ |
|
276 void AppendObjectConditionL(TBool aNegated); |
|
277 |
|
278 /** |
|
279 * Help method for appending range. |
|
280 * @param aRangeValueType type of range's values |
|
281 */ |
|
282 void AppendRangeL(TRangeValueType aRangeValueType); |
|
283 |
|
284 /** |
|
285 * Help method for appending property condition. |
|
286 * |
|
287 * @param aNegated is condition negated |
|
288 */ |
|
289 void AppendPropertyConditionL(TBool aNegated); |
|
290 |
|
291 /** |
|
292 * Helper method for getting object definition for property condition. |
|
293 * |
|
294 * @param aObjectDefId property condition's object definition |
|
295 * |
|
296 * @return object definition for query |
|
297 */ |
|
298 TDefId ObjectDefForPropertyCondition(TDefId aObjectDefId); |
|
299 |
|
300 /** |
|
301 * Help method for appending property range condition. |
|
302 * |
|
303 * @param aNegated is condition negated |
|
304 */ |
|
305 void AppendPropertyRangeConditionL(TBool aNegated); |
|
306 |
|
307 /** |
|
308 * Help method for appending property text condition. |
|
309 * @param aNegated is condition negated |
|
310 */ |
|
311 void AppendPropertyTextConditionL(TBool aNegated); |
|
312 |
|
313 /** |
|
314 * Help method for appending property bool condition. |
|
315 * @param aNegated is condition negated |
|
316 */ |
|
317 void AppendPropertyBoolConditionL(TBool aNegated); |
|
318 |
|
319 /** |
|
320 * Help method for appending event condition for object query. |
|
321 * @param aNegated is condition negated |
|
322 */ |
|
323 void AppendEventConditionL(TBool aNegated); |
|
324 |
|
325 /** |
|
326 * Help method for appending relation condition for object query. |
|
327 * @param aNegated is condition negated |
|
328 */ |
|
329 void AppendRelationConditionL(TBool aNegated); |
|
330 |
|
331 void AppendRelationSideConditionL(TBool aRelationConditions, |
|
332 const TMdCRelationCondition& aRelationCondition, |
|
333 TBool aLeftSide, TUint32 aRelationObjectConditionOffset); |
|
334 |
|
335 /** |
|
336 * Help method for searching object definition's table, |
|
337 * based on object definition's ID, and appending those to buffer. |
|
338 * @param aObjectDefId object definition's ID |
|
339 */ |
|
340 void AppendTableByObjectDefIdL(TDefId aObjectDefId); |
|
341 |
|
342 /** |
|
343 * Help method for searching property definition's column, |
|
344 * based on property definition's ID, and appending those to buffer. |
|
345 * @param aPropertyDefId property definition's ID |
|
346 * @param aObjectDefId object definition's ID |
|
347 * @param aResult append property to expected result row |
|
348 */ |
|
349 void AppendColumnByPropertyDefIdL(TDefId aPropertyDefId, TDefId aObjectDefId = KNoDefId, TBool aResult = EFalse); |
|
350 |
|
351 /** |
|
352 * Help method which appends GROUP BY statements. |
|
353 */ |
|
354 void AppendGroupByL(); |
|
355 |
|
356 /** |
|
357 * Help method which appends ORDER BY statements. |
|
358 */ |
|
359 void AppendOrderByL(); |
|
360 |
|
361 /** |
|
362 * Help method which appends LIMIT and OFFSET. |
|
363 */ |
|
364 void AppendLimitAndOffsetL(); |
|
365 |
|
366 /** |
|
367 * Help method that copies the rightmost part of the variables to |
|
368 * RowData. The function does not cut or remove any data but doubles |
|
369 * a number of variables. |
|
370 * @param aStart index of the first variable to be copied. |
|
371 * @param aEnd index of the last variable to be copied. |
|
372 */ |
|
373 void CopyVariablesL( TInt aStart, TInt aEnd ); |
|
374 |
|
375 private: // Member data |
|
376 |
|
377 /** |
|
378 * variables used in the clause. |
|
379 * Note: RRowData constructor cannot leave, since it is initialized (aInStack==EFalse) |
|
380 */ |
|
381 RRowData iVariables; |
|
382 |
|
383 /** |
|
384 * Expected result row from the clause. |
|
385 * Note: RRowData constructor cannot leave, since it is initialized (aInStack==EFalse) |
|
386 */ |
|
387 RRowData iResultRow; |
|
388 |
|
389 /** |
|
390 * Text buffer for whole query clause. CMdsClauseBuffer class takes care |
|
391 * of memory allocation for buffer. |
|
392 */ |
|
393 CMdsClauseBuffer* iQueryBuf; |
|
394 |
|
395 /** |
|
396 * Metadata Server's internal schema |
|
397 */ |
|
398 CMdsSchema& iSchema; |
|
399 |
|
400 /** |
|
401 * Serialized query critertia |
|
402 */ |
|
403 TMdCSearchCriteria* iSearchCriteria; |
|
404 |
|
405 /** |
|
406 * Serialized query critertia |
|
407 */ |
|
408 CMdCSerializationBuffer* iSerializedBuffer; |
|
409 |
|
410 /** |
|
411 * Client application's user level |
|
412 */ |
|
413 TUserLevel iUserLevel; |
|
414 |
|
415 /** |
|
416 * Namespace definition where to search |
|
417 */ |
|
418 CMdsNamespaceDef* iNamespaceDef; |
|
419 |
|
420 /** |
|
421 * Object definition for where to (WHERE expression) search in object |
|
422 * queries |
|
423 */ |
|
424 CMdsObjectDef* iObjectDef; |
|
425 |
|
426 /** |
|
427 * Object definition for what to (SELECT result and FROM table list) |
|
428 * search in object queries |
|
429 */ |
|
430 CMdsObjectDef* iSourceObjectDef; |
|
431 |
|
432 /** |
|
433 * Object definitions IDs for what to (SELECT result and FROM table list) |
|
434 * search in object queries |
|
435 */ |
|
436 RArray<TDefId>* iSourceObjectDefs; |
|
437 |
|
438 /** |
|
439 * Append columns to result row (ETrue only for first ID from iSourceObjectDefs). |
|
440 */ |
|
441 TBool iAppendToResultRow; |
|
442 |
|
443 /** |
|
444 * Descriptor which contains namespace definition's ID in text format |
|
445 */ |
|
446 TBuf16<16> iNamespaceIdDes; |
|
447 |
|
448 /** |
|
449 * Filter property definition references |
|
450 */ |
|
451 RPointerArray<CMdsPropertyDef> iPropertyFilters; |
|
452 |
|
453 /** |
|
454 * Include freetexts to result. |
|
455 */ |
|
456 TBool iIncludeFreetexts; |
|
457 |
|
458 /** |
|
459 * Include not present items to result. |
|
460 */ |
|
461 TBool iIncludeNotPresent; |
|
462 |
|
463 /** |
|
464 * Free text which belong to query. |
|
465 */ |
|
466 RPointerArray<HBufC> iFreeText; |
|
467 |
|
468 /** |
|
469 * Result objects are not locked. |
|
470 */ |
|
471 TBool iNoObjectLocking; |
|
472 |
|
473 TBool iPlaceholdersOnly; |
|
474 }; |
|
475 |
|
476 #endif //__MDSFINDSQLCLAUSE_H__ |