aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/sqlite/unix/sqlite-3.5.1/test/vtab7.test
diff options
context:
space:
mode:
authordan miller2007-10-20 02:49:29 +0000
committerdan miller2007-10-20 02:49:29 +0000
commite36d23a85ebff914d74bb541558c2b6082b78edb (patch)
tree54b58fdf162e78af64055282a6035c8d2443389d /libraries/sqlite/unix/sqlite-3.5.1/test/vtab7.test
parent* Fixed an issue whereby avatar chat distances were being calculated against ... (diff)
downloadopensim-SC-e36d23a85ebff914d74bb541558c2b6082b78edb.zip
opensim-SC-e36d23a85ebff914d74bb541558c2b6082b78edb.tar.gz
opensim-SC-e36d23a85ebff914d74bb541558c2b6082b78edb.tar.bz2
opensim-SC-e36d23a85ebff914d74bb541558c2b6082b78edb.tar.xz
sqlite source (unix build) added to libraries
Diffstat (limited to 'libraries/sqlite/unix/sqlite-3.5.1/test/vtab7.test')
-rw-r--r--libraries/sqlite/unix/sqlite-3.5.1/test/vtab7.test199
1 files changed, 199 insertions, 0 deletions
diff --git a/libraries/sqlite/unix/sqlite-3.5.1/test/vtab7.test b/libraries/sqlite/unix/sqlite-3.5.1/test/vtab7.test
new file mode 100644
index 0000000..5aeb66c
--- /dev/null
+++ b/libraries/sqlite/unix/sqlite-3.5.1/test/vtab7.test
@@ -0,0 +1,199 @@
1# 2006 July 25
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 focus
12# of this test is reading and writing to the database from within a
13# virtual table xSync() callback.
14#
15# $Id: vtab7.test,v 1.2 2006/07/26 16:22:16 danielk1977 Exp $
16
17set testdir [file dirname $argv0]
18source $testdir/tester.tcl
19
20ifcapable !vtab {
21 finish_test
22 return
23}
24
25# Register the echo module. Code inside the echo module appends elements
26# to the global tcl list variable ::echo_module whenever SQLite invokes
27# certain module callbacks. This includes the xSync(), xCommit() and
28# xRollback() callbacks. For each of these callback, two elements are
29# appended to ::echo_module, as follows:
30#
31# Module method Elements appended to ::echo_module
32# -------------------------------------------------------
33# xSync() xSync echo($tablename)
34# xCommit() xCommit echo($tablename)
35# xRollback() xRollback echo($tablename)
36# -------------------------------------------------------
37#
38# In each case, $tablename is replaced by the name of the real table (not
39# the echo table). By setting up a tcl trace on the ::echo_module variable,
40# code in this file arranges for a Tcl script to be executed from within
41# the echo module xSync() callback.
42#
43register_echo_module [sqlite3_connection_pointer db]
44trace add variable ::echo_module write echo_module_trace
45
46# This Tcl proc is invoked whenever the ::echo_module variable is written.
47#
48proc echo_module_trace {args} {
49 # Filter out writes to ::echo_module that are not xSync, xCommit or
50 # xRollback callbacks.
51 if {[llength $::echo_module] < 2} return
52 set x [lindex $::echo_module end-1]
53 if {$x ne "xSync" && $x ne "xCommit" && $x ne "xRollback"} return
54
55 regexp {^echo.(.*).$} [lindex $::echo_module end] dummy tablename
56 # puts "Ladies and gentlemen, an $x on $tablename!"
57
58 if {[info exists ::callbacks($x,$tablename)]} {
59 eval $::callbacks($x,$tablename)
60 }
61}
62
63# The following tests, vtab7-1.*, test that the trace callback on
64# ::echo_module is providing the expected tcl callbacks.
65do_test vtab7-1.1 {
66 execsql {
67 CREATE TABLE abc(a, b, c);
68 CREATE VIRTUAL TABLE abc2 USING echo(abc);
69 }
70} {}
71
72do_test vtab7-1.2 {
73 set ::callbacks(xSync,abc) {incr ::counter}
74 set ::counter 0
75 execsql {
76 INSERT INTO abc2 VALUES(1, 2, 3);
77 }
78 set ::counter
79} {1}
80
81# Write to an existing database table from within an xSync callback.
82do_test vtab7-2.1 {
83 set ::callbacks(xSync,abc) {
84 execsql {INSERT INTO log VALUES('xSync');}
85 }
86 execsql {
87 CREATE TABLE log(msg);
88 INSERT INTO abc2 VALUES(4, 5, 6);
89 SELECT * FROM log;
90 }
91} {xSync}
92do_test vtab7-2.3 {
93 execsql {
94 INSERT INTO abc2 VALUES(4, 5, 6);
95 SELECT * FROM log;
96 }
97} {xSync xSync}
98do_test vtab7-2.4 {
99 execsql {
100 INSERT INTO abc2 VALUES(4, 5, 6);
101 SELECT * FROM log;
102 }
103} {xSync xSync xSync}
104
105# Create a database table from within xSync callback.
106do_test vtab7-2.5 {
107 set ::callbacks(xSync,abc) {
108 execsql { CREATE TABLE newtab(d, e, f); }
109 }
110 execsql {
111 INSERT INTO abc2 VALUES(1, 2, 3);
112 SELECT name FROM sqlite_master ORDER BY name;
113 }
114} {abc abc2 log newtab}
115
116# Drop a database table from within xSync callback.
117do_test vtab7-2.6 {
118 set ::callbacks(xSync,abc) {
119 execsql { DROP TABLE newtab }
120 }
121 execsql {
122 INSERT INTO abc2 VALUES(1, 2, 3);
123 SELECT name FROM sqlite_master ORDER BY name;
124 }
125} {abc abc2 log}
126
127# Write to an attached database from xSync().
128do_test vtab7-3.1 {
129 file delete -force test2.db
130 file delete -force test2.db-journal
131 execsql {
132 ATTACH 'test2.db' AS db2;
133 CREATE TABLE db2.stuff(description, shape, color);
134 }
135 set ::callbacks(xSync,abc) {
136 execsql { INSERT INTO db2.stuff VALUES('abc', 'square', 'green'); }
137 }
138 execsql {
139 INSERT INTO abc2 VALUES(1, 2, 3);
140 SELECT * from stuff;
141 }
142} {abc square green}
143
144# UPDATE: The next test passes, but leaks memory. So leave it out.
145#
146# The following tests test that writing to the database from within
147# the xCommit callback causes a misuse error.
148# do_test vtab7-4.1 {
149# unset -nocomplain ::callbacks(xSync,abc)
150# set ::callbacks(xCommit,abc) {
151# execsql { INSERT INTO log VALUES('hello') }
152# }
153# catchsql {
154# INSERT INTO abc2 VALUES(1, 2, 3);
155# }
156# } {1 {library routine called out of sequence}}
157
158# These tests, vtab7-4.*, test that an SQLITE_LOCKED error is returned
159# if an attempt to write to a virtual module table or create a new
160# virtual table from within an xSync() callback.
161do_test vtab7-4.1 {
162 execsql {
163 CREATE TABLE def(d, e, f);
164 CREATE VIRTUAL TABLE def2 USING echo(def);
165 }
166 set ::callbacks(xSync,abc) {
167 set ::error [catchsql { INSERT INTO def2 VALUES(1, 2, 3) }]
168 }
169 execsql {
170 INSERT INTO abc2 VALUES(1, 2, 3);
171 }
172 set ::error
173} {1 {database table is locked}}
174do_test vtab7-4.2 {
175 set ::callbacks(xSync,abc) {
176 set ::error [catchsql { CREATE VIRTUAL TABLE def3 USING echo(def) }]
177 }
178 execsql {
179 INSERT INTO abc2 VALUES(1, 2, 3);
180 }
181 set ::error
182} {1 {database table is locked}}
183
184do_test vtab7-4.3 {
185 set ::callbacks(xSync,abc) {
186 set ::error [catchsql { DROP TABLE def2 }]
187 }
188 execsql {
189 INSERT INTO abc2 VALUES(1, 2, 3);
190 SELECT name FROM sqlite_master ORDER BY name;
191 }
192 set ::error
193} {1 {database table is locked}}
194
195trace remove variable ::echo_module write echo_module_trace
196unset -nocomplain ::callbacks
197
198finish_test
199