1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
1 // Copyright (c) 2006-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". |
530 User::After(2000000); |
530 User::After(2000000); |
531 |
531 |
532 CloseTestThreads(threads, statuses, KTestThreadCnt); |
532 CloseTestThreads(threads, statuses, KTestThreadCnt); |
533 } |
533 } |
534 |
534 |
|
535 /** |
|
536 @SYMTestCaseID PDS-SQL-CT-4201 |
|
537 @SYMTestCaseDesc Max number of SQL statements test. |
|
538 @SYMTestPriority High |
|
539 @SYMTestActions The test creates a table with couple of records and then |
|
540 creates as many as possible SQL statements. The expected result is |
|
541 that either the statement creation process will fail with KErrNoMemory or |
|
542 the max number of statements to be created is reached (100000). |
|
543 Then the test deletes 1/2 of the created statements object and |
|
544 after that attempts to execute Next() on the rest of them. |
|
545 @SYMTestExpectedResults Test must not fail |
|
546 @SYMDEF DEF145236 |
|
547 */ |
|
548 void StatementMaxNumberTest() |
|
549 { |
|
550 (void)RSqlDatabase::Delete(KTestDbName1); |
|
551 RSqlDatabase db; |
|
552 TInt err = db.Create(KTestDbName1); |
|
553 TEST2(err, KErrNone); |
|
554 err = db.Exec(_L("CREATE TABLE A(I INTEGER); INSERT INTO A(I) VALUES(1); INSERT INTO A(I) VALUES(2);")); |
|
555 TEST(err >= 0); |
|
556 |
|
557 //Reserve memory for the statement objects |
|
558 const TInt KMaxStmtCount = 100000; |
|
559 RSqlStatement* stmt = new RSqlStatement[KMaxStmtCount]; |
|
560 TEST(stmt != NULL); |
|
561 TInt stmtCnt = 0; |
|
562 |
|
563 //Create as many statement objects as possible |
|
564 err = KErrNone; |
|
565 for(TInt i=0;(i<KMaxStmtCount) && (err == KErrNone);++i,++stmtCnt) |
|
566 { |
|
567 err = stmt[i].Prepare(db, _L("SELECT * FROM A WHERE I>=0 AND I<10")); |
|
568 } |
|
569 TheTest.Printf(_L("%d created statement objects. Last error: %d.\r\n"), stmtCnt, err); |
|
570 TEST(err == KErrNone || err == KErrNoMemory); |
|
571 |
|
572 //Close 1/2 of the statements to free some memory |
|
573 for(TInt i=stmtCnt-1;i>=0;i-=2) |
|
574 { |
|
575 stmt[i].Close(); |
|
576 } |
|
577 |
|
578 //Now, there should be enough memory to be able to execute Next() on the rest of the statements |
|
579 for(TInt i=stmtCnt-2;i>=0;i-=2) |
|
580 { |
|
581 err = stmt[i].Next(); |
|
582 TEST2(err, KSqlAtRow); |
|
583 err = stmt[i].Next(); |
|
584 TEST2(err, KSqlAtRow); |
|
585 err = stmt[i].Next(); |
|
586 TEST2(err, KSqlAtEnd); |
|
587 } |
|
588 |
|
589 //Cleanup |
|
590 for(TInt i=stmtCnt-1;i>=0;--i) |
|
591 { |
|
592 stmt[i].Close(); |
|
593 } |
|
594 delete [] stmt; |
|
595 db.Close(); |
|
596 (void)RSqlDatabase::Delete(KTestDbName1); |
|
597 } |
|
598 |
535 void DoTests() |
599 void DoTests() |
536 { |
600 { |
537 TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1627-0001 SQL server load test ")); |
601 TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1627-0001 SQL server load test ")); |
538 SqlLoadTest(); |
602 SqlLoadTest(); |
|
603 TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4201 Statement max number test")); |
|
604 StatementMaxNumberTest(); |
539 } |
605 } |
540 |
606 |
541 TInt E32Main() |
607 TInt E32Main() |
542 { |
608 { |
543 TheTest.Title(); |
609 TheTest.Title(); |