contentstorage/castorage/src/casqlquerycreator.cpp
changeset 66 32469d7d46ff
parent 61 8e5041d13c84
child 80 397d00875918
equal deleted inserted replaced
61:8e5041d13c84 66:32469d7d46ff
   207     query.Append( KSQLUpdateWhere );
   207     query.Append( KSQLUpdateWhere );
   208 
   208 
   209     aQuery->SetQueryL( query );
   209     aQuery->SetQueryL( query );
   210     CleanupStack::PopAndDestroy( &query );
   210     CleanupStack::PopAndDestroy( &query );
   211     }
   211     }
       
   212 
       
   213 // ---------------------------------------------------------------------------
       
   214 //
       
   215 // ---------------------------------------------------------------------------
       
   216 //
       
   217 void CaSqlQueryCreator::CreateFindIconQueryL( CCaInnerEntry* aEntry,
       
   218         CCaSqlQuery* aQuery)
       
   219     {
       
   220     RBuf iconQuery;
       
   221     iconQuery.CleanupClosePushL();
       
   222     iconQuery.CreateL( KSQLGetIconIdWhere );
       
   223 
       
   224     if( aEntry->Icon()->FileName().Compare( KNullDesC ) )
       
   225         {
       
   226         iconQuery.ReAllocL( iconQuery.Length() + KSQLUpdateIconFileName().Length()
       
   227                 + KAnd().Length() );
       
   228         iconQuery.Append( KSQLUpdateIconFileName );
       
   229         iconQuery.Append( KAnd );
       
   230         }
       
   231     else
       
   232         { 
       
   233         iconQuery.ReAllocL( iconQuery.Length() + KSQLEmptyIconFileName().Length()
       
   234                 + KAnd().Length() );
       
   235         iconQuery.Append( KSQLEmptyIconFileName );
       
   236         iconQuery.Append( KAnd );
       
   237         }
       
   238 
       
   239     if( aEntry->Icon()->SkinId().Compare( KNullDesC ) )
       
   240         {
       
   241         iconQuery.ReAllocL( iconQuery.Length() + KSQLUpdateIconSkinId().Length()
       
   242                 + KAnd().Length() );
       
   243         iconQuery.Append( KSQLUpdateIconSkinId );
       
   244         iconQuery.Append( KAnd );
       
   245         }
       
   246     else
       
   247         {
       
   248         iconQuery.ReAllocL( iconQuery.Length() + KSQLEmptyIconSkinId().Length()
       
   249                 + KAnd().Length() );
       
   250         iconQuery.Append( KSQLEmptyIconSkinId );
       
   251         iconQuery.Append( KAnd );
       
   252         }
       
   253 
       
   254     if( aEntry->Icon()->ApplicationId().Compare( KNullDesC ) )
       
   255         {
       
   256         iconQuery.ReAllocL( iconQuery.Length() + KSQLUpdateIconAppId().Length()
       
   257                 + KAnd().Length() );
       
   258         iconQuery.Append( KSQLUpdateIconAppId );
       
   259         iconQuery.Append( KAnd );
       
   260         }
       
   261     else
       
   262         {
       
   263         iconQuery.ReAllocL( iconQuery.Length() + KSQLEmptyIconAppId().Length()
       
   264                 + KAnd().Length() );
       
   265         iconQuery.Append( KSQLEmptyIconAppId );
       
   266         iconQuery.Append( KAnd );
       
   267         }
       
   268 
       
   269     if (!iconQuery.Right(KAnd().Length()).Compare(KAnd))
       
   270         {    
       
   271         iconQuery.Delete( iconQuery.Length() - KAnd().Length(), KAnd().Length() );
       
   272         }
       
   273     
       
   274     aQuery->SetQueryL( iconQuery );
       
   275     CleanupStack::PopAndDestroy( &iconQuery );
       
   276     }
       
   277 
   212 // ---------------------------------------------------------------------------
   278 // ---------------------------------------------------------------------------
   213 //
   279 //
   214 // ---------------------------------------------------------------------------
   280 // ---------------------------------------------------------------------------
   215 //
   281 //
   216 void CaSqlQueryCreator::CreateAddIconQueryForNewL( CCaInnerEntry* aEntry,
   282 void CaSqlQueryCreator::CreateAddIconQueryForNewL( CCaInnerEntry* aEntry,
   217         CCaSqlQuery* aQuery, RSqlDatabase& aSqlDb )
   283         CCaSqlQuery* aQuery, RSqlDatabase& aSqlDb )
   218     {
   284     {
   219     DEBUG( ("_CA_:CASqlQueryCreator::CreateAddIconQueryForNewL") );
   285     DEBUG( ("_CA_:CASqlQueryCreator::CreateAddIconQueryForNewL") );
   220     CCaSqlQuery* query = CCaSqlQuery::NewLC( aSqlDb );
   286     CCaSqlQuery* query = CCaSqlQuery::NewLC( aSqlDb );
   221     query->SetQueryL( KSQLGetIconId );
   287 
       
   288     CreateFindIconQueryL(aEntry, query);
   222     query->SetTableType( CCaSqlQuery::EIconTable );
   289     query->SetTableType( CCaSqlQuery::EIconTable );
   223 
       
   224     query->PrepareL();
   290     query->PrepareL();
   225     query->BindValuesForGetIconL( aEntry );
   291     query->BindValuesForGetIconL( aEntry );
   226     TInt idIcon( 0 );
   292     TInt idIcon( 0 );
   227     query->ExecuteL( idIcon );
   293     query->ExecuteL( idIcon );
   228     CleanupStack::PopAndDestroy( query );
   294     CleanupStack::PopAndDestroy( query );
   229 
   295 
   230     if( idIcon == 0 )  
   296     if( idIcon == 0 )  
   231         {
   297         {
   232         // entry's icon data is not in DB
   298         // entry's icon data is not in DB
   233         if( ( aEntry->GetIcon().iFileName.Length() != 0 ) ||
   299         if( ( aEntry->Icon()->FileName().Length() != 0 ) ||
   234             ( aEntry->GetIcon().iSkinId.Length() != 0 ) ||
   300             ( aEntry->Icon()->SkinId().Length() != 0 ) ||
   235             ( aEntry->GetIcon().iApplicationId.Length() != 0 )
   301             ( aEntry->Icon()->ApplicationId().Length() != 0 )
   236              )
   302              )
   237             {
   303             {
   238             // icon is not null, so that insert it to storage
   304             // icon is not null, so that insert it to storage
   239             aQuery->SetQueryL( KSQLInsertToIcon );
   305             aQuery->SetQueryL( KSQLInsertToIcon );
   240             aQuery->SetTableType( CCaSqlQuery::EIconTable );
   306             aQuery->SetTableType( CCaSqlQuery::EIconTable );
   249         {
   315         {
   250         aEntry->SetIconId( idIcon );
   316         aEntry->SetIconId( idIcon );
   251         aQuery->SetTableType( CCaSqlQuery::ENoTableType );
   317         aQuery->SetTableType( CCaSqlQuery::ENoTableType );
   252         }
   318         }
   253     }
   319     }
       
   320 
   254 // ---------------------------------------------------------------------------
   321 // ---------------------------------------------------------------------------
   255 //
   322 //
   256 // ---------------------------------------------------------------------------
   323 // ---------------------------------------------------------------------------
   257 //
   324 //
   258 void CaSqlQueryCreator::CreateAddIconQueryForUpdateL(CCaInnerEntry* aEntry,
   325 void CaSqlQueryCreator::CreateAddIconQueryForUpdateL(CCaInnerEntry* aEntry,
   263     query->SetQueryL( KSQLGetIconDataByIdIcon );
   330     query->SetQueryL( KSQLGetIconDataByIdIcon );
   264     query->SetTableType( CCaSqlQuery::EIconTable );
   331     query->SetTableType( CCaSqlQuery::EIconTable );
   265 
   332 
   266     query->PrepareL();
   333     query->PrepareL();
   267     query->BindValuesForGetEntriesL( aEntry );
   334     query->BindValuesForGetEntriesL( aEntry );
   268     CCaInnerEntry::TIconAttributes iconAttributs;
   335     
   269     query->ExecuteL( iconAttributs );
   336     CCaInnerIconDescription* innerIcon = CCaInnerIconDescription::NewLC();
       
   337     
       
   338     query->ExecuteL( innerIcon );
   270     query->CloseStatement();
   339     query->CloseStatement();
   271     if( !(     !iconAttributs.iFileName.Compare( aEntry->GetIcon().iFileName )
   340     if( !(     !innerIcon->FileName().Compare( aEntry->Icon()->FileName() )
   272             && (!iconAttributs.iSkinId.Compare( aEntry->GetIcon().iSkinId ))
   341             && (!innerIcon->SkinId().Compare( aEntry->Icon()->SkinId() ))
   273             && (!iconAttributs.iApplicationId.Compare( aEntry->GetIcon().iApplicationId ))
   342             && (!innerIcon->ApplicationId().Compare( aEntry->Icon()->ApplicationId() ))
   274                     ) )
   343                     ) )
   275         {
   344         {
   276         // entry's icon data is updated
   345         // entry's icon data is updated
   277         // if icon is used by another entry(s), new icon'll added to DB and
   346         // if icon is used by another entry(s), new icon'll added to DB and
   278         // new Id_Icon'll set to entry, otherwise it'll just updated
   347         // new Id_Icon'll set to entry, otherwise it'll just updated
   297             CreateUpdateIconQueryL( aEntry, aQuery );
   366             CreateUpdateIconQueryL( aEntry, aQuery );
   298             }
   367             }
   299 
   368 
   300         CleanupStack::PopAndDestroy( &innerEntries );
   369         CleanupStack::PopAndDestroy( &innerEntries );
   301         }
   370         }
       
   371     CleanupStack::PopAndDestroy( innerIcon );
       
   372     
   302     CleanupStack::PopAndDestroy( query );
   373     CleanupStack::PopAndDestroy( query );
   303     }
   374     }
       
   375 
   304 // ---------------------------------------------------------------------------
   376 // ---------------------------------------------------------------------------
   305 //
   377 //
   306 // ---------------------------------------------------------------------------
   378 // ---------------------------------------------------------------------------
   307 //
   379 //
   308 void CaSqlQueryCreator::CreateAddIconQueryL( CCaInnerEntry* aEntry,
   380 void CaSqlQueryCreator::CreateAddIconQueryL( CCaInnerEntry* aEntry,
   321         // entry has id_icon set
   393         // entry has id_icon set
   322         // check if entry's icon data are the same as in database
   394         // check if entry's icon data are the same as in database
   323         CreateAddIconQueryForUpdateL( aEntry, aQuery, aSqlDb );
   395         CreateAddIconQueryForUpdateL( aEntry, aQuery, aSqlDb );
   324         }
   396         }
   325     }
   397     }
       
   398 
   326 // ---------------------------------------------------------------------------
   399 // ---------------------------------------------------------------------------
   327 //
   400 //
   328 // ---------------------------------------------------------------------------
   401 // ---------------------------------------------------------------------------
   329 //
   402 //
   330 void CaSqlQueryCreator::CreateUpdateIconQueryL(
   403 void CaSqlQueryCreator::CreateUpdateIconQueryL(
   333     DEBUG(("_CA_:CASqlQueryCreator::CreateUpdateIconQueryL"));
   406     DEBUG(("_CA_:CASqlQueryCreator::CreateUpdateIconQueryL"));
   334     RBuf query;
   407     RBuf query;
   335     query.CleanupClosePushL();
   408     query.CleanupClosePushL();
   336     query.CreateL( KSQLUpdateIcon().Length() );
   409     query.CreateL( KSQLUpdateIcon().Length() );
   337     query.Append( KSQLUpdateIcon );
   410     query.Append( KSQLUpdateIcon );
   338     if( aEntry->GetIcon().iFileName.Compare( KNullDesC ) )
   411     if( aEntry->Icon()->FileName().Compare( KNullDesC ) )
   339         {
   412         {
   340         query.ReAllocL( query.Length() + KSQLUpdateIconFileName().Length()
   413         query.ReAllocL( query.Length() + KSQLUpdateIconFileName().Length()
   341                 + KComma().Length() );
   414                 + KComma().Length() );
   342         query.Append( KSQLUpdateIconFileName );
   415         query.Append( KSQLUpdateIconFileName );
   343         query.Append( KComma );
   416         query.Append( KComma );
   344         }
   417         }
   345     if( aEntry->GetIcon().iSkinId.Compare( KNullDesC ) )
   418     if( aEntry->Icon()->SkinId().Compare( KNullDesC ) )
   346         {
   419         {
   347         query.ReAllocL( query.Length() + KSQLUpdateIconSkinId().Length()
   420         query.ReAllocL( query.Length() + KSQLUpdateIconSkinId().Length()
   348                 + KComma().Length() );
   421                 + KComma().Length() );
   349         query.Append( KSQLUpdateIconSkinId );
   422         query.Append( KSQLUpdateIconSkinId );
   350         query.Append( KComma );
   423         query.Append( KComma );
   351         }
   424         }
   352      if( aEntry->GetIcon().iApplicationId.Compare(KNullDesC) )
   425      if( aEntry->Icon()->ApplicationId().Compare(KNullDesC) )
   353         {
   426         {
   354         query.ReAllocL( query.Length() + KSQLUpdateIconAppId().Length()
   427         query.ReAllocL( query.Length() + KSQLUpdateIconAppId().Length()
   355                 + KComma().Length() );
   428                 + KComma().Length() );
   356         query.Append( KSQLUpdateIconAppId );
   429         query.Append( KSQLUpdateIconAppId );
   357         }
   430         }
   358     if( !query.Right( KComma().Length() ).Compare( KComma ) )
   431     if( !query.Right( KComma().Length() ).Compare( KComma ) )
   359         {
   432         {
   360         query.Assign( query.Mid( query.Length() - 
   433         query.Delete( query.Length() - KComma().Length(), KComma().Length() );
   361                 KComma().Length()).AllocL() );
       
   362         }
   434         }
   363     // add WHERE expr
   435     // add WHERE expr
   364     query.ReAllocL( query.Length() + KSQLUpdateIconWhere().Length() );
   436     query.ReAllocL( query.Length() + KSQLUpdateIconWhere().Length() );
   365     query.Append( KSQLUpdateIconWhere );
   437     query.Append( KSQLUpdateIconWhere );
   366 
   438 
  1033 //
  1105 //
  1034 CaSqlQueryCreator::TIconType CaSqlQueryCreator::CheckIconType( const CCaInnerEntry* aEntry )
  1106 CaSqlQueryCreator::TIconType CaSqlQueryCreator::CheckIconType( const CCaInnerEntry* aEntry )
  1035     {
  1107     {
  1036     CaSqlQueryCreator::TIconType iconType;
  1108     CaSqlQueryCreator::TIconType iconType;
  1037     if( 
  1109     if( 
  1038         aEntry->GetIcon().iApplicationId.Length() == 0 &&
  1110         aEntry->Icon()->ApplicationId().Length() == 0 &&
  1039         aEntry->GetIcon().iSkinId.Length() == 0 &&
  1111         aEntry->Icon()->SkinId().Length() == 0 &&
  1040         aEntry->GetIcon().iFileName.Length() == 0 )
  1112         aEntry->Icon()->FileName().Length() == 0 )
  1041         {
  1113         {
  1042         if( aEntry->GetIconId() > 0 )
  1114         if( aEntry->GetIconId() > 0 )
  1043             {
  1115             {
  1044             iconType = ENullIconToRemove;
  1116             iconType = ENullIconToRemove;
  1045             }
  1117             }