mpxplugins/serviceplugins/collectionplugins/mpxsqlitedbhgplugin/src/mpxdbcategory.cpp
branchRCL_3
changeset 66 1f1dad4af8f8
parent 56 2cbbefa9af78
equal deleted inserted replaced
60:bdd9da0d70fe 66:1f1dad4af8f8
    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"
       
    34 
    33 
    35 // CONSTANTS
    34 // CONSTANTS
    36 
    35 
    37 // maximum number of table name entries per query
    36 // maximum number of table name entries per query
    38 const TInt KMaxTableNameCount = 2;
    37 const TInt KMaxTableNameCount = 2;
    78 // ----------------------------------------------------------------------------
    77 // ----------------------------------------------------------------------------
    79 // CMPXDbCategory::AddItemL
    78 // CMPXDbCategory::AddItemL
    80 // ----------------------------------------------------------------------------
    79 // ----------------------------------------------------------------------------
    81 //
    80 //
    82 TUint32 CMPXDbCategory::AddItemL(
    81 TUint32 CMPXDbCategory::AddItemL(
    83     TMPXGeneralCategory aCategory,        
    82     const TDesC& aName,
    84     const CMPXMedia& aMedia,
       
    85     TInt aDriveId,
    83     TInt aDriveId,
    86     TBool& aNewRecord,
    84     TBool& aNewRecord,
    87     TBool aCaseSensitive)
    85     TBool aCaseSensitive)
    88     {
    86     {
    89     MPX_FUNC("CMPXDbCategory::AddItemL");
    87     MPX_FUNC("CMPXDbCategory::AddItemL");
    90 
    88 
    91     TPtrC itemName(ItemNameL(aCategory, aMedia));
       
    92     
       
    93     // try to find the item first
    89     // try to find the item first
    94     TUint32 rowId(MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), iCategory,
    90     TUint32 rowId(MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), iCategory,
    95         itemName, aCaseSensitive));
    91         aName, aCaseSensitive));
    96     aNewRecord = !CategoryItemExistsL(aDriveId, rowId);
    92     aNewRecord = !CategoryItemExistsL(aDriveId, rowId);
    97 
    93 
    98     if (aNewRecord)
    94     if (aNewRecord)
    99         {
    95         {
   100         // insert new
    96         // insert new
   101         HBufC* query = PreProcessStringLC(KQueryCategoryInsert);
    97         HBufC* query = PreProcessStringLC(KQueryCategoryInsert);
   102         HBufC* name = MPXDbCommonUtil::ProcessSingleQuotesLC(itemName);
    98         HBufC* name = MPXDbCommonUtil::ProcessSingleQuotesLC(aName);
   103 
    99 
   104         iDbManager.ExecuteQueryL(aDriveId, *query, rowId, name, 1);
   100         iDbManager.ExecuteQueryL(aDriveId, *query, rowId, name, 1);
   105 
   101 
   106         CleanupStack::PopAndDestroy(name);
   102         CleanupStack::PopAndDestroy(name);
   107         CleanupStack::PopAndDestroy(query);
   103         CleanupStack::PopAndDestroy(query);
   114         CleanupStack::PopAndDestroy(query);
   110         CleanupStack::PopAndDestroy(query);
   115         }
   111         }
   116 
   112 
   117     return rowId;
   113     return rowId;
   118     }
   114     }
   119 		
   115 
   120 // ----------------------------------------------------------------------------
   116 // ----------------------------------------------------------------------------
   121 // CMPXDbCategory::GetNameL
   117 // CMPXDbCategory::GetNameL
   122 // ----------------------------------------------------------------------------
   118 // ----------------------------------------------------------------------------
   123 //
   119 //
   124 HBufC* CMPXDbCategory::GetNameL(
   120 HBufC* CMPXDbCategory::GetNameL(
   242             // ignore attribute
   238             // ignore attribute
   243             }
   239             }
   244         }
   240         }
   245 
   241 
   246     // construct criteria string
   242     // construct criteria string
   247     HBufC* criteriaStr = NULL;
   243     HBufC* criteriaStr = MPXDbCommonUtil::StringFromArrayLC(*criteriaArray, KMCAndKeyword);
   248     if (criteriaArray->Count() > 0)
   244 
   249         {
   245     // either get all items or items filtered based on criteria
   250         criteriaStr = MPXDbCommonUtil::StringFromArrayLC(*criteriaArray, KMCAndKeyword);
   246     HBufC* query = PreProcessStringLC(criteriaStr->Length() ?
   251         }
   247         KQueryCategoryItems() : KQueryCategoryAll());
   252     else
   248     RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(*query, criteriaStr));
   253         {
   249     CleanupStack::PopAndDestroy(3, criteriaArray); // query, criteriaStr, criteriaArray
   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 
       
   271     CleanupClosePushL(recordset);
   250     CleanupClosePushL(recordset);
   272 
   251 
   273     // process the results
   252     // process the results
   274     ProcessRecordsetL(aAttrs, recordset, aMediaArray);
   253     ProcessRecordsetL(aAttrs, recordset, aMediaArray);
   275     CleanupStack::PopAndDestroy(&recordset);
   254     CleanupStack::PopAndDestroy(&recordset);
   276     }
   255     }
   277         
   256 
   278 // ----------------------------------------------------------------------------
   257 // ----------------------------------------------------------------------------
   279 // CMPXDbCategory::DecrementSongsForCategoryL
   258 // CMPXDbCategory::DecrementSongsForCategoryL
   280 // ----------------------------------------------------------------------------
   259 // ----------------------------------------------------------------------------
   281 //
   260 //
   282 void CMPXDbCategory::DecrementSongsForCategoryL(
   261 void CMPXDbCategory::DecrementSongsForCategoryL(
   505     TUint32 /*aId*/,
   484     TUint32 /*aId*/,
   506     const CMPXMedia& /*aMedia*/,
   485     const CMPXMedia& /*aMedia*/,
   507     TInt /*aDriveId*/,
   486     TInt /*aDriveId*/,
   508     CMPXMessageArray* /*aItemChangedMessages*/)
   487     CMPXMessageArray* /*aItemChangedMessages*/)
   509 	{
   488 	{
   510     MPX_FUNC("CMPXDbCategory::UpdateItemL");
   489 	// nothing
   511     
       
   512 	// do nothing
       
   513 	}
   490 	}
   514 
   491 
   515 // ----------------------------------------------------------------------------
   492 // ----------------------------------------------------------------------------
   516 // CMPXDbCategory::UpdateMediaL
   493 // CMPXDbCategory::UpdateMediaL
   517 // ----------------------------------------------------------------------------
   494 // ----------------------------------------------------------------------------
   595     return query;
   572     return query;
   596     }
   573     }
   597 
   574 
   598 // ----------------------------------------------------------------------------
   575 // ----------------------------------------------------------------------------
   599 // CMPXDbCategory::ProcessRecordsetL
   576 // CMPXDbCategory::ProcessRecordsetL
   600 // Unknown item is stored in the database as empty string (name field). This ensures the
   577 // Unknown item is stored in the database as NULL (name field). This ensures the
   601 // unknown item to be the 1st found record if it exists. This will save time in
   578 // unknown item to be the 1st found record if it exists. This will save time in
   602 // searching for the unknown record among the results and avoid performing
   579 // searching for the unknown record among the results and avoid performing
   603 // descriptor comparison. If the 1st record is the unknown item, it won't be
   580 // descriptor comparison. If the 1st record is the unknown item, it won't be
   604 // appended to the array until all other records have been put in the array.
   581 // appended to the array until all other records have been put in the array.
   605 //
   582 //
   687         }
   664         }
   688     CleanupStack::PopAndDestroy(&ids);
   665     CleanupStack::PopAndDestroy(&ids);
   689     }
   666     }
   690 
   667 
   691 // ----------------------------------------------------------------------------
   668 // ----------------------------------------------------------------------------
   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 // ----------------------------------------------------------------------------
       
   732 // CMPXDbCategory::CreateTableL
   669 // CMPXDbCategory::CreateTableL
   733 // ----------------------------------------------------------------------------
   670 // ----------------------------------------------------------------------------
   734 //
   671 //
   735 void CMPXDbCategory::CreateTableL(
   672 void CMPXDbCategory::CreateTableL(
   736     RSqlDatabase& aDatabase,
   673     RSqlDatabase& aDatabase,