1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/dbms/pcdbms/tdbms/src/t_sql.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,1204 @@
1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +// MSVC++ up to 5.0 has problems with expanding inline functions
1.20 +// This disables the mad warnings for the whole project
1.21 +#if defined(NDEBUG) && defined(__VC32__) && _MSC_VER<=1100
1.22 +#pragma warning(disable : 4710) // function not expanded. MSVC 5.0 is stupid
1.23 +#endif
1.24 +
1.25 +#include <d32dbms.h>
1.26 +#include <f32file.h>
1.27 +#include <e32test.h>
1.28 +#include <e32math.h>
1.29 +
1.30 +#include "crccheck.h"
1.31 +
1.32 +#undef __UHEAP_MARK
1.33 +#define __UHEAP_MARK
1.34 +#undef __UHEAP_MARKEND
1.35 +#define __UHEAP_MARKEND
1.36 +
1.37 +LOCAL_D TDBMS_CRCChecks TheCrcChecker;
1.38 +
1.39 +#ifndef __linux__ //No CRC test on LINUX
1.40 +#ifdef __TOOLS2__
1.41 +const TPtrC KCrcRecord=_L("\\epoc32\\winscw\\c\\dbms-tst\\T_SQL.CRC");
1.42 +#else
1.43 +const TPtrC KCrcRecord=_L("C:\\dbms-tst\\T_SQL.CRC");
1.44 +#endif
1.45 +#endif
1.46 +
1.47 +// constructing literal TInt64 from compiler 64 bit integer rep
1.48 +
1.49 +#ifndef I64LIT
1.50 +#if defined __GCC32__ || defined __EABI__
1.51 +#define _LINT64(val) MAKE_TINT64(TUint(val##LL>>32),TUint(val##LL&0xffffffffu))
1.52 +#else
1.53 +#define _LINT64(val) MAKE_TINT64(TUint(__int64(val)>>32),TUint(__int64(val)&0xffffffffu))
1.54 +#endif
1.55 +#else // I64LIT
1.56 +#define _LINT64 I64LIT
1.57 +#endif // I64LIT
1.58 +
1.59 +LOCAL_D RTest TheTest(_L("T_SQL: DBMS SQL parsing and execution tests"));
1.60 +
1.61 +LOCAL_D RFs TheFs;
1.62 +LOCAL_D CTrapCleanup* TheTrapCleanup;
1.63 +LOCAL_D RDbs TheDbs;
1.64 +LOCAL_D RDbNamedDatabase TheDatabase;
1.65 +LOCAL_D RDbTable TheTable;
1.66 +LOCAL_D RDbView TheView;
1.67 +LOCAL_D TBuf<1024> TheSql;
1.68 +
1.69 +const TInt KTestCleanupStack=0x20;
1.70 +
1.71 +#ifdef __TOOLS2__
1.72 +const TPtrC KTestDatabase=_L(".\\dbms-tst\\T_SQL.DB");
1.73 +#else
1.74 +const TPtrC KTestDatabase=_L("C:\\dbms-tst\\T_SQL.DB");
1.75 +#endif
1.76 +
1.77 +#define elementsof(array) (sizeof(array)/sizeof(array[0]))
1.78 +
1.79 +LOCAL_C void TestCleanup()
1.80 + {
1.81 + TheTable.Close();
1.82 + TheView.Close();
1.83 + TheDatabase.Close();
1.84 +#ifndef __TOOLS2__
1.85 + TheDbs.Close();
1.86 +#endif
1.87 +
1.88 + TRAPD(errCode, TheCrcChecker.GenerateCrcL(KTestDatabase));
1.89 +
1.90 + TheFs.Close();
1.91 + /////////////
1.92 + RFs fsSession;
1.93 + TInt err = fsSession.Connect();
1.94 + if(err == KErrNone)
1.95 + {
1.96 + TEntry entry;
1.97 + if(fsSession.Entry(KTestDatabase, entry) == KErrNone)
1.98 + {
1.99 + RDebug::Print(_L("Deleting \"%S\" file.\n"), &KTestDatabase);
1.100 + err = fsSession.SetAtt(KTestDatabase, 0, KEntryAttReadOnly);
1.101 + if(err != KErrNone)
1.102 + {
1.103 + RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &KTestDatabase);
1.104 + }
1.105 + err = fsSession.Delete(KTestDatabase);
1.106 + if(err != KErrNone)
1.107 + {
1.108 + RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &KTestDatabase);
1.109 + }
1.110 + }
1.111 + fsSession.Close();
1.112 + }
1.113 + else
1.114 + {
1.115 + RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &KTestDatabase);
1.116 + }
1.117 + }
1.118 +
1.119 +LOCAL_C void CloseDatabase()
1.120 + {
1.121 + TheDatabase.Close();
1.122 + TRAPD(errCode, TheCrcChecker.GenerateCrcL(KTestDatabase));
1.123 +
1.124 + }
1.125 +
1.126 +LOCAL_C void Disconnect()
1.127 + {
1.128 +#ifndef __TOOLS2__
1.129 + TheDbs.ResourceCheck();
1.130 + TheDbs.Close();
1.131 +#endif
1.132 + }
1.133 +
1.134 +///////////////////////////////////////////////////////////////////////////////////////
1.135 +///////////////////////////////////////////////////////////////////////////////////////
1.136 +//Tests macros and functions.
1.137 +//If (!aValue) then the test will be panicked, the test data files will be deleted.
1.138 +static void Check(TInt aValue, TInt aLine)
1.139 + {
1.140 + if(!aValue)
1.141 + {
1.142 + ::TestCleanup();
1.143 + TheTest(EFalse, aLine);
1.144 + }
1.145 + }
1.146 +//If (aValue != aExpected) then the test will be panicked, the test data files will be deleted.
1.147 +static void Check(TInt aValue, TInt aExpected, TInt aLine)
1.148 + {
1.149 + if(aValue != aExpected)
1.150 + {
1.151 + RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
1.152 + ::TestCleanup();
1.153 + TheTest(EFalse, aLine);
1.154 + }
1.155 + }
1.156 +//Use these to test conditions.
1.157 +#define TEST(arg) ::Check((arg), __LINE__)
1.158 +#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
1.159 +
1.160 +///////////////////////////////////////////////////////////////////////////////////////
1.161 +///////////////////////////////////////////////////////////////////////////////////////
1.162 +
1.163 +// Create the database
1.164 +LOCAL_C void CreateDatabase()
1.165 + {
1.166 + TInt r=TheDatabase.Replace(TheFs,KTestDatabase);
1.167 + TEST2(r, KErrNone);
1.168 + }
1.169 +
1.170 +LOCAL_C void Connect()
1.171 + {
1.172 +#ifndef __TOOLS2__
1.173 + TInt r=TheDbs.Connect();
1.174 + TEST2(r, KErrNone);
1.175 + TheDbs.ResourceMark();
1.176 +#endif
1.177 + }
1.178 +
1.179 +// Open the database through the server
1.180 +LOCAL_C void ShareDatabase()
1.181 + {
1.182 + TInt r=TheDatabase.Open(TheDbs,KTestDatabase);
1.183 + TEST2(r, KErrNone);
1.184 + }
1.185 +
1.186 +struct TSelectTest
1.187 + {
1.188 + const TText* iSearchCondition;
1.189 + TUint iResultSet;
1.190 + };
1.191 +#define ROWS(n,m) (((~0u)<<(n))&((2u<<(m))-1))
1.192 +#define ROW(n) ROWS(n,n)
1.193 +#define NO_ROWS 0
1.194 +#define ALL_ROWS (~1u) // all rows which are not NULL
1.195 +
1.196 +class TestPredicateBase
1.197 + {
1.198 +protected:
1.199 + static void Create(const TText* aType);
1.200 + static void Test(const TSelectTest* aTest,TInt aCount,TInt aRows);
1.201 + static void TestViewL(const TSelectTest* aTest,TInt aCount,TInt aRows);
1.202 + };
1.203 +
1.204 +// Create the table for the predicate tests
1.205 +void TestPredicateBase::Create(const TText* aType)
1.206 + {
1.207 + TheTest.Next(TPtrC(aType));
1.208 + TheDatabase.Begin();
1.209 + TheSql.Format(_L("CREATE TABLE Compare (Id COUNTER,Test %s)"),aType);
1.210 + TInt r=TheDatabase.Execute(TheSql);
1.211 + TEST2(r, KErrNone);
1.212 + r=TheTable.Open(TheDatabase,_L("Compare"),TheTable.EInsertOnly);
1.213 + TEST2(r, KErrNone);
1.214 + }
1.215 +
1.216 +// Test the predicate on the table, then on the indexed table
1.217 +void TestPredicateBase::Test(const TSelectTest* aTest,TInt aCount,TInt aRows)
1.218 + {
1.219 + TheTable.Close();
1.220 + TInt r=TheDatabase.Commit();
1.221 + TEST2(r, KErrNone);
1.222 + TRAPD(errCode, TestViewL(aTest,aCount,aRows));
1.223 + TEST2(errCode, KErrNone);
1.224 + r=TheDatabase.Execute(_L("CREATE INDEX Key ON Compare (Test)"));
1.225 + TEST2(r, KErrNone);
1.226 + TRAP(errCode,TestViewL(aTest,aCount,aRows));
1.227 + TEST2(errCode, KErrNone);
1.228 + r=TheDatabase.Execute(_L("DROP TABLE Compare"));
1.229 + TEST2(r, KErrNone);
1.230 + }
1.231 +
1.232 +// Test the predicate on the table
1.233 +void TestPredicateBase::TestViewL(const TSelectTest* aTest,TInt aCount,TInt aRows)
1.234 + {
1.235 + TUint rowMask=(2u<<aRows)-1;
1.236 + for (;--aCount>=0;++aTest)
1.237 + {
1.238 + TheSql.Format(_L("SELECT Id FROM Compare WHERE Test %s"),aTest->iSearchCondition);
1.239 + TInt r=TheView.Prepare(TheDatabase,TheSql,TheView.EReadOnly);
1.240 + TBool ignoreRow0=TheView.Unevaluated();
1.241 + TEST2(r, KErrNone);
1.242 + r=TheView.EvaluateAll();
1.243 + TEST2(r, KErrNone);
1.244 + TUint rows=0;
1.245 + while (TheView.NextL())
1.246 + {
1.247 + TheView.GetL();
1.248 + rows|=1u<<TheView.ColUint(1);
1.249 + }
1.250 + if (ignoreRow0)
1.251 + TEST((rows&~ROW(0))==(aTest->iResultSet&rowMask&~ROW(0)));
1.252 + else
1.253 + TEST(rows==(aTest->iResultSet&rowMask));
1.254 + TheView.Close();
1.255 + }
1.256 + }
1.257 +
1.258 +typedef void (*FSetColL)(TDbColNo aCol,const TAny* aVal);
1.259 +
1.260 +void WriteRows(const TAny* aValues,TInt aRows,TInt aSize,FSetColL aSetColL)
1.261 + {
1.262 + for (TInt row=0;row<=aRows;++row)
1.263 + {
1.264 + TheTable.InsertL();
1.265 + TEST(TheTable.ColUint(1)==TUint(row));
1.266 + if (row>0)
1.267 + { // first row is always null
1.268 + aSetColL(2,aValues);
1.269 + aValues=PtrAdd(aValues,aSize);
1.270 + }
1.271 + TheTable.PutL();
1.272 + }
1.273 + }
1.274 +
1.275 +template <class T>
1.276 +struct SetCol
1.277 + {
1.278 + static void SetColL(TDbColNo aCol,const TAny* aVal)
1.279 + {
1.280 + TheTable.SetColL(aCol,*(const T*)aVal);
1.281 + }
1.282 + };
1.283 +
1.284 +template <class T>
1.285 +inline void WriteRows(const T* aValues,TUint aRows)
1.286 + {
1.287 + WriteRows(aValues,aRows,sizeof(T),&SetCol<T>::SetColL);
1.288 + }
1.289 +
1.290 +template <class T>
1.291 +class TestPredicate : public TestPredicateBase
1.292 + {
1.293 +public:
1.294 + static void Run();
1.295 + };
1.296 +
1.297 +// Test the Predicate operators for all types
1.298 +template <class T>
1.299 +void TestPredicate<T>::Run()
1.300 + {
1.301 + Create(T::KType);
1.302 + WriteRows(T::KValues,elementsof(T::KValues));
1.303 + Test(T::KTests,elementsof(T::KTests),elementsof(T::KValues));
1.304 + }
1.305 +
1.306 +struct TypeBit
1.307 + {
1.308 +public:
1.309 + static const TText* const KType;
1.310 + static const TUint KValues[];
1.311 + static const TSelectTest KTests[];
1.312 + };
1.313 +const TText* const TypeBit::KType=_S("BIT");
1.314 +const TUint TypeBit::KValues[]={0,1};
1.315 +const TSelectTest TypeBit::KTests[]=
1.316 + {
1.317 + {_S("IS NULL"),ROW(0)},
1.318 + {_S("IS NOT NULL"),ALL_ROWS},
1.319 + {_S("=0"),ROW(1)},
1.320 + {_S("<>0"),ROW(2)},
1.321 + {_S(">0"),ROW(2)},
1.322 + {_S("<0"),NO_ROWS},
1.323 + {_S("<=0"),ROW(1)},
1.324 + {_S(">=0"),ALL_ROWS},
1.325 + {_S("=1"),ROW(2)},
1.326 + {_S("<>1"),ROW(1)},
1.327 + {_S(">1"),NO_ROWS},
1.328 + {_S("<1"),ROW(1)},
1.329 + {_S("<=1"),ALL_ROWS},
1.330 + {_S(">=1"),ROW(2)}
1.331 + };
1.332 +
1.333 +struct TypeUint8
1.334 + {
1.335 +public:
1.336 + static const TText* const KType;
1.337 + static const TUint KValues[];
1.338 + static const TSelectTest KTests[];
1.339 + };
1.340 +const TText* const TypeUint8::KType=_S("UNSIGNED TINYINT");
1.341 +const TUint TypeUint8::KValues[]={0,1,127,128,254,255};
1.342 +const TSelectTest TypeUint8::KTests[]=
1.343 + {
1.344 + {_S("IS NULL"),ROW(0)},
1.345 + {_S("IS NOT NULL"),ALL_ROWS},
1.346 + {_S("=0"),ROW(1)},
1.347 + {_S("=3"),NO_ROWS},
1.348 + {_S("<2"),ROWS(1,2)},
1.349 + {_S(">=0"),ALL_ROWS},
1.350 + {_S("<128"),ROWS(1,3)},
1.351 + {_S("<>1"),ALL_ROWS-ROW(2)},
1.352 + {_S(">255"),NO_ROWS}
1.353 + };
1.354 +
1.355 +struct TypeUint16
1.356 + {
1.357 +public:
1.358 + static const TText* const KType;
1.359 + static const TUint KValues[];
1.360 + static const TSelectTest KTests[];
1.361 + };
1.362 +const TText* const TypeUint16::KType=_S("UNSIGNED SMALLINT");
1.363 +const TUint TypeUint16::KValues[]={0,1,5000,32767,32768,65534,65535};
1.364 +const TSelectTest TypeUint16::KTests[]=
1.365 + {
1.366 + {_S("IS NULL"),ROW(0)},
1.367 + {_S("IS NOT NULL"),ALL_ROWS},
1.368 + {_S("=0"),ROW(1)},
1.369 + {_S("=3"),NO_ROWS},
1.370 + {_S("<2"),ROWS(1,2)},
1.371 + {_S(">=32768"),ROWS(5,7)},
1.372 + {_S("<32767"),ROWS(1,3)},
1.373 + {_S("<>1"),ALL_ROWS-ROW(2)},
1.374 + {_S(">65535"),NO_ROWS}
1.375 + };
1.376 +
1.377 +struct TypeUint32
1.378 + {
1.379 +public:
1.380 + static const TText* const KType;
1.381 + static const TUint KValues[];
1.382 + static const TSelectTest KTests[];
1.383 + };
1.384 +const TText* const TypeUint32::KType=_S("UNSIGNED INTEGER");
1.385 +const TUint TypeUint32::KValues[]={0,1,2147483647u,2147483648u,3000000000u,4294967294u,4294967295u};
1.386 +const TSelectTest TypeUint32::KTests[]=
1.387 + {
1.388 + {_S("IS NULL"),ROW(0)},
1.389 + {_S("IS NOT NULL"),ALL_ROWS},
1.390 + {_S("=0"),ROW(1)},
1.391 + {_S("=3"),NO_ROWS},
1.392 + {_S("<2"),ROWS(1,2)},
1.393 + {_S(">=2147483648"),ROWS(4,7)},
1.394 + {_S("<2147483647"),ROWS(1,2)},
1.395 + {_S("<>3000000000"),ALL_ROWS-ROW(5)},
1.396 + {_S(">4294967295"),NO_ROWS}
1.397 + };
1.398 +
1.399 +struct TypeInt8
1.400 + {
1.401 +public:
1.402 + static const TText* const KType;
1.403 + static const TInt KValues[];
1.404 + static const TSelectTest KTests[];
1.405 + };
1.406 +const TText* const TypeInt8::KType=_S("TINYINT");
1.407 +const TInt TypeInt8::KValues[]={-128,-1,0,1,127};
1.408 +const TSelectTest TypeInt8::KTests[]=
1.409 + {
1.410 + {_S("IS NULL"),ROW(0)},
1.411 + {_S("IS NOT NULL"),ALL_ROWS},
1.412 + {_S("=0"),ROW(3)},
1.413 + {_S("=-1"),ROW(2)},
1.414 + {_S("<2"),ROWS(1,4)},
1.415 + {_S(">=-128"),ALL_ROWS},
1.416 + {_S("<128"),ALL_ROWS},
1.417 + {_S("<>1"),ALL_ROWS-ROW(4)}
1.418 + };
1.419 +
1.420 +struct TypeInt16
1.421 + {
1.422 +public:
1.423 + static const TText* const KType;
1.424 + static const TInt KValues[];
1.425 + static const TSelectTest KTests[];
1.426 + };
1.427 +const TText* const TypeInt16::KType=_S("SMALLINT");
1.428 +const TInt TypeInt16::KValues[]={-32768,-32767,-1,0,1,32766,32767};
1.429 +const TSelectTest TypeInt16::KTests[]=
1.430 + {
1.431 + {_S("IS NULL"),ROW(0)},
1.432 + {_S("IS NOT NULL"),ALL_ROWS},
1.433 + {_S("=0"),ROW(4)},
1.434 + {_S("<>0"),ALL_ROWS-ROW(4)},
1.435 + {_S("=-1"),ROW(3)},
1.436 + {_S("<2"),ROWS(1,5)},
1.437 + {_S(">=-40000"),ALL_ROWS},
1.438 + {_S("<32766"),ROWS(1,5)},
1.439 + {_S("=40"),NO_ROWS}
1.440 + };
1.441 +
1.442 +struct TypeInt32
1.443 + {
1.444 +public:
1.445 + static const TText* const KType;
1.446 + static const TInt KValues[];
1.447 + static const TSelectTest KTests[];
1.448 + };
1.449 +const TText* const TypeInt32::KType=_S("INTEGER");
1.450 +const TInt TypeInt32::KValues[]={0x80000000/*-2147483648*/,-2147483647,-1,0,1,2147483646,2147483647};
1.451 +const TSelectTest TypeInt32::KTests[]=
1.452 + {
1.453 + {_S("IS NULL"),ROW(0)},
1.454 + {_S("IS NOT NULL"),ALL_ROWS},
1.455 + {_S("=0"),ROW(4)},
1.456 + {_S("<>0"),ALL_ROWS-ROW(4)},
1.457 + {_S("=-1"),ROW(3)},
1.458 + {_S("<2"),ROWS(1,5)},
1.459 + {_S(">=-2147483648"),ALL_ROWS},
1.460 + {_S("<2147483646"),ROWS(1,5)},
1.461 + {_S(">2147483647"),NO_ROWS},
1.462 + {_S("=40"),NO_ROWS}
1.463 + };
1.464 +
1.465 +struct TypeInt64
1.466 + {
1.467 +public:
1.468 + static const TText* const KType;
1.469 + static const TInt64 KValues[];
1.470 + static const TSelectTest KTests[];
1.471 + };
1.472 +const TText* const TypeInt64::KType=_S("BIGINT");
1.473 +const TInt64 TypeInt64::KValues[]=
1.474 + {
1.475 + MAKE_TINT64(0x80000000, 0x00000000), // min int64
1.476 + _LINT64(-4294967296),
1.477 + TInt(0x80000000), // -2147483648!
1.478 + -1,
1.479 + 0u,
1.480 + 1u,
1.481 + 2147483647u,
1.482 + _LINT64(2147483648),
1.483 + _LINT64(4294967295),
1.484 + _LINT64(4294967296),
1.485 + _LINT64(9223372036854775807) // max int64
1.486 + };
1.487 +const TSelectTest TypeInt64::KTests[]=
1.488 + {
1.489 + {_S("IS NULL"),ROW(0)},
1.490 + {_S("IS NOT NULL"),ALL_ROWS},
1.491 + {_S("=0"),ROW(5)},
1.492 + {_S("<>0"),ALL_ROWS-ROW(5)},
1.493 + {_S("=-1"),ROW(4)},
1.494 + {_S("<2"),ROWS(1,6)},
1.495 + {_S(">=-9223372036854775808"),ALL_ROWS},
1.496 + {_S("<4294967296"),ROWS(1,9)},
1.497 + {_S(">9223372036854775806"),ROW(11)},
1.498 + {_S("=40"),NO_ROWS}
1.499 + };
1.500 +
1.501 +struct TypeReal32
1.502 + {
1.503 +public:
1.504 + static const TText* const KType;
1.505 + static const TReal32 KValues[];
1.506 + static const TSelectTest KTests[];
1.507 + };
1.508 +const TText* const TypeReal32::KType=_S("REAL");
1.509 +const TReal32 TypeReal32::KValues[]=
1.510 + {
1.511 + -KMaxTReal32,
1.512 + -1.0f,
1.513 + -KMinTReal32,
1.514 + 0.0f,
1.515 + KMinTReal32,
1.516 + 1.0f,
1.517 + KMaxTReal32
1.518 + };
1.519 +const TSelectTest TypeReal32::KTests[]=
1.520 + {
1.521 + {_S("IS NULL"),ROW(0)},
1.522 + {_S("IS NOT NULL"),ALL_ROWS},
1.523 + {_S("=0"),ROW(4)},
1.524 + {_S("<>0.0"),ALL_ROWS-ROW(4)},
1.525 + {_S("=-1"),ROW(2)},
1.526 + {_S("<2e1"),ROWS(1,6)},
1.527 + {_S(">=-100000000000000"),ROWS(2,7)},
1.528 + {_S("<1e-36"),ROWS(1,5)},
1.529 + {_S(">1e15"),ROW(7)},
1.530 + {_S("=.5"),NO_ROWS},
1.531 + {_S("<=-.0"),ROWS(1,4)},
1.532 + {_S("<1e40"),ALL_ROWS}
1.533 + };
1.534 +
1.535 +struct TypeReal64
1.536 + {
1.537 +public:
1.538 + static const TText* const KType;
1.539 + static const TReal64 KValues[];
1.540 + static const TSelectTest KTests[];
1.541 + };
1.542 +const TText* const TypeReal64::KType=_S("DOUBLE");
1.543 +const TReal64 TypeReal64::KValues[]=
1.544 + {
1.545 + -KMaxTReal64,
1.546 + -1.0f,
1.547 + -KMinTReal64,
1.548 + 0.0f,
1.549 + KMinTReal64,
1.550 + 1.0f,
1.551 + KMaxTReal64
1.552 + };
1.553 +const TSelectTest TypeReal64::KTests[]=
1.554 + {
1.555 + {_S("IS NULL"),ROW(0)},
1.556 + {_S("IS NOT NULL"),ALL_ROWS},
1.557 + {_S("=0"),ROW(4)},
1.558 + {_S("<>0"),ALL_ROWS-ROW(4)},
1.559 + {_S("=-1"),ROW(2)},
1.560 + {_S("<2"),ROWS(1,6)},
1.561 + {_S(">=-100000000000000"),ROWS(2,7)},
1.562 + {_S("<1e-300"),ROWS(1,5)},
1.563 + {_S(">1e15"),ROW(7)},
1.564 + {_S("=.5"),NO_ROWS},
1.565 + {_S("<=0"),ROWS(1,4)},
1.566 + {_S("<1e40"),ROWS(1,6)}
1.567 + };
1.568 +
1.569 +struct TypeTime
1.570 + {
1.571 +public:
1.572 + static const TText* const KType;
1.573 + static const TTime KValues[];
1.574 + static const TSelectTest KTests[];
1.575 + };
1.576 +const TText* const TypeTime::KType=_S("TIME");
1.577 +const TTime TypeTime::KValues[]=
1.578 + {
1.579 + TInt64(0u), // zero date/time
1.580 + _L(":085815"), // 8:58:15am
1.581 + _L("19181010:110000"), // 11am, 11 Nov 1918
1.582 + _L("19750226:"), // midnight, 27 Mar 1975
1.583 + _L("19961130:235959"), // 11:59:59pm, 31 Dec 1996
1.584 + _L("19970000:"), // midnight, 1 Jan 1997
1.585 + _L("19970611:210000"), // 9pm, 12 July 1997
1.586 + _L("19980309:214500"), // 9:45pm, 10 April 1998
1.587 + _L("20700608:") // midnight, 9 July 2070
1.588 + };
1.589 +const TSelectTest TypeTime::KTests[]=
1.590 + {
1.591 + {_S("IS NULL"),ROW(0)},
1.592 + {_S("IS NOT NULL"),ALL_ROWS},
1.593 + {_S("=#12am#"),ROW(1)},
1.594 + {_S("<#Jan 1 2100#"),ALL_ROWS},
1.595 + {_S("<>#31/12/1996 23:59:59#"),ALL_ROWS-ROW(5)},
1.596 + {_S("<#9a#"),ROWS(1,2)},
1.597 + {_S(">=#11:59:59pm, 31 Dec 1996#"),ROWS(5,9)},
1.598 + {_S("=#9:45pm 10 April, 1998#"),ROW(8)},
1.599 + {_S("=#8:58:15#"),ROW(2)}
1.600 + };
1.601 +
1.602 +struct TypeText
1.603 + {
1.604 +public:
1.605 + static const TText* const KType;
1.606 + static const TText* const KValues[];
1.607 + static TSelectTest KTests[];
1.608 + };
1.609 +const TText* const TypeText::KType=_S("VARCHAR(100)");
1.610 +const TText* const TypeText::KValues[]=
1.611 + {
1.612 + _S(""), // this should be equivalent to NULL
1.613 + _S("a"),
1.614 + _S("aa"),
1.615 + _S("aba"),
1.616 + _S("like"),
1.617 + _S("abcdefghijklmnopqrstuvwxyzlike"),
1.618 + _S("likeabcdefghijklmnopqrstuvwxyz"),
1.619 + _S("abcdefghijklmnopqrstuvwxyzlikeabcdefghijklmnopqrstuvwxyz"),
1.620 + _S("abcdefghijklmnopqrstuvwxyzliveabcdefghijklmnopqrstuvwxyz"),
1.621 + _S("l'ke"),
1.622 + _S("'Tis")
1.623 + };
1.624 +TSelectTest TypeText::KTests[]=
1.625 + {
1.626 + {_S("IS NULL"),ROWS(0,1)},
1.627 + {_S("IS NOT NULL"),ALL_ROWS-ROW(1)},
1.628 +//
1.629 + {_S("=''"),ROWS(0,1)}, // equivalent to IS NULL
1.630 + {_S("<>''"),ALL_ROWS-ROW(1)}, // equivalent to IS NOT NULL
1.631 + {_S(">''"),ALL_ROWS-ROW(1)}, // equivalent to IS NOT NULL
1.632 + {_S("<''"),NO_ROWS}, // expression is trivially false
1.633 + {_S("<=''"),ROWS(0,1)},
1.634 + {_S(">=''"),ALL_ROWS+ROW(0)}, // expression is trivially true
1.635 +//
1.636 + {_S("LIKE ''"),ROWS(0,1)}, // synonomous with IS NULL
1.637 + {_S("NOT LIKE ''"),ALL_ROWS-ROW(1)},
1.638 + {_S("LIKE '?*'"),ALL_ROWS-ROW(1)}, // synonomous with IS NOT NULL
1.639 + {_S("NOT LIKE '?*'"),ROWS(0,1)},
1.640 + {_S("LIKE '*'"),ALL_ROWS+ROW(0)}, // trivially true
1.641 + {_S("NOT LIKE '*'"),NO_ROWS},
1.642 +//
1.643 + {_S("='a'"),ROW(2)},
1.644 + {_S("<'ab'"),ROWS(0,3)+ROW(11)},
1.645 + {_S("<'abc'"),ROWS(0,4)+ROW(11)},
1.646 + {_S("<'b'"),ROWS(0,4)+ROW(6)+ROWS(8,9)+ROW(11)},
1.647 + {_S(">'abc'"),ROWS(5,10)},
1.648 + {_S("='like'"),ROW(5)},
1.649 + {_S("='l''ke'"),ROW(10)},
1.650 + {_S("='''Tis'"),ROW(11)},
1.651 +//
1.652 + {_S("LIKE 'a'"),ROW(2)},
1.653 + {_S("LIKE 'a*'"),ROWS(2,4)+ROW(6)+ROWS(8,9)},
1.654 + {_S("LIKE '*a'"),ROWS(2,4)},
1.655 + {_S("LIKE 'a*a'"),ROWS(3,4)},
1.656 + {_S("LIKE '*a*'"),ROWS(2,4)+ROWS(6,9)},
1.657 +//
1.658 + {_S("LIKE 'like'"),ROW(5)},
1.659 + {_S("LIKE 'l?ke'"),ROW(5)+ROW(10)},
1.660 + {_S("LIKE 'like*'"),ROW(5)+ROW(7)},
1.661 + {_S("LIKE '*like'"),ROWS(5,6)},
1.662 + {_S("LIKE '*like*'"),ROWS(5,8)},
1.663 + {_S("LIKE '*likeit*'"),NO_ROWS},
1.664 + {_S("LIKE '*li?e*'"),ROWS(5,9)},
1.665 + {_S("LIKE '?*li?e*'"),ROW(6)+ROWS(8,9)},
1.666 + {_S("LIKE '*li?e*?'"),ROWS(7,9)},
1.667 + {_S("LIKE '?*li?e*?'"),ROWS(8,9)},
1.668 + {_S("LIKE '*?k?*'"),ROWS(5,10)},
1.669 + {_S("LIKE '*?i?e*'"),ROWS(5,9)},
1.670 +//
1.671 + {_S("LIKE '*e*'"),ROWS(5,10)},
1.672 + {_S("LIKE '*z*k*e*'"),ROW(6)+ROW(8)},
1.673 + {_S("LIKE '\?\?k?'"),ROW(5)+ROW(10)},
1.674 + {_S("LIKE '\?\?k*'"),ROW(5)+ROW(7)+ROW(10)},
1.675 + {_S("LIKE '*''*'"),ROWS(10,11)},
1.676 + {_S("LIKE '?''\?\?'"),ROW(10)},
1.677 + {_S("LIKE '?'"),ROW(2)},
1.678 + {_S("LIKE '\?\?\?\?'"),ROW(5)+ROWS(10,11)},
1.679 + {_S("LIKE '\?\?*\?\?'"),ROWS(5,11)},
1.680 + {_S("LIKE '''*'"),ROW(11)}
1.681 + };
1.682 +
1.683 +TEMPLATE_SPECIALIZATION struct SetCol<const TText* const>
1.684 + {
1.685 + static void SetColL(TDbColNo aCol,const TAny* aVal)
1.686 + {
1.687 + TheTable.SetColL(aCol,TPtrC(*(const TText* const*)aVal));
1.688 + }
1.689 + };
1.690 +TEMPLATE_SPECIALIZATION struct SetCol<const TText*>
1.691 + {
1.692 + static void SetColL(TDbColNo aCol,const TAny* aVal)
1.693 + {
1.694 + TheTable.SetColL(aCol,TPtrC(*(const TText* const*)aVal));
1.695 + }
1.696 + };
1.697 +
1.698 +struct TypeLongText
1.699 + {
1.700 +public:
1.701 + static const TText* const KType;
1.702 + };
1.703 +const TText* const TypeLongText::KType=_S("LONG VARCHAR");
1.704 +
1.705 +class TestPredicate2 : public TestPredicateBase
1.706 + {
1.707 +public:
1.708 + static void RunL();
1.709 + };
1.710 +
1.711 +// write rows equivalent to TypeText and use its tests
1.712 +void TestPredicate2::RunL()
1.713 + {
1.714 + Create(TypeLongText::KType);
1.715 + TBuf<1022> fill=_S("abcdefghijklmnopqrstuvqxyz");
1.716 + fill.AppendFill('.',fill.MaxLength()-fill.Length());
1.717 +
1.718 + for (TInt row=0;row<=TInt(elementsof(TypeText::KValues));++row)
1.719 + {
1.720 + TheTable.InsertL();
1.721 + TheTable.SetColL(1,row);
1.722 + if (row>0)
1.723 + {
1.724 + RDbColWriteStream blob;
1.725 + blob.OpenLC(TheTable,2);
1.726 + switch (row)
1.727 + {
1.728 + case 0:
1.729 + break;
1.730 + case 1: case 2: case 3: case 4: case 5: case 10: case 11:
1.731 + blob.WriteL(TPtrC(TypeText::KValues[row-1]));
1.732 + break;
1.733 + case 6:
1.734 + blob.WriteL(fill);
1.735 + blob.WriteL(_L("like"));
1.736 + break;
1.737 + case 7:
1.738 + blob.WriteL(_L("like"));
1.739 + blob.WriteL(fill);
1.740 + break;
1.741 + case 8:
1.742 + blob.WriteL(fill);
1.743 + blob.WriteL(_L("like"));
1.744 + blob.WriteL(fill);
1.745 + break;
1.746 + case 9:
1.747 + blob.WriteL(fill);
1.748 + blob.WriteL(_L("live"));
1.749 + blob.WriteL(fill);
1.750 + break;
1.751 + }
1.752 + blob.CommitL();
1.753 + CleanupStack::PopAndDestroy();
1.754 + }
1.755 + TheTable.PutL();
1.756 + }
1.757 + TheTable.Close();
1.758 + TInt r=TheDatabase.Commit();
1.759 + TEST2(r, KErrNone);
1.760 + TestViewL(TypeText::KTests,elementsof(TypeText::KTests),elementsof(TypeText::KValues));
1.761 + CDbKey& key=*CDbKey::NewLC();
1.762 + key.AddL(TDbKeyCol(_L("Test"),120));
1.763 + r=TheDatabase.CreateIndex(_L("Key"),_L("Compare"),key);
1.764 + TEST2(r, KErrNone);
1.765 + CleanupStack::PopAndDestroy();
1.766 + TestViewL(TypeText::KTests,elementsof(TypeText::KTests),elementsof(TypeText::KValues));
1.767 + r=TheDatabase.Execute(_L("DROP TABLE Compare"));
1.768 + TEST2(r, KErrNone);
1.769 + }
1.770 +
1.771 +/**
1.772 +* Utility for DEF063276 fix.
1.773 +*/
1.774 +
1.775 +#ifndef __TOOLS2__
1.776 +_LIT(KTypeTextKTests44, "Z:\\test\\data\\typetextktests44.dat");
1.777 +_LIT(KTypeTextKTests46, "Z:\\test\\data\\typetextktests46.dat");
1.778 +_LIT(KTypeTextKTests47, "Z:\\test\\data\\typetextktests47.dat");
1.779 +#else
1.780 +_LIT(KTypeTextKTests44, ".\\dbms-tst\\typetextktests44.dat");
1.781 +_LIT(KTypeTextKTests46, ".\\dbms-tst\\typetextktests46.dat");
1.782 +_LIT(KTypeTextKTests47, ".\\dbms-tst\\typetextktests47.dat");
1.783 +#endif
1.784 +
1.785 +static void ReadDesc(TDes& aDes, const TDesC& aFilename, RFs& aFs)
1.786 + {
1.787 + RFile file;
1.788 + TInt err = file.Open(aFs, aFilename, EFileRead);
1.789 + TheTest(err == KErrNone);
1.790 + CleanupClosePushL(file);
1.791 +
1.792 + TPtr8 ptr(reinterpret_cast<TUint8*>(const_cast<TUint16*>(aDes.Ptr())), aDes.MaxSize());
1.793 + err = file.Read(ptr);
1.794 + TheTest(err == KErrNone);
1.795 + aDes.SetLength(ptr.Length() / sizeof(TText));
1.796 + CleanupStack::PopAndDestroy(&file);
1.797 + }
1.798 +
1.799 +/**
1.800 +@SYMTestCaseID SYSLIB-DBMS-CT-0633
1.801 +@SYMTestCaseDesc Tests the Predicate operators for all types
1.802 +@SYMTestPriority Medium
1.803 +@SYMTestActions Attempt to check with different types
1.804 +@SYMTestExpectedResults Test must not fail
1.805 +@SYMREQ REQ0000
1.806 +*/
1.807 +LOCAL_C void TestPredicatesL()
1.808 + {
1.809 + TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0633 init "));
1.810 + CreateDatabase();
1.811 + TestPredicate<TypeBit>::Run();
1.812 + TestPredicate<TypeUint8>::Run();
1.813 + TestPredicate<TypeUint16>::Run();
1.814 + TestPredicate<TypeUint32>::Run();
1.815 + TestPredicate<TypeInt8>::Run();
1.816 + TestPredicate<TypeInt16>::Run();
1.817 + TestPredicate<TypeInt32>::Run();
1.818 + TestPredicate<TypeInt64>::Run();
1.819 + TestPredicate<TypeReal32>::Run();
1.820 + TestPredicate<TypeReal64>::Run();
1.821 + TestPredicate<TypeTime>::Run();
1.822 +
1.823 + /**
1.824 + * Work around for DEF063276.
1.825 + * These literals are now loaded from Z:\test\data\TypeTextKTests44.dat,
1.826 + * Z:\test\data\TypeTextKTests44.dat and Z:\test\data\TypeTextKTests44.dat respectively.
1.827 + * Bullseye Coverage corrupts these literals to avoid this they are stored in files as to not be touched by Bullseye Coverage.
1.828 + */
1.829 +
1.830 + TBuf<16> buf44;
1.831 + ReadDesc(buf44, KTypeTextKTests44, TheFs);
1.832 + TypeText::KTests[44].iSearchCondition = const_cast<TText*>(buf44.PtrZ());
1.833 +
1.834 + TBuf<32> buf46(TypeText::KTests[46].iSearchCondition);
1.835 + ReadDesc(buf46, KTypeTextKTests46, TheFs);
1.836 + TypeText::KTests[46].iSearchCondition = const_cast<TText*>(buf46.PtrZ());
1.837 +
1.838 + TBuf<32> buf47(TypeText::KTests[47].iSearchCondition);
1.839 + ReadDesc(buf47, KTypeTextKTests47, TheFs);
1.840 + TypeText::KTests[47].iSearchCondition = const_cast<TText*>(buf47.PtrZ());
1.841 +
1.842 + // End fix.
1.843 +
1.844 + TestPredicate<TypeText>::Run();
1.845 + TestPredicate2::RunL();
1.846 + CloseDatabase();
1.847 + TheTest.End();
1.848 + }
1.849 +
1.850 +/**
1.851 +@SYMTestCaseID SYSLIB-DBMS-CT-0634
1.852 +@SYMTestCaseDesc DML Query test
1.853 + Test for RDbNamedDatabase::Execute() function
1.854 +@SYMTestPriority Medium
1.855 +@SYMTestActions Tests for CREATE TABLE,CREATE UNIQUE INDEX,INSET INTO,UPDATE,DELETE,DROP queries
1.856 +@SYMTestExpectedResults Test must not fail
1.857 +@SYMREQ REQ0000
1.858 +*/
1.859 +LOCAL_C void TestDML()
1.860 + {
1.861 + TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0634 init "));
1.862 + Connect();
1.863 + ShareDatabase();
1.864 + TInt r=TheDatabase.Execute(_L("CREATE TABLE test (ID INTEGER NOT NULL,SALARY DOUBLE)"));
1.865 + TEST2(r, KErrNone);
1.866 + r=TheDatabase.Execute(_L("CREATE UNIQUE INDEX key ON test (ID)"));
1.867 + TEST2(r, KErrNone);
1.868 +
1.869 + TheTest.Next(_L("insert-statements"));
1.870 + r=TheDatabase.Execute(_L("INSERT INTO test VALUES (0,0)"));
1.871 + TEST(r==1);
1.872 + r=TheDatabase.Execute(_L("INSERT INTO test (ID) VALUES (1)"));
1.873 + TEST(r==1);
1.874 + r=TheDatabase.Execute(_L("INSERT INTO test (SALARY,ID) VALUES (20.4,2)"));
1.875 + TEST(r==1);
1.876 +
1.877 + TheTest.Next(_L("update-statements"));
1.878 + r=TheDatabase.Execute(_L("UPDATE test SET SALARY=30000 WHERE ID=1"));
1.879 + TEST(r==1);
1.880 +
1.881 + TheTest.Next(_L("delete-statements"));
1.882 + r=TheDatabase.Execute(_L("DELETE FROM test WHERE SALARY<40"));
1.883 + TEST(r==2);
1.884 + r=TheDatabase.Execute(_L("DELETE FROM test"));
1.885 + TEST(r==1);
1.886 + r=TheDatabase.Execute(_L("DROP TABLE test"));
1.887 + TEST2(r, KErrNone);
1.888 +//
1.889 + TheTest.Next(_L("larger table"));
1.890 + r=TheDatabase.Execute(_L("CREATE TABLE test (ID COUNTER,DATA INTEGER)"));
1.891 + TEST2(r, KErrNone);
1.892 +
1.893 + TheTest.Next(_L("insert"));
1.894 + TheDatabase.Begin();
1.895 + TBuf<256> sql;
1.896 + for (TInt ii=0;ii<100;++ii)
1.897 + {
1.898 + sql.Format(_L("INSERT INTO test (DATA) VALUES (%D)"),100-ii);
1.899 + r=TheDatabase.Execute(sql);
1.900 + TEST(r==1);
1.901 + }
1.902 + r=TheDatabase.Commit();
1.903 + TEST2(r, KErrNone);
1.904 +
1.905 + TheTest.Next(_L("update"));
1.906 + r=TheDatabase.Execute(_L("UPDATE test SET DATA=200 WHERE ID>=40 AND ID<60"));
1.907 + TEST(r==20);
1.908 +
1.909 + TheTest.Next(_L("delete"));
1.910 + r=TheDatabase.Execute(_L("DELETE FROM test WHERE DATA>90"));
1.911 + TEST(r==30);
1.912 +
1.913 + TheTest.Next(_L("update"));
1.914 + r=TheDatabase.Execute(_L("UPDATE test SET DATA=-1"));
1.915 + TEST(r==70);
1.916 +
1.917 + TheTest.Next(_L("delete"));
1.918 + r=TheDatabase.Execute(_L("DELETE FROM test"));
1.919 + TEST(r==70);
1.920 + r=TheDatabase.Execute(_L("DROP TABLE test"));
1.921 + TEST2(r, KErrNone);
1.922 + CloseDatabase();
1.923 + Disconnect();
1.924 + TheTest.End();
1.925 + }
1.926 +
1.927 +/**
1.928 +@SYMTestCaseID SYSLIB-DBMS-CT-0635
1.929 +@SYMTestCaseDesc DBMS SQL parsing and execution tests.Tests for database index order
1.930 + Test for RDbNamedDatabase::Execute() function
1.931 +@SYMTestPriority Medium
1.932 +@SYMTestActions Tests for order by index
1.933 +@SYMTestExpectedResults Test must not fail
1.934 +@SYMREQ REQ0000
1.935 +*/
1.936 +LOCAL_C void TestOrderByL()
1.937 + {
1.938 + static const TReal TestDataSalary[]={10,34000,15000,53200,17800,240000};
1.939 + static const TText* const TestDataNames[]={_S("gopher"),_S("james '007' bond"),_S("moneypenny"),_S("Q"),_S("james '007' bond"),_S("M")};
1.940 +//
1.941 + TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0635 init "));
1.942 + Connect();
1.943 + ShareDatabase();
1.944 + TheDatabase.Begin();
1.945 + TInt r=TheDatabase.Execute(_L("CREATE TABLE test (ID INTEGER NOT NULL,SALARY DOUBLE,NAME VARCHAR)"));
1.946 + TEST2(r, KErrNone);
1.947 + r=TheDatabase.Execute(_L("CREATE UNIQUE INDEX key ON test (ID)"));
1.948 + TEST2(r, KErrNone);
1.949 +
1.950 + TheTest.Next(_L("insert data"));
1.951 + r=TheView.Prepare(TheDatabase,_L("SELECT ID,SALARY,NAME FROM test"),TheView.EInsertOnly);
1.952 + TEST2(r, KErrNone);
1.953 + TInt ii;
1.954 + for (ii=0;ii<6;++ii)
1.955 + {
1.956 + TheView.InsertL();
1.957 + TheView.SetColL(1,6-ii);
1.958 + TheView.SetColL(2,TestDataSalary[ii]);
1.959 + TheView.SetColL(3,TPtrC(TestDataNames[ii]));
1.960 + TheView.PutL();
1.961 + }
1.962 + r=TheDatabase.Commit();
1.963 + TEST2(r, KErrNone);
1.964 + TheView.Close();
1.965 +
1.966 + TheTest.Next(_L("Order by <index>"));
1.967 + // test the index is used here
1.968 + r=TheView.Prepare(TheDatabase,_L("SELECT ID FROM test ORDER BY ID"));
1.969 + TEST2(r, KErrNone);
1.970 + TEST(!TheView.Unevaluated());
1.971 + TInt c=0;
1.972 + if (TheView.FirstL())
1.973 + {
1.974 + ++c;
1.975 + TheView.GetL();
1.976 + TInt last=TheView.ColInt(1);
1.977 + while (TheView.NextL())
1.978 + {
1.979 + ++c;
1.980 + TheView.GetL();
1.981 + TInt v=TheView.ColInt(1);
1.982 + TEST(v>last);
1.983 + last=v;
1.984 + }
1.985 + }
1.986 + TEST(c==6);
1.987 + TEST(c==TheView.CountL());
1.988 + TheView.Close();
1.989 +
1.990 + TheTest.Next(_L("Order by <no-index> 1"));
1.991 + // test that no index is used here
1.992 + r=TheView.Prepare(TheDatabase,_L("SELECT SALARY FROM test ORDER BY SALARY"));
1.993 + TEST2(r, KErrNone);
1.994 + TEST(TheView.Unevaluated());
1.995 + r=TheView.EvaluateAll();
1.996 + TEST2(r, KErrNone);
1.997 + c=0;
1.998 + if (TheView.FirstL())
1.999 + {
1.1000 + ++c;
1.1001 + TheView.GetL();
1.1002 + TReal last=TheView.ColReal(1);
1.1003 + while (TheView.NextL())
1.1004 + {
1.1005 + ++c;
1.1006 + TheView.GetL();
1.1007 + TReal v=TheView.ColReal(1);
1.1008 + TEST(v>=last);
1.1009 + last=v;
1.1010 + }
1.1011 + }
1.1012 + TEST(c==6);
1.1013 + TEST(c==TheView.CountL());
1.1014 + TheView.Close();
1.1015 +
1.1016 + TheTest.Next(_L("Order by <no-index> 2"));
1.1017 + // test that no index is used here
1.1018 + r=TheView.Prepare(TheDatabase,_L("SELECT SALARY FROM test ORDER BY SALARY,NAME"));
1.1019 + TEST2(r, KErrNone);
1.1020 + TEST(TheView.Unevaluated());
1.1021 + r=TheView.EvaluateAll();
1.1022 + TEST2(r, KErrNone);
1.1023 + c=0;
1.1024 + if (TheView.FirstL())
1.1025 + {
1.1026 + ++c;
1.1027 + TheView.GetL();
1.1028 + TReal last=TheView.ColReal(1);
1.1029 + while (TheView.NextL())
1.1030 + {
1.1031 + ++c;
1.1032 + TheView.GetL();
1.1033 + TReal v=TheView.ColReal(1);
1.1034 + TEST(v>=last);
1.1035 + last=v;
1.1036 + }
1.1037 + }
1.1038 + TEST(c==6);
1.1039 + TEST(c==TheView.CountL());
1.1040 + TheView.Close();
1.1041 +
1.1042 + TheTest.Next(_L("Order by <no-index> 3"));
1.1043 + // test that no index is used here
1.1044 + r=TheView.Prepare(TheDatabase,_L("SELECT NAME FROM test ORDER BY NAME"));
1.1045 + TEST2(r, KErrNone);
1.1046 + TEST(TheView.Unevaluated());
1.1047 + r=TheView.EvaluateAll();
1.1048 + TEST2(r, KErrNone);
1.1049 + c=0;
1.1050 + if (TheView.FirstL())
1.1051 + {
1.1052 + ++c;
1.1053 + TheView.GetL();
1.1054 + TBuf<50> last=TheView.ColDes(1);
1.1055 + while (TheView.NextL())
1.1056 + {
1.1057 + ++c;
1.1058 + TheView.GetL();
1.1059 + TPtrC v=TheView.ColDes(1);
1.1060 + TEST(v>=last);
1.1061 + last=v;
1.1062 + }
1.1063 + }
1.1064 + TEST(c==6);
1.1065 + TEST(c==TheView.CountL());
1.1066 + TheView.Close();
1.1067 +
1.1068 + TheTest.Next(_L("Order by <no-index> 4"));
1.1069 + // test that no index is used here
1.1070 + r=TheView.Prepare(TheDatabase,_L("SELECT NAME FROM test ORDER BY NAME,SALARY"));
1.1071 + TEST2(r, KErrNone);
1.1072 + TEST(TheView.Unevaluated());
1.1073 + r=TheView.EvaluateAll();
1.1074 + TEST2(r, KErrNone);
1.1075 + c=0;
1.1076 + if (TheView.FirstL())
1.1077 + {
1.1078 + ++c;
1.1079 + TheView.GetL();
1.1080 + TBuf<50> last=TheView.ColDes(1);
1.1081 + while (TheView.NextL())
1.1082 + {
1.1083 + ++c;
1.1084 + TheView.GetL();
1.1085 + TPtrC v=TheView.ColDes(1);
1.1086 + TEST(v>=last);
1.1087 + last=v;
1.1088 + }
1.1089 + }
1.1090 + TEST(c==6);
1.1091 + TEST(c==TheView.CountL());
1.1092 + TheView.Close();
1.1093 +
1.1094 + TheTest.Next(_L("Order by + search <no-index>"));
1.1095 + // test that no index is used here
1.1096 + r=TheView.Prepare(TheDatabase,_L("SELECT ID,SALARY FROM test WHERE SALARY>30000 ORDER BY SALARY DESC"));
1.1097 + TEST2(r, KErrNone);
1.1098 + TEST(TheView.Unevaluated());
1.1099 + r=TheView.EvaluateAll();
1.1100 + TEST2(r, KErrNone);
1.1101 + c=0;
1.1102 + if (TheView.FirstL())
1.1103 + {
1.1104 + ++c;
1.1105 + TheView.GetL();
1.1106 + TReal last=TheView.ColReal(2);
1.1107 + while (TheView.NextL())
1.1108 + {
1.1109 + ++c;
1.1110 + TheView.GetL();
1.1111 + TReal v=TheView.ColReal(2);
1.1112 + TEST(v<=last);
1.1113 + last=v;
1.1114 + }
1.1115 + }
1.1116 + TEST(c==3);
1.1117 + TEST(c==TheView.CountL());
1.1118 + TheView.Close();
1.1119 +//
1.1120 + CloseDatabase();
1.1121 + Disconnect();
1.1122 +
1.1123 + TheTest.Next(_L("Order by <index> Finished"));
1.1124 + TheTest.End();
1.1125 + }
1.1126 +
1.1127 +LOCAL_C void doMain()
1.1128 + {
1.1129 + TheTest.Start(_L("Predicate tests"));
1.1130 + TRAPD(errCode, TestPredicatesL());
1.1131 + TEST2(errCode, KErrNone);
1.1132 +
1.1133 + TheTest.Next(_L("DML execution"));
1.1134 + TestDML();
1.1135 +
1.1136 + TheTest.Next(_L("ORDER BY clause"));
1.1137 + TRAP(errCode, TestOrderByL());
1.1138 + TEST2(errCode, KErrNone);
1.1139 + TheTest.End();
1.1140 + }
1.1141 +
1.1142 +// Prepare the test directory.
1.1143 +LOCAL_C void setupTestDirectory()
1.1144 + {
1.1145 + TInt r=TheFs.Connect();
1.1146 + TEST2(r, KErrNone);
1.1147 +//
1.1148 + r=TheFs.MkDir(KTestDatabase);
1.1149 + TEST(r==KErrNone || r==KErrAlreadyExists);
1.1150 + }
1.1151 +
1.1152 +// Initialise the cleanup stack.
1.1153 +LOCAL_C void setupCleanup()
1.1154 + {
1.1155 + TheTrapCleanup=CTrapCleanup::New();
1.1156 + TEST(TheTrapCleanup!=NULL);
1.1157 + TRAPD(r,\
1.1158 + {\
1.1159 + for (TInt i=KTestCleanupStack;i>0;i--)\
1.1160 + CleanupStack::PushL((TAny*)0);\
1.1161 + CleanupStack::Pop(KTestCleanupStack);\
1.1162 + });
1.1163 + TEST2(r, KErrNone);
1.1164 + }
1.1165 +
1.1166 +// Test streaming conversions.
1.1167 +GLDEF_C TInt E32Main()
1.1168 + {
1.1169 + TheTest.Title();
1.1170 + setupTestDirectory();
1.1171 + setupCleanup();
1.1172 + __UHEAP_MARK;
1.1173 +//
1.1174 + TheTest.Start(_L("Standard database"));
1.1175 + doMain();
1.1176 +
1.1177 + TheTest.Printf(_L("Waiting for server exit\n"));
1.1178 + const TUint KExitDelay=6*0x100000; // ~6 seconds
1.1179 + User::After(KExitDelay);
1.1180 +
1.1181 + // clean up data file used by this test - must be done before call to End() - DEF047652
1.1182 + ::TestCleanup();
1.1183 +
1.1184 +#ifndef __linux__
1.1185 + TInt err;
1.1186 +#ifndef __TOOLS2__
1.1187 + TRAPD(lc, err = TheCrcChecker.DumpCrcRecordsL(KCrcRecord));
1.1188 + TheTest(err==KErrNone);
1.1189 + TheTest(lc==KErrNone);
1.1190 +#else
1.1191 + TRAPD(lc, err = TheCrcChecker.ValidateCrcRecordsL(KCrcRecord));
1.1192 + TPtrC errmsg;
1.1193 + TheCrcChecker.ErrorReportL(err, errmsg);
1.1194 + RDebug::Print(errmsg);
1.1195 + TheTest(err==KErrNone || err==TDBMS_CRCChecks::ECrcCheckOk);
1.1196 +#endif
1.1197 +#endif
1.1198 +
1.1199 + TheTest.End();
1.1200 +//
1.1201 + __UHEAP_MARKEND;
1.1202 +
1.1203 +
1.1204 + delete TheTrapCleanup;
1.1205 + TheTest.Close();
1.1206 + return 0;
1.1207 + }