3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give.
10 #***********************************************************************
12 # Test that errors encountered during a ROLLBACK operation correctly
13 # affect ongoing SQL statements.
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
18 source $testdir/malloc_common.tcl
19 set testprefix rollbackfault
22 proc int2hex {i} { format %.2X $i }
23 db func int2hex int2hex
25 SELECT int2hex(0), int2hex(100), int2hex(255)
28 CREATE TABLE t1(i, h);
29 CREATE INDEX i1 ON t1(h);
33 SELECT a+1, int2hex(a+1) FROM data WHERE a<40
35 INSERT INTO t1 SELECT * FROM data;
38 foreach f {oom ioerr} {
39 do_faultsim_test 1.2 -faults $f* -prep {
40 set sql1 { SELECT i FROM t1 WHERE (i%2)==0 }
41 set sql2 { SELECT i FROM t1 WHERE (i%2)==0 ORDER BY h }
42 set ::s1 [sqlite3_prepare db $sql1 -1 dummy]
43 set ::s2 [sqlite3_prepare db $sql2 -1 dummy]
45 for {set i 0} {$i < 10} {incr i} { sqlite3_step $::s1 }
46 for {set i 0} {$i < 3} {incr i} { sqlite3_step $::s2 }
49 BEGIN; DELETE FROM t1 WHERE (i%2)
57 while {"SQLITE_ROW" == [sqlite3_step $::s1]} {
58 lappend res1 [sqlite3_column_text $::s1 0]
60 while {"SQLITE_ROW" == [sqlite3_step $::s2]} {
61 lappend res2 [sqlite3_column_text $::s2 0]
63 set rc1 [sqlite3_finalize $::s1]
64 set rc2 [sqlite3_finalize $::s2]
68 if {$rc1=="SQLITE_OK" && $rc2=="SQLITE_OK"
69 && $res1=="22 24 26 28 30 32 34 36 38 40"
70 && $res2=="8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40"
73 } elseif {$rc1!="SQLITE_OK" && $rc2!="SQLITE_OK" && $res1=="" &&$res2==""} {
76 error "statements don't look right"