dan | d7b0690 | 2014-11-12 17:45:37 +0000 | [diff] [blame] | 1 | # 2014-11-12 |
| 2 | # |
| 3 | # The author disclaims copyright to this source code. In place of |
| 4 | # a legal notice, here is a blessing: |
| 5 | # |
| 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. |
| 9 | # |
| 10 | #*********************************************************************** |
| 11 | # |
| 12 | # Test that errors encountered during a ROLLBACK operation correctly |
| 13 | # affect ongoing SQL statements. |
| 14 | # |
| 15 | |
| 16 | set testdir [file dirname $argv0] |
| 17 | source $testdir/tester.tcl |
| 18 | source $testdir/malloc_common.tcl |
| 19 | set testprefix rollbackfault |
| 20 | |
| 21 | |
| 22 | proc int2hex {i} { format %.2X $i } |
| 23 | db func int2hex int2hex |
| 24 | do_execsql_test 1.0 { |
| 25 | SELECT int2hex(0), int2hex(100), int2hex(255) |
| 26 | } {00 64 FF} |
| 27 | do_execsql_test 1.1 { |
| 28 | CREATE TABLE t1(i, h); |
| 29 | CREATE INDEX i1 ON t1(h); |
| 30 | WITH data(a, b) AS ( |
| 31 | SELECT 1, int2hex(1) |
| 32 | UNION ALL |
| 33 | SELECT a+1, int2hex(a+1) FROM data WHERE a<40 |
| 34 | ) |
| 35 | INSERT INTO t1 SELECT * FROM data; |
| 36 | } {} |
| 37 | |
| 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] |
| 44 | |
| 45 | for {set i 0} {$i < 10} {incr i} { sqlite3_step $::s1 } |
| 46 | for {set i 0} {$i < 3} {incr i} { sqlite3_step $::s2 } |
| 47 | |
| 48 | execsql { |
| 49 | BEGIN; DELETE FROM t1 WHERE (i%2) |
| 50 | } |
| 51 | } -body { |
| 52 | execsql { ROLLBACK } |
| 53 | } -test { |
| 54 | |
| 55 | set res1 [list] |
| 56 | set res2 [list] |
| 57 | while {"SQLITE_ROW" == [sqlite3_step $::s1]} { |
| 58 | lappend res1 [sqlite3_column_text $::s1 0] |
| 59 | } |
| 60 | while {"SQLITE_ROW" == [sqlite3_step $::s2]} { |
| 61 | lappend res2 [sqlite3_column_text $::s2 0] |
| 62 | } |
| 63 | set rc1 [sqlite3_finalize $::s1] |
| 64 | set rc2 [sqlite3_finalize $::s2] |
| 65 | |
| 66 | catchsql { ROLLBACK } |
| 67 | |
| 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" |
| 71 | } { |
| 72 | # This is Ok. |
| 73 | } elseif {$rc1!="SQLITE_OK" && $rc2!="SQLITE_OK" && $res1=="" &&$res2==""} { |
| 74 | # Also Ok. |
| 75 | } else { |
| 76 | error "statements don't look right" |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | |
| 82 | finish_test |
| 83 | |
| 84 | |