|
1 /* |
|
2 * Copyright (c) 2007 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: Base class for all table classes. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <mpxlog.h> |
|
21 #include <mpxmedia.h> |
|
22 #include <mpxmediaarray.h> |
|
23 |
|
24 #include "mpxdbcommonstd.h" |
|
25 #include "mpxdbcommonutil.h" |
|
26 #include "mpxdbmanager.h" |
|
27 #include "mpxdbtable.h" |
|
28 |
|
29 // ============================ MEMBER FUNCTIONS ============================== |
|
30 |
|
31 // ---------------------------------------------------------------------------- |
|
32 // Constructor |
|
33 // ---------------------------------------------------------------------------- |
|
34 // |
|
35 EXPORT_C CMPXDbTable::CMPXDbTable( |
|
36 CMPXDbManager& aDbManager) : |
|
37 iDbManager(aDbManager) |
|
38 { |
|
39 MPX_FUNC("CMPXDbTable::CMPXDbTable"); |
|
40 } |
|
41 |
|
42 // ---------------------------------------------------------------------------- |
|
43 // Second phase constructor. |
|
44 // ---------------------------------------------------------------------------- |
|
45 // |
|
46 EXPORT_C void CMPXDbTable::BaseConstructL() |
|
47 { |
|
48 MPX_FUNC("CMPXDbTable::BaseConstructL"); |
|
49 iDbManager.RegisterTableL(*this); |
|
50 } |
|
51 |
|
52 // ---------------------------------------------------------------------------- |
|
53 // Destructor |
|
54 // ---------------------------------------------------------------------------- |
|
55 // |
|
56 EXPORT_C CMPXDbTable::~CMPXDbTable() |
|
57 { |
|
58 MPX_FUNC("CMPXDbTable::~CMPXDbTable"); |
|
59 } |
|
60 |
|
61 // ---------------------------------------------------------------------------- |
|
62 // CMPXDbTable::UpdateMediaL default implementation |
|
63 // ---------------------------------------------------------------------------- |
|
64 // |
|
65 EXPORT_C void CMPXDbTable::UpdateMediaL( |
|
66 RSqlStatement& /* aRecord */, |
|
67 const TArray<TMPXAttribute>& /* aAttrs */, |
|
68 CMPXMedia& /* aMedia */) |
|
69 { |
|
70 // do nothing |
|
71 } |
|
72 |
|
73 // ---------------------------------------------------------------------------- |
|
74 // CMPXDbTable::ExecuteMediaQueryL |
|
75 // ---------------------------------------------------------------------------- |
|
76 // |
|
77 EXPORT_C void CMPXDbTable::ExecuteMediaQueryL( |
|
78 const TArray<TMPXAttribute>& aAttrs, |
|
79 CMPXMediaArray& aMediaArray, |
|
80 const TDesC& aQuery, |
|
81 TInt aValue) |
|
82 { |
|
83 MPX_FUNC("CMPXDbTable::ExecuteMediaQueryL"); |
|
84 |
|
85 HBufC* query = HBufC::NewLC(aQuery.Length() + KMCIntegerLen); |
|
86 query->Des().Format(aQuery, aValue); |
|
87 ExecuteMediaQueryL(aAttrs, aMediaArray, *query); |
|
88 CleanupStack::PopAndDestroy(query); |
|
89 } |
|
90 |
|
91 // ---------------------------------------------------------------------------- |
|
92 // CMPXDbTable::ExecuteMediaQueryL |
|
93 // ---------------------------------------------------------------------------- |
|
94 // |
|
95 EXPORT_C void CMPXDbTable::ExecuteMediaQueryL( |
|
96 const TArray<TMPXAttribute>& aAttrs, |
|
97 CMPXMediaArray& aMediaArray, |
|
98 const TDesC& aQuery, |
|
99 const TDesC& aValue) |
|
100 { |
|
101 MPX_FUNC("CMPXDbTable::ExecuteMediaQueryL"); |
|
102 |
|
103 HBufC* query = HBufC::NewLC(aQuery.Length() + aValue.Length()); |
|
104 query->Des().Format(aQuery, &aValue); |
|
105 ExecuteMediaQueryL(aAttrs, aMediaArray, *query); |
|
106 CleanupStack::PopAndDestroy(query); |
|
107 } |
|
108 |
|
109 // ---------------------------------------------------------------------------- |
|
110 // CMPXDbTable::ExecuteMediaQueryL |
|
111 // ---------------------------------------------------------------------------- |
|
112 // |
|
113 EXPORT_C void CMPXDbTable::ExecuteMediaQueryL( |
|
114 const TArray<TMPXAttribute>& aAttrs, |
|
115 CMPXMediaArray& aMediaArray, |
|
116 const TDesC& aQuery, |
|
117 TInt aValue1, |
|
118 TInt aValue2) |
|
119 { |
|
120 MPX_FUNC("CMPXDbTable::ExecuteMediaQueryL"); |
|
121 |
|
122 HBufC* query = HBufC::NewLC(aQuery.Length() + 2 * KMCIntegerLen); |
|
123 query->Des().Format(aQuery, aValue1, aValue2); |
|
124 ExecuteMediaQueryL(aAttrs, aMediaArray, *query); |
|
125 CleanupStack::PopAndDestroy(query); |
|
126 } |
|
127 |
|
128 // ---------------------------------------------------------------------------- |
|
129 // CMPXDbTable::ExecuteMediaQueryL |
|
130 // ---------------------------------------------------------------------------- |
|
131 // |
|
132 EXPORT_C void CMPXDbTable::ExecuteMediaQueryL( |
|
133 const TArray<TMPXAttribute>& aAttrs, |
|
134 CMPXMediaArray& aMediaArray, |
|
135 const TDesC& aQuery, |
|
136 const TDesC& aValue1, |
|
137 TInt aValue2) |
|
138 { |
|
139 MPX_FUNC("CMPXDbTable::ExecuteMediaQueryL"); |
|
140 |
|
141 HBufC* query = HBufC::NewLC(aQuery.Length() + aValue1.Length() + KMCIntegerLen); |
|
142 query->Des().Format(aQuery, &aValue1, aValue2); |
|
143 ExecuteMediaQueryL(aAttrs, aMediaArray, *query); |
|
144 CleanupStack::PopAndDestroy(query); |
|
145 } |
|
146 |
|
147 // ---------------------------------------------------------------------------- |
|
148 // CMPXDbTable::ExecuteMediaQueryL |
|
149 // ---------------------------------------------------------------------------- |
|
150 // |
|
151 EXPORT_C void CMPXDbTable::ExecuteMediaQueryL( |
|
152 const TArray<TMPXAttribute>& aAttrs, |
|
153 CMPXMediaArray& aMediaArray, |
|
154 const TDesC& aQuery, |
|
155 const TDesC& aValue1, |
|
156 TInt aValue2, |
|
157 const TDesC& aValue3, |
|
158 TInt aValue4) |
|
159 { |
|
160 MPX_FUNC("CMPXDbTable::ExecuteMediaQueryL"); |
|
161 |
|
162 HBufC* query = HBufC::NewLC(aQuery.Length() + |
|
163 aValue1.Length() + |
|
164 aValue3.Length() + |
|
165 2*KMCIntegerLen); |
|
166 query->Des().Format(aQuery, &aValue1, aValue2, &aValue3, aValue4); |
|
167 ExecuteMediaQueryL(aAttrs, aMediaArray, *query); |
|
168 CleanupStack::PopAndDestroy(query); |
|
169 } |
|
170 |
|
171 // ---------------------------------------------------------------------------- |
|
172 // CMPXDbTable::ExecuteMediaQueryL |
|
173 // ---------------------------------------------------------------------------- |
|
174 // |
|
175 EXPORT_C void CMPXDbTable::ExecuteMediaQueryL( |
|
176 const TArray<TMPXAttribute>& aAttrs, |
|
177 CMPXMediaArray& aMediaArray, |
|
178 const TDesC& aQuery) |
|
179 { |
|
180 MPX_FUNC("CMPXDbTable::ExecuteMediaQueryL"); |
|
181 |
|
182 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(aQuery)); |
|
183 CleanupClosePushL(recordset); |
|
184 |
|
185 TInt pPath(0); |
|
186 if (aMediaArray.Count()) |
|
187 { |
|
188 CMPXMedia* pMedia = aMediaArray[0]; |
|
189 if (pMedia->IsSupported(KMPXMediaGeneralValue)) |
|
190 { // Query excuted by OpenL |
|
191 pPath = pMedia->ValueTObjectL<TInt>(KMPXMediaGeneralValue); |
|
192 MPX_ASSERT(pPath); |
|
193 } |
|
194 } |
|
195 |
|
196 TInt err(KErrNone); |
|
197 RArray<TMPXItemId> ids; |
|
198 CleanupClosePushL(ids); |
|
199 while ((err = recordset.Next()) == KSqlAtRow) |
|
200 { |
|
201 CMPXMedia* media = CMPXMedia::NewL(); |
|
202 CleanupStack::PushL(media); |
|
203 |
|
204 UpdateMediaL(recordset, aAttrs, *media); |
|
205 if (media->IsSupported(KMPXMediaGeneralId) && pPath) |
|
206 { |
|
207 ids.AppendL(media->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId)); |
|
208 } |
|
209 aMediaArray.AppendL(*media); |
|
210 CleanupStack::PopAndDestroy(media); |
|
211 } |
|
212 |
|
213 // Append ids to the returned path |
|
214 if (pPath) |
|
215 { |
|
216 ((CMPXCollectionPath*)pPath)->AppendL(ids.Array()); |
|
217 } |
|
218 CleanupStack::PopAndDestroy(&ids); |
|
219 CleanupStack::PopAndDestroy(&recordset); |
|
220 |
|
221 if (err!= KSqlAtEnd) |
|
222 { |
|
223 User::Leave(KErrCorrupt); |
|
224 } |
|
225 } |
|
226 |
|
227 // ---------------------------------------------------------------------------- |
|
228 // CMPXDbTable::ExecuteMediaQueryL |
|
229 // ---------------------------------------------------------------------------- |
|
230 // |
|
231 EXPORT_C void CMPXDbTable::ExecuteMediaQueryL( |
|
232 TInt aDrive, |
|
233 const TArray<TMPXAttribute>& aAttrs, |
|
234 CMPXMediaArray& aMediaArray, |
|
235 const TDesC& aQuery, |
|
236 TInt aPlaylistId) |
|
237 { |
|
238 MPX_FUNC("CMPXDbTable::ExecuteMediaQueryL"); |
|
239 |
|
240 HBufC* query = HBufC::NewLC(aQuery.Length() + KMCIntegerLen); |
|
241 query->Des().Format(aQuery, aPlaylistId); |
|
242 ExecuteMediaQueryOnDriveL(aDrive, aAttrs, aMediaArray, *query); |
|
243 CleanupStack::PopAndDestroy(query); |
|
244 } |
|
245 |
|
246 // ---------------------------------------------------------------------------- |
|
247 // CMPXDbTable::ExecuteMediaQueryOnDriveL |
|
248 // ---------------------------------------------------------------------------- |
|
249 // |
|
250 EXPORT_C void CMPXDbTable::ExecuteMediaQueryOnDriveL( |
|
251 TInt aDrive, |
|
252 const TArray<TMPXAttribute>& aAttrs, |
|
253 CMPXMediaArray& aMediaArray, |
|
254 const TDesC& aQuery) |
|
255 { |
|
256 MPX_FUNC("CMPXDbTable::ExecuteMediaQueryL"); |
|
257 |
|
258 RSqlStatement recordset(iDbManager.ExecuteSelectQueryOnAllDrivesL(aDrive,aQuery)); |
|
259 CleanupClosePushL(recordset); |
|
260 |
|
261 TInt pPath(0); |
|
262 if (aMediaArray.Count()) |
|
263 { |
|
264 CMPXMedia* pMedia = aMediaArray[0]; |
|
265 if (pMedia->IsSupported(KMPXMediaGeneralValue)) |
|
266 { // Query excuted by OpenL |
|
267 pPath = pMedia->ValueTObjectL<TInt>(KMPXMediaGeneralValue); |
|
268 MPX_ASSERT(pPath); |
|
269 } |
|
270 } |
|
271 |
|
272 TInt err(KErrNone); |
|
273 RArray<TMPXItemId> ids; |
|
274 CleanupClosePushL(ids); |
|
275 while ((err = recordset.Next()) == KSqlAtRow) |
|
276 { |
|
277 CMPXMedia* media = CMPXMedia::NewL(); |
|
278 CleanupStack::PushL(media); |
|
279 |
|
280 UpdateMediaL(recordset, aAttrs, *media); |
|
281 if (media->IsSupported(KMPXMediaGeneralId) && pPath) |
|
282 { |
|
283 ids.AppendL(media->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId)); |
|
284 } |
|
285 aMediaArray.AppendL(*media); |
|
286 CleanupStack::PopAndDestroy(media); |
|
287 } |
|
288 |
|
289 // Append ids to the returned path |
|
290 if (pPath) |
|
291 { |
|
292 ((CMPXCollectionPath*)pPath)->AppendL(ids.Array()); |
|
293 } |
|
294 CleanupStack::PopAndDestroy(&ids); |
|
295 CleanupStack::PopAndDestroy(&recordset); |
|
296 |
|
297 if (err!= KSqlAtEnd) |
|
298 { |
|
299 User::Leave(KErrCorrupt); |
|
300 } |
|
301 } |
|
302 |
|
303 // ---------------------------------------------------------------------------- |
|
304 // CMPXDbTable::ExecuteMediaQueryL |
|
305 // ---------------------------------------------------------------------------- |
|
306 // |
|
307 EXPORT_C void CMPXDbTable::ExecuteMediaQueryL( |
|
308 const TArray<TMPXAttribute>& aAttrs, |
|
309 CMPXMediaArray& aMediaArray, |
|
310 const TBool aAsc, |
|
311 const TDesC& aQuery) |
|
312 { |
|
313 |
|
314 MPX_FUNC("CMPXDbTable::ExecuteMediaQueryL"); |
|
315 |
|
316 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(aQuery)); |
|
317 CleanupClosePushL(recordset); |
|
318 |
|
319 TInt err(KErrNone); |
|
320 while ((err = recordset.Next()) == KSqlAtRow) |
|
321 { |
|
322 CMPXMedia* media = CMPXMedia::NewL(); |
|
323 CleanupStack::PushL(media); |
|
324 |
|
325 UpdateMediaL(recordset, aAttrs, *media); |
|
326 if (aAsc != EFalse) |
|
327 { |
|
328 aMediaArray.AppendL(*media); |
|
329 } |
|
330 else |
|
331 { |
|
332 aMediaArray.InsertL(*media, 0); |
|
333 } |
|
334 CleanupStack::PopAndDestroy(media); |
|
335 } |
|
336 |
|
337 CleanupStack::PopAndDestroy(&recordset); |
|
338 |
|
339 |
|
340 if (err!= KSqlAtEnd) |
|
341 { |
|
342 User::Leave(KErrCorrupt); |
|
343 } |
|
344 } |
|
345 |
|
346 |
|
347 // ---------------------------------------------------------------------------- |
|
348 // CMPXDbTable::ExecuteMediaQueryL |
|
349 // ---------------------------------------------------------------------------- |
|
350 // |
|
351 EXPORT_C void CMPXDbTable::ExecuteMediaQueryL( |
|
352 const TArray<TMPXAttribute>& aAttrs, |
|
353 CMPXMedia& aMedia, |
|
354 const TDesC& aQuery) |
|
355 { |
|
356 MPX_FUNC("CMPXDbTable::ExecuteMediaQueryL"); |
|
357 |
|
358 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(aQuery)); |
|
359 CleanupClosePushL(recordset); |
|
360 |
|
361 if (recordset.Next() != KSqlAtRow) |
|
362 { |
|
363 User::Leave(KErrNotFound); |
|
364 } |
|
365 |
|
366 UpdateMediaL(recordset, aAttrs, aMedia); |
|
367 CleanupStack::PopAndDestroy(&recordset); |
|
368 } |
|
369 |
|
370 // ---------------------------------------------------------------------------- |
|
371 // CMPXDbTable::ExecuteMediaQueryL |
|
372 // ---------------------------------------------------------------------------- |
|
373 // |
|
374 EXPORT_C void CMPXDbTable::ExecuteMediaQueryL( |
|
375 const TArray<TMPXAttribute>& aAttrs, |
|
376 CMPXMedia& aMedia, |
|
377 const TDesC& aQuery, |
|
378 TInt aValue) |
|
379 { |
|
380 MPX_FUNC("CMPXDbTable::ExecuteMediaQueryL"); |
|
381 |
|
382 HBufC* query = HBufC::NewLC(aQuery.Length() + KMCIntegerLen); |
|
383 query->Des().Format(aQuery, aValue); |
|
384 ExecuteMediaQueryL(aAttrs, aMedia, *query); |
|
385 CleanupStack::PopAndDestroy(query); |
|
386 } |
|
387 |
|
388 // ---------------------------------------------------------------------------- |
|
389 // CMPXDbTable::ExecuteMediaQueryL |
|
390 // ---------------------------------------------------------------------------- |
|
391 // |
|
392 EXPORT_C void CMPXDbTable::ExecuteMediaQueryL( |
|
393 const TArray<TMPXAttribute>& aAttrs, |
|
394 CMPXMediaArray& aMediaArray, |
|
395 const TDesC& aQuery, |
|
396 const TDesC& aValue1, |
|
397 const TDesC& aValue2) |
|
398 { |
|
399 MPX_FUNC("CMPXDbTable::ExecuteMediaQueryL"); |
|
400 |
|
401 HBufC* query = HBufC::NewLC(aQuery.Length() + aValue1.Length() + aValue2.Length()); |
|
402 query->Des().Format(aQuery, &aValue1, &aValue2); |
|
403 ExecuteMediaQueryL(aAttrs, aMediaArray, *query); |
|
404 CleanupStack::PopAndDestroy(query); |
|
405 } |
|
406 |
|
407 // ---------------------------------------------------------------------------- |
|
408 // CMPXDbTable::ExecuteIntQueryL |
|
409 // ---------------------------------------------------------------------------- |
|
410 // |
|
411 EXPORT_C TUint32 CMPXDbTable::ExecuteIntQueryL( |
|
412 const TDesC& aQuery) |
|
413 { |
|
414 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(aQuery)); |
|
415 CleanupClosePushL(recordset); |
|
416 |
|
417 if (recordset.Next() != KSqlAtRow) |
|
418 { |
|
419 User::Leave(KErrNotFound); |
|
420 } |
|
421 |
|
422 TInt64 value( recordset.ColumnInt64( KMPXTableDefaultIndex ) ); |
|
423 CleanupStack::PopAndDestroy(&recordset); |
|
424 |
|
425 return value < 0 ? 0: I64LOW( value ); |
|
426 } |
|
427 |
|
428 // ---------------------------------------------------------------------------- |
|
429 // CMPXDbTable::ExecuteIntQueryL |
|
430 // ---------------------------------------------------------------------------- |
|
431 // |
|
432 EXPORT_C TUint32 CMPXDbTable::ExecuteIntQueryL( |
|
433 const TDesC& aQuery, |
|
434 TUint32 aValue) |
|
435 { |
|
436 MPX_FUNC("CMPXDbTable::ExecuteIntQueryL"); |
|
437 |
|
438 HBufC* query = HBufC::NewLC(aQuery.Length() + KMCIntegerLen); |
|
439 query->Des().Format(aQuery, aValue); |
|
440 TUint32 ret(ExecuteIntQueryL(*query)); |
|
441 CleanupStack::PopAndDestroy(query); |
|
442 |
|
443 return ret; |
|
444 } |
|
445 |
|
446 // ---------------------------------------------------------------------------- |
|
447 // CMPXDbTable::ExecuteIntQueryL |
|
448 // ---------------------------------------------------------------------------- |
|
449 // |
|
450 EXPORT_C TUint32 CMPXDbTable::ExecuteIntQueryL( |
|
451 const TDesC& aQuery, |
|
452 const TDesC& aValue1, |
|
453 TUint32 aValue2) |
|
454 { |
|
455 MPX_FUNC("CMPXDbTable::ExecuteIntQueryL"); |
|
456 |
|
457 // replace single quotes |
|
458 // reserve double the value length for single quote duplicates |
|
459 // coverity[incorrect_multiplication] |
|
460 // coverity[buffer_alloc] |
|
461 HBufC* value1 = HBufC::NewLC(aValue1.Length() * 2); |
|
462 TPtr value1Ptr(value1->Des()); |
|
463 MPXDbCommonUtil::FindAndReplaceSingleQuote(aValue1, value1Ptr); |
|
464 |
|
465 // construct the query |
|
466 HBufC* query = HBufC::NewLC(aQuery.Length() + value1Ptr.Length() + KMCIntegerLen); |
|
467 query->Des().Format(aQuery, value1, aValue2); |
|
468 |
|
469 // execute the query |
|
470 TUint32 ret(ExecuteIntQueryL(*query)); |
|
471 |
|
472 CleanupStack::PopAndDestroy(query); |
|
473 CleanupStack::PopAndDestroy(value1); |
|
474 |
|
475 return ret; |
|
476 } |
|
477 |
|
478 // ---------------------------------------------------------------------------- |
|
479 // CMPXDbTable::ExecuteIntQueryL |
|
480 // ---------------------------------------------------------------------------- |
|
481 // |
|
482 EXPORT_C TUint32 CMPXDbTable::ExecuteIntQueryL( |
|
483 const TDesC& aQuery, |
|
484 const TDesC& aValue) |
|
485 { |
|
486 MPX_FUNC("CMPXDbTable::ExecuteIntQueryL"); |
|
487 |
|
488 // replace single quotes |
|
489 // coverity[incorrect_multiplication] |
|
490 // coverity[buffer_alloc] |
|
491 HBufC* value = HBufC::NewLC(aValue.Length() * 2); |
|
492 TPtr valuePtr(value->Des()); |
|
493 MPXDbCommonUtil::FindAndReplaceSingleQuote(aValue, valuePtr); |
|
494 |
|
495 // construct the query |
|
496 HBufC* query = HBufC::NewLC(aQuery.Length() + valuePtr.Length()); |
|
497 query->Des().Format(aQuery, value); |
|
498 |
|
499 // execute the query |
|
500 TUint32 ret(ExecuteIntQueryL(*query)); |
|
501 |
|
502 CleanupStack::PopAndDestroy(query); |
|
503 CleanupStack::PopAndDestroy(value); |
|
504 |
|
505 return ret; |
|
506 } |
|
507 |
|
508 // ---------------------------------------------------------------------------- |
|
509 // CMPXDbTable::ExecuteIntQueryL |
|
510 // ---------------------------------------------------------------------------- |
|
511 // |
|
512 EXPORT_C TUint32 CMPXDbTable::ExecuteIntQueryL( |
|
513 const TDesC& aQuery, |
|
514 TUint32 aValue1, |
|
515 TUint32 aValue2) |
|
516 { |
|
517 MPX_FUNC("CMPXDbTable::ExecuteIntQueryL"); |
|
518 |
|
519 HBufC* query = HBufC::NewLC(aQuery.Length() + 2 * KMCIntegerLen); |
|
520 query->Des().Format(aQuery, aValue1, aValue2); |
|
521 TUint32 ret(ExecuteIntQueryL(*query)); |
|
522 CleanupStack::PopAndDestroy(query); |
|
523 |
|
524 return ret; |
|
525 } |
|
526 |
|
527 // ---------------------------------------------------------------------------- |
|
528 // CMPXDbTable::ExecuteIntQueryL |
|
529 // ---------------------------------------------------------------------------- |
|
530 // |
|
531 EXPORT_C TUint32 CMPXDbTable::ExecuteIntQueryL(TInt aDriveID,const TDesC& aQuery) |
|
532 { |
|
533 MPX_FUNC("CMPXDbTable::ExecuteIntQueryL"); |
|
534 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(aDriveID,aQuery)); |
|
535 CleanupClosePushL(recordset); |
|
536 |
|
537 if (recordset.Next() != KSqlAtRow) |
|
538 { |
|
539 User::Leave(KErrNotFound); |
|
540 } |
|
541 |
|
542 TUint32 value(recordset.ColumnInt64(KMPXTableDefaultIndex)); |
|
543 CleanupStack::PopAndDestroy(&recordset); |
|
544 |
|
545 return value; |
|
546 } |
|
547 |
|
548 // ---------------------------------------------------------------------------- |
|
549 // CMPXDbTable::ExecuteSumQueryL |
|
550 // ---------------------------------------------------------------------------- |
|
551 // |
|
552 EXPORT_C TInt CMPXDbTable::ExecuteSumQueryL( |
|
553 const TDesC& aQuery) |
|
554 { |
|
555 MPX_FUNC("CMPXDbTable::ExecuteSumQueryL"); |
|
556 |
|
557 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(aQuery)); |
|
558 CleanupClosePushL(recordset); |
|
559 |
|
560 TInt sum(0); |
|
561 TInt err(KErrNone); |
|
562 while ((err = recordset.Next()) == KSqlAtRow) |
|
563 { |
|
564 sum += recordset.ColumnInt64(KMPXTableDefaultIndex); |
|
565 } |
|
566 |
|
567 CleanupStack::PopAndDestroy(&recordset); |
|
568 |
|
569 if (err != KSqlAtEnd) |
|
570 { |
|
571 User::Leave(KErrCorrupt); |
|
572 } |
|
573 |
|
574 return sum; |
|
575 } |
|
576 |
|
577 // ---------------------------------------------------------------------------- |
|
578 // CMPXDbTable::ExecuteSumQueryL |
|
579 // ---------------------------------------------------------------------------- |
|
580 // |
|
581 EXPORT_C TInt CMPXDbTable::ExecuteSumQueryL( |
|
582 const TDesC& aQuery, |
|
583 TUint32 aValue) |
|
584 { |
|
585 MPX_FUNC("CMPXDbTable::ExecuteSumQueryL"); |
|
586 |
|
587 HBufC* query = HBufC::NewLC(aQuery.Length() + KMCIntegerLen); |
|
588 query->Des().Format(aQuery, aValue); |
|
589 TUint32 ret(ExecuteSumQueryL(*query)); |
|
590 CleanupStack::PopAndDestroy(query); |
|
591 |
|
592 return ret; |
|
593 } |
|
594 |
|
595 // ---------------------------------------------------------------------------- |
|
596 // CMPXDbTable::ExecuteSumQueryL |
|
597 // ---------------------------------------------------------------------------- |
|
598 // |
|
599 EXPORT_C TInt CMPXDbTable::ExecuteSumQueryL( |
|
600 const TDesC& aQuery, |
|
601 TUint32 aValue1, |
|
602 TUint32 aValue2) |
|
603 { |
|
604 MPX_FUNC("CMPXDbTable::ExecuteSumQueryL"); |
|
605 |
|
606 HBufC* query = HBufC::NewLC(aQuery.Length() + 2 * KMCIntegerLen); |
|
607 query->Des().Format(aQuery, aValue1, aValue2); |
|
608 TUint32 ret(ExecuteSumQueryL(*query)); |
|
609 CleanupStack::PopAndDestroy(query); |
|
610 |
|
611 return ret; |
|
612 } |
|
613 |
|
614 // ---------------------------------------------------------------------------- |
|
615 // CMPXDbTable::ExecuteSumQueryL |
|
616 // ---------------------------------------------------------------------------- |
|
617 // |
|
618 EXPORT_C TInt CMPXDbTable::ExecuteSumQueryL( |
|
619 const TDesC& aQuery, |
|
620 TUint32 aValue1, |
|
621 TUint32 aValue2, |
|
622 TUint32 aValue3) |
|
623 { |
|
624 MPX_FUNC("CMPXDbTable::ExecuteSumQueryL"); |
|
625 |
|
626 HBufC* query = HBufC::NewLC(aQuery.Length() + 3 * KMCIntegerLen); |
|
627 query->Des().Format(aQuery, aValue1, aValue2, aValue3); |
|
628 TUint32 ret(ExecuteSumQueryL(*query)); |
|
629 CleanupStack::PopAndDestroy(query); |
|
630 |
|
631 return ret; |
|
632 } |
|
633 |
|
634 // ---------------------------------------------------------------------------- |
|
635 // CMPXDbTable::ExecuteSumQueryL |
|
636 // ---------------------------------------------------------------------------- |
|
637 // |
|
638 EXPORT_C TUint32 CMPXDbTable::ExecuteSumQueryL( |
|
639 const TDesC& aQuery, |
|
640 const TDesC& aValue1, |
|
641 TUint32 aValue2) |
|
642 { |
|
643 MPX_FUNC("CMPXDbTable::ExecuteSumQueryL"); |
|
644 |
|
645 // replace single quotes |
|
646 // reserve double the value length for single quote duplicates |
|
647 // coverity[incorrect_multiplication] |
|
648 // coverity[buffer_alloc] |
|
649 HBufC* value1 = HBufC::NewLC(aValue1.Length() * 2); |
|
650 TPtr value1Ptr(value1->Des()); |
|
651 MPXDbCommonUtil::FindAndReplaceSingleQuote(aValue1, value1Ptr); |
|
652 |
|
653 // construct the query |
|
654 HBufC* query = HBufC::NewLC(aQuery.Length() + value1Ptr.Length() + KMCIntegerLen); |
|
655 query->Des().Format(aQuery, value1, aValue2); |
|
656 |
|
657 // execute the query |
|
658 TUint32 ret(ExecuteSumQueryL(*query)); |
|
659 |
|
660 CleanupStack::PopAndDestroy(query); |
|
661 CleanupStack::PopAndDestroy(value1); |
|
662 |
|
663 return ret; |
|
664 } |
|
665 |
|
666 // ---------------------------------------------------------------------------- |
|
667 // CMPXDbTable::ExecuteSumQueryL |
|
668 // ---------------------------------------------------------------------------- |
|
669 // |
|
670 EXPORT_C TInt CMPXDbTable::ExecuteSumQueryL( |
|
671 const TDesC& aQuery, |
|
672 const TDesC& aValue1, |
|
673 const TDesC& aValue2) |
|
674 { |
|
675 MPX_FUNC("CMPXDbTable::ExecuteSumQueryL"); |
|
676 |
|
677 // replace single quotes |
|
678 // reserve double the value length for single quote duplicates |
|
679 // coverity[incorrect_multiplication] |
|
680 // coverity[buffer_alloc] |
|
681 HBufC* value1 = HBufC::NewLC(aValue1.Length() * 2); |
|
682 TPtr value1Ptr(value1->Des()); |
|
683 MPXDbCommonUtil::FindAndReplaceSingleQuote(aValue1, value1Ptr); |
|
684 |
|
685 // coverity[incorrect_multiplication] |
|
686 // coverity[buffer_alloc] |
|
687 HBufC* value2 = HBufC::NewLC(aValue2.Length() * 2); |
|
688 TPtr value2Ptr(value2->Des()); |
|
689 MPXDbCommonUtil::FindAndReplaceSingleQuote(aValue2, value2Ptr); |
|
690 |
|
691 // construct the query |
|
692 HBufC* query = HBufC::NewLC(aQuery.Length() + value1Ptr.Length() + value2Ptr.Length()); |
|
693 query->Des().Format(aQuery, value1, value2); |
|
694 |
|
695 // execute the query |
|
696 TUint32 ret(ExecuteSumQueryL(*query)); |
|
697 |
|
698 CleanupStack::PopAndDestroy(query); |
|
699 CleanupStack::PopAndDestroy(value2); |
|
700 CleanupStack::PopAndDestroy(value1); |
|
701 |
|
702 return ret; |
|
703 } |
|
704 |
|
705 // ---------------------------------------------------------------------------- |
|
706 // CMPXDbTable::ExecuteSumQueryL |
|
707 // ---------------------------------------------------------------------------- |
|
708 // |
|
709 EXPORT_C TInt CMPXDbTable::ExecuteSumQueryL( |
|
710 const TDesC& aQuery, |
|
711 const TDesC& aValue) |
|
712 { |
|
713 MPX_FUNC("CMPXDbTable::ExecuteSumQueryL"); |
|
714 |
|
715 // replace single quotes |
|
716 // reserve double the value length for single quote duplicates |
|
717 // coverity[incorrect_multiplication] |
|
718 // coverity[buffer_alloc] |
|
719 HBufC* value = HBufC::NewLC(aValue.Length() * 2); |
|
720 TPtr valuePtr(value->Des()); |
|
721 MPXDbCommonUtil::FindAndReplaceSingleQuote(aValue, valuePtr); |
|
722 |
|
723 // construct the query |
|
724 HBufC* query = HBufC::NewLC(aQuery.Length() + valuePtr.Length()); |
|
725 query->Des().Format(aQuery, value); |
|
726 |
|
727 // execute the query |
|
728 TUint32 ret(ExecuteSumQueryL(*query)); |
|
729 |
|
730 CleanupStack::PopAndDestroy(query); |
|
731 CleanupStack::PopAndDestroy(value); |
|
732 |
|
733 return ret; |
|
734 } |
|
735 |
|
736 // ---------------------------------------------------------------------------- |
|
737 // CMPXDbTable::ExecuteSumQueryL |
|
738 // ---------------------------------------------------------------------------- |
|
739 // |
|
740 EXPORT_C TInt CMPXDbTable::ExecuteSumQueryL( |
|
741 const TDesC& aQuery, |
|
742 const TDesC& aValue1, |
|
743 TUint32 aValue2, |
|
744 const TDesC& aValue3, |
|
745 TUint32 aValue4) |
|
746 { |
|
747 MPX_FUNC("CMPXDbTable::ExecuteSumQueryL"); |
|
748 |
|
749 // replace single quotes |
|
750 // reserve double the value length for single quote duplicates |
|
751 // coverity[incorrect_multiplication] |
|
752 // coverity[buffer_alloc] |
|
753 HBufC* value1 = HBufC::NewLC(aValue1.Length() * 2); |
|
754 TPtr value1Ptr(value1->Des()); |
|
755 MPXDbCommonUtil::FindAndReplaceSingleQuote(aValue1, value1Ptr); |
|
756 |
|
757 // replace single quotes |
|
758 // reserve double the value length for single quote duplicates |
|
759 // coverity[incorrect_multiplication] |
|
760 // coverity[buffer_alloc] |
|
761 HBufC* value3 = HBufC::NewLC(aValue3.Length() * 2); |
|
762 TPtr value3Ptr(value3->Des()); |
|
763 MPXDbCommonUtil::FindAndReplaceSingleQuote(aValue3, value3Ptr); |
|
764 |
|
765 // construct the query |
|
766 HBufC* query = HBufC::NewLC( aQuery.Length() + |
|
767 value1Ptr.Length() + |
|
768 2 * KMCIntegerLen + |
|
769 value3Ptr.Length() ); |
|
770 query->Des().Format(aQuery, value1, aValue2, value3, aValue4); |
|
771 |
|
772 // execute the query |
|
773 TUint32 ret(ExecuteSumQueryL(*query)); |
|
774 |
|
775 CleanupStack::PopAndDestroy(query); |
|
776 CleanupStack::PopAndDestroy(value3); |
|
777 CleanupStack::PopAndDestroy(value1); |
|
778 |
|
779 return ret; |
|
780 } |
|
781 |
|
782 // ---------------------------------------------------------------------------- |
|
783 // CMPXDbTable::ExecuteSumExQueryL |
|
784 // ---------------------------------------------------------------------------- |
|
785 // |
|
786 EXPORT_C TInt CMPXDbTable::ExecuteSumExQueryL( |
|
787 const TDesC& aQuery, |
|
788 TUint32 aPlaylistId, |
|
789 TInt aDrive) |
|
790 { |
|
791 MPX_FUNC("CMPXDbTable::ExecuteSumExQueryL"); |
|
792 |
|
793 HBufC* query = HBufC::NewLC(aQuery.Length() + KMCIntegerLen); |
|
794 query->Des().Format(aQuery, aPlaylistId); |
|
795 |
|
796 RSqlStatement recordset(iDbManager.ExecuteSelectQueryOnAllDrivesL(aDrive, *query)); |
|
797 CleanupClosePushL(recordset); |
|
798 |
|
799 TInt sum(0); |
|
800 TInt err(KErrNone); |
|
801 while ((err = recordset.Next()) == KSqlAtRow) |
|
802 { |
|
803 sum += recordset.ColumnInt64(KMPXTableDefaultIndex); |
|
804 } |
|
805 |
|
806 CleanupStack::PopAndDestroy(&recordset); |
|
807 CleanupStack::PopAndDestroy(query); |
|
808 |
|
809 if (err != KSqlAtEnd) |
|
810 { |
|
811 User::Leave(KErrCorrupt); |
|
812 } |
|
813 |
|
814 return sum; |
|
815 } |
|
816 |
|
817 // ---------------------------------------------------------------------------- |
|
818 // CMPXDbTable::ExecuteMediaQueryL |
|
819 // ---------------------------------------------------------------------------- |
|
820 // |
|
821 EXPORT_C void CMPXDbTable::ExecuteMediaQueryL( |
|
822 const TArray<TMPXAttribute>& aAttrs, |
|
823 CMPXMediaArray& aMediaArray, |
|
824 const TDesC& aQuery, |
|
825 TInt aValue1, |
|
826 TInt aValue2, |
|
827 TUint aQueryId ) |
|
828 { |
|
829 MPX_FUNC("CMPXDbTable::ExecuteMediaOffsetQueryL"); |
|
830 |
|
831 RSqlStatement& recordset(iDbManager.ExecuteSelectQueryL(aQueryId, |
|
832 aValue1, |
|
833 aValue2, |
|
834 aQuery)); |
|
835 CleanupClosePushL(recordset); |
|
836 |
|
837 TInt err(KErrNone); |
|
838 while ((err = recordset.Next()) == KSqlAtRow) |
|
839 { |
|
840 CMPXMedia* media = CMPXMedia::NewL(); |
|
841 CleanupStack::PushL(media); |
|
842 |
|
843 UpdateMediaL(recordset, aAttrs, *media); |
|
844 |
|
845 aMediaArray.AppendL(*media); |
|
846 CleanupStack::PopAndDestroy(media); |
|
847 } |
|
848 CleanupStack::Pop(&recordset); |
|
849 |
|
850 if (err!= KSqlAtEnd) |
|
851 { |
|
852 User::Leave(KErrCorrupt); |
|
853 } |
|
854 } |
|
855 |
|
856 // ---------------------------------------------------------------------------- |
|
857 // CMPXDbTable::ExecuteMediaQueryL |
|
858 // ---------------------------------------------------------------------------- |
|
859 // |
|
860 EXPORT_C void CMPXDbTable::ExecuteMediaQueryL( const TArray<TMPXAttribute>& aAttrs, |
|
861 CMPXMediaArray& aMediaArray, |
|
862 const TDesC& aQuery, |
|
863 const TDesC& aValue1, |
|
864 TInt aValue2, |
|
865 TBool aAsc, |
|
866 TUint aQueryId ) |
|
867 { |
|
868 MPX_DEBUG1("CMPXDbTable::ExecuteMediaAscQueryL <--"); |
|
869 |
|
870 RSqlStatement& recordset(iDbManager.ExecuteSelectQueryL(aQueryId, |
|
871 aValue1, |
|
872 aValue2, |
|
873 aQuery)); |
|
874 CleanupClosePushL(recordset); |
|
875 |
|
876 TInt err(KErrNone); |
|
877 while ((err = recordset.Next()) == KSqlAtRow) |
|
878 { |
|
879 CMPXMedia* media = CMPXMedia::NewL(); |
|
880 CleanupStack::PushL(media); |
|
881 |
|
882 UpdateMediaL(recordset, aAttrs, *media); |
|
883 |
|
884 if( aAsc ) |
|
885 { |
|
886 aMediaArray.AppendL(*media); |
|
887 } |
|
888 else |
|
889 { |
|
890 aMediaArray.InsertL(*media, 0); |
|
891 } |
|
892 CleanupStack::PopAndDestroy(media); |
|
893 } |
|
894 |
|
895 CleanupStack::Pop(&recordset); |
|
896 |
|
897 if (err!= KSqlAtEnd) |
|
898 { |
|
899 User::Leave(KErrCorrupt); |
|
900 } |
|
901 |
|
902 MPX_DEBUG1("CMPXDbTable::ExecuteMediaAscQueryL -->"); |
|
903 } |
|
904 |
|
905 // ---------------------------------------------------------------------------- |
|
906 // CMPXDbTable::DoCheckTable |
|
907 // ---------------------------------------------------------------------------- |
|
908 // |
|
909 EXPORT_C TBool CMPXDbTable::DoCheckTable( |
|
910 RSqlDatabase& aDatabase, |
|
911 const TDesC& aQuery) |
|
912 { |
|
913 MPX_FUNC("CMPXDbTable::DoCheckTable"); |
|
914 |
|
915 RSqlStatement statement; |
|
916 TInt err(statement.Prepare(aDatabase, aQuery)); |
|
917 statement.Close(); |
|
918 |
|
919 return (err == KErrNone); |
|
920 } |
|
921 |
|
922 |
|
923 // End of File |