os/persistentdata/persistentstorage/dbms/tdbms/t_dbperf3.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include <d32dbms.h>
sl@0
    17
#include <s32file.h>
sl@0
    18
#include <e32test.h>
sl@0
    19
#include <e32math.h>
sl@0
    20
#include <s32mem.h>
sl@0
    21
#include <hal.h>
sl@0
    22
sl@0
    23
static RTest TheTest(_L("t_dbperf3"));
sl@0
    24
static CTrapCleanup* 	TheTrapCleanup;
sl@0
    25
static RFs				TheFs;
sl@0
    26
static RDbs 			TheDbs;
sl@0
    27
static RDbNamedDatabase TheDatabase;
sl@0
    28
static RDbRowSet 		TheRowSet, TheRowSet2;
sl@0
    29
static RFile 			TheTestFile;
sl@0
    30
static TFileName 		TheDatabaseFileName;
sl@0
    31
sl@0
    32
#define COUNT_OF(array) (sizeof(array)/sizeof(array[0]))
sl@0
    33
sl@0
    34
const TInt KTrackRecordCount = 200;
sl@0
    35
const TInt KCategoryRecordCount = 50;
sl@0
    36
const TInt KStatsRecordCount = 50;
sl@0
    37
const TInt KTestBlobSize = 4096;
sl@0
    38
sl@0
    39
//_LIT(KCreateTrackTable, "CREATE TABLE TRACKS (id INTEGER, marked_2_play INTEGER, category_id INTEGER, artist_last_name CHAR(15) NOT NULL,artist_first_name CHAR(15) NOT NULL, title CHAR(16) NOT NULL,download_site CHAR(30) NOT NULL,band_name CHAR(20) NOT NULL,origin CHAR(16),autostart INTEGER, init_volume INTEGER, music_file LONG VARCHAR)");
sl@0
    40
_LIT(KCreateTrackIndex, "CREATE INDEX IDX1 ON TRACKS(id,marked_2_play,category_id)");
sl@0
    41
_LIT(KCreateTrackTable, "CREATE TABLE TRACKS (id INTEGER, marked_2_play INTEGER, category_id INTEGER, artist_last_name CHAR(15) NOT NULL,artist_first_name CHAR(15) NOT NULL, title CHAR(16) NOT NULL,download_site CHAR(30) NOT NULL,band_name CHAR(20) NOT NULL,origin CHAR(16),autostart INTEGER, init_volume INTEGER)");
sl@0
    42
_LIT(KCreateTrackTable2, "CREATE TABLE TRACKS2 (id INTEGER, music_file LONG VARCHAR)");
sl@0
    43
//_LIT(KCreateTrackIndex2, "CREATE INDEX IDX4 ON TRACKS2(id)");
sl@0
    44
sl@0
    45
//_LIT(KTrackTable,"TRACKS");
sl@0
    46
sl@0
    47
_LIT(KId,"id");
sl@0
    48
_LIT(KLastName,"artist_last_name");
sl@0
    49
_LIT(KFirstName,"artist_first_name");
sl@0
    50
_LIT(KTitle,"title");
sl@0
    51
_LIT(KDownloadSite,"download_site");
sl@0
    52
_LIT(KBandName,"band_name");
sl@0
    53
_LIT(KOrigin,"origin");
sl@0
    54
_LIT(KAutoStart,"autostart");
sl@0
    55
_LIT(KInitVolume,"init_volume");
sl@0
    56
_LIT(KMarked2Play,"marked_2_play");
sl@0
    57
_LIT(KCategoryId,"category_id");
sl@0
    58
_LIT(KMusicFile,"music_file");
sl@0
    59
sl@0
    60
sl@0
    61
//category Table LITS
sl@0
    62
_LIT(KCreateCategoryTable, "CREATE TABLE CATEGORY (category_id INTEGER,category_name CHAR(20),genre INTEGER)");
sl@0
    63
_LIT(KCreateCategoryIndex, "CREATE INDEX IDX2 ON CATEGORY(category_id)");
sl@0
    64
sl@0
    65
//_LIT(KCategoryTable,"CATEGORY");
sl@0
    66
sl@0
    67
//KCategoryId defined for category table	
sl@0
    68
_LIT(KCategoryName,"category_name");
sl@0
    69
_LIT(KGenre,"genre");
sl@0
    70
sl@0
    71
sl@0
    72
//STATS Table LITS
sl@0
    73
_LIT(KCreatestatsTable, "CREATE TABLE STATS (category_id INTEGER, no_of_tracks INTEGER, no_autostart INTEGER,no_manualstart INTEGER,no_marked_2_play INTEGER, no_unmarked_2_play INTEGER, size_of_musicfiles INTEGER)");
sl@0
    74
_LIT(KCreatestatsIndex, "CREATE UNIQUE INDEX IDX3 ON STATS(category_id)");
sl@0
    75
sl@0
    76
//_LIT(KStatsTable,"STATS");
sl@0
    77
