mpserviceplugins/mpxsqlitedbhgplugin/src/mpxdbplaylist.cpp
branchRCL_3
changeset 52 14979e23cb5e
equal deleted inserted replaced
50:26a1709b9fec 52:14979e23cb5e
       
     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:  Responsible for interaction with the playlist tables.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <f32file.h>
       
    21 #include <mpxlog.h>
       
    22 #include <mpxmediacontainerdefs.h>
       
    23 
       
    24 #include "mpxdbcommonutil.h"
       
    25 #include "mpxdbcommondef.h"
       
    26 #include "mpxdbcommonstd.h"
       
    27 
       
    28 #include "mpxcollectiondbdef.h"
       
    29 #include "mpxdbmanager.h"
       
    30 #include "mpxdbutil.h"
       
    31 #include "mpxdbpluginqueries.h"
       
    32 #include "mpxdbplaylistsongs.h"
       
    33 #include "mpxdbplaylist.h"
       
    34 
       
    35 // CONSTANTS
       
    36 // UniqueID column in Uris requests
       
    37 const TInt KColUniqueID = 0;
       
    38 // URI column in Uris requests
       
    39 const TInt KColUri = 1;
       
    40 
       
    41 // ============================ MEMBER FUNCTIONS ==============================
       
    42 
       
    43 // ----------------------------------------------------------------------------
       
    44 // Two-phased constructor.
       
    45 // ----------------------------------------------------------------------------
       
    46 //
       
    47 CMPXDbPlaylist* CMPXDbPlaylist::NewL(
       
    48     CMPXDbManager& aDbManager,
       
    49 	MMPXDbPlaylistObserver& aObserver)
       
    50     {
       
    51     MPX_FUNC("CMPXDbPlaylist::NewL");
       
    52 
       
    53     CMPXDbPlaylist* self = CMPXDbPlaylist::NewLC(aDbManager, aObserver);
       
    54     CleanupStack::Pop(self);
       
    55     return self;
       
    56     }
       
    57 
       
    58 // ----------------------------------------------------------------------------
       
    59 // Two-phased constructor.
       
    60 // ----------------------------------------------------------------------------
       
    61 //
       
    62 CMPXDbPlaylist* CMPXDbPlaylist::NewLC(
       
    63     CMPXDbManager& aDbManager,
       
    64 	MMPXDbPlaylistObserver& aObserver)
       
    65     {
       
    66     MPX_FUNC("CMPXDbPlaylist::NewLC");
       
    67 
       
    68 	CMPXDbPlaylist* self = new (ELeave) CMPXDbPlaylist(aDbManager, aObserver);
       
    69     CleanupStack::PushL(self);
       
    70     self->ConstructL();
       
    71     return self;
       
    72     }
       
    73 
       
    74 // ----------------------------------------------------------------------------
       
    75 // Destructor
       
    76 // ----------------------------------------------------------------------------
       
    77 //
       
    78 CMPXDbPlaylist::~CMPXDbPlaylist()
       
    79     {
       
    80     MPX_FUNC("CMPXDbPlaylist::~CMPXDbPlaylist");
       
    81     delete iPlaylistSongs;
       
    82     }
       
    83 
       
    84 // ----------------------------------------------------------------------------
       
    85 // Constructor
       
    86 // ----------------------------------------------------------------------------
       
    87 //
       
    88 CMPXDbPlaylist::CMPXDbPlaylist(
       
    89     CMPXDbManager& aDbManager,
       
    90     MMPXDbPlaylistObserver& aObserver) :
       
    91     CMPXDbTable(aDbManager),
       
    92 	iObserver(aObserver)
       
    93     {
       
    94     MPX_FUNC("CMPXDbPlaylist::CMPXDbPlaylist");
       
    95     }
       
    96 
       
    97 // ----------------------------------------------------------------------------
       
    98 // Second phase constructor.
       
    99 // ----------------------------------------------------------------------------
       
   100 //
       
   101 void CMPXDbPlaylist::ConstructL()
       
   102     {
       
   103     MPX_FUNC("CMPXDbPlaylist::ConstructL");
       
   104 
       
   105     BaseConstructL();
       
   106     iPlaylistSongs = CMPXDbPlaylistSongs::NewL(iDbManager);
       
   107     }
       
   108 
       
   109 // ----------------------------------------------------------------------------
       
   110 // CMPXDbPlaylist::AddPlaylistL
       
   111 // ----------------------------------------------------------------------------
       
   112 //
       
   113 TUint32 CMPXDbPlaylist::AddPlaylistL(
       
   114     const CMPXMedia& aMedia)
       
   115     {
       
   116     MPX_FUNC("CMPXDbPlaylist::AddPlaylistL");
       
   117 
       
   118     // make sure the playlist and the corresponding songs are deleted
       
   119     TUint32 playlistId(MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), EMPXPlaylist,
       
   120         aMedia.ValueText(KMPXMediaGeneralUri), EFalse));
       
   121     DeletePlaylistNoUriL(playlistId);
       
   122 
       
   123     // add the playlist
       
   124     return DoAddPlaylistL(aMedia, TDriveUnit(aMedia.ValueText(KMPXMediaGeneralUri)));
       
   125     }
       
   126 
       
   127 // ----------------------------------------------------------------------------
       
   128 // CMPXDbPlaylist::AddSongsL
       
   129 // ----------------------------------------------------------------------------
       
   130 //
       
   131 void CMPXDbPlaylist::AddSongsL(
       
   132     TUint32 aPlaylistId,
       
   133     const CMPXMediaArray& aMediaArray)
       
   134     {
       
   135     MPX_FUNC("CMPXDbPlaylist::AddSongsL");
       
   136 
       
   137     // get the drive ID of corresponding playlist
       
   138     TInt drive(GetDriveIdL(aPlaylistId));
       
   139 
       
   140     // add the songs
       
   141     iPlaylistSongs->AddSongsL(aPlaylistId, aMediaArray, drive);
       
   142 
       
   143     // update the time for the playlist
       
   144     UpdatePlaylistTimeL(aPlaylistId, drive);
       
   145     }
       
   146 
       
   147 // ----------------------------------------------------------------------------
       
   148 // CMPXDbPlaylist::UpdatePlaylistL
       
   149 // ----------------------------------------------------------------------------
       
   150 //
       
   151 void CMPXDbPlaylist::UpdatePlaylistL(
       
   152     const CMPXMedia& aMedia,
       
   153     CMPXMessage& aMessage,
       
   154     TInt aDriveId)
       
   155     {
       
   156     MPX_FUNC("CMPXDbPlaylist::UpdatePlaylistL");
       
   157 
       
   158     TUint32 playlistId((aMedia.ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId)).iId2);
       
   159     DoUpdatePlaylistL(playlistId, aMedia, aDriveId, aMessage);
       
   160     }
       
   161 
       
   162 // ----------------------------------------------------------------------------
       
   163 // CMPXDbPlaylist::UpdateSongL
       
   164 // ----------------------------------------------------------------------------
       
   165 //
       
   166 TBool CMPXDbPlaylist::UpdateSongL(
       
   167     const CMPXMedia& aMedia,
       
   168     TBool aResetFlags,
       
   169     CMPXMessageArray* aItemChangedMessages /* = NULL */)
       
   170     {
       
   171     MPX_FUNC("CMPXDbPlaylist::UpdateSongL");
       
   172 
       
   173     // find the song ID
       
   174     TInt oldSongId(0);
       
   175     TInt newSongId(0);
       
   176     if (aMedia.IsSupported(KMPXMediaGeneralId))
       
   177         {
       
   178         oldSongId = (aMedia.ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId)).iId2;
       
   179         }
       
   180     if (aMedia.IsSupported(KMPXMediaGeneralUri))
       
   181         {
       
   182         newSongId = MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), EMPXCollection,
       
   183             aMedia.ValueText(KMPXMediaGeneralUri), EFalse);
       
   184         }
       
   185     if ( !aMedia.IsSupported( KMPXMediaGeneralId ) && !aMedia.IsSupported( KMPXMediaGeneralUri ))
       
   186         {
       
   187         User::Leave( KErrArgument );
       
   188         }
       
   189 
       
   190     if ( newSongId <= 0 )
       
   191         {
       
   192         newSongId = oldSongId;
       
   193         }
       
   194 
       
   195     if ( oldSongId <= 0 )
       
   196         {
       
   197         oldSongId = newSongId;
       
   198         }
       
   199 
       
   200     // update the PlaylistSongs and PlaylistSongInfo tables first
       
   201     TBool updated(EFalse);
       
   202     TBool visible(iPlaylistSongs->UpdateSongL( oldSongId, aMedia, aResetFlags, updated ));
       
   203     TBool bSongInPlaylists( EFalse );
       
   204     if (updated)
       
   205         {
       
   206         UpdatePlaylistsForSongL( newSongId, aItemChangedMessages,bSongInPlaylists );
       
   207         }
       
   208 
       
   209     return visible;
       
   210     }
       
   211 
       
   212 // ----------------------------------------------------------------------------
       
   213 // CMPXDbPlaylist::DeleteSongL
       
   214 // ----------------------------------------------------------------------------
       
   215 //
       
   216 void CMPXDbPlaylist::DeleteSongL(
       
   217     TUint32 aSongId,
       
   218     CMPXMessageArray& aItemChangedMessages)
       
   219     {
       
   220     MPX_FUNC("CMPXDbPlaylist::DeleteSongL");
       
   221     TBool bSongInPlaylists(EFalse);
       
   222     // add item changed messages for all playlists that contain the song
       
   223     UpdatePlaylistsForSongL (aSongId, &aItemChangedMessages, bSongInPlaylists);
       
   224     if (bSongInPlaylists)
       
   225         {
       
   226         // delete the song from the PlaylistSongs and PlaylistSongInfo tables
       
   227         iPlaylistSongs->DeleteSongL (aSongId);
       
   228         }
       
   229     }
       
   230 
       
   231 // ----------------------------------------------------------------------------
       
   232 // CMPXDbPlaylist::DeleteSongL
       
   233 // ----------------------------------------------------------------------------
       
   234 //
       
   235 void CMPXDbPlaylist::DeleteSongL(
       
   236     TUint32 aPlaylistId,
       
   237     TUint32 aSongId,
       
   238     TInt aOrdinal)
       
   239     {
       
   240     MPX_FUNC("CMPXDbPlaylist::DeleteSongL");
       
   241 
       
   242     // get playlist drive
       
   243     TInt drive(GetDriveIdL(aPlaylistId));
       
   244 
       
   245     // delete the song from the PlaylistSongs / PlaylistSongInfo tables
       
   246     iPlaylistSongs->DeleteSongL(aPlaylistId, aSongId, aOrdinal, drive);
       
   247 
       
   248     // update the time for the playlist
       
   249     UpdatePlaylistTimeL(aPlaylistId, drive);
       
   250     }
       
   251 
       
   252 // ----------------------------------------------------------------------------
       
   253 // CMPXDbPlaylist::DeletePlaylistL
       
   254 // ----------------------------------------------------------------------------
       
   255 //
       
   256 HBufC* CMPXDbPlaylist::DeletePlaylistL(
       
   257     TUint32 aPlaylistId)
       
   258     {
       
   259     MPX_FUNC("CMPXDbPlaylist::DeletePlaylistL");
       
   260 
       
   261     // get the uri
       
   262     HBufC* uri = GetUriL(aPlaylistId);
       
   263     if (uri)
       
   264         {
       
   265         CleanupStack::PushL(uri);
       
   266         TDriveUnit drive(*uri);
       
   267 
       
   268         // delete the songs from the PlaylistSongs table
       
   269         iPlaylistSongs->DeleteSongsL(aPlaylistId, drive);
       
   270 
       
   271         // delete the playlist record from the Playlist table
       
   272         iDbManager.ExecuteQueryL(drive, KQueryPlaylistDelete, aPlaylistId);
       
   273 
       
   274         CleanupStack::Pop(uri);
       
   275         }
       
   276 
       
   277     return uri;
       
   278     }
       
   279 
       
   280 // ----------------------------------------------------------------------------
       
   281 // CMPXDbPlaylist::DeletePlaylistNoUriL
       
   282 // ----------------------------------------------------------------------------
       
   283 //
       
   284 void CMPXDbPlaylist::DeletePlaylistNoUriL(
       
   285     TUint32 aPlaylistId)
       
   286     {
       
   287     MPX_FUNC("CMPXDbPlaylist::DeletePlaylistNoUriL");
       
   288 
       
   289     TInt drive(0);
       
   290     MPX_TRAPD(err, drive = GetDriveIdL(aPlaylistId));
       
   291     if (err != KErrNotFound)
       
   292         {
       
   293         User::LeaveIfError(err);
       
   294 
       
   295         // delete the songs from the PlaylistSongs table
       
   296         iPlaylistSongs->DeleteSongsL(aPlaylistId, drive);
       
   297 
       
   298         // delete the playlist record from the Playlist table
       
   299         iDbManager.ExecuteQueryL(drive, KQueryPlaylistDelete, aPlaylistId);
       
   300         }
       
   301     }
       
   302 
       
   303 // ----------------------------------------------------------------------------
       
   304 // CMPXDbPlaylist::DeleteAllPlaylistsL
       
   305 // ----------------------------------------------------------------------------
       
   306 //
       
   307 void CMPXDbPlaylist::DeleteAllPlaylistsL()
       
   308     {
       
   309     MPX_FUNC("CMPXDbPlaylist::DeleteAllPlaylistsL");
       
   310 
       
   311     // delete the songs from the PlaylistSongs table
       
   312     iPlaylistSongs->DeleteAllSongsL();
       
   313 
       
   314     // delete all playlists
       
   315     iDbManager.ExecuteQueryL(KDbManagerAllDrives, KQueryPlaylistDeleteAll);
       
   316     }
       
   317 
       
   318 // ----------------------------------------------------------------------------
       
   319 // CMPXDbPlaylist::CountL
       
   320 // ----------------------------------------------------------------------------
       
   321 //
       
   322 TInt CMPXDbPlaylist::CountL()
       
   323     {
       
   324     MPX_FUNC("CMPXDbPlaylist::CountL");
       
   325     return ExecuteSumQueryL(KQueryPlaylistCount);
       
   326     }
       
   327 
       
   328 // ----------------------------------------------------------------------------
       
   329 // CMPXDbPlaylist::GetPlaylistL
       
   330 // ----------------------------------------------------------------------------
       
   331 //
       
   332 void CMPXDbPlaylist::GetPlaylistL(
       
   333     TUint32 aPlaylistId,
       
   334     const TArray<TMPXAttribute>& aAttrs,
       
   335     CMPXMedia& aMedia)
       
   336     {
       
   337     MPX_FUNC("CMPXDbPlaylist::GetPlaylistL");
       
   338     ExecuteMediaQueryL(aAttrs, aMedia, KQueryPlaylistGet, aPlaylistId);
       
   339     }
       
   340 
       
   341 // ----------------------------------------------------------------------------
       
   342 // CMPXDbPlaylist::GetAllPlaylistsL
       
   343 // ----------------------------------------------------------------------------
       
   344 //
       
   345 void CMPXDbPlaylist::GetAllPlaylistsL(
       
   346     const TArray<TMPXAttribute>& aAttrs,
       
   347     CMPXMediaArray& aMediaArray)
       
   348     {
       
   349     MPX_FUNC("CMPXDbPlaylist::GetAllPlaylistsL");
       
   350     ExecuteMediaQueryL(aAttrs, aMediaArray, KQueryPlaylistGetAll);
       
   351     }
       
   352 
       
   353 // ----------------------------------------------------------------------------
       
   354 // CMPXDbPlaylist::GetNameL
       
   355 // ----------------------------------------------------------------------------
       
   356 //
       
   357 HBufC* CMPXDbPlaylist::GetNameL(
       
   358     TUint32 aPlaylistId)
       
   359     {
       
   360     MPX_FUNC("CMPXDbPlaylist::GetNameL");
       
   361 
       
   362     RSqlStatement recordset(GetPlaylistRecordL(aPlaylistId));
       
   363     CleanupClosePushL(recordset);
       
   364 
       
   365     HBufC* name(NULL);
       
   366     TInt err(KErrNone);
       
   367     if ((err = recordset.Next()) == KSqlAtRow)
       
   368         {
       
   369         name = MPXDbCommonUtil::GetColumnTextL(recordset, EPlaylistName).AllocL();
       
   370         }
       
   371     CleanupStack::PopAndDestroy(&recordset);
       
   372 
       
   373     if (err != KSqlAtEnd)
       
   374         {
       
   375         User::LeaveIfError(err);
       
   376         }
       
   377 
       
   378     if (name == NULL)
       
   379         {
       
   380         User::LeaveIfError(KErrNotFound);
       
   381         }
       
   382     return name;
       
   383     }
       
   384 
       
   385 // ----------------------------------------------------------------------------
       
   386 // CMPXDbPlaylist::GetUriL
       
   387 // ----------------------------------------------------------------------------
       
   388 //
       
   389 HBufC* CMPXDbPlaylist::GetUriL(
       
   390     TUint32 aPlaylistId)
       
   391     {
       
   392     MPX_FUNC("CMPXDbPlaylist::GetUriL");
       
   393 
       
   394     RSqlStatement recordset(GetPlaylistRecordL(aPlaylistId));
       
   395     CleanupClosePushL(recordset);
       
   396 
       
   397     HBufC* uri(NULL);
       
   398     TInt err(KErrNone);
       
   399     if ((err = recordset.Next()) == KSqlAtRow)
       
   400         {
       
   401         uri = MPXDbCommonUtil::CreateFullPathL(
       
   402             MPXDbCommonUtil::GetDriveIdMatchVolIdL(iDbManager.Fs(),
       
   403             recordset.ColumnInt64(EPlaylistVolumeId)),
       
   404             MPXDbCommonUtil::GetColumnTextL(recordset, EPlaylistUri));
       
   405 
       
   406         }
       
   407     CleanupStack::PopAndDestroy(&recordset);
       
   408 
       
   409     if (err != KSqlAtEnd)
       
   410         {
       
   411         User::LeaveIfError(err);
       
   412         }
       
   413 
       
   414     if (uri == NULL)
       
   415         {
       
   416         User::LeaveIfError(KErrNotFound);
       
   417         }
       
   418 
       
   419     return uri;
       
   420     }
       
   421 
       
   422 // ----------------------------------------------------------------------------
       
   423 // CMPXDbPlaylist::GetIdL
       
   424 // ----------------------------------------------------------------------------
       
   425 //
       
   426 TUint32 CMPXDbPlaylist::GetIdL(
       
   427     const TDesC& aUri)
       
   428     {
       
   429     MPX_FUNC("CMPXDbPlaylist::GetIdL");
       
   430     HBufC* uri = MPXDbCommonUtil::ProcessPatternCharsLC( aUri );
       
   431     TUint32 ret = ExecuteIntQueryL(
       
   432         KQueryLikePlaylistId, uri->Mid( KMCPathStartPos ) );
       
   433 
       
   434    	CleanupStack::PopAndDestroy( uri );
       
   435 
       
   436     return ret;
       
   437     }
       
   438 
       
   439 // ----------------------------------------------------------------------------
       
   440 // CMPXDbPlaylist::FindAllL
       
   441 // ----------------------------------------------------------------------------
       
   442 //
       
   443 void CMPXDbPlaylist::FindAllL(
       
   444     const CMPXMedia& aCriteria,
       
   445     const TArray<TMPXAttribute>& aAttrs,
       
   446     CMPXMediaArray& aMediaArray)
       
   447     {
       
   448     MPX_FUNC("CMPXDbPlaylist::FindAllL");
       
   449 
       
   450     // process the requested attributes
       
   451     // the UniqueId is always requested
       
   452     TBool titleRequested(EFalse);
       
   453     TBool counterRequested(EFalse);
       
   454 
       
   455     TInt viewingColumnCount(aAttrs.Count());
       
   456     for (TInt i = 0; (i < viewingColumnCount) && !(titleRequested && counterRequested); ++i)
       
   457         {
       
   458         if (aAttrs[i].ContentId() == KMPXMediaIdGeneral)
       
   459             {
       
   460             TUint attributeId(aAttrs[i].AttributeId());
       
   461 
       
   462             if (attributeId & EMPXMediaGeneralTitle)
       
   463                 {
       
   464                 titleRequested = ETrue;
       
   465                 }
       
   466             if (attributeId & EMPXMediaGeneralCount)
       
   467                 {
       
   468                 counterRequested = ETrue;
       
   469                 }
       
   470             }
       
   471         }
       
   472 
       
   473     TMPXGeneralType type = aCriteria.ValueTObjectL<TMPXGeneralType>(KMPXMediaGeneralType);
       
   474 
       
   475     const TArray<TMPXAttribute> criteria = aCriteria.Attributes();
       
   476     TInt criteriaCount(criteria.Count());
       
   477 
       
   478     // process the criteria and construct the criteria string
       
   479     CDesCArrayFlat* criteriaArray = new (ELeave) CDesCArrayFlat(criteriaCount);
       
   480     CleanupStack::PushL(criteriaArray);
       
   481 
       
   482     TBool criteriaCounterSet(EFalse);
       
   483     TInt criteriaCounter(0);
       
   484 
       
   485     for (TInt i = 0; i < criteriaCount; ++i)
       
   486         {
       
   487         const TMPXAttribute& criterion = criteria[i];
       
   488         if (type == EMPXItem && criterion == KMPXMediaGeneralId)
       
   489             {
       
   490             TUint32 itemId((aCriteria.ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId)).iId2);
       
   491             if (MPX_ITEM_CATEGORY(itemId) != EMPXPlaylist)
       
   492                 {
       
   493                 User::Leave(KErrNotSupported);
       
   494                 }
       
   495 
       
   496             MPXDbCommonUtil::AddSqlCriterionL(*criteriaArray, KCriterionPlaylistUniqueId, itemId);
       
   497             }
       
   498         else if (criterion == KMPXMediaGeneralTitle)
       
   499             {
       
   500             HBufC* title = MPXDbCommonUtil::ProcessPatternCharsLC(
       
   501                 aCriteria.ValueText(KMPXMediaGeneralTitle));
       
   502             if( type == EMPXOtherType )
       
   503                 {
       
   504                 MPXDbCommonUtil::AddSqlCriterionL(*criteriaArray, KCriterionPlaylistTitle, *title);
       
   505                 }
       
   506             else
       
   507                 {
       
   508             MPXDbCommonUtil::AddSqlCriterionL(*criteriaArray, KCriterionPlaylistLikeTitle, *title);
       
   509                 }
       
   510             CleanupStack::PopAndDestroy(title);
       
   511             }
       
   512         else if (criterion == KMPXMediaGeneralUri)
       
   513             {
       
   514             MPXDbCommonUtil::AddSqlCriterionL(*criteriaArray, KCriterionPlaylistUniqueId,
       
   515                 MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), EMPXPlaylist,
       
   516                 aCriteria.ValueText(KMPXMediaGeneralUri), EFalse));
       
   517             }
       
   518         else if (criterion == KMPXMediaGeneralDrive)
       
   519             {
       
   520             const TDesC& drive(aCriteria.ValueText(KMPXMediaGeneralDrive));
       
   521             TDriveUnit driveUnit(drive);
       
   522             MPXDbCommonUtil::AddSqlCriterionL(*criteriaArray, KCriterionPlaylistVolumeId,
       
   523                 MPXDbCommonUtil::GetVolIdMatchDriveIdL(iDbManager.Fs(), driveUnit));
       
   524             }
       
   525         else if (criterion == KMPXMediaGeneralSynchronized)
       
   526             {
       
   527             MPXDbCommonUtil::AddSqlCriterionL(*criteriaArray, KCriterionPlaylistSync,
       
   528                 aCriteria.ValueTObjectL<TBool>(KMPXMediaGeneralSynchronized));
       
   529             }
       
   530         else if (criterion == KMPXMediaGeneralCount)
       
   531             {
       
   532             criteriaCounterSet = ETrue;
       
   533             criteriaCounter = aCriteria.ValueTObjectL<TInt>(KMPXMediaGeneralCount);
       
   534             }
       
   535         }
       
   536 
       
   537     // construct criteria string
       
   538     HBufC* criteriaStr = MPXDbCommonUtil::StringFromArrayLC(*criteriaArray, KMCAndKeyword);
       
   539 
       
   540     HBufC* query(NULL);
       
   541     if (criteriaStr->Length() > 0)
       
   542         {
       
   543         // construct and execute the query
       
   544         query = HBufC::NewLC(KQueryPlaylistItems().Length() + criteriaStr->Length());
       
   545         query->Des().Format(KQueryPlaylistItems, criteriaStr);
       
   546         }
       
   547     else
       
   548         {
       
   549         query = HBufC::NewLC(KQueryPlaylistGetAll().Length());
       
   550         query->Des().Format(KQueryPlaylistGetAll);
       
   551         }
       
   552 
       
   553     RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(*query));
       
   554 
       
   555     CleanupStack::PopAndDestroy(query);
       
   556     CleanupStack::PopAndDestroy(criteriaStr);
       
   557     CleanupStack::PopAndDestroy(criteriaArray);
       
   558 
       
   559     CleanupClosePushL(recordset);
       
   560 
       
   561     TInt err(KErrNone);
       
   562     while ((err = recordset.Next()) == KSqlAtRow)
       
   563         {
       
   564         // Setup basic info - with first record of a group
       
   565         TUint32 playlistId(recordset.ColumnInt64(EPlaylistUniqueId));
       
   566         TUint32 volId(recordset.ColumnInt64(EPlaylistVolumeId));
       
   567         TInt driveId = MPXDbCommonUtil::GetDriveIdMatchVolIdL(iDbManager.Fs(), volId);
       
   568 
       
   569         TBool valid(ETrue);
       
   570         TInt songCount(-1);
       
   571         if (criteriaCounterSet)
       
   572             {
       
   573             if (driveId >= 0)
       
   574                 {
       
   575                 //valid disk
       
   576                 songCount = iPlaylistSongs->CountL(playlistId, driveId);
       
   577                 }
       
   578             valid = (criteriaCounter == songCount);
       
   579             }
       
   580 
       
   581         if (valid)
       
   582             {
       
   583             // start a new media object
       
   584             CMPXMedia* media = CMPXMedia::NewL();
       
   585             CleanupStack::PushL(media);
       
   586 
       
   587             UpdateMediaL(recordset, aAttrs, *media);
       
   588 
       
   589             aMediaArray.AppendL(*media);
       
   590             CleanupStack::PopAndDestroy(media);
       
   591             }
       
   592         }
       
   593 
       
   594     CleanupStack::PopAndDestroy(&recordset);
       
   595 
       
   596     if (err != KSqlAtEnd)
       
   597         {
       
   598         User::LeaveIfError(err);
       
   599         }
       
   600     }
       
   601 
       
   602 // ----------------------------------------------------------------------------
       
   603 // CMPXDbPlaylist::GetDriveIdL
       
   604 // ----------------------------------------------------------------------------
       
   605 //
       
   606 TInt CMPXDbPlaylist::GetDriveIdL(
       
   607     TUint32 aPlaylistId)
       
   608     {
       
   609     MPX_FUNC("CMPXDbPlaylist::GetDriveIdL");
       
   610     return MPXDbCommonUtil::GetDriveIdMatchVolIdL(iDbManager.Fs(),
       
   611         ExecuteIntQueryL(KQueryPlaylistDriveId, aPlaylistId));
       
   612     }
       
   613 
       
   614 // ----------------------------------------------------------------------------
       
   615 // CMPXDbPlaylist::Songs
       
   616 // ----------------------------------------------------------------------------
       
   617 //
       
   618 CMPXDbPlaylistSongs& CMPXDbPlaylist::Songs()
       
   619     {
       
   620     return *iPlaylistSongs;
       
   621     }
       
   622 
       
   623 // ----------------------------------------------------------------------------
       
   624 // CMPXDbPlaylist::GetDrivePlaylistCount
       
   625 // ----------------------------------------------------------------------------
       
   626 //
       
   627 TUint CMPXDbPlaylist::GetDrivePlaylistCountL(TInt aDrive)
       
   628     {
       
   629     TUint count(0);
       
   630 
       
   631     RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(aDrive,KQueryPlaylistFileCount));
       
   632     CleanupClosePushL(recordset);
       
   633 
       
   634     if (recordset.Next() != KSqlAtRow)
       
   635         {
       
   636         User::Leave(KErrCorrupt);
       
   637         }
       
   638 
       
   639     count = TUint(recordset.ColumnInt64(KMPXTableDefaultIndex));
       
   640     CleanupStack::PopAndDestroy(&recordset);
       
   641 
       
   642     return count;
       
   643     }
       
   644 
       
   645 // ----------------------------------------------------------------------------
       
   646 // CMPXDbPlaylist::GetPlaylistUriArrayL
       
   647 // ----------------------------------------------------------------------------
       
   648 //
       
   649 void CMPXDbPlaylist::GetPlaylistUriArrayL(TInt aDrive, TInt aFromID, TInt aRecords,
       
   650                                           CDesCArray& aUriArr, TInt& aLastID)
       
   651     {
       
   652     MPX_FUNC("CMPXDbPlaylist::GetPlaylistUriArrayL");
       
   653 
       
   654     HBufC* query = NULL;
       
   655     if(aFromID == 0)
       
   656         {
       
   657         query = HBufC::NewLC(KQueryPlaylistGetFileUris().Length()
       
   658                             + KMCIntegerLen);
       
   659         query->Des().Format(KQueryPlaylistGetFileUris, aRecords);
       
   660         }
       
   661     else
       
   662         {
       
   663         query = HBufC::NewLC(KQueryPlaylistGetFileUrisFrom().Length()
       
   664                             + 2*KMCIntegerLen);
       
   665         query->Des().Format(KQueryPlaylistGetFileUrisFrom, aFromID, aRecords);
       
   666         }
       
   667 
       
   668     RSqlStatement playlist_rs(iDbManager.ExecuteSelectQueryL(aDrive,*query));
       
   669 
       
   670     CleanupStack::PopAndDestroy(query);
       
   671 
       
   672     CleanupClosePushL(playlist_rs);
       
   673 
       
   674     TInt lastID = 0;
       
   675     TInt err(KErrNone);
       
   676     while((err = playlist_rs.Next()) == KSqlAtRow)
       
   677         {
       
   678         HBufC* fullPath = MPXDbCommonUtil::CreateFullPathL(aDrive,
       
   679                 MPXDbCommonUtil::GetColumnTextL(playlist_rs, KColUri));
       
   680         CleanupStack::PushL(fullPath);
       
   681         aUriArr.AppendL(*fullPath);
       
   682         CleanupStack::PopAndDestroy(fullPath);
       
   683 
       
   684         lastID = playlist_rs.ColumnInt(KColUniqueID);
       
   685         }
       
   686     CleanupStack::PopAndDestroy(&playlist_rs);
       
   687 
       
   688     aLastID = lastID;
       
   689 
       
   690     if (err!= KSqlAtEnd)
       
   691         {
       
   692         User::Leave(KErrCorrupt);
       
   693         }
       
   694     }
       
   695 
       
   696 // ----------------------------------------------------------------------------
       
   697 // CMPXDbPlaylist::UpdateMediaL
       
   698 // ----------------------------------------------------------------------------
       
   699 //
       
   700 void CMPXDbPlaylist::UpdateMediaL(
       
   701     RSqlStatement& aRecord,
       
   702     const TArray<TMPXAttribute>& aAttrs,
       
   703     CMPXMedia& aMedia)
       
   704     {
       
   705     MPX_FUNC("CMPXDbPlaylist::UpdateMediaL");
       
   706 
       
   707     TBool countRequested(EFalse);
       
   708 	TBool durationRequested(EFalse);
       
   709     TUint32 playlistId(aRecord.ColumnInt64(EPlaylistUniqueId));
       
   710 
       
   711     TInt count(aAttrs.Count());
       
   712     TUint32 volId(aRecord.ColumnInt64(EPlaylistVolumeId));
       
   713     TInt driveId = MPXDbCommonUtil::GetDriveIdMatchVolIdL(iDbManager.Fs(), volId);
       
   714     for (TInt i = 0; i < count; ++i)
       
   715         {
       
   716         TInt contentId(aAttrs[i].ContentId());
       
   717         TUint attributeId(aAttrs[i].AttributeId());
       
   718 
       
   719         if (contentId == KMPXMediaIdGeneral)
       
   720             {
       
   721             if (attributeId & EMPXMediaGeneralId)
       
   722                 {
       
   723                 aMedia.SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, playlistId);
       
   724                 MPX_DEBUG2("    Playlist ID[%u]", playlistId);
       
   725                 }
       
   726             if (attributeId & EMPXMediaGeneralCollectionId)
       
   727                 {
       
   728                 aMedia.SetTObjectValueL<TUid>(KMPXMediaGeneralCollectionId,
       
   729                     TUid::Uid(KDBPluginUid));
       
   730                 }
       
   731             if (attributeId & EMPXMediaGeneralTitle)
       
   732                 {
       
   733                 TPtrC title(MPXDbCommonUtil::GetColumnTextL(aRecord, EPlaylistName));
       
   734                 aMedia.SetTextValueL(KMPXMediaGeneralTitle, title);
       
   735                 MPX_DEBUG2("    Title[%S]", &title);
       
   736                 }
       
   737             if ((attributeId & EMPXMediaGeneralUri) ||
       
   738                 (attributeId & EMPXMediaGeneralDrive) ||
       
   739                 (attributeId & EMPXMediaGeneralFlags))
       
   740                 {
       
   741 
       
   742                 // LTAN-7GH6BZ, crash if eject memory card when adding song to existing playlist
       
   743                 // due to special timing issue, it is possible drive number is -1 and create a
       
   744                 // panic when use for TDriveUnit
       
   745                 MPX_DEBUG3("volId = %d, driveId = %d", volId, driveId);
       
   746 
       
   747                 // handle possibly delay from framework notification
       
   748                 if (driveId < 0)
       
   749                     {
       
   750                     MPX_DEBUG1("invalid driveId, leave with KErrNotReady");
       
   751                     User::Leave(KErrNotReady);
       
   752                     }
       
   753 
       
   754                 TDriveUnit driveUnit(driveId);
       
   755 
       
   756                 if (attributeId & EMPXMediaGeneralUri)
       
   757                     {
       
   758                     HBufC* fullPath = MPXDbCommonUtil::CreateFullPathL(driveUnit,
       
   759                         MPXDbCommonUtil::GetColumnTextL(aRecord, EPlaylistUri));
       
   760                     CleanupStack::PushL(fullPath);
       
   761                     aMedia.SetTextValueL(KMPXMediaGeneralUri, *fullPath);
       
   762                     MPX_DEBUG2("    URI[%S]", fullPath);
       
   763                     CleanupStack::PopAndDestroy(fullPath);
       
   764                     }
       
   765                 if (attributeId & EMPXMediaGeneralDrive)
       
   766                     {
       
   767                     aMedia.SetTextValueL(KMPXMediaGeneralDrive, driveUnit.Name());
       
   768                     }
       
   769                 if (attributeId & EMPXMediaGeneralFlags)
       
   770                     {
       
   771                     TUint32 dbFlags(aRecord.ColumnInt64(EPlaylistDbFlag));
       
   772                     TInt driveId = driveUnit & KMPXMediaGeneralFlagsDriveInfo;  // 5 bits
       
   773                     aMedia.SetTObjectValueL<TUint>(KMPXMediaGeneralFlags, dbFlags | driveId);
       
   774                     }
       
   775                 }
       
   776             if (attributeId & EMPXMediaGeneralSynchronized)
       
   777                 {
       
   778                 aMedia.SetTObjectValueL<TBool>(KMPXMediaGeneralSynchronized,
       
   779                     aRecord.ColumnInt(EPlaylistSync));
       
   780                 }
       
   781             if (attributeId & EMPXMediaGeneralCount)
       
   782                 {
       
   783                 // make sure the PlaylistSongs query is executed after all fields
       
   784                 // from the current record have been processed, otherwise the recordset
       
   785                 // may point to something else
       
   786                 countRequested = ETrue;
       
   787                 }
       
   788             if (attributeId & EMPXMediaGeneralDate)
       
   789                 {
       
   790                 // convert the time from the internal DB string format
       
   791                 // to the int64 format used by TTime
       
   792                 aMedia.SetTObjectValueL<TInt64>(KMPXMediaGeneralDate,
       
   793                     MPXDbCommonUtil::DesToTTimeL(
       
   794                     MPXDbCommonUtil::GetColumnTextL(aRecord, EPlaylistTime)).Int64());
       
   795                 }
       
   796 			if ( attributeId & EMPXMediaGeneralDuration )
       
   797 				{
       
   798 				// make sure the PlaylistSongs query is executed after all fields
       
   799 				// from the current record have been processed, otherwise the recordset
       
   800 				// may point to something else
       
   801 
       
   802 				durationRequested = ETrue;
       
   803 				}
       
   804             } // end if contentId == KMPXMediaIdGeneral
       
   805         } // end for
       
   806 
       
   807     TInt plSongCount(0);
       
   808     TInt plSongDuration(0);
       
   809     if (countRequested)
       
   810         {
       
   811         if (driveId >= 0)
       
   812             {
       
   813             //valid disk
       
   814             iObserver.HandlePlaylistInfoL(playlistId, plSongCount, plSongDuration);
       
   815             }
       
   816         aMedia.SetTObjectValueL<TInt>(KMPXMediaGeneralCount,
       
   817         		plSongCount );
       
   818         
       
   819         MPX_DEBUG1("    EMPXMediaGeneralCount");
       
   820 		MPX_DEBUG2("	Count[%d]", plSongCount);				
       
   821         }
       
   822 	if (durationRequested)
       
   823 		{
       
   824         aMedia.SetTObjectValueL<TInt>(KMPXMediaGeneralDuration, plSongDuration);
       
   825 		
       
   826         MPX_DEBUG1("    EMPXMediaGeneralDuration");
       
   827         MPX_DEBUG2("	Duration[%d]", plSongDuration);				
       
   828 		}
       
   829 
       
   830     aMedia.SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXItem);
       
   831     aMedia.SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXPlaylist);
       
   832     }
       
   833 
       
   834 // ----------------------------------------------------------------------------
       
   835 // CMPXDbPlaylist::GetPlaylistRecordL
       
   836 // ----------------------------------------------------------------------------
       
   837 //
       
   838 RSqlStatement CMPXDbPlaylist::GetPlaylistRecordL(
       
   839     TUint32 aPlaylistId)
       
   840     {
       
   841     MPX_FUNC("CMPXDbPlaylist::GetPlaylistRecordL");
       
   842     return iDbManager.ExecuteSelectQueryL(KQueryPlaylistGet, aPlaylistId);
       
   843     }
       
   844 
       
   845 // ----------------------------------------------------------------------------
       
   846 // CMPXDbPlaylist::DoAddPlaylistL
       
   847 // ----------------------------------------------------------------------------
       
   848 //
       
   849 TUint32 CMPXDbPlaylist::DoAddPlaylistL(
       
   850     const CMPXMedia& aMedia,
       
   851     TInt aDriveId)
       
   852     {
       
   853     MPX_FUNC("CMPXDbPlaylist::DoAddPlaylistL");
       
   854 
       
   855     const TDesC& playlistName(aMedia.ValueText(KMPXMediaGeneralTitle));
       
   856     const TDesC& playlistUri(aMedia.ValueText(KMPXMediaGeneralUri));
       
   857 
       
   858     TUint32 playlistId(MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), EMPXPlaylist, playlistUri, EFalse));
       
   859     const CMPXMediaArray* mediaArray = aMedia.Value<CMPXMediaArray>(KMPXMediaArrayContents);
       
   860     if( !mediaArray )
       
   861         {
       
   862         User::Leave( KErrNoMemory );
       
   863         }
       
   864     // add the songs to the PlaylistSongs table
       
   865     TInt count(mediaArray->Count());
       
   866     for (TInt i = 0; i < count; ++i)
       
   867         {
       
   868         iPlaylistSongs->AddSongL(playlistId, i, *mediaArray->AtL(i), aDriveId);
       
   869         }
       
   870 
       
   871     // determine the value of DbFlag
       
   872     TUint dbflags(0);
       
   873     if (aMedia.IsSupported(KMPXMediaGeneralFlags))
       
   874         {
       
   875         TUint flag(aMedia.ValueTObjectL<TUint>(KMPXMediaGeneralFlags));
       
   876         if (flag & KMPXMediaGeneralFlagsSetOrUnsetBit )
       
   877             {
       
   878             // Set flag
       
   879             dbflags |= flag;
       
   880             MPX_DEBUG2("    GeneralFlags[%b]", dbflags);
       
   881             }
       
   882         }
       
   883 
       
   884     // add playlist record
       
   885     HBufC* time = MPXDbCommonUtil::CurrentTimeDesLC();
       
   886     HBufC* name = MPXDbCommonUtil::ProcessSingleQuotesLC(playlistName);
       
   887     HBufC* uri = MPXDbCommonUtil::ProcessSingleQuotesLC(playlistUri);
       
   888     TPtrC uriPtr(uri->Mid(KMCPathStartPos));
       
   889     TPtrC namePtr(name->Left(KMCMaxTextLen));
       
   890 
       
   891     iDbManager.ExecuteQueryL(aDriveId, KQueryPlaylistInsert, playlistId, &namePtr,
       
   892         &uriPtr, MPXDbCommonUtil::GetVolIdMatchDriveIdL(iDbManager.Fs(), aDriveId),
       
   893         dbflags, time);
       
   894 
       
   895     CleanupStack::PopAndDestroy(uri);
       
   896     CleanupStack::PopAndDestroy(name);
       
   897     CleanupStack::PopAndDestroy(time);
       
   898 
       
   899     return playlistId;
       
   900     }
       
   901 
       
   902 // ----------------------------------------------------------------------------
       
   903 // CMPXDbPlaylist::DoUpdatePlaylistL
       
   904 // ----------------------------------------------------------------------------
       
   905 //
       
   906 void CMPXDbPlaylist::DoUpdatePlaylistL(
       
   907     TUint32 aPlaylistId,
       
   908     const CMPXMedia& aMedia,
       
   909     TInt aDriveId,
       
   910     CMPXMessage& aMessage)
       
   911     {
       
   912     MPX_FUNC("CMPXDbPlaylist::DoUpdatePlaylistL");
       
   913 
       
   914     // construct the criteria array
       
   915     const TArray<TMPXAttribute> attributes = aMedia.Attributes();
       
   916 
       
   917     CDesCArrayFlat* criteriaArray = new (ELeave) CDesCArrayFlat(attributes.Count());
       
   918     CleanupStack::PushL(criteriaArray);
       
   919 
       
   920     TInt attrCount(attributes.Count());
       
   921     for (TInt index = 0; index < attrCount; ++index)
       
   922         {
       
   923         TInt contentId(attributes[index].ContentId());
       
   924         TUint attributeId(attributes[index].AttributeId());
       
   925 
       
   926         switch(contentId)
       
   927             {
       
   928             case KMPXMediaIdGeneral:
       
   929                 {
       
   930                 if (attributeId & EMPXMediaGeneralTitle)
       
   931                     {
       
   932                     MPXDbCommonUtil::AddSqlCriterionL(*criteriaArray, KCriterionPlaylistTitle,
       
   933                         aMedia.ValueText(KMPXMediaGeneralTitle));
       
   934                     }
       
   935                 if (attributeId & EMPXMediaGeneralUri)
       
   936                     {
       
   937                     const TDesC& uri(aMedia.ValueText (KMPXMediaGeneralUri));
       
   938 
       
   939                     // determine if we are changing URI of an existing playlist.
       
   940                     // if so, update playlist URI + its Id
       
   941                     TUint32 newId(MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), EMPXPlaylist, uri, EFalse));
       
   942 
       
   943                     if (aPlaylistId != newId)
       
   944                         {
       
   945                         aMessage.SetTObjectValueL<TMPXItemId>(KMPXMessageMediaGeneralId, newId);
       
   946                         aMessage.SetTObjectValueL<TMPXItemId>(KMPXMessageMediaDeprecatedId, aPlaylistId);
       
   947 
       
   948                         // Change event handling for renaming a playlist should be like a song
       
   949                         // The item focus should goto the new name of the playlist
       
   950                         // to-do: this should be abstracted from the plugin. framework should
       
   951                         //        have enough info to deal with this scenario, if not, add more
       
   952                         //        info in the message passing back to framework
       
   953                         aMessage.SetTObjectValueL<TMPXGeneralCategory>(KMPXMessageMediaGeneralCategory,
       
   954                             EMPXSong);
       
   955 
       
   956                         // update the PlaylistSongs to reflect playlist id change
       
   957                         iPlaylistSongs->UpdateSongsL(aPlaylistId, newId);
       
   958 
       
   959                         // this takes care of processing the single quotes in the URI
       
   960                         MPXDbCommonUtil::AddSqlCriterionL(*criteriaArray, KCriterionPlaylistUri,
       
   961                             uri.Mid(KMCPathStartPos));
       
   962                         MPXDbCommonUtil::AddSqlCriterionL(*criteriaArray, KCriterionPlaylistVolumeId,
       
   963                             MPXDbCommonUtil::GetVolIdMatchDriveIdL(iDbManager.Fs(), TDriveUnit(uri)));
       
   964                         MPXDbCommonUtil::AddSqlCriterionL(*criteriaArray, KCriterionPlaylistUniqueId,
       
   965                             newId);
       
   966                         }
       
   967                     }
       
   968                 if (attributeId & EMPXMediaGeneralSynchronized)
       
   969                     {
       
   970                     MPXDbCommonUtil::AddSqlCriterionL(*criteriaArray, KCriterionPlaylistSync,
       
   971                         aMedia.ValueTObjectL<TBool>(KMPXMediaGeneralSynchronized));
       
   972                     }
       
   973                 }
       
   974                 break;
       
   975 
       
   976             default:
       
   977                 break;
       
   978 
       
   979             } // end switch
       
   980         } // end for
       
   981 
       
   982     // update the time field to the current time
       
   983     HBufC* time = MPXDbCommonUtil::CurrentTimeDesLC();
       
   984     MPXDbCommonUtil::AddSqlCriterionL(*criteriaArray, KCriterionPlaylistTime, *time);
       
   985     CleanupStack::PopAndDestroy(time);
       
   986 
       
   987     // construct a string from all criteria
       
   988     HBufC* criteria = MPXDbCommonUtil::StringFromArrayLC(*criteriaArray, KMCCommaSign);
       
   989 
       
   990     // execute the query
       
   991     iDbManager.ExecuteQueryL(aDriveId, KQueryPlaylistUpdate, criteria, aPlaylistId);
       
   992 
       
   993     CleanupStack::PopAndDestroy(criteria);
       
   994     CleanupStack::PopAndDestroy(criteriaArray);
       
   995     }
       
   996 
       
   997 // ----------------------------------------------------------------------------
       
   998 // CMPXDbPlaylist::UpdatePlaylistsForSongL
       
   999 // ----------------------------------------------------------------------------
       
  1000 //
       
  1001 void CMPXDbPlaylist::UpdatePlaylistsForSongL(
       
  1002     TUint32 aSongId,
       
  1003     CMPXMessageArray* aItemChangedMessages, TBool& aSongInPlaylists)
       
  1004     {
       
  1005     MPX_FUNC("CMPXDbPlaylist::UpdatePlaylistsForSongL");
       
  1006 
       
  1007     aSongInPlaylists = EFalse;
       
  1008     if (aItemChangedMessages)
       
  1009         {
       
  1010         // get all playlists for the song
       
  1011         RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(KQueryPlaylistGetForSong, aSongId));
       
  1012         CleanupClosePushL(recordset);
       
  1013 
       
  1014         // ignore the errors
       
  1015         while (recordset.Next() == KSqlAtRow)
       
  1016             {
       
  1017             aSongInPlaylists = ETrue;
       
  1018             // add item changed messages for all of them
       
  1019             MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages,
       
  1020                 recordset.ColumnInt64(KMPXTableDefaultIndex), EMPXItemModified,
       
  1021                 EMPXPlaylist, KDBPluginUid);
       
  1022             }
       
  1023 
       
  1024         CleanupStack::PopAndDestroy(&recordset);
       
  1025         }
       
  1026     if (aSongInPlaylists)
       
  1027         {
       
  1028         // update the time for all playlists that contain this song
       
  1029         HBufC* time = MPXDbCommonUtil::CurrentTimeDesLC();
       
  1030         iDbManager.ExecuteQueryL (KDbManagerAllDrives,
       
  1031                 KQueryPlaylistUpdateTimeForSong, time, aSongId);
       
  1032         CleanupStack::PopAndDestroy (time);
       
  1033         }
       
  1034     }
       
  1035 
       
  1036 // ----------------------------------------------------------------------------
       
  1037 // CMPXDbPlaylist::CreateTableL
       
  1038 // ----------------------------------------------------------------------------
       
  1039 //
       
  1040 void CMPXDbPlaylist::UpdatePlaylistTimeL(
       
  1041     TUint32 aPlaylistId,
       
  1042     TInt aDrive)
       
  1043     {
       
  1044     MPX_FUNC("CMPXDbPlaylist::UpdatePlaylistTimeL");
       
  1045 
       
  1046     HBufC* time = MPXDbCommonUtil::CurrentTimeDesLC();
       
  1047     iDbManager.ExecuteQueryL(aDrive, KQueryPlaylistUpdateTime, time, aPlaylistId);
       
  1048     CleanupStack::PopAndDestroy(time);
       
  1049     }
       
  1050 
       
  1051 // ----------------------------------------------------------------------------
       
  1052 // CMPXDbPlaylist::GetDrivePlaylistDuration
       
  1053 // ----------------------------------------------------------------------------
       
  1054 //
       
  1055 TInt CMPXDbPlaylist::GetDrivePlaylistDuration(TUint32 /*aPlaylistId*/)
       
  1056     {
       
  1057     return 0;
       
  1058     }
       
  1059 // ----------------------------------------------------------------------------
       
  1060 // CMPXDbPlaylist::CreateTableL
       
  1061 // ----------------------------------------------------------------------------
       
  1062 //
       
  1063 void CMPXDbPlaylist::CreateTableL(
       
  1064     RSqlDatabase& aDatabase,
       
  1065     TBool /* aCorruptTable */)
       
  1066     {
       
  1067     MPX_FUNC("CMPXDbPlaylist::CreateTableL");
       
  1068 
       
  1069     // create the table
       
  1070     User::LeaveIfError(aDatabase.Exec(KPlaylistCreateTable));
       
  1071 
       
  1072     // create the index on the Name field
       
  1073     User::LeaveIfError(aDatabase.Exec(KPlaylistNameIndex));
       
  1074     }
       
  1075 
       
  1076 // ----------------------------------------------------------------------------
       
  1077 // CMPXDbPlaylist::DropTableL
       
  1078 // ----------------------------------------------------------------------------
       
  1079 //
       
  1080 void CMPXDbPlaylist::DropTableL(
       
  1081     RSqlDatabase& aDatabase)
       
  1082     {
       
  1083     MPX_FUNC("CMPXDbPlaylist::DropTableL");
       
  1084     User::LeaveIfError(aDatabase.Exec(KPlaylistDropTable));
       
  1085     }
       
  1086 
       
  1087 // ----------------------------------------------------------------------------
       
  1088 // CMPXDbPlaylist::CheckTableL
       
  1089 // ----------------------------------------------------------------------------
       
  1090 //
       
  1091 TBool CMPXDbPlaylist::CheckTableL(
       
  1092     RSqlDatabase& aDatabase)
       
  1093     {
       
  1094     MPX_FUNC("CMPXDbPlaylist::CheckTableL");
       
  1095     return DoCheckTable(aDatabase, KPlaylistCheckTable);
       
  1096     }
       
  1097 
       
  1098 // End of File