mpserviceplugins/mpxsqlitedbhgplugin/src/mpxdbalbum.cpp
changeset 38 b93f525c9244
parent 35 fdb31ab341af
child 51 560ce2306a17
--- a/mpserviceplugins/mpxsqlitedbhgplugin/src/mpxdbalbum.cpp	Fri Jun 11 19:36:32 2010 -0500
+++ b/mpserviceplugins/mpxsqlitedbhgplugin/src/mpxdbalbum.cpp	Fri Jun 25 17:21:37 2010 -0500
@@ -112,7 +112,7 @@
 //
 TUint32 CMPXDbAlbum::AddItemL(
     const TDesC& aName,
-    TUint32 aArtist,
+    const TDesC& aArtistName,
     const TDesC& aArt,
     TInt aDriveId,
     TBool& aNewRecord,
@@ -130,11 +130,13 @@
         // insert new
         HBufC* query = PreProcessStringLC(KQueryAlbumInsert);
         HBufC* name = MPXDbCommonUtil::ProcessSingleQuotesLC(aName);
+        HBufC* artistname = MPXDbCommonUtil::ProcessSingleQuotesLC(aArtistName);
 		HBufC* art = MPXDbCommonUtil::ProcessSingleQuotesLC(aArt);
 
-        iDbManager.ExecuteQueryL(aDriveId, *query, rowId, name, 1, aArtist, art);
+        iDbManager.ExecuteQueryL(aDriveId, *query, rowId, artistname, name, 1, art); 
 
 		CleanupStack::PopAndDestroy(art);
+        CleanupStack::PopAndDestroy(artistname);
         CleanupStack::PopAndDestroy(name);
         CleanupStack::PopAndDestroy(query);
         }
@@ -154,17 +156,21 @@
 	    }
 
         // Artist
-        TUint32 artistId = recordset.ColumnInt64(EAlbumArtist);
+        TPtrC artistname(KNullDesC);
+        artistname.Set(MPXDbCommonUtil::GetColumnTextL(recordset, EAlbumArtistName));
 
         // the current one is Unknown and the new one is Not Unknown.
-        if ( IsUnknownArtistL( artistId ) && !IsUnknownArtistL( aArtist ) )
+         if ( artistname == KNullDesC  && aArtistName!= KNullDesC )
             {
-            _LIT( KFormatArtistId, "Artist=%d" );
-            HBufC* setStr = HBufC::NewLC(KFormatArtistId().Length() + KMCIntegerLen);
-            setStr->Des().Format( KFormatArtistId, aArtist );
-
+            HBufC* artistnameReplaceSingleQuote = 
+                            MPXDbCommonUtil::ProcessSingleQuotesLC( aArtistName );
+            TPtrC criteria(KCriterionArtistName);
+            HBufC* setStr = HBufC::NewLC(criteria.Length() + artistnameReplaceSingleQuote->Length()); 
+            setStr->Des().Format( KCriterionArtistName, artistnameReplaceSingleQuote );
+           
             iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, rowId);
             CleanupStack::PopAndDestroy(setStr);
+            CleanupStack::PopAndDestroy(artistnameReplaceSingleQuote);
             }
 
         // Album Art
@@ -176,9 +182,10 @@
             {
             HBufC* artReplaceSingleQuote = 
                             MPXDbCommonUtil::ProcessSingleQuotesLC( aArt );
-            _LIT( KFormatArt, "Art=\'%S\'" );
-            HBufC* setStr = HBufC::NewLC(256);
-            setStr->Des().Format( KFormatArt, artReplaceSingleQuote );
+
+            TPtrC criteria(KCriterionArt);
+            HBufC* setStr = HBufC::NewLC(criteria.Length() + artReplaceSingleQuote->Length()); 
+            setStr->Des().Format( KCriterionArt, artReplaceSingleQuote );
 
             iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, rowId);
             CleanupStack::PopAndDestroy(setStr);
@@ -240,24 +247,31 @@
             User::Leave(KErrNotFound);
         }
 
-        TUint32 artistId = recordset.ColumnInt64(EAlbumArtist);
         TBool itemModified = EFalse;
+        TPtrC artistname(MPXDbCommonUtil::GetColumnTextL(recordset, EAlbumArtistName));
+        TUint32 artistId = MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), EMPXArtist,
+	            artistname, ETrue);
 
         // the current artist is equal to deleted song's artist
         if ( artistId == aArtist )
             {
-            TUint32 newArtistId = ArtistForAlbumL(aId);
-            if ( artistId != newArtistId )
-                {
-                _LIT( KFormatArtistId, "Artist=%d" );
-                HBufC* setStr = HBufC::NewLC(KFormatArtistId().Length() + KMCIntegerLen);
-                setStr->Des().Format(KFormatArtistId, newArtistId);
+            HBufC* newArtistname = ArtistForAlbumL(aId);
+            
+            CleanupStack::PushL(newArtistname);
+            if (newArtistname && newArtistname->CompareF(artistname)!=0)
+                { 
+                HBufC* artistnameReplaceSingleQuote = MPXDbCommonUtil::ProcessSingleQuotesLC( *newArtistname );
+                TPtrC criteria(KCriterionArtistName);
+                HBufC* setStr = HBufC::NewLC(criteria.Length() + artistnameReplaceSingleQuote->Length()); 
+                setStr->Des().Format( KCriterionArtistName, artistnameReplaceSingleQuote );                    	
 
                 iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, aId);
                 CleanupStack::PopAndDestroy(setStr);
+                CleanupStack::PopAndDestroy(artistnameReplaceSingleQuote);
                 itemModified = ETrue;
                 }
-            }
+            CleanupStack::PopAndDestroy(newArtistname);             
+            }         
         
 #ifdef ABSTRACTAUDIOALBUM_INCLUDED      
     TBool nonEmbeddedArt = EFalse;
@@ -290,9 +304,9 @@
                 {
                 MPX_DEBUG1("CMPXDbAlbum::DecrementSongsForCategoryL, get newArt");
                 HBufC* artReplaceSingleQuote = MPXDbCommonUtil::ProcessSingleQuotesLC( *newArt );
-                _LIT( KFormatArt, "Art=\'%S\'" );
-                HBufC* setStr = HBufC::NewLC(256);                 
-                setStr->Des().Format( KFormatArt, artReplaceSingleQuote );
+                TPtrC criteria(KCriterionArt);   
+                HBufC* setStr = HBufC::NewLC(criteria.Length() + artReplaceSingleQuote->Length()); 
+                setStr->Des().Format( KCriterionArt, artReplaceSingleQuote );
 
                 iDbManager.ExecuteQueryL(aDriveId, KQueryAlbumUpdate, setStr, aId);
                 CleanupStack::PopAndDestroy(setStr);
@@ -553,9 +567,7 @@
 	if (aMedia.IsSupported(KMPXMediaMusicArtist))
 	    {
 	    const TDesC& artistName = aMedia.ValueText(KMPXMediaMusicArtist).Left(KMCMaxTextLen);
-	    TUint32 artistId = MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), EMPXArtist,
-	            artistName, ETrue);
-	    MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicArtist, artistId);
+	    MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCAlbumArtistName, artistName);
 	    }
 	}
 
@@ -572,7 +584,7 @@
 // CMPXDbAlbum::ArtistForAlbumL
 // ----------------------------------------------------------------------------
 //
-TUint32 CMPXDbAlbum::ArtistForAlbumL(const TUint32 aId)
+HBufC* CMPXDbAlbum::ArtistForAlbumL(const TUint32 aId)
     {
     return iObserver.HandleArtistForAlbumL(aId);
     }