persistentstorage/sql/TEST/t_sqlapi2.cpp
changeset 29 cce6680bbf1c
parent 15 3eacc0623088
child 55 44f437012c90
equal deleted inserted replaced
28:7a522c0700d3 29:cce6680bbf1c
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
   975 	TRAP(err, strm5.OpenL(TheDb, KNullDesC, KNullDesC, 1, KNullDesC));
   975 	TRAP(err, strm5.OpenL(TheDb, KNullDesC, KNullDesC, 1, KNullDesC));
   976 	TEST(err != KErrNone);
   976 	TEST(err != KErrNone);
   977 	//Attempt to open a read blob stream with a set of KNullDesC database/table/column names.
   977 	//Attempt to open a read blob stream with a set of KNullDesC database/table/column names.
   978 	RSqlBlobReadStream strm6;
   978 	RSqlBlobReadStream strm6;
   979 	TRAP(err, strm6.OpenL(TheDb, KNullDesC, KNullDesC, 1, KNullDesC));
   979 	TRAP(err, strm6.OpenL(TheDb, KNullDesC, KNullDesC, 1, KNullDesC));
       
   980 	TEST(err != KErrNone);
       
   981 	//Attempt to open a read blob stream, where the blob column name is invalid and contains non-convertible characters.
       
   982     TBuf<3> invName;
       
   983     invName.SetLength(3);
       
   984     invName[0] = TChar(0xD800); 
       
   985     invName[1] = TChar(0xFC00); 
       
   986     invName[2] = TChar(0x0000);
       
   987 	RSqlBlobReadStream strm7;
       
   988 	TRAP(err, strm7.OpenL(TheDb,  _L("A"), invName, 1, KNullDesC));
       
   989 	TEST(err != KErrNone);
       
   990 	//Attempt to open a read blob stream, where the table name is invalid and contains non-convertible characters.
       
   991 	RSqlBlobReadStream strm8;
       
   992 	TRAP(err, strm8.OpenL(TheDb, invName, _L("Data"), 1, KNullDesC));
       
   993 	TEST(err != KErrNone);
       
   994 	//Attempt to open a read blob stream, where the attached db name is invalid and contains non-convertible characters.
       
   995 	RSqlBlobReadStream strm9;
       
   996 	TRAP(err, strm9.OpenL(TheDb, _L("A"), _L("Data"), 1, invName));
   980 	TEST(err != KErrNone);
   997 	TEST(err != KErrNone);
   981 	//
   998 	//
   982 	err = TheDb.Detach(KAttachDb);
   999 	err = TheDb.Detach(KAttachDb);
   983 	TEST2(err, KErrNone);
  1000 	TEST2(err, KErrNone);
   984 	TheDb.Close();
  1001 	TheDb.Close();
  1695 		TheTest.Printf(_L("  The test has succeeded with SELECT statement count=%d\r\n"), cnt);
  1712 		TheTest.Printf(_L("  The test has succeeded with SELECT statement count=%d\r\n"), cnt);
  1696 		break;
  1713 		break;
  1697 		}
  1714 		}
  1698 	}
  1715 	}
  1699 
  1716 
       
  1717 /**
       
  1718 @SYMTestCaseID			PDS-SQL-CT-4198
       
  1719 @SYMTestCaseDesc		Expired SQL statements test.
       
  1720 						The test creates a database and opens 2 connections to that database.
       
  1721 						Connection 2 prepares couple of SELECT and INSERT statements (8-bit and 16-bit).
       
  1722 						Then connection 1 renames the table used in the already prepared statements.
       
  1723 						Connection 2 attempts to execute the prepared statements. The execution should fail
       
  1724 						because the database schema has changed after they were prepared.
       
  1725 @SYMTestActions			Expired SQL statements test.
       
  1726 @SYMTestExpectedResults Test must not fail
       
  1727 @SYMTestPriority		High
       
  1728 @SYMDEF					DEF145236
       
  1729 */
       
  1730 void ExpiredStmtTest()
       
  1731 	{
       
  1732 	(void)RSqlDatabase::Delete(KTestDbName1);
       
  1733 	//Create a database and create db connection 1.
       
  1734 	TInt err = TheDb.Create(KTestDbName1);
       
  1735 	TEST2(err, KErrNone);
       
  1736 	err = TheDb.Exec(_L("CREATE TABLE A(C1 INTEGER)"));
       
  1737 	TEST(err >= 0);
       
  1738 	err = TheDb.Exec(_L("INSERT INTO A(C1) VALUES(1)"));
       
  1739 	TEST2(err, 1);
       
  1740 	
       
  1741 	//Create db connection 2 to the same database, as db connection 1.
       
  1742 	RSqlDatabase db2;
       
  1743 	err = db2.Open(KTestDbName1);
       
  1744 	TEST2(err, KErrNone);
       
  1745 	
       
  1746 	//Db connection 2. Prepare SELECT and INSERT, 8-bit and 16-bit statements. 
       
  1747 	RSqlStatement stmt1, stmt2, stmt3, stmt4;
       
  1748 	err = stmt1.Prepare(db2, _L("SELECT * FROM A"));
       
  1749 	TEST2(err, KErrNone);
       
  1750 	err = stmt2.Prepare(db2, _L8("SELECT * FROM A"));
       
  1751 	TEST2(err, KErrNone);
       
  1752 	err = stmt3.Prepare(db2, _L("INSERT INTO A(C1) VALUES(2)"));
       
  1753 	TEST2(err, KErrNone);
       
  1754 	err = stmt4.Prepare(db2, _L8("INSERT INTO A(C1) VALUES(3)"));
       
  1755 	TEST2(err, KErrNone);
       
  1756 	
       
  1757 	//Modify the A table structure from the other connection
       
  1758 	//err = TheDb.Exec(_L("ALTER TABLE A ADD C2 INTEGER"));
       
  1759 	err = TheDb.Exec(_L("ALTER TABLE A RENAME TO B"));
       
  1760 	TEST(err >= 0);
       
  1761 	
       
  1762 	//Try to execute the already prepared statements.
       
  1763 	err = stmt1.Next();
       
  1764 	TEST2(err, KSqlErrSchema);
       
  1765 	err = stmt1.Next();
       
  1766 	TEST(err != KSqlAtRow);
       
  1767 	err = stmt2.Next();
       
  1768 	TEST(err != KSqlAtRow);
       
  1769 	err = stmt3.Exec();
       
  1770 	TEST(err < 0);
       
  1771 	err = stmt4.Exec();
       
  1772 	TEST(err < 0);
       
  1773 	//
       
  1774 	stmt4.Close();
       
  1775 	stmt3.Close();
       
  1776 	stmt2.Close();
       
  1777 	stmt1.Close();
       
  1778 	db2.Close();
       
  1779 	TheDb.Close();
       
  1780 	err = RSqlDatabase::Delete(KTestDbName1);
       
  1781 	TEST2(err, KErrNone);
       
  1782 	}
       
  1783 
  1700 void DoTestsL()
  1784 void DoTestsL()
  1701 	{
  1785 	{
  1702 	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3512 RSqlStatement::ColumnCount() tests "));
  1786 	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3512 RSqlStatement::ColumnCount() tests "));
  1703 	ColumnCountTest();
  1787 	ColumnCountTest();
  1704 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3513 RSqlStatement::ColumnCount(), non-SELECT tests "));
  1788 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3513 RSqlStatement::ColumnCount(), non-SELECT tests "));
  1733 	BoundParameterValuesTest5();
  1817 	BoundParameterValuesTest5();
  1734 	TheTest.Next( _L(" @SYMTestCaseID:SYSLIB-SQL-UT-4088 TSqlResourceProfiler - file I/O and configuration test"));
  1818 	TheTest.Next( _L(" @SYMTestCaseID:SYSLIB-SQL-UT-4088 TSqlResourceProfiler - file I/O and configuration test"));
  1735 	ProfilerTest();
  1819 	ProfilerTest();
  1736 	TheTest.Next( _L(" Compound SELECT, stack overflow test"));
  1820 	TheTest.Next( _L(" Compound SELECT, stack overflow test"));
  1737 	CompoundSelectStackOverflowTest();
  1821 	CompoundSelectStackOverflowTest();
       
  1822 	TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4198 Expired statements test"));
       
  1823 	ExpiredStmtTest();
  1738 	}
  1824 	}
  1739 
  1825 
  1740 TInt E32Main()
  1826 TInt E32Main()
  1741 	{
  1827 	{
  1742 	TheTest.Title();
  1828 	TheTest.Title();