persistentstorage/sql/TEST/t_sqlattach2.cpp
changeset 0 08ec8eefde2f
child 55 44f437012c90
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 2008-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 // Note: Only runs on hardware as you cannot remove MMC card on emulator
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32test.h>
       
    19 #include <bautils.h>
       
    20 #include <s32stor.h>
       
    21 #include <sqldb.h>
       
    22 
       
    23 ///////////////////////////////////////////////////////////////////////////////////////
       
    24 
       
    25 static RFs TheFs;
       
    26 RTest TheTest(_L("t_sqlattach2 test"));
       
    27 RSqlDatabase TheDb;
       
    28 RSqlDatabase TheDb2;
       
    29 _LIT(KTestMMCDir, "c:\\test\\");
       
    30 _LIT(KTestDir, "E:\\test\\");
       
    31 _LIT(KTestDatabase1, "c:\\test\\t_sqlattach2_1.db");
       
    32 _LIT(KTestMMCDatabase1, "E:\\test\\t_sqlattach2_2.db");
       
    33 _LIT(KTestMMCDatabase2, "E:\\test\\t_sqlattach2_3.db");
       
    34 
       
    35 
       
    36 _LIT(KTxtInsertMMCTxt," Insert MMC card\r\n");
       
    37 _LIT(KTxtRemoveMMCTxt," Remove MMC card\r\n");
       
    38 _LIT(KTxtPressAnyKey," [press any key to continue]\r\n");
       
    39 _LIT(KTxtDefectTitle,"DEF116630  SQL, Missing test scenario: Open db, attach db on external media, remove media");
       
    40 
       
    41 
       
    42 ///////////////////////////////////////////////////////////////////////////////////////
       
    43 ///////////////////////////////////////////////////////////////////////////////////////
       
    44 //Test macros and functions
       
    45 void Check1(TInt aValue, TInt aLine)
       
    46 	{
       
    47 	if(!aValue)
       
    48 		{
       
    49 		RDebug::Print(_L("*** Line %d\r\n"), aLine);
       
    50 		TheTest(EFalse, aLine);
       
    51 		}
       
    52 	}
       
    53 void Check2(TInt aValue, TInt aExpected, TInt aLine)
       
    54 	{
       
    55 	if(aValue != aExpected)
       
    56 		{
       
    57 		RDebug::Print(_L("*** Line %d, Expected error: %d, got: %d\r\n"), aLine, aExpected, aValue);
       
    58 		TheTest(EFalse, aLine);
       
    59 		}
       
    60 	}
       
    61 #define TEST(arg) ::Check1((arg), __LINE__)
       
    62 #define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__)
       
    63 
       
    64 ///////////////////////////////////////////////////////////////////////////////////////
       
    65 
       
    66 //Creates file session instance and the test directory
       
    67 void CreateTestEnv()
       
    68     {
       
    69 	TInt err = TheFs.Connect();
       
    70 	TEST2(err, KErrNone);
       
    71 
       
    72 	err = TheFs.MkDir(KTestDir);
       
    73 	TEST(err == KErrNone || err == KErrAlreadyExists);
       
    74 	err = TheFs.MkDir(KTestMMCDir);
       
    75 	TEST(err == KErrNone || err == KErrAlreadyExists);
       
    76 	}
       
    77 
       
    78 
       
    79 /**
       
    80 @SYMTestCaseID			SYSLIB-SQL-CT-4021
       
    81 @SYMTestCaseDesc		Determine the result of union select operations on an external media located attached database
       
    82 						when the external media is removed.
       
    83 @SYMTestPriority		Medium
       
    84 
       
    85 @SYMTestActions			Create database one on internal media and database two on external media.
       
    86 						Insert records into both databases.
       
    87 						Attach database two which resides on MMC card to database one.
       
    88 						Prepare a union SELECT sql statement1 to retrieve records from the internal and attached database with database two listed before database one.
       
    89 						Prepare a union SELECT sql statement2 to retrieve records from the internal and attached database with database one listed before database two
       
    90 						Pauses and prompts the removal of the MMC card.
       
    91 						Exec union select statement1 across databases.
       
    92 						Exec union select statement2 across databases.
       
    93 
       
    94 @SYMTestExpectedResults Databases are created and populated successfully.
       
    95 						Database are attached sucessfully.
       
    96 						Union statement1 operations return KErrNotReady
       
    97 						Union statement2 operations return one record from internal database.
       
    98 @SYMDEF					DEF116630
       
    99 */
       
   100 void SqlAttachMMCDb2InternalDbUnionTestL()
       
   101 	{
       
   102 
       
   103 	CConsoleBase* console=Console::NewL(KTxtDefectTitle,TSize(KConsFullScreen,KConsFullScreen));
       
   104 	CleanupStack::PushL(console);
       
   105 	console->Printf(KTxtInsertMMCTxt);
       
   106 	console->Printf(KTxtPressAnyKey);
       
   107 	console->Getch(); // get and ignore character
       
   108 
       
   109 	//Initially remove any preexisting database;
       
   110 	(void)RSqlDatabase::Delete(KTestMMCDatabase1);
       
   111 	(void)RSqlDatabase::Delete(KTestDatabase1);
       
   112 
       
   113 	TInt err = TheDb.Create(KTestDatabase1);
       
   114 	TEST2(err, KErrNone);
       
   115 	err = TheDb.Exec(_L8("CREATE TABLE A(Id INTEGER)"));
       
   116 	TEST(err >= 0);
       
   117 	err = TheDb.Exec(_L8("INSERT INTO A(Id) VALUES(1)"));
       
   118 	TEST2(err, 1);
       
   119 	err = TheDb.Exec(_L8("INSERT INTO A(Id) VALUES(2)"));
       
   120 	TEST2(err, 1);
       
   121 	TheDb.Close();
       
   122 
       
   123 	err = TheDb.Create(KTestMMCDatabase1);
       
   124 	TEST2(err, KErrNone);
       
   125 	err = TheDb.Exec(_L8("CREATE TABLE B(N INTEGER)"));
       
   126 	TEST(err >= 0);
       
   127 	err = TheDb.Exec(_L8("INSERT INTO B(N) VALUES(10)"));
       
   128 	TEST2(err, 1);
       
   129 	err = TheDb.Exec(_L8("INSERT INTO B(N) VALUES(20)"));
       
   130 	TEST2(err, 1);
       
   131 	err = TheDb.Exec(_L8("INSERT INTO B(N) VALUES(30)"));
       
   132 	TEST2(err, 1);
       
   133 	err = TheDb.Exec(_L8("INSERT INTO B(N) VALUES(40)"));
       
   134 	TEST2(err, 1);
       
   135 	TheDb.Close();
       
   136 
       
   137 	err = TheDb.Open(KTestDatabase1);
       
   138 	TEST2(err, KErrNone);
       
   139 	err = TheDb.Attach(KTestMMCDatabase1, _L("Db2"));
       
   140 	TEST2(err, KErrNone);
       
   141 
       
   142 	RSqlStatement stmt;
       
   143 	err = stmt.Prepare(TheDb, _L8("SELECT * FROM B union all Select * from A"));
       
   144 	TEST2(err, KErrNone);
       
   145 
       
   146 	RSqlStatement stmt2;
       
   147 	err = stmt2.Prepare(TheDb, _L8("SELECT * FROM A union all Select * from B"));
       
   148 	TEST2(err, KErrNone);
       
   149 
       
   150 	console->Printf(KTxtRemoveMMCTxt);
       
   151 	console->Printf(KTxtPressAnyKey);
       
   152 	console->Getch(); // get and ignore character
       
   153 
       
   154 	err = stmt.Next();
       
   155 	TEST2(err, KSqlAtRow);
       
   156 	stmt.Close();
       
   157 
       
   158 	err = stmt2.Next();
       
   159 	TEST2(err, KSqlAtRow);
       
   160 	stmt2.Close();
       
   161 
       
   162 	err = TheDb.Detach(_L("Db2"));
       
   163 	TEST2(err, KErrNone);
       
   164 
       
   165 	TheDb.Close();
       
   166 
       
   167 	CleanupStack::PopAndDestroy(); // close console
       
   168 	(void)RSqlDatabase::Delete(KTestDatabase1);
       
   169 	}
       
   170 
       
   171 
       
   172 /**
       
   173 @SYMTestCaseID			SYSLIB-SQL-CT-4022
       
   174 @SYMTestCaseDesc		Determine the result of operations on an external media located attached database
       
   175 						when the external media is removed.
       
   176 
       
   177 @SYMTestPriority		Medium
       
   178 @SYMTestActions			Create database one on internal media and database two on external media.
       
   179 						Insert records into both databases.
       
   180 						Attach database two which resides on MMC card to database one.
       
   181 						Prepare a SELECT sql statement to retrieve records from the attached database two.
       
   182 						Retrieve a record from database 2.
       
   183 						Pauses and prompts the removal of the MMC card.
       
   184 						Attempt to insert two records into database two.
       
   185 						Prepare a SELECT sql statement to retrieve records from the attached database one.
       
   186 						Attempt to select a record from dabase one.
       
   187 						Attempt to insert record into database one.
       
   188 						Reinsert the MMC card.
       
   189 						Attempt to insert record in database one.
       
   190 						Attempt to insert a record in database two.
       
   191 
       
   192 @SYMTestExpectedResults Databases are created and populated successfully.
       
   193 						Database are attached sucessfully.
       
   194 						Select operations on database one are successful
       
   195 						After MMC removal
       
   196 						Disk write for database two return KErrNotReady.
       
   197 						Select operations on database two are successful
       
   198 						Select operations on database one are successful
       
   199 						Write operations for database one are successful.
       
   200 						After MMC re-insert
       
   201 						Inserting a record into database one are succesful.
       
   202 						Inserting a record into database two are successful
       
   203 
       
   204 @SYMDEF					DEF116630
       
   205 */
       
   206 void SqlAttachMMCDb2InternalDbTestL()
       
   207 	{
       
   208 
       
   209 	CConsoleBase* console=Console::NewL(KTxtDefectTitle,TSize(KConsFullScreen,KConsFullScreen));
       
   210 	CleanupStack::PushL(console);
       
   211 	console->Printf(KTxtInsertMMCTxt);
       
   212 	console->Printf(KTxtPressAnyKey);
       
   213 	console->Getch(); // get and ignore character
       
   214 
       
   215 	//Initially remove any preexisting database;
       
   216 	(void)RSqlDatabase::Delete(KTestMMCDatabase1);
       
   217 	(void)RSqlDatabase::Delete(KTestDatabase1);
       
   218 
       
   219 	TInt err = TheDb.Create(KTestDatabase1);
       
   220 	TEST2(err, KErrNone);
       
   221 	err = TheDb.Exec(_L8("CREATE TABLE A(Id INTEGER)"));
       
   222 	TEST(err >= 0);
       
   223 	err = TheDb.Exec(_L8("INSERT INTO A(Id) VALUES(1)"));
       
   224 	TEST2(err, 1);
       
   225 	err = TheDb.Exec(_L8("INSERT INTO A(Id) VALUES(2)"));
       
   226 	TEST2(err, 1);
       
   227 	TheDb.Close();
       
   228 
       
   229 	err = TheDb.Create(KTestMMCDatabase1);
       
   230 	TEST2(err, KErrNone);
       
   231 	err = TheDb.Exec(_L8("CREATE TABLE B(N INTEGER)"));
       
   232 	TEST(err >= 0);
       
   233 	err = TheDb.Exec(_L8("INSERT INTO B(N) VALUES(10)"));
       
   234 	TEST2(err, 1);
       
   235 	err = TheDb.Exec(_L8("INSERT INTO B(N) VALUES(20)"));
       
   236 	TEST2(err, 1);
       
   237 	err = TheDb.Exec(_L8("INSERT INTO B(N) VALUES(30)"));
       
   238 	TEST2(err, 1);
       
   239 	err = TheDb.Exec(_L8("INSERT INTO B(N) VALUES(40)"));
       
   240 	TEST2(err, 1);
       
   241 	TheDb.Close();
       
   242 
       
   243 	err = TheDb.Open(KTestDatabase1);
       
   244 	TEST2(err, KErrNone);
       
   245 	err = TheDb.Attach(KTestMMCDatabase1, _L("Db2"));
       
   246 	TEST2(err, KErrNone);
       
   247 
       
   248 	RSqlStatement stmt;
       
   249 	err = stmt.Prepare(TheDb, _L8("SELECT * FROM B"));
       
   250 	TEST2(err, KErrNone);
       
   251 
       
   252 	err = stmt.Next();
       
   253 	TEST2(err, KSqlAtRow);
       
   254 
       
   255 	console->Printf(KTxtRemoveMMCTxt);
       
   256 	console->Printf(KTxtPressAnyKey);
       
   257 	console->Getch(); // get and ignore character
       
   258 
       
   259 	err = stmt.Next();
       
   260 	TEST2(err, KSqlAtRow);
       
   261 
       
   262 	err = TheDb.Exec(_L8("INSERT INTO B(N) VALUES(40)"));
       
   263 	TEST2(err, KErrNotReady);
       
   264 
       
   265 
       
   266 	err = TheDb.Exec(_L8("INSERT INTO B(N) VALUES(50)"));
       
   267 	TEST2(err, KErrNotReady);
       
   268 
       
   269 
       
   270 	err = stmt.Next();
       
   271 	TEST2(err, KSqlAtRow);
       
   272 	stmt.Close();
       
   273 //Check that you can still perform operations on internal media based database
       
   274 	RSqlStatement stmt2;
       
   275 	err = stmt2.Prepare(TheDb, _L8("SELECT * FROM A"));
       
   276 	TEST2(err, KErrNone);
       
   277 	err = stmt2.Next();
       
   278 	TEST2(err, KSqlAtRow);
       
   279 
       
   280 	err = TheDb.Exec(_L8("INSERT INTO A(Id) VALUES(40)"));
       
   281 	TEST2(err, 1);
       
   282 
       
   283 	err = stmt2.Next();
       
   284 	TEST2(err, KSqlAtRow);
       
   285 	stmt2.Close();
       
   286 
       
   287 	//Check that databases start working again when mmc card reinserted.
       
   288 	console->Printf(KTxtInsertMMCTxt);
       
   289 	console->Printf(KTxtPressAnyKey);
       
   290 	console->Getch(); // get and ignore character
       
   291 
       
   292 	err = TheDb.Detach(_L("Db2"));
       
   293 	TEST2(err, KErrNone);
       
   294 
       
   295 	TheDb.Close();
       
   296 
       
   297 	err = TheDb2.Open(KTestDatabase1);
       
   298 	TEST2(err, KErrNone);
       
   299 	err = TheDb2.Attach(KTestMMCDatabase1, _L("Db2"));
       
   300 	TEST2(err, KErrNone);
       
   301 
       
   302 
       
   303 	err = TheDb2.Exec(_L8("INSERT INTO A(Id) VALUES(50)"));
       
   304 	TEST2(err, 1);
       
   305 	err = TheDb2.Exec(_L8("INSERT INTO B(N) VALUES(50)"));
       
   306 	TEST2(err, 1);
       
   307 
       
   308 	err = TheDb2.Detach(_L("Db2"));
       
   309 	TEST2(err, KErrNone);
       
   310 
       
   311 	TheDb2.Close();
       
   312 	CleanupStack::PopAndDestroy(); // close console
       
   313 	(void)RSqlDatabase::Delete(KTestMMCDatabase1);
       
   314 	(void)RSqlDatabase::Delete(KTestDatabase1);
       
   315 	}
       
   316 
       
   317 /**
       
   318 @SYMTestCaseID			SYSLIB-SQL-CT-4023
       
   319 @SYMTestCaseDesc		Determine the result of multiple disk write operations on an internal and
       
   320 						external media located database when the attached external media is removed.
       
   321 @SYMTestPriority		Medium
       
   322 
       
   323 @SYMTestActions			Create database 1 on internal media and database two on external media.
       
   324 						Insert records into both databases.
       
   325 						Attaches database 2 which resides on MMC card to database 1.
       
   326 						Prepare a SELECT sql statement to retrieve records from database 1.
       
   327 						Retrieve a record from database 1.
       
   328 						Pause and prompts the removal of the MMC card.
       
   329 						Attempt to insert a record into database one.
       
   330 						Attempt to select records from dabase one.
       
   331 						Attempt to prepare a select statement on database two.
       
   332 						Attempt to retrieve a record from database two.
       
   333 						Attempts to insert record into database two.
       
   334 @SYMTestExpectedResults Databases are created and populated successfully.
       
   335 						Database are attached sucessfully.
       
   336 						Prepare and select operations on database one are successful
       
   337 						MMC Removed
       
   338 						Write operations on database one are successful.
       
   339 						Select operations on database one are successful.
       
   340 						Prepare statement on database two are successful
       
   341 						Disk read/write operations on database two return KErrNotReady.
       
   342 
       
   343 @SYMDEF					DEF116630
       
   344 */
       
   345 void SqlAttachMMCDb2InternalDbAndDoDiskOpsTestL()
       
   346 	{
       
   347 
       
   348 	CConsoleBase* console=Console::NewL(KTxtDefectTitle,TSize(KConsFullScreen,KConsFullScreen));
       
   349 	CleanupStack::PushL(console);
       
   350 	console->Printf(KTxtInsertMMCTxt);
       
   351 	console->Printf(KTxtPressAnyKey);
       
   352 	console->Getch(); // get and ignore character
       
   353 
       
   354 	//Initially remove any preexisting database;
       
   355 	(void)RSqlDatabase::Delete(KTestMMCDatabase1);
       
   356 	(void)RSqlDatabase::Delete(KTestDatabase1);
       
   357 
       
   358 	TInt err = TheDb.Create(KTestDatabase1);
       
   359 	TEST2(err, KErrNone);
       
   360 	err = TheDb.Exec(_L8("CREATE TABLE A(Id INTEGER)"));
       
   361 	TEST(err >= 0);
       
   362 	err = TheDb.Exec(_L8("INSERT INTO A(Id) VALUES(1)"));
       
   363 	TEST2(err, 1);
       
   364 	err = TheDb.Exec(_L8("INSERT INTO A(Id) VALUES(2)"));
       
   365 	TEST2(err, 1);
       
   366 	TheDb.Close();
       
   367 
       
   368 	err = TheDb.Create(KTestMMCDatabase1);
       
   369 	TEST2(err, KErrNone);
       
   370 	err = TheDb.Exec(_L8("CREATE TABLE B(N INTEGER)"));
       
   371 	TEST(err >= 0);
       
   372 	err = TheDb.Exec(_L8("INSERT INTO B(N) VALUES(10)"));
       
   373 	TEST2(err, 1);
       
   374 	err = TheDb.Exec(_L8("INSERT INTO B(N) VALUES(20)"));
       
   375 	TEST2(err, 1);
       
   376 	err = TheDb.Exec(_L8("INSERT INTO B(N) VALUES(30)"));
       
   377 	TEST2(err, 1);
       
   378 	TheDb.Close();
       
   379 
       
   380 	err = TheDb.Open(KTestDatabase1);
       
   381 	TEST2(err, KErrNone);
       
   382 	err = TheDb.Attach(KTestMMCDatabase1, _L("Db2"));
       
   383 	TEST2(err, KErrNone);
       
   384 
       
   385 	RSqlStatement stmt;
       
   386 	err = stmt.Prepare(TheDb, _L8("SELECT * FROM A"));
       
   387 	TEST2(err, KErrNone);
       
   388 	err = stmt.Next();
       
   389 	TEST2(err, KSqlAtRow);
       
   390 
       
   391 	console->Printf(KTxtRemoveMMCTxt);
       
   392 	console->Printf(KTxtPressAnyKey);
       
   393 	console->Getch(); // get and ignore character
       
   394 
       
   395 	err = TheDb.Exec(_L8("INSERT INTO A(Id) VALUES(40)"));
       
   396 	TEST2(err, 1);
       
   397 
       
   398 	err = stmt.Next();
       
   399 	TEST2(err, KSqlAtRow);
       
   400 
       
   401 	stmt.Close();
       
   402 
       
   403 //Check that you can still perform operations on external media based database
       
   404 	RSqlStatement stmt2;
       
   405 	err = stmt2.Prepare(TheDb, _L8("SELECT * FROM B"));
       
   406 	TEST2(err, KErrNone);
       
   407 	err = stmt2.Next();
       
   408 	TEST2(err,KSqlAtRow);
       
   409 
       
   410 	stmt2.Close();
       
   411 
       
   412 	err = TheDb.Exec(_L8("INSERT INTO B(N) VALUES(40)"));
       
   413 	TEST2(err, KErrNotReady);
       
   414 
       
   415 	err = TheDb.Detach(_L("Db2"));
       
   416 	TEST2(err, KErrNone);
       
   417 
       
   418 	TheDb.Close();
       
   419 	CleanupStack::PopAndDestroy(); // close console
       
   420 	(void)RSqlDatabase::Delete(KTestDatabase1);
       
   421 	}
       
   422 
       
   423 /**
       
   424 @SYMTestCaseID			SYSLIB-SQL-CT-4024
       
   425 @SYMTestCaseDesc		Determine the result of operations on an internal media located attached database
       
   426 						to a external media database
       
   427 						when the external media is removed.
       
   428 @SYMTestPriority		Medium
       
   429 
       
   430 @SYMTestActions			Create database 1 on internal media and database two on external media.
       
   431 						Insert records into both databases.
       
   432 						Attempt to Attach database 1 to database two which resides on MMC card.
       
   433 						Attempt to Prepare a SELECT statement to retrieve records from the attached database 2.
       
   434 						Attempt to retrieve record from database two.
       
   435 						Pause and prompts the removal of the MMC card.
       
   436 						Attempt to SELECT a record from database two.
       
   437 						Attempt to insert a record into database two.
       
   438 						Attempt to SELECT a record from database two.
       
   439 						Attempt to prepare a select statement on database one.
       
   440 						Attempt to select records from dabase one.
       
   441 						Attempt to insert record into database one.
       
   442 
       
   443 @SYMTestExpectedResults Databases are created and populated successfully.
       
   444 						Database are attached sucessfully.
       
   445 						Select operations on database two are successful
       
   446 						MMC Removed
       
   447 						Select operation on database two is successful
       
   448 						Operations involving a disk write for database 2 return KErrNotReady.
       
   449 						Select operation on database two is successful
       
   450 						Prepare select operations on database on is successful
       
   451 						Select operations on database one are successful
       
   452 						Insert operations on database one are successful
       
   453 @SYMDEF					DEF116630
       
   454 */
       
   455 void SqlAttachInternalDb2MMCDbTestL()
       
   456 	{
       
   457 
       
   458 	CConsoleBase* console=Console::NewL(KTxtDefectTitle,TSize(KConsFullScreen,KConsFullScreen));
       
   459 	CleanupStack::PushL(console);
       
   460 	console->Printf(KTxtInsertMMCTxt);
       
   461 	console->Printf(KTxtPressAnyKey);
       
   462 	console->Getch(); // get and ignore character
       
   463 
       
   464 	//Initially remove any preexisting database;
       
   465 	(void)RSqlDatabase::Delete(KTestMMCDatabase1);
       
   466 	(void)RSqlDatabase::Delete(KTestDatabase1);
       
   467 
       
   468 	TInt err = TheDb.Create(KTestDatabase1);
       
   469 	TEST2(err, KErrNone);
       
   470 	err = TheDb.Exec(_L8("CREATE TABLE A(Id INTEGER)"));
       
   471 	TEST(err >= 0);
       
   472 	err = TheDb.Exec(_L8("INSERT INTO A(Id) VALUES(1)"));
       
   473 	TEST2(err, 1);
       
   474 	err = TheDb.Exec(_L8("INSERT INTO A(Id) VALUES(2)"));
       
   475 	TEST2(err, 1);
       
   476 	TheDb.Close();
       
   477 
       
   478 	err = TheDb.Create(KTestMMCDatabase1);
       
   479 	TEST2(err, KErrNone);
       
   480 	err = TheDb.Exec(_L8("CREATE TABLE B(N INTEGER)"));
       
   481 	TEST(err >= 0);
       
   482 	err = TheDb.Exec(_L8("INSERT INTO B(N) VALUES(10)"));
       
   483 	TEST2(err, 1);
       
   484 	err = TheDb.Exec(_L8("INSERT INTO B(N) VALUES(20)"));
       
   485 	TEST2(err, 1);
       
   486 	err = TheDb.Exec(_L8("INSERT INTO B(N) VALUES(30)"));
       
   487 	TEST2(err, 1);
       
   488 	TheDb.Close();
       
   489 
       
   490 	err = TheDb.Open(KTestMMCDatabase1);
       
   491 	TEST2(err, KErrNone);
       
   492 	err = TheDb.Attach(KTestDatabase1, _L("Db2"));
       
   493 	TEST2(err, KErrNone);
       
   494 
       
   495 	RSqlStatement stmt;
       
   496 	err = stmt.Prepare(TheDb, _L8("SELECT * FROM B"));
       
   497 	TEST2(err, KErrNone);
       
   498 	err = stmt.Next();
       
   499 	TEST2(err, KSqlAtRow);
       
   500 
       
   501 	console->Printf(KTxtRemoveMMCTxt);
       
   502 	console->Printf(KTxtPressAnyKey);
       
   503 	console->Getch(); // get and ignore character
       
   504 
       
   505 	err = stmt.Next();
       
   506 	TEST2(err, KSqlAtRow);
       
   507 
       
   508 	err = TheDb.Exec(_L8("INSERT INTO B(N) VALUES(40)"));
       
   509 	TEST2(err, KErrNotReady);
       
   510 
       
   511 	err = stmt.Next();
       
   512 	TEST2(err, KSqlAtRow);
       
   513 	stmt.Close();
       
   514 
       
   515 //Check that you can still perform operations on internal media based database
       
   516 	RSqlStatement stmt2;
       
   517 	err = stmt2.Prepare(TheDb, _L8("SELECT * FROM A"));
       
   518 	TEST2(err, KErrNone);
       
   519 	err = stmt2.Next();
       
   520 	TEST2(err, KSqlAtRow);
       
   521 
       
   522 	err = TheDb.Exec(_L8("INSERT INTO A(Id) VALUES(40)"));
       
   523 	TEST2(err, 1);
       
   524 
       
   525 	err = stmt2.Next();
       
   526 	TEST2(err, KSqlAtRow);
       
   527 	stmt2.Close();
       
   528 
       
   529 	err = TheDb.Detach(_L("Db2"));
       
   530 	TEST2(err, KErrNone);
       
   531 
       
   532 	TheDb.Close();
       
   533 	CleanupStack::PopAndDestroy(); // close console
       
   534 	(void)RSqlDatabase::Delete(KTestDatabase1);
       
   535 	}
       
   536 
       
   537 /**
       
   538 @SYMTestCaseID			SYSLIB-SQL-CT-4025
       
   539 @SYMTestCaseDesc		Determine the result of operations on an external media located attached database
       
   540 						to another external media database when the external media is removed.
       
   541 @SYMTestPriority		Medium
       
   542 @SYMTestActions			Create database one and database two on external media.
       
   543 						Insert records into both databases.
       
   544 						Attach database two to database one
       
   545 						Prepare a select statement on database two.
       
   546 						Retrieve a record from database two.
       
   547 						Pause and prompts the removal of the MMC card.
       
   548 						Retrieve a record from database two.
       
   549 						Attempt to insert a record into database two.
       
   550 						Attempt to insert another record into database two.
       
   551 						Retrieve a record from database two.
       
   552 						Prepare a select statement on database one.
       
   553 						Attempt to retrieve record from database one.
       
   554 						Attempt to insert a record into database one.
       
   555 						Attempt to retrieve record from database one.
       
   556 
       
   557 @SYMTestExpectedResults Databases are created and populated successfully.
       
   558 						Database are attached sucessfully.
       
   559 						Select operations on database two are successful
       
   560 						MMC Removed.
       
   561 						Read operations are successful on database two.
       
   562 						First Insert operation return KErrNotReady for database two.
       
   563 						Second Insert operation return KErrNotReady for database two.
       
   564 						Read operations are still successful on database two.
       
   565 						Read operations are still successful on database one.
       
   566 						Insert operation returns KErrNotReady.
       
   567 						Read operations are still successful on database one.
       
   568 @SYMDEF				DEF116630
       
   569 */
       
   570 void SqlAttachMMCDb12MMCDb2TestL()
       
   571 	{
       
   572 
       
   573 	CConsoleBase* console=Console::NewL(KTxtDefectTitle,TSize(KConsFullScreen,KConsFullScreen));
       
   574 	CleanupStack::PushL(console);
       
   575 	console->Printf(KTxtInsertMMCTxt);
       
   576 	console->Printf(KTxtPressAnyKey);
       
   577 	console->Getch(); // get and ignore character
       
   578 
       
   579 	//Initially remove any preexisting database;
       
   580 	(void)RSqlDatabase::Delete(KTestMMCDatabase1);
       
   581 	(void)RSqlDatabase::Delete(KTestMMCDatabase2);
       
   582 
       
   583 	TInt err = TheDb.Create(KTestMMCDatabase1);
       
   584 	TEST2(err, KErrNone);
       
   585 	err = TheDb.Exec(_L8("CREATE TABLE A(Id INTEGER)"));
       
   586 	TEST(err >= 0);
       
   587 	err = TheDb.Exec(_L8("INSERT INTO A(Id) VALUES(1)"));
       
   588 	TEST2(err, 1);
       
   589 	err = TheDb.Exec(_L8("INSERT INTO A(Id) VALUES(2)"));
       
   590 	TEST2(err, 1);
       
   591 	TheDb.Close();
       
   592 
       
   593 	err = TheDb.Create(KTestMMCDatabase2);
       
   594 	TEST2(err, KErrNone);
       
   595 	err = TheDb.Exec(_L8("CREATE TABLE B(N INTEGER)"));
       
   596 	TEST(err >= 0);
       
   597 	err = TheDb.Exec(_L8("INSERT INTO B(N) VALUES(10)"));
       
   598 	TEST2(err, 1);
       
   599 	err = TheDb.Exec(_L8("INSERT INTO B(N) VALUES(20)"));
       
   600 	TEST2(err, 1);
       
   601 	err = TheDb.Exec(_L8("INSERT INTO B(N) VALUES(30)"));
       
   602 	TEST2(err, 1);
       
   603 	TheDb.Close();
       
   604 
       
   605 	err = TheDb.Open(KTestMMCDatabase1);
       
   606 	TEST2(err, KErrNone);
       
   607 	err = TheDb.Attach(KTestMMCDatabase2, _L("Db2"));
       
   608 	TEST2(err, KErrNone);
       
   609 
       
   610 	RSqlStatement stmt;
       
   611 	err = stmt.Prepare(TheDb, _L8("SELECT * FROM B"));
       
   612 	TEST2(err, KErrNone);
       
   613 	err = stmt.Next();
       
   614 	TEST2(err, KSqlAtRow);
       
   615 
       
   616 	console->Printf(KTxtRemoveMMCTxt);
       
   617 	console->Printf(KTxtPressAnyKey);
       
   618 	console->Getch(); // get and ignore character
       
   619 
       
   620 	err = stmt.Next();
       
   621 	TEST2(err, KSqlAtRow);
       
   622 
       
   623 	err = TheDb.Exec(_L8("INSERT INTO B(N) VALUES(40)"));
       
   624 	TEST2(err, KErrNotReady);
       
   625 
       
   626 	err = TheDb.Exec(_L8("INSERT INTO B(N) VALUES(50)"));
       
   627 	TEST2(err, KErrNotReady);
       
   628 
       
   629 	err = stmt.Next();
       
   630 	TEST2(err, KSqlAtRow);
       
   631 	stmt.Close();
       
   632 
       
   633 //Check the error conditions when you attempt operations on the other database
       
   634 	RSqlStatement stmt2;
       
   635 	err = stmt2.Prepare(TheDb, _L8("SELECT * FROM A"));
       
   636 	TEST2(err, KErrNone);
       
   637 	err = stmt2.Next();
       
   638 	TEST2(err, KSqlAtRow);
       
   639 
       
   640 	err = TheDb.Exec(_L8("INSERT INTO A(Id) VALUES(40)"));
       
   641 	TEST2(err, KErrNotReady);
       
   642 
       
   643 	err = stmt2.Next();
       
   644 	TEST2(err, KSqlAtRow);
       
   645 	stmt2.Close();
       
   646 
       
   647 	TheDb.Close();
       
   648 
       
   649 	//Initially remove any preexisting database;
       
   650 	(void)RSqlDatabase::Delete(KTestMMCDatabase1);
       
   651 	(void)RSqlDatabase::Delete(KTestMMCDatabase2);
       
   652 
       
   653 	CleanupStack::PopAndDestroy(); // close console
       
   654 	}
       
   655 
       
   656 
       
   657 
       
   658 void DoTestsL()
       
   659 	{
       
   660 	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-4022 \"SQL against attached MMC db when MMC removed\" test "));
       
   661 	SqlAttachMMCDb2InternalDbTestL();
       
   662 
       
   663 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-4024 SQL against MMC db with attached internal database when MMC removed  "));
       
   664 	SqlAttachInternalDb2MMCDbTestL();
       
   665 
       
   666 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-4025 SQL against MMC based db with attached MMC based database when MMC removed  "));
       
   667 	SqlAttachMMCDb12MMCDb2TestL();
       
   668 
       
   669 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-4023 SQL against internal database with attached MMC db when MMC removed "));
       
   670 	SqlAttachMMCDb2InternalDbAndDoDiskOpsTestL();
       
   671 
       
   672 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-4021 SQL UNION against internal database with attached MMC db when MMC removed "));
       
   673 	SqlAttachMMCDb2InternalDbUnionTestL();
       
   674 
       
   675 	}
       
   676 
       
   677 TInt E32Main()
       
   678 	{
       
   679 	TheTest.Title();
       
   680 
       
   681 	CTrapCleanup* tc = CTrapCleanup::New();
       
   682 
       
   683 	__UHEAP_MARK;
       
   684 	CreateTestEnv();
       
   685 	TRAPD(err, DoTestsL());
       
   686 	TheFs.Close();
       
   687 	TEST2(err, KErrNone);
       
   688 
       
   689 	__UHEAP_MARKEND;
       
   690 
       
   691 	TheTest.End();
       
   692 	TheTest.Close();
       
   693 
       
   694 	delete tc;
       
   695 
       
   696 	User::Heap().Check();
       
   697 	return KErrNone;
       
   698 	}