sl@0
    78
//KCategoryId defined for category table
sl@0
    79
_LIT(KNoOfTracks,"no_of_tracks");
sl@0
    80
_LIT(KNoMarked2Play,"no_marked_2_play");
sl@0
    81
_LIT(KNoUnmarked2Play,"no_unmarked_2_play");
sl@0
    82
_LIT(KNoAutostart,"no_autostart");
sl@0
    83
_LIT(KNoManualStart,"no_manualstart");
sl@0
    84
_LIT(KSizeOfMusicFiles,"size_of_musicfiles");
sl@0
    85
sl@0
    86
//////////////////////////////////////////////////////
sl@0
    87
sl@0
    88
static TInt TheCounterFreq = -10000000;
sl@0
    89
const TInt KMicroSecIn1Sec = 1000000;
sl@0
    90
sl@0
    91
TUint32 CalcTickDiff(TUint32 aStartTicks, TUint32 aEndTicks)
sl@0
    92
	{
sl@0
    93
	TInt64 diffTicks = (TInt64)aEndTicks - (TInt64)aStartTicks;
sl@0
    94
	if(diffTicks < 0)
sl@0
    95
		{
sl@0
    96
		diffTicks = KMaxTUint32 + diffTicks + 1;
sl@0
    97
		}
sl@0
    98
	return (TUint32)diffTicks;
sl@0
    99
	}
sl@0
   100
sl@0
   101
//Prints aFastCount parameter (converted to us)
sl@0
   102
void PrintFcDiffAsUs(const TDesC& aFormatStr, TUint32 aFastCount)
sl@0
   103
	{
sl@0
   104
	double v = ((double)aFastCount * KMicroSecIn1Sec) / (double)TheCounterFreq;
sl@0
   105
	TInt v2 = (TInt)v;
sl@0
   106
	TheTest.Printf(aFormatStr, v2);
sl@0
   107
	}
sl@0
   108
sl@0
   109
///////////////////////////////////////////////////////////////////////////////////////
sl@0
   110
sl@0
   111
//Delete "aFullName" file.
sl@0
   112
