persistentstorage/sql/TEST/t_sqllang.cpp
changeset 55 44f437012c90
parent 0 08ec8eefde2f
equal deleted inserted replaced
51:7d4490026038 55:44f437012c90
    42 void Check(TInt aValue, TInt aLine)
    42 void Check(TInt aValue, TInt aLine)
    43 	{
    43 	{
    44 	if(!aValue)
    44 	if(!aValue)
    45 		{
    45 		{
    46 		DeleteTestFiles();
    46 		DeleteTestFiles();
       
    47 		TheTest.Printf(_L("*** Expression evaluated to false\r\n"));
    47 		TheTest(EFalse, aLine);
    48 		TheTest(EFalse, aLine);
    48 		}
    49 		}
    49 	}
    50 	}
    50 void Check(TInt aValue, TInt aExpected, TInt aLine)
    51 void Check(TInt aValue, TInt aExpected, TInt aLine)
    51 	{
    52 	{
    52 	if(aValue != aExpected)
    53 	if(aValue != aExpected)
    53 		{
    54 		{
    54 		DeleteTestFiles();
    55 		DeleteTestFiles();
    55 		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
    56 		TheTest.Printf(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
    56 		TheTest(EFalse, aLine);
    57 		TheTest(EFalse, aLine);
    57 		}
    58 		}
    58 	}
    59 	}
    59 void Check2(TInt64 aValue, TInt64 aExpected, TInt aLine)
    60 void Check2(TInt64 aValue, TInt64 aExpected, TInt aLine)
    60 	{
    61 	{
    61 	if(aValue != aExpected)
    62 	if(aValue != aExpected)
    62 		{
    63 		{
    63 		DeleteTestFiles();
    64 		DeleteTestFiles();
    64 		RDebug::Print(_L("*** Expected error: %ld, got: %ld\r\n"), aExpected, aValue);
    65 		TheTest.Printf(_L("*** Expected error: %ld, got: %ld\r\n"), aExpected, aValue);
    65 		TheTest(EFalse, aLine);
    66 		TheTest(EFalse, aLine);
    66 		}
    67 		}
    67 	}
    68 	}
    68 #define TEST(arg) ::Check((arg), __LINE__)
    69 #define TEST(arg) ::Check((arg), __LINE__)
    69 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
    70 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
    88 void PrintLastMsgIfError(TInt aErr)
    89 void PrintLastMsgIfError(TInt aErr)
    89 	{
    90 	{
    90 	if(aErr < 0 && SqlRetCodeClass(aErr) == ESqlDbError)
    91 	if(aErr < 0 && SqlRetCodeClass(aErr) == ESqlDbError)
    91 		{
    92 		{
    92 		const TPtrC& msg = TheDb.LastErrorMessage();
    93 		const TPtrC& msg = TheDb.LastErrorMessage();
    93 		RDebug::Print(_L("Last error msg: \"%S\"\r\n"), &msg);	
    94 		TheTest.Printf(_L("Last error msg: \"%S\"\r\n"), &msg);	
    94 		}
    95 		}
    95 	}
    96 	}
    96 
    97 
    97 /**
    98 /**
    98 @SYMTestCaseID			SYSLIB-SQL-CT-1611
    99 @SYMTestCaseID			SYSLIB-SQL-CT-1611
   317 	err = stmt.Prepare(TheDb, _L("SELECT last_insert_rowid() AS F"));
   318 	err = stmt.Prepare(TheDb, _L("SELECT last_insert_rowid() AS F"));
   318 	TEST2(err, KErrNone);
   319 	TEST2(err, KErrNone);
   319 	err = stmt.Next();
   320 	err = stmt.Next();
   320 	TEST2(err, KSqlAtRow);
   321 	TEST2(err, KSqlAtRow);
   321 	TInt64 colVal64 = stmt.ColumnInt64(0);
   322 	TInt64 colVal64 = stmt.ColumnInt64(0);
   322 	RDebug::Print(_L("Last insert row id=%d\r\n"), (TInt)colVal64);
   323 	TheTest.Printf(_L("Last insert row id=%d\r\n"), (TInt)colVal64);
   323 	stmt.Close();
   324 	stmt.Close();
   324 
   325 
   325 	//length() test --------------------------------------------------------
   326 	//length() test --------------------------------------------------------
   326 	err = stmt.Prepare(TheDb, _L("SELECT length(F4) AS L FROM A WHERE ID >= 3"));
   327 	err = stmt.Prepare(TheDb, _L("SELECT length(F4) AS L FROM A WHERE ID >= 3"));
   327 	TEST2(err, KErrNone);
   328 	TEST2(err, KErrNone);
   440 	TEST2(err, KErrNone);
   441 	TEST2(err, KErrNone);
   441 	err = stmt.Next();
   442 	err = stmt.Next();
   442 	TEST2(err, KSqlAtRow);
   443 	TEST2(err, KSqlAtRow);
   443 	err = stmt.ColumnText(0, colVal);
   444 	err = stmt.ColumnText(0, colVal);
   444 	TEST2(err, KErrNone);
   445 	TEST2(err, KErrNone);
   445 	RDebug::Print(_L("Database engine version: \"%S\"\r\n"), &colVal);
   446 	TheTest.Printf(_L("Database engine version: \"%S\"\r\n"), &colVal);
   446 	stmt.Close();
   447 	stmt.Close();
   447 
   448 
   448 	//substr() test --------------------------------------------------------
   449 	//substr() test --------------------------------------------------------
   449 	err = stmt.Prepare(TheDb, _L("SELECT SUBSTR('abcd', 2, 2) AS S"));
   450 	err = stmt.Prepare(TheDb, _L("SELECT SUBSTR('abcd', 2, 2) AS S"));
   450 	TEST2(err, KErrNone);
   451 	TEST2(err, KErrNone);