OLD | NEW |
(Empty) | |
| 1 # 2014 November 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 |
| 13 set testdir [file dirname $argv0] |
| 14 source $testdir/tester.tcl |
| 15 set ::testprefix rollback2 |
| 16 |
| 17 proc int2hex {i} { format %.2X $i } |
| 18 db func int2hex int2hex |
| 19 |
| 20 do_execsql_test 1.0 { |
| 21 SELECT int2hex(0), int2hex(100), int2hex(255) |
| 22 } {00 64 FF} |
| 23 do_execsql_test 1.1 { |
| 24 CREATE TABLE t1(i, h); |
| 25 CREATE INDEX i1 ON t1(h); |
| 26 WITH data(a, b) AS ( |
| 27 SELECT 1, int2hex(1) |
| 28 UNION ALL |
| 29 SELECT a+1, int2hex(a+1) FROM data WHERE a<40 |
| 30 ) |
| 31 INSERT INTO t1 SELECT * FROM data; |
| 32 } {} |
| 33 |
| 34 |
| 35 proc do_rollback_test {tn args} { |
| 36 set A(-setup) "" |
| 37 set A(-select) "" |
| 38 set A(-result) "" |
| 39 set A(-rollback) ROLLBACK |
| 40 |
| 41 array set O $args |
| 42 foreach k [array names O] { |
| 43 if {[info exists A($k)]==0} { error "unknown option: $k" } |
| 44 set A($k) $O($k) |
| 45 } |
| 46 |
| 47 for {set iRollback 0} 1 {incr iRollback} { |
| 48 catch { db eval ROLLBACK } |
| 49 set res [list] |
| 50 db eval $A(-setup) |
| 51 |
| 52 set i 0 |
| 53 db eval $A(-select) x { |
| 54 if {$i==$iRollback} { db eval $A(-rollback) } |
| 55 foreach k $x(*) { lappend res $x($k) } |
| 56 incr i |
| 57 } |
| 58 |
| 59 do_test $tn.$iRollback [list set {} $res] [list {*}$A(-result)] |
| 60 if {$i < $iRollback} break |
| 61 } |
| 62 } |
| 63 |
| 64 do_rollback_test 2 -setup { |
| 65 BEGIN; |
| 66 DELETE FROM t1 WHERE (i%2)==1; |
| 67 } -select { |
| 68 SELECT i FROM t1 WHERE (i%2)==0 |
| 69 } -result { |
| 70 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 |
| 71 } |
| 72 |
| 73 finish_test |
| 74 |
OLD | NEW |