
// Called by BasicSQL2-8S.script.
// Duplicates BasicSQL2.script/APIBasic2.ini but uses 8-bit methods (Prepare
// and Exec) and asynchronous methods rather than the usual synchronous
// UTF-16 methods.
//
// Tests that a transaction  which is not completed is visible  to a EReadUncommitted
// session and simultaneously (so a bit of concurrency), not visible
// to a EReadSerializable session.

// Set up a new database.
[Thread1]
WaitB0=2
EightBit1=True
Async2=True
Delete3=C:\Transaction0.db
ExpectedError3=KErrNotFound
Create4=C:\Transaction0.db
Exec5=Create Table Curtab(f1 int primary key, f2 real, f3 text);
Prepare6=Insert into Curtab(f1, f2, f3) values(:mary, :mungo, :midge);
ParameterIndex7=:mary
ParameterIndex8=:mungo
ParameterIndex9=:midge
BindInt10=0,-4853
BindReal11=1,6.0827626
BindText12=2,Here's some text
St_Exec13=
Reset14=
St_Close15=
// At this point one record outside of a transaction is present.

Exec16=Begin Transaction;
Prepare17=Insert into Curtab(f1, f2, f3) values(:mary, :mungo, :midge);
ParameterIndex18=:mary
ParameterIndex19=:mungo
ParameterIndex20=:midge
BindInt21=0,9876
BindReal22=1,7.0710678
BindText23=2,Here's yet more text
St_Exec24=
Reset25=
BindInt26=0,1011010
BindReal27=1,182282.397
BindText28=2,I want chocolate. Now.
St_Exec29=
Reset30=
BindInt31=0,7070707
BindReal32=1,-1.60217733e-19
BindText33=2,Now I want ice-cream.
St_Exec34=
Reset35=
St_Close36=
// At this point we've added one row outside of the transaction and 3 more
// within it. Send a signal to the slave threads which will check for the
// above content (one is ESerializable, one is EReadUncommitted, so they'll
// see different content).
// Wake up 2 threads..
SignalA37=2
// Wait for two signals to show they've finished..
WaitB38=2
Exec39=Rollback;
Close40=
EndBlock41=

// ESerializable thread.
[Thread2]
SignalB0=1
EightBit1=True
Async2=True
// Wait until the db has been setup.
WaitA3=1
Open4=C:\Transaction0.db
SetIsolationLevel5=ESerializable
Prepare6=Select * from Curtab;
ColumnIndex7=f1
ColumnIndex8=f2
ColumnIndex9=f3
Next10=
ExpectedError10=KSqlErrLocked
St_Close11=
Close12=
SignalB13=1
EndBlock14=

[Thread3]
SignalB0=1
EightBit1=True
Async2=True
// Wait until the db has been setup.
WaitA3=1
Open4=C:\Transaction0.db
SetIsolationLevel5=EReadUncommitted
Prepare6=Select * from Curtab;
ColumnIndex7=f1
ColumnIndex8=f2
ColumnIndex9=f3
Next10=KSqlAtRow
ColumnInt11=0,-4853
ColumnReal12=1,6.0827626
ColumnTextL13=2,Here's some text
Next14=KSqlAtRow
ColumnInt15=0,9876
ColumnReal16=1,7.0710678
ColumnTextL17=2,Here's yet more text
Next18=KSqlAtRow
ColumnInt19=0,1011010
ColumnReal20=1,182282.397
ColumnTextL21=2,I want chocolate. Now.
Next22=KSqlAtRow
ColumnInt23=0,7070707
ColumnReal24=1,-1.60217733e-19
ColumnTextL25=2,Now I want ice-cream.
Next26=KSqlAtEnd
St_Close27=
Close28=
SignalB29=1
EndBlock30=

[CheckFollowingRollback]
EightBit0=True
Async1=True
Open2=C:\Transaction0.db
Prepare3=Select * from Curtab;
ColumnIndex4=f1
ColumnIndex5=f2
ColumnIndex6=f3
Next7=KSqlAtRow
ColumnInt8=0,-4853
ColumnReal9=1,6.0827626
ColumnTextL10=2,Here's some text
Next11=KSqlAtEnd
St_Close12=
Close13=
Delete14=C:\Transaction0.db
EndBlock15=


// Create some cells with text in. Copy these with streams - passing
// an RSqlColumnReadStream to an RSqlParamWriteStream.
[CopyCellsWithStreams]
EightBit0=True
Async1=True
Delete2=C:\CopyCells.db
ExpectedError2=KErrNotFound
Create3=C:\CopyCells.db
Exec4=Create table Table1(field1 text(50));
Exec5=Create table Table2(field1 text(50));

