28 |
28 |
29 #include "mpxcollectiondbdef.h" |
29 #include "mpxcollectiondbdef.h" |
30 #include "mpxdbpluginqueries.h" |
30 #include "mpxdbpluginqueries.h" |
31 #include "mpxdbutil.h" |
31 #include "mpxdbutil.h" |
32 #include "mpxdbcategory.h" |
32 #include "mpxdbcategory.h" |
|
33 #include "mpxmediamusicdefs.h" |
33 |
34 |
34 // CONSTANTS |
35 // CONSTANTS |
35 |
36 |
36 // maximum number of table name entries per query |
37 // maximum number of table name entries per query |
37 const TInt KMaxTableNameCount = 2; |
38 const TInt KMaxTableNameCount = 2; |
77 // ---------------------------------------------------------------------------- |
78 // ---------------------------------------------------------------------------- |
78 // CMPXDbCategory::AddItemL |
79 // CMPXDbCategory::AddItemL |
79 // ---------------------------------------------------------------------------- |
80 // ---------------------------------------------------------------------------- |
80 // |
81 // |
81 TUint32 CMPXDbCategory::AddItemL( |
82 TUint32 CMPXDbCategory::AddItemL( |
82 const TDesC& aName, |
83 TMPXGeneralCategory aCategory, |
|
84 const CMPXMedia& aMedia, |
83 TInt aDriveId, |
85 TInt aDriveId, |
84 TBool& aNewRecord, |
86 TBool& aNewRecord, |
85 TBool aCaseSensitive) |
87 TBool aCaseSensitive) |
86 { |
88 { |
87 MPX_FUNC("CMPXDbCategory::AddItemL"); |
89 MPX_FUNC("CMPXDbCategory::AddItemL"); |
88 |
90 |
|
91 TPtrC itemName(ItemNameL(aCategory, aMedia)); |
|
92 |
89 // try to find the item first |
93 // try to find the item first |
90 TUint32 rowId(MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), iCategory, |
94 TUint32 rowId(MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), iCategory, |
91 aName, aCaseSensitive)); |
95 itemName, aCaseSensitive)); |
92 aNewRecord = !CategoryItemExistsL(aDriveId, rowId); |
96 aNewRecord = !CategoryItemExistsL(aDriveId, rowId); |
93 |
97 |
94 if (aNewRecord) |
98 if (aNewRecord) |
95 { |
99 { |
96 // insert new |
100 // insert new |
97 HBufC* query = PreProcessStringLC(KQueryCategoryInsert); |
101 HBufC* query = PreProcessStringLC(KQueryCategoryInsert); |
98 HBufC* name = MPXDbCommonUtil::ProcessSingleQuotesLC(aName); |
102 HBufC* name = MPXDbCommonUtil::ProcessSingleQuotesLC(itemName); |
99 |
103 |
100 iDbManager.ExecuteQueryL(aDriveId, *query, rowId, name, 1); |
104 iDbManager.ExecuteQueryL(aDriveId, *query, rowId, name, 1); |
101 |
105 |
102 CleanupStack::PopAndDestroy(name); |
106 CleanupStack::PopAndDestroy(name); |
103 CleanupStack::PopAndDestroy(query); |
107 CleanupStack::PopAndDestroy(query); |
110 CleanupStack::PopAndDestroy(query); |
114 CleanupStack::PopAndDestroy(query); |
111 } |
115 } |
112 |
116 |
113 return rowId; |
117 return rowId; |
114 } |
118 } |
115 |
119 |
116 // ---------------------------------------------------------------------------- |
120 // ---------------------------------------------------------------------------- |
117 // CMPXDbCategory::GetNameL |
121 // CMPXDbCategory::GetNameL |
118 // ---------------------------------------------------------------------------- |
122 // ---------------------------------------------------------------------------- |
119 // |
123 // |
120 HBufC* CMPXDbCategory::GetNameL( |
124 HBufC* CMPXDbCategory::GetNameL( |
238 // ignore attribute |
242 // ignore attribute |
239 } |
243 } |
240 } |
244 } |
241 |
245 |
242 // construct criteria string |
246 // construct criteria string |
243 HBufC* criteriaStr = MPXDbCommonUtil::StringFromArrayLC(*criteriaArray, KMCAndKeyword); |
247 HBufC* criteriaStr = NULL; |
244 |
248 if (criteriaArray->Count() > 0) |
245 // either get all items or items filtered based on criteria |
249 { |
246 HBufC* query = PreProcessStringLC(criteriaStr->Length() ? |
250 criteriaStr = MPXDbCommonUtil::StringFromArrayLC(*criteriaArray, KMCAndKeyword); |
247 KQueryCategoryItems() : KQueryCategoryAll()); |
251 } |
248 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(*query, criteriaStr)); |
252 else |
249 CleanupStack::PopAndDestroy(3, criteriaArray); // query, criteriaStr, criteriaArray |
253 { |
|
254 _LIT(KCriteriaTrue, "1"); |
|
255 criteriaStr = KCriteriaTrue().AllocLC(); |
|
256 } |
|
257 |
|
258 RSqlStatement recordset; |
|
259 if (iCategory == EMPXArtist) |
|
260 { |
|
261 recordset = iDbManager.ExecuteSelectQueryL(KQueryArtistItems, criteriaStr); |
|
262 CleanupStack::PopAndDestroy(2, criteriaArray); //criteriaStr, criteriaArray |
|
263 } |
|
264 else |
|
265 { |
|
266 HBufC* query = PreProcessStringLC(KQueryCategoryItems); |
|
267 recordset = iDbManager.ExecuteSelectQueryL(*query, criteriaStr); |
|
268 CleanupStack::PopAndDestroy(3, criteriaArray); //query, criteriaStr, criteriaArray |
|
269 } |
|
270 |
250 CleanupClosePushL(recordset); |
271 CleanupClosePushL(recordset); |
251 |
272 |
252 // process the results |
273 // process the results |
253 ProcessRecordsetL(aAttrs, recordset, aMediaArray); |
274 ProcessRecordsetL(aAttrs, recordset, aMediaArray); |
254 CleanupStack::PopAndDestroy(&recordset); |
275 CleanupStack::PopAndDestroy(&recordset); |
255 } |
276 } |
256 |
277 |
257 // ---------------------------------------------------------------------------- |
278 // ---------------------------------------------------------------------------- |
258 // CMPXDbCategory::DecrementSongsForCategoryL |
279 // CMPXDbCategory::DecrementSongsForCategoryL |
259 // ---------------------------------------------------------------------------- |
280 // ---------------------------------------------------------------------------- |
260 // |
281 // |
261 void CMPXDbCategory::DecrementSongsForCategoryL( |
282 void CMPXDbCategory::DecrementSongsForCategoryL( |
484 TUint32 /*aId*/, |
505 TUint32 /*aId*/, |
485 const CMPXMedia& /*aMedia*/, |
506 const CMPXMedia& /*aMedia*/, |
486 TInt /*aDriveId*/, |
507 TInt /*aDriveId*/, |
487 CMPXMessageArray* /*aItemChangedMessages*/) |
508 CMPXMessageArray* /*aItemChangedMessages*/) |
488 { |
509 { |
489 // nothing |
510 MPX_FUNC("CMPXDbCategory::UpdateItemL"); |
|
511 |
|
512 // do nothing |
490 } |
513 } |
491 |
514 |
492 // ---------------------------------------------------------------------------- |
515 // ---------------------------------------------------------------------------- |
493 // CMPXDbCategory::UpdateMediaL |
516 // CMPXDbCategory::UpdateMediaL |
494 // ---------------------------------------------------------------------------- |
517 // ---------------------------------------------------------------------------- |
572 return query; |
595 return query; |
573 } |
596 } |
574 |
597 |
575 // ---------------------------------------------------------------------------- |
598 // ---------------------------------------------------------------------------- |
576 // CMPXDbCategory::ProcessRecordsetL |
599 // CMPXDbCategory::ProcessRecordsetL |
577 // Unknown item is stored in the database as NULL (name field). This ensures the |
600 // Unknown item is stored in the database as empty string (name field). This ensures the |
578 // unknown item to be the 1st found record if it exists. This will save time in |
601 // unknown item to be the 1st found record if it exists. This will save time in |
579 // searching for the unknown record among the results and avoid performing |
602 // searching for the unknown record among the results and avoid performing |
580 // descriptor comparison. If the 1st record is the unknown item, it won't be |
603 // descriptor comparison. If the 1st record is the unknown item, it won't be |
581 // appended to the array until all other records have been put in the array. |
604 // appended to the array until all other records have been put in the array. |
582 // |
605 // |
664 } |
687 } |
665 CleanupStack::PopAndDestroy(&ids); |
688 CleanupStack::PopAndDestroy(&ids); |
666 } |
689 } |
667 |
690 |
668 // ---------------------------------------------------------------------------- |
691 // ---------------------------------------------------------------------------- |
|
692 // CMPXDbCategory::ItemNameL |
|
693 // ---------------------------------------------------------------------------- |
|
694 // |
|
695 TPtrC CMPXDbCategory::ItemNameL( |
|
696 TMPXGeneralCategory aCategory, |
|
697 const CMPXMedia& aMedia) |
|
698 { |
|
699 MPX_FUNC("CMPXDbCategory::ItemNameL"); |
|
700 |
|
701 TMPXAttribute attribute; |
|
702 switch(aCategory) |
|
703 { |
|
704 case EMPXGenre: |
|
705 { |
|
706 attribute = KMPXMediaMusicGenre; |
|
707 break; |
|
708 } |
|
709 case EMPXComposer: |
|
710 { |
|
711 attribute = KMPXMediaMusicComposer; |
|
712 break; |
|
713 } |
|
714 default: |
|
715 { |
|
716 User::Leave(KErrArgument); |
|
717 break; |
|
718 } |
|
719 } |
|
720 |
|
721 if (aMedia.IsSupported(attribute)) |
|
722 { |
|
723 return aMedia.ValueText(attribute).Left(KMCMaxTextLen); |
|
724 } |
|
725 else |
|
726 { |
|
727 return KNullDesC(); |
|
728 } |
|
729 } |
|
730 |
|
731 // ---------------------------------------------------------------------------- |
669 // CMPXDbCategory::CreateTableL |
732 // CMPXDbCategory::CreateTableL |
670 // ---------------------------------------------------------------------------- |
733 // ---------------------------------------------------------------------------- |
671 // |
734 // |
672 void CMPXDbCategory::CreateTableL( |
735 void CMPXDbCategory::CreateTableL( |
673 RSqlDatabase& aDatabase, |
736 RSqlDatabase& aDatabase, |