Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Add further tests for rollback operations in the presence of ongoing selects. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: | eaf3aae014f59c8d37aa20aa31d54cf1 |
User & Date: | dan 2014-11-12 17:45:37 |
Context
2014-11-13
| ||
14:18 | Have calls to sqlite3_backup_init() fail if there is already a read or read-write transaction open on the destination database. check-in: 169b5505 user: dan tags: trunk | |
2014-11-12
| ||
17:45 | Add further tests for rollback operations in the presence of ongoing selects. check-in: eaf3aae0 user: dan tags: trunk | |
14:56 | When a transaction or savepoint rollback occurs, save the positions of all open read-cursors so that they can be restored following the rollback operation. check-in: dd03a280 user: dan tags: trunk | |
Changes
Changes to test/rollback2.test.
5 5 # 6 6 # May you do good and not evil. 7 7 # May you find forgiveness for yourself and forgive others. 8 8 # May you share freely, never taking more than you give. 9 9 # 10 10 #*********************************************************************** 11 11 # 12 +# This file containst tests to verify that ROLLBACK or ROLLBACK TO 13 +# operations interact correctly with ongoing SELECT statements. 14 +# 12 15 13 16 set testdir [file dirname $argv0] 14 17 source $testdir/tester.tcl 15 18 set ::testprefix rollback2 16 19 17 20 proc int2hex {i} { format %.2X $i } 18 21 db func int2hex int2hex 19 - 20 22 do_execsql_test 1.0 { 21 23 SELECT int2hex(0), int2hex(100), int2hex(255) 22 24 } {00 64 FF} 23 25 do_execsql_test 1.1 { 24 26 CREATE TABLE t1(i, h); 25 27 CREATE INDEX i1 ON t1(h); 26 28 WITH data(a, b) AS ( ................................................................................ 28 30 UNION ALL 29 31 SELECT a+1, int2hex(a+1) FROM data WHERE a<40 30 32 ) 31 33 INSERT INTO t1 SELECT * FROM data; 32 34 } {} 33 35 34 36 37 +# do_rollback_test ID SWITCHES 38 +# 39 +# where SWITCHES are: 40 +# 41 +# -setup SQL script to open transaction and begin writing. 42 +# -select SELECT to execute after -setup script 43 +# -result Expected result of -select statement 44 +# -rollback Use this SQL command ("ROLLBACK" or "ROLLBACK TO ...") to 45 +# rollback the transaction in the middle of the -select statment 46 +# execution. 47 +# 35 48 proc do_rollback_test {tn args} { 36 49 set A(-setup) "" 37 50 set A(-select) "" 38 51 set A(-result) "" 39 52 set A(-rollback) ROLLBACK 40 53 41 54 array set O $args ................................................................................ 57 70 } 58 71 59 72 do_test $tn.$iRollback [list set {} $res] [list {*}$A(-result)] 60 73 if {$i < $iRollback} break 61 74 } 62 75 } 63 76 64 -do_rollback_test 2 -setup { 77 +do_rollback_test 2.1 -setup { 78 + BEGIN; 79 + DELETE FROM t1 WHERE (i%2)==1; 80 +} -select { 81 + SELECT i FROM t1 WHERE (i%2)==0 82 +} -result { 83 + 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 84 +} 85 + 86 +do_rollback_test 2.2 -setup { 87 + BEGIN; 88 + DELETE FROM t1 WHERE (i%4)==1; 89 + SAVEPOINT one; 90 + DELETE FROM t1 WHERE (i%2)==1; 91 +} -rollback { 92 + ROLLBACK TO one; 93 +} -select { 94 + SELECT i FROM t1 WHERE (i%2)==0 95 +} -result { 96 + 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 97 +} 98 + 99 +#-------------------------------------------------------------------- 100 +# Try with some index scans 101 +# 102 +do_eqp_test 3.1 { 103 + SELECT i FROM t1 WHERE (i%2)==0 ORDER BY h DESC; 104 +} {0 0 0 {SCAN TABLE t1 USING INDEX i1}} 105 +do_rollback_test 3.2 -setup { 106 + BEGIN; 107 + DELETE FROM t1 WHERE (i%2)==1; 108 +} -select { 109 + SELECT i FROM t1 WHERE (i%2)==0 ORDER BY h DESC; 110 +} -result { 111 + 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 112 +} 113 +do_rollback_test 3.3 -setup { 114 + BEGIN; 115 + DELETE FROM t1 WHERE (i%4)==1; 116 + SAVEPOINT one; 117 + DELETE FROM t1 WHERE (i%2)==1; 118 +} -rollback { 119 + ROLLBACK TO one; 120 +} -select { 121 + SELECT i FROM t1 WHERE (i%2)==0 ORDER BY h DESC; 122 +} -result { 123 + 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 124 +} 125 + 126 +#-------------------------------------------------------------------- 127 +# Now with some index scans that feature overflow keys. 128 +# 129 +set leader [string repeat "abcdefghij" 70] 130 +do_execsql_test 4.1 { UPDATE t1 SET h = $leader || h; } 131 + 132 +do_eqp_test 4.2 { 133 + SELECT i FROM t1 WHERE (i%2)==0 ORDER BY h ASC; 134 +} {0 0 0 {SCAN TABLE t1 USING INDEX i1}} 135 +do_rollback_test 4.3 -setup { 65 136 BEGIN; 66 137 DELETE FROM t1 WHERE (i%2)==1; 67 138 } -select { 68 - SELECT i FROM t1 WHERE (i%2)==0 139 + SELECT i FROM t1 WHERE (i%2)==0 ORDER BY h ASC; 140 +} -result { 141 + 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 142 +} 143 +do_rollback_test 4.4 -setup { 144 + BEGIN; 145 + DELETE FROM t1 WHERE (i%4)==1; 146 + SAVEPOINT one; 147 + DELETE FROM t1 WHERE (i%2)==1; 148 +} -rollback { 149 + ROLLBACK TO one; 150 +} -select { 151 + SELECT i FROM t1 WHERE (i%2)==0 ORDER BY h ASC; 69 152 } -result { 70 153 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 71 154 } 72 155 73 156 finish_test 74 157
Added test/rollbackfault.test.
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 +