persistentstorage/sql/TEST/t_sqlperformance2.cpp
changeset 0 08ec8eefde2f
child 15 fcc16690f446
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <e32test.h>
       
    17 #include <bautils.h>
       
    18 #include <sqldb.h>
       
    19 
       
    20 ///////////////////////////////////////////////////////////////////////////////////////
       
    21 
       
    22 RTest			TheTest(_L("t_sqlperformance2 test"));
       
    23 RSqlDatabase 	TheDb;
       
    24 TFileName		TheDbFileName;
       
    25 RFs				TheFs;
       
    26 
       
    27 TInt TheBlobSize = 1024 * 256;
       
    28 
       
    29 TBuf<256>  TheCmd;
       
    30 TDriveName TheDriveName;
       
    31 TParse     TheParse;
       
    32 
       
    33 ///////////////////////////////////////////////////////////////////////////////////////
       
    34 
       
    35 void TestEnvDestroy()
       
    36 	{
       
    37 	TheDb.Close();
       
    38 	(void)RSqlDatabase::Delete(TheDbFileName);
       
    39 	TheFs.Close();
       
    40 	}
       
    41 
       
    42 ///////////////////////////////////////////////////////////////////////////////////////
       
    43 ///////////////////////////////////////////////////////////////////////////////////////
       
    44 //Test macros and functions
       
    45 void Check1(TInt aValue, TInt aLine)
       
    46 	{
       
    47 	if(!aValue)
       
    48 		{
       
    49 		TestEnvDestroy();
       
    50 		TheTest.Printf(_L("*** Line %d\r\n"), aLine);
       
    51 		TheTest(EFalse, aLine);
       
    52 		}
       
    53 	}
       
    54 void Check2(TInt aValue, TInt aExpected, TInt aLine)
       
    55 	{
       
    56 	if(aValue != aExpected)
       
    57 		{
       
    58 		TestEnvDestroy();
       
    59 		TheTest.Printf(_L("*** Line %d, Expected error: %d, got: %d\r\n"), aLine, aExpected, aValue);
       
    60 		TheTest(EFalse, aLine);
       
    61 		}
       
    62 	}
       
    63 #define TEST(arg) ::Check1((arg), __LINE__)
       
    64 #define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__)
       
    65 
       
    66 ///////////////////////////////////////////////////////////////////////////////////////
       
    67 
       
    68 void TestEnvInit()
       
    69     {
       
    70     TInt err = TheFs.Connect();
       
    71     TEST2(err, KErrNone);
       
    72     //Get the drive number from the database file name
       
    73 	err = TheParse.Set(TheDbFileName, NULL, NULL);
       
    74 	TEST2(err, KErrNone);
       
    75 	TPtrC driveName = TheParse.Drive();
       
    76 	TEST(driveName.Length() > 0);
       
    77 	TInt driveNumber = -1;
       
    78 	err = RFs::CharToDrive(driveName[0], driveNumber);
       
    79 	TEST2(err, KErrNone);
       
    80 	TDriveNumber driveNo = static_cast <TDriveNumber> (driveNumber);
       
    81 	TDriveInfo driveInfo;
       
    82 	err = TheFs.Drive(driveInfo, driveNo);
       
    83 	TEST2(err, KErrNone);
       
    84     //Create the test directory
       
    85 	err = TheFs.MkDir(TheParse.DriveAndPath());
       
    86 	TEST(err == KErrNone || err == KErrAlreadyExists);
       
    87     //Print drive info and the database name 
       
    88 	_LIT(KType1, "Not present");
       
    89 	_LIT(KType2, "Unknown");
       
    90 	_LIT(KType3, "Floppy");
       
    91 	_LIT(KType4, "Hard disk");
       
    92 	_LIT(KType5, "CD ROM");
       
    93 	_LIT(KType6, "RAM disk");
       
    94 	_LIT(KType7, "Flash");
       
    95 	_LIT(KType8, "ROM drive");
       
    96 	_LIT(KType9, "Remote drive");
       
    97 	_LIT(KType10,"NAND flash");
       
    98 	_LIT(KType11,"Rotating media");
       
    99 	TPtrC KMediaTypeNames[] = {KType1(), KType2(), KType3(), KType4(), KType5(), KType6(), KType7(), KType8(), KType9(), KType10(), KType11()};
       
   100 	TheTest.Printf(_L("Drive %C: %S. File: \"%S\"\r\n"), 'A' + driveNo, &KMediaTypeNames[driveInfo.iType], &TheDbFileName);
       
   101 	}
       
   102 	
       
   103 void PrintWriteTime(TTimeIntervalMicroSeconds aTime, TTimeIntervalMicroSeconds aWriteTime, TTimeIntervalMicroSeconds aCommitTime)
       
   104 	{
       
   105 	TheTest.Printf(_L("####Execution time: %d ms, Write: %d ms, Commit: %d ms\r\n"), 
       
   106 		(TInt)(aTime.Int64() / 1000), (TInt)(aWriteTime.Int64() / 1000), (TInt)(aCommitTime.Int64() / 1000));
       
   107 	}
       
   108 
       
   109 void PrintReadTime(TTimeIntervalMicroSeconds aPrepareTime, TTimeIntervalMicroSeconds aNextTime, TTimeIntervalMicroSeconds aReadTime)
       
   110 	{
       
   111 	TInt executionTime = (TInt)(aPrepareTime.Int64() / 1000) + (TInt)(aNextTime.Int64() / 1000) + (TInt)(aReadTime.Int64() / 1000);
       
   112 	TheTest.Printf(_L("####Execution time: %d ms, Prepare: %d ms, Next: %d ms, Read: %d ms\r\n"), 
       
   113 		executionTime, (TInt)(aPrepareTime.Int64() / 1000), (TInt)(aNextTime.Int64() / 1000), (TInt)(aReadTime.Int64() / 1000));
       
   114 	}
       
   115 
       
   116 void PrintReadTime(TTimeIntervalMicroSeconds aOpenTime, TTimeIntervalMicroSeconds aReadTime)
       
   117 	{
       
   118 	TInt executionTime = (TInt)(aOpenTime.Int64() / 1000) + (TInt)(aReadTime.Int64() / 1000);
       
   119 	TheTest.Printf(_L("####Execution time: %d ms, Open: %d ms, Read: %d ms\r\n"), 
       
   120 		executionTime, (TInt)(aOpenTime.Int64() / 1000), (TInt)(aReadTime.Int64() / 1000));
       
   121 	}
       
   122 	
       
   123 void PrintFileSize(RSqlDatabase& aDb)
       
   124 	{
       
   125 	TheTest.Printf(_L("####FileSize: %d\r\n"), aDb.Size());
       
   126 	}
       
   127 		
       
   128 ///////////////////////////////////////////////////////////////////////////////////////
       
   129 	
       
   130 void CreateTestDb()
       
   131 	{
       
   132 	(void)RSqlDatabase::Delete(TheDbFileName);
       
   133 	TInt err = TheDb.Create(TheDbFileName);
       
   134 	TEST2(err, KErrNone);
       
   135 	err = TheDb.Exec(_L8("CREATE TABLE A(B BLOB)"));
       
   136 	TEST2(err, 1);
       
   137 	}
       
   138 
       
   139 void DoWriteBlobIncrL(const TDesC8& aData, 
       
   140 					  TTime& aT1, 
       
   141 					  TTime& aT2,
       
   142 					  TTime& aT3,
       
   143 					  TTime& aT4)
       
   144 	{
       
   145 	
       
   146 	RSqlBlobWriteStream strm;
       
   147 	CleanupClosePushL(strm);
       
   148 	
       
   149 	aT1.HomeTime();
       
   150 	strm.OpenL(TheDb, _L("A"), _L("B"));	
       
   151 	strm.WriteL(aData);
       
   152 	aT2.HomeTime();
       
   153 	
       
   154 	aT3.HomeTime();
       
   155 	strm.CommitL();
       
   156 	aT4.HomeTime();
       
   157 	
       
   158 	CleanupStack::PopAndDestroy(&strm);
       
   159 	}
       
   160 	
       
   161 void InsertZeroBlob(TBool aDoPrintTime = EFalse)
       
   162 	{
       
   163 	TBuf<100> sql;
       
   164 	sql.Format(_L("INSERT INTO A VALUES(zeroblob(%d))"), TheBlobSize);
       
   165 	
       
   166 	TTime t1, t2;
       
   167 	t1.HomeTime();
       
   168 	TInt err = TheDb.Exec(sql);
       
   169 	t2.HomeTime();
       
   170 	TEST2(err, 1);
       
   171 	TTimeIntervalMicroSeconds insertTime = t2.MicroSecondsFrom(t1);
       
   172 	
       
   173 	if(aDoPrintTime)
       
   174 		{
       
   175 		PrintWriteTime(insertTime, TTimeIntervalMicroSeconds(0), TTimeIntervalMicroSeconds(0));
       
   176 		}
       
   177 	}
       
   178 	
       
   179 void InsertRealBlob()
       
   180 	{
       
   181 	HBufC8* data = HBufC8::New(TheBlobSize);
       
   182 	TEST(data != NULL);
       
   183 	TPtr8 dataptr = data->Des();
       
   184 	dataptr.SetLength(TheBlobSize);
       
   185 	dataptr.Fill(TChar('A'));
       
   186 		
       
   187 	RSqlStatement stmt;
       
   188 	TInt err = stmt.Prepare(TheDb, _L8("INSERT INTO A VALUES(:Prm)"));
       
   189 	TEST2(err, KErrNone);
       
   190 
       
   191 	RSqlParamWriteStream strm;
       
   192 	err = strm.BindBinary(stmt, 0);
       
   193 	TEST2(err, KErrNone);
       
   194 	
       
   195 	TRAP(err, strm.WriteL(dataptr));
       
   196 	TEST2(err, KErrNone);
       
   197 	TRAP(err, strm.CommitL());
       
   198 	TEST2(err, KErrNone);
       
   199 	strm.Close();
       
   200 
       
   201 	err = stmt.Exec();	
       
   202 	TEST2(err, 1);			
       
   203 	stmt.Close();	
       
   204 	
       
   205 	delete data;
       
   206 	}
       
   207 	
       
   208 void InsertBlobIncr()
       
   209 	{
       
   210 	HBufC8* data = HBufC8::New(TheBlobSize);
       
   211 	TEST(data != NULL);
       
   212 	TPtr8 dataptr = data->Des();
       
   213 	dataptr.SetLength(TheBlobSize);
       
   214 	dataptr.Fill(TChar('B'));
       
   215 	
       
   216 	TTimeIntervalMicroSeconds totalTime, writeTime, commitTime;
       
   217 
       
   218 	TBuf<100> sql;
       
   219 	sql.Format(_L("INSERT INTO A VALUES(zeroblob(%d))"), TheBlobSize);
       
   220 
       
   221 	TTime t1, t2, subt1, subt2, subt3, subt4;
       
   222 	t1.HomeTime();
       
   223 	
       
   224 	TInt err = TheDb.Exec(_L8("BEGIN"));
       
   225 	TEST(err >= 0);
       
   226 	
       
   227 	err = TheDb.Exec(sql);
       
   228 	TEST2(err, 1);
       
   229 	
       
   230 	TRAP(err, DoWriteBlobIncrL(dataptr, subt1, subt2, subt3, subt4));
       
   231 	TEST2(err, KErrNone);
       
   232 	
       
   233 	err = TheDb.Exec(_L8("COMMIT"));
       
   234 	TEST(err >= 0);
       
   235 		
       
   236 	t2.HomeTime();
       
   237 	totalTime = t2.MicroSecondsFrom(t1);
       
   238 	
       
   239 	writeTime = subt2.MicroSecondsFrom(subt1);
       
   240 	commitTime = subt4.MicroSecondsFrom(subt3);
       
   241 	
       
   242 	PrintWriteTime(totalTime, writeTime, commitTime);
       
   243 	
       
   244 	delete data;
       
   245 	}
       
   246 	
       
   247 void InsertBlobExec()
       
   248 	{
       
   249 	HBufC8* buf = HBufC8::New(TheBlobSize * 2 + 100);
       
   250 	TEST(buf != NULL);
       
   251 	TPtr8 sql = buf->Des();
       
   252 	_LIT8(KStr, "INSERT INTO A VALUES(x'");
       
   253 	sql.SetLength(TheBlobSize * 2 + KStr().Length());
       
   254 	sql.Fill(TChar('A'));
       
   255 	sql.Replace(0, KStr().Length(), KStr);
       
   256 	sql.Append(_L8("')"));
       
   257 
       
   258 	TTime t1, t2;
       
   259 	
       
   260 	t1.HomeTime();		
       
   261 	TInt err = TheDb.Exec(sql);
       
   262 	t2.HomeTime();
       
   263 	TEST2(err, 1);
       
   264 
       
   265 	TTimeIntervalMicroSeconds totalTime = t2.MicroSecondsFrom(t1);
       
   266 	
       
   267 	PrintWriteTime(totalTime, TTimeIntervalMicroSeconds(0), TTimeIntervalMicroSeconds(0));
       
   268 	
       
   269 	delete buf;	
       
   270 	}
       
   271 
       
   272 void InsertBlobBindStreamPrm()
       
   273 	{
       
   274 	HBufC8* data = HBufC8::New(TheBlobSize);
       
   275 	TEST(data != NULL);
       
   276 	TPtr8 dataptr = data->Des();
       
   277 	dataptr.SetLength(TheBlobSize);
       
   278 	dataptr.Fill(TChar('A'));
       
   279 	
       
   280 	TTimeIntervalMicroSeconds totalTime, writeTime, commitTime;
       
   281 
       
   282 	TTime t1, t2, t3, t4, t5, t6;
       
   283 	t1.HomeTime();
       
   284 				
       
   285 	RSqlStatement stmt;
       
   286 	TInt err = stmt.Prepare(TheDb, _L8("INSERT INTO A VALUES(:Prm)"));
       
   287 	TEST2(err, KErrNone);
       
   288 
       
   289 	RSqlParamWriteStream strm;
       
   290 	err = strm.BindBinary(stmt, 0);
       
   291 	TEST2(err, KErrNone);
       
   292 	
       
   293 	t3.HomeTime();
       
   294 	TRAP(err, strm.WriteL(dataptr));
       
   295 	t4.HomeTime();
       
   296 	TEST2(err, KErrNone);
       
   297 	
       
   298 	t5.HomeTime();
       
   299 	TRAP(err, strm.CommitL());
       
   300 	t6.HomeTime();
       
   301 	TEST2(err, KErrNone);
       
   302 	
       
   303 	err = stmt.Exec();	
       
   304 	
       
   305 	strm.Close();
       
   306 	stmt.Close();	
       
   307 	
       
   308 	t2.HomeTime();
       
   309 	TEST2(err, 1);
       
   310 					
       
   311 	totalTime = t2.MicroSecondsFrom(t1);
       
   312 	
       
   313 	writeTime = t4.MicroSecondsFrom(t3);
       
   314 	commitTime = t6.MicroSecondsFrom(t5);
       
   315 	
       
   316 	PrintWriteTime(totalTime, writeTime, commitTime);
       
   317 			
       
   318 	delete data;	
       
   319 	}
       
   320 	
       
   321 void UpdateBlobIncr()
       
   322 	{
       
   323 	HBufC8* data = HBufC8::New(TheBlobSize);
       
   324 	TEST(data != NULL);
       
   325 	TPtr8 dataptr = data->Des();
       
   326 	dataptr.SetLength(TheBlobSize);
       
   327 	dataptr.Fill(TChar('A'));
       
   328 	
       
   329 	TTimeIntervalMicroSeconds totalTime, writeTime, commitTime;
       
   330 
       
   331 	TTime t1, t2, subt1, subt2, subt3, subt4;
       
   332 	t1.HomeTime();
       
   333 	
       
   334 	TInt err = TheDb.Exec(_L8("BEGIN"));
       
   335 	TEST(err >= 0);
       
   336 		
       
   337 	TRAP(err, DoWriteBlobIncrL(dataptr, subt1, subt2, subt3, subt4));
       
   338 	TEST2(err, KErrNone);
       
   339 	
       
   340 	err = TheDb.Exec(_L8("COMMIT"));
       
   341 	TEST(err >= 0);
       
   342 		
       
   343 	t2.HomeTime();
       
   344 	totalTime = t2.MicroSecondsFrom(t1);
       
   345 	
       
   346 	writeTime = subt2.MicroSecondsFrom(subt1);
       
   347 	commitTime = subt4.MicroSecondsFrom(subt3);
       
   348 	
       
   349 	PrintWriteTime(totalTime, writeTime, commitTime);
       
   350 	
       
   351 	delete data;
       
   352 	}
       
   353 	
       
   354 void UpdateBlobExec()
       
   355 	{
       
   356 	HBufC8* buf = HBufC8::New(TheBlobSize * 2 + 100);
       
   357 	TEST(buf != NULL);
       
   358 	TPtr8 sql = buf->Des();
       
   359 	_LIT8(KStr, "UPDATE A SET B=x'");
       
   360 	sql.SetLength(TheBlobSize * 2 + KStr().Length());
       
   361 	sql.Fill(TChar('B'));
       
   362 	sql.Replace(0, KStr().Length(), KStr);
       
   363 	sql.Append(_L8("'"));
       
   364 
       
   365 	TTime t1, t2;
       
   366 	t1.HomeTime();			
       
   367 	TInt err = TheDb.Exec(sql);	
       
   368 	t2.HomeTime();
       
   369 	TEST2(err, 1);
       
   370 
       
   371 	TTimeIntervalMicroSeconds totalTime = t2.MicroSecondsFrom(t1);
       
   372 	
       
   373 	PrintWriteTime(totalTime, TTimeIntervalMicroSeconds(0), TTimeIntervalMicroSeconds(0));
       
   374 	
       
   375 	delete buf;	
       
   376 	}
       
   377 
       
   378 void UpdateBlobBindStreamPrm()
       
   379 	{
       
   380 	HBufC8* data = HBufC8::New(TheBlobSize);
       
   381 	TEST(data != NULL);
       
   382 	TPtr8 dataptr = data->Des();
       
   383 	dataptr.SetLength(TheBlobSize);
       
   384 	dataptr.Fill(TChar('B'));
       
   385 	
       
   386 	TTimeIntervalMicroSeconds totalTime, writeTime, commitTime;
       
   387 
       
   388 	TTime t1, t2, t3, t4, t5, t6;
       
   389 	t1.HomeTime();
       
   390 				
       
   391 	RSqlStatement stmt;
       
   392 	TInt err = stmt.Prepare(TheDb, _L8("UPDATE A SET B=(:Prm)"));
       
   393 	TEST2(err, KErrNone);
       
   394 
       
   395 	RSqlParamWriteStream strm;
       
   396 	err = strm.BindBinary(stmt, 0);
       
   397 	TEST2(err, KErrNone);
       
   398 	
       
   399 	t3.HomeTime();;
       
   400 	TRAP(err, strm.WriteL(dataptr));
       
   401 	t4.HomeTime();
       
   402 	TEST2(err, KErrNone);
       
   403 	
       
   404 	t5.HomeTime();
       
   405 	TRAP(err, strm.CommitL());
       
   406 	t6.HomeTime();
       
   407 	TEST2(err, KErrNone);
       
   408 	
       
   409 	err = stmt.Exec();	
       
   410 
       
   411 	strm.Close();		
       
   412 	stmt.Close();	
       
   413 
       
   414 	t2.HomeTime();
       
   415 	TEST2(err, 1);
       
   416 	
       
   417 	totalTime = t2.MicroSecondsFrom(t1);
       
   418 	
       
   419 	writeTime = t4.MicroSecondsFrom(t3);
       
   420 	commitTime = t6.MicroSecondsFrom(t5);
       
   421 	
       
   422 	PrintWriteTime(totalTime, writeTime, commitTime);
       
   423 			
       
   424 	delete data;	
       
   425 	}
       
   426 
       
   427 /**
       
   428 @SYMTestCaseID			SYSLIB-SQL-UT-4084
       
   429 @SYMTestCaseDesc		SQL, BLOB write, performance tests.
       
   430 						Tests insertion and updates of BLOBs using the old
       
   431 						APIs and the new RSqlBlobWriteStream APIs.
       
   432 @SYMTestPriority		Medium
       
   433 @SYMTestActions			Insertion and updates of blobs using the old and new APIs.
       
   434 @SYMTestExpectedResults Test must not fail
       
   435 @SYMREQ					REQ5912
       
   436 */
       
   437 void BlobWriteTest()
       
   438 	{	
       
   439 	TheTest.Printf(_L("Blob size=%d Kb\r\n"), TheBlobSize / 1024);
       
   440 	
       
   441 	//Insert a blob
       
   442 	TheTest.Printf(_L("==================================================================\r\n"));
       
   443 	
       
   444 	CreateTestDb();
       
   445 	TheTest.Printf(_L("INSERT zeroblob - RSqlDatabase::Exec()\r\n"));
       
   446 	PrintFileSize(TheDb);
       
   447 	InsertZeroBlob(ETrue);
       
   448 	PrintFileSize(TheDb);
       
   449 	TheDb.Close();
       
   450 	(void)RSqlDatabase::Delete(TheDbFileName);
       
   451 				
       
   452 	CreateTestDb();
       
   453 	TheTest.Printf(_L("INSERT blob - RSqlParamWriteStream\r\n"));
       
   454 	PrintFileSize(TheDb);
       
   455 	InsertBlobBindStreamPrm();
       
   456 	PrintFileSize(TheDb);
       
   457 	TheDb.Close();
       
   458 	(void)RSqlDatabase::Delete(TheDbFileName);
       
   459 	
       
   460 	CreateTestDb();
       
   461 	TheTest.Printf(_L("INSERT blob - RSqlDatabase::Exec()\r\n"));
       
   462 	PrintFileSize(TheDb);
       
   463 	InsertBlobExec();
       
   464 	PrintFileSize(TheDb);
       
   465 	TheDb.Close();
       
   466 	(void)RSqlDatabase::Delete(TheDbFileName);
       
   467 	
       
   468 	CreateTestDb();
       
   469 	TheTest.Printf(_L("INSERT blob - RSqlBlobWriteStream + transaction\r\n"));
       
   470 	PrintFileSize(TheDb);
       
   471 	InsertBlobIncr();
       
   472 	PrintFileSize(TheDb);
       
   473 	TheDb.Close();
       
   474 	(void)RSqlDatabase::Delete(TheDbFileName);
       
   475 						
       
   476 	// Update a blob 
       
   477 	TheTest.Printf(_L("==================================================================\r\n"));
       
   478 		
       
   479 	CreateTestDb();
       
   480 	TheTest.Printf(_L("UPDATE zeroblob - RSqlParamWriteStream\r\n"));
       
   481 	PrintFileSize(TheDb);
       
   482 	InsertZeroBlob();
       
   483 	UpdateBlobBindStreamPrm();
       
   484 	PrintFileSize(TheDb);
       
   485 	TheDb.Close();
       
   486 	(void)RSqlDatabase::Delete(TheDbFileName);
       
   487 		
       
   488 	CreateTestDb();
       
   489 	TheTest.Printf(_L("UPDATE blob - RSqlParamWriteStream\r\n"));
       
   490 	PrintFileSize(TheDb);
       
   491 	InsertRealBlob();
       
   492 	UpdateBlobBindStreamPrm();
       
   493 	PrintFileSize(TheDb);
       
   494 	TheDb.Close();
       
   495 	(void)RSqlDatabase::Delete(TheDbFileName);
       
   496 			
       
   497 	CreateTestDb();
       
   498 	TheTest.Printf(_L("UPDATE zeroblob - RSqlDatabase::Exec()\r\n"));
       
   499 	PrintFileSize(TheDb);
       
   500 	InsertZeroBlob();
       
   501 	UpdateBlobExec();
       
   502 	PrintFileSize(TheDb);
       
   503 	TheDb.Close();
       
   504 	(void)RSqlDatabase::Delete(TheDbFileName);
       
   505 		
       
   506 	CreateTestDb();
       
   507 	TheTest.Printf(_L("UPDATE blob - RSqlDatabase::Exec()\r\n"));
       
   508 	PrintFileSize(TheDb);
       
   509 	InsertRealBlob();
       
   510 	UpdateBlobExec();
       
   511 	PrintFileSize(TheDb);
       
   512 	TheDb.Close();
       
   513 	(void)RSqlDatabase::Delete(TheDbFileName);
       
   514 		
       
   515 	CreateTestDb();
       
   516 	TheTest.Printf(_L("UPDATE zeroblob - RSqlBlobWriteStream + transaction\r\n"));
       
   517 	PrintFileSize(TheDb);
       
   518 	InsertZeroBlob();
       
   519 	UpdateBlobIncr();
       
   520 	PrintFileSize(TheDb);
       
   521 	TheDb.Close();
       
   522 	(void)RSqlDatabase::Delete(TheDbFileName);
       
   523 		
       
   524 	CreateTestDb();
       
   525 	TheTest.Printf(_L("UPDATE blob - RSqlBlobWriteStream + transaction\r\n"));
       
   526 	PrintFileSize(TheDb);
       
   527 	InsertRealBlob();
       
   528 	UpdateBlobIncr();
       
   529 	PrintFileSize(TheDb);
       
   530 	TheDb.Close();
       
   531 	(void)RSqlDatabase::Delete(TheDbFileName);	
       
   532 	}
       
   533 
       
   534 void DoReadBlobIncrL(TDes8& aDes)
       
   535 	{
       
   536 	TTime t1, t2, t3, t4;
       
   537 	
       
   538 	TTimeIntervalMicroSeconds openTime, readTime; 
       
   539 	
       
   540 	RSqlBlobReadStream strm;
       
   541 	CleanupClosePushL(strm);
       
   542 	
       
   543 	t1.HomeTime();
       
   544 	strm.OpenL(TheDb, _L("A"), _L("B"), 1);
       
   545 	t2.HomeTime();
       
   546 	
       
   547 	openTime = t2.MicroSecondsFrom(t1);
       
   548 		
       
   549 	t3.HomeTime();
       
   550 	strm.ReadL(aDes);
       
   551 	t4.HomeTime();
       
   552 
       
   553 	readTime = t4.MicroSecondsFrom(t3);
       
   554 	
       
   555 	PrintReadTime(openTime, readTime);
       
   556 
       
   557 	CleanupStack::PopAndDestroy(&strm);
       
   558 	}
       
   559 
       
   560 void ReadBlobIncr()
       
   561 	{
       
   562 	HBufC8* data = HBufC8::New(TheBlobSize);
       
   563 	TEST(data != NULL);
       
   564 	TPtr8 dataptr = data->Des();
       
   565 	
       
   566 	TRAPD(err, DoReadBlobIncrL(dataptr));
       
   567 	TEST2(err, KErrNone);
       
   568 	TEST2(dataptr.Length(), TheBlobSize);
       
   569 	
       
   570 	delete data;
       
   571 	}
       
   572 
       
   573 void ReadBlobColDes()
       
   574 	{
       
   575 	HBufC8* data = HBufC8::New(TheBlobSize);
       
   576 	TEST(data != NULL);
       
   577 	TPtr8 dataptr = data->Des();
       
   578 	
       
   579 	TTime t1, t2, t3, t4, t5, t6;
       
   580 	TTimeIntervalMicroSeconds prepareTime, nextTime, readTime;
       
   581 	
       
   582 	RSqlStatement stmt;
       
   583 	t1.HomeTime();
       
   584 	TInt err = stmt.Prepare(TheDb, _L8("SELECT B FROM A WHERE ROWID=1"));
       
   585 	t2.HomeTime();
       
   586 	TEST2(err, KErrNone);
       
   587 	prepareTime = t2.MicroSecondsFrom(t1);
       
   588 
       
   589 	t3.HomeTime();
       
   590 	err = stmt.Next();
       
   591 	t4.HomeTime();
       
   592 	TEST2(err, KSqlAtRow);
       
   593 	nextTime = t4.MicroSecondsFrom(t3);
       
   594 	
       
   595 	t5.HomeTime();
       
   596 	err = stmt.ColumnBinary(0, dataptr);
       
   597 	t6.HomeTime();
       
   598 	TEST2(err, KErrNone);
       
   599 	TEST2(dataptr.Length(), TheBlobSize);
       
   600 	readTime = t6.MicroSecondsFrom(t5);
       
   601 		
       
   602 	PrintReadTime(prepareTime, nextTime, readTime);
       
   603 	stmt.Close();
       
   604 	
       
   605 	delete data;
       
   606 	}
       
   607 
       
   608 void ReadBlobColPtr()
       
   609 	{
       
   610 	TTime t1, t2, t3, t4, t5, t6;
       
   611 	TTimeIntervalMicroSeconds prepareTime, nextTime, readTime;
       
   612 	
       
   613 	RSqlStatement stmt;
       
   614 	t1.HomeTime();
       
   615 	TInt err = stmt.Prepare(TheDb, _L8("SELECT B FROM A WHERE ROWID=1"));
       
   616 	t2.HomeTime();
       
   617 	TEST2(err, KErrNone);
       
   618 	prepareTime = t2.MicroSecondsFrom(t1);
       
   619 	
       
   620 	t3.HomeTime();
       
   621 	err = stmt.Next();
       
   622 	t4.HomeTime();
       
   623 	TEST2(err, KSqlAtRow);
       
   624 	nextTime = t4.MicroSecondsFrom(t3);
       
   625 	
       
   626 	TPtrC8 data;
       
   627 	t5.HomeTime();
       
   628 	err = stmt.ColumnBinary(0, data);
       
   629 	t6.HomeTime();
       
   630 	TEST2(err, KErrNone);
       
   631 	TEST2(data.Length(), TheBlobSize);
       
   632 	readTime = t6.MicroSecondsFrom(t5);
       
   633 
       
   634 	PrintReadTime(prepareTime, nextTime, readTime);
       
   635 	stmt.Close();
       
   636 	}
       
   637 
       
   638 void ReadBlobStreamCol()
       
   639 	{
       
   640 	HBufC8* data = HBufC8::New(TheBlobSize);
       
   641 	TEST(data != NULL);
       
   642 	TPtr8 dataptr = data->Des();
       
   643 	
       
   644 	TTime t1, t2, t3, t4, t5, t6;
       
   645 	TTimeIntervalMicroSeconds prepareTime, nextTime, readTime;
       
   646 	
       
   647 	RSqlStatement stmt;
       
   648 	t1.HomeTime();
       
   649 	TInt err = stmt.Prepare(TheDb, _L8("SELECT B FROM A WHERE ROWID=1"));
       
   650 	t2.HomeTime();
       
   651 	TEST2(err, KErrNone);
       
   652 	prepareTime = t2.MicroSecondsFrom(t1);
       
   653 
       
   654 	t3.HomeTime();
       
   655 	err = stmt.Next();
       
   656 	t4.HomeTime();
       
   657 	TEST2(err, KSqlAtRow);
       
   658 	nextTime = t4.MicroSecondsFrom(t3);
       
   659 
       
   660 	RSqlColumnReadStream strm;
       
   661 	t5.HomeTime();
       
   662 	err = strm.ColumnBinary(stmt, 0);
       
   663 	TEST2(err, KErrNone);
       
   664 	TRAP(err, strm.ReadL(dataptr));
       
   665 	t6.HomeTime();
       
   666 	TEST2(err, KErrNone);
       
   667 	TEST2(dataptr.Length(), TheBlobSize);
       
   668 	readTime = t6.MicroSecondsFrom(t5);
       
   669 
       
   670 	strm.Close();
       
   671 	stmt.Close();
       
   672 	
       
   673 	PrintReadTime(prepareTime, nextTime, readTime);
       
   674 		
       
   675 	delete data;
       
   676 	}
       
   677 	
       
   678 /**
       
   679 @SYMTestCaseID			SYSLIB-SQL-UT-4085
       
   680 @SYMTestCaseDesc		SQL, BLOB read, performance tests.
       
   681 						Tests retrieval of BLOBs using the old
       
   682 						APIs and the new RSqlBlobReadStream APIs.
       
   683 @SYMTestPriority		Medium
       
   684 @SYMTestActions			Retrieval of blobs using the old and new APIs.
       
   685 @SYMTestExpectedResults Test must not fail
       
   686 @SYMREQ					REQ5912
       
   687 */
       
   688 void BlobReadTest()
       
   689 	{
       
   690 	TheTest.Printf(_L("Blob size=%d Kb\r\n"), TheBlobSize / 1024);
       
   691 	
       
   692 	// Insert a blob
       
   693 	TheTest.Printf(_L("==================================================================\r\n"));
       
   694 	TheTest.Printf(_L("Insert blob\r\n"));
       
   695 		
       
   696 	CreateTestDb();
       
   697 	PrintFileSize(TheDb);
       
   698 	InsertBlobExec();
       
   699 	PrintFileSize(TheDb);
       
   700 	TheDb.Close();
       
   701 		
       
   702 	// Read the blob
       
   703 	TheTest.Printf(_L("==================================================================\r\n"));
       
   704 		
       
   705 	TheTest.Printf(_L("Read blob - RSqlBlobReadStream\r\n"));	
       
   706 	TInt err = TheDb.Open(TheDbFileName);
       
   707 	TEST2(err, KErrNone);
       
   708 	ReadBlobIncr();
       
   709 	TheDb.Close();
       
   710 
       
   711 	TheTest.Printf(_L("Read blob - RSqlStatement::ColumnBinary(TInt, TDes8&)\r\n"));	
       
   712 	err = TheDb.Open(TheDbFileName);
       
   713 	TEST2(err, KErrNone);
       
   714 	ReadBlobColDes();
       
   715 	TheDb.Close();
       
   716 		
       
   717 	TheTest.Printf(_L("Read blob - RSqlStatement::ColumnBinary(TInt, TPtrC8&)\r\n"));	
       
   718 	err = TheDb.Open(TheDbFileName);
       
   719 	TEST2(err, KErrNone);
       
   720 	ReadBlobColPtr();
       
   721 	TheDb.Close();
       
   722 		
       
   723 	TheTest.Printf(_L("Read blob - RSqlColumnReadStream\r\n"));	
       
   724 	err = TheDb.Open(TheDbFileName);
       
   725 	TEST2(err, KErrNone);
       
   726 	ReadBlobStreamCol();
       
   727 	TheDb.Close();
       
   728 		
       
   729 	(void)RSqlDatabase::Delete(TheDbFileName);
       
   730 	}
       
   731 	
       
   732 /**
       
   733 @SYMTestCaseID			SYSLIB-SQL-UT-4115
       
   734 @SYMTestCaseDesc		SQL, sequential BLOB writes, performance tests.
       
   735 						Tests sequentially writing 32Kb blocks to a 1.125Mb blob
       
   736 						using the new RSqlBlobWriteStream APIs to examine
       
   737 					    the write performance at different stages in the 
       
   738 						sequence.
       
   739 @SYMTestPriority		Medium
       
   740 @SYMTestActions			Sequential writing of a blob using the new RSqlBlobWriteStream APIs.
       
   741 @SYMTestExpectedResults Test must not fail
       
   742 @SYMREQ					REQ5912
       
   743 */
       
   744 void SequentialWriteTestL()
       
   745 	{
       
   746 	const TInt KBufLen = 32768; // 32Kb
       
   747 	HBufC8* buf = HBufC8::NewL(KBufLen);
       
   748 	TPtr8 dataPtr =	buf->Des();
       
   749 	dataPtr.Fill('A', KBufLen);	
       
   750 	
       
   751 	CreateTestDb();
       
   752 	InsertZeroBlob(); // insert zeroblob of "TheBlobSize" size
       
   753 		
       
   754 	RSqlBlobWriteStream strm;
       
   755 	strm.OpenL(TheDb, _L("A"), _L("B"));	
       
   756 								
       
   757 	// Sequentially write 32Kb blocks of data to the 
       
   758 	// blob until the 1Mb cache is full and writes to the disk begin.
       
   759 	// 32 * 32Kb = 1Mb = soft heap limit
       
   760 	const TInt KItCount = TheBlobSize / KBufLen - 1;
       
   761 	for(TInt i = 1; i <= KItCount; ++i)
       
   762 		{
       
   763 		TheTest.Printf(_L("***Iteration %d\r\n"), i);
       
   764 		
       
   765 		PrintFileSize(TheDb);
       
   766 	
       
   767 		TTimeIntervalMicroSeconds writeTime;
       
   768 		TTime t1, t2;
       
   769 
       
   770 		t1.HomeTime();
       
   771 		strm.WriteL(dataPtr);
       
   772 		t2.HomeTime();		
       
   773 
       
   774 		writeTime = t2.MicroSecondsFrom(t1);
       
   775 							
       
   776 		PrintWriteTime(TTimeIntervalMicroSeconds(0), writeTime, TTimeIntervalMicroSeconds(0));		
       
   777 		PrintFileSize(TheDb);		
       
   778 		}	
       
   779 			
       
   780 	TTimeIntervalMicroSeconds commitTime;
       
   781 	TTime t3, t4;
       
   782 	t3.HomeTime();
       
   783 	strm.CommitL();
       
   784 	t4.HomeTime();	
       
   785 	commitTime = t4.MicroSecondsFrom(t3);
       
   786 		
       
   787 	PrintWriteTime(TTimeIntervalMicroSeconds(0), TTimeIntervalMicroSeconds(0), commitTime);		
       
   788 	PrintFileSize(TheDb);		
       
   789 			
       
   790 	strm.Close();		
       
   791 	TheDb.Close();
       
   792 	(void)RSqlDatabase::Delete(TheDbFileName);
       
   793 		
       
   794 	delete buf;
       
   795 	}
       
   796 	
       
   797 /**
       
   798 @SYMTestCaseID			SYSLIB-SQL-UT-4116
       
   799 @SYMTestCaseDesc		SQL, transaction sequential BLOB writes, performance tests.
       
   800 						Tests sequentially writing 32Kb blocks to a 1.125Mb blob
       
   801 						within a transaction, using the new RSqlBlobWriteStream APIs,
       
   802 						to examine the write performance at different stages in the 
       
   803 						sequence.
       
   804 @SYMTestPriority		Medium
       
   805 @SYMTestActions			Sequential writing of a blob within a transactions, using the 
       
   806 						new RSqlBlobWriteStream APIs.
       
   807 @SYMTestExpectedResults Test must not fail
       
   808 @SYMREQ					REQ5912
       
   809 */
       
   810 void TransSequentialWriteTestL()
       
   811 	{
       
   812 	const TInt KBufLen = 32768; // 32Kb
       
   813 	HBufC8* buf = HBufC8::NewL(KBufLen);
       
   814 	TPtr8 dataPtr =	buf->Des();
       
   815 	dataPtr.Fill('A', KBufLen);	
       
   816 	
       
   817 	CreateTestDb();
       
   818 	InsertZeroBlob(); // insert zeroblob of "TheBlobSize" size
       
   819 		
       
   820 	RSqlBlobWriteStream strm;
       
   821 	strm.OpenL(TheDb, _L("A"), _L("B"));
       
   822 	
       
   823 	TInt err = TheDb.Exec(_L8("BEGIN"));
       
   824 	TEST(err >= 0);	
       
   825 								
       
   826 	// Sequentially write 32Kb blocks of data to the 
       
   827 	// blob until the 1Mb cache is full and writes to the disk begin.
       
   828 	// 32 * 32Kb = 1Mb = soft heap limit
       
   829 	const TInt KItCount = TheBlobSize / KBufLen - 1;
       
   830 	for(TInt i = 1; i <= KItCount; ++i)
       
   831 		{
       
   832 		TheTest.Printf(_L("***Iteration %d\r\n"), i);
       
   833 		
       
   834 		PrintFileSize(TheDb);
       
   835 	
       
   836 		TTimeIntervalMicroSeconds writeTime;
       
   837 		TTime t1, t2;
       
   838 		
       
   839 		t1.HomeTime();
       
   840 		strm.WriteL(dataPtr);
       
   841 		t2.HomeTime();	
       
   842 
       
   843 		writeTime = t2.MicroSecondsFrom(t1);
       
   844 							
       
   845 		PrintWriteTime(TTimeIntervalMicroSeconds(0), writeTime, TTimeIntervalMicroSeconds(0));		
       
   846 		PrintFileSize(TheDb);		
       
   847 		}	
       
   848 		
       
   849 	TTimeIntervalMicroSeconds commitTime;
       
   850 	TTime t3, t4;
       
   851 	
       
   852 	t3.HomeTime();
       
   853 	strm.CommitL();
       
   854 	t4.HomeTime();	
       
   855 	commitTime = t4.MicroSecondsFrom(t3);
       
   856 
       
   857 	PrintWriteTime(TTimeIntervalMicroSeconds(0), TTimeIntervalMicroSeconds(0), commitTime);		
       
   858 	PrintFileSize(TheDb);		
       
   859 		
       
   860 	TTime t5, t6;
       
   861 	t5.HomeTime();	
       
   862 	err = TheDb.Exec(_L8("COMMIT"));
       
   863 	t6.HomeTime();	
       
   864 	TEST(err >= 0);
       
   865 	
       
   866 	TTimeIntervalMicroSeconds transCommitTime = t6.MicroSecondsFrom(t5);		
       
   867 	PrintWriteTime(TTimeIntervalMicroSeconds(0), TTimeIntervalMicroSeconds(0), transCommitTime);		
       
   868 	PrintFileSize(TheDb);	
       
   869 			
       
   870 	strm.Close();		
       
   871 	TheDb.Close();
       
   872 	(void)RSqlDatabase::Delete(TheDbFileName);
       
   873 		
       
   874 	delete buf;
       
   875 	}
       
   876 
       
   877 /**
       
   878 @SYMTestCaseID			SYSLIB-SQL-UT-4117
       
   879 @SYMTestCaseDesc		SQL, whole BLOB write, performance tests.
       
   880 						Tests writing a 256Kb data block to a 256Kb blob to examine the
       
   881 						relative performance of the TSqlBlob and RSqlBlobWriteStream APIs.
       
   882 @SYMTestPriority		Medium
       
   883 @SYMTestActions			Whole update of a blob using the new TSqlBlob and RSqlBlobWriteStream APIs.
       
   884 @SYMTestExpectedResults Test must not fail
       
   885 @SYMREQ					REQ5912
       
   886 */
       
   887 void WholeWriteTestL()
       
   888 	{
       
   889 	TInt bufLen = TheBlobSize; 
       
   890 	HBufC8* buf = HBufC8::NewL(bufLen);
       
   891 	TPtr8 dataPtr =	buf->Des();
       
   892 	dataPtr.Fill('Z', bufLen);	
       
   893 	
       
   894 	CreateTestDb();
       
   895 	InsertRealBlob(); // insert blob of "TheBlobSize" size
       
   896 			
       
   897 	TheTest.Printf(_L("***WholeWriteTestL - %dKb blob \r\n"), TheBlobSize / 1024);		
       
   898 	PrintFileSize(TheDb);
       
   899 	
       
   900 	// TSqlBlob::Set
       
   901 	TTimeIntervalMicroSeconds writeTime;
       
   902 	TTime t1, t2, t3, t4;
       
   903 
       
   904 	t1.HomeTime();
       
   905 	TSqlBlob::SetL(TheDb, _L("A"), _L("B"), dataPtr);	
       
   906 	t2.HomeTime();	
       
   907 		
       
   908 	writeTime = t2.MicroSecondsFrom(t1);
       
   909 								
       
   910 	PrintWriteTime(TTimeIntervalMicroSeconds(0), writeTime, TTimeIntervalMicroSeconds(0));		
       
   911 	PrintFileSize(TheDb);
       
   912 	
       
   913 	// to avoid caching issues, close and re-create the database for the next part
       
   914 	TheDb.Close();
       
   915 	(void)RSqlDatabase::Delete(TheDbFileName);		
       
   916 	CreateTestDb();
       
   917 	InsertRealBlob(); // insert blob of "TheBlobSize" size
       
   918 	PrintFileSize(TheDb);
       
   919 
       
   920 	// RSqlBlobWriteStream::WriteL
       
   921 	t3.HomeTime();
       
   922 	RSqlBlobWriteStream strm;
       
   923 	CleanupClosePushL(strm);
       
   924 	strm.OpenL(TheDb, _L("A"), _L("B"));	
       
   925 	strm.WriteL(dataPtr);
       
   926 	CleanupStack::PopAndDestroy(&strm);
       
   927 	t4.HomeTime();	
       
   928 		
       
   929 	writeTime = t4.MicroSecondsFrom(t3);
       
   930 							
       
   931 	PrintWriteTime(TTimeIntervalMicroSeconds(0), writeTime, TTimeIntervalMicroSeconds(0));		
       
   932 	PrintFileSize(TheDb);				
       
   933 				
       
   934 	TheDb.Close();
       
   935 	(void)RSqlDatabase::Delete(TheDbFileName);
       
   936 		
       
   937 	delete buf;
       
   938 	}
       
   939 	
       
   940 /**
       
   941 @SYMTestCaseID			SYSLIB-SQL-UT-4118
       
   942 @SYMTestCaseDesc		SQL, transaction whole BLOB write, performance tests.
       
   943 						Tests writing a 256Kb data block to a 256Kb blob, within a transaction,
       
   944 						to examine the relative performance of the TSqlBlob and RSqlBlobWriteStream APIs.
       
   945 @SYMTestPriority		Medium
       
   946 @SYMTestActions			Whole update of a blob, within a transaction, using the new TSqlBlob and 
       
   947 						RSqlBlobWriteStream APIs.
       
   948 @SYMTestExpectedResults Test must not fail
       
   949 @SYMREQ					REQ5912
       
   950 */
       
   951 void TransWholeWriteTestL()
       
   952 	{
       
   953 	TInt bufLen = TheBlobSize;
       
   954 	HBufC8* buf = HBufC8::NewL(bufLen);
       
   955 	TPtr8 dataPtr =	buf->Des();
       
   956 	dataPtr.Fill('Z', bufLen);	
       
   957 	
       
   958 	CreateTestDb();
       
   959 	InsertRealBlob(); // insert blob of "TheBlobSize" size
       
   960 	
       
   961 	TheTest.Printf(_L("***TransWholeWriteTestL - %dKb blob\r\n"), TheBlobSize / 1024);	
       
   962 	PrintFileSize(TheDb);
       
   963 		
       
   964 	// TSqlBlob::Set
       
   965 	TTimeIntervalMicroSeconds writeTime;
       
   966 	TTime t1, t2, t3, t4;
       
   967 
       
   968 	t1.HomeTime();
       
   969 	TInt err = TheDb.Exec(_L8("BEGIN"));
       
   970 	TEST(err >= 0);		
       
   971 	TSqlBlob::SetL(TheDb, _L("A"), _L("B"), dataPtr);			
       
   972 	err = TheDb.Exec(_L8("COMMIT"));
       
   973 	t2.HomeTime();	
       
   974 	TEST(err >= 0);	
       
   975 
       
   976 	writeTime = t2.MicroSecondsFrom(t1);
       
   977 							
       
   978 	PrintWriteTime(TTimeIntervalMicroSeconds(0), writeTime, TTimeIntervalMicroSeconds(0));		
       
   979 	PrintFileSize(TheDb);	
       
   980 	
       
   981 	// to avoid caching issues, close and re-create the database for the next part
       
   982 	TheDb.Close();
       
   983 	(void)RSqlDatabase::Delete(TheDbFileName);
       
   984 	CreateTestDb();
       
   985 	InsertRealBlob(); // insert blob of "TheBlobSize" size
       
   986 	PrintFileSize(TheDb);
       
   987 	
       
   988 	// RSqlBlobWriteStream::WriteL
       
   989 	t3.HomeTime();
       
   990 	err = TheDb.Exec(_L8("BEGIN"));
       
   991 	TEST(err >= 0);	
       
   992 	RSqlBlobWriteStream strm;
       
   993 	CleanupClosePushL(strm);
       
   994 	strm.OpenL(TheDb, _L("A"), _L("B"));	
       
   995 	strm.WriteL(dataPtr);
       
   996 	CleanupStack::PopAndDestroy(&strm);
       
   997 	err = TheDb.Exec(_L8("COMMIT"));
       
   998 	t4.HomeTime();
       
   999 	TEST(err >= 0);	
       
  1000 
       
  1001 	writeTime = t4.MicroSecondsFrom(t3);
       
  1002 							
       
  1003 	PrintWriteTime(TTimeIntervalMicroSeconds(0), writeTime, TTimeIntervalMicroSeconds(0));		
       
  1004 	PrintFileSize(TheDb);				
       
  1005 				
       
  1006 	TheDb.Close();
       
  1007 	(void)RSqlDatabase::Delete(TheDbFileName);
       
  1008 		
       
  1009 	delete buf;
       
  1010 	}	
       
  1011 
       
  1012 /**
       
  1013 @SYMTestCaseID			SYSLIB-SQL-UT-4119
       
  1014 @SYMTestCaseDesc		SQL, whole BLOB read, performance tests.
       
  1015 						Tests reading a 256Kb blob in one block to examine the
       
  1016 						relative performance of the TSqlBlob and RSqlBlobReadStream APIs.
       
  1017 @SYMTestPriority		Medium
       
  1018 @SYMTestActions			Whole retrieval of a blob using the new TSqlBlob and RSqlBlobReadStream APIs.
       
  1019 @SYMTestExpectedResults Test must not fail
       
  1020 @SYMREQ					REQ5912
       
  1021 */	
       
  1022 void WholeReadTestL()
       
  1023 	{
       
  1024 	TInt bufLen = TheBlobSize; 
       
  1025 	HBufC8* buf = HBufC8::NewL(bufLen);
       
  1026 	TPtr8 dataPtr =	buf->Des();
       
  1027 	dataPtr.Fill('A', bufLen);	
       
  1028 	
       
  1029 	CreateTestDb();
       
  1030 	InsertRealBlob(); // insert blob of "TheBlobSize" size
       
  1031 	
       
  1032 	TheTest.Printf(_L("***WholeReadTestL - %dKb blob \r\n"), TheBlobSize / 1024);
       
  1033 	PrintFileSize(TheDb);
       
  1034 	
       
  1035 	// TSqlBlob::GetLC
       
  1036 	TTimeIntervalMicroSeconds readTime;
       
  1037 	TTime t1, t2, t3, t4, t5, t6;
       
  1038 
       
  1039 	t1.HomeTime();
       
  1040 	HBufC8* readBuf = TSqlBlob::GetLC(TheDb, _L("A"), _L("B"));
       
  1041 	t2.HomeTime();
       
  1042 	TEST(readBuf->Des().Compare(buf->Des()) == 0);
       
  1043 	
       
  1044 	readTime = t2.MicroSecondsFrom(t1);
       
  1045 							
       
  1046 	PrintReadTime(TTimeIntervalMicroSeconds(0), readTime);
       
  1047 	PrintFileSize(TheDb);				
       
  1048 	CleanupStack::PopAndDestroy(readBuf);
       
  1049 	
       
  1050 	// to avoid caching issues, close and re-create the database for the next part
       
  1051 	TheDb.Close();
       
  1052 	(void)RSqlDatabase::Delete(TheDbFileName);
       
  1053 	CreateTestDb();
       
  1054 	InsertRealBlob(); // insert blob of "TheBlobSize" size
       
  1055 	PrintFileSize(TheDb);
       
  1056 	
       
  1057 	// TSqlBlob::Get
       
  1058 	HBufC8* preBuf = HBufC8::NewLC(bufLen);
       
  1059 	TPtr8 preBufPtr(preBuf->Des());
       
  1060 	t3.HomeTime();
       
  1061 	TInt err = TSqlBlob::Get(TheDb, _L("A"), _L("B"), preBufPtr);	
       
  1062 	t4.HomeTime();
       
  1063 	TEST2(err, KErrNone);
       
  1064 	TEST(preBufPtr.Compare(buf->Des()) == 0);
       
  1065 
       
  1066 	readTime = t4.MicroSecondsFrom(t3);
       
  1067 							
       
  1068 	PrintReadTime(TTimeIntervalMicroSeconds(0), readTime);
       
  1069 	PrintFileSize(TheDb);				
       
  1070 	CleanupStack::PopAndDestroy(preBuf);
       
  1071 	
       
  1072 	// to avoid caching issues, close and re-create the database for the next part
       
  1073 	TheDb.Close();
       
  1074 	(void)RSqlDatabase::Delete(TheDbFileName);
       
  1075 	CreateTestDb();
       
  1076 	InsertRealBlob(); // insert blob of "TheBlobSize" size
       
  1077 	PrintFileSize(TheDb);
       
  1078 	
       
  1079 	// RSqlBlobReadStream::ReadL
       
  1080 	preBuf = HBufC8::NewLC(bufLen);	
       
  1081 	TPtr8 preBufP(preBuf->Des());
       
  1082 	t5.HomeTime();
       
  1083 	RSqlBlobReadStream strm;
       
  1084 	CleanupClosePushL(strm);
       
  1085 	strm.OpenL(TheDb, _L("A"), _L("B"));
       
  1086 	strm.ReadL(preBufP, bufLen);
       
  1087 	CleanupStack::PopAndDestroy(&strm);
       
  1088 	t6.HomeTime();
       
  1089 	TEST(preBufP.Compare(buf->Des()) == 0);
       
  1090 		
       
  1091 	readTime = t6.MicroSecondsFrom(t5);
       
  1092 							
       
  1093 	PrintReadTime(TTimeIntervalMicroSeconds(0), readTime);
       
  1094 	PrintFileSize(TheDb);	
       
  1095 	CleanupStack::PopAndDestroy(preBuf);
       
  1096 			
       
  1097 	TheDb.Close();
       
  1098 	(void)RSqlDatabase::Delete(TheDbFileName);
       
  1099 		
       
  1100 	delete buf;
       
  1101 	}
       
  1102 ///////////////////////////////////////////////////////////////////////////////////
       
  1103 ///////////////////////////////////////////////////////////////////////////////////
       
  1104 
       
  1105 void DoTests()
       
  1106 	{
       
  1107 	TheTest.Start(_L("@SYMTestCaseID:SYSLIB-SQL-UT-4084 SQL, BLOB write, performance tests\r\n"));
       
  1108 	BlobWriteTest();
       
  1109 	
       
  1110 	TheTest.Next(_L("@SYMTestCaseID:SYSLIB-SQL-UT-4085 SQL, BLOB read, performance tests\r\n"));
       
  1111 	BlobReadTest();
       
  1112 
       
  1113 	TheTest.Printf(_L("==================================================================\r\n"));
       
  1114 	
       
  1115 	// Bigger blob tests - only on hardware, release mode
       
  1116 #if !defined __WINS__ && !defined __WINSCW__ && !defined _DEBUG
       
  1117 	
       
  1118 	TheBlobSize = 1024 * 1024 + 128 * 1024;//1.125Mb 
       
  1119 
       
  1120 	TheTest.Next(_L("@SYMTestCaseID:SYSLIB-SQL-UT-4115 SQL, sequential BLOB writes, performance tests\r\n"));
       
  1121 	TRAPD(err, SequentialWriteTestL());
       
  1122 	TEST2(err, KErrNone);
       
  1123 	
       
  1124 	TheTest.Next(_L("@SYMTestCaseID:SYSLIB-SQL-UT-4116 SQL, transaction sequential BLOB writes, performance tests\r\n"));
       
  1125 	TRAP(err, TransSequentialWriteTestL());
       
  1126 	TEST2(err, KErrNone);
       
  1127 		
       
  1128 	TheBlobSize = 256 * 1024 ; // 256Kb
       
  1129 		
       
  1130 	TheTest.Next(_L("@SYMTestCaseID:SYSLIB-SQL-UT-4117 SQL, whole BLOB write, performance tests\r\n"));
       
  1131 	TRAP(err, WholeWriteTestL());
       
  1132 	TEST2(err, KErrNone);
       
  1133 	
       
  1134 	TheTest.Next(_L("@SYMTestCaseID:SYSLIB-SQL-UT-4118 SQL, transaction whole BLOB write, performance tests\r\n"));
       
  1135 	TRAP(err, TransWholeWriteTestL());
       
  1136 	TEST2(err, KErrNone);
       
  1137 	
       
  1138 	TheTest.Next(_L("@SYMTestCaseID:SYSLIB-SQL-UT-4119 SQL, whole BLOB read, performance tests\r\n"));
       
  1139 	TRAP(err, WholeReadTestL());
       
  1140 	TEST2(err, KErrNone);
       
  1141 	
       
  1142 #endif//!defined __WINS__ && !defined __WINSCW__ && !defined _DEBUG
       
  1143 	}
       
  1144 
       
  1145 //Usage: "t_sqlperformance2 [<drive letter>:]"
       
  1146 
       
  1147 TInt E32Main()
       
  1148 	{
       
  1149 	TheTest.Title();
       
  1150 
       
  1151 	CTrapCleanup* tc = CTrapCleanup::New();
       
  1152 	TheTest(tc != NULL);
       
  1153 
       
  1154 	__UHEAP_MARK;
       
  1155 
       
  1156 	User::CommandLine(TheCmd);
       
  1157 	TheCmd.TrimAll();
       
  1158 	if(TheCmd.Length() > 0)
       
  1159 		{
       
  1160 		TheDriveName.Copy(TheCmd);
       
  1161 		}
       
  1162 
       
  1163 	_LIT(KDbName, "c:\\test\\t_sqlperformance2.db");
       
  1164 	TheParse.Set(TheDriveName, &KDbName, 0);
       
  1165 	const TDesC& dbFilePath = TheParse.FullName();
       
  1166 	TheDbFileName.Copy(dbFilePath);
       
  1167 	
       
  1168 	TestEnvInit();
       
  1169 	DoTests();
       
  1170 	TestEnvDestroy();
       
  1171 
       
  1172 	__UHEAP_MARKEND;
       
  1173 	
       
  1174 	TheTest.End();
       
  1175 	TheTest.Close();
       
  1176 	
       
  1177 	delete tc;
       
  1178 
       
  1179 	User::Heap().Check();
       
  1180 	return KErrNone;
       
  1181 	}
       
  1182 	
       
  1183