mpserviceplugins/mpxsqlitedbhgplugin/src/mpxdbcategory.cpp
changeset 51 560ce2306a17
parent 34 2c5162224003
equal deleted inserted replaced
47:4cc1412daed0 51:560ce2306a17
    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(
   407     const TArray<TMPXAttribute>& aAttrs,
   428     const TArray<TMPXAttribute>& aAttrs,
   408     CMPXMediaArray& aMediaArray)
   429     CMPXMediaArray& aMediaArray)
   409     {
   430     {
   410     MPX_FUNC("CMPXDbCategory::GetSubCategoryItemsL");
   431     MPX_FUNC("CMPXDbCategory::GetSubCategoryItemsL");
   411 
   432 
   412     // this is only valid for albums belonging to an artist
       
   413     ASSERT((iCategory == EMPXAlbum) && (aParentCategory == EMPXArtist));
       
   414 
       
   415     // to handle the UREL warning
       
   416     (void)aParentCategory;
       
   417 
       
   418     RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(KQueryCategorySubcategoryItems, aParentId));
       
   419     CleanupClosePushL(recordset);
       
   420     ProcessRecordsetL(aAttrs, recordset, aMediaArray);
       
   421     CleanupStack::PopAndDestroy(&recordset);
       
   422     }
   433     }
   423 
   434 
   424 // ----------------------------------------------------------------------------
   435 // ----------------------------------------------------------------------------
   425 // CMPXDbCategory::CategoryItemExistsL
   436 // CMPXDbCategory::CategoryItemExistsL
   426 // The category records must be in the same database as the corresponding
   437 // The category records must be in the same database as the corresponding
   484     TUint32 /*aId*/,
   495     TUint32 /*aId*/,
   485     const CMPXMedia& /*aMedia*/,
   496     const CMPXMedia& /*aMedia*/,
   486     TInt /*aDriveId*/,
   497     TInt /*aDriveId*/,
   487     CMPXMessageArray* /*aItemChangedMessages*/)
   498     CMPXMessageArray* /*aItemChangedMessages*/)
   488 	{
   499 	{
   489 	// nothing
   500     MPX_FUNC("CMPXDbCategory::UpdateItemL");
       
   501     
       
   502 	// do nothing
   490 	}
   503 	}
   491 
   504 
   492 // ----------------------------------------------------------------------------
   505 // ----------------------------------------------------------------------------
   493 // CMPXDbCategory::UpdateMediaL
   506 // CMPXDbCategory::UpdateMediaL
   494 // ----------------------------------------------------------------------------
   507 // ----------------------------------------------------------------------------
   572     return query;
   585     return query;
   573     }
   586     }
   574 
   587 
   575 // ----------------------------------------------------------------------------
   588 // ----------------------------------------------------------------------------
   576 // CMPXDbCategory::ProcessRecordsetL
   589 // CMPXDbCategory::ProcessRecordsetL
   577 // Unknown item is stored in the database as NULL (name field). This ensures the
   590 // 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
   591 // 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
   592 // 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
   593 // 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.
   594 // appended to the array until all other records have been put in the array.
   582 //
   595 //
   664         }
   677         }
   665     CleanupStack::PopAndDestroy(&ids);
   678     CleanupStack::PopAndDestroy(&ids);
   666     }
   679     }
   667 
   680 
   668 // ----------------------------------------------------------------------------
   681 // ----------------------------------------------------------------------------
       
   682 // CMPXDbCategory::ItemNameL
       
   683 // ----------------------------------------------------------------------------
       
   684 //
       
   685 TPtrC CMPXDbCategory::ItemNameL(
       
   686     TMPXGeneralCategory aCategory,        
       
   687     const CMPXMedia& aMedia)
       
   688     {
       
   689     MPX_FUNC("CMPXDbCategory::ItemNameL");
       
   690     
       
   691     TMPXAttribute attribute;
       
   692     switch(aCategory)
       
   693         {
       
   694         case EMPXGenre:
       
   695             {
       
   696             attribute = KMPXMediaMusicGenre;
       
   697             break;
       
   698             }
       
   699         case EMPXComposer:
       
   700             {
       
   701             attribute = KMPXMediaMusicComposer;
       
   702             break;
       
   703             }
       
   704         default:
       
   705             {
       
   706             User::Leave(KErrArgument);
       
   707             break;
       
   708             }
       
   709         }
       
   710     
       
   711     if (aMedia.IsSupported(attribute))
       
   712         {
       
   713         return aMedia.ValueText(attribute).Left(KMCMaxTextLen);
       
   714         }
       
   715     else
       
   716         {
       
   717         return KNullDesC();
       
   718         }
       
   719     }
       
   720 
       
   721 // ----------------------------------------------------------------------------
   669 // CMPXDbCategory::CreateTableL
   722 // CMPXDbCategory::CreateTableL
   670 // ----------------------------------------------------------------------------
   723 // ----------------------------------------------------------------------------
   671 //
   724 //
   672 void CMPXDbCategory::CreateTableL(
   725 void CMPXDbCategory::CreateTableL(
   673     RSqlDatabase& aDatabase,
   726     RSqlDatabase& aDatabase,