phonebookengines/contactsmodel/cntplsql/src/pplcontactitemmanager.cpp
changeset 46 efe85016a067
parent 40 b46a585f6909
equal deleted inserted replaced
40:b46a585f6909 46:efe85016a067
    24 
    24 
    25 #include "pplcontactitemmanager.h"
    25 #include "pplcontactitemmanager.h"
    26 #include "cntsqlprovider.h"
    26 #include "cntsqlprovider.h"
    27 #include "dbsqlconstants.h"
    27 #include "dbsqlconstants.h"
    28 #include "cntpersistenceutility.h"
    28 #include "cntpersistenceutility.h"
       
    29 #include "c12keypredictivesearchtable.h"
       
    30 #include "cqwertypredictivesearchtable.h"
       
    31 #include "cpredictivesearchsettingstable.h"
       
    32 #include "cpredictivesearchsynchronizer.h"
       
    33 #include "predictivesearchlog.h"
    29 //#include "cntmetadataoperation.h"
    34 //#include "cntmetadataoperation.h"
    30 #include <cntdef.h>
    35 #include <cntdef.h>
    31 #include <sqldb.h>
    36 #include <sqldb.h>
    32 #include <cntdb.h>
    37 #include <cntdb.h>
    33 
    38 
    34 // TODO: The code related to predictive search table is placed inside this
    39 // TODO: The code related to predictive search table is placed inside this
    35 // macro. Uncomment the below line to get the table into use.
    40 // macro. Uncomment the below line to get the table into use.
    36 #define USE_PRED_SEARCH_TABLE
    41 #define USE_PRED_SEARCH_TABLE
       
    42 
       
    43 // If this macro is defined, then pred.search qwerty tables are used
       
    44 #define USE_QWERTY_PRED_SEARCH_TABLE
    37 
    45 
    38 
    46 
    39 /**
    47 /**
    40 Creates a concrete CPplContactItemManager object 
    48 Creates a concrete CPplContactItemManager object 
    41 
    49 
    61 	{
    69 	{
    62 	delete iSelectStatement;	
    70 	delete iSelectStatement;	
    63 	delete iContactTable;
    71 	delete iContactTable;
    64 	delete iCommAddrTable;
    72 	delete iCommAddrTable;
    65 #if defined(USE_PRED_SEARCH_TABLE)
    73 #if defined(USE_PRED_SEARCH_TABLE)
    66 	RDebug::Print(_L("delete pred search table"));
    74 	PRINT(_L("delete pred search table objects"));
    67 	delete iPredSearchTable;
    75 	delete iPredictiveSearchSynchronizer;
    68 #endif
    76 	delete iPredSearch12keyTable;
    69     delete 	iPresenceTable; 
    77 #if defined(USE_QWERTY_PRED_SEARCH_TABLE)
       
    78 	delete iPredSearchQwertyTable;
       
    79 	delete iPredSearchSettingsTable;
       
    80 #endif
       
    81 	PRINT(_L("delete pred search table objects - done"));
       
    82 #endif
       
    83     delete iPresenceTable; 
    70 	delete iGroupTable;
    84 	delete iGroupTable;
    71 	delete iPreferencePersistor;
    85 	delete iPreferencePersistor;
    72 	//iColSession.Close();
    86 	//iColSession.Close();
    73 	}
    87 	}
    74 	
    88 	
   127 		
   141 		
   128 	iContactTable->CreateInDbL(aItem);	
   142 	iContactTable->CreateInDbL(aItem);	
   129 	iGroupTable->CreateInDbL(aItem);	
   143 	iGroupTable->CreateInDbL(aItem);	
   130 	iCommAddrTable->CreateInDbL(aItem);
   144 	iCommAddrTable->CreateInDbL(aItem);
   131 #if defined(USE_PRED_SEARCH_TABLE)
   145 #if defined(USE_PRED_SEARCH_TABLE)
   132 	RDebug::Print(_L("add new contact to pred search table"));
   146 	PRINT(_L("add new contact to pred search tables"));
   133 	iPredSearchTable->CreateInDbL(aItem);
   147 	iPredSearch12keyTable->CreateInDbL(aItem);
   134 	RDebug::Print(_L("add new contact to pred search table - done"));
   148 #if defined(USE_QWERTY_PRED_SEARCH_TABLE)
       
   149 	iPredSearchQwertyTable->CreateInDbL(aItem);
       
   150 	iPredSearchSettingsTable->CreateInDbL(aItem);
       
   151 #endif
       
   152 	PRINT(_L("add new contact to pred search tables - done"));
   135 #endif
   153 #endif
   136 
   154 
   137    	TContactItemId groupId = iIccContactStore.CreateInDbL(aItem, aSessionId);
   155    	TContactItemId groupId = iIccContactStore.CreateInDbL(aItem, aSessionId);
   138    	if(groupId != KNullContactId)
   156    	if(groupId != KNullContactId)
   139    	    {
   157    	    {
   320 	iIccContactStore.UpdateL(aItem, aSessionId);
   338 	iIccContactStore.UpdateL(aItem, aSessionId);
   321 	iContactTable->UpdateL(aItem);	
   339 	iContactTable->UpdateL(aItem);	
   322 	iGroupTable->UpdateL(aItem);	
   340 	iGroupTable->UpdateL(aItem);	
   323 	iCommAddrTable->UpdateL(aItem);
   341 	iCommAddrTable->UpdateL(aItem);
   324 #if defined(USE_PRED_SEARCH_TABLE)
   342 #if defined(USE_PRED_SEARCH_TABLE)
   325 	RDebug::Print(_L("update contact in pred search table"));
   343 	PRINT(_L("update contact in pred search tables"));
   326 	iPredSearchTable->UpdateL(aItem);
   344 	iPredSearch12keyTable->UpdateL(aItem);
   327 	RDebug::Print(_L("update contact in pred search table - done"));
   345 #if defined(USE_QWERTY_PRED_SEARCH_TABLE)
       
   346 	iPredSearchQwertyTable->UpdateL(aItem);
       
   347 	iPredSearchSettingsTable->UpdateL(aItem);
       
   348 #endif
       
   349 	PRINT(_L("update contact in pred search tables - done"));
   328 #endif
   350 #endif
   329 
   351 
   330 	if(controlTransaction)
   352 	if(controlTransaction)
   331 		{
   353 		{
   332 		CommitTransactionL();
   354 		CommitTransactionL();
   374 		StartTransactionL(aSessionId);
   396 		StartTransactionL(aSessionId);
   375 		}
   397 		}
   376 
   398 
   377 	TBool lowDisk = EFalse;
   399 	TBool lowDisk = EFalse;
   378 	CContactItem* savedContactItem = static_cast<CPplContactTable*>(iContactTable)->DeleteLC(aItemId, lowDisk);
   400 	CContactItem* savedContactItem = static_cast<CPplContactTable*>(iContactTable)->DeleteLC(aItemId, lowDisk);
   379 	if(lowDisk) 
   401 	if (lowDisk) 
   380 		{
   402 		{
   381 		CleanupStack::PopAndDestroy(savedContactItem); // this was returned from the first call, but not deleted in the db
   403 		CleanupStack::PopAndDestroy(savedContactItem); // this was returned from the first call, but not deleted in the db
   382 		TInt err = iDatabase.GetReserveAccess();
   404 		TInt err = iDatabase.GetReserveAccess();
   383 		if(err != KErrNotFound)
   405 		if(err != KErrNotFound)
   384 			{
   406 			{
   396 		iDatabase.FreeReservedSpace();		
   418 		iDatabase.FreeReservedSpace();		
   397 		}
   419 		}
   398 
   420 
   399 	lowDisk = EFalse;	
   421 	lowDisk = EFalse;	
   400 	iGroupTable->DeleteL(*savedContactItem, lowDisk);	
   422 	iGroupTable->DeleteL(*savedContactItem, lowDisk);	
   401 	if(lowDisk) 
   423 	if (lowDisk) 
   402 		{
   424 		{
   403 		DeleteInLowDiskConditionL(iGroupTable, savedContactItem);
   425 		DeleteInLowDiskConditionL(iGroupTable, savedContactItem);
   404 		}
   426 		}
   405 
   427 
   406 	lowDisk = EFalse;
   428 	lowDisk = EFalse;
   407 	iCommAddrTable->DeleteL(*savedContactItem, lowDisk);	
   429 	iCommAddrTable->DeleteL(*savedContactItem, lowDisk);	
   408 	if(lowDisk) 
   430 	if (lowDisk) 
   409 		{
   431 		{
   410 		DeleteInLowDiskConditionL(iCommAddrTable, savedContactItem);
   432 		DeleteInLowDiskConditionL(iCommAddrTable, savedContactItem);
   411 		}
   433 		}
   412 
   434 
   413 #if defined(USE_PRED_SEARCH_TABLE)
   435 #if defined(USE_PRED_SEARCH_TABLE)
   414 	RDebug::Print(_L("delete contact from pred search table"));
   436 	PRINT(_L("delete contact from pred search tables"));
   415 	lowDisk = EFalse;
   437 	lowDisk = EFalse;
   416     iPredSearchTable->DeleteL(*savedContactItem, lowDisk);
   438     iPredSearch12keyTable->DeleteL(*savedContactItem, lowDisk);
   417     if(lowDisk) 
   439     if (lowDisk) 
   418 		{
   440 		{
   419 		DeleteInLowDiskConditionL(iPredSearchTable, savedContactItem);
   441 		DeleteInLowDiskConditionL(iPredSearch12keyTable, savedContactItem);
   420 		}
   442 		}
   421 	RDebug::Print(_L("delete contact from pred search table - done"));
   443 	lowDisk = EFalse;
       
   444 #if defined(USE_QWERTY_PRED_SEARCH_TABLE)
       
   445 	iPredSearchQwertyTable->DeleteL(*savedContactItem, lowDisk);
       
   446     if (lowDisk) 
       
   447 		{
       
   448 		DeleteInLowDiskConditionL(iPredSearchQwertyTable, savedContactItem);
       
   449 		}
       
   450 	iPredSearchSettingsTable->DeleteL(*savedContactItem, lowDisk);
       
   451     if (lowDisk) 
       
   452 		{
       
   453 		DeleteInLowDiskConditionL(iPredSearchSettingsTable, savedContactItem);
       
   454 		}
       
   455 #endif
       
   456 	PRINT(_L("delete contact from pred search tables - done"));
   422 #endif
   457 #endif
   423   
   458   
   424     //Fake checking read access to ICCEntry store to keep BC.
   459     //Fake checking read access to ICCEntry store to keep BC.
   425     iIccContactStore.ReadL(*savedContactItem, EPlGroupMembershipInfo, aSessionId, EFalse);    
   460     iIccContactStore.ReadL(*savedContactItem, EPlGroupMembershipInfo, aSessionId, EFalse);    
   426     
   461     
   531 	// construct tables
   566 	// construct tables
   532 	iContactTable = CPplContactTable::NewL(iDatabase, iContactProperties);
   567 	iContactTable = CPplContactTable::NewL(iDatabase, iContactProperties);
   533 	iCommAddrTable = CPplCommAddrTable::NewL(iDatabase, iContactProperties);
   568 	iCommAddrTable = CPplCommAddrTable::NewL(iDatabase, iContactProperties);
   534 	iGroupTable = CPplGroupsTable::NewL(iDatabase);
   569 	iGroupTable = CPplGroupsTable::NewL(iDatabase);
   535 	iPreferencePersistor = CPplPreferencesPersistor::NewL(iDatabase);
   570 	iPreferencePersistor = CPplPreferencesPersistor::NewL(iDatabase);
       
   571 
   536 #if defined(USE_PRED_SEARCH_TABLE)
   572 #if defined(USE_PRED_SEARCH_TABLE)
   537 	RDebug::Print(_L("create CPplPredictiveSearchTable object"));
   573 	PRINT(_L("create C12keyPredictiveSearchTable object"));
   538 	iPredSearchTable = CPplPredictiveSearchTable::NewL(iDatabase);
   574 	iPredSearch12keyTable = C12keyPredictiveSearchTable::NewL(iDatabase);
   539 	RDebug::Print(_L("create CPplPredictiveSearchTable object - done"));
   575 #if defined(USE_QWERTY_PRED_SEARCH_TABLE)
   540 #endif
   576 	PRINT(_L("create CQwertyPredictiveSearchTable object"));
       
   577 	iPredSearchQwertyTable = CQwertyPredictiveSearchTable::NewL(iDatabase);
       
   578 	PRINT(_L("create CPredictiveSearchSettingsTable object"));
       
   579 	iPredSearchSettingsTable = CPredictiveSearchSettingsTable::NewL(iDatabase);
       
   580 
       
   581 	iPredictiveSearchSynchronizer =
       
   582 		CPredictiveSearchSynchronizer::NewL(iDatabase,
       
   583 											*iPredSearch12keyTable,
       
   584 											*iPredSearchQwertyTable,
       
   585 											*iPredSearchSettingsTable);
       
   586 #endif // #if defined(USE_QWERTY_PRED_SEARCH_TABLE)
       
   587 #endif // #if defined(USE_PRED_SEARCH_TABLE)
       
   588 
   541 	iPresenceTable = CPplPresenceTable::NewL(iDatabase); 
   589 	iPresenceTable = CPplPresenceTable::NewL(iDatabase); 
   542 	
   590 	
   543 	// Connect to metadata server
   591 	// Connect to metadata server
   544 	//User::LeaveIfError(iColSession.Connect());
   592 	//User::LeaveIfError(iColSession.Connect());
   545 
   593 
   608 	{
   656 	{
   609 	RDebug::Print(_L("CPplContactItemManager::CreateTablesL"));	
   657 	RDebug::Print(_L("CPplContactItemManager::CreateTablesL"));	
   610 
   658 
   611 	TBool controlTransaction = !(iTransactionManager.IsTransactionActive());
   659 	TBool controlTransaction = !(iTransactionManager.IsTransactionActive());
   612 	
   660 	
   613 	if(controlTransaction)
   661 	if (controlTransaction)
   614 		{
   662 		{
   615 		StartTransactionL(0);
   663 		StartTransactionL(0);
   616 		}
   664 		}
   617 		
   665 		
   618 	iContactTable->CreateTableL();	
   666 	iContactTable->CreateTableL();	
   619 	iGroupTable->CreateTableL();	
   667 	iGroupTable->CreateTableL();	
   620 	iCommAddrTable->CreateTableL();
   668 	iCommAddrTable->CreateTableL();
   621 	iPreferencePersistor->CreateTableL();
   669 	iPreferencePersistor->CreateTableL();
   622 #if defined(USE_PRED_SEARCH_TABLE)
   670 #if defined(USE_PRED_SEARCH_TABLE)
   623 	RDebug::Print(_L("create pred search table to DB"));	
   671 	PRINT(_L("create pred search tables to DB"));	
   624 	iPredSearchTable->CreateTableL();
   672 	iPredSearch12keyTable->CreateTableL();
   625 	RDebug::Print(_L("create pred search table to DB - done"));	
   673 #if defined(USE_QWERTY_PRED_SEARCH_TABLE)
       
   674 	iPredSearchQwertyTable->CreateTableL();
       
   675 	iPredSearchSettingsTable->CreateTableL();
       
   676 #endif
       
   677 	PRINT(_L("create pred search tables to DB - done"));	
   626 #endif
   678 #endif
   627 	iPresenceTable->CreateTableL(); 
   679 	iPresenceTable->CreateTableL(); 
   628 	
   680 	
   629 	if(controlTransaction)
   681 	if (controlTransaction)
   630 		{
   682 		{
   631 		CommitTransactionL();
   683 		CommitTransactionL();
   632 		}			
   684 		}			
   633 
   685 
   634 	RDebug::Print(_L("CPplContactItemManager::CreateTablesL ends"));	
   686 	RDebug::Print(_L("CPplContactItemManager::CreateTablesL ends"));	
   710 	
   762 	
   711 	User::LeaveIfError(selectStatement.Prepare(iDatabase, ptrSelectString));
   763 	User::LeaveIfError(selectStatement.Prepare(iDatabase, ptrSelectString));
   712 	const TInt KIdx = iSelectStatement->ParameterIndex(KContactId);
   764 	const TInt KIdx = iSelectStatement->ParameterIndex(KContactId);
   713 	
   765 	
   714 	TInt err;
   766 	TInt err;
   715 	while((err = selectStatement.Next()) == KSqlAtRow)
   767 	while ((err = selectStatement.Next()) == KSqlAtRow)
   716 		{
   768 		{
   717 		idArray->AddL(selectStatement.ColumnInt(KIdx));	
   769 		idArray->AddL(selectStatement.ColumnInt(KIdx));	
   718 		}
   770 		}
   719 
   771 
   720 	if(err != KSqlAtEnd)
   772 	if (err != KSqlAtEnd)
   721 		{
   773 		{
   722 		User::Leave(err);
   774 		User::Leave(err);
   723 		}
   775 		}
   724 
   776 
   725     CleanupStack::PopAndDestroy(&selectStatement);
   777     CleanupStack::PopAndDestroy(&selectStatement);
   761 	        stream << selectStatement.ColumnTextL(i);
   813 	        stream << selectStatement.ColumnTextL(i);
   762         }
   814         }
   763     stream.WriteInt32L(0);
   815     stream.WriteInt32L(0);
   764     stream.Close();
   816     stream.Close();
   765 
   817 
   766     if(err != KSqlAtEnd)
   818     if (err != KSqlAtEnd)
   767         {
   819         {
   768         User::Leave(err);
   820         User::Leave(err);
   769         }
   821         }
   770 
   822 
   771     //Cleanup 
   823     //Cleanup 
   773     CleanupStack::Pop(array);
   825     CleanupStack::Pop(array);
   774     
   826     
   775     return array;
   827     return array;
   776     }
   828     }
   777 
   829 
   778 
       
   779 /**
   830 /**
   780 Utility method used to rthe prefered card template id
   831 Utility method used to rthe prefered card template id
   781 */
   832 */
   782 TInt CPplContactItemManager::CardTemplatePrefIdL() const
   833 TInt CPplContactItemManager::CardTemplatePrefIdL() const
   783 	{
   834 	{
   790 void CPplContactItemManager::SetCardTemplatePrefIdL(TInt aCardTemplatePrefId)
   841 void CPplContactItemManager::SetCardTemplatePrefIdL(TInt aCardTemplatePrefId)
   791 	{
   842 	{
   792 	iPreferencePersistor->SetPreferredCardTemplateIdL(aCardTemplatePrefId);
   843 	iPreferencePersistor->SetPreferredCardTemplateIdL(aCardTemplatePrefId);
   793 	}
   844 	}
   794 
   845 
   795 // If predictive search tables do not exist, generate them using data from
       
   796 // contacts table.
       
   797 void CPplContactItemManager::SynchronizePredSearchTableL()
   846 void CPplContactItemManager::SynchronizePredSearchTableL()
   798 	{
   847 	{
   799 #if !defined(USE_PRED_SEARCH_TABLE)
   848 #if defined(USE_PRED_SEARCH_TABLE)
   800 	return;
   849 	iPredictiveSearchSynchronizer->SynchronizeTablesL();
   801 #endif
   850 #endif
   802 	RDebug::Print(_L("CPplContactItemManager::SynchronizePredSearchTableL"));
       
   803 
       
   804 	if (!DoesPredSearchTableExistL())
       
   805 		{
       
   806 		CreatePredSearchTablesL();
       
   807 		}
       
   808 	}
   851 	}
   809 
   852 
   810 void CPplContactItemManager::RecreatePredSearchTablesL()
   853 void CPplContactItemManager::RecreatePredSearchTablesL()
   811 	{
   854 	{
   812 	DeletePredSearchTablesL();
   855 #if defined(USE_PRED_SEARCH_TABLE)
   813 	CreatePredSearchTablesL();
   856 	iPredictiveSearchSynchronizer->DeletePredSearchTablesL();
   814 	}
   857 	iPredictiveSearchSynchronizer->CreatePredSearchTablesL();
   815 
   858 #endif
   816 void CPplContactItemManager::CreatePredSearchTablesL()
   859 	}
   817 	{
       
   818 	RDebug::Print(_L("CPplContactItemManager::CreatePredSearchTablesL"));
       
   819 
       
   820 	iPredSearchTable->CreateTableL();
       
   821 	_LIT(KSelectAllContactsFormat, "SELECT %S,%S,%S FROM %S;");
       
   822 	TInt bufSize = KSelectAllContactsFormat().Length() +
       
   823 				   KContactId().Length() +
       
   824 				   KContactFirstName().Length() +
       
   825 				   KContactLastName().Length() +
       
   826 				   KSqlContactTableName().Length();
       
   827 	HBufC* sqlStatement = HBufC::NewLC(bufSize);
       
   828 	sqlStatement->Des().AppendFormat(KSelectAllContactsFormat,
       
   829 		&KContactId,
       
   830 		&KContactFirstName,
       
   831 		&KContactLastName,
       
   832 		&KSqlContactTableName);
       
   833 
       
   834 	RSqlStatement stmnt;
       
   835 	CleanupClosePushL(stmnt);
       
   836 	RDebug::Print(_L("CreatePredSearchTablesL prepare SQL statement"));
       
   837     stmnt.PrepareL(iDatabase, *sqlStatement);
       
   838 
       
   839 	const TInt KContactIdIndex = 0;
       
   840 	const TInt KFirstNameIndex = 1;
       
   841 	const TInt KLastNameIndex = 2;
       
   842 	TInt err(KErrNone);
       
   843     while ((err = stmnt.Next()) == KSqlAtRow)
       
   844         {
       
   845 		RDebug::Print(_L("CreatePredSearchTablesL create CContactItem"));
       
   846 
       
   847 		TInt id = KUidContactCardValue;
       
   848 		TUid uid;
       
   849 		uid.iUid = id;
       
   850 		CContactItem* contact = CContactItem::NewLC(uid);
       
   851 		contact->SetId(stmnt.ColumnInt(KContactIdIndex));
       
   852 
       
   853 		// If first name exists, write it to contact item
       
   854 		TPtrC firstName;
       
   855 		if (stmnt.ColumnText(KFirstNameIndex, firstName) == KErrNone)
       
   856 			{
       
   857 			CContactItemField* field =
       
   858 				CContactItemField::NewLC(KStorageTypeText, KUidContactFieldGivenName);
       
   859 			CContactTextField* textfield = field->TextStorage();
       
   860 			textfield->SetTextL(firstName);
       
   861 			contact->AddFieldL(*field); // Takes ownership
       
   862 			CleanupStack::Pop(field);
       
   863 			}
       
   864 
       
   865 		TPtrC lastName;
       
   866 		if (stmnt.ColumnText(KLastNameIndex, lastName) == KErrNone)
       
   867 			{
       
   868 			CContactItemField* field =
       
   869 				CContactItemField::NewLC(KStorageTypeText, KUidContactFieldFamilyName);
       
   870 			CContactTextField* textfield = field->TextStorage();
       
   871 			textfield->SetTextL(lastName);
       
   872 			contact->AddFieldL(*field); // Takes ownership
       
   873 			CleanupStack::Pop(field);
       
   874 			}
       
   875 		RDebug::Print(_L("CreatePredSearchTablesL create entry to tables"));
       
   876 		iPredSearchTable->CreateInDbL(*contact);
       
   877 		CleanupStack::PopAndDestroy(contact);
       
   878         }
       
   879 
       
   880     // Leave if we didn't complete going through the results properly
       
   881     if (err != KSqlAtEnd)
       
   882         {
       
   883 		RDebug::Print(_L("CreatePredSearchTablesL SQL err=%d"), err);
       
   884         User::Leave(err);
       
   885         }
       
   886     CleanupStack::PopAndDestroy(&stmnt);
       
   887 	CleanupStack::PopAndDestroy(sqlStatement);
       
   888 
       
   889 	RDebug::Print(_L("CPplContactItemManager::CreatePredSearchTablesL ends"));
       
   890 	}
       
   891 
       
   892 TBool CPplContactItemManager::DoesPredSearchTableExistL() const
       
   893 	{
       
   894 	RDebug::Print(_L("CPplContactItemManager::DoesPredSearchTableExistL"));
       
   895 
       
   896 	_LIT(KSelectContactIdsFormat, "SELECT %S FROM %S;");
       
   897 	TInt bufSize = KSelectContactIdsFormat().Length() +
       
   898 				   KPredSearchContactId().Length() +
       
   899 				   KSqlContactPredSearchTable0().Length();
       
   900 	HBufC* sqlStatement = HBufC::NewLC(bufSize);
       
   901 	sqlStatement->Des().AppendFormat(KSelectContactIdsFormat,
       
   902 		&KPredSearchContactId,
       
   903 		&KSqlContactPredSearchTable0);
       
   904 
       
   905 	RSqlStatement stmnt;
       
   906 	CleanupClosePushL(stmnt);
       
   907 	// If predictive search table does not exist, leaves with -311.
       
   908     // If it exists, does not leave.
       
   909     TRAPD(err, stmnt.PrepareL(iDatabase, *sqlStatement));
       
   910 	RDebug::Print(_L("err=%d"), err );
       
   911 
       
   912 	CleanupStack::PopAndDestroy(&stmnt);
       
   913 	CleanupStack::PopAndDestroy(sqlStatement);
       
   914 
       
   915 	RDebug::Print(_L("CPplContactItemManager::DoesPredSearchTableExistL return %d"),
       
   916 				  err == KErrNone );
       
   917 	return err == KErrNone;
       
   918 	}
       
   919 
       
   920 void CPplContactItemManager::DeletePredSearchTablesL()
       
   921 	{
       
   922 	RDebug::Print(_L("CPplContactItemManager::DeletePredSearchTablesL"));
       
   923 
       
   924 	const TInt KTableCount = 10;
       
   925     const TDesC* KTableNames[KTableCount] =
       
   926         {
       
   927         &KSqlContactPredSearchTable0,
       
   928         &KSqlContactPredSearchTable1,
       
   929         &KSqlContactPredSearchTable2,
       
   930         &KSqlContactPredSearchTable3,
       
   931         &KSqlContactPredSearchTable4,
       
   932         &KSqlContactPredSearchTable5,
       
   933         &KSqlContactPredSearchTable6,
       
   934         &KSqlContactPredSearchTable7,
       
   935         &KSqlContactPredSearchTable8,
       
   936         &KSqlContactPredSearchTable9
       
   937         };
       
   938 
       
   939 	// IF EXISTS suppresses error that would occur if table does not exist
       
   940 	_LIT(KDropTable, "DROP TABLE IF EXISTS %S;");
       
   941     for (TInt i = 0; i < KTableCount; ++i)
       
   942         {
       
   943         HBufC* dropTableCommand = HBufC::NewLC(KDropTable().Length() +
       
   944             // All table names are of same length
       
   945             KTableNames[i]->Length());
       
   946         TPtr ptr = dropTableCommand->Des();
       
   947         ptr.Format(KDropTable, KTableNames[i]);
       
   948 
       
   949 		User::LeaveIfError(iDatabase.Exec(*dropTableCommand));
       
   950         CleanupStack::PopAndDestroy(dropTableCommand);
       
   951         }
       
   952 	RDebug::Print(_L("CPplContactItemManager::DeletePredSearchTablesL ends"));
       
   953 	}