contentstorage/castorage/src/casqlquerycreator.cpp
changeset 61 8e5041d13c84
parent 60 f62f87b200ec
child 66 32469d7d46ff
equal deleted inserted replaced
60:f62f87b200ec 61:8e5041d13c84
   229 
   229 
   230     if( idIcon == 0 )  
   230     if( idIcon == 0 )  
   231         {
   231         {
   232         // entry's icon data is not in DB
   232         // entry's icon data is not in DB
   233         if( ( aEntry->GetIcon().iFileName.Length() != 0 ) ||
   233         if( ( aEntry->GetIcon().iFileName.Length() != 0 ) ||
   234              ( aEntry->GetIcon().iBitmapId != 0 ) ||
   234             ( aEntry->GetIcon().iSkinId.Length() != 0 ) ||
   235              ( aEntry->GetIcon().iMaskId != 0 ) ||
   235             ( aEntry->GetIcon().iApplicationId.Length() != 0 )
   236              ( aEntry->GetIcon().iSkinMajorId != 0 ) ||
   236              )
   237              ( aEntry->GetIcon().iSkinMinorId != 0 ) )
       
   238             {
   237             {
   239             // icon is not null, so that insert it to storage
   238             // icon is not null, so that insert it to storage
   240             aQuery->SetQueryL( KSQLInsertToIcon );
   239             aQuery->SetQueryL( KSQLInsertToIcon );
   241             aQuery->SetTableType( CCaSqlQuery::EIconTable );
   240             aQuery->SetTableType( CCaSqlQuery::EIconTable );
   242             }
   241             }
   267     query->PrepareL();
   266     query->PrepareL();
   268     query->BindValuesForGetEntriesL( aEntry );
   267     query->BindValuesForGetEntriesL( aEntry );
   269     CCaInnerEntry::TIconAttributes iconAttributs;
   268     CCaInnerEntry::TIconAttributes iconAttributs;
   270     query->ExecuteL( iconAttributs );
   269     query->ExecuteL( iconAttributs );
   271     query->CloseStatement();
   270     query->CloseStatement();
   272     if( !( !iconAttributs.iFileName.Compare( aEntry->GetIcon().iFileName )
   271     if( !(     !iconAttributs.iFileName.Compare( aEntry->GetIcon().iFileName )
   273             && ( iconAttributs.iBitmapId == aEntry->GetIcon().iBitmapId )
   272             && (!iconAttributs.iSkinId.Compare( aEntry->GetIcon().iSkinId ))
   274             && ( iconAttributs.iMaskId == aEntry->GetIcon().iMaskId )
   273             && (!iconAttributs.iApplicationId.Compare( aEntry->GetIcon().iApplicationId ))
   275             && ( iconAttributs.iSkinMajorId
   274                     ) )
   276                     == aEntry->GetIcon().iSkinMajorId )
       
   277             && ( iconAttributs.iSkinMinorId
       
   278                     == aEntry->GetIcon().iSkinMinorId ) ) )
       
   279         {
   275         {
   280         // entry's icon data is updated
   276         // entry's icon data is updated
   281         // if icon is used by another entry(s), new icon'll added to DB and
   277         // if icon is used by another entry(s), new icon'll added to DB and
   282         // new Id_Icon'll set to entry, otherwise it'll just updated
   278         // new Id_Icon'll set to entry, otherwise it'll just updated
   283         query->SetQueryL( KSQLGetIconsItems );
   279         query->SetQueryL( KSQLGetIconsItems );
   344         query.ReAllocL( query.Length() + KSQLUpdateIconFileName().Length()
   340         query.ReAllocL( query.Length() + KSQLUpdateIconFileName().Length()
   345                 + KComma().Length() );
   341                 + KComma().Length() );
   346         query.Append( KSQLUpdateIconFileName );
   342         query.Append( KSQLUpdateIconFileName );
   347         query.Append( KComma );
   343         query.Append( KComma );
   348         }
   344         }
   349     if( aEntry->GetIcon().iBitmapId )
   345     if( aEntry->GetIcon().iSkinId.Compare( KNullDesC ) )
   350         {
   346         {
   351         query.ReAllocL( query.Length() + KSQLUpdateIconBitmapId().Length()
   347         query.ReAllocL( query.Length() + KSQLUpdateIconSkinId().Length()
   352                 + KComma().Length() );
   348                 + KComma().Length() );
   353         query.Append( KSQLUpdateIconBitmapId );
   349         query.Append( KSQLUpdateIconSkinId );
   354         query.Append( KComma );
   350         query.Append( KComma );
   355         }
   351         }
   356     if( aEntry->GetIcon().iMaskId )
   352      if( aEntry->GetIcon().iApplicationId.Compare(KNullDesC) )
   357         {
   353         {
   358         query.ReAllocL( query.Length() + KSQLUpdateIconMaskId().Length()
   354         query.ReAllocL( query.Length() + KSQLUpdateIconAppId().Length()
   359                 + KComma().Length() );
   355                 + KComma().Length() );
   360         query.Append( KSQLUpdateIconMaskId );
   356         query.Append( KSQLUpdateIconAppId );
   361         query.Append( KComma );
       
   362         }
       
   363     if( aEntry->GetIcon().iSkinMajorId )
       
   364         {
       
   365         query.ReAllocL( query.Length() + KSQLUpdateIconSkinMajorId().Length()
       
   366                 + KComma().Length() );
       
   367         query.Append( KSQLUpdateIconSkinMajorId );
       
   368         query.Append( KComma );
       
   369         }
       
   370     if( aEntry->GetIcon().iSkinMinorId )
       
   371         {
       
   372         query.ReAllocL( query.Length() + KSQLUpdateIconSkinMinorId().Length()
       
   373                 + KComma().Length() );
       
   374         query.Append( KSQLUpdateIconSkinMinorId );
       
   375         }
   357         }
   376     if( !query.Right( KComma().Length() ).Compare( KComma ) )
   358     if( !query.Right( KComma().Length() ).Compare( KComma ) )
   377         {
   359         {
   378         query.Assign( query.Mid( query.Length() - 
   360         query.Assign( query.Mid( query.Length() - 
   379                 KComma().Length()).AllocL() );
   361                 KComma().Length()).AllocL() );
   684         whereStatement.Append( KAnd );
   666         whereStatement.Append( KAnd );
   685         whereStatement.AppendFormat( KSQLGetEntryTypeNames,
   667         whereStatement.AppendFormat( KSQLGetEntryTypeNames,
   686                 &typeNameWhereStatement );
   668                 &typeNameWhereStatement );
   687         CleanupStack::PopAndDestroy( &typeNameWhereStatement );
   669         CleanupStack::PopAndDestroy( &typeNameWhereStatement );
   688         }
   670         }
       
   671     
       
   672     if( aQuery->GetAttributes().Count() )
       
   673         {
       
   674         RBuf whereAttributes;
       
   675         whereAttributes.CleanupClosePushL();
       
   676         whereAttributes.CreateL( KEmpty );
       
   677         
       
   678         for( TInt j=1; j <= aQuery->GetAttributes().Count(); j++ )
       
   679             {
       
   680             // at1.AT_NAME = 'Attribute_Name_1' AND at1.AT_VALUE = 'Attribute_VALUE_1'
       
   681             TPtrC atrName( aQuery->GetAttributes().operator [](j-1)->Name() );
       
   682             TPtrC atrValue( aQuery->GetAttributes().operator [](j-1)->Value() );
       
   683 
       
   684             whereAttributes.ReAllocL( whereAttributes.Length() + 2 * KAnd().Length() + 
       
   685                     4 * KSingleQuotes().Length() +
       
   686                     2 * KMaxIntNumLength + 
       
   687                     2 * KAt().Length() + 2 * KDot().Length() + 2 * KEqual().Length() +
       
   688                     KColumnAttrName().Length() + KColumnAttrValue().Length() +
       
   689                     atrName.Length() + atrValue.Length() );
       
   690             
       
   691             whereAttributes.Append( KAnd );
       
   692             
       
   693             whereAttributes.Append( KAt );
       
   694             whereAttributes.AppendNum( j );
       
   695             whereAttributes.Append( KDot );
       
   696             whereAttributes.Append( KColumnAttrName );
       
   697             whereAttributes.Append( KEqual );
       
   698             whereAttributes.Append( KSingleQuotes );
       
   699             whereAttributes.Append( atrName );
       
   700             whereAttributes.Append( KSingleQuotes );
       
   701             
       
   702             whereAttributes.Append( KAnd );
       
   703             
       
   704             whereAttributes.Append( KAt );
       
   705             whereAttributes.AppendNum( j );
       
   706             whereAttributes.Append( KDot );
       
   707             whereAttributes.Append( KColumnAttrValue );
       
   708             whereAttributes.Append( KEqual );
       
   709             whereAttributes.Append( KSingleQuotes );
       
   710             whereAttributes.Append( atrValue );
       
   711             whereAttributes.Append( KSingleQuotes );
       
   712             
       
   713             }
       
   714         
       
   715         whereStatement.ReAllocL( whereStatement.Length() + whereAttributes.Length() );
       
   716         whereStatement.Append( whereAttributes );
       
   717         
       
   718         CleanupStack::PopAndDestroy( &whereAttributes );
       
   719         }
       
   720 
       
   721     RBuf leftJoins;
       
   722     leftJoins.CleanupClosePushL();
       
   723     leftJoins.CreateL( KEmpty );
       
   724     if( aQuery->GetAttributes().Count() )
       
   725         {
       
   726         for( TInt j=1; j <= aQuery->GetAttributes().Count(); j++ )
       
   727             {
       
   728             // LEFT JOIN CA_ATTRIBUTE as at1 ON ENTRY_ID = at1.AT_ENTRY_ID
       
   729             leftJoins.ReAllocL( leftJoins.Length() + 
       
   730                     KLeftJoinCaAttrubute1().Length() + KMaxIntNumLength +
       
   731                     KLeftJoinCaAttrubute2().Length() + KMaxIntNumLength +
       
   732                     KLeftJoinCaAttrubute3().Length()
       
   733                     );
       
   734             
       
   735             leftJoins.Append( KLeftJoinCaAttrubute1 );
       
   736             leftJoins.AppendNum( j );
       
   737             leftJoins.Append( KLeftJoinCaAttrubute2 );
       
   738             leftJoins.AppendNum( j );
       
   739             leftJoins.Append( KLeftJoinCaAttrubute3 );
       
   740             }
       
   741         }
       
   742     
       
   743     
       
   744     whereStatement.ReAllocL( whereStatement.Length() + 
       
   745             KGroupBy().Length() + KColumnEntryId().Length() );
       
   746     whereStatement.Append( KGroupBy );
       
   747     whereStatement.Append( KColumnEntryId );
   689 
   748 
   690     TInt groupId = aQuery->GetParentId();
   749     TInt groupId = aQuery->GetParentId();
   691     RBuf query;
   750     RBuf query;
   692     query.CleanupClosePushL();
   751     query.CleanupClosePushL();
   693     if( groupId > 0 )
   752     if( groupId > 0 )
   694         {
   753         {
   695         query.CreateL( KSQLGetListByParentId().Length()
   754         RBuf getListByParentId2withWhere;
   696                 + whereStatement.Length() - 2 );
   755         getListByParentId2withWhere.CleanupClosePushL();
   697         query.AppendFormat( KSQLGetListByParentId, &whereStatement );
   756         getListByParentId2withWhere.CreateL( KSQLGetListByParentId2().Length() + whereStatement.Length() );
       
   757         getListByParentId2withWhere.AppendFormat( KSQLGetListByParentId2, &whereStatement );
       
   758         
       
   759         query.ReAllocL( KSQLGetListByParentId1().Length() +  leftJoins.Length() +
       
   760                 getListByParentId2withWhere.Length() );
       
   761         query.Append( KSQLGetListByParentId1 );
       
   762         query.Append( leftJoins );
       
   763         query.Append( getListByParentId2withWhere );
       
   764         CleanupStack::PopAndDestroy( &getListByParentId2withWhere );
   698         }
   765         }
   699     else
   766     else
   700         {
   767         {
   701         query.CreateL( KSQLGetList().Length() );
   768         query.CreateL( KSQLGetList1().Length() );
   702         query.Append( KSQLGetList );
   769         query.Append( KSQLGetList1 );
       
   770         query.ReAllocL( query.Length() + leftJoins.Length() + KSQLGetList2().Length() );
       
   771         query.Append( leftJoins );
       
   772         query.Append( KSQLGetList2 );
   703         if( whereStatement.Length() >= KAnd().Length() )
   773         if( whereStatement.Length() >= KAnd().Length() )
   704             {
   774             {
   705             TPtrC ptrWhereStatement( whereStatement.Right(
   775             TPtrC ptrWhereStatement( whereStatement.Right(
   706                     whereStatement.Length() - KAnd().Length() ) );
   776                     whereStatement.Length() - KAnd().Length() ) );
   707             query.ReAllocL( KSQLGetList().Length() + KWhere().Length()
   777             query.ReAllocL( query.Length() +  KWhere().Length()
   708                     + ptrWhereStatement.Length() );
   778                     + ptrWhereStatement.Length() );
       
   779 
   709             query.Append( KWhere );
   780             query.Append( KWhere );
   710             query.Append( ptrWhereStatement );
   781             query.Append( ptrWhereStatement );
   711             }
   782             }
   712         }
   783         }
   713 
   784 
   723         query.AppendNum( limitCount );
   794         query.AppendNum( limitCount );
   724         }
   795         }
   725 
   796 
   726     aSqlQuery->SetQueryL( query );
   797     aSqlQuery->SetQueryL( query );
   727     CleanupStack::PopAndDestroy( &query );
   798     CleanupStack::PopAndDestroy( &query );
       
   799     CleanupStack::PopAndDestroy( &leftJoins );
   728     CleanupStack::PopAndDestroy( &whereStatement );
   800     CleanupStack::PopAndDestroy( &whereStatement );
   729     }
   801     }
   730 
   802 
   731 
   803 
   732 // ---------------------------------------------------------------------------
   804 // ---------------------------------------------------------------------------
   960 // ---------------------------------------------------------------------------
  1032 // ---------------------------------------------------------------------------
   961 //
  1033 //
   962 CaSqlQueryCreator::TIconType CaSqlQueryCreator::CheckIconType( const CCaInnerEntry* aEntry )
  1034 CaSqlQueryCreator::TIconType CaSqlQueryCreator::CheckIconType( const CCaInnerEntry* aEntry )
   963     {
  1035     {
   964     CaSqlQueryCreator::TIconType iconType;
  1036     CaSqlQueryCreator::TIconType iconType;
   965     if( aEntry->GetIcon().iBitmapId == 0 &&
  1037     if( 
   966         aEntry->GetIcon().iMaskId == 0 &&
  1038         aEntry->GetIcon().iApplicationId.Length() == 0 &&
   967         aEntry->GetIcon().iSkinMajorId == 0 &&
  1039         aEntry->GetIcon().iSkinId.Length() == 0 &&
   968         aEntry->GetIcon().iSkinMinorId == 0 &&
       
   969         aEntry->GetIcon().iFileName.Length() == 0 )
  1040         aEntry->GetIcon().iFileName.Length() == 0 )
   970         {
  1041         {
   971         if( aEntry->GetIconId() > 0 )
  1042         if( aEntry->GetIconId() > 0 )
   972             {
  1043             {
   973             iconType = ENullIconToRemove;
  1044             iconType = ENullIconToRemove;