85
|
1 |
/*
|
|
2 |
* Copyright (c) 2008 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: CSqlQuery declaration
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
#ifndef CASQLQUERY_H
|
|
18 |
#define CASQLQUERY_H
|
|
19 |
// INCLUDES
|
|
20 |
#include <e32std.h>
|
|
21 |
#include <e32base.h>
|
|
22 |
#include <sqldb.h>
|
|
23 |
#include "caentryattribute.h"
|
|
24 |
#include "castorage_global.h"
|
|
25 |
#include "cainnerentry.h"
|
|
26 |
CA_STORAGE_TEST_CLASS(CCAStorageTest)
|
|
27 |
|
|
28 |
// CLASS DECLARATION
|
|
29 |
class RSqlDatabase;
|
|
30 |
class RSqlStatement;
|
|
31 |
class CCaInnerEntry;
|
|
32 |
class CCaInnerQuery;
|
|
33 |
class TCaOperationParams;
|
|
34 |
class CCaLocalizationEntry;
|
|
35 |
/**
|
|
36 |
* CSqlQuery
|
|
37 |
*
|
|
38 |
*/
|
|
39 |
const TInt KMaxIntNumLength = 10;
|
|
40 |
|
|
41 |
/**
|
|
42 |
* @ingroup group_catorage.
|
|
43 |
* CCaSqlQuery represents a query to be executed on the sql database.
|
|
44 |
*
|
|
45 |
*/
|
|
46 |
NONSHARABLE_CLASS( CCaSqlQuery ) : public CBase
|
|
47 |
{
|
|
48 |
CA_STORAGE_TEST_FRIEND_CLASS(CCAStorageTest)
|
|
49 |
|
|
50 |
public:
|
|
51 |
|
|
52 |
/**
|
|
53 |
* The query table types.
|
|
54 |
*/
|
|
55 |
enum TTableType
|
|
56 |
{
|
|
57 |
ENoTableType,
|
|
58 |
EEntryTable,
|
|
59 |
EIconTable,
|
|
60 |
EAttributeTable,
|
|
61 |
EGroupTable,
|
|
62 |
EGroupTableRemove,
|
|
63 |
EGroupTableInsert,
|
|
64 |
ELaunchTable
|
|
65 |
};
|
|
66 |
|
|
67 |
/**
|
|
68 |
* The query execution result types.
|
|
69 |
*/
|
|
70 |
enum TQueryResultType
|
|
71 |
{
|
|
72 |
EEntry,
|
|
73 |
EAttribute
|
|
74 |
};
|
|
75 |
// Constructors and destructor
|
|
76 |
|
|
77 |
/**
|
|
78 |
* Destructor.
|
|
79 |
*/
|
|
80 |
~CCaSqlQuery();
|
|
81 |
|
|
82 |
/**
|
|
83 |
* Two-phased constructor.
|
|
84 |
*/
|
|
85 |
static CCaSqlQuery* NewL( RSqlDatabase& aSql );
|
|
86 |
|
|
87 |
/**
|
|
88 |
* Two-phased constructor.
|
|
89 |
*/
|
|
90 |
static CCaSqlQuery* NewLC( RSqlDatabase& aSql );
|
|
91 |
|
|
92 |
/**
|
|
93 |
* Set the query text.
|
|
94 |
*
|
|
95 |
* @param aQuery the new query text.
|
|
96 |
*/
|
|
97 |
void SetQueryL( const TDesC& aQuery );
|
|
98 |
|
|
99 |
/**
|
|
100 |
* Sets the table type on which the sql operation
|
|
101 |
* will be performed for this query.
|
|
102 |
*
|
|
103 |
* @param aType the table type.
|
|
104 |
*/
|
|
105 |
void SetTableType( TTableType aType )
|
|
106 |
{
|
|
107 |
iType = aType;
|
|
108 |
}
|
|
109 |
|
|
110 |
/**
|
|
111 |
* Returns the table type on which the sql operation
|
|
112 |
* will be performed for this query.
|
|
113 |
*
|
|
114 |
* @return
|
|
115 |
*/
|
|
116 |
TTableType Type()
|
|
117 |
{
|
|
118 |
return iType;
|
|
119 |
}
|
|
120 |
|
|
121 |
/**
|
|
122 |
* Executes prepares for iStatement.
|
|
123 |
*/
|
|
124 |
void PrepareL();
|
|
125 |
|
|
126 |
/**
|
|
127 |
* Closes the statement to free resources.
|
|
128 |
*/
|
|
129 |
void CloseStatement();
|
|
130 |
|
|
131 |
/**
|
|
132 |
* Reset the statement for future bindings and use.
|
|
133 |
*/
|
|
134 |
void ResetStatement();
|
|
135 |
|
|
136 |
/**
|
|
137 |
* Binds values for an add operation.
|
|
138 |
*
|
|
139 |
* @param aEntry The entry from which to get data for bindings.
|
|
140 |
*/
|
|
141 |
void BindValuesForAddL( const CCaInnerEntry* aEntry );
|
|
142 |
|
|
143 |
/**
|
94
|
144 |
* Binds values for an get localization entry
|
|
145 |
*
|
|
146 |
* @param aLocalization The entry from which to get data for bindings.
|
|
147 |
*/
|
|
148 |
void BindValuesForGetLocalizationEntryL(
|
|
149 |
const CCaLocalizationEntry& aLocalization);
|
|
150 |
|
|
151 |
/**
|
|
152 |
* Binds values for an add and update localization entry
|
|
153 |
*
|
|
154 |
* @param aLocalization The entry from which to get data for bindings.
|
|
155 |
*/
|
|
156 |
void BindValuesForLocalizationEntryL(
|
|
157 |
const CCaLocalizationEntry& aLocalization);
|
|
158 |
|
|
159 |
/**
|
85
|
160 |
* Binds values for an add operation.
|
|
161 |
*
|
|
162 |
* @param aQuery The query from which to get data for bindings.
|
|
163 |
*/
|
|
164 |
void BindValuesForGetEntriesL( const CCaInnerQuery* aQuery );
|
|
165 |
|
|
166 |
/**
|
|
167 |
* Binds values for an add operation.
|
|
168 |
*
|
|
169 |
* @param aEntry The entry from which to get data for bindings.
|
|
170 |
*/
|
|
171 |
void BindValuesForGetEntriesL( const CCaInnerEntry* aEntry );
|
|
172 |
|
|
173 |
/**
|
|
174 |
* Binds values for an add operation.
|
|
175 |
*
|
|
176 |
* @param aEntry The entry from which to get data for bindings.
|
|
177 |
*/
|
|
178 |
void BindValuesForGetIconL( const CCaInnerEntry* aEntry );
|
|
179 |
|
|
180 |
/**
|
|
181 |
* Binds the entry ids from a given entry array.
|
|
182 |
*
|
|
183 |
* @param aEntryArray An array of entries which
|
|
184 |
* ids to bind with the statement.
|
|
185 |
*/
|
|
186 |
void BindEntryIdsL( const RPointerArray<CCaInnerEntry>& aEntryArray );
|
|
187 |
|
|
188 |
/**
|
|
189 |
* Binds the entry ids from a given entry id array.
|
|
190 |
*
|
|
191 |
* @param aEntryIdArray An array of entry ids to bind with the statement.
|
|
192 |
* @param aColName column name with specified id.
|
|
193 |
*/
|
|
194 |
void BindIdsL( const RArray<TInt>& aEntryIdArray,
|
|
195 |
const TDesC& aColName );
|
|
196 |
|
|
197 |
/**
|
|
198 |
* Bind one entry id to the statement.
|
|
199 |
*
|
|
200 |
* @param aEntryId the id to bind.
|
|
201 |
*/
|
|
202 |
void BindEntryIdL( const TInt& aEntryId );
|
|
203 |
|
|
204 |
/**
|
|
205 |
* Binds values for an add attributes operation.
|
|
206 |
*
|
|
207 |
* @param aEntry The entry from which to get data for bindings.
|
|
208 |
* @param aAttr The attribute data to bind.
|
|
209 |
*/
|
|
210 |
void BindValuesForAddAttributeL( const CCaInnerEntry* aEntry,
|
|
211 |
const CCaEntryAttribute* aAttr );
|
|
212 |
|
|
213 |
/**
|
|
214 |
* Binds values for a launch operation.
|
|
215 |
*
|
|
216 |
* @param aEntryId The entry id to bind.
|
|
217 |
* @param aLaunchTime the launch time to bind.
|
|
218 |
*/
|
|
219 |
void BindValuesForLaunchL( const TInt aEntryId,
|
|
220 |
const TInt64 aLaunchTime );
|
|
221 |
|
|
222 |
/**
|
|
223 |
* Binds values for a remove operation.
|
|
224 |
*
|
|
225 |
* @param aEntryId The entry id to bind.
|
|
226 |
* @param aIconId the icon id to bind.
|
|
227 |
*/
|
|
228 |
void BindValuesForRemoveL( const TInt aEntryId, const TInt aIconId );
|
|
229 |
|
|
230 |
/**
|
|
231 |
* Binds values for an organize operation.
|
|
232 |
*
|
|
233 |
* @param aEntryIds The id array to bind.
|
|
234 |
* @param aParams Organize operation parameters to bind.
|
|
235 |
* @param aEntryId A concrete entry id to bind if needed.
|
|
236 |
*/
|
|
237 |
void BindValuesForOrganizeL( const RArray<TInt>& aEntryIds,
|
|
238 |
TCaOperationParams& aParams, const TInt aEntryId = -1 );
|
|
239 |
|
|
240 |
/**
|
|
241 |
* Binds values for a localize operation.
|
|
242 |
*
|
|
243 |
* @param aLocalization Localization data to bind
|
|
244 |
*/
|
|
245 |
void BindValuesForLocalizeL( CCaLocalizationEntry& aLocalization );
|
|
246 |
|
|
247 |
/**
|
|
248 |
* Binds values for property operation.
|
|
249 |
*
|
|
250 |
* @param aProperty Property data to bind.
|
|
251 |
*/
|
|
252 |
void BindValuesForPropertyL( const TDesC& aProperty );
|
|
253 |
|
|
254 |
/**
|
|
255 |
* Binds values for property update operation.
|
|
256 |
*
|
|
257 |
* @param aProperty Property data to bind.
|
|
258 |
* @param aPropertyValue Property value data to bind.
|
|
259 |
*/
|
|
260 |
void BindValuesForPropertyUpdateL( const TDesC& aProperty, const TDesC& aPropertyValue );
|
|
261 |
|
|
262 |
/**
|
|
263 |
* Binds values for remove from localization.
|
|
264 |
*
|
|
265 |
* @param aEntryId.
|
|
266 |
*/
|
|
267 |
void BindValuesForRemoveFromLocalizationL( const TInt aEntryId );
|
|
268 |
|
|
269 |
/**
|
|
270 |
* Binds values for custom sort.
|
|
271 |
*
|
|
272 |
* @param aGroupId.
|
|
273 |
* @param aEntryId.
|
|
274 |
* @param aNewPostion.
|
|
275 |
*/
|
|
276 |
void BindValuesForCustomSortL( const TInt aGroupId, const TInt aEntryId,
|
|
277 |
const TInt aNewPostion );
|
|
278 |
|
|
279 |
/**
|
|
280 |
*
|
|
281 |
* Executes a statement.
|
|
282 |
*
|
|
283 |
* @return the id of a last insert operation done.
|
|
284 |
*/
|
|
285 |
TInt ExecuteL();
|
|
286 |
|
|
287 |
/**
|
|
288 |
* Executes a statement.
|
|
289 |
*
|
94
|
290 |
* @return ETrue if any data was found
|
|
291 |
*/
|
|
292 |
TBool ExecuteEntryPresentL( );
|
|
293 |
|
|
294 |
/**
|
|
295 |
* Executes a statement.
|
|
296 |
*
|
85
|
297 |
* @param[out] aId id of single data the query statement queries for.
|
|
298 |
* @return Entry count.
|
|
299 |
*/
|
|
300 |
TInt ExecuteL( TInt& aId );
|
|
301 |
|
|
302 |
/**
|
|
303 |
* Executes a statement.
|
|
304 |
*
|
|
305 |
* @param[out] aId id of single data the query statement queries for.
|
|
306 |
* @return Entry count.
|
|
307 |
*/
|
|
308 |
TInt ExecuteL( TInt64& aId );
|
|
309 |
|
|
310 |
/**
|
|
311 |
* Executes a statement.
|
|
312 |
*
|
|
313 |
* @param aEntryArray An entry array to be populated
|
|
314 |
* with data specified by aResultType.
|
|
315 |
* @return Entry count.
|
|
316 |
*/
|
|
317 |
TInt ExecuteL( RPointerArray<CCaInnerEntry>& result,
|
|
318 |
TQueryResultType aResultType );
|
|
319 |
|
|
320 |
/**
|
|
321 |
* Executes a statement.
|
|
322 |
*
|
|
323 |
* @param aResultInput An localization array to be populated.
|
|
324 |
* @return localization count.
|
|
325 |
*/
|
|
326 |
TInt ExecuteLocalizationsL(
|
|
327 |
RPointerArray<CCaLocalizationEntry>& aResultInput );
|
|
328 |
|
|
329 |
/**
|
|
330 |
* Executes a statement.
|
|
331 |
*
|
|
332 |
* @param aPropertyValue An property value.
|
|
333 |
* @return count.
|
|
334 |
*/
|
|
335 |
TInt ExecutePropertyL( TDes& aPropertyValue );
|
|
336 |
|
|
337 |
/**
|
|
338 |
* Executes a statement.
|
|
339 |
*
|
|
340 |
* @param aEntryArray An ids array to be populated
|
|
341 |
* with id specified by TableType.
|
|
342 |
* @param aType a table type.
|
|
343 |
* @return Entry count.
|
|
344 |
*/
|
|
345 |
TInt ExecuteL( RArray<TInt>& aResultIdArray, TTableType aType );
|
|
346 |
|
|
347 |
/**
|
|
348 |
* Executes a statement.
|
|
349 |
*
|
|
350 |
* @param aIconAttributes an icon attributes.
|
|
351 |
* @return Entry count.
|
|
352 |
*/
|
92
|
353 |
TInt ExecuteL( CCaInnerIconDescription* aInnerIconDescription );
|
85
|
354 |
|
|
355 |
private:
|
|
356 |
|
|
357 |
/**
|
|
358 |
* Executes a statement.
|
|
359 |
*
|
|
360 |
* @param aEntryArray An entry array to be populated.
|
|
361 |
* @return Entry count.
|
|
362 |
*/
|
|
363 |
TInt ExecuteEntryL( RPointerArray<CCaInnerEntry>& aEntryArray );
|
|
364 |
|
|
365 |
/**
|
|
366 |
* Executes a statement.
|
|
367 |
*
|
|
368 |
* @param aEntryArray An entry array to be populated.
|
|
369 |
* @return Entry count.
|
|
370 |
*/
|
|
371 |
TInt ExecuteAttributeL( RPointerArray<CCaInnerEntry>& aEntryArray );
|
|
372 |
|
|
373 |
/**
|
|
374 |
* Constructor for performing 1st stage construction
|
|
375 |
* @param aSql
|
|
376 |
*/
|
|
377 |
CCaSqlQuery( RSqlDatabase& aSql );
|
|
378 |
|
|
379 |
/**
|
|
380 |
* default constructor for performing 2nd stage construction
|
|
381 |
*/
|
|
382 |
void ConstructL();
|
|
383 |
|
|
384 |
/**
|
|
385 |
* Binds values for an add entry operation.
|
|
386 |
*
|
|
387 |
* @param aEntry The entry from which to get data for bindings.
|
|
388 |
*/
|
|
389 |
void BindValuesForAddEntryL( const CCaInnerEntry* aEntry );
|
|
390 |
|
|
391 |
/**
|
|
392 |
* Binds values for an add icon operation.
|
|
393 |
*
|
|
394 |
* @param aEntry The entry from which to get data for bindings.
|
|
395 |
*/
|
|
396 |
void BindValuesForAddIconL( const CCaInnerEntry* aEntry );
|
|
397 |
|
|
398 |
/**
|
|
399 |
* Binds a text value to iStatement.
|
|
400 |
*
|
|
401 |
* @param aParameterIndex The parameter index to bind to.
|
|
402 |
* @param aParameterValue The text to bind.
|
|
403 |
*/
|
|
404 |
void BindTextL( TInt aParameterIndex,
|
|
405 |
const TDesC& aParameterValue );
|
|
406 |
|
|
407 |
/**
|
|
408 |
* Binds a int value to iStatement.
|
|
409 |
*
|
|
410 |
* @param aParameterIndex The parameter index to bind to.
|
|
411 |
* @param aParameterValue The number to bind.
|
|
412 |
*/
|
|
413 |
void BindIntL( TInt aParameterIndex,
|
|
414 |
TInt aParameterValue );
|
|
415 |
|
|
416 |
/**
|
|
417 |
* Binds a int64 value to iStatement.
|
|
418 |
*
|
|
419 |
* @param aParameterIndex The parameter index to bind to.
|
|
420 |
* @param aParameterValue The number to bind.
|
|
421 |
*/
|
|
422 |
void BindInt64L( TInt aParameterIndex,
|
|
423 |
TInt64 aParameterValue );
|
|
424 |
|
|
425 |
/**
|
|
426 |
* Gets the column index for a given column name.
|
|
427 |
*
|
|
428 |
* @param aStmt The statement to search for a column index.
|
|
429 |
* @param aColumnName The name of the column.
|
|
430 |
* @return The column index.
|
|
431 |
*/
|
|
432 |
TInt ColumnIndexL( RSqlStatement& aStmt,
|
|
433 |
const TDesC& aColumnName ) const;
|
|
434 |
|
|
435 |
/**
|
|
436 |
* Sets attributes to entries.
|
|
437 |
*
|
|
438 |
* @param aResultInput A list of entries for which to set attributes.
|
|
439 |
*/
|
|
440 |
void SetAttributeToEntriesL(
|
|
441 |
RPointerArray<CCaInnerEntry>& aResultInput );
|
|
442 |
|
|
443 |
/**
|
|
444 |
* Own.
|
|
445 |
* The query text to be executed.
|
|
446 |
*/
|
|
447 |
RBuf iQuery;
|
|
448 |
|
|
449 |
/**
|
|
450 |
* The table type on which teh operation is done.
|
|
451 |
* @return
|
|
452 |
*/
|
|
453 |
TTableType iType;
|
|
454 |
|
|
455 |
/**
|
|
456 |
* The statement to be executed.
|
|
457 |
* Own.
|
|
458 |
*/
|
|
459 |
RSqlStatement iStatement;
|
|
460 |
|
|
461 |
/*not own*/
|
|
462 |
RSqlDatabase& iSqlDb;
|
|
463 |
|
|
464 |
/**
|
|
465 |
* The execute method result type.
|
|
466 |
* Needs to be specified when the same result type in ExecuteL
|
|
467 |
* is used to perform dufferent operations.
|
|
468 |
*/
|
|
469 |
TQueryResultType iQueryResultType;
|
|
470 |
|
|
471 |
};
|
|
472 |
|
|
473 |
#endif // CASQLQUERY_H
|