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 |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
eaf3aae014f59c8d37aa20aa31d54cf1 |
User & Date: | dan 2014-11-12 17:45:37.113 |
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: 169b550549 user: dan tags: trunk) | |
2014-11-12
| ||
17:45 | Add further tests for rollback operations in the presence of ongoing selects. (check-in: eaf3aae014 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: dd03a2802f user: dan tags: trunk) | |
Changes
Changes to test/rollback2.test.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | # 2014 November 12 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: # # May you do good and not evil. # May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #*********************************************************************** # set testdir [file dirname $argv0] source $testdir/tester.tcl set ::testprefix rollback2 proc int2hex {i} { format %.2X $i } db func int2hex int2hex | > > > < > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | # 2014 November 12 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: # # May you do good and not evil. # May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #*********************************************************************** # # This file containst tests to verify that ROLLBACK or ROLLBACK TO # operations interact correctly with ongoing SELECT statements. # set testdir [file dirname $argv0] source $testdir/tester.tcl set ::testprefix rollback2 proc int2hex {i} { format %.2X $i } db func int2hex int2hex do_execsql_test 1.0 { SELECT int2hex(0), int2hex(100), int2hex(255) } {00 64 FF} do_execsql_test 1.1 { CREATE TABLE t1(i, h); CREATE INDEX i1 ON t1(h); WITH data(a, b) AS ( SELECT 1, int2hex(1) UNION ALL SELECT a+1, int2hex(a+1) FROM data WHERE a<40 ) INSERT INTO t1 SELECT * FROM data; } {} # do_rollback_test ID SWITCHES # # where SWITCHES are: # # -setup SQL script to open transaction and begin writing. # -select SELECT to execute after -setup script # -result Expected result of -select statement # -rollback Use this SQL command ("ROLLBACK" or "ROLLBACK TO ...") to # rollback the transaction in the middle of the -select statment # execution. # proc do_rollback_test {tn args} { set A(-setup) "" set A(-select) "" set A(-result) "" set A(-rollback) ROLLBACK array set O $args |
︙ | ︙ | |||
57 58 59 60 61 62 63 | } do_test $tn.$iRollback [list set {} $res] [list {*}$A(-result)] if {$i < $iRollback} break } } | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | } do_test $tn.$iRollback [list set {} $res] [list {*}$A(-result)] if {$i < $iRollback} break } } do_rollback_test 2.1 -setup { BEGIN; DELETE FROM t1 WHERE (i%2)==1; } -select { SELECT i FROM t1 WHERE (i%2)==0 } -result { 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 } do_rollback_test 2.2 -setup { BEGIN; DELETE FROM t1 WHERE (i%4)==1; SAVEPOINT one; DELETE FROM t1 WHERE (i%2)==1; } -rollback { ROLLBACK TO one; } -select { SELECT i FROM t1 WHERE (i%2)==0 } -result { 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 } #-------------------------------------------------------------------- # Try with some index scans # do_eqp_test 3.1 { SELECT i FROM t1 WHERE (i%2)==0 ORDER BY h DESC; } {0 0 0 {SCAN TABLE t1 USING INDEX i1}} do_rollback_test 3.2 -setup { BEGIN; DELETE FROM t1 WHERE (i%2)==1; } -select { SELECT i FROM t1 WHERE (i%2)==0 ORDER BY h DESC; } -result { 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 } do_rollback_test 3.3 -setup { BEGIN; DELETE FROM t1 WHERE (i%4)==1; SAVEPOINT one; DELETE FROM t1 WHERE (i%2)==1; } -rollback { ROLLBACK TO one; } -select { SELECT i FROM t1 WHERE (i%2)==0 ORDER BY h DESC; } -result { 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 } #-------------------------------------------------------------------- # Now with some index scans that feature overflow keys. # set leader [string repeat "abcdefghij" 70] do_execsql_test 4.1 { UPDATE t1 SET h = $leader || h; } do_eqp_test 4.2 { SELECT i FROM t1 WHERE (i%2)==0 ORDER BY h ASC; } {0 0 0 {SCAN TABLE t1 USING INDEX i1}} do_rollback_test 4.3 -setup { BEGIN; DELETE FROM t1 WHERE (i%2)==1; } -select { SELECT i FROM t1 WHERE (i%2)==0 ORDER BY h ASC; } -result { 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 } do_rollback_test 4.4 -setup { BEGIN; DELETE FROM t1 WHERE (i%4)==1; SAVEPOINT one; DELETE FROM t1 WHERE (i%2)==1; } -rollback { ROLLBACK TO one; } -select { SELECT i FROM t1 WHERE (i%2)==0 ORDER BY h ASC; } -result { 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 } finish_test |
Added test/rollbackfault.test.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | # 2014-11-12 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: # # May you do good and not evil. # May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #*********************************************************************** # # Test that errors encountered during a ROLLBACK operation correctly # affect ongoing SQL statements. # set testdir [file dirname $argv0] source $testdir/tester.tcl source $testdir/malloc_common.tcl set testprefix rollbackfault proc int2hex {i} { format %.2X $i } db func int2hex int2hex do_execsql_test 1.0 { SELECT int2hex(0), int2hex(100), int2hex(255) } {00 64 FF} do_execsql_test 1.1 { CREATE TABLE t1(i, h); CREATE INDEX i1 ON t1(h); WITH data(a, b) AS ( SELECT 1, int2hex(1) UNION ALL SELECT a+1, int2hex(a+1) FROM data WHERE a<40 ) INSERT INTO t1 SELECT * FROM data; } {} foreach f {oom ioerr} { do_faultsim_test 1.2 -faults $f* -prep { set sql1 { SELECT i FROM t1 WHERE (i%2)==0 } set sql2 { SELECT i FROM t1 WHERE (i%2)==0 ORDER BY h } set ::s1 [sqlite3_prepare db $sql1 -1 dummy] set ::s2 [sqlite3_prepare db $sql2 -1 dummy] for {set i 0} {$i < 10} {incr i} { sqlite3_step $::s1 } for {set i 0} {$i < 3} {incr i} { sqlite3_step $::s2 } execsql { BEGIN; DELETE FROM t1 WHERE (i%2) } } -body { execsql { ROLLBACK } } -test { set res1 [list] set res2 [list] while {"SQLITE_ROW" == [sqlite3_step $::s1]} { lappend res1 [sqlite3_column_text $::s1 0] } while {"SQLITE_ROW" == [sqlite3_step $::s2]} { lappend res2 [sqlite3_column_text $::s2 0] } set rc1 [sqlite3_finalize $::s1] set rc2 [sqlite3_finalize $::s2] catchsql { ROLLBACK } if {$rc1=="SQLITE_OK" && $rc2=="SQLITE_OK" && $res1=="22 24 26 28 30 32 34 36 38 40" && $res2=="8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40" } { # This is Ok. } elseif {$rc1!="SQLITE_OK" && $rc2!="SQLITE_OK" && $res1=="" &&$res2==""} { # Also Ok. } else { error "statements don't look right" } } } finish_test |