3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
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.
16 # $Id: vtabC.test,v 1.2 2009/04/07 14:14:23 danielk1977 Exp $
18 set testdir [file dirname $argv0]
19 source $testdir/tester.tcl
26 ifcapable !trigger { finish_test ; return }
29 # N will be the number of virtual tables we have defined.
32 for {set N 1} {$N<=20} {incr N} {
34 forcedelete test.db test.db-journal
36 register_echo_module [sqlite3_connection_pointer db]
38 # Create $N tables and $N virtual tables to echo them.
40 unset -nocomplain 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
48 execsql {SELECT count(*) FROM sqlite_master}
50 do_test vtabC-1.$N.2 {
51 execsql {SELECT name FROM sqlite_master}
54 # Create a table m and add triggers to make changes on all
55 # of the virtual tables when m is changed.
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"
65 execsql {SELECT count(*) FROM sqlite_master}
67 do_test vtabC-1.$N.4 {
69 INSERT INTO m VALUES(1000);
73 for {set j 1} {$j<=$::N} {incr j} {
74 do_test vtabC-1.$N.5.$j {
75 execsql "SELECT * FROM t$::j"
77 do_test vtabC-1.$N.6.$j {
78 execsql "SELECT * FROM vt$::j"
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"
86 for {set i 1} {$i<=$::N} {incr i} {
87 append sql " INSERT INTO vt$i VALUES(NEW.a+$i*10000);\n"
91 execsql {SELECT count(*) FROM sqlite_master}
93 do_test vtabC-1.$N.8 {
95 INSERT INTO m VALUES(9000000);
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"
108 do_test vtabC-1.$N.10.$j {
109 execsql "SELECT * FROM vt$::j"
113 unset -nocomplain res N i j