mpxplugins/serviceplugins/collectionplugins/mpxsqlitedbplugin/src/mpxdbplaylist.cpp
changeset 0 ff3acec5bc43
child 11 13afc0e517bd
equal deleted inserted replaced
-1:000000000000 0:ff3acec5bc43
       
     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 
       
   567         TBool valid(ETrue);
       
   568         TInt songCount(-1);
       
   569         if (criteriaCounterSet)
       
   570             {
       
   571             songCount = iPlaylistSongs->CountL(playlistId);
       
   572             valid = (criteriaCounter == songCount);
       
   573             }
       
   574 
       
   575         if (valid)
       
   576             {
       
   577             // start a new media object
       
   578             CMPXMedia* media = CMPXMedia::NewL();
       
   579             CleanupStack::PushL(media);
       
   580 
       
   581             UpdateMediaL(recordset, aAttrs, *media);
       
   582 
       
   583             aMediaArray.AppendL(*media);
       
   584             CleanupStack::PopAndDestroy(media);
       
   585             }
       
   586         }
       
   587 
       
   588     CleanupStack::PopAndDestroy(&recordset);
       
   589 
       
   590     if (err != KSqlAtEnd)
       
   591         {
       
   592         User::LeaveIfError(err);
       
   593         }
       
   594     }
       
   595 
       
   596 // ----------------------------------------------------------------------------
       
   597 // CMPXDbPlaylist::GetDriveIdL
       
   598 // ----------------------------------------------------------------------------
       
   599 //
       
   600 TInt CMPXDbPlaylist::GetDriveIdL(
       
   601     TUint32 aPlaylistId)
       
   602     {
       
   603     MPX_FUNC("CMPXDbPlaylist::GetDriveIdL");
       
   604     return MPXDbCommonUtil::GetDriveIdMatchVolIdL(iDbManager.Fs(),
       
   605         ExecuteIntQueryL(KQueryPlaylistDriveId, aPlaylistId));
       
   606     }
       
   607 
       
   608 // ----------------------------------------------------------------------------
       
   609 // CMPXDbPlaylist::Songs
       
   610 // ----------------------------------------------------------------------------
       
   611 //
       
   612 CMPXDbPlaylistSongs& CMPXDbPlaylist::Songs()
       
   613     {
       
   614     return *iPlaylistSongs;
       
   615     }
       
   616 
       
   617 // ----------------------------------------------------------------------------
       
   618 // CMPXDbPlaylist::GetDrivePlaylistCount
       
   619 // ----------------------------------------------------------------------------
       
   620 //
       
   621 TUint CMPXDbPlaylist::GetDrivePlaylistCountL(TInt aDrive)
       
   622     {
       
   623     TUint count(0);
       
   624 
       
   625     RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(aDrive,KQueryPlaylistFileCount));
       
   626     CleanupClosePushL(recordset);
       
   627 
       
   628     if (recordset.Next() != KSqlAtRow)
       
   629         {
       
   630         User::Leave(KErrCorrupt);
       
   631         }
       
   632 
       
   633     count = TUint(recordset.ColumnInt64(KMPXTableDefaultIndex));
       
   634     CleanupStack::PopAndDestroy(&recordset);
       
   635 
       
   636     return count;
       
   637     }
       
   638 
       
   639 // ----------------------------------------------------------------------------
       
   640 // CMPXDbPlaylist::GetPlaylistUriArrayL
       
   641 // ----------------------------------------------------------------------------
       
   642 //
       
   643 void CMPXDbPlaylist::GetPlaylistUriArrayL(TInt aDrive, TInt aFromID, TInt aRecords,
       
   644                                           CDesCArray& aUriArr, TInt& aLastID)
       
   645     {
       
   646     MPX_FUNC("CMPXDbPlaylist::GetPlaylistUriArrayL");
       
   647 
       
   648     HBufC* query = NULL;
       
   649     if(aFromID == 0)
       
   650         {
       
   651         query = HBufC::NewLC(KQueryPlaylistGetFileUris().Length()
       
   652                             + KMCIntegerLen);
       
   653         query->Des().Format(KQueryPlaylistGetFileUris, aRecords);
       
   654         }
       
   655     else
       
   656         {
       
   657         query = HBufC::NewLC(KQueryPlaylistGetFileUrisFrom().Length()
       
   658                             + 2*KMCIntegerLen);
       
   659         query->Des().Format(KQueryPlaylistGetFileUrisFrom, aFromID, aRecords);
       
   660         }
       
   661 
       
   662     RSqlStatement playlist_rs(iDbManager.ExecuteSelectQueryL(aDrive,*query));
       
   663 
       
   664     CleanupStack::PopAndDestroy(query);
       
   665 
       
   666     CleanupClosePushL(playlist_rs);
       
   667 
       
   668     TInt lastID = 0;
       
   669     TInt err(KErrNone);
       
   670     while((err = playlist_rs.Next()) == KSqlAtRow)
       
   671         {
       
   672         HBufC* fullPath = MPXDbCommonUtil::CreateFullPathL(aDrive,
       
   673                 MPXDbCommonUtil::GetColumnTextL(playlist_rs, KColUri));
       
   674         CleanupStack::PushL(fullPath);
       
   675         aUriArr.AppendL(*fullPath);
       
   676         CleanupStack::PopAndDestroy(fullPath);
       
   677 
       
   678         lastID = playlist_rs.ColumnInt(KColUniqueID);
       
   679         }
       
   680     CleanupStack::PopAndDestroy(&playlist_rs);
       
   681 
       
   682     aLastID = lastID;
       
   683 
       
   684     if (err!= KSqlAtEnd)
       
   685         {
       
   686         User::Leave(KErrCorrupt);
       
   687         }
       
   688     }
       
   689 
       
   690 // ----------------------------------------------------------------------------
       
   691 // CMPXDbPlaylist::UpdateMediaL
       
   692 // ----------------------------------------------------------------------------
       
   693 //
       
   694 void CMPXDbPlaylist::UpdateMediaL(
       
   695     RSqlStatement& aRecord,
       
   696     const TArray<TMPXAttribute>& aAttrs,
       
   697     CMPXMedia& aMedia)
       
   698     {
       
   699     MPX_FUNC("CMPXDbPlaylist::UpdateMediaL");
       
   700 
       
   701     TBool countRequested(EFalse);
       
   702 	TBool durationRequested(EFalse);
       
   703     TUint32 playlistId(aRecord.ColumnInt64(EPlaylistUniqueId));
       
   704 
       
   705     TInt count(aAttrs.Count());
       
   706     for (TInt i = 0; i < count; ++i)
       
   707         {
       
   708         TInt contentId(aAttrs[i].ContentId());
       
   709         TUint attributeId(aAttrs[i].AttributeId());
       
   710 
       
   711         if (contentId == KMPXMediaIdGeneral)
       
   712             {
       
   713             if (attributeId & EMPXMediaGeneralId)
       
   714                 {
       
   715                 aMedia.SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, playlistId);
       
   716                 MPX_DEBUG2("    Playlist ID[%u]", playlistId);
       
   717                 }
       
   718             if (attributeId & EMPXMediaGeneralCollectionId)
       
   719                 {
       
   720                 aMedia.SetTObjectValueL<TUid>(KMPXMediaGeneralCollectionId,
       
   721                     TUid::Uid(KDBPluginUid));
       
   722                 }
       
   723             if (attributeId & EMPXMediaGeneralTitle)
       
   724                 {
       
   725                 TPtrC title(MPXDbCommonUtil::GetColumnTextL(aRecord, EPlaylistName));
       
   726                 aMedia.SetTextValueL(KMPXMediaGeneralTitle, title);
       
   727                 MPX_DEBUG2("    Title[%S]", &title);
       
   728                 }
       
   729             if ((attributeId & EMPXMediaGeneralUri) ||
       
   730                 (attributeId & EMPXMediaGeneralDrive) ||
       
   731                 (attributeId & EMPXMediaGeneralFlags))
       
   732                 {
       
   733                 TUint32 volId(aRecord.ColumnInt64(EPlaylistVolumeId));
       
   734                 TInt driveId = MPXDbCommonUtil::GetDriveIdMatchVolIdL(iDbManager.Fs(), volId);
       
   735 
       
   736                 // LTAN-7GH6BZ, crash if eject memory card when adding song to existing playlist
       
   737                 // due to special timing issue, it is possible drive number is -1 and create a
       
   738                 // panic when use for TDriveUnit
       
   739                 MPX_DEBUG3("volId = %d, driveId = %d", volId, driveId);
       
   740 
       
   741                 // handle possibly delay from framework notification
       
   742                 if (driveId < 0)
       
   743                     {
       
   744                     MPX_DEBUG1("invalid driveId, leave with KErrNotReady");
       
   745                     User::Leave(KErrNotReady);
       
   746                     }
       
   747 
       
   748                 TDriveUnit driveUnit(driveId);
       
   749 
       
   750                 if (attributeId & EMPXMediaGeneralUri)
       
   751                     {
       
   752                     HBufC* fullPath = MPXDbCommonUtil::CreateFullPathL(driveUnit,
       
   753                         MPXDbCommonUtil::GetColumnTextL(aRecord, EPlaylistUri));
       
   754                     CleanupStack::PushL(fullPath);
       
   755                     aMedia.SetTextValueL(KMPXMediaGeneralUri, *fullPath);
       
   756                     MPX_DEBUG2("    URI[%S]", fullPath);
       
   757                     CleanupStack::PopAndDestroy(fullPath);
       
   758                     }
       
   759                 if (attributeId & EMPXMediaGeneralDrive)
       
   760                     {
       
   761                     aMedia.SetTextValueL(KMPXMediaGeneralDrive, driveUnit.Name());
       
   762                     }
       
   763                 if (attributeId & EMPXMediaGeneralFlags)
       
   764                     {
       
   765                     TUint32 dbFlags(aRecord.ColumnInt64(EPlaylistDbFlag));
       
   766                     TInt driveId = driveUnit & KMPXMediaGeneralFlagsDriveInfo;  // 5 bits
       
   767                     aMedia.SetTObjectValueL<TUint>(KMPXMediaGeneralFlags, dbFlags | driveId);
       
   768                     }
       
   769                 }
       
   770             if (attributeId & EMPXMediaGeneralSynchronized)
       
   771                 {
       
   772                 aMedia.SetTObjectValueL<TBool>(KMPXMediaGeneralSynchronized,
       
   773                     aRecord.ColumnInt(EPlaylistSync));
       
   774                 }
       
   775             if (attributeId & EMPXMediaGeneralCount)
       
   776                 {
       
   777                 // make sure the PlaylistSongs query is executed after all fields
       
   778                 // from the current record have been processed, otherwise the recordset
       
   779                 // may point to something else
       
   780                 countRequested = ETrue;
       
   781                 }
       
   782             if (attributeId & EMPXMediaGeneralDate)
       
   783                 {
       
   784                 // convert the time from the internal DB string format
       
   785                 // to the int64 format used by TTime
       
   786                 aMedia.SetTObjectValueL<TInt64>(KMPXMediaGeneralDate,
       
   787                     MPXDbCommonUtil::DesToTTimeL(
       
   788                     MPXDbCommonUtil::GetColumnTextL(aRecord, EPlaylistTime)).Int64());
       
   789                 }
       
   790 			if ( attributeId & EMPXMediaGeneralDuration )
       
   791 				{		        
       
   792 				// make sure the PlaylistSongs query is executed after all fields
       
   793 				// from the current record have been processed, otherwise the recordset
       
   794 				// may point to something else				
       
   795 
       
   796 				durationRequested = ETrue;
       
   797 				}
       
   798             } // end if contentId == KMPXMediaIdGeneral
       
   799         } // end for
       
   800 
       
   801     if (countRequested)
       
   802         {
       
   803 		TInt count = iPlaylistSongs->CountL(playlistId);
       
   804         aMedia.SetTObjectValueL<TInt>(KMPXMediaGeneralCount,
       
   805             count );
       
   806         
       
   807         MPX_DEBUG1("    EMPXMediaGeneralCount");
       
   808 		MPX_DEBUG2("	Count[%d]", count);				
       
   809         }
       
   810 	if (durationRequested)
       
   811 		{
       
   812 		TInt duration = iObserver.HandlePlaylistDurationL(playlistId);		
       
   813 		aMedia.SetTObjectValueL<TInt>(KMPXMediaGeneralDuration, duration);
       
   814 		
       
   815 		MPX_DEBUG1("    EMPXMediaGeneralDuration");
       
   816 		MPX_DEBUG2("	Duration[%d]", duration);				
       
   817 		}
       
   818 
       
   819     aMedia.SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXItem);
       
   820     aMedia.SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXPlaylist);
       
   821     }
       
   822 
       
   823 // ----------------------------------------------------------------------------
       
   824 // CMPXDbPlaylist::GetPlaylistRecordL
       
   825 // ----------------------------------------------------------------------------
       
   826 //
       
   827 RSqlStatement CMPXDbPlaylist::GetPlaylistRecordL(
       
   828     TUint32 aPlaylistId)
       
   829     {
       
   830     MPX_FUNC("CMPXDbPlaylist::GetPlaylistRecordL");
       
   831     return iDbManager.ExecuteSelectQueryL(KQueryPlaylistGet, aPlaylistId);
       
   832     }
       
   833 
       
   834 // ----------------------------------------------------------------------------
       
   835 // CMPXDbPlaylist::DoAddPlaylistL
       
   836 // ----------------------------------------------------------------------------
       
   837 //
       
   838 TUint32 CMPXDbPlaylist::DoAddPlaylistL(
       
   839     const CMPXMedia& aMedia,
       
   840     TInt aDriveId)
       
   841     {
       
   842     MPX_FUNC("CMPXDbPlaylist::DoAddPlaylistL");
       
   843 
       
   844     const TDesC& playlistName(aMedia.ValueText(KMPXMediaGeneralTitle));
       
   845     const TDesC& playlistUri(aMedia.ValueText(KMPXMediaGeneralUri));
       
   846 
       
   847     TUint32 playlistId(MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), EMPXPlaylist, playlistUri, EFalse));
       
   848     const CMPXMediaArray* mediaArray = aMedia.Value<CMPXMediaArray>(KMPXMediaArrayContents);
       
   849     if( !mediaArray )
       
   850         {
       
   851         User::Leave( KErrNoMemory );
       
   852         }
       
   853     // add the songs to the PlaylistSongs table
       
   854     TInt count(mediaArray->Count());
       
   855     for (TInt i = 0; i < count; ++i)
       
   856         {
       
   857         iPlaylistSongs->AddSongL(playlistId, i, *mediaArray->AtL(i), aDriveId);
       
   858         }
       
   859 
       
   860     // determine the value of DbFlag
       
   861     TUint dbflags(0);
       
   862     if (aMedia.IsSupported(KMPXMediaGeneralFlags))
       
   863         {
       
   864         TUint flag(aMedia.ValueTObjectL<TUint>(KMPXMediaGeneralFlags));
       
   865         if (flag & KMPXMediaGeneralFlagsSetOrUnsetBit )
       
   866             {
       
   867             // Set flag
       
   868             dbflags |= flag;
       
   869             MPX_DEBUG2("    GeneralFlags[%b]", dbflags);
       
   870             }
       
   871         }
       
   872 
       
   873     // add playlist record
       
   874     HBufC* time = MPXDbCommonUtil::CurrentTimeDesLC();
       
   875     HBufC* name = MPXDbCommonUtil::ProcessSingleQuotesLC(playlistName);
       
   876     HBufC* uri = MPXDbCommonUtil::ProcessSingleQuotesLC(playlistUri);
       
   877     TPtrC uriPtr(uri->Mid(KMCPathStartPos));
       
   878     TPtrC namePtr(name->Left(KMCMaxTextLen));
       
   879 
       
   880     iDbManager.ExecuteQueryL(aDriveId, KQueryPlaylistInsert, playlistId, &namePtr,
       
   881         &uriPtr, MPXDbCommonUtil::GetVolIdMatchDriveIdL(iDbManager.Fs(), aDriveId),
       
   882         dbflags, time);
       
   883 
       
   884     CleanupStack::PopAndDestroy(uri);
       
   885     CleanupStack::PopAndDestroy(name);
       
   886     CleanupStack::PopAndDestroy(time);
       
   887 
       
   888     return playlistId;
       
   889     }
       
   890 
       
   891 // ----------------------------------------------------------------------------
       
   892 // CMPXDbPlaylist::DoUpdatePlaylistL
       
   893 // ----------------------------------------------------------------------------
       
   894 //
       
   895 void CMPXDbPlaylist::DoUpdatePlaylistL(
       
   896     TUint32 aPlaylistId,
       
   897     const CMPXMedia& aMedia,
       
   898     TInt aDriveId,
       
   899     CMPXMessage& aMessage)
       
   900     {
       
   901     MPX_FUNC("CMPXDbPlaylist::DoUpdatePlaylistL");
       
   902 
       
   903     // construct the criteria array
       
   904     const TArray<TMPXAttribute> attributes = aMedia.Attributes();
       
   905 
       
   906     CDesCArrayFlat* criteriaArray = new (ELeave) CDesCArrayFlat(attributes.Count());
       
   907     CleanupStack::PushL(criteriaArray);
       
   908 
       
   909     TInt attrCount(attributes.Count());
       
   910     for (TInt index = 0; index < attrCount; ++index)
       
   911         {
       
   912         TInt contentId(attributes[index].ContentId());
       
   913         TUint attributeId(attributes[index].AttributeId());
       
   914 
       
   915         switch(contentId)
       
   916             {
       
   917             case KMPXMediaIdGeneral:
       
   918                 {
       
   919                 if (attributeId & EMPXMediaGeneralTitle)
       
   920                     {
       
   921                     MPXDbCommonUtil::AddSqlCriterionL(*criteriaArray, KCriterionPlaylistTitle,
       
   922                         aMedia.ValueText(KMPXMediaGeneralTitle));
       
   923                     }
       
   924                 if (attributeId & EMPXMediaGeneralUri)
       
   925                     {
       
   926                     const TDesC& uri(aMedia.ValueText (KMPXMediaGeneralUri));
       
   927 
       
   928                     // determine if we are changing URI of an existing playlist.
       
   929                     // if so, update playlist URI + its Id
       
   930                     TUint32 newId(MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), EMPXPlaylist, uri, EFalse));
       
   931 
       
   932                     if (aPlaylistId != newId)
       
   933                         {
       
   934                         aMessage.SetTObjectValueL<TMPXItemId>(KMPXMessageMediaGeneralId, newId);
       
   935                         aMessage.SetTObjectValueL<TMPXItemId>(KMPXMessageMediaDeprecatedId, aPlaylistId);
       
   936 
       
   937                         // Change event handling for renaming a playlist should be like a song
       
   938                         // The item focus should goto the new name of the playlist
       
   939                         // to-do: this should be abstracted from the plugin. framework should
       
   940                         //        have enough info to deal with this scenario, if not, add more
       
   941                         //        info in the message passing back to framework
       
   942                         aMessage.SetTObjectValueL<TMPXGeneralCategory>(KMPXMessageMediaGeneralCategory,
       
   943                             EMPXSong);
       
   944 
       
   945                         // update the PlaylistSongs to reflect playlist id change
       
   946                         iPlaylistSongs->UpdateSongsL(aPlaylistId, newId);
       
   947 
       
   948                         // this takes care of processing the single quotes in the URI
       
   949                         MPXDbCommonUtil::AddSqlCriterionL(*criteriaArray, KCriterionPlaylistUri,
       
   950                             uri.Mid(KMCPathStartPos));
       
   951                         MPXDbCommonUtil::AddSqlCriterionL(*criteriaArray, KCriterionPlaylistVolumeId,
       
   952                             MPXDbCommonUtil::GetVolIdMatchDriveIdL(iDbManager.Fs(), TDriveUnit(uri)));
       
   953                         MPXDbCommonUtil::AddSqlCriterionL(*criteriaArray, KCriterionPlaylistUniqueId,
       
   954                             newId);
       
   955                         }
       
   956                     }
       
   957                 if (attributeId & EMPXMediaGeneralSynchronized)
       
   958                     {
       
   959                     MPXDbCommonUtil::AddSqlCriterionL(*criteriaArray, KCriterionPlaylistSync,
       
   960                         aMedia.ValueTObjectL<TBool>(KMPXMediaGeneralSynchronized));
       
   961                     }
       
   962                 }
       
   963                 break;
       
   964 
       
   965             default:
       
   966                 break;
       
   967 
       
   968             } // end switch
       
   969         } // end for
       
   970 
       
   971     // update the time field to the current time
       
   972     HBufC* time = MPXDbCommonUtil::CurrentTimeDesLC();
       
   973     MPXDbCommonUtil::AddSqlCriterionL(*criteriaArray, KCriterionPlaylistTime, *time);
       
   974     CleanupStack::PopAndDestroy(time);
       
   975 
       
   976     // construct a string from all criteria
       
   977     HBufC* criteria = MPXDbCommonUtil::StringFromArrayLC(*criteriaArray, KMCCommaSign);
       
   978 
       
   979     // execute the query
       
   980     iDbManager.ExecuteQueryL(aDriveId, KQueryPlaylistUpdate, criteria, aPlaylistId);
       
   981 
       
   982     CleanupStack::PopAndDestroy(criteria);
       
   983     CleanupStack::PopAndDestroy(criteriaArray);
       
   984     }
       
   985 
       
   986 // ----------------------------------------------------------------------------
       
   987 // CMPXDbPlaylist::UpdatePlaylistsForSongL
       
   988 // ----------------------------------------------------------------------------
       
   989 //
       
   990 void CMPXDbPlaylist::UpdatePlaylistsForSongL(
       
   991     TUint32 aSongId,
       
   992     CMPXMessageArray* aItemChangedMessages, TBool& aSongInPlaylists)
       
   993     {
       
   994     MPX_FUNC("CMPXDbPlaylist::UpdatePlaylistsForSongL");
       
   995 
       
   996     aSongInPlaylists = EFalse;
       
   997     if (aItemChangedMessages)
       
   998         {
       
   999         // get all playlists for the song
       
  1000         RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(KQueryPlaylistGetForSong, aSongId));
       
  1001         CleanupClosePushL(recordset);
       
  1002 
       
  1003         // ignore the errors
       
  1004         while (recordset.Next() == KSqlAtRow)
       
  1005             {
       
  1006             aSongInPlaylists = ETrue;
       
  1007             // add item changed messages for all of them
       
  1008             MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages,
       
  1009                 recordset.ColumnInt64(KMPXTableDefaultIndex), EMPXItemModified,
       
  1010                 EMPXPlaylist, KDBPluginUid);
       
  1011             }
       
  1012 
       
  1013         CleanupStack::PopAndDestroy(&recordset);
       
  1014         }
       
  1015     if (aSongInPlaylists)
       
  1016         {
       
  1017         // update the time for all playlists that contain this song
       
  1018         HBufC* time = MPXDbCommonUtil::CurrentTimeDesLC();
       
  1019         iDbManager.ExecuteQueryL (KDbManagerAllDrives,
       
  1020                 KQueryPlaylistUpdateTimeForSong, time, aSongId);
       
  1021         CleanupStack::PopAndDestroy (time);
       
  1022         }
       
  1023     }
       
  1024 
       
  1025 // ----------------------------------------------------------------------------
       
  1026 // CMPXDbPlaylist::CreateTableL
       
  1027 // ----------------------------------------------------------------------------
       
  1028 //
       
  1029 void CMPXDbPlaylist::UpdatePlaylistTimeL(
       
  1030     TUint32 aPlaylistId,
       
  1031     TInt aDrive)
       
  1032     {
       
  1033     MPX_FUNC("CMPXDbPlaylist::UpdatePlaylistTimeL");
       
  1034 
       
  1035     HBufC* time = MPXDbCommonUtil::CurrentTimeDesLC();
       
  1036     iDbManager.ExecuteQueryL(aDrive, KQueryPlaylistUpdateTime, time, aPlaylistId);
       
  1037     CleanupStack::PopAndDestroy(time);
       
  1038     }
       
  1039 
       
  1040 // ----------------------------------------------------------------------------
       
  1041 // CMPXDbPlaylist::GetDrivePlaylistDuration
       
  1042 // ----------------------------------------------------------------------------
       
  1043 //
       
  1044 TInt CMPXDbPlaylist::GetDrivePlaylistDuration(TUint32 aPlaylistId)
       
  1045     {
       
  1046     return 0;
       
  1047     }
       
  1048 // ----------------------------------------------------------------------------
       
  1049 // CMPXDbPlaylist::CreateTableL
       
  1050 // ----------------------------------------------------------------------------
       
  1051 //
       
  1052 void CMPXDbPlaylist::CreateTableL(
       
  1053     RSqlDatabase& aDatabase,
       
  1054     TBool /* aCorruptTable */)
       
  1055     {
       
  1056     MPX_FUNC("CMPXDbPlaylist::CreateTableL");
       
  1057 
       
  1058     // create the table
       
  1059     User::LeaveIfError(aDatabase.Exec(KPlaylistCreateTable));
       
  1060 
       
  1061     // create the index on the Name field
       
  1062     User::LeaveIfError(aDatabase.Exec(KPlaylistNameIndex));
       
  1063     }
       
  1064 
       
  1065 // ----------------------------------------------------------------------------
       
  1066 // CMPXDbPlaylist::DropTableL
       
  1067 // ----------------------------------------------------------------------------
       
  1068 //
       
  1069 void CMPXDbPlaylist::DropTableL(
       
  1070     RSqlDatabase& aDatabase)
       
  1071     {
       
  1072     MPX_FUNC("CMPXDbPlaylist::DropTableL");
       
  1073     User::LeaveIfError(aDatabase.Exec(KPlaylistDropTable));
       
  1074     }
       
  1075 
       
  1076 // ----------------------------------------------------------------------------
       
  1077 // CMPXDbPlaylist::CheckTableL
       
  1078 // ----------------------------------------------------------------------------
       
  1079 //
       
  1080 TBool CMPXDbPlaylist::CheckTableL(
       
  1081     RSqlDatabase& aDatabase)
       
  1082     {
       
  1083     MPX_FUNC("CMPXDbPlaylist::CheckTableL");
       
  1084     return DoCheckTable(aDatabase, KPlaylistCheckTable);
       
  1085     }
       
  1086 
       
  1087 // End of File