/** @SYMTestCaseID SYSLIB-SQL-CT-1612 @SYMTestCaseDesc Two connections to the same database in the same thread. Create a test database and insert some records from both connections. Verify that all records were inserted successfully. @SYMTestPriority High @SYMTestActions Testing SQL engine behaviour when having mutiple connections to the same database in the same thread. @SYMTestExpectedResults Test must not fail @SYMREQ REQ5792 REQ5793 */ void TestMultiConnSameThread() { //Connection 1 RSqlDatabase db1; TInt err = db1.Create(KTestDbName1); TEST2(err, KErrNone); //Create test database RDebug::Print(_L("###Create test database\r\n")); _LIT8(KCreateSql, "CREATE TABLE A(Id INTEGER PRIMARY KEY AUTOINCREMENT, Data INTEGER)"); err = db1.Exec(KCreateSql); TEST(err >= 0); //Connection 2 RSqlDatabase db2; err = db2.Open(KTestDbName1); TEST2(err, KErrNone); //Insert some records using both connections RDebug::Print(_L("###Insert some records\r\n")); const TInt KRecNum = 100; _LIT8(KInsertSql, "INSERT INTO A(Data) VALUES("); for(TInt i=0;i<KRecNum;++i) { TBuf8<100> sql(KInsertSql); sql.AppendNum((TInt64)i + 1); sql.Append(_L(");")); err = (i%2) ? db1.Exec(sql) : db2.Exec(sql); if(err < 0) { TPtrC msg = (i%2) ? db1.LastErrorMessage() : db2.LastErrorMessage(); RDebug::Print(_L("##Db Error msg: \"%S\"\n\r"), &msg); } TEST2(err, 1); } //Check the database content RDebug::Print(_L("###Check the database content\r\n")); _LIT8(KSelectSql, "SELECT * FROM A"); RSqlStatement stmt; err = stmt.Prepare(db1, KSelectSql); TEST2(err, KErrNone); for(TInt j=0;j<KRecNum;++j) { err = stmt.Next(); TEST2(err, KSqlAtRow); TEST(stmt.AtRow()); TInt id = stmt.ColumnInt(0); TInt data = stmt.ColumnInt(1); TEST(id == data); } stmt.Close(); //Cleanup db2.Close(); db1.Close(); RDebug::Print(_L("###Delete the test database\r\n")); (void)RSqlDatabase::Delete(KTestDbName1); }