348 HBufC* query = PreProcessStringLC(KQueryAlbumAll); |
348 HBufC* query = PreProcessStringLC(KQueryAlbumAll); |
349 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(*query)); |
349 RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(*query)); |
350 CleanupStack::PopAndDestroy(query); |
350 CleanupStack::PopAndDestroy(query); |
351 |
351 |
352 CleanupClosePushL(recordset); |
352 CleanupClosePushL(recordset); |
353 ProcessRecordsetL(aAttrs, recordset, aMediaArray); |
353 ProcessAlbumRecordSetL(aAttrs, recordset, aMediaArray); |
354 CleanupStack::PopAndDestroy(&recordset); |
354 CleanupStack::PopAndDestroy(&recordset); |
355 } |
355 } |
356 |
356 |
357 // ---------------------------------------------------------------------------- |
357 // ---------------------------------------------------------------------------- |
358 // CMPXDbAlbum::UpdateItemL |
358 // CMPXDbAlbum::UpdateItemL |
615 CleanupStack::PopAndDestroy(query); |
615 CleanupStack::PopAndDestroy(query); |
616 |
616 |
617 return check; |
617 return check; |
618 } |
618 } |
619 |
619 |
|
620 // ---------------------------------------------------------------------------- |
|
621 // CMPXDbAlbum::ProcessAlbumRecordSetL |
|
622 // Unknown album is stored in the database as NULL (name field). |
|
623 // The first available unknown album is saved for later and will be appended to the array |
|
624 // as the last item and rest available unknown album will be ignored. |
|
625 // |
|
626 // NOTE: putting unknown album to the end of the array only takes place when title |
|
627 // field is requested. normal sorting algorithm occurs if title isn't |
|
628 // requested. |
|
629 // ---------------------------------------------------------------------------- |
|
630 // |
|
631 void CMPXDbAlbum::ProcessAlbumRecordSetL( |
|
632 const TArray<TMPXAttribute>& aAttrs, |
|
633 RSqlStatement& aRecordset, |
|
634 CMPXMediaArray& aMediaArray) |
|
635 { |
|
636 // populate the array |
|
637 TBool unknownRecord(EFalse); |
|
638 TBool firstUnknownRecord(EFalse); |
|
639 CMPXMedia* unknownMedia(NULL); |
|
640 TInt prevId(0); |
|
641 TInt err(KErrNone); |
|
642 |
|
643 TInt pPath(0); |
|
644 if (aMediaArray.Count()) |
|
645 { |
|
646 CMPXMedia* pMedia = aMediaArray[0]; |
|
647 if (pMedia->IsSupported(KMPXMediaGeneralValue)) |
|
648 { // Query excuted by OpenL |
|
649 pPath = pMedia->ValueTObjectL<TInt>(KMPXMediaGeneralValue); |
|
650 MPX_ASSERT(pPath); |
|
651 } |
|
652 } |
|
653 RArray<TMPXItemId> ids; |
|
654 CleanupClosePushL(ids); |
|
655 |
|
656 while ((err = aRecordset.Next()) == KSqlAtRow) |
|
657 { |
|
658 TUint32 rowId(aRecordset.ColumnInt64(EAlbumUniqueId)); |
|
659 if (prevId == rowId) |
|
660 { |
|
661 continue; |
|
662 } |
|
663 |
|
664 prevId = rowId; |
|
665 CMPXMedia* media = CMPXMedia::NewL(); |
|
666 CleanupStack::PushL(media); |
|
667 |
|
668 UpdateMediaL(aRecordset, aAttrs, *media); |
|
669 |
|
670 if (MPXDbCommonUtil::GetColumnTextL(aRecordset, EAlbumName).Length() == 0) |
|
671 { |
|
672 if (!unknownMedia) |
|
673 { |
|
674 unknownMedia = media; |
|
675 firstUnknownRecord = ETrue; |
|
676 } |
|
677 unknownRecord = ETrue; |
|
678 } |
|
679 |
|
680 if (!unknownRecord) |
|
681 { |
|
682 if (media->IsSupported(KMPXMediaGeneralId) && pPath) |
|
683 { |
|
684 ids.AppendL(media->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId)); |
|
685 } |
|
686 aMediaArray.AppendL(*media); |
|
687 } |
|
688 |
|
689 if (!firstUnknownRecord) |
|
690 { |
|
691 CleanupStack::PopAndDestroy(media); |
|
692 } |
|
693 else |
|
694 { |
|
695 firstUnknownRecord = EFalse; |
|
696 } |
|
697 |
|
698 unknownRecord = EFalse; |
|
699 } // end while |
|
700 |
|
701 if (err != KSqlAtEnd) |
|
702 { |
|
703 User::LeaveIfError(err); |
|
704 } |
|
705 |
|
706 if (unknownMedia) |
|
707 { |
|
708 if (unknownMedia->IsSupported(KMPXMediaGeneralId) && pPath) |
|
709 { |
|
710 ids.AppendL(unknownMedia->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId)); |
|
711 } |
|
712 aMediaArray.AppendL(*unknownMedia); |
|
713 CleanupStack::PopAndDestroy(unknownMedia); |
|
714 } |
|
715 |
|
716 // Append ids to the returned path |
|
717 if (pPath) |
|
718 { |
|
719 ((CMPXCollectionPath*)pPath)->AppendL(ids.Array()); |
|
720 } |
|
721 CleanupStack::PopAndDestroy(&ids); |
|
722 } |
|
723 |
620 // End of File |
724 // End of File |