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 is on testing the following virtual table methods:
19 # $Id: vtab4.test,v 1.3 2008/07/12 14:52:21 drh Exp $
21 set testdir [file dirname $argv0]
22 source $testdir/tester.tcl
24 unset -nocomplain echo_module
25 unset -nocomplain echo_module_sync_fail
32 # Register the echo module
34 register_echo_module [sqlite3_connection_pointer db]
38 CREATE TABLE treal(a PRIMARY KEY, b, c);
39 CREATE VIRTUAL TABLE techo USING echo(treal);
43 # Test an INSERT, UPDATE and DELETE statement on the virtual table
44 # in an implicit transaction. Each should result in a single call
45 # to xBegin, xSync and xCommit.
48 set echo_module [list]
50 INSERT INTO techo VALUES(1, 2, 3);
53 } {xBegin echo(treal) xSync echo(treal) xCommit echo(treal)}
55 set echo_module [list]
57 UPDATE techo SET a = 2;
60 } [list xBestIndex {SELECT rowid, a, b, c FROM 'treal'} \
62 xFilter {SELECT rowid, a, b, c FROM 'treal'} \
67 set echo_module [list]
72 } [list xBestIndex {SELECT rowid, NULL, NULL, NULL FROM 'treal'} \
74 xFilter {SELECT rowid, NULL, NULL, NULL FROM 'treal'} \
79 # Ensure xBegin is not called more than once in a single transaction.
82 set echo_module [list]
85 INSERT INTO techo VALUES(1, 2, 3);
86 INSERT INTO techo VALUES(4, 5, 6);
87 INSERT INTO techo VALUES(7, 8, 9);
91 } {xBegin echo(treal) xSync echo(treal) xCommit echo(treal)}
93 # Try a transaction with two virtual tables.
97 CREATE TABLE sreal(a, b, c UNIQUE);
98 CREATE VIRTUAL TABLE secho USING echo(sreal);
100 set echo_module [list]
103 INSERT INTO secho SELECT * FROM techo;
108 } [list xBestIndex {SELECT rowid, a, b, c FROM 'treal'} \
110 xFilter {SELECT rowid, a, b, c FROM 'treal'} \
111 xBestIndex {SELECT rowid, NULL, NULL, NULL FROM 'treal'} \
113 xFilter {SELECT rowid, NULL, NULL, NULL FROM 'treal'} \
116 xCommit echo(sreal) \
117 xCommit echo(treal) \
123 } {1 2 3 4 5 6 7 8 9}
130 # Try an explicit ROLLBACK on a transaction with two open virtual tables.
132 set echo_module [list]
135 INSERT INTO techo SELECT * FROM secho;
140 } [list xBestIndex {SELECT rowid, a, b, c FROM 'sreal'} \
142 xFilter {SELECT rowid, a, b, c FROM 'sreal'} \
143 xBestIndex {SELECT rowid, NULL, NULL, NULL FROM 'sreal'} \
145 xFilter {SELECT rowid, NULL, NULL, NULL FROM 'sreal'} \
146 xRollback echo(treal) \
147 xRollback echo(sreal) \
153 } {1 2 3 4 5 6 7 8 9}
161 set echo_module [list]
162 set echo_module_sync_fail treal
164 INSERT INTO techo VALUES(1, 2, 3);
166 } {1 {unknown error}}
169 } {xBegin echo(treal) xSync echo(treal) xRollback echo(treal)}
172 set echo_module [list]
173 set echo_module_sync_fail sreal
176 INSERT INTO techo SELECT * FROM secho;
181 } [list xBestIndex {SELECT rowid, a, b, c FROM 'sreal'} \
183 xFilter {SELECT rowid, a, b, c FROM 'sreal'} \
184 xBestIndex {SELECT rowid, NULL, NULL, NULL FROM 'sreal'} \
186 xFilter {SELECT rowid, NULL, NULL, NULL FROM 'sreal'} \
189 xRollback echo(treal) \
190 xRollback echo(sreal) \