os/persistentdata/persistentstorage/dbms/pcdbms/tdbms/src/t_sql.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 1998-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 // MSVC++ up to 5.0 has problems with expanding inline functions
    17 // This disables the mad warnings for the whole project
    18 #if defined(NDEBUG) && defined(__VC32__) && _MSC_VER<=1100
    19 #pragma warning(disable : 4710)			// function not expanded. MSVC 5.0 is stupid
    20 #endif
    21 
    22 #include <d32dbms.h>
    23 #include <f32file.h>
    24 #include <e32test.h>
    25 #include <e32math.h>
    26 
    27 #include "crccheck.h"
    28 
    29 #undef __UHEAP_MARK
    30 #define __UHEAP_MARK
    31 #undef __UHEAP_MARKEND
    32 #define __UHEAP_MARKEND
    33 
    34 LOCAL_D TDBMS_CRCChecks TheCrcChecker;
    35 
    36 #ifndef __linux__ //No CRC test on LINUX
    37 #ifdef __TOOLS2__
    38 const TPtrC	KCrcRecord=_L("\\epoc32\\winscw\\c\\dbms-tst\\T_SQL.CRC");
    39 #else
    40 const TPtrC	KCrcRecord=_L("C:\\dbms-tst\\T_SQL.CRC");
    41 #endif
    42 #endif
    43 
    44 // constructing literal TInt64 from compiler 64 bit integer rep
    45 
    46 #ifndef I64LIT
    47 #if defined __GCC32__ || defined __EABI__
    48 #define _LINT64(val) MAKE_TINT64(TUint(val##LL>>32),TUint(val##LL&0xffffffffu))
    49 #else
    50 #define _LINT64(val) MAKE_TINT64(TUint(__int64(val)>>32),TUint(__int64(val)&0xffffffffu))
    51 #endif
    52 #else // I64LIT
    53 #define _LINT64 I64LIT
    54 #endif // I64LIT
    55 
    56 LOCAL_D RTest TheTest(_L("T_SQL: DBMS SQL parsing and execution tests"));
    57 
    58 LOCAL_D RFs TheFs;
    59 LOCAL_D CTrapCleanup* TheTrapCleanup;
    60 LOCAL_D RDbs TheDbs;
    61 LOCAL_D RDbNamedDatabase TheDatabase;
    62 LOCAL_D RDbTable TheTable;
    63 LOCAL_D RDbView TheView;
    64 LOCAL_D TBuf<1024> TheSql;
    65 
    66 const TInt KTestCleanupStack=0x20;
    67 
    68 #ifdef __TOOLS2__
    69 const TPtrC KTestDatabase=_L(".\\dbms-tst\\T_SQL.DB");
    70 #else
    71 const TPtrC KTestDatabase=_L("C:\\dbms-tst\\T_SQL.DB");
    72 #endif
    73 
    74 #define elementsof(array) (sizeof(array)/sizeof(array[0]))
    75 
    76 LOCAL_C void TestCleanup()
    77 	{
    78 	TheTable.Close();
    79 	TheView.Close();
    80 	TheDatabase.Close();
    81 #ifndef __TOOLS2__
    82 	TheDbs.Close();
    83 #endif
    84 
    85 	TRAPD(errCode, TheCrcChecker.GenerateCrcL(KTestDatabase));
    86 
    87 	TheFs.Close();
    88 	/////////////
    89 	RFs fsSession;
    90 	TInt err = fsSession.Connect();
    91 	if(err == KErrNone)
    92 		{
    93 		TEntry entry;
    94 		if(fsSession.Entry(KTestDatabase, entry) == KErrNone)
    95 			{
    96 			RDebug::Print(_L("Deleting \"%S\" file.\n"), &KTestDatabase);
    97 			err = fsSession.SetAtt(KTestDatabase, 0, KEntryAttReadOnly);
    98 			if(err != KErrNone) 
    99 				{
   100 				RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &KTestDatabase);
   101 				}
   102 			err = fsSession.Delete(KTestDatabase);
   103 			if(err != KErrNone) 
   104 				{
   105 				RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &KTestDatabase);
   106 				}
   107 			}
   108 		fsSession.Close();
   109 		}
   110 	else
   111 		{
   112 		RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &KTestDatabase);
   113 		}
   114 	}
   115 
   116 LOCAL_C void CloseDatabase()
   117 	{
   118 	TheDatabase.Close();
   119 	TRAPD(errCode, TheCrcChecker.GenerateCrcL(KTestDatabase));
   120 
   121 	}
   122 
   123 LOCAL_C void Disconnect()
   124 	{
   125 #ifndef __TOOLS2__
   126 	TheDbs.ResourceCheck();
   127 	TheDbs.Close();
   128 #endif
   129 	}
   130 
   131 ///////////////////////////////////////////////////////////////////////////////////////
   132 ///////////////////////////////////////////////////////////////////////////////////////
   133 //Tests macros and functions.
   134 //If (!aValue) then the test will be panicked, the test data files will be deleted.
   135 static void Check(TInt aValue, TInt aLine)
   136 	{
   137 	if(!aValue)
   138 		{
   139 		::TestCleanup();
   140 		TheTest(EFalse, aLine);
   141 		}
   142 	}
   143 //If (aValue != aExpected) then the test will be panicked, the test data files will be deleted.
   144 static void Check(TInt aValue, TInt aExpected, TInt aLine)
   145 	{
   146 	if(aValue != aExpected)
   147 		{
   148 		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
   149 		::TestCleanup();
   150 		TheTest(EFalse, aLine);
   151 		}
   152 	}
   153 //Use these to test conditions.
   154 #define TEST(arg) ::Check((arg), __LINE__)
   155 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
   156 
   157 ///////////////////////////////////////////////////////////////////////////////////////
   158 ///////////////////////////////////////////////////////////////////////////////////////
   159 
   160 // Create the database
   161 LOCAL_C void CreateDatabase()
   162 	{
   163 	TInt r=TheDatabase.Replace(TheFs,KTestDatabase);
   164 	TEST2(r, KErrNone);
   165 	}
   166 
   167 LOCAL_C void Connect()
   168 	{
   169 #ifndef __TOOLS2__
   170 	TInt r=TheDbs.Connect();
   171 	TEST2(r, KErrNone);
   172 	TheDbs.ResourceMark();
   173 #endif
   174 	}
   175 
   176 // Open the database through the server
   177 LOCAL_C void ShareDatabase()
   178 	{
   179 	TInt r=TheDatabase.Open(TheDbs,KTestDatabase);
   180 	TEST2(r, KErrNone);
   181 	}
   182 
   183 struct TSelectTest
   184 	{
   185 	const TText* iSearchCondition;
   186 	TUint iResultSet;
   187 	};
   188 #define ROWS(n,m) (((~0u)<<(n))&((2u<<(m))-1))
   189 #define ROW(n) ROWS(n,n)
   190 #define NO_ROWS 0
   191 #define ALL_ROWS (~1u)		// all rows which are not NULL
   192 
   193 class TestPredicateBase
   194 	{
   195 protected:
   196 	static void Create(const TText* aType);
   197 	static void Test(const TSelectTest* aTest,TInt aCount,TInt aRows);
   198 	static void TestViewL(const TSelectTest* aTest,TInt aCount,TInt aRows);
   199 	};
   200 
   201 // Create the table for the predicate tests
   202 void TestPredicateBase::Create(const TText* aType)
   203 	{
   204 	TheTest.Next(TPtrC(aType));
   205 	TheDatabase.Begin();
   206 	TheSql.Format(_L("CREATE TABLE Compare (Id COUNTER,Test %s)"),aType);
   207 	TInt r=TheDatabase.Execute(TheSql);
   208 	TEST2(r, KErrNone);
   209 	r=TheTable.Open(TheDatabase,_L("Compare"),TheTable.EInsertOnly);
   210 	TEST2(r, KErrNone);
   211 	}
   212 
   213 // Test the predicate on the table, then on the indexed table
   214 void TestPredicateBase::Test(const TSelectTest* aTest,TInt aCount,TInt aRows)
   215 	{
   216 	TheTable.Close();
   217 	TInt r=TheDatabase.Commit();
   218 	TEST2(r, KErrNone);
   219 	TRAPD(errCode, TestViewL(aTest,aCount,aRows));
   220 	TEST2(errCode, KErrNone);
   221 	r=TheDatabase.Execute(_L("CREATE INDEX Key ON Compare (Test)"));
   222 	TEST2(r, KErrNone);
   223 	TRAP(errCode,TestViewL(aTest,aCount,aRows));
   224 	TEST2(errCode, KErrNone);
   225 	r=TheDatabase.Execute(_L("DROP TABLE Compare"));
   226 	TEST2(r, KErrNone);
   227 	}
   228 
   229 // Test the predicate on the table
   230 void TestPredicateBase::TestViewL(const TSelectTest* aTest,TInt aCount,TInt aRows)
   231 	{
   232 	TUint rowMask=(2u<<aRows)-1;
   233 	for (;--aCount>=0;++aTest)
   234 		{
   235 		TheSql.Format(_L("SELECT Id FROM Compare WHERE Test %s"),aTest->iSearchCondition);
   236 		TInt r=TheView.Prepare(TheDatabase,TheSql,TheView.EReadOnly);
   237 		TBool ignoreRow0=TheView.Unevaluated();
   238 		TEST2(r, KErrNone);
   239 		r=TheView.EvaluateAll();
   240 		TEST2(r, KErrNone);
   241 		TUint rows=0;
   242 		while (TheView.NextL())
   243 			{
   244 			TheView.GetL();
   245 			rows|=1u<<TheView.ColUint(1);
   246 			}
   247 		if (ignoreRow0)
   248 			TEST((rows&~ROW(0))==(aTest->iResultSet&rowMask&~ROW(0)));
   249 		else
   250 			TEST(rows==(aTest->iResultSet&rowMask));
   251 		TheView.Close();
   252 		}
   253 	}
   254 
   255 typedef void (*FSetColL)(TDbColNo aCol,const TAny* aVal);
   256 
   257 void WriteRows(const TAny* aValues,TInt aRows,TInt aSize,FSetColL aSetColL)
   258 	{
   259 	for (TInt row=0;row<=aRows;++row)
   260 		{
   261 		TheTable.InsertL();
   262 		TEST(TheTable.ColUint(1)==TUint(row));
   263 		if (row>0)
   264 			{	// first row is always null
   265 			aSetColL(2,aValues);
   266 			aValues=PtrAdd(aValues,aSize);
   267 			}
   268 		TheTable.PutL();
   269 		}
   270 	}
   271 
   272 template <class T>
   273 struct SetCol
   274 	{
   275 	static void SetColL(TDbColNo aCol,const TAny* aVal)
   276 		{
   277 		TheTable.SetColL(aCol,*(const T*)aVal);
   278 		}
   279 	};
   280 
   281 template <class T>
   282 inline void WriteRows(const T* aValues,TUint aRows)
   283 	{
   284 	WriteRows(aValues,aRows,sizeof(T),&SetCol<T>::SetColL);
   285 	}
   286 
   287 template <class T>
   288 class TestPredicate : public TestPredicateBase
   289 	{
   290 public:
   291 	static void Run();
   292 	};
   293 
   294 // Test the Predicate operators for all types
   295 template <class T>
   296 void TestPredicate<T>::Run()
   297 	{
   298 	Create(T::KType);
   299 	WriteRows(T::KValues,elementsof(T::KValues));
   300 	Test(T::KTests,elementsof(T::KTests),elementsof(T::KValues));
   301 	}
   302 
   303 struct TypeBit
   304 	{
   305 public:
   306 	static const TText* const KType;
   307 	static const TUint KValues[];
   308 	static const TSelectTest KTests[];
   309 	};
   310 const TText* const TypeBit::KType=_S("BIT");
   311 const TUint TypeBit::KValues[]={0,1};
   312 const TSelectTest TypeBit::KTests[]=
   313 	{
   314 	{_S("IS NULL"),ROW(0)},
   315 	{_S("IS NOT NULL"),ALL_ROWS},
   316 	{_S("=0"),ROW(1)},
   317 	{_S("<>0"),ROW(2)},
   318 	{_S(">0"),ROW(2)},
   319 	{_S("<0"),NO_ROWS},
   320 	{_S("<=0"),ROW(1)},
   321 	{_S(">=0"),ALL_ROWS},
   322 	{_S("=1"),ROW(2)},
   323 	{_S("<>1"),ROW(1)},
   324 	{_S(">1"),NO_ROWS},
   325 	{_S("<1"),ROW(1)},
   326 	{_S("<=1"),ALL_ROWS},
   327 	{_S(">=1"),ROW(2)}
   328 	};
   329 
   330 struct TypeUint8
   331 	{
   332 public:
   333 	static const TText* const KType;
   334 	static const TUint KValues[];
   335 	static const TSelectTest KTests[];
   336 	};
   337 const TText* const TypeUint8::KType=_S("UNSIGNED TINYINT");
   338 const TUint TypeUint8::KValues[]={0,1,127,128,254,255};
   339 const TSelectTest TypeUint8::KTests[]=
   340 	{
   341 	{_S("IS NULL"),ROW(0)},
   342 	{_S("IS NOT NULL"),ALL_ROWS},
   343 	{_S("=0"),ROW(1)},
   344 	{_S("=3"),NO_ROWS},
   345 	{_S("<2"),ROWS(1,2)},
   346 	{_S(">=0"),ALL_ROWS},
   347 	{_S("<128"),ROWS(1,3)},
   348 	{_S("<>1"),ALL_ROWS-ROW(2)},
   349 	{_S(">255"),NO_ROWS}
   350 	};
   351 
   352 struct TypeUint16
   353 	{
   354 public:
   355 	static const TText* const KType;
   356 	static const TUint KValues[];
   357 	static const TSelectTest KTests[];
   358 	};
   359 const TText* const TypeUint16::KType=_S("UNSIGNED SMALLINT");
   360 const TUint TypeUint16::KValues[]={0,1,5000,32767,32768,65534,65535};
   361 const TSelectTest TypeUint16::KTests[]=
   362 	{
   363 	{_S("IS NULL"),ROW(0)},
   364 	{_S("IS NOT NULL"),ALL_ROWS},
   365 	{_S("=0"),ROW(1)},
   366 	{_S("=3"),NO_ROWS},
   367 	{_S("<2"),ROWS(1,2)},
   368 	{_S(">=32768"),ROWS(5,7)},
   369 	{_S("<32767"),ROWS(1,3)},
   370 	{_S("<>1"),ALL_ROWS-ROW(2)},
   371 	{_S(">65535"),NO_ROWS}
   372 	};
   373 
   374 struct TypeUint32
   375 	{
   376 public:
   377 	static const TText* const KType;
   378 	static const TUint KValues[];
   379 	static const TSelectTest KTests[];
   380 	};
   381 const TText* const TypeUint32::KType=_S("UNSIGNED INTEGER");
   382 const TUint TypeUint32::KValues[]={0,1,2147483647u,2147483648u,3000000000u,4294967294u,4294967295u};
   383 const TSelectTest TypeUint32::KTests[]=
   384 	{
   385 	{_S("IS NULL"),ROW(0)},
   386 	{_S("IS NOT NULL"),ALL_ROWS},
   387 	{_S("=0"),ROW(1)},
   388 	{_S("=3"),NO_ROWS},
   389 	{_S("<2"),ROWS(1,2)},
   390 	{_S(">=2147483648"),ROWS(4,7)},
   391 	{_S("<2147483647"),ROWS(1,2)},
   392 	{_S("<>3000000000"),ALL_ROWS-ROW(5)},
   393 	{_S(">4294967295"),NO_ROWS}
   394 	};
   395 
   396 struct TypeInt8
   397 	{
   398 public:
   399 	static const TText* const KType;
   400 	static const TInt KValues[];
   401 	static const TSelectTest KTests[];
   402 	};
   403 const TText* const TypeInt8::KType=_S("TINYINT");
   404 const TInt TypeInt8::KValues[]={-128,-1,0,1,127};
   405 const TSelectTest TypeInt8::KTests[]=
   406 	{
   407 	{_S("IS NULL"),ROW(0)},
   408 	{_S("IS NOT NULL"),ALL_ROWS},
   409 	{_S("=0"),ROW(3)},
   410 	{_S("=-1"),ROW(2)},
   411 	{_S("<2"),ROWS(1,4)},
   412 	{_S(">=-128"),ALL_ROWS},
   413 	{_S("<128"),ALL_ROWS},
   414 	{_S("<>1"),ALL_ROWS-ROW(4)}
   415 	};
   416 
   417 struct TypeInt16
   418 	{
   419 public:
   420 	static const TText* const KType;
   421 	static const TInt KValues[];
   422 	static const TSelectTest KTests[];
   423 	};
   424 const TText* const TypeInt16::KType=_S("SMALLINT");
   425 const TInt TypeInt16::KValues[]={-32768,-32767,-1,0,1,32766,32767};
   426 const TSelectTest TypeInt16::KTests[]=
   427 	{
   428 	{_S("IS NULL"),ROW(0)},
   429 	{_S("IS NOT NULL"),ALL_ROWS},
   430 	{_S("=0"),ROW(4)},
   431 	{_S("<>0"),ALL_ROWS-ROW(4)},
   432 	{_S("=-1"),ROW(3)},
   433 	{_S("<2"),ROWS(1,5)},
   434 	{_S(">=-40000"),ALL_ROWS},
   435 	{_S("<32766"),ROWS(1,5)},
   436 	{_S("=40"),NO_ROWS}
   437 	};
   438 
   439 struct TypeInt32
   440 	{
   441 public:
   442 	static const TText* const KType;
   443 	static const TInt KValues[];
   444 	static const TSelectTest KTests[];
   445 	};
   446 const TText* const TypeInt32::KType=_S("INTEGER");
   447 const TInt TypeInt32::KValues[]={0x80000000/*-2147483648*/,-2147483647,-1,0,1,2147483646,2147483647};
   448 const TSelectTest TypeInt32::KTests[]=
   449 	{
   450 	{_S("IS NULL"),ROW(0)},
   451 	{_S("IS NOT NULL"),ALL_ROWS},
   452 	{_S("=0"),ROW(4)},
   453 	{_S("<>0"),ALL_ROWS-ROW(4)},
   454 	{_S("=-1"),ROW(3)},
   455 	{_S("<2"),ROWS(1,5)},
   456 	{_S(">=-2147483648"),ALL_ROWS},
   457 	{_S("<2147483646"),ROWS(1,5)},
   458 	{_S(">2147483647"),NO_ROWS},
   459 	{_S("=40"),NO_ROWS}
   460 	};
   461 
   462 struct TypeInt64
   463 	{
   464 public:
   465 	static const TText* const KType;
   466 	static const TInt64 KValues[];
   467 	static const TSelectTest KTests[];
   468 	};
   469 const TText* const TypeInt64::KType=_S("BIGINT");
   470 const TInt64 TypeInt64::KValues[]=
   471 	{
   472 	MAKE_TINT64(0x80000000, 0x00000000), // min int64
   473 	_LINT64(-4294967296),
   474 	TInt(0x80000000),			// -2147483648!
   475 	-1,
   476 	0u,
   477 	1u,
   478 	2147483647u,
   479 	_LINT64(2147483648),
   480 	_LINT64(4294967295),
   481 	_LINT64(4294967296),
   482 	_LINT64(9223372036854775807)		// max int64
   483 	};
   484 const TSelectTest TypeInt64::KTests[]=
   485 	{
   486 	{_S("IS NULL"),ROW(0)},
   487 	{_S("IS NOT NULL"),ALL_ROWS},
   488 	{_S("=0"),ROW(5)},
   489 	{_S("<>0"),ALL_ROWS-ROW(5)},
   490 	{_S("=-1"),ROW(4)},
   491 	{_S("<2"),ROWS(1,6)},
   492 	{_S(">=-9223372036854775808"),ALL_ROWS},
   493 	{_S("<4294967296"),ROWS(1,9)},
   494 	{_S(">9223372036854775806"),ROW(11)},
   495 	{_S("=40"),NO_ROWS}
   496 	};
   497 
   498 struct TypeReal32
   499 	{
   500 public:
   501 	static const TText* const KType;
   502 	static const TReal32 KValues[];
   503 	static const TSelectTest KTests[];
   504 	};
   505 const TText* const TypeReal32::KType=_S("REAL");
   506 const TReal32 TypeReal32::KValues[]=
   507 	{
   508 	-KMaxTReal32,
   509 	-1.0f,
   510 	-KMinTReal32,
   511 	0.0f,
   512 	KMinTReal32,
   513 	1.0f,
   514 	KMaxTReal32
   515 	};
   516 const TSelectTest TypeReal32::KTests[]=
   517 	{
   518 	{_S("IS NULL"),ROW(0)},
   519 	{_S("IS NOT NULL"),ALL_ROWS},
   520 	{_S("=0"),ROW(4)},
   521 	{_S("<>0.0"),ALL_ROWS-ROW(4)},
   522 	{_S("=-1"),ROW(2)},
   523 	{_S("<2e1"),ROWS(1,6)},
   524 	{_S(">=-100000000000000"),ROWS(2,7)},
   525 	{_S("<1e-36"),ROWS(1,5)},
   526 	{_S(">1e15"),ROW(7)},
   527 	{_S("=.5"),NO_ROWS},
   528 	{_S("<=-.0"),ROWS(1,4)},
   529 	{_S("<1e40"),ALL_ROWS}
   530 	};
   531 
   532 struct TypeReal64
   533 	{
   534 public:
   535 	static const TText* const KType;
   536 	static const TReal64 KValues[];
   537 	static const TSelectTest KTests[];
   538 	};
   539 const TText* const TypeReal64::KType=_S("DOUBLE");
   540 const TReal64 TypeReal64::KValues[]=
   541 	{
   542 	-KMaxTReal64,
   543 	-1.0f,
   544 	-KMinTReal64,
   545 	0.0f,
   546 	KMinTReal64,
   547 	1.0f,
   548 	KMaxTReal64
   549 	};
   550 const TSelectTest TypeReal64::KTests[]=
   551 	{
   552 	{_S("IS NULL"),ROW(0)},
   553 	{_S("IS NOT NULL"),ALL_ROWS},
   554 	{_S("=0"),ROW(4)},
   555 	{_S("<>0"),ALL_ROWS-ROW(4)},
   556 	{_S("=-1"),ROW(2)},
   557 	{_S("<2"),ROWS(1,6)},
   558 	{_S(">=-100000000000000"),ROWS(2,7)},
   559 	{_S("<1e-300"),ROWS(1,5)},
   560 	{_S(">1e15"),ROW(7)},
   561 	{_S("=.5"),NO_ROWS},
   562 	{_S("<=0"),ROWS(1,4)},
   563 	{_S("<1e40"),ROWS(1,6)}
   564 	};
   565 
   566 struct TypeTime
   567 	{
   568 public:
   569 	static const TText* const KType;
   570 	static const TTime KValues[];
   571 	static const TSelectTest KTests[];
   572 	};
   573 const TText* const TypeTime::KType=_S("TIME");
   574 const TTime TypeTime::KValues[]=
   575 	{
   576 	TInt64(0u),				// zero date/time
   577 	_L(":085815"),			// 8:58:15am
   578 	_L("19181010:110000"),	// 11am, 11 Nov 1918
   579 	_L("19750226:"),		// midnight, 27 Mar 1975
   580 	_L("19961130:235959"),	// 11:59:59pm, 31 Dec 1996
   581 	_L("19970000:"),		// midnight, 1 Jan 1997
   582 	_L("19970611:210000"),	// 9pm, 12 July 1997
   583 	_L("19980309:214500"),	// 9:45pm, 10 April 1998
   584 	_L("20700608:")			// midnight, 9 July 2070
   585 	};
   586 const TSelectTest TypeTime::KTests[]=
   587 	{
   588 	{_S("IS NULL"),ROW(0)},
   589 	{_S("IS NOT NULL"),ALL_ROWS},
   590 	{_S("=#12am#"),ROW(1)},
   591 	{_S("<#Jan 1 2100#"),ALL_ROWS},
   592 	{_S("<>#31/12/1996 23:59:59#"),ALL_ROWS-ROW(5)},
   593 	{_S("<#9a#"),ROWS(1,2)},
   594 	{_S(">=#11:59:59pm, 31 Dec 1996#"),ROWS(5,9)},
   595 	{_S("=#9:45pm 10 April, 1998#"),ROW(8)},
   596 	{_S("=#8:58:15#"),ROW(2)}
   597 	};
   598 
   599 struct TypeText
   600 	{
   601 public:
   602 	static const TText* const KType;
   603 	static const TText* const KValues[];
   604 	static TSelectTest KTests[];
   605 	};
   606 const TText* const TypeText::KType=_S("VARCHAR(100)");
   607 const TText* const TypeText::KValues[]=
   608 	{
   609 	_S(""),					// this should be equivalent to NULL
   610 	_S("a"),
   611 	_S("aa"),
   612 	_S("aba"),
   613 	_S("like"),
   614 	_S("abcdefghijklmnopqrstuvwxyzlike"),
   615 	_S("likeabcdefghijklmnopqrstuvwxyz"),
   616 	_S("abcdefghijklmnopqrstuvwxyzlikeabcdefghijklmnopqrstuvwxyz"),
   617 	_S("abcdefghijklmnopqrstuvwxyzliveabcdefghijklmnopqrstuvwxyz"),
   618 	_S("l'ke"),
   619 	_S("'Tis")
   620 	};
   621 TSelectTest TypeText::KTests[]=
   622 	{
   623 	{_S("IS NULL"),ROWS(0,1)},
   624 	{_S("IS NOT NULL"),ALL_ROWS-ROW(1)},
   625 //
   626 	{_S("=''"),ROWS(0,1)},					// equivalent to IS NULL
   627 	{_S("<>''"),ALL_ROWS-ROW(1)},			// equivalent to IS NOT NULL
   628 	{_S(">''"),ALL_ROWS-ROW(1)},			// equivalent to IS NOT NULL
   629 	{_S("<''"),NO_ROWS},					// expression is trivially false
   630 	{_S("<=''"),ROWS(0,1)},
   631 	{_S(">=''"),ALL_ROWS+ROW(0)},			// expression is trivially true
   632 //
   633 	{_S("LIKE ''"),ROWS(0,1)},			// synonomous with IS NULL
   634 	{_S("NOT LIKE ''"),ALL_ROWS-ROW(1)},
   635 	{_S("LIKE '?*'"),ALL_ROWS-ROW(1)},	// synonomous with IS NOT NULL
   636 	{_S("NOT LIKE '?*'"),ROWS(0,1)},
   637 	{_S("LIKE '*'"),ALL_ROWS+ROW(0)},	// trivially true
   638 	{_S("NOT LIKE '*'"),NO_ROWS},
   639 //
   640 	{_S("='a'"),ROW(2)},
   641 	{_S("<'ab'"),ROWS(0,3)+ROW(11)},
   642 	{_S("<'abc'"),ROWS(0,4)+ROW(11)},
   643 	{_S("<'b'"),ROWS(0,4)+ROW(6)+ROWS(8,9)+ROW(11)},
   644 	{_S(">'abc'"),ROWS(5,10)},
   645 	{_S("='like'"),ROW(5)},
   646 	{_S("='l''ke'"),ROW(10)},
   647 	{_S("='''Tis'"),ROW(11)},
   648 //
   649 	{_S("LIKE 'a'"),ROW(2)},
   650 	{_S("LIKE 'a*'"),ROWS(2,4)+ROW(6)+ROWS(8,9)},
   651 	{_S("LIKE '*a'"),ROWS(2,4)},
   652 	{_S("LIKE 'a*a'"),ROWS(3,4)},
   653 	{_S("LIKE '*a*'"),ROWS(2,4)+ROWS(6,9)},
   654 //
   655 	{_S("LIKE 'like'"),ROW(5)},
   656 	{_S("LIKE 'l?ke'"),ROW(5)+ROW(10)},
   657 	{_S("LIKE 'like*'"),ROW(5)+ROW(7)},
   658 	{_S("LIKE '*like'"),ROWS(5,6)},
   659 	{_S("LIKE '*like*'"),ROWS(5,8)},
   660 	{_S("LIKE '*likeit*'"),NO_ROWS},
   661 	{_S("LIKE '*li?e*'"),ROWS(5,9)},
   662 	{_S("LIKE '?*li?e*'"),ROW(6)+ROWS(8,9)},
   663 	{_S("LIKE '*li?e*?'"),ROWS(7,9)},
   664 	{_S("LIKE '?*li?e*?'"),ROWS(8,9)},
   665 	{_S("LIKE '*?k?*'"),ROWS(5,10)},
   666 	{_S("LIKE '*?i?e*'"),ROWS(5,9)},
   667 //
   668 	{_S("LIKE '*e*'"),ROWS(5,10)},
   669 	{_S("LIKE '*z*k*e*'"),ROW(6)+ROW(8)},
   670 	{_S("LIKE '\?\?k?'"),ROW(5)+ROW(10)},
   671 	{_S("LIKE '\?\?k*'"),ROW(5)+ROW(7)+ROW(10)},
   672 	{_S("LIKE '*''*'"),ROWS(10,11)},
   673 	{_S("LIKE '?''\?\?'"),ROW(10)},
   674 	{_S("LIKE '?'"),ROW(2)},
   675 	{_S("LIKE '\?\?\?\?'"),ROW(5)+ROWS(10,11)},
   676 	{_S("LIKE '\?\?*\?\?'"),ROWS(5,11)},
   677 	{_S("LIKE '''*'"),ROW(11)}
   678 	};
   679 
   680 TEMPLATE_SPECIALIZATION struct SetCol<const TText* const>
   681 	{
   682 	static void SetColL(TDbColNo aCol,const TAny* aVal)
   683 		{
   684 		TheTable.SetColL(aCol,TPtrC(*(const TText* const*)aVal));
   685 		}
   686 	};
   687 TEMPLATE_SPECIALIZATION struct SetCol<const TText*>
   688 	{
   689 	static void SetColL(TDbColNo aCol,const TAny* aVal)
   690 		{
   691 		TheTable.SetColL(aCol,TPtrC(*(const TText* const*)aVal));
   692 		}
   693 	};
   694 
   695 struct TypeLongText
   696 	{
   697 public:
   698 	static const TText* const KType;
   699 	};
   700 const TText* const TypeLongText::KType=_S("LONG VARCHAR");
   701 
   702 class TestPredicate2 : public TestPredicateBase
   703 	{
   704 public:
   705 	static void RunL();
   706 	};
   707 
   708 // write rows equivalent to TypeText and use its tests
   709 void TestPredicate2::RunL()
   710 	{
   711 	Create(TypeLongText::KType);
   712 	TBuf<1022> fill=_S("abcdefghijklmnopqrstuvqxyz");
   713 	fill.AppendFill('.',fill.MaxLength()-fill.Length());
   714 
   715 	for (TInt row=0;row<=TInt(elementsof(TypeText::KValues));++row)
   716 		{
   717 		TheTable.InsertL();
   718 		TheTable.SetColL(1,row);
   719 		if (row>0)
   720 			{
   721 			RDbColWriteStream blob;
   722 			blob.OpenLC(TheTable,2);
   723 			switch (row)
   724 				{
   725 			case 0:
   726 				break;
   727 			case 1: case 2: case 3: case 4: case 5: case 10: case 11:
   728 				blob.WriteL(TPtrC(TypeText::KValues[row-1]));
   729 				break;
   730 			case 6:
   731 				blob.WriteL(fill);
   732 				blob.WriteL(_L("like"));
   733 				break;
   734 			case 7:
   735 				blob.WriteL(_L("like"));
   736 				blob.WriteL(fill);
   737 				break;
   738 			case 8:
   739 				blob.WriteL(fill);
   740 				blob.WriteL(_L("like"));
   741 				blob.WriteL(fill);
   742 				break;
   743 			case 9:
   744 				blob.WriteL(fill);
   745 				blob.WriteL(_L("live"));
   746 				blob.WriteL(fill);
   747 				break;
   748 				}
   749 			blob.CommitL();
   750 			CleanupStack::PopAndDestroy();
   751 			}
   752 		TheTable.PutL();
   753 		}
   754 	TheTable.Close();
   755 	TInt r=TheDatabase.Commit();
   756 	TEST2(r, KErrNone);
   757 	TestViewL(TypeText::KTests,elementsof(TypeText::KTests),elementsof(TypeText::KValues));
   758 	CDbKey& key=*CDbKey::NewLC();
   759 	key.AddL(TDbKeyCol(_L("Test"),120));
   760 	r=TheDatabase.CreateIndex(_L("Key"),_L("Compare"),key);
   761 	TEST2(r, KErrNone);
   762 	CleanupStack::PopAndDestroy();
   763 	TestViewL(TypeText::KTests,elementsof(TypeText::KTests),elementsof(TypeText::KValues));
   764 	r=TheDatabase.Execute(_L("DROP TABLE Compare"));
   765 	TEST2(r, KErrNone);
   766 	}
   767 
   768 /**
   769 * Utility for DEF063276 fix.
   770 */
   771 
   772 #ifndef __TOOLS2__
   773 _LIT(KTypeTextKTests44, "Z:\\test\\data\\typetextktests44.dat");
   774 _LIT(KTypeTextKTests46, "Z:\\test\\data\\typetextktests46.dat");
   775 _LIT(KTypeTextKTests47, "Z:\\test\\data\\typetextktests47.dat");
   776 #else
   777 _LIT(KTypeTextKTests44, ".\\dbms-tst\\typetextktests44.dat");
   778 _LIT(KTypeTextKTests46, ".\\dbms-tst\\typetextktests46.dat");
   779 _LIT(KTypeTextKTests47, ".\\dbms-tst\\typetextktests47.dat");
   780 #endif
   781 
   782 static void ReadDesc(TDes& aDes, const TDesC& aFilename, RFs& aFs)
   783 	{
   784 	RFile file;
   785 	TInt err = file.Open(aFs, aFilename, EFileRead);
   786 	TheTest(err == KErrNone);
   787 	CleanupClosePushL(file);
   788 	
   789 	TPtr8 ptr(reinterpret_cast<TUint8*>(const_cast<TUint16*>(aDes.Ptr())), aDes.MaxSize());
   790 	err = file.Read(ptr);
   791 	TheTest(err == KErrNone);
   792 	aDes.SetLength(ptr.Length() / sizeof(TText));
   793 	CleanupStack::PopAndDestroy(&file);
   794 	}
   795 
   796 /**
   797 @SYMTestCaseID          SYSLIB-DBMS-CT-0633
   798 @SYMTestCaseDesc        Tests the Predicate operators for all types
   799 @SYMTestPriority        Medium
   800 @SYMTestActions         Attempt to check with different types
   801 @SYMTestExpectedResults Test must not fail
   802 @SYMREQ                 REQ0000
   803 */
   804 LOCAL_C void TestPredicatesL()
   805 	{
   806 	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0633 init "));
   807 	CreateDatabase();
   808 	TestPredicate<TypeBit>::Run();
   809 	TestPredicate<TypeUint8>::Run();
   810 	TestPredicate<TypeUint16>::Run();
   811 	TestPredicate<TypeUint32>::Run();
   812 	TestPredicate<TypeInt8>::Run();
   813 	TestPredicate<TypeInt16>::Run();
   814 	TestPredicate<TypeInt32>::Run();
   815 	TestPredicate<TypeInt64>::Run();
   816 	TestPredicate<TypeReal32>::Run();
   817 	TestPredicate<TypeReal64>::Run();
   818 	TestPredicate<TypeTime>::Run();
   819 
   820 	/**
   821 	* Work around for DEF063276.
   822 	* These literals are now loaded from Z:\test\data\TypeTextKTests44.dat, 
   823 	* Z:\test\data\TypeTextKTests44.dat and Z:\test\data\TypeTextKTests44.dat respectively.
   824 	* Bullseye Coverage corrupts these literals to avoid this they are stored in files as to not be touched by Bullseye Coverage.
   825 	*/	
   826 	
   827 	TBuf<16> buf44;
   828 	ReadDesc(buf44, KTypeTextKTests44, TheFs);	
   829 	TypeText::KTests[44].iSearchCondition = const_cast<TText*>(buf44.PtrZ());
   830 	
   831 	TBuf<32> buf46(TypeText::KTests[46].iSearchCondition);
   832 	ReadDesc(buf46, KTypeTextKTests46, TheFs);	
   833 	TypeText::KTests[46].iSearchCondition = const_cast<TText*>(buf46.PtrZ());
   834 	
   835 	TBuf<32> buf47(TypeText::KTests[47].iSearchCondition);
   836 	ReadDesc(buf47, KTypeTextKTests47, TheFs);	
   837 	TypeText::KTests[47].iSearchCondition = const_cast<TText*>(buf47.PtrZ());
   838 	
   839 	// End fix.
   840 	
   841 	TestPredicate<TypeText>::Run();
   842 	TestPredicate2::RunL();
   843 	CloseDatabase();
   844 	TheTest.End();
   845 	}
   846 
   847 /**
   848 @SYMTestCaseID          SYSLIB-DBMS-CT-0634
   849 @SYMTestCaseDesc        DML Query test
   850                         Test for RDbNamedDatabase::Execute() function
   851 @SYMTestPriority        Medium
   852 @SYMTestActions         Tests for CREATE TABLE,CREATE UNIQUE INDEX,INSET INTO,UPDATE,DELETE,DROP queries
   853 @SYMTestExpectedResults Test must not fail
   854 @SYMREQ                 REQ0000
   855 */
   856 LOCAL_C void TestDML()
   857 	{
   858 	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0634 init "));
   859 	Connect();
   860 	ShareDatabase();
   861 	TInt r=TheDatabase.Execute(_L("CREATE TABLE test (ID INTEGER NOT NULL,SALARY DOUBLE)"));
   862 	TEST2(r, KErrNone);
   863 	r=TheDatabase.Execute(_L("CREATE UNIQUE INDEX key ON test (ID)"));
   864 	TEST2(r, KErrNone);
   865 	
   866 	TheTest.Next(_L("insert-statements"));
   867 	r=TheDatabase.Execute(_L("INSERT INTO test VALUES (0,0)"));
   868 	TEST(r==1);
   869 	r=TheDatabase.Execute(_L("INSERT INTO test (ID) VALUES (1)"));
   870 	TEST(r==1);
   871 	r=TheDatabase.Execute(_L("INSERT INTO test (SALARY,ID) VALUES (20.4,2)"));
   872 	TEST(r==1);
   873 	
   874 	TheTest.Next(_L("update-statements"));
   875 	r=TheDatabase.Execute(_L("UPDATE test SET SALARY=30000 WHERE ID=1"));
   876 	TEST(r==1);
   877 	
   878 	TheTest.Next(_L("delete-statements"));
   879 	r=TheDatabase.Execute(_L("DELETE FROM test WHERE SALARY<40"));
   880 	TEST(r==2);
   881 	r=TheDatabase.Execute(_L("DELETE FROM test"));
   882 	TEST(r==1);
   883 	r=TheDatabase.Execute(_L("DROP TABLE test"));
   884 	TEST2(r, KErrNone);
   885 //
   886 	TheTest.Next(_L("larger table"));
   887 	r=TheDatabase.Execute(_L("CREATE TABLE test (ID COUNTER,DATA INTEGER)"));
   888 	TEST2(r, KErrNone);
   889 	
   890 	TheTest.Next(_L("insert"));
   891 	TheDatabase.Begin();
   892 	TBuf<256> sql;
   893 	for (TInt ii=0;ii<100;++ii)
   894 		{
   895 		sql.Format(_L("INSERT INTO test (DATA) VALUES (%D)"),100-ii);
   896 		r=TheDatabase.Execute(sql);
   897 		TEST(r==1);
   898 		}
   899 	r=TheDatabase.Commit();
   900 	TEST2(r, KErrNone);
   901 	
   902 	TheTest.Next(_L("update"));
   903 	r=TheDatabase.Execute(_L("UPDATE test SET DATA=200 WHERE ID>=40 AND ID<60"));
   904 	TEST(r==20);
   905 	
   906 	TheTest.Next(_L("delete"));
   907 	r=TheDatabase.Execute(_L("DELETE FROM test WHERE DATA>90"));
   908 	TEST(r==30);
   909 	
   910 	TheTest.Next(_L("update"));
   911 	r=TheDatabase.Execute(_L("UPDATE test SET DATA=-1"));
   912 	TEST(r==70);
   913 	
   914 	TheTest.Next(_L("delete"));
   915 	r=TheDatabase.Execute(_L("DELETE FROM test"));
   916 	TEST(r==70);
   917 	r=TheDatabase.Execute(_L("DROP TABLE test"));
   918 	TEST2(r, KErrNone);
   919 	CloseDatabase();
   920 	Disconnect();
   921 	TheTest.End();
   922 	}
   923 
   924 /**
   925 @SYMTestCaseID          SYSLIB-DBMS-CT-0635
   926 @SYMTestCaseDesc        DBMS SQL parsing and execution tests.Tests for database index order
   927 						Test for RDbNamedDatabase::Execute() function
   928 @SYMTestPriority        Medium
   929 @SYMTestActions         Tests for order by index
   930 @SYMTestExpectedResults Test must not fail
   931 @SYMREQ                 REQ0000
   932 */
   933 LOCAL_C void TestOrderByL()
   934 	{
   935 	static const TReal TestDataSalary[]={10,34000,15000,53200,17800,240000};
   936 	static const TText* const TestDataNames[]={_S("gopher"),_S("james '007' bond"),_S("moneypenny"),_S("Q"),_S("james '007' bond"),_S("M")};
   937 //
   938 	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0635 init "));
   939 	Connect();
   940 	ShareDatabase();
   941 	TheDatabase.Begin();
   942 	TInt r=TheDatabase.Execute(_L("CREATE TABLE test (ID INTEGER NOT NULL,SALARY DOUBLE,NAME VARCHAR)"));
   943 	TEST2(r, KErrNone);
   944 	r=TheDatabase.Execute(_L("CREATE UNIQUE INDEX key ON test (ID)"));
   945 	TEST2(r, KErrNone);
   946 	
   947 	TheTest.Next(_L("insert data"));
   948 	r=TheView.Prepare(TheDatabase,_L("SELECT ID,SALARY,NAME FROM test"),TheView.EInsertOnly);
   949 	TEST2(r, KErrNone);
   950 	TInt ii;
   951 	for (ii=0;ii<6;++ii)
   952 		{
   953 		TheView.InsertL();
   954 		TheView.SetColL(1,6-ii);
   955 		TheView.SetColL(2,TestDataSalary[ii]);
   956 		TheView.SetColL(3,TPtrC(TestDataNames[ii]));
   957 		TheView.PutL();
   958 		}
   959 	r=TheDatabase.Commit();
   960 	TEST2(r, KErrNone);
   961 	TheView.Close();
   962 	
   963 	TheTest.Next(_L("Order by <index>"));
   964 	// test the index is used here
   965 	r=TheView.Prepare(TheDatabase,_L("SELECT ID FROM test ORDER BY ID"));
   966 	TEST2(r, KErrNone);
   967 	TEST(!TheView.Unevaluated());
   968 	TInt c=0;
   969 	if (TheView.FirstL())
   970 		{
   971 		++c;
   972 		TheView.GetL();
   973 		TInt last=TheView.ColInt(1);
   974 		while (TheView.NextL())
   975 			{
   976 			++c;
   977 			TheView.GetL();
   978 			TInt v=TheView.ColInt(1);
   979 			TEST(v>last);
   980 			last=v;
   981 			}
   982 		}
   983 	TEST(c==6);
   984 	TEST(c==TheView.CountL());
   985 	TheView.Close();
   986 	
   987 	TheTest.Next(_L("Order by <no-index> 1"));
   988 	// test that no index is used here
   989 	r=TheView.Prepare(TheDatabase,_L("SELECT SALARY FROM test ORDER BY SALARY"));
   990 	TEST2(r, KErrNone);
   991 	TEST(TheView.Unevaluated());
   992 	r=TheView.EvaluateAll();
   993 	TEST2(r, KErrNone);
   994 	c=0;
   995 	if (TheView.FirstL())
   996 		{
   997 		++c;
   998 		TheView.GetL();
   999 		TReal last=TheView.ColReal(1);
  1000 		while (TheView.NextL())
  1001 			{
  1002 			++c;
  1003 			TheView.GetL();
  1004 			TReal v=TheView.ColReal(1);
  1005 			TEST(v>=last);
  1006 			last=v;
  1007 			}
  1008 		}
  1009 	TEST(c==6);
  1010 	TEST(c==TheView.CountL());
  1011 	TheView.Close();
  1012 	
  1013 	TheTest.Next(_L("Order by <no-index> 2"));
  1014 	// test that no index is used here
  1015 	r=TheView.Prepare(TheDatabase,_L("SELECT SALARY FROM test ORDER BY SALARY,NAME"));
  1016 	TEST2(r, KErrNone);
  1017 	TEST(TheView.Unevaluated());
  1018 	r=TheView.EvaluateAll();
  1019 	TEST2(r, KErrNone);
  1020 	c=0;
  1021 	if (TheView.FirstL())
  1022 		{
  1023 		++c;
  1024 		TheView.GetL();
  1025 		TReal last=TheView.ColReal(1);
  1026 		while (TheView.NextL())
  1027 			{
  1028 			++c;
  1029 			TheView.GetL();
  1030 			TReal v=TheView.ColReal(1);
  1031 			TEST(v>=last);
  1032 			last=v;
  1033 			}
  1034 		}
  1035 	TEST(c==6);
  1036 	TEST(c==TheView.CountL());
  1037 	TheView.Close();
  1038 	
  1039 	TheTest.Next(_L("Order by <no-index> 3"));
  1040 	// test that no index is used here
  1041 	r=TheView.Prepare(TheDatabase,_L("SELECT NAME FROM test ORDER BY NAME"));
  1042 	TEST2(r, KErrNone);
  1043 	TEST(TheView.Unevaluated());
  1044 	r=TheView.EvaluateAll();
  1045 	TEST2(r, KErrNone);
  1046 	c=0;
  1047 	if (TheView.FirstL())
  1048 		{
  1049 		++c;
  1050 		TheView.GetL();
  1051 		TBuf<50> last=TheView.ColDes(1);
  1052 		while (TheView.NextL())
  1053 			{
  1054 			++c;
  1055 			TheView.GetL();
  1056 			TPtrC v=TheView.ColDes(1);
  1057 			TEST(v>=last);
  1058 			last=v;
  1059 			}
  1060 		}
  1061 	TEST(c==6);
  1062 	TEST(c==TheView.CountL());
  1063 	TheView.Close();
  1064 	
  1065 	TheTest.Next(_L("Order by <no-index> 4"));
  1066 	// test that no index is used here
  1067 	r=TheView.Prepare(TheDatabase,_L("SELECT NAME FROM test ORDER BY NAME,SALARY"));
  1068 	TEST2(r, KErrNone);
  1069 	TEST(TheView.Unevaluated());
  1070 	r=TheView.EvaluateAll();
  1071 	TEST2(r, KErrNone);
  1072 	c=0;
  1073 	if (TheView.FirstL())
  1074 		{
  1075 		++c;
  1076 		TheView.GetL();
  1077 		TBuf<50> last=TheView.ColDes(1);
  1078 		while (TheView.NextL())
  1079 			{
  1080 			++c;
  1081 			TheView.GetL();
  1082 			TPtrC v=TheView.ColDes(1);
  1083 			TEST(v>=last);
  1084 			last=v;
  1085 			}
  1086 		}
  1087 	TEST(c==6);
  1088 	TEST(c==TheView.CountL());
  1089 	TheView.Close();
  1090 	
  1091 	TheTest.Next(_L("Order by + search <no-index>"));
  1092 	// test that no index is used here
  1093 	r=TheView.Prepare(TheDatabase,_L("SELECT ID,SALARY FROM test WHERE SALARY>30000 ORDER BY SALARY DESC"));
  1094 	TEST2(r, KErrNone);
  1095 	TEST(TheView.Unevaluated());
  1096 	r=TheView.EvaluateAll();
  1097 	TEST2(r, KErrNone);
  1098 	c=0;
  1099 	if (TheView.FirstL())
  1100 		{
  1101 		++c;
  1102 		TheView.GetL();
  1103 		TReal last=TheView.ColReal(2);
  1104 		while (TheView.NextL())
  1105 			{
  1106 			++c;
  1107 			TheView.GetL();
  1108 			TReal v=TheView.ColReal(2);
  1109 			TEST(v<=last);
  1110 			last=v;
  1111 			}
  1112 		}
  1113 	TEST(c==3);
  1114 	TEST(c==TheView.CountL());
  1115 	TheView.Close();
  1116 //
  1117 	CloseDatabase();
  1118 	Disconnect();
  1119 	
  1120 	TheTest.Next(_L("Order by <index> Finished"));
  1121 	TheTest.End();
  1122 	}
  1123 
  1124 LOCAL_C void doMain()
  1125 	{
  1126 	TheTest.Start(_L("Predicate tests"));
  1127 	TRAPD(errCode, TestPredicatesL());
  1128 	TEST2(errCode, KErrNone);
  1129 	
  1130 	TheTest.Next(_L("DML execution"));
  1131 	TestDML();
  1132 	
  1133 	TheTest.Next(_L("ORDER BY clause"));
  1134 	TRAP(errCode, TestOrderByL());
  1135 	TEST2(errCode, KErrNone);
  1136 	TheTest.End();
  1137 	}
  1138 
  1139 // Prepare the test directory.
  1140 LOCAL_C void setupTestDirectory()
  1141     {
  1142 	TInt r=TheFs.Connect();
  1143 	TEST2(r, KErrNone);
  1144 //
  1145 	r=TheFs.MkDir(KTestDatabase);
  1146 	TEST(r==KErrNone || r==KErrAlreadyExists);
  1147 	}
  1148 
  1149 // Initialise the cleanup stack.
  1150 LOCAL_C void setupCleanup()
  1151     {
  1152 	TheTrapCleanup=CTrapCleanup::New();
  1153 	TEST(TheTrapCleanup!=NULL);
  1154 	TRAPD(r,\
  1155 		{\
  1156 		for (TInt i=KTestCleanupStack;i>0;i--)\
  1157 			CleanupStack::PushL((TAny*)0);\
  1158 		CleanupStack::Pop(KTestCleanupStack);\
  1159 		});
  1160 	TEST2(r, KErrNone);
  1161 	}
  1162 
  1163 // Test streaming conversions.
  1164 GLDEF_C TInt E32Main()
  1165     {
  1166 	TheTest.Title();
  1167 	setupTestDirectory();
  1168 	setupCleanup();
  1169 	__UHEAP_MARK;
  1170 //
  1171 	TheTest.Start(_L("Standard database"));
  1172 	doMain();
  1173 
  1174 	TheTest.Printf(_L("Waiting for server exit\n"));
  1175 	const TUint KExitDelay=6*0x100000;	// ~6 seconds
  1176 	User::After(KExitDelay);
  1177 
  1178 	// clean up data file used by this test - must be done before call to End() - DEF047652
  1179 	::TestCleanup();
  1180 	
  1181 #ifndef __linux__
  1182 	TInt err;
  1183 #ifndef __TOOLS2__
  1184 	TRAPD(lc, err = TheCrcChecker.DumpCrcRecordsL(KCrcRecord));
  1185 	TheTest(err==KErrNone);
  1186 	TheTest(lc==KErrNone);
  1187 #else
  1188 	TRAPD(lc, err = TheCrcChecker.ValidateCrcRecordsL(KCrcRecord));
  1189 	TPtrC errmsg;
  1190 	TheCrcChecker.ErrorReportL(err, errmsg);
  1191 	RDebug::Print(errmsg);
  1192 	TheTest(err==KErrNone || err==TDBMS_CRCChecks::ECrcCheckOk);
  1193 #endif
  1194 #endif
  1195 	
  1196 	TheTest.End();
  1197 //
  1198 	__UHEAP_MARKEND;
  1199 
  1200 
  1201 	delete TheTrapCleanup;
  1202 	TheTest.Close();
  1203 	return 0;
  1204     }