Post by kokenge on Jun 22, 2011 14:08:43 GMT -5
Alan.
Here is a quick test.
The DB has 3 fields..
The first 2 inserts work.
The 3rd insert fails because it tries to insert 4 fields into the 3 field table.
The on error causes it to go the [rollback]
It gets the number of rows inserted, and correctly reports 2.
It executes the ROLLBACK
Now when it gets the rows inserted it is 0. That's because the BEGIN TRANSACTION surrounded all the inserts..
Hope this helps..
sqliteconnect #mem, ":memory:"
mem$ = "CREATE TABLE tempTbl (aa text,bb text,cc text);"
#mem execute(mem$)
#mem execute("BEGIN TRANSACTION")
on error goto [rollback]
mem$ = "INSERT INTO tempTbl VALUES('a1','b1','c1')"
#mem execute(mem$)
print "Insert ok:";mem$ ' first insert works
mem$ = "INSERT INTO tempTbl VALUES('a2','b2','c2')"
#mem execute(mem$) ' second insert works
print "Insert ok:";mem$
mem$ = "INSERT INTO tempTbl VALUES('a4','b3','c3','d3')"
#mem execute(mem$) ' this fails and trips the on error
print "Insert ok:";mem$
#mem execute("COMMIT TRANSACTION")
print "commited"
wait
[rollback]
#mem execute("SELECT * FROM tempTbl")
rows = #mem ROWCOUNT()
print "Rolls inserted:";rows
#mem execute("ROLLBACK TRANSACTION")
print "Roll back"
#mem execute("SELECT * FROM tempTbl")
rows = #mem ROWCOUNT()
print "Rolls inserted:";rows
wait