598 |
598 |
599 //Reserve memory for the statement objects |
599 //Reserve memory for the statement objects |
600 const TInt KMaxStmtCount = 100000; |
600 const TInt KMaxStmtCount = 100000; |
601 RSqlStatement* stmt = new RSqlStatement[KMaxStmtCount]; |
601 RSqlStatement* stmt = new RSqlStatement[KMaxStmtCount]; |
602 TEST(stmt != NULL); |
602 TEST(stmt != NULL); |
603 TInt stmtCnt = 0; |
|
604 |
603 |
605 //Create as many statement objects as possible |
604 //Create as many statement objects as possible |
|
605 TInt idx = 0; |
606 err = KErrNone; |
606 err = KErrNone; |
607 for(TInt i=0;(i<KMaxStmtCount) && (err == KErrNone);++i,++stmtCnt) |
607 for(;idx<KMaxStmtCount;++idx) |
608 { |
608 { |
609 err = stmt[i].Prepare(db, _L("SELECT * FROM A WHERE I>=0 AND I<10")); |
609 err = stmt[idx].Prepare(db, _L("SELECT * FROM A WHERE I>=0 AND I<10")); |
610 if((i % 100) == 0) |
610 if(err != KErrNone) |
|
611 { |
|
612 break; |
|
613 } |
|
614 if((idx % 100) == 0) |
611 { |
615 { |
612 GetHomeTimeAsString(time); |
616 GetHomeTimeAsString(time); |
613 TheTest.Printf(_L("=== %S: Create % 5d statements\r\n"), &time, i + 1); |
617 TheTest.Printf(_L("=== %S: Create % 5d statements\r\n"), &time, idx + 1); |
614 if(IsTimeLimitReached()) |
618 if(IsTimeLimitReached()) |
615 { |
619 { |
616 TheTest.Printf(_L("=== %S: The time limit reached.\r\n"), &time); |
620 TheTest.Printf(_L("=== %S: The time limit reached.\r\n"), &time); |
|
621 ++idx;//The idx-th statement is valid, the statement count is idx + 1. |
617 break; |
622 break; |
618 } |
623 } |
619 } |
624 } |
620 } |
625 } |
|
626 |
|
627 TInt stmtCnt = idx; |
621 TheTest.Printf(_L("%d created statement objects. Last error: %d.\r\n"), stmtCnt, err); |
628 TheTest.Printf(_L("%d created statement objects. Last error: %d.\r\n"), stmtCnt, err); |
622 TEST(err == KErrNone || err == KErrNoMemory); |
629 TEST(err == KErrNone || err == KErrNoMemory); |
623 |
630 |
624 //Close 1/2 of the statements to free some memory |
631 //Close 1/2 of the statements to free some memory |
625 for(TInt i=stmtCnt-1,j=0;i>=0;i-=2,++j) |
632 idx = 0; |
626 { |
633 for(;idx<(stmtCnt/2);++idx) |
627 stmt[i].Close(); |
634 { |
628 if((j % 100) == 0) |
635 stmt[idx].Close(); |
|
636 if((idx % 100) == 0) |
629 { |
637 { |
630 GetHomeTimeAsString(time); |
638 GetHomeTimeAsString(time); |
631 TheTest.Printf(_L("=== %S: % 5d statements closed\r\n"), &time, j + 1); |
639 TheTest.Printf(_L("=== %S: % 5d statements closed\r\n"), &time, idx + 1); |
632 } |
640 } |
633 } |
641 } |
634 |
642 |
635 //Now, there should be enough memory to be able to execute Next() on the rest of the statements |
643 //Now, there should be enough memory to be able to execute Next() on the rest of the statements |
636 for(TInt i=stmtCnt-2,j=0;i>=0;i-=2,++j) |
644 for(TInt j=0;idx<stmtCnt;++idx,++j) |
637 { |
645 { |
638 err = stmt[i].Next(); |
646 err = stmt[idx].Next(); |
639 TEST2(err, KSqlAtRow); |
647 TEST2(err, KSqlAtRow); |
640 err = stmt[i].Next(); |
648 err = stmt[idx].Next(); |
641 TEST2(err, KSqlAtRow); |
649 TEST2(err, KSqlAtRow); |
642 err = stmt[i].Next(); |
650 err = stmt[idx].Next(); |
643 TEST2(err, KSqlAtEnd); |
651 TEST2(err, KSqlAtEnd); |
644 if((j % 100) == 0) |
652 if((j % 100) == 0) |
645 { |
653 { |
646 GetHomeTimeAsString(time); |
654 GetHomeTimeAsString(time); |
647 TheTest.Printf(_L("=== %S: % 5d statements processed\r\n"), &time, j + 1); |
655 TheTest.Printf(_L("=== %S: % 5d statements processed\r\n"), &time, j + 1); |
652 break; |
660 break; |
653 } |
661 } |
654 } |
662 } |
655 |
663 |
656 //Cleanup |
664 //Cleanup |
657 for(TInt i=stmtCnt-1,j=0;i>=0;--i,++j) |
665 for(idx=0;idx<stmtCnt;++idx) |
658 { |
666 { |
659 stmt[i].Close(); |
667 stmt[idx].Close(); |
660 if((j % 100) == 0) |
668 if((idx % 100) == 0) |
661 { |
669 { |
662 GetHomeTimeAsString(time); |
670 GetHomeTimeAsString(time); |
663 TheTest.Printf(_L("=== %S: % 5d statements closed\r\n"), &time, j + 1); |
671 TheTest.Printf(_L("=== %S: % 5d statements closed\r\n"), &time, idx + 1); |
664 } |
672 } |
665 } |
673 } |
666 delete [] stmt; |
674 delete [] stmt; |
667 db.Close(); |
675 db.Close(); |
668 (void)RSqlDatabase::Delete(KTestDbName1); |
676 (void)RSqlDatabase::Delete(KTestDbName1); |
|
677 GetHomeTimeAsString(time); |
|
678 TheTest.Printf(_L("=== %S: Test case end\r\n"), &time); |
669 } |
679 } |
670 |
680 |
671 void DoTests() |
681 void DoTests() |
672 { |
682 { |
673 TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1627-0001 SQL server load test ")); |
683 TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1627-0001 SQL server load test ")); |