static void DeleteFile(const TDesC& aFullName)
sl@0
   113
	{
sl@0
   114
	RFs fsSession;
sl@0
   115
	TInt err = fsSession.Connect();
sl@0
   116
	if(err == KErrNone)
sl@0
   117
		{
sl@0
   118
		TEntry entry;
sl@0
   119
		if(fsSession.Entry(aFullName, entry) == KErrNone)
sl@0
   120
			{
sl@0
   121
			err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
sl@0
   122
			if(err != KErrNone) 
sl@0
   123
				{
sl@0
   124
				TheTest.Printf(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
sl@0
   125
				}
sl@0
   126
			err = fsSession.Delete(aFullName);
sl@0
   127
			if(err != KErrNone) 
sl@0
   128
				{
sl@0
   129
				TheTest.Printf(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
sl@0
   130
				}
sl@0
   131
			}
sl@0
   132
		fsSession.Close();
sl@0
   133
		}
sl@0
   134
	else
sl@0
   135
		{
sl@0
   136
		TheTest.Printf(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
sl@0
   137
		}
sl@0
   138
	}
sl@0
   139
sl@0
   140
///////////////////////////////////////////////////////////////////////////////////////
sl@0
   141
sl@0
   142
static void CloseAll()
sl@0
   143
	{
sl@0
   144
	TheRowSet2.Close();
sl@0
   145
	TheRowSet.Close();
sl@0
   146
	TheDatabase.Close();
sl@0
   147
	TheDbs.Close();
sl@0
   148
	TheFs.Close();
sl@0
   149
	}
sl@0
   150
sl@0
   151
///////////////////////////////////////////////////////////////////////////////////////
sl@0
   152
///////////////////////////////////////////////////////////////////////////////////////
sl@0
   153
//Tests macros and functions.
sl@0
   154
//If (!aValue) then the test will be panicked, the test data files will be deleted.
sl@0
   155
static void Check(TInt aValue, TInt aLine)
sl@0
   156
	{
sl@0
   157
	if(!aValue)
sl@0
   158
		{
sl@0
   159
		CloseAll();
sl@0
   160
		DeleteFile(TheDatabaseFileName);
sl@0
   161
		TheTest(EFalse, aLine);
sl@0
   162
		}
sl@0
   163
	}
sl@0
   164
//If (aValue != aExpected) then the test will be panicked, the test data files will be deleted.
sl@0
   165
static void Check(TInt aValue, TInt aExpected, TInt aLine)
sl@0
   166
	{
sl@0
   167
	if(aValue != aExpected)
sl@0
   168
		{
sl@0
   169
		TheTest.Printf(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
sl@0
   170
		CloseAll();
sl@0
   171
		DeleteFile(TheDatabaseFileName);
sl@0
   172
		TheTest(EFalse, aLine);
sl@0
   173
		}
sl@0
   174
	}
sl@0
   175
//Use these to test conditions.
sl@0
   176
#define TEST(arg) ::Check((arg), __LINE__)
sl@0
   177
#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
sl@0
   178
sl@0
   179
///////////////////////////////////////////////////////////////////////////////////////
sl@0
   180
sl@0
   181
void PrintFileSize()
sl@0
   182
	{
sl@0
   183
	RDbDatabase::TSize s = TheDatabase.Size();
sl@0
   184
	TheTest.Printf(_L("####FileSize: %d\r\n"), s.iSize);
sl@0
   185
	}
sl@0
   186
sl@0
   187
///////////////////////////////////////////////////////////////////////////////////////
sl@0
   188
sl@0
   189
void FillRandomData(TDes& aData, TInt64 aSeed)
sl@0
   190
	{
sl@0
   191
	aData.Zero();
sl@0
   192
	for (TInt i=0; i<aData.MaxLength(); ++i)
sl@0
   193
		{
sl@0
   194
		// add next character (we stick to lowercase alphabet for now)
sl@0
   195
		aData.Append(TChar(Math::FRand(aSeed)*25 + 'a'));	
sl@0
   196
		}
sl@0
   197
	}
sl@0
   198
sl@0
   199
void FillRandomData(TDes& aData)
sl@0
   200
	{
sl@0
   201
	// get random seed
sl@0
   202
	TTime time;
sl@0
   203
	time.UniversalTime();
sl@0
   204
	TInt64 seed = time.Int64();
sl@0
   205
	// do the filling
sl@0
   206
	FillRandomData(aData, seed);
sl@0
   207
	}
sl@0
   208
sl@0
   209
///////////////////////////////////////////////////////////////////////////////////////
sl@0
   210
sl@0
   211
void CreateDatabase()
sl@0
   212
	{
sl@0
   213
	TInt err = TheDatabase.Replace(TheFs, TheDatabaseFileName);
sl@0
   214
	TEST2(err, KErrNone);
sl@0
   215
	TheDatabase.Close();
sl@0
   216
	err = TheDbs.Connect();
sl@0
   217
	TEST2(err, KErrNone);
sl@0
   218
	err = TheDatabase.Open(TheDbs, TheDatabaseFileName);
sl@0
   219
	TEST2(err, KErrNone);
sl@0
   220
	err = TheDatabase.Execute(KCreateTrackTable);
sl@0
   221
	TEST2(err, KErrNone);
sl@0
   222
	err = TheDatabase.Execute(KCreateTrackIndex);
sl@0
   223
	TEST2(err, KErrNone);
sl@0
   224
	err = TheDatabase.Execute(KCreateTrackTable2);
sl@0
   225
	TEST2(err, KErrNone);
sl@0
   226
	//err = TheDatabase.Execute(KCreateTrackIndex2);
sl@0
   227
	//TEST2(err, KErrNone);
sl@0
   228
	err = TheDatabase.Execute(KCreateCategoryTable);
sl@0
   229
	TEST2(err, KErrNone);
sl@0
   230
	err = TheDatabase.Execute(KCreateCategoryIndex);
sl@0
   231
	TEST2(err, KErrNone);
sl@0
   232
	err = TheDatabase.Execute(KCreatestatsTable);
sl@0
   233
	TEST2(err, KErrNone);
sl@0
   234
	err = TheDatabase.Execute(KCreatestatsIndex);
sl@0
   235
	TEST2(err, KErrNone);
sl@0
   236
	//err = TheDatabase.Compact();
sl@0
   237
	//TEST2(err, KErrNone);
sl@0
   238
	}
sl@0
   239
sl@0
   240
void InsertTrackTableL()
sl@0
   241
	{	
sl@0
   242
	HBufC* randomDataBuf = HBufC::NewLC(KTestBlobSize);
sl@0
   243
	TPtr randomData(randomDataBuf->Des());
sl@0
   244
	FillRandomData(randomData);
sl@0
   245
	
sl@0
   246
	RDbView view;
sl@0
   247
	TInt err = view.Prepare(TheDatabase, _L("select * from TRACKS"), view.EInsertOnly);
sl@0
   248
	TEST2(err, KErrNone);
sl@0
   249
	TheRowSet = view;	
sl@0
   250
	
sl@0
   251
	CDbColSet* colSet = TheRowSet.ColSetL();
sl@0
   252
	const TInt KIdIdx = colSet->ColNo(KId);
sl@0
   253
	const TInt KLastNameIdx = colSet->ColNo(KLastName);
sl@0
   254
	const TInt KFirstNameIdx = colSet->ColNo(KFirstName);
sl@0
   255
	const TInt KTitleIdx = colSet->ColNo(KTitle);
sl@0
   256
	const TInt KDownloadSiteIdx = colSet->ColNo(KDownloadSite);
sl@0
   257
	const TInt KBandNameIdx = colSet->ColNo(KBandName);
sl@0
   258
	const TInt KOriginIdx = colSet->ColNo(KOrigin);
sl@0
   259
	const TInt KAutoStartIdx = colSet->ColNo(KAutoStart);
sl@0
   260
	const TInt KInitVolumeIdx = colSet->ColNo(KInitVolume);
sl@0
   261
	const TInt KMarkedToPlayIdx = colSet->ColNo(KMarked2Play);
sl@0
   262
	const TInt KCategoryIdIdx = colSet->ColNo(KCategoryId);
sl@0
   263
	//const TInt KMusicFileIdx = colSet->ColNo(KMusicFile);
sl@0
   264
	delete colSet;
sl@0
   265
	colSet = NULL;
sl@0
   266
sl@0
   267
	err = TheDatabase.Begin();
sl@0
   268
	TEST2(err, KErrNone);
sl@0
   269
	
sl@0
   270
	for (TInt ii=1;ii<=KTrackRecordCount;++ii)
sl@0
   271
		{
sl@0
   272
		TheRowSet.InsertL();
sl@0
   273
		TheRowSet.SetColL(KIdIdx, ii);
sl@0
   274
		TheRowSet.SetColL(KLastNameIdx, _L("Dummy"));
sl@0
   275
		TheRowSet.SetColL(KFirstNameIdx,_L("Dummy"));
sl@0
   276
		TheRowSet.SetColL(KTitleIdx,_L("Dummy"));
sl@0
   277
		TheRowSet.SetColL(KDownloadSiteIdx,_L("Dummy"));
sl@0
   278
		TheRowSet.SetColL(KBandNameIdx,_L("Dummy"));
sl@0
   279
		TheRowSet.SetColL(KOriginIdx,_L("Dummy"));
sl@0
   280
		TheRowSet.SetColL(KAutoStartIdx,(ii%2));
sl@0
   281
		TheRowSet.SetColL(KInitVolumeIdx,(ii%2));
sl@0
   282
		TheRowSet.SetColL(KMarkedToPlayIdx,(ii%2));
sl@0
   283
		TheRowSet.SetColL(KCategoryIdIdx,(ii%KCategoryRecordCount));
sl@0
   284
sl@0
   285
		//RDbColWriteStream musicfile;
sl@0
   286
		//musicfile.OpenLC(TheRowSet, KMusicFileIdx);
sl@0
   287
		//musicfile.WriteL(randomData,KTestBlobSize);
sl@0
   288
		//musicfile.CommitL();
sl@0
   289
		//CleanupStack::PopAndDestroy(&musicfile);
sl@0
   290
sl@0
   291
		TheRowSet.PutL();
sl@0
   292
		}
sl@0
   293
sl@0
   294
	err = TheDatabase.Commit();
sl@0
   295
	TEST2(err, KErrNone);
sl@0
   296
sl@0
   297
	//err = TheDatabase.Compact();
sl@0
   298
	//TEST2(err, KErrNone);
sl@0
   299
sl@0
   300
	TheRowSet.Close();	
sl@0
   301
sl@0
   302
	////////////////////////////////////////////////////////////////////////////////////////////////
sl@0
   303
sl@0
   304
	err = view.Prepare(TheDatabase, _L("select * from TRACKS2"), view.EInsertOnly);
sl@0
   305
	TEST2(err, KErrNone);
sl@0
   306
	TheRowSet = view;	
sl@0
   307
	
sl@0
   308
	colSet = TheRowSet.ColSetL();
sl@0
   309
	const TInt KIdIdx2 = colSet->ColNo(KId);
sl@0
   310
	const TInt KMusicFileIdx2 = colSet->ColNo(KMusicFile);
sl@0
   311
	delete colSet;
sl@0
   312
sl@0
   313
	err = TheDatabase.Begin();
sl@0
   314
	TEST2(err, KErrNone);
sl@0
   315
sl@0
   316
	for (TInt ii=1;ii<=KTrackRecordCount;++ii)
sl@0
   317
		{
sl@0
   318
		TheRowSet.InsertL();
sl@0
   319
		TheRowSet.SetColL(KIdIdx2, ii);
sl@0
   320
		
sl@0
   321
		RDbColWriteStream musicfile;
sl@0
   322
		musicfile.OpenLC(TheRowSet, KMusicFileIdx2);
sl@0
   323
		musicfile.WriteL(randomData,KTestBlobSize);
sl@0
   324
		musicfile.CommitL();
sl@0
   325
		CleanupStack::PopAndDestroy(&musicfile);
sl@0
   326
		
sl@0
   327
		TheRowSet.PutL();
sl@0
   328
		}
sl@0
   329
sl@0
   330
	err = TheDatabase.Commit();
sl@0
   331
	TEST2(err, KErrNone);
sl@0
   332
sl@0
   333
	//err = TheDatabase.Compact();
sl@0
   334
	//TEST2(err, KErrNone);
sl@0
   335
sl@0
   336
	TheRowSet.Close();	
sl@0
   337
sl@0
   338
	CleanupStack::PopAndDestroy(randomDataBuf);
sl@0
   339
	}
sl@0
   340
	
sl@0
   341
void InsertCategoryTableL()
sl@0
   342
	{
sl@0
   343
	RDbView view;
sl@0
   344
	TInt err = view.Prepare(TheDatabase, _L("select * from CATEGORY"), view.EInsertOnly);
sl@0
   345
	TEST2(err, KErrNone);
sl@0
   346
	TheRowSet = view;	
sl@0
   347
sl@0
   348
	CDbColSet* colSet = TheRowSet.ColSetL();
sl@0
   349
	const TInt KCategoryIdIdx = colSet->ColNo(KCategoryId);
sl@0
   350
	const TInt KCategoryNameIdx = colSet->ColNo(KCategoryName);
sl@0
   351
	const TInt KGenreIdx = colSet->ColNo(KGenre);
sl@0
   352
	delete colSet;
sl@0
   353
sl@0
   354
	err = TheDatabase.Begin();
sl@0
   355
	TEST2(err, KErrNone);
sl@0
   356
sl@0
   357
	for (TInt ii=1;ii<=KCategoryRecordCount;++ii)
sl@0
   358
		{
sl@0
   359
		TheRowSet.InsertL();
sl@0
   360
		TheRowSet.SetColL(KCategoryIdIdx, ii);
sl@0
   361
		TheRowSet.SetColL(KCategoryNameIdx, _L("History"));
sl@0
   362
		TheRowSet.SetColL(KGenreIdx,(ii*500));
sl@0
   363
		TheRowSet.PutL();
sl@0
   364
		}
sl@0
   365
sl@0
   366
	err = TheDatabase.Commit();
sl@0
   367
	TEST2(err, KErrNone);
sl@0
   368
	
sl@0
   369
	//err = TheDatabase.Compact();
sl@0
   370
	//TEST2(err, KErrNone);
sl@0
   371
sl@0
   372
	TheRowSet.Close();	
sl@0
   373
	}
sl@0
   374
	
sl@0
   375
void InsertStatsTableL()
sl@0
   376
	{
sl@0
   377
	RDbView view;
sl@0
   378
	TInt err = view.Prepare(TheDatabase, _L("select * from STATS"), view.EInsertOnly);
sl@0
   379
	TEST2(err, KErrNone);
sl@0
   380
	TheRowSet = view;	
sl@0
   381
sl@0
   382
	CDbColSet* colSet = TheRowSet.ColSetL();
sl@0
   383
	const TInt KCategoryIdIdx = colSet->ColNo(KCategoryId);
sl@0
   384
	const TInt KTrackCntIdx = colSet->ColNo(KNoOfTracks);
sl@0
   385
	const TInt KMarkedToPlayCntIdx = colSet->ColNo(KNoMarked2Play);
sl@0
   386
	const TInt KUnmarkedToPlayCntIdx = colSet->ColNo(KNoUnmarked2Play);
sl@0
   387
	const TInt KAutoStartCntIdx = colSet->ColNo(KNoAutostart);
sl@0
   388
	const TInt KManualStartCntIdx = colSet->ColNo(KNoManualStart);
sl@0
   389
	const TInt KSizeMusicFilesIdx = colSet->ColNo(KSizeOfMusicFiles);
sl@0
   390
	delete colSet;
sl@0
   391
sl@0
   392
	TInt default_Stat = 0;
sl@0
   393
sl@0
   394
	err = TheDatabase.Begin();
sl@0
   395
	TEST2(err, KErrNone);
sl@0
   396
	
sl@0
   397
	for (TInt ii=0;ii<KStatsRecordCount;++ii)
sl@0
   398
		{
sl@0
   399
		TheRowSet.InsertL();
sl@0
   400
		TheRowSet.SetColL(KCategoryIdIdx, ii);
sl@0
   401
		TheRowSet.SetColL(KTrackCntIdx,default_Stat);
sl@0
   402
		TheRowSet.SetColL(KMarkedToPlayCntIdx,default_Stat);
sl@0
   403
		TheRowSet.SetColL(KUnmarkedToPlayCntIdx,default_Stat);
sl@0
   404
		TheRowSet.SetColL(KAutoStartCntIdx,default_Stat);
sl@0
   405
		TheRowSet.SetColL(KManualStartCntIdx,default_Stat);
sl@0
   406
		TheRowSet.SetColL(KSizeMusicFilesIdx,default_Stat);
sl@0
   407
		TheRowSet.PutL();
sl@0
   408
		}
sl@0
   409
sl@0
   410
	err = TheDatabase.Commit();
sl@0
   411
	TEST2(err, KErrNone);
sl@0
   412
	
sl@0
   413
	//err = TheDatabase.Compact();
sl@0
   414
	//TEST2(err, KErrNone);
sl@0
   415
sl@0
   416
	TheRowSet.Close();	
sl@0
   417
	}
sl@0
   418
	
sl@0
   419
void FillDatabaseL()
sl@0
   420
	{
sl@0
   421
	InsertTrackTableL();
sl@0
   422
	InsertCategoryTableL();	
sl@0
   423
	InsertStatsTableL();
sl@0
   424
	}
sl@0
   425
sl@0
   426
void DestroyDatabase()
sl@0
   427
	{
sl@0
   428
	TheRowSet.Close();
sl@0
   429
	TheDatabase.Close();
sl@0
   430
	TheDbs.Close();
sl@0
   431
	TInt err = TheFs.Delete(TheDatabaseFileName);
sl@0
   432
	TEST2(err, KErrNone);
sl@0
   433
	}
sl@0
   434
sl@0
   435
///////////////////////////////////////////////////////////////////////////////////////
sl@0
   436
sl@0
   437
void GetFastCounterFrequency()
sl@0
   438
	{
sl@0
   439
	TEST2(HAL::Get(HAL::EFastCounterFrequency, TheCounterFreq), KErrNone);
sl@0
   440
	TheTest.Printf(_L("Counter frequency=%d\r\n"), TheCounterFreq);
sl@0
   441
	}
sl@0
   442
sl@0
   443
///////////////////////////////////////////////////////////////////////////////////////
sl@0
   444
sl@0
   445
void SelectTracksL(TInt aCount, RArray<TInt>& aTracks)
sl@0
   446
	{
sl@0
   447
	TUint32 fc = User::FastCounter();
sl@0
   448
	RDbView view;
sl@0
   449
	TUint32 fc2 = User::FastCounter();
sl@0
   450
	TInt err = view.Prepare(TheDatabase, _L("select id from TRACKS"), view.EReadOnly);
sl@0
   451
	TEST2(err, KErrNone);
sl@0
   452
	PrintFcDiffAsUs(_L("###\"Prepare()\",time=%d us\r\n"), CalcTickDiff(fc2, User::FastCounter()));
sl@0
   453
	fc2 = User::FastCounter();
sl@0
   454
	err = view.EvaluateAll();
sl@0
   455
	TEST2(err, KErrNone);
sl@0
   456
	PrintFcDiffAsUs(_L("###\"EvaluateAll()\",time=%d us\r\n"), CalcTickDiff(fc2, User::FastCounter()));
sl@0
   457
	TheRowSet = view;
sl@0
   458
sl@0
   459
	TUint32 diff1 = 0, diff2 = 0;
sl@0
   460
	TInt count = 0;	
sl@0
   461
	while(count < aCount)
sl@0
   462
		{
sl@0
   463
		fc2 = User::FastCounter();
sl@0
   464
		if(!TheRowSet.NextL())
sl@0
   465
			{
sl@0
   466
			break;	
sl@0
   467
			}
sl@0
   468
		diff1 += CalcTickDiff(fc2, User::FastCounter());	
sl@0
   469
		fc2 = User::FastCounter();
sl@0
   470
		TheRowSet.GetL();
sl@0
   471
		diff2 += CalcTickDiff(fc2, User::FastCounter());	
sl@0
   472
		aTracks.Append(TheRowSet.ColInt(1));
sl@0
   473
		++count;
sl@0
   474
		}
sl@0
   475
	TEST2(count, aCount);
sl@0
   476
	PrintFcDiffAsUs(_L("###\"Total NextL()\",time=%d us\r\n"), diff1);
sl@0
   477
	PrintFcDiffAsUs(_L("###\"Total GetL()\",time=%d us\r\n"), diff2);
sl@0
   478
	
sl@0
   479
	fc2 = User::FastCounter();
sl@0
   480
	TheRowSet.Close();	
sl@0
   481
	PrintFcDiffAsUs(_L("###\"Close()\",time=%d us\r\n"), CalcTickDiff(fc2, User::FastCounter()));
sl@0
   482
	PrintFcDiffAsUs(_L("###\"SELECT FROM TRACKS\",time=%d us\r\n"), CalcTickDiff(fc, User::FastCounter()));
sl@0
   483
	}
sl@0
   484
sl@0
   485
/** 
sl@0
   486
@SYMTestCaseID          PDS-DBMS-UT-4009
sl@0
   487
@SYMTestCaseDesc        DBMS performance tests.
sl@0
   488
@SYMTestPriority        High
sl@0
   489
@SYMTestActions        	The test opens the test database and:
sl@0
   490
						- selects the ids of the tracks to be deleted and collects them into an array;
sl@0
   491
						- deletes the recods with matching track ids from TRACK table;
sl@0
   492
						- deletes the recods with matching track ids from TRACK2 table;
sl@0
   493
						The execution times are printed out.
sl@0
   494
@SYMTestExpectedResults Test must not fail
sl@0
   495
@SYMREQ                 REQ7141
sl@0
   496
*/
sl@0
   497
void DeleteTracksL()
sl@0
   498
	{
sl@0
   499
	TheTest.Printf(_L("Record count: %d\r\n"), KTrackRecordCount);
sl@0
   500
	
sl@0
   501
	RArray<TInt> tracks;
sl@0
   502
	tracks.ReserveL(KTrackRecordCount);
sl@0
   503
	CleanupClosePushL(tracks);
sl@0
   504
	SelectTracksL(KTrackRecordCount, tracks);
sl@0
   505
	//
sl@0
   506
	_LIT(KDeleteSql, "DELETE FROM tracks  WHERE id>=%d AND id<=%d");
sl@0
   507
sl@0
   508
	TBuf<100> sql;
sl@0
   509
	sql.Format(KDeleteSql, tracks[0], tracks[tracks.Count() - 1]);
sl@0
   510
sl@0
   511
	TUint32 fc2 = User::FastCounter();
sl@0
   512
sl@0
   513
	TInt err = TheDatabase.Begin();
sl@0
   514
	TEST2(err, KErrNone);
sl@0
   515
	
sl@0
   516
	TUint32 fc = User::FastCounter();
sl@0
   517
	TInt rc = TheDatabase.Execute(sql);
sl@0
   518
	PrintFcDiffAsUs(_L("###\"DELETE FROM TRACKS\",time=%d us\r\n"), CalcTickDiff(fc, User::FastCounter()));
sl@0
   519
	TEST2(rc, KTrackRecordCount);
sl@0
   520
	TheTest.Printf(_L("Deleted record count: %d\r\n"), rc);
sl@0
   521
sl@0
   522
	sql.Replace(12, 6, _L("TRACKS2"));
sl@0
   523
	fc = User::FastCounter();
sl@0
   524
	rc = TheDatabase.Execute(sql);
sl@0
   525
	PrintFcDiffAsUs(_L("###\"DELETE FROM TRACKS2\",time=%d us\r\n"), CalcTickDiff(fc, User::FastCounter()));
sl@0
   526
	TEST2(rc, KTrackRecordCount);
sl@0
   527
	TheTest.Printf(_L("Deleted record count: %d\r\n"), rc);
sl@0
   528
sl@0
   529
	err = TheDatabase.Commit();
sl@0
   530
	TEST2(err, KErrNone);
sl@0
   531
sl@0
   532
	PrintFcDiffAsUs(_L("###Total \"DELETE FROM TRACKS\",time=%d us\r\n"), CalcTickDiff(fc2, User::FastCounter()));
sl@0
   533
	
sl@0
   534
	CleanupStack::PopAndDestroy(&tracks);
sl@0
   535
	}
sl@0
   536
sl@0
   537
///////////////////////////////////////////////////////////////////////////////////////
sl@0
   538
sl@0
   539
//This test checks how RDbDatabase::Commit() works if there are some active RDbRowSet objects - 
sl@0
   540
//read-only and updatable. The expectation is that the Commit() call won't fail, the RDbRowSet objects
sl@0
   541
//retain their pre-commit positions.
sl@0
   542
void CommitTestL()
sl@0
   543
	{
sl@0
   544
	//Create 2 test tables, insert some records in the first table
sl@0
   545
	TheDatabase.Close();
sl@0
   546
	TInt err = TheDatabase.Replace(TheFs, TheDatabaseFileName);
sl@0
   547
	TEST2(err, KErrNone);
sl@0
   548
	err = TheDatabase.Execute(_L("CREATE TABLE AA1(Id INTEGER)"));
sl@0
   549
	TEST2(err, KErrNone);
sl@0
   550
	err = TheDatabase.Execute(_L("CREATE TABLE AA2(Id INTEGER)"));
sl@0
   551
	TEST2(err, KErrNone);
sl@0
   552
	err = TheDatabase.Execute(_L("INSERT INTO AA1(Id) VALUES(1)"));
sl@0
   553
	TEST2(err, 1);
sl@0
   554
	err = TheDatabase.Execute(_L("INSERT INTO AA1(Id) VALUES(2)"));
sl@0
   555
	TEST2(err, 1);
sl@0
   556
	err = TheDatabase.Execute(_L("INSERT INTO AA1(Id) VALUES(3)"));
sl@0
   557
	TEST2(err, 1);
sl@0
   558
	//Begin transaction
sl@0
   559
	err = TheDatabase.Begin();
sl@0
   560
	TEST2(err, KErrNone);
sl@0
   561
	//Prepare read-only view and call FirstL() (TheRowSet object)
sl@0
   562
	RDbView view;
sl@0
   563
	err = view.Prepare(TheDatabase, _L("select * from AA1"), RDbRowSet::EReadOnly);
sl@0
   564
	TEST2(err, KErrNone);
sl@0
   565
	TheRowSet = view;
sl@0
   566
	err = view.EvaluateAll();	//DBMS can use FirstL() without the EvaluateAll() call in this case
sl@0
   567
	TEST2(err, KErrNone);
sl@0
   568
	TBool rc = TheRowSet.FirstL();
sl@0
   569
	TEST(rc);
sl@0
   570
	//Prepare updatable view and call NextL() (TheRowSet2 object)
sl@0
   571
	err = view.Prepare(TheDatabase, _L("select * from AA1"), RDbRowSet::EUpdatable);
sl@0
   572
	TEST2(err, KErrNone);
sl@0
   573
	TheRowSet2 = view;
sl@0
   574
	err = view.EvaluateAll();	//DBMS can use NextL() without the EvaluateAll() call in this case
sl@0
   575
	TEST2(err, KErrNone);
sl@0
   576
	rc = TheRowSet2.FirstL();
sl@0
   577
	TEST(rc);
sl@0
   578
	rc = TheRowSet2.NextL();
sl@0
   579
	TEST(rc);
sl@0
   580
	//Execute one INSERT statement
sl@0
   581
	err = TheDatabase.Execute(_L("INSERT INTO AA2(Id) VALUES(1)"));
sl@0
   582
	TEST2(err, 1);
sl@0
   583
	//Commit transaction
sl@0
   584
	err = TheDatabase.Commit();
sl@0
   585
	TEST2(err, KErrNone);
sl@0
   586
	//Check the retrieved by TheRowSet record 
sl@0
   587
	TheRowSet.GetL();
sl@0
   588
	TEST2(TheRowSet.ColInt(1), 1);
sl@0
   589
	//Check the retrieved by TheRowSet2 record 
sl@0
   590
	TheRowSet2.GetL();
sl@0
   591
	TEST2(TheRowSet2.ColInt(1), 2);
sl@0
   592
	//Cleanup
sl@0
   593
	TheRowSet2.Close();
sl@0
   594
	TheRowSet.Close();
sl@0
   595
	TheDatabase.Close();
sl@0
   596
	}
sl@0
   597
sl@0
   598
///////////////////////////////////////////////////////////////////////////////////////
sl@0
   599
	
sl@0
   600
void DoTestL()
sl@0
   601
	{
sl@0
   602
	TheTest.Start(_L("Get fast counter frequency"));
sl@0
   603
	GetFastCounterFrequency();
sl@0
   604
	
sl@0
   605
	TheTest.Next(_L("Create&Fill test database"));
sl@0
   606
	CreateDatabase();
sl@0
   607
	FillDatabaseL();
sl@0
   608
sl@0
   609
	TheTest.Next(_L(" @SYMTestCaseID:PDS-DBMS-UT-4009 Delete tracks"));
sl@0
   610
	DeleteTracksL();
sl@0
   611
sl@0
   612
	TheTest.Next(_L("Commit() test (not a performance test)"));
sl@0
   613
	CommitTestL();
sl@0
   614
	}
sl@0
   615
sl@0
   616
///////////////////////////////////////////////////////////////////////////////////////
sl@0
   617
sl@0
   618
//Usage: "t_dbperf3 [<drive letter>:]"
sl@0
   619
TInt E32Main()
sl@0
   620
    {
sl@0
   621
	TheTest.Title();
sl@0
   622
	
sl@0
   623
	TheTrapCleanup = CTrapCleanup::New();
sl@0
   624
	TEST(TheTrapCleanup != NULL);
sl@0
   625
	
sl@0
   626
	//Construct test database file name
sl@0
   627
	_LIT(KTestDatabase, "c:\\dbms-tst\\t_dbperf3.db");
sl@0
   628
	TFileName fname;
sl@0
   629
	User::CommandLine(fname);
sl@0
   630
	TParse parse;
sl@0
   631
	parse.Set(fname, &KTestDatabase, 0);
sl@0
   632
	const TDesC& dbFilePath = parse.FullName();
sl@0
   633
	TheDatabaseFileName.Copy(dbFilePath);
sl@0
   634
	TheTest.Printf(_L("Test database: %S\r\n"), &TheDatabaseFileName);
sl@0
   635
sl@0
   636
	__UHEAP_MARK;
sl@0
   637
sl@0
   638
	TInt err = TheFs.Connect();
sl@0
   639
	TEST2(err, KErrNone);
sl@0
   640
	err = TheFs.MkDir(TheDatabaseFileName);
sl@0
   641
	TheTest.Printf(_L("MkDir(): err=%d\r\n"), err);
sl@0
   642
	TEST(err == KErrNone || err == KErrAlreadyExists);
sl@0
   643
sl@0
   644
	DeleteFile(TheDatabaseFileName);
sl@0
   645
sl@0
   646
	TRAP(err, DoTestL());
sl@0
   647
	TEST2(err, KErrNone);
sl@0
   648
sl@0
   649
	CloseAll();
sl@0
   650
	DeleteFile(TheDatabaseFileName);
sl@0
   651
sl@0
   652
	__UHEAP_MARKEND;
sl@0
   653
sl@0
   654
	TheTest.End();
sl@0
   655
	TheTest.Close();
sl@0
   656
	
sl@0
   657
	delete TheTrapCleanup;
sl@0
   658
	return KErrNone;
sl@0
   659
    }