persistentstorage/dbms/tdbms/t_dbsql.cpp
changeset 51 7d4490026038
parent 0 08ec8eefde2f
child 55 44f437012c90
equal deleted inserted replaced
40:b8bdbc8f59c7 51:7d4490026038
   160 
   160 
   161 class TestPredicateBase
   161 class TestPredicateBase
   162 	{
   162 	{
   163 protected:
   163 protected:
   164 	static void Create(const TText* aType);
   164 	static void Create(const TText* aType);
   165 	static void Test(const TSelectTest* aTest,TInt aCount,TInt aRows);
   165 	static void Test(const TSelectTest* aTest,TInt aCount,TInt aRows, TBool aLog);
   166 	static void TestViewL(const TSelectTest* aTest,TInt aCount,TInt aRows);
   166 	static void TestViewL(const TSelectTest* aTest,TInt aCount,TInt aRows, TBool aLog=EFalse);
   167 	};
   167 	};
   168 
   168 
   169 // Create the table for the predicate tests
   169 // Create the table for the predicate tests
   170 void TestPredicateBase::Create(const TText* aType)
   170 void TestPredicateBase::Create(const TText* aType)
   171 	{
   171 	{
   177 	r=TheTable.Open(TheDatabase,_L("Compare"),TheTable.EInsertOnly);
   177 	r=TheTable.Open(TheDatabase,_L("Compare"),TheTable.EInsertOnly);
   178 	TEST2(r, KErrNone);
   178 	TEST2(r, KErrNone);
   179 	}
   179 	}
   180 
   180 
   181 // Test the predicate on the table, then on the indexed table
   181 // Test the predicate on the table, then on the indexed table
   182 void TestPredicateBase::Test(const TSelectTest* aTest,TInt aCount,TInt aRows)
   182 void TestPredicateBase::Test(const TSelectTest* aTest,TInt aCount,TInt aRows, TBool aLog)
   183 	{
   183 	{
       
   184     if(aLog)
       
   185         {
       
   186         TheTest.Printf(_L("TestPredicateBase::Test\r\n"));
       
   187         }
   184 	TheTable.Close();
   188 	TheTable.Close();
   185 	TInt r=TheDatabase.Commit();
   189 	TInt r=TheDatabase.Commit();
   186 	TEST2(r, KErrNone);
   190 	if(aLog)
   187 	TRAPD(errCode, TestViewL(aTest,aCount,aRows));
   191         {
       
   192         TheTest.Printf(_L("Commit %d\r\n"), r);
       
   193         }
       
   194 	TEST2(r, KErrNone);
       
   195 	TRAPD(errCode, TestViewL(aTest,aCount,aRows, aLog));
       
   196 	if(aLog)
       
   197         {
       
   198         TheTest.Printf(_L("TestViewL %d"), errCode);
       
   199         }
       
   200 
   188 	TEST2(errCode, KErrNone);
   201 	TEST2(errCode, KErrNone);
   189 	r=TheDatabase.Execute(_L("CREATE INDEX Key ON Compare (Test)"));
   202 	r=TheDatabase.Execute(_L("CREATE INDEX Key ON Compare (Test)"));
   190 	TEST2(r, KErrNone);
   203    if(aLog)
   191 	TRAP(errCode,TestViewL(aTest,aCount,aRows));
   204         {
       
   205         TheTest.Printf(_L("Execute %d"), r);
       
   206         }
       
   207 
       
   208 	TEST2(r, KErrNone);
       
   209 	TRAP(errCode,TestViewL(aTest,aCount,aRows, aLog));
       
   210 	if(aLog)
       
   211         {
       
   212         TheTest.Printf(_L("TestViewL %d"), errCode);
       
   213 	    }
       
   214 
   192 	TEST2(errCode, KErrNone);
   215 	TEST2(errCode, KErrNone);
   193 	r=TheDatabase.Execute(_L("DROP TABLE Compare"));
   216 	r=TheDatabase.Execute(_L("DROP TABLE Compare"));
       
   217     if(aLog)
       
   218         {
       
   219         TheTest.Printf(_L("Execute %d"), r);
       
   220         }
       
   221 
   194 	TEST2(r, KErrNone);
   222 	TEST2(r, KErrNone);
   195 	}
   223 	}
   196 
   224 
   197 // Test the predicate on the table
   225 // Test the predicate on the table
   198 void TestPredicateBase::TestViewL(const TSelectTest* aTest,TInt aCount,TInt aRows)
   226 void TestPredicateBase::TestViewL(const TSelectTest* aTest,TInt aCount,TInt aRows, TBool /*aLog*/)
   199 	{
   227 	{
   200 	TUint rowMask=(2u<<aRows)-1;
   228 	TUint rowMask=(2u<<aRows)-1;
   201 	for (;--aCount>=0;++aTest)
   229 	for (;--aCount>=0;++aTest)
   202 		{
   230 		{
   203 		TheSql.Format(_L("SELECT Id FROM Compare WHERE Test %s"),aTest->iSearchCondition);
   231 		TheSql.Format(_L("SELECT Id FROM Compare WHERE Test %s"),aTest->iSearchCondition);
   204 		TInt r=TheView.Prepare(TheDatabase,TheSql,TheView.EReadOnly);
   232 		TInt r=TheView.Prepare(TheDatabase,TheSql,TheView.EReadOnly);
   205 
   233 		if(r!=KErrNone)
       
   234 		    {
       
   235             TheTest.Printf(_L("Prepare r= %d aCount= %d  statement %S\r\n"), r, aCount, &TheSql);
       
   236 		    }
       
   237 		TEST2(r, KErrNone);
   206 		TBool ignoreRow0=TheView.Unevaluated();
   238 		TBool ignoreRow0=TheView.Unevaluated();
   207 		TEST2(r, KErrNone);
       
   208 		r=TheView.EvaluateAll();
   239 		r=TheView.EvaluateAll();
   209 		TEST2(r, KErrNone);
   240  		TEST2(r, KErrNone);
   210 		TUint rows=0;
   241 		TUint rows=0;
   211 		while (TheView.NextL())
   242 		while (TheView.NextL())
   212 			{
   243 			{
   213 			TheView.GetL();
   244  			TheView.GetL();
   214 			rows|=1u<<TheView.ColUint(1);
   245 			rows|=1u<<TheView.ColUint(1);
   215 			}
   246 			}
   216 		if (ignoreRow0)
   247 		if (ignoreRow0)
   217 			TEST((rows&~ROW(0))==(aTest->iResultSet&rowMask&~ROW(0)));
   248 		    {
       
   249   			TEST((rows&~ROW(0))==(aTest->iResultSet&rowMask&~ROW(0)));
       
   250 		    }
   218 		else
   251 		else
   219 			TEST(rows==(aTest->iResultSet&rowMask));
   252 		    {
       
   253  			TEST(rows==(aTest->iResultSet&rowMask));
       
   254 		    }
   220 		TheView.Close();
   255 		TheView.Close();
   221 		}
   256 		}
   222 	}
   257 	}
   223 
   258 
   224 typedef void (*FSetColL)(TDbColNo aCol,const TAny* aVal);
   259 typedef void (*FSetColL)(TDbColNo aCol,const TAny* aVal);
   225 
   260 
   226 void WriteRowsL(const TAny* aValues,TInt aRows,TInt aSize,FSetColL aSetColL)
   261 void WriteRowsL(const TAny* aValues,TInt aRows,TInt aSize,FSetColL aSetColL, TBool aLog)
   227 	{
   262 	{
   228 	for (TInt row=0;row<=aRows;++row)
   263 	for (TInt row=0;row<=aRows;++row)
   229 		{
   264 		{
       
   265         if(aLog)
       
   266             {
       
   267             TheTest.Printf(_L("row = %d"), row);
       
   268             }
   230 		TheTable.InsertL();
   269 		TheTable.InsertL();
   231 		TEST(TheTable.ColUint(1)==TUint(row));
   270 		TEST(TheTable.ColUint(1)==TUint(row));
   232 		if (row>0)
   271 		if (row>0)
   233 			{	// first row is always null
   272 			{	// first row is always null
   234 			aSetColL(2,aValues);
   273 			aSetColL(2,aValues);
   246 		TheTable.SetColL(aCol,*(const T*)aVal);
   285 		TheTable.SetColL(aCol,*(const T*)aVal);
   247 		}
   286 		}
   248 	};
   287 	};
   249 
   288 
   250 template <class T>
   289 template <class T>
   251 inline void WriteRowsL(const T* aValues,TUint aRows)
   290 inline void WriteRowsL(const T* aValues,TUint aRows, TBool aLog)
   252 	{
   291 	{
   253 	WriteRowsL(aValues,aRows,sizeof(T),&SetCol<T>::SetColL);
   292 	WriteRowsL(aValues,aRows,sizeof(T),&SetCol<T>::SetColL, aLog);
   254 	}
   293 	}
   255 
   294 
   256 template <class T>
   295 template <class T>
   257 class TestPredicate : public TestPredicateBase
   296 class TestPredicate : public TestPredicateBase
   258 	{
   297 	{
   263 // Test the Predicate operators for all types
   302 // Test the Predicate operators for all types
   264 template <class T>
   303 template <class T>
   265 void TestPredicate<T>::RunL()
   304 void TestPredicate<T>::RunL()
   266 	{
   305 	{
   267 	Create(T::KType);
   306 	Create(T::KType);
   268 	WriteRowsL(T::KValues,elementsof(T::KValues));
   307 	TBool log = EFalse;
   269 	Test(T::KTests,elementsof(T::KTests),elementsof(T::KValues));
   308 	if((TPtrC(T::KType)).CompareF(_L("TIME"))==0)
       
   309 	    {
       
   310         log = ETrue;
       
   311 	    }
       
   312 	WriteRowsL(T::KValues,elementsof(T::KValues), log);
       
   313 	Test(T::KTests,elementsof(T::KTests),elementsof(T::KValues),log);
   270 	}
   314 	}
   271 
   315 
   272 struct TypeBit
   316 struct TypeBit
   273 	{
   317 	{
   274 public:
   318 public:
   742 _LIT(KTypeTextKTests46, "Z:\\test\\TypeTextKTests46.dat");
   786 _LIT(KTypeTextKTests46, "Z:\\test\\TypeTextKTests46.dat");
   743 _LIT(KTypeTextKTests47, "Z:\\test\\TypeTextKTests47.dat");
   787 _LIT(KTypeTextKTests47, "Z:\\test\\TypeTextKTests47.dat");
   744 
   788 
   745 static void ReadDesc(TDes& aDes, const TDesC& aFilename, RFs& aFs)
   789 static void ReadDesc(TDes& aDes, const TDesC& aFilename, RFs& aFs)
   746 	{
   790 	{
   747 	RDebug::Print(_L("---ReadDesc(), aFilename=%S\r\n"), &aFilename);
   791     TheTest.Printf(_L("---ReadDesc(), aFilename=%S\r\n"), &aFilename);
   748 	RFile file;
   792 	RFile file;
   749 	TInt err = file.Open(aFs, aFilename, EFileRead);
   793 	TInt err = file.Open(aFs, aFilename, EFileRead);
       
   794 	TheTest.Printf(_L("Open file aFilename=%S err = %d\r\n"), &aFilename, err);
   750 	TEST2(err, KErrNone);
   795 	TEST2(err, KErrNone);
   751 
   796 
   752 	TPtr8 ptr(reinterpret_cast<TUint8*>(const_cast<TUint16*>(aDes.Ptr())), aDes.MaxSize());
   797 	TPtr8 ptr(reinterpret_cast<TUint8*>(const_cast<TUint16*>(aDes.Ptr())), aDes.MaxSize());
   753 	err = file.Read(ptr);
   798 	err = file.Read(ptr);
       
   799 	TheTest.Printf(_L("Read file aFilename=%S err = %d\r\n"), &aFilename, err);
   754 	TEST2(err, KErrNone);
   800 	TEST2(err, KErrNone);
   755 	aDes.SetLength(ptr.Length() / sizeof(TText));
   801 	aDes.SetLength(ptr.Length() / sizeof(TText));
   756 	file.Close();
   802 	file.Close();
   757 	}
   803 	}
   758 
   804