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