persistentstorage/sqlite3api/TEST/t_sqlitewsdinsert.cpp
changeset 0 08ec8eefde2f
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 //
       
    15 
       
    16 #include <e32test.h>
       
    17 #include <e32uid.h>
       
    18 #include <f32file.h>
       
    19 #include <e32math.h>
       
    20 #include <sqlite3.h>
       
    21 #include "t_sqlitewsd.h"
       
    22 
       
    23 void DoInserts(TInt aProcId, TInt aRecId1, TInt aRecId2)
       
    24 	{
       
    25 	TEST(TheDb != 0);
       
    26 	
       
    27 	TTime now;
       
    28 	now.UniversalTime();
       
    29 	TInt64 seed = now.Int64();
       
    30 	
       
    31 	const TInt KMaxFailingAllocationNo = 20;
       
    32 	TInt lockcnt = 0;
       
    33 	
       
    34 	for(TInt recno=0;recno<KTestRecordCnt;)
       
    35 		{
       
    36 		//Insert record 1 under OOM simulation
       
    37 		TInt failingAllocationNo = Math::Rand(seed) % (KMaxFailingAllocationNo + 1);
       
    38 		__UHEAP_SETFAIL(RHeap::EDeterministic, failingAllocationNo );
       
    39 		TBuf8<100> sql;
       
    40 		sql.Format(_L8("INSERT INTO A VALUES(%d)"), aRecId1);
       
    41 		TInt err = sqlite3_exec(TheDb, (const char*)sql.PtrZ(), 0, 0, 0);
       
    42 		__UHEAP_SETFAIL(RHeap::ENone, 0);	
       
    43 		TEST(err == SQLITE_NOMEM || err == SQLITE_BUSY || err == SQLITE_OK);
       
    44 		if(err == SQLITE_BUSY)
       
    45 			{
       
    46 			++lockcnt;
       
    47 			User::After(1);
       
    48 			continue;	
       
    49 			}
       
    50 		else if(err == SQLITE_OK)
       
    51 			{
       
    52 			++recno;
       
    53 			if((recno % 100) == 0)
       
    54 				{
       
    55 				RDebug::Print(_L("Process %d: %d records inserted.\r\n"), aProcId, recno);	
       
    56 				}
       
    57 			continue;	
       
    58 			}
       
    59 		//Insert record 2
       
    60 		sql.Format(_L8("INSERT INTO A VALUES(%d)"), aRecId2);
       
    61 		err = sqlite3_exec(TheDb, (const char*)sql.PtrZ(), 0, 0, 0);
       
    62 		TEST(err == SQLITE_BUSY || err == SQLITE_OK);
       
    63 		if(err == SQLITE_BUSY)
       
    64 			{
       
    65 			++lockcnt;
       
    66 			User::After(1);
       
    67 			continue;	
       
    68 			}
       
    69 		//SQLITE_OK case
       
    70 		++recno;
       
    71 		if((recno % 100) == 0)
       
    72 			{
       
    73 			RDebug::Print(_L("Process %d: %d records inserted.\r\n"), aProcId, recno);	
       
    74 			}
       
    75 		}
       
    76 	RDebug::Print(_L("Process %d inserted %d records. %d locks occured.\r\n"), aProcId, KTestRecordCnt, lockcnt);
       
    77 	}
       
    78