Exec6=Insert Into Table1(field1) values("We're going to copy this string");
Exec7=Insert Into Table1(field1) values("And this one");
Exec8=Insert Into Table1(field1) values("In fact, all of them. There's a loop");

// This is used to select the field we want to copy.
Prepare9=select field1 from Table1;

// This will copy the first cell into a new one (using a separate
// RSqlStatement object). The two lines below define values for the separate
// RSqlStatement to use.
Function10=CopyCellsUsingStreams
PrepareStatement=Insert into Table2(field1) values(:mob);
ParamName=:mob

// Close PrepareX and read back the content of Table2 to see if the cell
// copied correctly.
St_Close11=
Prepare12=select field1 from Table2;
Next13=KSqlAtRow
ColumnIndex14=field1
ColumnTextL15=0,We're going to copy this string
Next16=KSqlAtRow
ColumnTextL17=0,And this one
Next18=KSqlAtRow
ColumnTextL19=0,In fact, all of them. There's a loop
Next20=KSqlAtEnd

// Shut down our RSqlStatement and RSqlDatabase resources.
St_Close21=
Close22=
Delete23=C:\CopyCells.db
EndBlock24=

// A separate test, here we bind the content of one file (to an integer
// field actually, but SQLite doesn't care about that), then we bind the
// content of another before performing the exec/reset. So which data
// ends up in the cell? The data from the second bind.
[DoubleBind]
EightBit0=True
Async1=True
Delete2=C:\GenerateErrors2.db
ExpectedError2=KErrNotFound
Create3=C:\GenerateErrors2.db
Exec4=Create Table Table1(Field1 int);
Prepare5=Insert into Table1(Field1) Values (:Mickey);
ParameterIndex6=:Mickey
StreamWriteBindText7=0,Z:\TEF_SQL\TestData\reference1.bin
StreamWriteBindText8=0,Z:\TEF_SQL\TestData\reference1.txt
St_Exec9=
Reset10=
St_Close11=
Prepare12=select * from Table1;
ColumnIndex13=Field1
Next14=KSqlAtRow
ColumnTextL15=0,Z:\TEF_SQL\TestData\reference1.txt
St_Close16=
Close17=
Delete18=C:\GenerateErrors2.db
EndBlock19=


// Test the 'leaving' version of Create, Prepare and Open, also see what
// happens if you try creating a database on ROM..
[LeaveMethods]
EightBit0=True
Async1=True
Delete2=C:\Leave1.db
ExpectedError2=KErrNotFound
OpenL3=C:\Leave1.db
ExpectedError3=KErrNotFound
CreateL4=C:\Leave1.db
Exec5=Create table Leavetable(f1 text(50), f2 int, f3 real);
PrepareL6=Insert into Leavetable values(:wonka, :charlie, :joe);
ParameterIndex7=:wonka
ParameterIndex8=:charlie
ParameterIndex9=:joe
BindText10=0,Great Glass Elevator
BindInt11=1,5
BindReal12=2,1.23456
St_Exec13=
Reset14=
BindText15=0,Chocolate Factory
BindInt16=1,54
BindReal17=2,9.87654
St_Exec18=
Reset19=
St_Close20=
PrepareL21=select * from Leavetable;
Next22=KSqlAtRow
ColumnIndex23=f1
ColumnIndex24=f2
ColumnIndex25=f3
ColumnTextL26=0,Great Glass Elevator
ColumnInt27=1,5
ColumnReal28=2,1.23456
Next29=KSqlAtRow
ColumnTextL30=0,Chocolate Factory
ColumnInt31=1,54
ColumnReal32=2,9.87654
Next33=KSqlAtEnd
St_Close34=

Close35=
CreateL36=C:\Leave1.db
ExpectedError36=KErrAlreadyExists
Delete37=C:\Leave1.db
CreateL38=Z:\TEF_SQL\TestData\ReadOnly.db
ExpectedError38=KErrAlreadyExists
CreateL39=Z:\TEF_SQL\TestData\DoesntExist.db
ExpectedError39=KErrAccessDenied
EndBlock40=

