OLD | NEW |
(Empty) | |
| 1 # 2008 April 10 |
| 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 # This file implements regression tests for SQLite library. The |
| 12 # focus of this file is is verifying that the xUpdate, xSync, xCommit |
| 13 # and xRollback methods are only invoked after an xBegin or xCreate. |
| 14 # Ticket #3083. |
| 15 # |
| 16 # $Id: vtabC.test,v 1.2 2009/04/07 14:14:23 danielk1977 Exp $ |
| 17 |
| 18 set testdir [file dirname $argv0] |
| 19 source $testdir/tester.tcl |
| 20 |
| 21 ifcapable !vtab { |
| 22 finish_test |
| 23 return |
| 24 } |
| 25 |
| 26 ifcapable !trigger { finish_test ; return } |
| 27 |
| 28 |
| 29 # N will be the number of virtual tables we have defined. |
| 30 # |
| 31 unset -nocomplain N |
| 32 for {set N 1} {$N<=20} {incr N} { |
| 33 db close |
| 34 file delete -force test.db test.db-journal |
| 35 sqlite3 db test.db |
| 36 register_echo_module [sqlite3_connection_pointer db] |
| 37 |
| 38 # Create $N tables and $N virtual tables to echo them. |
| 39 # |
| 40 unset -nocomplain tablist |
| 41 set tablist {} |
| 42 do_test vtabC-1.$N.1 { |
| 43 for {set i 1} {$i<=$::N} {incr i} { |
| 44 execsql "CREATE TABLE t${i}(x)" |
| 45 execsql "CREATE VIRTUAL TABLE vt$i USING echo(t$i)" |
| 46 lappend ::tablist t$i vt$i |
| 47 } |
| 48 execsql {SELECT count(*) FROM sqlite_master} |
| 49 } [expr {$N*2}] |
| 50 do_test vtabC-1.$N.2 { |
| 51 execsql {SELECT name FROM sqlite_master} |
| 52 } $tablist |
| 53 |
| 54 # Create a table m and add triggers to make changes on all |
| 55 # of the virtual tables when m is changed. |
| 56 # |
| 57 do_test vtabC-1.$N.3 { |
| 58 execsql {CREATE TABLE m(a)} |
| 59 set sql "CREATE TRIGGER rins AFTER INSERT ON m BEGIN\n" |
| 60 for {set i 1} {$i<=$::N} {incr i} { |
| 61 append sql " INSERT INTO vt$i VALUES(NEW.a+$i);\n" |
| 62 } |
| 63 append sql "END;" |
| 64 execsql $sql |
| 65 execsql {SELECT count(*) FROM sqlite_master} |
| 66 } [expr {$N*2+2}] |
| 67 do_test vtabC-1.$N.4 { |
| 68 execsql { |
| 69 INSERT INTO m VALUES(1000); |
| 70 SELECT * FROM m; |
| 71 } |
| 72 } {1000} |
| 73 for {set j 1} {$j<=$::N} {incr j} { |
| 74 do_test vtabC-1.$N.5.$j { |
| 75 execsql "SELECT * FROM t$::j" |
| 76 } [expr {$j+1000}] |
| 77 do_test vtabC-1.$N.6.$j { |
| 78 execsql "SELECT * FROM vt$::j" |
| 79 } [expr {$j+1000}] |
| 80 } |
| 81 do_test vtabC-1.$N.7 { |
| 82 set sql "CREATE TRIGGER rins2 BEFORE INSERT ON m BEGIN\n" |
| 83 for {set i 1} {$i<=$::N} {incr i} { |
| 84 append sql " INSERT INTO vt$i VALUES(NEW.a+$i*100);\n" |
| 85 } |
| 86 for {set i 1} {$i<=$::N} {incr i} { |
| 87 append sql " INSERT INTO vt$i VALUES(NEW.a+$i*10000);\n" |
| 88 } |
| 89 append sql "END;" |
| 90 execsql $sql |
| 91 execsql {SELECT count(*) FROM sqlite_master} |
| 92 } [expr {$N*2+3}] |
| 93 do_test vtabC-1.$N.8 { |
| 94 execsql { |
| 95 INSERT INTO m VALUES(9000000); |
| 96 SELECT * FROM m; |
| 97 } |
| 98 } {1000 9000000} |
| 99 unset -nocomplain res |
| 100 for {set j 1} {$j<=$::N} {incr j} { |
| 101 set res [expr {$j+1000}] |
| 102 lappend res [expr {$j*100+9000000}] |
| 103 lappend res [expr {$j*10000+9000000}] |
| 104 lappend res [expr {$j+9000000}] |
| 105 do_test vtabC-1.$N.9.$j { |
| 106 execsql "SELECT * FROM t$::j" |
| 107 } $res |
| 108 do_test vtabC-1.$N.10.$j { |
| 109 execsql "SELECT * FROM vt$::j" |
| 110 } $res |
| 111 } |
| 112 } |
| 113 unset -nocomplain res N i j |
| 114 |
| 115 |
| 116 finish_test |
OLD | NEW |