/** GetListForItemL has a dual nature. If aIsGroup is ETrue, a list of contact items belonging to specified group is returned. Otherwise a list of group ids to which contact id belongs is returned. @param aItemId contact item id @param aIsGroup ETrue if the method will fill a group. */ CContactIdArray* CPplGroupsTable::GetListForItemL(TContactItemId aItemId, TBool aIsGroup) { /* // Check if group membership information was not requested or if the item // is not derived from CContactItemPlusGroup. if (!(aType == KUidContactGroup || aType == KUidContactCard || aType == KUidContactOwnCard || aType == KUidContactICCEntry) ) { return NULL; } */ // build the RSqlStatement RSqlStatement stmnt; CleanupClosePushL(stmnt); TInt idIndex; // build the CCntSqlStatement statement const TInt KWhereParamIndex(KFirstIndex); // only one parameter in the query if (aIsGroup) { // group -> select members stmnt.PrepareL(iDatabase, iSelectMembersStmnt->SqlStringL() ); User::LeaveIfError(stmnt.BindInt(KWhereParamIndex, aItemId ) ); idIndex = stmnt.ColumnIndex(KGroupContactGroupMemberId() ); } else { // member -> select groups stmnt.PrepareL(iDatabase, iSelectGroupsStmnt->SqlStringL() ); User::LeaveIfError(stmnt.BindInt(KWhereParamIndex, aItemId ) ); idIndex = stmnt.ColumnIndex(KGroupContactGroupId() ); } User::LeaveIfError(idIndex); // fetch the list of any matching ids CContactIdArray* items = CContactIdArray::NewLC(); TInt err(KErrNone); while ((err = stmnt.Next() ) == KSqlAtRow) { items->AddL(stmnt.ColumnInt(idIndex) ); } // leave if we didn't complete going through the results properly if(err != KSqlAtEnd) { User::Leave(err); } CleanupStack::Pop(items); CleanupStack::PopAndDestroy(&stmnt); return items; }
/** Searches the contacts database to find any contact items with an exact match on the address supplied. @param aCommAddr A descriptor containing the address to be found in the database. @param aAddrType The type of addresses that is being sought. @return An array of contact IDs which match the supplied address. */ CContactIdArray* CPplCommAddrTable::MatchNonPhoneAddrL(const TDesC& aCommAddr, TCommAddrType aAddrType) { // build statement RSqlStatement stmnt; CleanupClosePushL(stmnt); stmnt.PrepareL(iDatabase, iMatchSelectStmnt->SqlStringL() ); const TInt KValueParamIndex(KFirstParam); // first parameter in query... const TInt KTypeParamIndex(KValueParamIndex + 1); // ...and the second. User::LeaveIfError(stmnt.BindText(KValueParamIndex, aCommAddr) ); User::LeaveIfError(stmnt.BindInt(KTypeParamIndex, aAddrType) ); // fetch the list of any matching contact ids CContactIdArray* idArray = CContactIdArray::NewLC(); TInt err(KErrNone); const TInt KContactIdIdx(iMatchSelectStmnt->ParameterIndex(KCommAddrContactId() ) ); while ((err = stmnt.Next() ) == KSqlAtRow) { idArray->AddL(stmnt.ColumnInt(KContactIdIdx) ); } // leave if we didn't complete going through the results properly if(err != KSqlAtEnd) { User::Leave(err); } CleanupStack::Pop(idArray); CleanupStack::PopAndDestroy(&stmnt); return idArray; }
/** Deletes all the communication addresses for a particular contact item. Should be used when deleting a contact item from the database altogether. @param aItem The contact item whose communcation addresses are to be deleted. */ void CPplCommAddrTable::DeleteL(const CContactItem& aItem, TBool& aLowDiskErrorOccurred) { const TUid KType = aItem.Type(); if (KType != KUidContactCard && KType != KUidContactOwnCard && KType != KUidContactICCEntry && KType != KUidContactGroup) { return; } RSqlStatement stmnt; CleanupClosePushL(stmnt); stmnt.PrepareL(iDatabase, iAllForItemDeleteStmnt->SqlStringL() ); const TInt KContactIdParamIndex(KFirstIndex); // first and only parameter in query User::LeaveIfError(stmnt.BindInt(KContactIdParamIndex, aItem.Id() ) ); TInt err = stmnt.Exec(); CleanupStack::PopAndDestroy(&stmnt); if (err == KErrDiskFull) { aLowDiskErrorOccurred = ETrue; } else { User::LeaveIfError(err); } }
/** @SYMTestCaseID PDS-SQLITE3SEC-UT-4034 @SYMTestCaseDesc SQL server multi-insert performance test. The test inserts 1000 records in a single transaction and stores the execution time for later use (comparison and printing). @SYMTestPriority High @SYMTestActions SQL server multi-insert performance test. @SYMTestExpectedResults Test must not fail @SYMREQ REQ11320 */ static void SqlServerMultiInsertTest(const char aInsertSql[], TInt aInsertRecCnt) { TheTest.Next( _L("@SYMTestCaseID:PDS-SQLITE3SEC-UT-4034")); (void)KillProcess(KSqlSrvName); TInt err = TheDb.Open(KTestDbName); TEST2(err, KErrNone); RSqlStatement stmt; err = stmt.Prepare(TheDb, TPtrC8((const TUint8*)aInsertSql)); TEST2(err, KErrNone); TUint32 fc = FastCounterValue(); err = TheDb.Exec(_L8("BEGIN")); TEST(err >= 0); for(TInt i=0;i<aInsertRecCnt;++i) { err = stmt.BindInt(0, i + 1); TEST2(err, KErrNone); err = stmt.Exec(); TEST2(err, 1); err = stmt.Reset(); TEST2(err, KErrNone); } err = TheDb.Exec(_L8("COMMIT")); TEST(err >= 0); StorePerfTestResult(EPerfTestSqlMode, EPerfTestMultiInsert, FastCounterValue() - fc); stmt.Close(); TheDb.Close(); }
/** * Method to change a plugin id in plugin Id table * @param aNewPluginID The ID of the new plugin * @param aFlag The flag that indicates the plugin id is enables or disabled * @param aOldPluginID The ID of the plugin to be replaced * @return Returns KErrNone if success. Refer ESqlDbError and system-wide * error codes for detailed error description. */ TInt CSmfCredMgrDbUser::updatePlugin(const TDesC& aPluginID, const TBool& aFlag, const TDesC& aOldPluginID) { TInt err(KErrNone); RSqlStatement sqlStatement; TInt paramIndex(KErrNone); TBuf<KMaxBufSize> newPluginBuf(aPluginID); TBuf<KMaxBufSize> OldPluginBuf(aOldPluginID); RSqlDatabase db; err = db.Open(iDbFilePathName); __ASSERT_DEBUG( (err >= KErrNone), User::Invariant()); err = sqlStatement.Prepare(db, KUpdatePluginID); __ASSERT_DEBUG( (err >= KErrNone), User::Invariant()); paramIndex = sqlStatement.ParameterIndex(_L(":iText")); err = sqlStatement.BindText(paramIndex, newPluginBuf); __ASSERT_DEBUG( (err >= KErrNone), User::Invariant()); paramIndex = sqlStatement.ParameterIndex(_L(":iFlag")); err = sqlStatement.BindInt(paramIndex, aFlag); __ASSERT_DEBUG( (err >= KErrNone), User::Invariant()); paramIndex = sqlStatement.ParameterIndex(_L(":iID")); err = sqlStatement.BindText(paramIndex, OldPluginBuf); __ASSERT_DEBUG( (err >= KErrNone), User::Invariant()); err = db.Exec(KBegin); __ASSERT_DEBUG( (err >= KErrNone), User::Invariant()); err = sqlStatement.Exec(); if (KSqlErrConstraint == err) { // } else if (err < KErrNone) { __ASSERT_DEBUG( (err >= KErrNone), User::Invariant()); } err = db.Exec(KCommit); __ASSERT_DEBUG( (err >= KErrNone), User::Invariant()); //if commit fails we have to roll back if (err < KErrNone) { err = db.Exec(KRollback); } sqlStatement.Close(); db.Close(); if (err >= 0) { return KErrNone; } return err; }
/** Performs write (Insert/Update) operations for indiviual communication addresses of type "phone number". */ void CPplCommAddrTable::DoPhoneNumWriteOpL(const CPplCommAddrTable::TMatch& aPhoneNum, TCntSqlStatement aType, TInt aCntId, TInt aCommAddrId,CPplCommAddrTable::TCommAddrExtraInfoType aExtraInfoType) { // leave if the statement type is not insert or update. // also, we can't update if aCommAddrId is 0 as we don't know the record's id if ((aType != EUpdate && aType != EInsert) || (aType == EUpdate && aCommAddrId == 0) ) { User::Leave(KErrArgument); } RSqlStatement stmnt; CleanupClosePushL(stmnt); // temporary reference to the CCntSqlStatements member variables to take advantage // of the commonality between update and insert operations. CCntSqlStatement* tempCntStmnt = iUpdateStmnt; if (aType == EInsert) { tempCntStmnt = iInsertStmnt; } User::LeaveIfError(stmnt.Prepare(iDatabase, tempCntStmnt->SqlStringL() ) ); User::LeaveIfError(stmnt.BindInt(tempCntStmnt->ParameterIndex(KCommAddrContactId() ), aCntId) ); User::LeaveIfError(stmnt.BindInt(tempCntStmnt->ParameterIndex(KCommAddrExtraValue() ), aPhoneNum.iUpperDigits) ); User::LeaveIfError(stmnt.BindInt(tempCntStmnt->ParameterIndex(KCommAddrValue() ), aPhoneNum.iLowerSevenDigits) ); User::LeaveIfError(stmnt.BindInt(tempCntStmnt->ParameterIndex(KCommAddrType() ), EPhoneNumber) ); User::LeaveIfError(stmnt.BindInt(tempCntStmnt->ParameterIndex(KCommAddrExtraTypeInfo() ), aExtraInfoType) ); if (aType == EInsert) { User::LeaveIfError(stmnt.BindNull(tempCntStmnt->ParameterIndex(KCommAddrId() ) ) ); } else { // it's the sixth parameter in the query and is in the WHERE // clause so we can't get its index from the CCntSqlStatement const TInt KCommAddrIdParamIndex(KFirstIndex + 5); User::LeaveIfError(stmnt.BindInt(KCommAddrIdParamIndex, aCommAddrId) ); } User::LeaveIfError(stmnt.Exec() ); CleanupStack::PopAndDestroy(&stmnt); }
// ----------------------------------------------------------------------------- // CUpnpSecurityDbConnection::ExecStatementL // Execute given db command // ----------------------------------------------------------------------------- // void CUpnpSecurityDbConnection::ExecStatementL( const TDesC8& aCommand, TInt aIntToBind ) { RSqlStatement statement; User::LeaveIfError( statement.Prepare( iDatabase, aCommand ) ); CleanupClosePushL( statement ); User::LeaveIfError( statement.BindInt( 0, aIntToBind ) ); User::LeaveIfError( statement.Exec() ); CleanupStack::PopAndDestroy( &statement ); }
/** * Method to insert RegTokenValidityTable * @param aRegToken The Registration token for the authentication app * @param aAuthAppId The ID of the Authentication app * @param aValidity The time by which the set will expire * @return Returns KErrNone if success. Refer ESqlDbError and system-wide * error codes for detailed error description. */ TInt CSmfCredMgrDbUser::RegTokenValidityTableInsert(const TDesC& aRegToken, const TDesC& aAuthAppId, const TUint aValidity) { TInt err(KErrNone); RSqlStatement sqlStatement; RSqlDatabase db; TBuf<KMaxBufSize> regTokenBuf(aRegToken); err = db.Open(iDbFilePathName); __ASSERT_DEBUG( (err >= KErrNone), User::Invariant()); err = sqlStatement.Prepare(db, KSmfRegTokenValidityTableInsert); TInt paramIndex(KErrNone); paramIndex = sqlStatement.ParameterIndex(_L(":Val1")); err = sqlStatement.BindText(paramIndex, aRegToken); paramIndex = sqlStatement.ParameterIndex(_L(":Val2")); err = sqlStatement.BindText(paramIndex, aAuthAppId); paramIndex = sqlStatement.ParameterIndex(_L(":Val3")); err = sqlStatement.BindInt(paramIndex, aValidity); err = db.Exec(KBegin); __ASSERT_DEBUG( (err >= KErrNone), User::Invariant()); err = sqlStatement.Exec(); if (KSqlErrConstraint == err) { //Table already present. } else if (err < KErrNone) { __ASSERT_DEBUG( (err >= KErrNone), User::Invariant()); } err = db.Exec(KCommit); __ASSERT_DEBUG( (err >= KErrNone), User::Invariant()); //if commit fails we have to roll back if (err < KErrNone) { err = db.Exec(KRollback); } sqlStatement.Close(); db.Close(); if (err >= 0) { return KErrNone; } return err; }
/** Deletes information about group for the passed contact item id @param aItemId contact item id @param aLowDiskErrorOccurred out parameter; will be set to ETrue if there was a deletion in low disk condition */ void CPplGroupsTable::DeleteItemL(TContactItemId aItemId, TBool& aLowDiskErrorOccurred) { RSqlStatement stmnt; CleanupClosePushL(stmnt); stmnt.PrepareL(iDatabase, iDeleteStmnt->SqlStringL() ); const TInt KGroupIdIndex(KFirstIndex); // first parameter in query... const TInt KMemberIdIndex(KGroupIdIndex + 1); // ...and the second parameter User::LeaveIfError(stmnt.BindInt(KGroupIdIndex, aItemId) ); User::LeaveIfError(stmnt.BindInt(KMemberIdIndex, aItemId) ); TInt err = stmnt.Exec(); CleanupStack::PopAndDestroy(&stmnt); if (err == KErrDiskFull) { aLowDiskErrorOccurred = ETrue; } else { User::LeaveIfError(err); } }
/** Create view contact object based on given sql statement. @return CViewContact object or NULL the contact is not found. */ CViewContact* CCntPplViewSession::CreateViewItemL(RSqlStatement& aSqlStmt, const CCntSqlStatement& aCntSqlStmt, const TContactViewPreferences& aViewPrefs) { if (! iContactsFile.IsOpened()) { User::Leave(KErrInUse); } CViewContact* viewContact = InitialiseViewItemL(aSqlStmt, aCntSqlStmt, aViewPrefs); if(!viewContact) { //Couldn't find the contact. return NULL; } CleanupStack::PushL(viewContact); if(viewContact->ContactType() == CViewContact::EContactItem) { FillViewItemL(*viewContact, aSqlStmt, aViewPrefs); } TUid typeUid = GetContactFieldMatchUid(*viewContact, aViewPrefs); if(typeUid != KUidContactFieldNone) { RSqlStatement contactSqlStmt; CleanupClosePushL(contactSqlStmt); /* we have to reload the row from SQL database to cache in text header and text blob */ contactSqlStmt.PrepareL(iContactsFile.NamedDatabase(), iSqlSmtSelectAllFieldsById.SqlStringL()); User::LeaveIfError(contactSqlStmt.BindInt(KFirstIndex, viewContact->Id())); //Bind item id into the condition. TInt err = contactSqlStmt.Next(); if(err == KSqlAtEnd) { //Should never be here, we found it in InitialiseViewItemL //but couldn't find the same contact in same database. CleanupStack::PopAndDestroy(viewContact); return NULL; } User::LeaveIfError(err); /* set first field with possible content for group or unsorted contact */ CContactDatabase::TTextFieldMinimal buf; TextFieldL(contactSqlStmt, iSqlSmtSelectAllFieldsById, iContactProperties.SystemTemplateL(), typeUid, buf); viewContact->SetFirstFieldForBlankContactL(buf); CleanupStack::PopAndDestroy(&contactSqlStmt); } //if(typeUid != 0) CleanupStack::Pop(viewContact); return viewContact; }
/** Deletes individual communication addresses from the database. In other words, deletes at the sub-contact item level rather than deleting everything with a specific contact item ID. */ void CPplCommAddrTable::DeleteSingleCommAddrL(TInt aCommAddrId, TBool& aLowDiskErrorOccurred) { RSqlStatement stmnt; CleanupClosePushL(stmnt); stmnt.PrepareL(iDatabase, iSingleDeleteStmnt->SqlStringL() ); const TInt KCommAddrIdParamIndex(KFirstIndex); // first and only parameter in the query User::LeaveIfError(stmnt.BindInt(KCommAddrIdParamIndex, aCommAddrId ) ); TInt err = stmnt.Exec(); CleanupStack::PopAndDestroy(&stmnt); if (err == KErrDiskFull) { aLowDiskErrorOccurred = ETrue; } else { User::LeaveIfError(err); } }
/** Returns an array of contact item IDs for all the contact items which may contain the specified telephone number in a telephone, fax or SMS type field. This is improved version of MatchPhoneNumberL method. The number is compared starting from the right side of the number and the method returns an array of candidate matches. Punctuation (e.g. spaces) and other alphabetic characters are ignored when comparing. Leading zeros are removed. Digits are compared up to the lenght of shorter number. @param aNumber Phone number string. @return Array of contact IDs which are candidate matches. */ CContactIdArray* CPplCommAddrTable::BestMatchingPhoneNumberL(const TDesC& aNumber) { const TInt KUpperMaxLength = KMaxPhoneMatchLength - KLowerSevenDigits; CContactIdArray* phoneMatchArray = CContactIdArray::NewLC(); TMatch phoneDigits = CreatePaddedPhoneDigitsL(aNumber, KLowerSevenDigits, KUpperMaxLength); if (phoneDigits.iNumLowerDigits + phoneDigits.iNumUpperDigits > 0) { // build statement RSqlStatement stmnt; CleanupClosePushL(stmnt); stmnt.PrepareL(iDatabase, iMatchSelectStmnt->SqlStringL()); const TInt KValueParamIndex(KFirstParam); // first parameter in query... const TInt KTypeParamIndex(KValueParamIndex + 1); // ...and the second. User::LeaveIfError(stmnt.BindInt(KValueParamIndex, phoneDigits.iLowerSevenDigits)); User::LeaveIfError(stmnt.BindInt(KTypeParamIndex, EPhoneNumber)); // fetch the list of any matching contact ids TInt err(KErrNone); const TInt KContactIdIdx(iMatchSelectStmnt->ParameterIndex( KCommAddrContactId())); const TInt KExtraValueIdx(iMatchSelectStmnt->ParameterIndex(KCommAddrExtraValue())); while ((err = stmnt.Next()) == KSqlAtRow) { // Check the upper digits... TInt32 number = phoneDigits.iUpperDigits; TPtrC extValString = stmnt.ColumnTextL(KExtraValueIdx); TInt32 storedUpperDigits; User::LeaveIfError(TLex(extValString).Val(storedUpperDigits)); TInt32 stored = storedUpperDigits; TBool nonZeroInStoredFound = EFalse; TBool nonZeroInNumberFound = EFalse; while ((number != 0) && (stored != 0)) { nonZeroInNumberFound |= (number % 10 != 0); nonZeroInStoredFound |= (stored % 10 != 0); if (nonZeroInStoredFound && nonZeroInNumberFound) { break; } number /= 10; stored /= 10; } if ( (phoneDigits.iUpperDigits == 0) || (storedUpperDigits == 0) || (number == stored) ) { phoneMatchArray->AddL(stmnt.ColumnInt(KContactIdIdx)); } } // leave if we didn't complete going through the results properly if (err != KSqlAtEnd) { User::Leave(err); } CleanupStack::PopAndDestroy(&stmnt); } CleanupStack::Pop(phoneMatchArray); return phoneMatchArray; }
/** Returns an array of contact item IDs for all the contact items which may contain the specified telephone number in a telephone, fax or SMS type field. The comparison method used is not exact. The number is compared starting from the right side of the number and the method returns an array of candidate matches. Punctuation (e.g. spaces) and other alphabetic characters are ignored when comparing. Additionally, if the Contacts Model Phone Parser (CNTPHONE.DLL) is available, then any DTMF digits are also excluded from the comparision. Note that due to the way numbers are stored in the database, it is recommended that at least 7 match digits are specified even when matching a number containing fewer digits. Failure to follow this guideline may (depending on the database contents) mean that the function will not return the expected Contact IDs. @param aNumber Phone number string. @param aMatchLengthFromRight Number of digits from the right of the phone number to use. Up to 15 digits can be specified, and it is recommended that at least 7 match digits are specified. @param aDatabase The database. @return Array of contact IDs which are candidate matches. */ CContactIdArray* CPplCommAddrTable::MatchPhoneNumberL(const TDesC& aNumber, const TInt aMatchLengthFromRight) { CContactIdArray* phoneMatchArray = CContactIdArray::NewLC(); TInt numLowerDigits = aMatchLengthFromRight; TInt numUpperDigits = 0; if(numLowerDigits > KLowerSevenDigits) { // New style matching. numLowerDigits = KLowerSevenDigits; numUpperDigits = aMatchLengthFromRight - KLowerSevenDigits; } TMatch phoneDigits = CreatePaddedPhoneDigitsL(aNumber, numLowerDigits, numUpperDigits); if (phoneDigits.iNumLowerDigits + phoneDigits.iNumUpperDigits > 0) { // build statement RSqlStatement stmnt; CleanupClosePushL(stmnt); stmnt.PrepareL(iDatabase, iMatchSelectStmnt->SqlStringL() ); const TInt KValueParamIndex(KFirstParam); // first parameter in query... const TInt KTypeParamIndex(KValueParamIndex + 1); // ...and the second. User::LeaveIfError(stmnt.BindInt(KValueParamIndex, phoneDigits.iLowerSevenDigits )); User::LeaveIfError(stmnt.BindInt(KTypeParamIndex, EPhoneNumber )); // fetch the list of any matching contact ids TInt err(KErrNone); const TInt KContactIdIdx(iMatchSelectStmnt->ParameterIndex(KCommAddrContactId() ) ); const TInt KExtraValueIdx(iMatchSelectStmnt->ParameterIndex(KCommAddrExtraValue() ) ); while ((err = stmnt.Next() ) == KSqlAtRow) { if (aMatchLengthFromRight <= KLowerSevenDigits) { // Matching 7 or less digits...we've already matched. phoneMatchArray->AddL(stmnt.ColumnInt(KContactIdIdx) ); } else { // Check the upper digits... TInt32 storedUpperDigits(0); TPtrC extValString = stmnt.ColumnTextL(KExtraValueIdx); User::LeaveIfError(TLex(extValString).Val(storedUpperDigits) ); const TInt KDigitsToRemove = KMaxPhoneMatchLength - KLowerSevenDigits - phoneDigits.iNumUpperDigits; for(TInt i = 0; i < KDigitsToRemove; ++i) { // repeatedly divide by 10 to lop off the appropriate number of digits from the right storedUpperDigits /= 10; } storedUpperDigits = TMatch::PadOutPhoneMatchNumber(storedUpperDigits, KDigitsToRemove); if (phoneDigits.iUpperDigits == storedUpperDigits) { phoneMatchArray->AddL(stmnt.ColumnInt(KContactIdIdx) ); } } } // leave if we didn't complete going through the results properly if(err != KSqlAtEnd) { User::Leave(err); } CleanupStack::PopAndDestroy(&stmnt); } CleanupStack::Pop(phoneMatchArray); return phoneMatchArray; }
/** Persist the items belonging to curent group into group table @param aGroup referece to a contact group */ void CPplGroupsTable::WriteGroupMembersL(const CContactItem& aGroup) { if (aGroup.Type() != KUidContactGroup) { return; } const TContactItemId KGroupId(aGroup.Id() ); // make sure we clear out any previous, out-of-date data TBool lowDiskErr(EFalse); DeleteItemL(KGroupId, lowDiskErr); if (lowDiskErr) { User::Leave(KErrDiskFull); } // build the RSqlStatement RSqlStatement stmnt; CleanupClosePushL(stmnt); stmnt.PrepareL(iDatabase, iInsertStmnt->SqlStringL() ); const TInt KGroupIdIndex(KFirstIndex); // first parameter in query... const TInt KMemberIdIndex(KGroupIdIndex + 1); // ...and the second parameter // copy and sort the member id array so we can see if there are duplicates const CContactIdArray* contactIdArray = static_cast<const CContactGroup&>(aGroup).ItemsContained(); //does not take the ownership const TInt arrayCount = contactIdArray->Count(); CArrayFixFlat<TContactItemId>* sortedList = new(ELeave) CArrayFixFlat<TContactItemId>(KArrayGranularity); CleanupStack::PushL(sortedList); for(TInt loop = 0;loop < arrayCount; ++loop) { sortedList->AppendL((*contactIdArray)[loop]); } TKeyArrayFix key(0,ECmpTInt); sortedList->Sort(key); // insert the group-member relationships const TInt KCountStmntParamIndex(KFirstIndex); // first and only parameter in query const TInt listLen(sortedList->Count() ); TInt lastId(0); for (TInt i = 0; i < listLen; ++i) { TInt itemId((*sortedList)[i]); //check if a contact item with itemId id really exists in contact database RSqlStatement countStmnt; CleanupClosePushL(countStmnt); countStmnt.PrepareL(iDatabase, iCountContactsStmnt->SqlStringL() ); User::LeaveIfError(countStmnt.BindInt(KCountStmntParamIndex, itemId) ); TInt count = 0; TInt err = KErrNone; if((err = countStmnt.Next() ) == KSqlAtRow) { count = countStmnt.ColumnInt(iCountContactsStmnt->ParameterIndex(KSqlCount) ); } else { User::LeaveIfError(err); } if(count == 0) { User::Leave(KErrNotFound); } CleanupStack::PopAndDestroy(&countStmnt); // only insert this if we haven't already seen it if (itemId != lastId || i == 0) { User::LeaveIfError(stmnt.BindInt(KGroupIdIndex, KGroupId) ); User::LeaveIfError(stmnt.BindInt(KMemberIdIndex, itemId) ); User::LeaveIfError(stmnt.Exec() ); User::LeaveIfError(stmnt.Reset() ); } lastId = itemId; } CleanupStack::PopAndDestroy(2, &stmnt); // and sortedList }
/** Reads the contact item from the database using the given contact item ID. @param aItemId The Id number of the contact to be read. @param aView Specifies the fields to be read. @param aInfoToRead not used @param aSessionId The ID of the session that issued the request. This is used to prevent Phonebook Synchroniser deadlock. @param aIccOpenCheck Specifies if validation with the Phonebook Synchroniser is needed for this contact. @leave KErrArgument if the itemID can't be set within select statement @leave KErrNotFound if a contact item with aItemId does not exist within contact database @leave KSqlErrBusy the database file is locked; thrown if RSqlStatement::Next() returns this error @leave KErrNoMemory an out of memory condition has occurred - the statement will be reset;thrown if RSqlStatement::Next() returns this error @leave KSqlErrGeneral a run-time error has occured - this function must not be called again;thrown if RSqlStatement::Next() returns this error @leave KSqlErrMisuse this function has been called after a previous call returned KSqlAtEnd or KSqlErrGeneral.thrown if RSqlStatement::Next() returns this error @leave KSqlErrStmtExpired the SQL statement has expired (if new functions or collating sequences have been registered or if an authorizer function has been added or changed); thrown if RSqlStatement::Next() returns this error @return CContactItem created from reading the database tables. */ CContactItem* CPplContactItemManager::ReadLC(TContactItemId aItemId, const CContactItemViewDef& aView, TInt aInfoToRead, TUint aSessionId, TBool aIccOpenCheck) const { CContactTemplate* sysTemplate = NULL; if (aItemId != KGoldenTemplateId) { sysTemplate = const_cast<CContactTemplate*>(&iContactProperties.SystemTemplateL()); } RSqlStatement selectStmt; CleanupClosePushL(selectStmt); User::LeaveIfError(selectStmt.Prepare(iDatabase, iSelectStatement->SqlStringL())); TInt err = selectStmt.BindInt(KFirstParam, aItemId); if(err != KErrNone) { User::Leave(KErrArgument); } CContactItem* item = NULL; TUid type(KNullUid); if((err = selectStmt.Next()) == KSqlAtRow) { TInt contactId = selectStmt.ColumnInt(iSelectStatement->ParameterIndex(KContactId)); TInt templateId = selectStmt.ColumnInt(iSelectStatement->ParameterIndex(KContactTemplateId)); TInt typeFlags = selectStmt.ColumnInt(iSelectStatement->ParameterIndex(KContactTypeFlags)); type = TCntPersistenceUtility::TypeFlagsToContactTypeUid(typeFlags); item = CContactItem::NewLC(type); item->SetId(contactId); TPtrC guid = selectStmt.ColumnTextL(iSelectStatement->ParameterIndex(KContactGuidString)); item->SetUidStringL(guid); TInt attr = (typeFlags & EContactAttributes_Mask) >> EContactAttributes_Shift; item->SetAttributes(attr); item->SetTemplateRefId(templateId); item->SetLastModified(TTime(selectStmt.ColumnInt64(iSelectStatement->ParameterIndex(KContactLastModified)))); item->SetCreationDate(TTime(selectStmt.ColumnInt64(iSelectStatement->ParameterIndex(KContactCreationDate)))); item->SetAccessCount(selectStmt.ColumnInt(iSelectStatement->ParameterIndex(KContactAccessCount))); RArray<TPtrC> fastAccessFields; CleanupClosePushL(fastAccessFields); fastAccessFields.AppendL(selectStmt.ColumnTextL(iSelectStatement->ParameterIndex(KContactFirstName))); fastAccessFields.AppendL(selectStmt.ColumnTextL(iSelectStatement->ParameterIndex(KContactLastName))); fastAccessFields.AppendL(selectStmt.ColumnTextL(iSelectStatement->ParameterIndex(KContactCompanyName))); fastAccessFields.AppendL(selectStmt.ColumnTextL(iSelectStatement->ParameterIndex(KContactFirstNamePrn))); fastAccessFields.AppendL(selectStmt.ColumnTextL(iSelectStatement->ParameterIndex(KContactLastNamePrn))); fastAccessFields.AppendL(selectStmt.ColumnTextL(iSelectStatement->ParameterIndex(KContactCompanyNamePrn))); //set first name, last name, company name, first name pronunciation, last name pronunciation, company name pronunciation for (TInt fieldNum = item->CardFields().Count() - 1; fieldNum>=0; --fieldNum) { CContactItemField& textField = (item->CardFields())[fieldNum]; const TInt nameFieldIndex = NameFieldIndex(textField); // Check if field is first name, last name, company name, // first name pronunciation, last name pronunciation, company name pronunciation. if (nameFieldIndex != KErrNotFound) { HBufC* text = HBufC::NewLC(fastAccessFields[nameFieldIndex].Size()); text->Des() = fastAccessFields[nameFieldIndex]; textField.TextStorage()->SetText(text); CleanupStack::PopAndDestroy(text); } } CleanupStack::PopAndDestroy(&fastAccessFields); }
/** Removes comm addresses from the 3 lists that are already in the database and have been updated. It takes the 3 lists in as parameters and modifies them accordingly. It also populates the list of comm address ids that are free to be recycled during updating. */ void CPplCommAddrTable::RemoveNonUpdatedAddrsL(RArray<TMatch>& aNewPhones, RArray<TPtrC>& aNewEmails, RArray<TPtrC>& aNewSips, RArray<TInt>& aFreeCommAddrIds, const TInt aItemId,CPplCommAddrTable::TCommAddrExtraInfoType aExtraInfoType ) { // build the RSqlStatement RSqlStatement stmnt; CleanupClosePushL(stmnt); stmnt.PrepareL(iDatabase, iWholeSelectStmnt->SqlStringL() ); const TInt KContactIdParamIndex(KFirstIndex); // first and only parameter in the query User::LeaveIfError(stmnt.BindInt(KContactIdParamIndex, aItemId) ) ; // fetch the results from the query and compare them with the new comm_addrs we have TInt err(KErrNone); while ((err = stmnt.Next() ) == KSqlAtRow) { const TInt KType(stmnt.ColumnInt(iWholeSelectStmnt->ParameterIndex(KCommAddrType() ) ) ); if (KType == EPhoneNumber) { TMatch phoneNumber; TPtrC valString = stmnt.ColumnTextL(iWholeSelectStmnt->ParameterIndex(KCommAddrValue() ) ); TPtrC extValString = stmnt.ColumnTextL(iWholeSelectStmnt->ParameterIndex(KCommAddrExtraValue() ) ); TInt extTypeInfoString = stmnt.ColumnInt(iWholeSelectStmnt->ParameterIndex(KCommAddrExtraTypeInfo() ) ); User::LeaveIfError(TLex(valString).Val(phoneNumber.iLowerSevenDigits) ); User::LeaveIfError(TLex(extValString).Val(phoneNumber.iUpperDigits) ); TInt matchIndex(aNewPhones.Find(phoneNumber, TIdentityRelation<TMatch>(&TMatch::Equals) ) ); // remove any phone numbers from the new list if we already // have them in the db and they haven't changed... if (matchIndex != KErrNotFound && (extTypeInfoString == aExtraInfoType)) { aNewPhones.Remove(matchIndex); } // ...and add any spare ids to the recycle list else { aFreeCommAddrIds.AppendL( stmnt.ColumnInt(iWholeSelectStmnt->ParameterIndex(KCommAddrId() ) ) ); } } else // is Email or SIP { TPtrC valString = stmnt.ColumnTextL(iWholeSelectStmnt->ParameterIndex(KCommAddrValue() ) ); TInt matchIndex(0); // remove any email and sip addresses from the new list if // we already have them in the db and they haven't changed... if (KType == EEmailAddress) { matchIndex = aNewEmails.Find(valString); if (matchIndex != KErrNotFound) { aNewEmails.Remove(matchIndex); } } else // SIP { matchIndex = aNewSips.Find(valString); if (matchIndex != KErrNotFound) { aNewSips.Remove(matchIndex); } } // ...and add any spare ids to the recycle list if (matchIndex == KErrNotFound) { aFreeCommAddrIds.AppendL( stmnt.ColumnInt(iWholeSelectStmnt->ParameterIndex(KCommAddrId() ) ) ); } } } // leave if we didn't complete going through the results properly if(err != KSqlAtEnd) { User::Leave(err); } CleanupStack::PopAndDestroy(&stmnt); }
void CMdSSqLiteConnection::DoBindL( RSqlStatement& aStatement, const RRowData& aVariables ) { const TInt count( aVariables.Size() ); for( TInt i=0; i < count; ++i ) { switch ( aVariables.Column( i ).Type() ) { case EColumnInt32: { TInt32 val = 0; aVariables.Column( i ).Get( val ); aStatement.BindInt( i, val ); break; } case EColumnUint32: { TUint32 val = 0; aVariables.Column( i ).Get( val ); aStatement.BindInt64( i, (TInt64)val ); break; } case EColumnBool: { TBool val = 0; aVariables.Column( i ).Get( val ); aStatement.BindInt( i, val ); break; } case EColumnInt64: { TInt64 val = 0; aVariables.Column( i ).Get( val ); aStatement.BindInt64( i, val ); break; } case EColumnReal32: { TReal32 val = 0; aVariables.Column( i ).Get( val ); aStatement.BindReal( i, val ); break; } case EColumnReal64: { TReal64 val = 0; aVariables.Column( i ).Get( val ); aStatement.BindReal( i, val ); break; } case EColumnTime: { TTime val = TInt64(0); aVariables.Column( i ).Get( val ); aStatement.BindInt64( i, val.Int64() ); break; } case EColumnDes16: { TPtrC16 val = TPtr16((TUint16*)0, 0); //KNullPtr16; aVariables.Column( i ).Get( val ); aStatement.BindText( i, val ); break; } case EColumnNotUsed: // skip this variable break; default: #ifdef _DEBUG User::Panic( _L( "MdSSCDoB" ), KErrCorrupt ); #endif User::Leave( KErrCorrupt ); } } }