os/persistentdata/persistentstorage/sql/TEST/t_sqlperformance3.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2009-2010 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: MDS harvesting performance test
    14 //
    15 #include <e32test.h>
    16 #include <e32math.h>
    17 #include <bautils.h>
    18 #include <hal.h>
    19 #include <sqldb.h>
    20 #include "t_sqlcmdlineutil.h"
    21 
    22 RTest 			TheTest(_L("t_sqlperformance3 test"));
    23 RSqlDatabase 	TheDb;
    24 
    25 _LIT(KDbName, 	"c:\\test\\t_sqlperformance3.db");
    26 
    27 TFileName		TheDbFileName;
    28 TBuf<200> 		TheTestTitle;
    29 TCmdLineParams 	TheCmdLineParams(TCmdLineParams::EDbUtf16, 4096, 10000);
    30 TBuf8<200> 		TheSqlConfigString;
    31 
    32 _LIT(KUtf8,  "UTF8 ");
    33 _LIT(KUtf16, "UTF16");
    34 
    35 TInt TheFastCounterFreq = 0;
    36 
    37 const TInt KItemCnt = 1000;
    38 const TInt KItemBlockSize = 100;
    39 
    40 TInt TheIterations[100];
    41 TInt TheIterationsCount = -1;
    42 
    43 void CalcIterationsCount()
    44 	{
    45 	TheIterationsCount = KItemCnt / KItemBlockSize;
    46 	TInt r = KItemCnt % KItemBlockSize;
    47 	if(r > 0)
    48 		{
    49 		++TheIterationsCount;		
    50 		}
    51 	else
    52 		{
    53 		r = KItemBlockSize;
    54 		}
    55 	for(TInt i=0;i<(TheIterationsCount-1);++i)
    56 		{
    57 		TheIterations[i] = KItemBlockSize;
    58 		}
    59 	TheIterations[TheIterationsCount - 1] = r;
    60 	}
    61 
    62 ////////////////////////////////////////////////////////////////////////////////////////////////////
    63 
    64 void TestEnvDestroy()
    65 	{
    66 	TheDb.Close();
    67 	(void)RSqlDatabase::Delete(TheDbFileName);
    68 	}
    69 
    70 ///////////////////////////////////////////////////////////////////////////////////////
    71 ///////////////////////////////////////////////////////////////////////////////////////
    72 //Test macros and functions
    73 void Check1(TInt aValue, TInt aLine)
    74 	{
    75 	if(!aValue)
    76 		{
    77 		TestEnvDestroy();
    78 		TheTest.Printf(_L("*** Line %d\r\n"), aLine);
    79 		TheTest(EFalse, aLine);
    80 		}
    81 	}
    82 void Check2(TInt aValue, TInt aExpected, TInt aLine)
    83 	{
    84 	if(aValue != aExpected)
    85 		{
    86 		TSqlRetCodeClass cl = SqlRetCodeClass(aValue);
    87 		if(cl == ESqlDbError)
    88 			{
    89 			TPtrC errmsg = TheDb.LastErrorMessage();
    90 			TheTest.Printf(_L("*** SQLite err=\"%S\"\r\n"), &errmsg);
    91 			}
    92 		TestEnvDestroy();
    93 		TheTest.Printf(_L("*** Line %d, Expected error: %d, got: %d\r\n"), aLine, aExpected, aValue);
    94 		TheTest(EFalse, aLine);
    95 		}
    96 	}
    97 #define TEST(arg) ::Check1((arg), __LINE__)
    98 #define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__)
    99 
   100 ///////////////////////////////////////////////////////////////////////////////////////
   101 
   102 void TestEnvInit()
   103 	{
   104 	RFs fs;
   105 	TInt err = fs.Connect();
   106 	TEST2(err, KErrNone);
   107 	err = fs.MkDirAll(TheDbFileName);
   108 	TEST(err == KErrNone || err == KErrAlreadyExists);
   109 	fs.Close();
   110 	}
   111 
   112 TInt TimeDiffUs(TUint32 aStartTicks, TUint32 aEndTicks)
   113 	{
   114 	if(TheFastCounterFreq == 0)
   115 		{
   116 		TEST2(HAL::Get(HAL::EFastCounterFrequency, TheFastCounterFreq), KErrNone);
   117 		}
   118 	TInt64 diffTicks = (TInt64)aEndTicks - (TInt64)aStartTicks;
   119 	if(diffTicks < 0)
   120 		{
   121 		diffTicks = KMaxTUint32 + diffTicks + 1;
   122 		}
   123 	const TInt KMicroSecIn1Sec = 1000000;
   124 	TInt us = (diffTicks * KMicroSecIn1Sec) / TheFastCounterFreq;
   125 	return us;
   126 	}
   127 
   128 void PrintTime(const TDesC& aFmt, TUint32 aStartTicks, TUint32 aEndTicks)
   129 	{
   130 	TInt us = TimeDiffUs(aStartTicks, aEndTicks);
   131 	TheTest.Printf(aFmt, us);
   132 	}
   133 
   134 //=============================================================================
   135 TInt TheCreateDbCreateConnTime = 0;
   136 TInt TheCreateDbOpenConnTime = 0;
   137 TInt TheLastItemIdTime = 0;
   138 TInt TheTableExistsTime = 0;
   139 TInt TheMdeTablesCreationTime = 0;
   140 TInt TheLastInsertedRowIdTime = 0;
   141 TInt TheCreateTables1Time = 0;
   142 TInt TheCreateTables2Time = 0;
   143 TInt TheCreateTables3Time = 0;
   144 TInt TheTransactionTime = 0;
   145 TInt TheDbCreateTime = 0;
   146 TInt TheCreateTriggersTime = 0;
   147 TInt TheInsertEventRelationTime = 0;
   148 TInt TheDeleteObjPropertyTime = 0;
   149 TInt TheInsertCol2PropTime = 0;
   150 TInt TheHarvestTime = 0;
   151 TInt TheHarvestSelectTime = 0;
   152 TInt TheHarvestInsertObjImageTime = 0;
   153 TInt TheHarvestSelect2Time = 0;
   154 TInt TheHarvestInsertEventTime = 0;
   155 TInt TheHarvestUpdateObjImageTime = 0;
   156 TInt TheHarvestSelect3Time = 0;
   157 TInt TheHarvestSelect4Time = 0;
   158 TInt TheHarvestUpdateObjTime = 0;
   159 //=============================================================================
   160 
   161 void DoCreateDbFile()
   162 	{
   163 	TUint32 fc1 = User::FastCounter();
   164     TInt err = TheDb.Create(TheDbFileName, &TheSqlConfigString);
   165     if(err != KErrNone)
   166     	{
   167     	if(err == KErrAlreadyExists)
   168     		{
   169     		err = TheDb.Open(TheDbFileName, &TheSqlConfigString);
   170     		if(err == KErrNone)
   171     			{
   172     			TUint32 fc2 = User::FastCounter();
   173     			TheCreateDbCreateConnTime += TimeDiffUs(fc1, fc2);
   174     			}
   175     		}
   176     	}
   177     else
   178     	{
   179     	TUint32 fc2 = User::FastCounter();
   180 		TheCreateDbOpenConnTime += TimeDiffUs(fc1, fc2);
   181     	}
   182     TEST2(err, KErrNone);
   183 	}
   184 
   185 void DoGetlastItemId()
   186 	{
   187 	_LIT(KGetLastMaxId, "SELECT max(seq) FROM SQLITE_SEQUENCE WHERE name!='symbian_security';");
   188 	TUint32 fc1 = User::FastCounter();
   189 	RSqlStatement stmt;
   190 	TInt err = stmt.Prepare(TheDb, KGetLastMaxId);
   191 	if(err == KErrNone)
   192 		{
   193 		(void)stmt.Next();
   194 		}
   195 	stmt.Close();
   196 	TUint32 fc2 = User::FastCounter();
   197 	TheLastItemIdTime += TimeDiffUs(fc1, fc2);
   198 	}
   199 
   200 TBool MdePreferencesCheck()
   201 	{
   202 	_LIT(KCheck, "SELECT COUNT(*) FROM MdE_Preferences;");
   203 	TUint32 fc1 = User::FastCounter();
   204 	RSqlStatement stmt;
   205 	TInt err = stmt.Prepare(TheDb, KCheck);
   206 	if(err == KErrNone)
   207 		{
   208 		err = stmt.Next();
   209 		}
   210 	stmt.Close();
   211 	TUint32 fc2 = User::FastCounter();
   212 	TheTableExistsTime += TimeDiffUs(fc1, fc2);
   213 	return err == KSqlAtRow;
   214 	}
   215 
   216 void CreateMdeTables()
   217 	{
   218 	_LIT(KSql1, "CREATE TABLE MdE_Preferences(Key TEXT,Value NONE,ExtraValue LARGEINT,UNIQUE(Key,Value))");
   219 	_LIT(KSql2, "CREATE TABLE MdS_Medias(MediaId INTEGER PRIMARY KEY,Drive INTEGER,PresentState INTEGER,Time LARGEINT)");
   220 	_LIT(KSql3, "INSERT INTO MdE_Preferences(Key, Value, ExtraValue) VALUES(?, ?, ?)");
   221 	
   222 	TUint32 fc1 = User::FastCounter();
   223 	
   224 	TInt rc = TheDb.Exec(KSql1);
   225 	TEST(rc >= 0);
   226 	rc = TheDb.Exec(KSql2);
   227 	TEST(rc >= 0);
   228 	
   229 	RSqlStatement stmt;
   230 	rc = stmt.Prepare(TheDb, KSql3);
   231 	TEST2(rc, KErrNone);
   232 	rc = stmt.BindInt(0, 1);
   233 	TEST2(rc, KErrNone);
   234 	rc = stmt.BindInt(1, 2);
   235 	TEST2(rc, KErrNone);
   236 	rc = stmt.BindInt(2, 3);
   237 	TEST2(rc, KErrNone);
   238 	rc = stmt.Exec();
   239 	TEST2(rc, 1);
   240 	stmt.Close();
   241 
   242 	TUint32 fc2 = User::FastCounter();
   243 	TheMdeTablesCreationTime += TimeDiffUs(fc1, fc2);
   244 	}
   245 
   246 TInt64 LastInsertedRowId()
   247 	{
   248 	_LIT(KSql, "SELECT last_insert_rowid();");
   249 	TUint32 fc1 = User::FastCounter();
   250 	RSqlStatement stmt;
   251 	TInt err = stmt.Prepare(TheDb, KSql);
   252 	TEST2(err, KErrNone);
   253 	err = stmt.Next();
   254 	TEST2(err, KSqlAtRow);
   255 	TInt64 rowid = stmt.ColumnInt64(0); 
   256 	stmt.Close();
   257 	TUint32 fc2 = User::FastCounter();
   258 	TheLastInsertedRowIdTime += TimeDiffUs(fc1, fc2);
   259 	return rowid;
   260 	}
   261 
   262 void DoCreateTables1()
   263 	{
   264 	_LIT(KSql1, "CREATE TABLE IF NOT EXISTS NamespaceDef(NamespaceDefId INTEGER PRIMARY KEY,ReadOnly INTEGER,VendorId INTEGER,Name TEXT)");
   265 	_LIT(KSql2, "CREATE TABLE IF NOT EXISTS ObjectDef(ObjectDefId INTEGER PRIMARY KEY,NamespaceDefId INTEGER NOT NULL,ParentDefId INTEGER NOT NULL,Flags INTEGER,Name TEXT)");
   266 	_LIT(KSql3, "CREATE TABLE IF NOT EXISTS PropertyDef(PropertyDefId INTEGER PRIMARY KEY,ObjectDefId INTEGER NOT NULL,Flags INTEGER,Type INTEGER,MinValue NUMERIC,MaxValue NUMERIC,Name TEXT)");
   267 	_LIT(KSql4, "CREATE TABLE IF NOT EXISTS RelationDef(RelationDefId INTEGER PRIMARY KEY,NamespaceDefId INTEGER NOT NULL,Name TEXT)");
   268 	_LIT(KSql5, "CREATE TABLE IF NOT EXISTS EventDef(EventDefId INTEGER PRIMARY KEY,NamespaceDefId INTEGER NOT NULL,Priority INTEGER,Name TEXT)");
   269 
   270 	TUint32 fc1 = User::FastCounter();
   271 	
   272 	TInt rc = TheDb.Exec(KSql1);
   273 	TEST(rc >= 0);
   274 	rc = TheDb.Exec(KSql2);
   275 	TEST(rc >= 0);
   276 	rc = TheDb.Exec(KSql3);
   277 	TEST(rc >= 0);
   278 	rc = TheDb.Exec(KSql4);
   279 	TEST(rc >= 0);
   280 	rc = TheDb.Exec(KSql5);
   281 	TEST(rc >= 0);
   282 	
   283 	_LIT(KSql6, "INSERT INTO NamespaceDef(ReadOnly,VendorId,Name) Values(?,?,?);");
   284 	RSqlStatement stmt;
   285 	rc = stmt.Prepare(TheDb, KSql6);
   286 	TEST2(rc, KErrNone);
   287 	rc = stmt.BindInt(0, 1);
   288 	TEST2(rc, KErrNone);
   289 	rc = stmt.BindInt(1, 2);
   290 	TEST2(rc, KErrNone);
   291 	rc = stmt.BindText(2, _L("Nokia"));
   292 	TEST2(rc, KErrNone);
   293 	rc = stmt.Exec();
   294 	TEST2(rc, 1);
   295 	stmt.Close();
   296 
   297 	TUint32 fc2 = User::FastCounter();
   298 	TheCreateTables1Time += TimeDiffUs(fc1, fc2);
   299 	}
   300 
   301 void BeginTransaction()
   302 	{
   303 	TInt err = TheDb.Exec(_L("BEGIN"));
   304 	TEST(err >= 0);
   305 	}
   306 
   307 void CommitTransaction()
   308 	{
   309 	TInt err = TheDb.Exec(_L("COMMIT"));
   310 	TEST(err >= 0);
   311 	}
   312 
   313 void DoCreateTables2()
   314 	{
   315 	_LIT(KSql1, "CREATE TABLE IF NOT EXISTS Object1(ObjectId INTEGER PRIMARY KEY AUTOINCREMENT,ObjectDefId INTEGER NOT NULL,Flags INTEGER,MediaId LARGEINT,UsageCount LARGEINT DEFAULT 0,GuidHigh LARGEINT,GuidLow LARGEINT,URI TEXT NOT NULL COLLATE NOCASE,Origin INTEGER,Size LARGEINT,TimeOffset INTEGER,CreationDate LARGEINT,LastModifiedDate LARGEINT,ItemType TEXT,Title TEXT,UNIQUE(GuidHigh,GuidLow),UNIQUE(MediaId,URI))");
   316 	_LIT(KSql2, "CREATE TABLE IF NOT EXISTS Relations1(RelationId INTEGER PRIMARY KEY AUTOINCREMENT,Flags INTEGER,RelationDefId INTEGER NOT NULL,LeftObjectId INTEGER NOT NULL,RightObjectId INTEGER NOT NULL,Parameter INTEGER,GuidHigh LARGEINT,GuidLow LARGEINT,LastModifiedDate LARGEINT)");
   317 	_LIT(KSql3, "CREATE TRIGGER DeleteRelations1 BEFORE DELETE ON Object1 BEGIN DELETE FROM Relations1 WHERE LeftObjectId=OLD.ObjectId OR RightObjectId=OLD.ObjectId; END");
   318 	_LIT(KSql4, "CREATE TABLE IF NOT EXISTS Event1(EventId INTEGER PRIMARY KEY AUTOINCREMENT,ObjectId INTEGER NOT NULL, EventDefId INTEGER NOT NULL, Timestamp INTEGER NOT NULL, Source TEXT, Participant TEXT)");
   319 	_LIT(KSql5, "CREATE TRIGGER DeleteEvent1 BEFORE DELETE ON Object1 BEGIN DELETE FROM Event1 WHERE ObjectId=OLD.ObjectId; END");
   320 	_LIT(KSql6, "CREATE TABLE IF NOT EXISTS TextSearch1(WordId INTEGER NOT NULL,ObjectId INTEGER NOT NULL,Position INTEGER)");
   321 	_LIT(KSql7, "CREATE TRIGGER DeleteTextSearch1 BEFORE DELETE ON Object1 BEGIN DELETE FROM TextSearch1 WHERE ObjectId=OLD.ObjectId; END");
   322 	_LIT(KSql8, "CREATE INDEX FreetextWordIdIndex1 ON TextSearch1(WordId)");
   323 	_LIT(KSql9, "CREATE INDEX FreetextObjectIdIndex1 ON TextSearch1(ObjectId)");
   324 	_LIT(KSql10, "CREATE TABLE IF NOT EXISTS TextSearchDictionary1(WordId INTEGER PRIMARY KEY,Word TEXT NOT NULL)");
   325 	_LIT(KSql11, "CREATE TRIGGER InsertRelations1 INSERT ON Relations1 BEGIN UPDATE Object1 SET UsageCount = UsageCount + 1 WHERE ObjectId=NEW.LeftObjectId OR ObjectId=NEW.RightObjectId; END");
   326 	_LIT(KSql12, "CREATE TRIGGER UpdateRelations1 UPDATE OF LeftObjectId, RightObjectId ON Relations1 WHEN OLD.Flags=NEW.Flags BEGIN UPDATE Object1 SET UsageCount = UsageCount - 1 WHERE ObjectId=OLD.LeftObjectId OR ObjectId=OLD.RightObjectId; UPDATE Object1 SET UsageCount = UsageCount + 1 WHERE ObjectId=NEW.LeftObjectId OR ObjectId=NEW.RightObjectId; END");
   327 	_LIT(KSql13, "CREATE TRIGGER UpdateNotRemovedRelations1 UPDATE OF Flags ON Relations1 WHEN OLD.Flags!=NEW.Flags AND NOT NEW.Flags&3 BEGIN UPDATE Object1 SET UsageCount = UsageCount + 1 WHERE ObjectId=NEW.LeftObjectId OR ObjectId=NEW.RightObjectId; END");
   328 	_LIT(KSql14, "CREATE TRIGGER UpdateRemovedRelations1 UPDATE OF Flags ON Relations1 WHEN OLD.Flags!=NEW.Flags AND NEW.Flags&3 AND NOT OLD.Flags&3 BEGIN UPDATE Object1 SET UsageCount = UsageCount - 1 WHERE ObjectId=OLD.LeftObjectId OR ObjectId=OLD.RightObjectId; END");
   329 	_LIT(KSql15, "CREATE INDEX RelationsLeftObjectIdIndex1 ON Relations1(LeftObjectId)");
   330 	_LIT(KSql16, "CREATE INDEX RelationsRightObjectIdIndex1 ON Relations1(RightObjectId)");
   331 	_LIT(KSql17, "CREATE INDEX ObjectDefIndex1 ON Object1(ObjectDefId)");
   332 	_LIT(KSql18, "CREATE TABLE IF NOT EXISTS Location1(ObjectId INTEGER NOT NULL,CellID LARGEINT,LocationAreaCode LARGEINT,Speed REAL,Direction REAL,Quality REAL,Latitude REAL,Longitude REAL,Altitude REAL,CountryCodeStr TEXT,NetworkCodeStr TEXT,Satellites TEXT,Country TEXT,CellName TEXT, UNIQUE(ObjectId))");
   333 	_LIT(KSql19, "CREATE TABLE IF NOT EXISTS Calendar1(ObjectId INTEGER NOT NULL,CalendarType INTEGER,LocalUid LARGEINT,StartTime LARGEINT,EndTime LARGEINT,Location TEXT,vCalendar TEXT, UNIQUE(ObjectId))");
   334 	_LIT(KSql20, "CREATE TABLE IF NOT EXISTS Contact1(ObjectId INTEGER NOT NULL,Number TEXT,EmailAddress TEXT,Company TEXT,JobTitle TEXT,Address TEXT,ContactURL TEXT,vCard TEXT, UNIQUE(ObjectId))");
   335 	_LIT(KSql21, "CREATE TABLE IF NOT EXISTS Message1(ObjectId INTEGER NOT NULL,Received INTEGER,ToWhom TEXT,Sender TEXT, UNIQUE(ObjectId))");
   336 	_LIT(KSql22, "CREATE TABLE IF NOT EXISTS Album1(ObjectId INTEGER NOT NULL,Ordered INTEGER,Type INTEGER, UNIQUE(ObjectId))");
   337 	_LIT(KSql23, "CREATE TABLE IF NOT EXISTS Tag1(ObjectId INTEGER NOT NULL, UNIQUE(ObjectId))");
   338 	_LIT(KSql24, "CREATE TABLE IF NOT EXISTS MediaObject1(ObjectId INTEGER NOT NULL,Protected INTEGER,DRM INTEGER,ThumbnailPresent INTEGER,Resized INTEGER,Sample INTEGER,Rating INTEGER,Privacy INTEGER,ResolutionUnit INTEGER,Bitrate INTEGER,Width INTEGER,Height INTEGER,Preinstalled INTEGER,AccessCount LARGEINT,DownloadID LARGEINT,Duration REAL,ReleaseDate LARGEINT,CaptureDate LARGEINT,Artist TEXT,Author TEXT,Copyright TEXT,Legal TEXT,Description TEXT,Comment TEXT,Genre TEXT, UNIQUE(ObjectId))");
   339 	_LIT(KSql25, "CREATE TABLE IF NOT EXISTS Video1(ObjectId INTEGER NOT NULL,Protected INTEGER,DRM INTEGER,ThumbnailPresent INTEGER,Resized INTEGER,Sample INTEGER,Rating INTEGER,Privacy INTEGER,ResolutionUnit INTEGER,Bitrate INTEGER,Width INTEGER,Height INTEGER,Preinstalled INTEGER,AccessCount LARGEINT,DownloadID LARGEINT,Duration REAL,ReleaseDate LARGEINT,CaptureDate LARGEINT,AgeProfile INTEGER,AudioFourCC LARGEINT,RecordingFlags LARGEINT,LastPlayPosition REAL,Framerate REAL,Artist TEXT,Author TEXT,Copyright TEXT,Legal TEXT,Description TEXT,Comment TEXT,Genre TEXT,AudioLanguage TEXT, UNIQUE(ObjectId))");
   340 	_LIT(KSql26, "CREATE TABLE IF NOT EXISTS Image1(ObjectId INTEGER NOT NULL,Protected INTEGER,DRM INTEGER,ThumbnailPresent INTEGER,Resized INTEGER,Sample INTEGER,Rating INTEGER,Privacy INTEGER,ResolutionUnit INTEGER,Bitrate INTEGER,Width INTEGER,Height INTEGER,Preinstalled INTEGER,AccessCount LARGEINT,DownloadID LARGEINT,Duration REAL,ReleaseDate LARGEINT,CaptureDate LARGEINT,FocalPlaneResolutionUnit INTEGER,ExposureProgram INTEGER,FocalLengthIn35mmFilm INTEGER,ISOSpeedRatings INTEGER,MeteringMode INTEGER,WhiteBalance INTEGER,Flash INTEGER,ColourSpace INTEGER,Orientation INTEGER,SamplesPerPixel INTEGER,BitsPerSample INTEGER,YCbCrPositioning INTEGER,ThumbCompression INTEGER,ThumbResolutionUnit INTEGER,ThumbOrientation INTEGER,FrameCount INTEGER,PixelXDimension LARGEINT,PixelYDimension LARGEINT,ExifVersion LARGEINT,ComponentsConfiguration LARGEINT,FlashPixVersion LARGEINT,ThumbXResolution LARGEINT,ThumbYResolution LARGEINT,FocalPlaneXResolution REAL,FocalPlaneYResolution REAL,ExposureTime REAL,ExposureBiasValue REAL,FNumber REAL,FocalLength REAL,ApertureValue REAL,MaxAperture REAL,ShutterSpeedValue REAL,XResolution REAL,YResolution REAL,DateTime LARGEINT,DateTimeDigitized LARGEINT,DateTimeOriginal LARGEINT,Artist TEXT,Author TEXT,Copyright TEXT,Legal TEXT,Description TEXT,Comment TEXT,Genre TEXT,Model TEXT,Make TEXT,RelatedSoundFile TEXT, UNIQUE(ObjectId))");
   341 	_LIT(KSql27, "CREATE TABLE IF NOT EXISTS Audio1(ObjectId INTEGER NOT NULL,Protected INTEGER,DRM INTEGER,ThumbnailPresent INTEGER,Resized INTEGER,Sample INTEGER,Rating INTEGER,Privacy INTEGER,ResolutionUnit INTEGER,Bitrate INTEGER,Width INTEGER,Height INTEGER,Preinstalled INTEGER,AccessCount LARGEINT,DownloadID LARGEINT,Duration REAL,ReleaseDate LARGEINT,CaptureDate LARGEINT,Track INTEGER,SamplingFrequency REAL,Artist TEXT,Author TEXT,Copyright TEXT,Legal TEXT,Description TEXT,Comment TEXT,Genre TEXT,Album TEXT,Composer TEXT,OriginalArtist TEXT,AlbumArtist TEXT, UNIQUE(ObjectId))");
   342 	_LIT(KSql28, "CREATE TABLE IF NOT EXISTS TrackLog1(ObjectId INTEGER NOT NULL,Length LARGEINT,StartTime LARGEINT,StopTime LARGEINT, UNIQUE(ObjectId))");
   343 	
   344 	const TPtrC KSql[] = 
   345 		{
   346 		KSql1(), KSql2(), KSql3(), KSql4(), KSql5(), KSql6(), KSql7(), KSql8(), KSql9(), KSql10(), 
   347 		KSql11(), KSql12(), KSql13(), KSql14(), KSql15(), KSql16(), KSql17(), KSql18(), KSql19(), KSql20(), 
   348 		KSql21(), KSql22(), KSql23(), KSql24(), KSql25(), KSql26(), KSql27(), KSql28() 
   349 		};
   350 	
   351 	TUint32 fc1 = User::FastCounter();	
   352 	for(TInt i=0;i<(sizeof(KSql)/sizeof(KSql[0]));++i)
   353 		{
   354 		TInt err = TheDb.Exec(KSql[i]);
   355 		TEST(err >= 0);
   356 		}
   357 	TUint32 fc2 = User::FastCounter();
   358 	TheCreateTables2Time += TimeDiffUs(fc1, fc2);
   359 	}
   360 
   361 void DoCreateTables3()
   362 	{
   363 	const TInt KInsObjDefRecCnt = 12;
   364 	const TInt KInsPropDefRecCnt[KInsObjDefRecCnt] = {7, 11, 6, 7, 3, 2, 0, 24, 6, 40, 6, 3};
   365 	TUint32 fc1 = User::FastCounter();	
   366 	for(TInt i=0;i<KInsObjDefRecCnt;++i)
   367 		{
   368 		TBuf<10> objDefName;
   369 		RSqlStatement stmt1;
   370 		TInt err = stmt1.Prepare(TheDb, _L("INSERT INTO ObjectDef(NamespaceDefId, ParentDefId, Flags, Name) Values(?,?,?,?)"));
   371 		TEST2(err, KErrNone);
   372 		err = stmt1.BindInt(0, 1);
   373 		TEST2(err, KErrNone);
   374 		err = stmt1.BindInt(1, 2);
   375 		TEST2(err, KErrNone);
   376 		err = stmt1.BindInt(2, 3);
   377 		TEST2(err, KErrNone);
   378 		objDefName.Copy(_L("ObjDef"));
   379 		objDefName.AppendNum(i + 1);
   380 		err = stmt1.BindText(3, objDefName);
   381 		TEST2(err, KErrNone);
   382 		err = stmt1.Exec();
   383 		TEST2(err, 1);
   384 		stmt1.Close();
   385 		TInt64 objdefid = LastInsertedRowId();
   386 		for(TInt j=0;j<KInsPropDefRecCnt[i];++j)
   387 			{
   388 			TBuf<10> propDefName;
   389 			RSqlStatement stmt2;
   390 			err = stmt2.Prepare(TheDb, _L("INSERT INTO PropertyDef(ObjectDefId,Flags,Type,MinValue,MaxValue,Name) Values(?,?,?,?,?,?);"));
   391 			TEST2(err, KErrNone);
   392 			err = stmt2.BindInt64(0, objdefid);
   393 			TEST2(err, KErrNone);
   394 			err = stmt2.BindInt(1, 2);
   395 			TEST2(err, KErrNone);
   396 			err = stmt2.BindInt(2, 3);
   397 			TEST2(err, KErrNone);
   398 			err = stmt2.BindInt(3, 100);
   399 			TEST2(err, KErrNone);
   400 			err = stmt2.BindInt(4, 200);
   401 			TEST2(err, KErrNone);
   402 			propDefName.Copy(_L("PropDef"));
   403 			propDefName.AppendNum(j + 1);
   404 			err = stmt2.BindText(5, propDefName);
   405 			TEST2(err, KErrNone);
   406 			err = stmt2.Exec();
   407 			TEST2(err, 1);
   408 			stmt2.Close();
   409 			LastInsertedRowId();
   410 			}
   411 		}
   412 	TUint32 fc2 = User::FastCounter();
   413 	TheCreateTables3Time += TimeDiffUs(fc1, fc2);
   414 	}
   415 
   416 void DoCreateTriggers()
   417 	{
   418 	_LIT(KSql1, "CREATE TRIGGER DeleteLocation1 DELETE ON Object1 BEGIN DELETE FROM Location1 WHERE ObjectId=OLD.ObjectId; END");
   419 	_LIT(KSql2, "CREATE TRIGGER DeleteCalendar1 DELETE ON Object1 BEGIN DELETE FROM Calendar1 WHERE ObjectId=OLD.ObjectId; END");
   420 	_LIT(KSql3, "CREATE TRIGGER DeleteContact1 DELETE ON Object1 BEGIN DELETE FROM Contact1 WHERE ObjectId=OLD.ObjectId; END");
   421 	_LIT(KSql4, "CREATE TRIGGER DeleteMessage1 DELETE ON Object1 BEGIN DELETE FROM Message1 WHERE ObjectId=OLD.ObjectId; END");
   422 	_LIT(KSql5, "CREATE TRIGGER DeleteAlbum1 DELETE ON Object1 BEGIN DELETE FROM Album1 WHERE ObjectId=OLD.ObjectId; END");
   423 	_LIT(KSql6, "CREATE TRIGGER DeleteTag1 DELETE ON Object1 BEGIN DELETE FROM Tag1 WHERE ObjectId=OLD.ObjectId; END");
   424 	_LIT(KSql7, "CREATE TRIGGER DeleteMediaObject1 DELETE ON Object1 BEGIN DELETE FROM MediaObject1 WHERE ObjectId=OLD.ObjectId; END");
   425 	_LIT(KSql8, "CREATE TRIGGER DeleteVideo1 DELETE ON Object1 BEGIN DELETE FROM Video1 WHERE ObjectId=OLD.ObjectId; END");
   426 	_LIT(KSql9, "CREATE TRIGGER DeleteImage1 DELETE ON Object1 BEGIN DELETE FROM Image1 WHERE ObjectId=OLD.ObjectId; END");
   427 	_LIT(KSql10, "CREATE TRIGGER DeleteAudio1 DELETE ON Object1 BEGIN DELETE FROM Audio1 WHERE ObjectId=OLD.ObjectId; END");
   428 	_LIT(KSql11, "CREATE TRIGGER DeleteTrackLog1 DELETE ON Object1 BEGIN DELETE FROM TrackLog1 WHERE ObjectId=OLD.ObjectId; END");
   429 	
   430 	const TPtrC KSql[] = 
   431 		{
   432 		KSql1(), KSql2(), KSql3(), KSql4(), KSql5(), KSql6(), KSql7(), KSql8(), KSql9(), KSql10(), KSql11() 
   433 		};
   434 	
   435 	TUint32 fc1 = User::FastCounter();	
   436 	for(TInt i=0;i<(sizeof(KSql)/sizeof(KSql[0]));++i)
   437 		{
   438 		TInt err = TheDb.Exec(KSql[i]);
   439 		TEST(err >= 0);
   440 		}
   441 	TUint32 fc2 = User::FastCounter();
   442 	TheCreateTriggersTime += TimeDiffUs(fc1, fc2);
   443 	}
   444 
   445 void DoInsertEventRelationDefs()
   446 	{
   447 	_LIT(KSql1, "INSERT INTO EventDef (NamespaceDefId, Priority, Name ) Values(?, ?, ?);");
   448 	const TInt KSql1Cnt = 7;
   449 	_LIT(KSql2, "INSERT INTO RelationDef (NamespaceDefId,Name) Values(?,?);");
   450 	const TInt KSql2Cnt = 8;
   451 	
   452 	TUint32 fc1 = User::FastCounter();	
   453 	
   454 	for(TInt i=0;i<KSql1Cnt;++i)
   455 		{
   456 		TBuf<10> eventDefName;
   457 		RSqlStatement stmt;
   458 		TInt err = stmt.Prepare(TheDb, KSql1);
   459 		TEST2(err, KErrNone);
   460 		err = stmt.BindInt(0, 1);
   461 		TEST2(err, KErrNone);
   462 		err = stmt.BindInt(1, 2);
   463 		TEST2(err, KErrNone);
   464 		eventDefName.Copy(_L("EvtDef"));
   465 		eventDefName.AppendNum(i + 1);
   466 		err = stmt.BindText(2, eventDefName);
   467 		TEST2(err, KErrNone);
   468 		err = stmt.Exec();
   469 		TEST2(err, 1);
   470 		stmt.Close();
   471 		LastInsertedRowId();
   472 		}
   473 
   474 	for(TInt i=0;i<KSql2Cnt;++i)
   475 		{
   476 		TBuf<10> relDefName;
   477 		RSqlStatement stmt;
   478 		TInt err = stmt.Prepare(TheDb, KSql2);
   479 		TEST2(err, KErrNone);
   480 		err = stmt.BindInt(0, 1);
   481 		TEST2(err, KErrNone);
   482 		relDefName.Copy(_L("RelDef"));
   483 		relDefName.AppendNum(i + 1);
   484 		err = stmt.BindText(1, relDefName);
   485 		TEST2(err, KErrNone);
   486 		err = stmt.Exec();
   487 		TEST2(err, 1);
   488 		stmt.Close();
   489 		LastInsertedRowId();
   490 		}
   491 	
   492 	TUint32 fc2 = User::FastCounter();
   493 	TheInsertEventRelationTime += TimeDiffUs(fc1, fc2);
   494 	}
   495 
   496 void DoDeleteObjPropertyDef()
   497 	{
   498 	_LIT(KSql1, "DELETE FROM ObjectDef WHERE ObjectDefId=?;");
   499 	_LIT(KSql2, "DELETE FROM PropertyDef WHERE ObjectDefId=?;");
   500 
   501 	TUint32 fc1 = User::FastCounter();
   502 	
   503 	RSqlStatement stmt1;
   504 	TInt err = stmt1.Prepare(TheDb, KSql1);
   505 	TEST2(err, KErrNone);
   506 	err = stmt1.BindInt(0, 0);
   507 	TEST2(err, KErrNone);
   508 	err = stmt1.Exec();
   509 	TEST(err >= 0);
   510 	stmt1.Close();
   511 	
   512 	RSqlStatement stmt2;
   513 	err = stmt2.Prepare(TheDb, KSql2);
   514 	TEST2(err, KErrNone);
   515 	err = stmt2.BindInt(0, 0);
   516 	TEST2(err, KErrNone);
   517 	err = stmt2.Exec();
   518 	TEST(err >= 0);
   519 	stmt2.Close();
   520 	
   521 	TUint32 fc2 = User::FastCounter();
   522 	TheDeleteObjPropertyTime += TimeDiffUs(fc1, fc2);
   523 	}
   524 
   525 void DoInsertCol2Prop()
   526 	{
   527 	_LIT(KSql1, "CREATE TABLE IF NOT EXISTS Col2Prop(ObjectDefId INTEGER NOT NULL,PropertyDefId INTEGER NOT NULL,ColumnId INTEGER NOT NULL)");
   528 	TInt KCol2PropCnt = KItemCnt;
   529 	_LIT(KSql2, "INSERT INTO Col2Prop(ObjectDefId,PropertyDefId,ColumnId) Values(?,?,?);");
   530 	
   531 	TUint32 fc1 = User::FastCounter();
   532 
   533 	TInt err = TheDb.Exec(KSql1);
   534 	TEST(err >= 0);
   535 	for(TInt i=0;i<KCol2PropCnt;++i)
   536 		{
   537 		RSqlStatement stmt;
   538 		err = stmt.Prepare(TheDb, KSql2);
   539 		TEST2(err, KErrNone);
   540 		err = stmt.BindInt(0, 10);
   541 		TEST2(err, KErrNone);
   542 		err = stmt.BindInt(1, 20);
   543 		TEST2(err, KErrNone);
   544 		err = stmt.BindInt(2, i);
   545 		TEST2(err, KErrNone);
   546 		err = stmt.Exec();
   547 		TEST(err >= 0);
   548 		stmt.Close();
   549 		}
   550 	
   551 	TUint32 fc2 = User::FastCounter();
   552 	TheInsertCol2PropTime += TimeDiffUs(fc1, fc2);
   553 	}
   554 
   555 /**
   556 @SYMTestCaseID			PDS-SQL-UT-4149
   557 @SYMTestCaseDesc		MDE database creation performance test.
   558 						The test creates the MDE database using the SQL statements from the 
   559 						production code of the MetaDataEngine server. The time taken for the execution of
   560 						SQL statements is measured and printed out.
   561 @SYMTestActions			MDE database creation performance test.
   562 @SYMTestExpectedResults Test must not fail
   563 @SYMTestPriority		High
   564 @SYMDEF					DEF142327
   565 */
   566 void CreateDb()
   567 	{
   568 	DoCreateDbFile();
   569 	TheDb.Close();
   570 	DoCreateDbFile();
   571 	
   572 	TUint32 fc1 = User::FastCounter();	
   573 	
   574 	////////////////////////////////
   575 	DoGetlastItemId();
   576 	MdePreferencesCheck();
   577 	CreateMdeTables();
   578 	////////////////////////////////
   579 	TUint32 fc2 = User::FastCounter();	
   580 	BeginTransaction();
   581 	//
   582 	DoCreateTables1();
   583 	DoCreateTables2();
   584 	DoCreateTables3();
   585 	DoCreateTriggers();
   586 	DoInsertEventRelationDefs();
   587 	DoDeleteObjPropertyDef();
   588 	DoInsertCol2Prop();
   589 	//
   590 	CommitTransaction();
   591 	TUint32 fc3 = User::FastCounter();
   592 	TheTransactionTime += TimeDiffUs(fc2, fc3);
   593 	TheDbCreateTime += TimeDiffUs(fc1, fc3);
   594 	}
   595 
   596 void DoHarvestSelect()
   597 	{
   598 	TUint32 fc1 = User::FastCounter();	
   599 	for(TInt i=0;i<TheIterationsCount;++i)
   600 		{
   601 		BeginTransaction();
   602 		for(TInt j=0;j<TheIterations[i];++j)
   603 			{
   604 			_LIT(KSql, "SELECT ObjectId, Flags, LastModifiedDate, Size FROM Object1 WHERE NOT Flags&? AND (Flags&? OR Flags&?) AND MediaId=? AND URI=?;");
   605 			RSqlStatement stmt;
   606 			TInt err = stmt.Prepare(TheDb, KSql);
   607 			TEST2(err, KErrNone);
   608 			err = stmt.BindInt(0, 8);
   609 			TEST2(err, KErrNone);
   610 			err = stmt.BindInt(1, 16);
   611 			TEST2(err, KErrNone);
   612 			err = stmt.BindInt(2, 32);
   613 			TEST2(err, KErrNone);
   614 			TBuf<16> media;
   615 			media.Copy(_L("media"));
   616 			media.AppendNum(j + 1);
   617 			err = stmt.BindText(3, media);
   618 			TEST2(err, KErrNone);
   619 			TBuf<16> uri;
   620 			uri.Copy(_L("uri"));
   621 			uri.AppendNum(j + 1);
   622 			err = stmt.BindText(4, uri);
   623 			TEST2(err, KErrNone);
   624 			while((err = stmt.Next()) == KSqlAtRow)
   625 				{
   626 				}
   627 			TEST2(err, KSqlAtEnd);
   628 			stmt.Close();
   629 			}
   630 		CommitTransaction();
   631 		}
   632 	TUint32 fc2 = User::FastCounter();
   633 	TheHarvestSelectTime += TimeDiffUs(fc1, fc2);
   634 	}
   635 
   636 void DoHarvestInsertObjImage()
   637 	{
   638 	_LIT(KSql1, "INSERT INTO Object1(ObjectId,ObjectDefId,Flags,MediaId,GuidHigh,GuidLow,URI,Origin,Size,CreationDate,LastModifiedDate) VALUES(?,?,?,?,?,?,?,?,?,?,?);");
   639 	_LIT(KSql2, "INSERT INTO Image1(ObjectId) VALUES(?);");
   640 	
   641 	TUint32 fc1 = User::FastCounter();	
   642 	TInt objdef = 0;
   643 	for(TInt i=0;i<TheIterationsCount;++i)
   644 		{
   645 		BeginTransaction();
   646 		for(TInt j=0;j<TheIterations[i];++j)
   647 			{
   648 			++objdef;
   649 			RSqlStatement stmt1;
   650 			TInt err = stmt1.Prepare(TheDb, KSql1);
   651 			TEST2(err, KErrNone);
   652 			err = stmt1.BindInt(0, objdef);
   653 			TEST2(err, KErrNone);
   654 			err = stmt1.BindInt(1, 9);
   655 			TEST2(err, KErrNone);
   656 			err = stmt1.BindInt(2, 48);
   657 			TEST2(err, KErrNone);
   658 			err = stmt1.BindInt(3, 3);
   659 			TEST2(err, KErrNone);
   660 			err = stmt1.BindInt(4, j + 1 + i * 100);
   661 			TEST2(err, KErrNone);
   662 			err = stmt1.BindInt(5, j + 1 + i * 10000);
   663 			TEST2(err, KErrNone);
   664 			TBuf<16> uri;
   665 			uri.Copy(_L("URI-"));
   666 			uri.AppendNum(j + 1 + i * 100);
   667 			err = stmt1.BindText(6, uri);
   668 			TEST2(err, KErrNone);
   669 			err = stmt1.BindInt(7, 0);
   670 			TEST2(err, KErrNone);
   671 			err = stmt1.BindInt(8, 1000000);
   672 			TEST2(err, KErrNone);
   673 			err = stmt1.BindInt64(9, 32324234218723LL);
   674 			TEST2(err, KErrNone);
   675 			err = stmt1.BindInt64(10, 5675069785676565LL);
   676 			TEST2(err, KErrNone);
   677 			err = stmt1.Exec();
   678 			TEST(err >= 0);
   679 			stmt1.Close();
   680 
   681 			RSqlStatement stmt2;
   682 			err = stmt2.Prepare(TheDb, KSql2);
   683 			TEST2(err, KErrNone);
   684 			err = stmt2.BindInt(0, objdef);
   685 			TEST2(err, KErrNone);
   686 			err = stmt2.Exec();
   687 			TEST(err >= 0);
   688 			stmt2.Close();
   689 			}
   690 		CommitTransaction();
   691 		}
   692 	TUint32 fc2 = User::FastCounter();
   693 	TheHarvestInsertObjImageTime += TimeDiffUs(fc1, fc2);
   694 	}
   695 
   696 void DoHarvestSelect2()
   697 	{
   698 	TUint32 fc1 = User::FastCounter();
   699 	///////////////////////////////////////////////////////////////////////
   700 	_LIT(KSql1, "SELECT count(*) FROM Object1 AS BO WHERE(NOT Flags&?)AND (NOT Flags&?) AND (((BO.ObjectId IN(SELECT ObjectId FROM Object1 WHERE((NOT Flags&?)AND (NOT Flags&?)AND (NOT Flags&?)AND ObjectDefId=?))OR BO.ObjectId IN(SELECT ObjectId FROM Object1 WHERE((NOT Flags&?)AND (NOT Flags&?)AND (NOT Flags&?)AND ObjectDefId=?)))AND BO.ObjectId IN(SELECT ObjectId FROM Object1 WHERE(Origin=?)))) ORDER BY LastModifiedDate DESC,BO.ObjectId DESC ;");
   701 	RSqlStatement stmt1;
   702 	TInt err = stmt1.Prepare(TheDb, KSql1);
   703 	TEST2(err, KErrNone);
   704 	err = stmt1.BindInt(0, 8);
   705 	TEST2(err, KErrNone);
   706 	err = stmt1.BindInt(1, 16);
   707 	TEST2(err, KErrNone);
   708 	err = stmt1.BindInt(2, 32);
   709 	TEST2(err, KErrNone);
   710 	err = stmt1.BindInt(3, 64);
   711 	TEST2(err, KErrNone);
   712 	err = stmt1.BindInt(4, 128);
   713 	TEST2(err, KErrNone);
   714 	err = stmt1.BindInt(5, 1);
   715 	TEST2(err, KErrNone);
   716 	err = stmt1.BindInt(6, 8);
   717 	TEST2(err, KErrNone);
   718 	err = stmt1.BindInt(7, 16);
   719 	TEST2(err, KErrNone);
   720 	err = stmt1.BindInt(8, 32);
   721 	TEST2(err, KErrNone);
   722 	err = stmt1.BindInt(9, 1);
   723 	TEST2(err, KErrNone);
   724 	err = stmt1.BindInt(10, 1);
   725 	TEST2(err, KErrNone);
   726 	while((err = stmt1.Next()) == KSqlAtRow)
   727 		{
   728 		}
   729 	TEST2(err, KSqlAtEnd);
   730 	stmt1.Close();
   731 	///////////////////////////////////////////////////////////////////////
   732 	_LIT(KSql2, "SELECT count(*) FROM Object1 AS BO WHERE(NOT Flags&?)AND (NOT Flags&?)AND ((BO.ObjectId IN(SELECT ObjectId FROM Object1 WHERE(Origin=?)))) ORDER BY CreationDate DESC,BO.ObjectId DESC ;");
   733 	RSqlStatement stmt2;
   734 	err = stmt2.Prepare(TheDb, KSql2);
   735 	TEST2(err, KErrNone);
   736 	err = stmt2.BindInt(0, 8);
   737 	TEST2(err, KErrNone);
   738 	err = stmt2.BindInt(1, 16);
   739 	TEST2(err, KErrNone);
   740 	err = stmt2.BindInt(2, 1);
   741 	TEST2(err, KErrNone);
   742 	while((err = stmt2.Next()) == KSqlAtRow)
   743 		{
   744 		}
   745 	TEST2(err, KSqlAtEnd);
   746 	stmt2.Close();
   747 	///////////////////////////////////////////////////////////////////////
   748 	_LIT(KSql3, "SELECT BO.* FROM Object1 AS BO WHERE(NOT Flags&?)AND (NOT Flags&?)AND ((BO.ObjectId IN(SELECT ObjectId FROM Object1 WHERE(Origin=?)))) ORDER BY CreationDate ASC,BO.ObjectId ASC ;");
   749 	RSqlStatement stmt3;
   750 	err = stmt3.Prepare(TheDb, KSql3);
   751 	TEST2(err, KErrNone);
   752 	err = stmt3.BindInt(0, 8);
   753 	TEST2(err, KErrNone);
   754 	err = stmt3.BindInt(1, 16);
   755 	TEST2(err, KErrNone);
   756 	err = stmt3.BindInt(2, 1);
   757 	TEST2(err, KErrNone);
   758 	while((err = stmt3.Next()) == KSqlAtRow)
   759 		{
   760 		}
   761 	TEST2(err, KSqlAtEnd);
   762 	stmt3.Close();
   763 	/////////////////////////////////////////////////////////////////////////
   764 	_LIT(KSql4, "SELECT count(*) FROM Object1 AS BO ,Album1 AS O ON BO.ObjectId=O.ObjectId WHERE(NOT Flags&?)AND (NOT Flags&?)  ORDER BY Title COLLATE NOCASE  ASC ;");
   765 	RSqlStatement stmt4;
   766 	err = stmt4.Prepare(TheDb, KSql4);
   767 	TEST2(err, KErrNone);
   768 	err = stmt4.BindInt(0, 8);
   769 	TEST2(err, KErrNone);
   770 	err = stmt4.BindInt(1, 16);
   771 	TEST2(err, KErrNone);
   772 	while((err = stmt4.Next()) == KSqlAtRow)
   773 		{
   774 		}
   775 	TEST2(err, KSqlAtEnd);
   776 	stmt4.Close();
   777 	///////////////////////////////////////////////////////////////////////////
   778 	_LIT(KSql5, "SELECT count(*) FROM Object1 AS BO WHERE(NOT Flags&?)AND (NOT Flags&?)AND (((BO.ObjectId IN(SELECT ObjectId FROM Object1 WHERE((NOT Flags&?)AND (NOT Flags&?)AND (NOT Flags&?)AND ObjectDefId=?))OR BO.ObjectId IN(SELECT ObjectId FROM Object1 WHERE((NOT Flags&?)AND (NOT Flags&?)AND (NOT Flags&?)AND ObjectDefId=?)))AND BO.ObjectId IN(SELECT ObjectId FROM Object1 WHERE(Origin!=?)))) ORDER BY CreationDate DESC,BO.ObjectId DESC ;");
   779 	RSqlStatement stmt5;
   780 	err = stmt5.Prepare(TheDb, KSql5);
   781 	TEST2(err, KErrNone);
   782 	err = stmt5.BindInt(0, 8);
   783 	TEST2(err, KErrNone);
   784 	err = stmt5.BindInt(1, 16);
   785 	TEST2(err, KErrNone);
   786 	err = stmt5.BindInt(2, 32);
   787 	TEST2(err, KErrNone);
   788 	err = stmt5.BindInt(3, 64);
   789 	TEST2(err, KErrNone);
   790 	err = stmt5.BindInt(4, 128);
   791 	TEST2(err, KErrNone);
   792 	err = stmt5.BindInt(5, 1);
   793 	TEST2(err, KErrNone);
   794 	err = stmt5.BindInt(6, 8);
   795 	TEST2(err, KErrNone);
   796 	err = stmt5.BindInt(7, 16);
   797 	TEST2(err, KErrNone);
   798 	err = stmt5.BindInt(8, 32);
   799 	TEST2(err, KErrNone);
   800 	err = stmt5.BindInt(9, 1);
   801 	TEST2(err, KErrNone);
   802 	err = stmt5.BindInt(10, 1);
   803 	TEST2(err, KErrNone);
   804 	while((err = stmt5.Next()) == KSqlAtRow)
   805 		{
   806 		}
   807 	TEST2(err, KSqlAtEnd);
   808 	stmt5.Close();
   809 	////////////////////////////////////////////////////////////////////////////////////////////////////////////
   810 	_LIT(KSql6, "SELECT count(*) FROM Object1 AS BO ,Tag1 AS O ON BO.ObjectId=O.ObjectId WHERE(NOT Flags&?)AND (NOT Flags&?)AND ((O.ObjectId IN(SELECT ObjectId FROM Object1 WHERE((NOT Flags&?)AND (NOT Flags&?)AND (NOT Flags&?)AND UsageCount>=?)))) ORDER BY Title COLLATE NOCASE  ASC ;");	
   811 	RSqlStatement stmt6;
   812 	err = stmt6.Prepare(TheDb, KSql6);
   813 	TEST2(err, KErrNone);
   814 	err = stmt6.BindInt(0, 8);
   815 	TEST2(err, KErrNone);
   816 	err = stmt6.BindInt(1, 16);
   817 	TEST2(err, KErrNone);
   818 	err = stmt6.BindInt(2, 32);
   819 	TEST2(err, KErrNone);
   820 	err = stmt6.BindInt(3, 64);
   821 	TEST2(err, KErrNone);
   822 	err = stmt6.BindInt(4, 128);
   823 	TEST2(err, KErrNone);
   824 	err = stmt6.BindInt(5, 1);
   825 	TEST2(err, KErrNone);
   826 	while((err = stmt6.Next()) == KSqlAtRow)
   827 		{
   828 		}
   829 	TEST2(err, KSqlAtEnd);
   830 	stmt6.Close();
   831 	
   832 	TUint32 fc2 = User::FastCounter();
   833 	TheHarvestSelect2Time += TimeDiffUs(fc1, fc2);
   834 	}
   835 
   836 void DoHarvestInsertEvent()
   837 	{
   838 	TUint32 fc1 = User::FastCounter();
   839 	
   840 	_LIT(KSql, "INSERT INTO Event1(EventId,ObjectId,EventDefId,Timestamp,Source,Participant) VALUES(?,?,?,?,?,?);");
   841 	const TInt KEventCnt = KItemCnt;
   842 	
   843 	for(TInt i=0;i<KEventCnt;++i)
   844 		{
   845 		BeginTransaction();
   846 		RSqlStatement stmt;
   847 		TInt err = stmt.Prepare(TheDb, KSql);
   848 		TEST2(err, KErrNone);
   849 		err = stmt.BindInt(0, i + 1);
   850 		TEST2(err, KErrNone);
   851 		err = stmt.BindInt(1, i + 1);
   852 		TEST2(err, KErrNone);
   853 		err = stmt.BindInt(2, i + 1);
   854 		TEST2(err, KErrNone);
   855 		err = stmt.BindInt64(3, 329231202230LL);
   856 		TEST2(err, KErrNone);
   857 		err = stmt.BindInt(4, 1);
   858 		TEST2(err, KErrNone);
   859 		err = stmt.BindInt(5, 367);
   860 		TEST2(err, KErrNone);
   861 		stmt.Close();
   862 		CommitTransaction();
   863 		}
   864 	
   865 	TUint32 fc2 = User::FastCounter();
   866 	TheHarvestInsertEventTime += TimeDiffUs(fc1, fc2);
   867 	}
   868 
   869 void DoHarvestUpdateObjImage()
   870 	{
   871 	TUint32 fc1 = User::FastCounter();
   872 	
   873 	_LIT(KSql1, "UPDATE Object1 SET Flags=? ,Origin=?,TimeOffset=?,ItemType=?,Title=? WHERE ObjectId=?;");
   874 	_LIT(KSql2, "UPDATE Image1 SET Width=?,Height=?,BitsPerSample=?,FrameCount=? WHERE ObjectId=?;");
   875 	
   876 	for(TInt i=0;i<KItemCnt;++i)
   877 		{
   878 		BeginTransaction();
   879 		
   880 		RSqlStatement stmt1;
   881 		TInt err = stmt1.Prepare(TheDb, KSql1);
   882 		TEST2(err, KErrNone);
   883 		err = stmt1.BindInt(0, 32);
   884 		TEST2(err, KErrNone);
   885 		err = stmt1.BindInt(1, 1);
   886 		TEST2(err, KErrNone);
   887 		err = stmt1.BindInt(2, 2);
   888 		TEST2(err, KErrNone);
   889 		err = stmt1.BindInt(3, 3);
   890 		TEST2(err, KErrNone);
   891 		TBuf<32> title;
   892 		title.Copy(_L("Title-"));
   893 		title.AppendNum(i + 1);
   894 		err = stmt1.BindText(4, title);
   895 		TEST2(err, KErrNone);
   896 		err = stmt1.BindInt(5, i + 1);
   897 		TEST2(err, KErrNone);
   898 		err = stmt1.Exec();
   899 		TEST2(err, 1);
   900 		stmt1.Close();
   901 
   902 		RSqlStatement stmt2;
   903 		err = stmt2.Prepare(TheDb, KSql2);
   904 		TEST2(err, KErrNone);
   905 		err = stmt2.BindInt(0, 1000);
   906 		TEST2(err, KErrNone);
   907 		err = stmt2.BindInt(1, 1200);
   908 		TEST2(err, KErrNone);
   909 		err = stmt2.BindInt(2, 24);
   910 		TEST2(err, KErrNone);
   911 		err = stmt2.BindInt(3, 3);
   912 		TEST2(err, KErrNone);
   913 		err = stmt2.BindInt(4, i + 1);
   914 		TEST2(err, KErrNone);
   915 		err = stmt2.Exec();
   916 		TEST2(err, 1);
   917 		stmt2.Close();
   918 
   919 		CommitTransaction();
   920 		}
   921 	
   922 	TUint32 fc2 = User::FastCounter();
   923 	TheHarvestUpdateObjImageTime += TimeDiffUs(fc1, fc2);
   924 	}
   925 
   926 void DoHarvestSelect3()
   927 	{
   928 	TUint32 fc1 = User::FastCounter();
   929 	
   930 	_LIT(KSql1, "SELECT BO.* ,O.* FROM Object1 AS BO ,Image1 AS O ON BO.ObjectId=O.ObjectId WHERE(NOT Flags&?)AND (NOT Flags&?)AND ((O.ObjectId IN(SELECT ObjectId FROM Object1 WHERE((NOT Flags&?)AND (NOT Flags&?)AND ObjectId=?))))LIMIT 1;");
   931 	
   932 	for(TInt i=0;i<KItemCnt;++i)
   933 		{
   934 		RSqlStatement stmt;
   935 		TInt err = stmt.Prepare(TheDb, KSql1);
   936 		TEST2(err, KErrNone);
   937 		err = stmt.BindInt(0, 65536);
   938 		TEST2(err, KErrNone);
   939 		err = stmt.BindInt(1, 65536);
   940 		TEST2(err, KErrNone);
   941 		err = stmt.BindInt(2, 65536);
   942 		TEST2(err, KErrNone);
   943 		err = stmt.BindInt(3, 65536);
   944 		TEST2(err, KErrNone);
   945 		err = stmt.BindInt(4, i + 1);
   946 		TEST2(err, KErrNone);
   947 		TInt cnt = 0;
   948 		while((err = stmt.Next()) == KSqlAtRow)
   949 			{
   950 			++cnt;
   951 			}
   952 		TEST2(err, KSqlAtEnd);
   953 		TEST2(cnt, 1);
   954 		stmt.Close();
   955 		}
   956 
   957 	TUint32 fc2 = User::FastCounter();
   958 	TheHarvestSelect3Time += TimeDiffUs(fc1, fc2);
   959 	}
   960 
   961 void DoHarvestSelect4()
   962 	{
   963 	TUint32 fc1 = User::FastCounter();
   964 	
   965 	_LIT(KSql2, "SELECT BO.* FROM Object1 AS BO WHERE(NOT Flags&?)AND (NOT Flags&?)AND ((BO.ObjectId IN(SELECT ObjectId FROM Object1 WHERE((NOT Flags&?)AND (NOT Flags&?)AND (NOT Flags&?)AND ObjectId=?))));");
   966 	
   967 	for(TInt i=0;i<KItemCnt;++i)
   968 		{
   969 		RSqlStatement stmt;
   970 		TInt err = stmt.Prepare(TheDb, KSql2);
   971 		TEST2(err, KErrNone);
   972 		err = stmt.BindInt(0, 65536);
   973 		TEST2(err, KErrNone);
   974 		err = stmt.BindInt(1, 65536);
   975 		TEST2(err, KErrNone);
   976 		err = stmt.BindInt(2, 65536);
   977 		TEST2(err, KErrNone);
   978 		err = stmt.BindInt(3, 65536);
   979 		TEST2(err, KErrNone);
   980 		err = stmt.BindInt(4, 65536);
   981 		TEST2(err, KErrNone);
   982 		err = stmt.BindInt(5, i + 1);
   983 		TEST2(err, KErrNone);
   984 		TInt cnt = 0;
   985 		while((err = stmt.Next()) == KSqlAtRow)
   986 			{
   987 			++cnt;
   988 			}
   989 		TEST2(err, KSqlAtEnd);
   990 		TEST2(cnt, 1);
   991 		stmt.Close();
   992 		}
   993 	
   994 	TUint32 fc2 = User::FastCounter();
   995 	TheHarvestSelect4Time += TimeDiffUs(fc1, fc2);
   996 	}
   997 
   998 void DoHarvestUpdateObj()
   999 	{
  1000 	TUint32 fc1 = User::FastCounter();
  1001 
  1002 	_LIT(KSql, "UPDATE Object1 SET Flags=Flags&? WHERE ObjectId IN(?);");
  1003 	
  1004 	for(TInt i=0;i<KItemCnt;++i)
  1005 		{
  1006 		BeginTransaction();
  1007 		RSqlStatement stmt;
  1008 		TInt err = stmt.Prepare(TheDb, KSql);
  1009 		TEST2(err, KErrNone);
  1010 		err = stmt.BindInt(0, 32768);
  1011 		TEST2(err, KErrNone);
  1012 		err = stmt.BindInt(1, i + 1);
  1013 		TEST2(err, KErrNone);
  1014 		err = stmt.Exec();
  1015 		TEST2(err, 1);
  1016 		stmt.Close();
  1017 		CommitTransaction();
  1018 		}
  1019 	
  1020 	TUint32 fc2 = User::FastCounter();
  1021 	TheHarvestUpdateObjTime += TimeDiffUs(fc1, fc2);
  1022 	}
  1023 
  1024 void Harvest()
  1025 	{
  1026 	TUint32 fc1 = User::FastCounter();	
  1027 	DoHarvestSelect();
  1028 	DoHarvestInsertObjImage();
  1029 	DoHarvestSelect2();
  1030 	DoHarvestSelect2();
  1031 	DoHarvestSelect2();
  1032 	DoHarvestInsertEvent();
  1033 	DoHarvestUpdateObjImage();
  1034 	DoHarvestSelect3();
  1035 	DoHarvestSelect4();
  1036 	DoHarvestUpdateObj();
  1037 	TUint32 fc2 = User::FastCounter();
  1038 	TheHarvestTime += TimeDiffUs(fc1, fc2);
  1039 	}
  1040 
  1041 /**
  1042 @SYMTestCaseID			PDS-SQL-UT-4150
  1043 @SYMTestCaseDesc		MDS harvesting performance test.
  1044 						The test reproduces the MDS harvesting actions with the SQL server,
  1045 						performed for 1000 images. The time taken for the execution of SQL statements 
  1046 						is measured and printed out.
  1047 @SYMTestActions			MDS harvesting performance test.
  1048 @SYMTestExpectedResults Test must not fail
  1049 @SYMTestPriority		High
  1050 @SYMDEF					DEF142327
  1051 */
  1052 void PrintResults()
  1053 	{
  1054 	TheTest.Printf(_L("==Fast counter frequency=%d Hz\r\n"), TheFastCounterFreq);
  1055 	TheTest.Printf(_L("==Create database, time=%d us\r\n"), TheCreateDbCreateConnTime);
  1056 	TheTest.Printf(_L("==Open database, time=%d us\r\n"), TheCreateDbOpenConnTime);
  1057 	TheTest.Printf(_L("=='SELECT max(seq) FROM SQLITE_SEQUENCE', time=%d us\r\n"), TheLastItemIdTime);
  1058 	TheTest.Printf(_L("=='SELECT COUNT(*) FROM MdE_Preferences', time=%d us\r\n"), TheTableExistsTime);
  1059 	TheTest.Printf(_L("==MDE tables creation, time=%d us\r\n"), TheMdeTablesCreationTime);
  1060 	TheTest.Printf(_L("=='SELECT last_insert_rowid()', time=%d us\r\n"), TheLastInsertedRowIdTime);
  1061 	TheTest.Printf(_L("==1.Create tables, time=%d us\r\n"), TheCreateTables1Time);
  1062 	TheTest.Printf(_L("==2.Create tables, time=%d us\r\n"), TheCreateTables2Time);
  1063 	TheTest.Printf(_L("==3.Create tables, time=%d us\r\n"), TheCreateTables3Time);
  1064 	TheTest.Printf(_L("==InsertEventRelation, time=%d us\r\n"), TheInsertEventRelationTime);
  1065 	TheTest.Printf(_L("==Create triggers, time=%d us\r\n"), TheCreateTriggersTime);
  1066 	TheTest.Printf(_L("==DeleteObjectProperty, time=%d us\r\n"), TheDeleteObjPropertyTime);
  1067 	TheTest.Printf(_L("==InsertCol2Property, time=%d us\r\n"), TheInsertCol2PropTime);
  1068 	TheTest.Printf(_L("==The create transaction, time=%d us\r\n"), TheTransactionTime);
  1069 	TheTest.Printf(_L("==Database create schema, time=%d us\r\n"), TheDbCreateTime);
  1070 
  1071 	TheTest.Printf(_L("==HarvestSelect, time=%d us\r\n"), TheHarvestSelectTime);
  1072 	TheTest.Printf(_L("==HarvestInsertObjImage, time=%d us\r\n"), TheHarvestInsertObjImageTime);
  1073 	TheTest.Printf(_L("==HarvestSelect2, time=%d us\r\n"), TheHarvestSelect2Time);
  1074 	TheTest.Printf(_L("==HarvestSelect3, time=%d us\r\n"), TheHarvestSelect3Time);
  1075 	TheTest.Printf(_L("==HarvestSelect4, time=%d us\r\n"), TheHarvestSelect4Time);
  1076 	TheTest.Printf(_L("==HarvestInsertEvent, time=%d us\r\n"), TheHarvestInsertEventTime);
  1077 	TheTest.Printf(_L("==HarvestUpdateObjImage, time=%d us\r\n"), TheHarvestUpdateObjImageTime);
  1078 	TheTest.Printf(_L("==HarvestUpdateObj, time=%d us\r\n"), TheHarvestUpdateObjTime);
  1079 	TheTest.Printf(_L("==Harvest, time=%d us\r\n"), TheHarvestTime);
  1080 	}
  1081 
  1082 void DoTestsL()
  1083 	{
  1084 	CalcIterationsCount();
  1085 	
  1086 	TheTestTitle.Format(_L("@SYMTestCaseID:PDS-SQL-UT-4149 Create database, encoding: \"%S\", page size: %d\r\n"), 
  1087 			TheCmdLineParams.iDbEncoding == TCmdLineParams::EDbUtf16 ? &KUtf16 : &KUtf8, TheCmdLineParams.iPageSize);
  1088 	TheTest.Start(TheTestTitle);
  1089 	CreateDb();
  1090 
  1091 	TheTestTitle.Format(_L("@SYMTestCaseID:PDS-SQL-UT-4150 Harvest %d items, encoding: \"%S\", page size: %d\r\n"), 
  1092 			KItemCnt, TheCmdLineParams.iDbEncoding == TCmdLineParams::EDbUtf16 ? &KUtf16 : &KUtf8, TheCmdLineParams.iPageSize);
  1093 	TheTest.Next(TheTestTitle);
  1094 	Harvest();
  1095 	
  1096 	PrintResults();
  1097 	}
  1098 
  1099 TInt E32Main()
  1100 	{
  1101 	TheTest.Title();
  1102 
  1103 	CTrapCleanup* tc = CTrapCleanup::New();
  1104 	TheTest(tc != NULL);
  1105 	
  1106 	__UHEAP_MARK;
  1107 
  1108 	GetCmdLineParamsAndSqlConfigString(TheTest, _L("t_sqlperformance3"), TheCmdLineParams, TheSqlConfigString);
  1109 	PrepareDbName(KDbName, TheCmdLineParams.iDriveName, TheDbFileName);
  1110 
  1111 	TheTest.Printf(_L("==Databases: %S\r\n"), &TheDbFileName); 
  1112 	
  1113 	TestEnvDestroy();
  1114 	TestEnvInit();
  1115 	TRAPD(err, DoTestsL());
  1116 	TestEnvDestroy();
  1117 	TEST2(err, KErrNone);
  1118 
  1119 	__UHEAP_MARKEND;
  1120 	
  1121 	TheTest.End();
  1122 	TheTest.Close();
  1123 	
  1124 	delete tc;
  1125 
  1126 	User::Heap().Check();
  1127 	return KErrNone;
  1128 	}