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: SQLite Connection class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 #ifndef C_CMSQLCONNECTION_H |
|
25 #define C_CMSQLCONNECTION_H |
|
26 |
|
27 #include <e32base.h> |
|
28 #include <sqldb.h> |
|
29 #include "cmcommontypes.h" |
|
30 |
|
31 /* Forward declarations. */ |
|
32 class CCmSqlBaseItem; |
|
33 class CCmSqlGenericItem; |
|
34 class CCmSqlPropertyItem; |
|
35 class CCmBaseListItem; |
|
36 class CCmFillListItem; |
|
37 class CCmFillRule; |
|
38 class CCmSqlPropertyCollector; |
|
39 class CCmSqlPropertyContainer; |
|
40 |
|
41 // Constants |
|
42 const TUint KCmSqlBatchSize = 100; |
|
43 |
|
44 // CLASS DECLARATION |
|
45 /** |
|
46 * Class represents methods to communication with SQLite database API. |
|
47 * |
|
48 * @lib cmsqlwrapper.lib |
|
49 * |
|
50 * @since S60 5.1 |
|
51 */ |
|
52 class CCmSqlConnection : public CBase |
|
53 { |
|
54 |
|
55 private: |
|
56 |
|
57 // Operation modes |
|
58 enum TCmSqlOperationMode |
|
59 { |
|
60 ECmSqlFillItemGet = 1, |
|
61 ECmSqlBaseItemGet, |
|
62 ECmSqlPropertyValueGet, |
|
63 ECmSqlGenericItemAdd, |
|
64 ECmSqlPropertyItemAdd, |
|
65 ECmSqlIdle, |
|
66 ECmSqlDeletingMetadata, |
|
67 ECmSqlFilteredPropertyGet |
|
68 }; |
|
69 public: |
|
70 |
|
71 /** |
|
72 * Two-phased constructor. |
|
73 */ |
|
74 static CCmSqlConnection* NewL(); |
|
75 |
|
76 /** |
|
77 * Two-phased constructor. |
|
78 */ |
|
79 static CCmSqlConnection* NewLC(); |
|
80 |
|
81 /** |
|
82 * Destructor. |
|
83 */ |
|
84 virtual ~CCmSqlConnection(); |
|
85 |
|
86 /** |
|
87 * Open database (creates if doesn't exist) |
|
88 * |
|
89 * @since S60 5.1 |
|
90 * @param aDb, Database filename and path |
|
91 * @return error code |
|
92 */ |
|
93 TInt OpenDb( const TDesC& aDb ); |
|
94 |
|
95 /** |
|
96 * Close opened database |
|
97 * |
|
98 * @since S60 5.1 |
|
99 * @param None |
|
100 * @return None |
|
101 */ |
|
102 void CloseDb(); |
|
103 |
|
104 /** |
|
105 * Creates db file |
|
106 * @since S60 5.1 |
|
107 * @param aDb, Database filename and path |
|
108 * @return error code |
|
109 */ |
|
110 TInt CreateDbFile( const TDesC& aDb ); |
|
111 |
|
112 /** |
|
113 * Validates database existence and format |
|
114 * |
|
115 * @since S60 5.1 |
|
116 * @param None |
|
117 * @return ETrue if db valid |
|
118 */ |
|
119 TBool Validate(); |
|
120 |
|
121 /** |
|
122 * Executes sql command |
|
123 * |
|
124 * @since S60 5.1 |
|
125 * @param aCommand, command to be executed |
|
126 * @return None |
|
127 */ |
|
128 void ExecuteL( const TDesC8& aCommand ); |
|
129 |
|
130 /** |
|
131 * Cance asyncronous operation |
|
132 * |
|
133 * @since S60 5.1 |
|
134 * @param None |
|
135 * @return None |
|
136 */ |
|
137 void CancelAsyncOperation(); |
|
138 |
|
139 /** |
|
140 * Setting media server id |
|
141 * |
|
142 * @since S60 5.1 |
|
143 * @param aId, media server id to be used |
|
144 * @return None |
|
145 */ |
|
146 void SetMsId( TUint aId ); |
|
147 |
|
148 /** |
|
149 * Setting mmc quota |
|
150 * |
|
151 * @since S60 5.1 |
|
152 * @param aQuota, quota to be used |
|
153 * @return None |
|
154 */ |
|
155 void SetQuota( TInt64 aQuota ); |
|
156 |
|
157 /** |
|
158 * Asyncronous batch add |
|
159 * |
|
160 * @since S60 5.1 |
|
161 * @param aItems, items to be inserted into database |
|
162 * @param aStatus, request status to be completed after insert is ready |
|
163 * @return None |
|
164 */ |
|
165 void AsyncBatchAdd( RPointerArray<CCmSqlGenericItem>& aItems, |
|
166 TRequestStatus& aStatus ); |
|
167 |
|
168 /** |
|
169 * Asyncronous property item batch add |
|
170 * |
|
171 * @since S60 5.1 |
|
172 * @param aItems, items to be inserted into database |
|
173 * @param aField, property type identifier |
|
174 * @param aStatus, request status to be completed after insert is ready |
|
175 * @return None |
|
176 */ |
|
177 void AsyncBatchAddPropertyItems( |
|
178 RPointerArray<CCmSqlPropertyItem>& aItems, TCmMetadataField aField, |
|
179 TRequestStatus& aStatus ); |
|
180 |
|
181 /** |
|
182 * Syncronous property item add |
|
183 * |
|
184 * @since S60 5.1 |
|
185 * @param aItem, item to be inserted into database |
|
186 * @param aField, property type identifier |
|
187 * @return None |
|
188 */ |
|
189 void SyncAddPropertyItemL( |
|
190 CCmSqlPropertyItem& aItem, TCmMetadataField aField ); |
|
191 |
|
192 /** |
|
193 * Asyncronous item batch delete |
|
194 * |
|
195 * @since S60 5.1 |
|
196 * @param aItems, items to be deleted |
|
197 * @param aStatus, request status to be completed |
|
198 * @return None |
|
199 */ |
|
200 void AsyncBatchDelete( RPointerArray<CCmSqlBaseItem>& aItems, |
|
201 TRequestStatus& aStatus ); |
|
202 |
|
203 /** |
|
204 * Asyncronous metadata delete |
|
205 * |
|
206 * @since S60 5.1 |
|
207 * @param aMsIds, defines where metadata is harvested |
|
208 * @param aStatus, request status to be completed |
|
209 * @return None |
|
210 */ |
|
211 void AsyncMetadataDelete( RArray<TInt>& aMsIds, |
|
212 TRequestStatus& aStatus ); |
|
213 |
|
214 /** |
|
215 * SELECT XXX oldest and delete those |
|
216 * Delete defined amount of media items |
|
217 * |
|
218 * @since S60 5.1 |
|
219 * @param aType, media type identifier |
|
220 * @param aCount, amount to be deleted |
|
221 * @return None |
|
222 */ |
|
223 void DeleteOldestMediaItemsL( TCmMediaType aType, TInt64 aCount ); |
|
224 |
|
225 /** |
|
226 * Deletes unused propertys |
|
227 * |
|
228 * @since S60 5.1 |
|
229 * @param None |
|
230 * @return None |
|
231 */ |
|
232 void DeleteUnusedPropertys( ); |
|
233 |
|
234 /** |
|
235 * Asyncronous metadata column qyery |
|
236 * |
|
237 * @since S60 5.1 |
|
238 * @param aItems, listed base items ( included only ItemId, dbId and |
|
239 * Hash code ) |
|
240 * @param aStatus, request status to be completed when result set ready |
|
241 * @return None |
|
242 */ |
|
243 void GetItemsL( RPointerArray<CCmSqlBaseItem>& aItems, |
|
244 TRequestStatus& aStatus ); |
|
245 |
|
246 /** |
|
247 * Asyncronous metadata qyery for fill list |
|
248 * |
|
249 * @since S60 5.1 |
|
250 * @param aItems, listed fill list items |
|
251 * @param aClause, sql clause to be executed |
|
252 * @param aRule, used fill list |
|
253 * @param aStatus, request status to be completed when result set ready |
|
254 * @return None |
|
255 */ |
|
256 void GetFillItemsL( RPointerArray<CCmFillListItem>& aItems, |
|
257 TDesC8& aClause, CCmFillRule& aRule, TRequestStatus& aStatus ); |
|
258 |
|
259 /** |
|
260 * Asyncronous metadata column qyery |
|
261 * |
|
262 * @since S60 5.1 |
|
263 * @param aItems, listed property values |
|
264 * @param aClause, sql clause to be executed |
|
265 * @param aStatus, request status to be completed when result set ready |
|
266 * @return None |
|
267 */ |
|
268 void GetPropertyValuesL( RPointerArray<CCmSqlPropertyItem>& aItems, |
|
269 TDesC8& aClause, TRequestStatus& aStatus ); |
|
270 |
|
271 /** |
|
272 * Asyncronous metadata filtered property values query |
|
273 * |
|
274 * @since S60 5.1 |
|
275 * @param aPropertys, result array reference |
|
276 * @param aClause, sql clause to be executed |
|
277 * @param aStatus, request status to be completed |
|
278 * @return None |
|
279 */ |
|
280 void GetFilteredPropertyValuesL( |
|
281 CCmSqlPropertyCollector& aPropertys, const TDesC8& aClause, |
|
282 TRequestStatus& aStatus ); |
|
283 |
|
284 /** |
|
285 * Returns amount of media items |
|
286 * |
|
287 * @since S60 5.1 |
|
288 * @param aCount, media amount on return |
|
289 * @param aType, media type |
|
290 * @return None |
|
291 */ |
|
292 void GetMediaCountL( TInt64& aCount, TCmMediaType aType ); |
|
293 |
|
294 /** |
|
295 * Returns ETrue if item exist in db |
|
296 * |
|
297 * @since S60 5.1 |
|
298 * @param aItem, item |
|
299 * @param aDevId, device id |
|
300 * @return ETrue if exists |
|
301 */ |
|
302 TBool ExistsL( const CCmBaseListItem& aItem, const TInt aDevId ); |
|
303 |
|
304 private: |
|
305 |
|
306 /** |
|
307 * Static callback method for db handling |
|
308 * |
|
309 * @since S60 5.1 |
|
310 * @param aDbHandler, database handler |
|
311 * @return None |
|
312 */ |
|
313 static TInt BatchAdd( TAny* aDbHandler ); |
|
314 |
|
315 /** |
|
316 * Adds items into db in background |
|
317 * |
|
318 * @since S60 5.1 |
|
319 * @param None |
|
320 * @return None |
|
321 */ |
|
322 TInt DoBatchAdd(); |
|
323 |
|
324 /** |
|
325 * Static callback method for db handling |
|
326 * |
|
327 * @since S60 5.1 |
|
328 * @param aDbHandler, database handler |
|
329 * @return None |
|
330 */ |
|
331 static TInt BatchDelete( TAny* aDbHandler ); |
|
332 |
|
333 /** |
|
334 * Deletes items from db |
|
335 * |
|
336 * @since S60 5.1 |
|
337 * @param None |
|
338 * @return None |
|
339 */ |
|
340 TInt DoBatchDelete(); |
|
341 |
|
342 /** |
|
343 * Static callback method for db handling |
|
344 * |
|
345 * @since S60 5.1 |
|
346 * @param aDbHandler, database handler |
|
347 * @return None |
|
348 */ |
|
349 static TInt BatchGetL( TAny* aDbHandler ); |
|
350 |
|
351 /** |
|
352 * Gets items from db |
|
353 * |
|
354 * @since S60 5.1 |
|
355 * @param None |
|
356 * @return None |
|
357 */ |
|
358 TInt DoBatchGetL(); |
|
359 |
|
360 /** |
|
361 * Collect item data |
|
362 * |
|
363 * @since S60 5.1 |
|
364 * @param None |
|
365 * @return None |
|
366 */ |
|
367 void CollectItemDataL(); |
|
368 |
|
369 /** |
|
370 * Adds generic item into db |
|
371 * |
|
372 * @since S60 5.1 |
|
373 * @param None |
|
374 * @return None |
|
375 */ |
|
376 void AddItemL(); |
|
377 |
|
378 /** |
|
379 * Adds property item into db |
|
380 * |
|
381 * @since S60 5.1 |
|
382 * @param None |
|
383 * @return None |
|
384 */ |
|
385 void AddPropertyItemL(); |
|
386 |
|
387 /** |
|
388 * Adds resource item into db |
|
389 * |
|
390 * @since S60 5.1 |
|
391 * @param None |
|
392 * @return None |
|
393 */ |
|
394 void AddResourceL(); |
|
395 |
|
396 /** |
|
397 * Deletes items from the item table |
|
398 * |
|
399 * @since S60 5.1 |
|
400 * @param None |
|
401 * @return None |
|
402 */ |
|
403 void DeleteItemL(); |
|
404 |
|
405 /** |
|
406 * Deletes resource from the resources table |
|
407 * |
|
408 * @since S60 5.1 |
|
409 * @param None |
|
410 * @return None |
|
411 */ |
|
412 void DeleteResourceL(); |
|
413 |
|
414 /** |
|
415 * Deletes metadata from defined server |
|
416 * |
|
417 * @since S60 5.1 |
|
418 * @param aMsId, mediaserver id |
|
419 * @return None |
|
420 */ |
|
421 void DeleteMetadataFromDefServerL( const TInt aMsId ); |
|
422 |
|
423 /** |
|
424 * Formats row count query clause, used in property |
|
425 * indexing |
|
426 * |
|
427 * @since S60 5.1 |
|
428 * @param aField, metadata field |
|
429 * @return None |
|
430 */ |
|
431 void FormatRowCountQueryL( TCmMetadataField aField ); |
|
432 |
|
433 /** |
|
434 * Returns row count, used in property indexing |
|
435 * |
|
436 * @since S60 5.1 |
|
437 * @param None |
|
438 * @return None |
|
439 */ |
|
440 TInt64 RowCountL(); |
|
441 |
|
442 /** |
|
443 * Helper function for format maximun index query |
|
444 * |
|
445 * @since S60 5.1 |
|
446 * @param aId, item id |
|
447 * @param aTable, table name |
|
448 * @return None |
|
449 */ |
|
450 void FormatCountQueryL( const TDesC8& aId, const TDesC8& aTable ); |
|
451 |
|
452 /** |
|
453 * Helper function for getting filtered propertys |
|
454 * |
|
455 * @since S60 5.1 |
|
456 * @param aContainer, propertycontainer |
|
457 * @param aIndex1, column index |
|
458 * @param aIndex2, column index |
|
459 * @return None |
|
460 */ |
|
461 void GetFilteredPropertysL( CCmSqlPropertyContainer& aContainer, |
|
462 const TInt aIndex1, const TInt aIndex2 ); |
|
463 |
|
464 private: |
|
465 |
|
466 /** |
|
467 * Performs the first phase of two phase construction. |
|
468 */ |
|
469 CCmSqlConnection(); |
|
470 |
|
471 /** |
|
472 * Performs the second phase construction. |
|
473 */ |
|
474 void ConstructL(); |
|
475 |
|
476 private: |
|
477 |
|
478 /** |
|
479 * iDatabase, interface to Sqlite database |
|
480 */ |
|
481 RSqlDatabase iDatabase; |
|
482 |
|
483 /** |
|
484 * iStatement, interface to Sqlite database |
|
485 */ |
|
486 RSqlStatement iStatement; |
|
487 |
|
488 /** |
|
489 * Pending request status |
|
490 */ |
|
491 TRequestStatus* iStatus; |
|
492 |
|
493 /** |
|
494 * Media server id |
|
495 */ |
|
496 TUint iMsId; |
|
497 |
|
498 /** |
|
499 * User mmc quota |
|
500 */ |
|
501 TInt64 iQuota; |
|
502 |
|
503 /** |
|
504 * Generic item array pointer |
|
505 */ |
|
506 RPointerArray<CCmSqlGenericItem>* iGenericItems; // not owned |
|
507 |
|
508 /** |
|
509 * Base item array pointer |
|
510 */ |
|
511 RPointerArray<CCmSqlBaseItem>* iBaseItems; // not owned |
|
512 |
|
513 /** |
|
514 * Fill list item array pointer |
|
515 */ |
|
516 RPointerArray<CCmFillListItem>* iFillItems; // not owned |
|
517 |
|
518 /** |
|
519 * Property item array pointer |
|
520 */ |
|
521 RPointerArray<CCmSqlPropertyItem>* iPropertyItems; // not owned |
|
522 |
|
523 /** |
|
524 * Filtered property item array pointer |
|
525 */ |
|
526 CCmSqlPropertyCollector* iPropertyCollector; // not owned |
|
527 |
|
528 /** |
|
529 * Mediaserver ids |
|
530 */ |
|
531 RArray<TInt>* iMsIds; // not owned |
|
532 |
|
533 /** |
|
534 * Asyncronous database handler |
|
535 */ |
|
536 CIdle* iAsyncDbHandler; // owned |
|
537 |
|
538 /** |
|
539 * Operation mode |
|
540 */ |
|
541 TCmSqlOperationMode iMode; |
|
542 |
|
543 /** |
|
544 * Index to item array |
|
545 */ |
|
546 TInt iIndex; |
|
547 |
|
548 /** |
|
549 * Property table identifier |
|
550 */ |
|
551 TCmMetadataField iField; |
|
552 |
|
553 /** |
|
554 * Fill list |
|
555 */ |
|
556 CCmFillRule* iList; // not owned |
|
557 |
|
558 /** |
|
559 * Fill list size |
|
560 */ |
|
561 TInt64 iListSize; |
|
562 |
|
563 /** |
|
564 * Maximun size of the fill list in Bytes |
|
565 */ |
|
566 TInt64 iListMaxSize; |
|
567 |
|
568 /** |
|
569 * Used to get max count of items |
|
570 */ |
|
571 HBufC8* iCountQuery; // Owned |
|
572 |
|
573 }; |
|
574 |
|
575 #endif // C_CMSQLCONNECTION_H |
|