void CTestContactOperations::DeleteContactsL() { // existing database TPtrC databaseFile(_L("C:contactDB.cdb")); TContactItemId itemId = KErrNotFound; CContactDatabase* dBase = NULL; CContactIdArray* idArray = NULL; dBase = CContactDatabase::OpenL(databaseFile); CleanupStack::PushL(dBase); // Set the filter to select all the contact items in the database CCntFilter* exportFilter = CCntFilter::NewL(); CleanupStack::PushL(exportFilter); exportFilter->SetContactFilterTypeCard(ETrue); dBase->FilterDatabaseL(*exportFilter); idArray = exportFilter->iIds; CleanupStack::PushL(idArray); TInt numberOfContacts; GetIntFromConfig(ConfigSection(), KNumberOfCont, numberOfContacts); INFO_PRINTF1(_L("Deleting Contacts.....")); // Delete the contacts one at a time for(TInt i=(idArray->Count()-1);i>=0;i--) { dBase->DeleteContactL((*idArray)[i]); } _LIT(KCount, "The number of contacts in the database is %d \n"); INFO_PRINTF2(KCount, dBase->CountL()); // Close the contacts dBase->CloseContactL(itemId); // Cleanup CleanupStack::Pop(idArray); CleanupStack::PopAndDestroy(exportFilter); CleanupStack::PopAndDestroy(dBase); }
void CTestContactsPBAPExport::ExportContactsL() { TInt err = KErrNone; // Retrieve the file name to which contact item is to be exported RFs fsSession; RFileWriteStream writeStream; // connect to file system User::LeaveIfError(fsSession.Connect()); CleanupClosePushL(fsSession); GetInputFromIni(); // Makes one or more directories. fsSession.MkDirAll(iExportTo); // Replaces a single file with another User::LeaveIfError(writeStream.Replace(fsSession, iExportTo, EFileWrite)); INFO_PRINTF1(_L("Exporting Contact.....")); // Existing database TPtrC databaseFile(_L("C:contactDb.cdb")); CContactDatabase* dBase = NULL; CContactIdArray* idArray = NULL; // Open the existing database dBase = CContactDatabase::OpenL(databaseFile); CleanupStack::PushL(dBase); // Create Utility class object, to export the contact from database CTestStep* self = static_cast<CTestStep*>(this); iExportObj = new(ELeave) CContactsPBAPExportUtilityClass(self); SetFilterL(); CCntFilter* exportFilter = CCntFilter::NewL(); CleanupStack::PushL(exportFilter); // Get all the contacts from the database to export exportFilter->SetContactFilterTypeCard(ETrue); dBase->FilterDatabaseL(*exportFilter); idArray = exportFilter->iIds; CleanupStack::PushL(idArray); if(iDamageDb) { #ifdef _DEBUG #ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__ TRAPD(err1,dBase->DamageDatabaseL(0x666)); if(err1 == KErrNone) { TRAPD(err,iExportObj->ExportvCardL(dBase, iStandard, idArray, writeStream, iContactFilter)); INFO_PRINTF2(_L("Err:%d"),err); if(err == KErrNotReady) { SetTestStepResult(EPass); } else { SetTestStepResult(EFail); } if(dBase->IsDamaged()) { dBase->RecoverL(); } } else { INFO_PRINTF2(_L("Could not damage database Err:"),err1); } #else SetTestStepResult(EPass); #endif #endif } else { if(iInvalidFileSystem) { #ifdef _DEBUG fsSession.SetErrorCondition(KErrNotReady); TRAPD(err,iExportObj->ExportvCardL(dBase, iStandard, idArray, writeStream, iContactFilter)); if(err == KErrNotReady) { SetTestStepResult(EPass); } else { SetTestStepResult(EFail); } fsSession.SetErrorCondition(KErrNone); #endif } else { if(!iSetOOM) { if(idArray->Count() > 0) { for(TInt i=0; i<idArray->Count() ; i++) { TInt dCount = dBase->CountL(); if(i>=dCount) { break; } // temporary array used to export one contact at a time CContactIdArray* tempIdArray = CContactIdArray::NewL(); CleanupStack::PushL(tempIdArray); tempIdArray->AddL((*idArray)[i]); TRAPD(err,iExportObj->ExportvCardL(dBase, iStandard, tempIdArray, writeStream, iContactFilter)); if(err != KErrNone ) { if(err != KErrNotFound) { SetTestStepError(err); } } CleanupStack::PopAndDestroy(tempIdArray); } } else { if(idArray->Count()==0) { TRAPD(err,iExportObj->ExportvCardL(dBase, iStandard, idArray, writeStream, iContactFilter)); if(err != KErrNone) { SetTestStepError(err); } } } } else { TInt tryCount = 1; for ( ;; ) { __UHEAP_SETFAIL(RHeap::EDeterministic, tryCount); TRAP(err, iExportObj->ExportvCardL(dBase, iStandard, idArray, writeStream, iContactFilter)); if ( err == KErrNone ) { __UHEAP_RESET; INFO_PRINTF1(_L("OOM testing of CContactDatabase::ExportSelectedContactsL Api is done")); break; } if ( err != KErrNoMemory ) { INFO_PRINTF2(_L("The unexpected error code is:%d"),err); SetTestStepResult(EFail); break; } __UHEAP_SETFAIL(RHeap::ENone, 0); tryCount++; } } } } CleanupStack::Pop(idArray); CleanupStack::PopAndDestroy(exportFilter); INFO_PRINTF1(_L("Exported Contact")); writeStream.CommitL(); writeStream.Close(); INFO_PRINTF2(_L("Total number of contacts in database %d "), dBase->CountL()); // Cleanup CleanupStack::PopAndDestroy(dBase); CleanupStack::PopAndDestroy(&fsSession); }