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