void CRuleManager::ReadFromFile(RFile& file) { TInt size; file.Size(size); HBufC8* text = HBufC8::NewL(size); TPtr8 ptr = text->Des(); file.Read(ptr); TInt pos = ptr.Locate(KCharRuleSymbolEnd); while (pos != KErrNotFound) { CRule* rule = CRule::NewL(); ReadFromFile(ptr,pos,rule); iRules->Append(rule); ptr.Delete(0,pos+1); pos = ptr.Locate(KCharRuleSymbolEnd); } delete text; }
void CRuleManager::ReadFavFromFile() { TFileName filename; GetAppPath(filename); filename.Append(KFavRuleFile); RFile file; TInt err; err = file.Open(CCoeEnv::Static()->FsSession(), filename, EFileRead); CleanupClosePushL(file); if (KErrNone != err) { CleanupStack::PopAndDestroy(); // file return; } TInt size; file.Size(size); if (size > 0) { HBufC8* text = HBufC8::NewL(size); TPtr8 ptr = text->Des(); file.Read(ptr); TInt pos = ptr.Locate(KCharRuleSymbolEnd); if (pos != KErrNotFound) { ReadFromFile(ptr,pos,iFavRule); ptr.Delete(0,pos+1); TInt num = CCommonUtils::StrToInt(ptr); iFavRule->SetFavCount(num); } delete text; } CleanupStack::PopAndDestroy(); // file }
// ----------------------------------------------------------------------------- // MceSip::HeaderValueL // ----------------------------------------------------------------------------- // TUint MceSip::HeaderValueL( TPtr8 aHeader ) { TUint value; aHeader.Trim(); TInt index = aHeader.Locate( KMceSipHeaderSeparator ); if( index != KErrNotFound ) { TLex8 lexValue( aHeader.Left( index ) ); User::LeaveIfError ( lexValue.Val( value, EDecimal ) ); } else { TLex8 lexValue( aHeader ); User::LeaveIfError ( lexValue.Val( value, EDecimal ) ); } return value; }
/** @SYMTestCaseID PDS-SQL-UT-4151 @SYMTestCaseDesc Measures the performance of inserting multiple records into the Music Player MPX database. This test is based on a real Music Player Harvesting use case @SYMTestPriority Medium @SYMTestActions Reads SQL transactions from a file and executes them. Records the time for executing each statement @SYMTestExpectedResults All statements should be executed without error and performance measurements logged @SYMDEF DEF142306 */ void RunTest() { //Open the file with the sql statements _LIT(KSqlFileName,"z:\\test\\t_sqlperformance4.sql"); RFile sqlFile; TInt err = sqlFile.Open(TheFs, KSqlFileName, EFileRead); TEST2(err, KErrNone); TInt fileLen = 0; err = sqlFile.Size(fileLen); TEST2(err, KErrNone); HBufC8* sqlBuf = HBufC8::New(fileLen); TEST(sqlBuf != NULL); TPtr8 sql = sqlBuf->Des(); err = sqlFile.Read(sql); sqlFile.Close(); TEST2(err, KErrNone); TEST2(sql.Length(), fileLen); //Open main database err = TheDbC.Open(TheDbFileName, &TheSqlConfigString); TEST2(err, KErrNone); TheTest.Printf(_L("Beginning INSERTS...\n")); const TInt KRecordCount = 6544; TInt recordCount = 0; TInt insertCnt = 0; TInt updateCnt = 0; TInt selectCnt = 0; TInt trnCnt = 0; TInt totalTime = 0; TInt insertTrnCnt = 0; TInt updateTrnCnt = 0; TInt selectTrnCnt = 0; for(;sql.Length()>0;) { TInt eolPos = sql.Locate(TChar('\n')); if(eolPos < 0) { break;//No more SQL statements } TInt stmtLength = eolPos; while (stmtLength > 0 && (sql[stmtLength-1] == '\r')) { --stmtLength; //Reduce length to remove carriage return characters from the end of the statement string } TPtrC8 sqlStmt8(sql.Ptr(), stmtLength); TPtrC8 ptr = sql.Mid(eolPos + 1);//"eolPos + 1" - first character after '\n' sql.Set(const_cast <TUint8*> (ptr.Ptr()), ptr.Length(), ptr.Length()); ++recordCount; //Convert to 16 bit query string TBuf<1024> query; query.Copy(sqlStmt8); //Execute the statement TInt start = User::FastCounter(); err = TheDbC.Exec(query); TInt end = User::FastCounter(); TEST(err >= 0); //Get the execution time for that statement TInt duration = GetDuration(start, end); totalTime += duration; if(query == KBeginTransaction) { TheTest.Printf(_L("Execute Statement - BEGIN: %d us\n"), duration); } else if(query == KCommitTransaction) { ++trnCnt; TheTest.Printf(_L("Execute Statement - COMMIT: %d us, Trn#%d, \"INSERT\" count: %d, \"UPDATE\" count: %d, \"SELECT\" count: %d\n"), duration, trnCnt, insertTrnCnt, updateTrnCnt, selectTrnCnt); insertTrnCnt = updateTrnCnt = selectTrnCnt = 0; } else { TPtrC queryType(query.Ptr(), 6); TheTest.Printf(_L("Execute Statement - %S: %d us\n"),&queryType, duration); if(queryType.FindF(_L("INSERT")) >= 0) { ++insertCnt; ++insertTrnCnt; } else if(queryType.FindF(_L("UPDATE")) >= 0) { ++updateCnt; ++updateTrnCnt; } else if(queryType.FindF(_L("SELECT")) >= 0) { ++selectCnt; ++selectTrnCnt; } } } delete sqlBuf; TheDbC.Close(); TheTest.Printf(_L("Total time to process Songs: %d us\n"), totalTime); TheTest.Printf(_L("Transactions count: %d, \"INSERT\" count: %d, \"UPDATE\" count: %d, \"SELECT\" count: %d\n"), trnCnt, insertCnt, updateCnt, selectCnt); TEST2(recordCount, KRecordCount); }