// Create (and implicitly open) a database, then another, then another, etc.
// This actually isn't supposed to generate errors.
// This leaks memory, normally the programmer would be expected to close
// each of the databases before opening another, but we're explicitly
// checking that successive Opens/Creates give no error.
[MultipleCreateOpen]
EightBit0=True
Async1=True
Delete2=C:\MCO1.db
ExpectedError2=KErrNotFound
Delete3=C:\MCO2.db
ExpectedError3=KErrNotFound
Delete4=C:\MCO3.db
ExpectedError4=KErrNotFound
Delete5=C:\MCO4.db
ExpectedError5=KErrNotFound
Delete6=C:\MCO5.db
ExpectedError6=KErrNotFound

CreateL7=C:\MCO1.db
Create8=C:\MCO2.db
OpenL9=Z:\TEF_SQL\TestData\test1.db
CreateL10=C:\MCO3.db
Create11=C:\MCO4.db
CreateL12=C:\MCO5.db

Delete13=C:\MCO1.db
ExpectedError13=KErrInUse
Delete14=C:\MCO2.db
ExpectedError14=KErrInUse
Delete15=C:\MCO3.db
ExpectedError15=KErrInUse
Delete16=C:\MCO4.db
ExpectedError16=KErrInUse
Delete17=C:\MCO5.db
ExpectedError17=KErrInUse
Close18=
Delete19=C:\MCO5.db

Open20=Z:\TEF_SQL\TestData\ReadOnly.db
OpenL21=Z:\TEF_SQL\TestData\test1.db
Open22=Z:\TEF_SQL\TestData\ReadOnly.db

EndBlock23=

[ExtraBindTest]
EightBit0=True
Async1=True
// First set up a table.
Delete2=C:\ExtraBindTest.db
ExpectedError2=KErrNotFound
Create3=C:\ExtraBindTest.db
Exec4=Create table Sometable(Someint int, Somereal real, Sometext text);
Prepare5=Insert into Sometable(Someint, Somereal, Sometext) values (:FInt, :FReal, :FText);
Function6=WriteBigTable
LowCount=105
HighCount=119
CountStep=3
Multiplier=0.0
Text=Here's some rather pointless text
EventuallyExpectedError=KErrNone
St_Close7=
// Now try a non-trivial select. Ok then, fairly trivial, ;-)
Prepare8=Select * from Sometable where Someint > :Brian;
ParameterIndex9=:Brian
BindInt10=0,112
Next11=KSqlAtRow
ColumnIndex12=Someint
ColumnIndex13=Somereal
ColumnIndex14=Sometext
ColumnInt15=0,114
ColumnReal16=1,0.0
ColumnTextL17=2,Here's some rather pointless text
Next18=KSqlAtRow
ColumnInt19=0,117
ColumnReal20=1,0.0
ColumnTextL21=2,Here's some rather pointless text
Next22=KSqlAtEnd
St_Close23=
Close24=
Delete25=C:\ExtraBindTest.db
EndBlock26=

[ExtraBindTest2]
EightBit0=True
Async1=True
Delete2=C:\ExtraBindTest2.db
ExpectedError2=KErrNotFound
Create3=C:\ExtraBindTest2.db
Exec4=Create table Sometable(Someint int, Somereal real, Sometext text);
Prepare5=Insert into Sometable(Sometext) values (:FText);
ParameterIndex6=:FText
NewBlock7=WriteInts20
St_Exec8=
Reset9=
NewBlock10=WriteInts21
St_Exec11=
Reset12=
NewBlock13=WriteInts22
St_Exec14=
Reset15=
NewBlock16=WriteInts400
St_Exec17=
Reset18=
St_Close19=
Prepare20=Select * from Sometable;
ColumnIndex21=Sometext
Next22=KSqlAtRow
ColumnSize23=0,80
Next24=KSqlAtRow
ColumnSize25=0,84
Next26=KSqlAtRow
ColumnSize27=0,88
Next28=KSqlAtRow
ColumnSize29=0,1600
Next30=KSqlAtEnd
// MUST close the Statement or confusion ensues!!
St_Close31==
Prepare32=Select Sometext from Sometable where Sometext=:Block
ParameterIndex33=:Block
// We're trying to recover one of the blocks. This function does a bind..
NewBlock34=WriteInts21
Next35=KSqlAtRow
ColumnIndex36=Sometext
ColumnSize37=0,84
Next38=KSqlAtEnd
St_Close39=
Close40=
Delete41=C:\ExtraBindTest2.db
EndBlock42=

[WriteInts20]
Function0=WriteIntsToStream
Count=20
EndBlock1=
[WriteInts21]
Function0=WriteIntsToStream
Count=21
EndBlock1=
[WriteInts22]
Function0=WriteIntsToStream
Count=22
EndBlock1=
[WriteInts400]
Function0=WriteIntsToStream
Count=400
EndBlock1=

