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.
13 # This file implements tests for the "sqlite3_trace()" API. Specifically,
14 # it tests the special handling of nested SQL statements (those executed
15 # by virtual table or user function callbacks). These statements are treated
16 # differently in two respects:
18 # 1. Each line of the statement is prefixed with "-- " to turn it into
21 # 2. Parameter expansion is not performed.
24 set testdir [file dirname $argv0]
25 source $testdir/tester.tcl
26 ifcapable !trace { finish_test ; return }
27 set ::testprefix trace2
29 proc sql {zSql} { db one $zSql }
30 proc trace {zSql} { lappend ::trace $zSql }
35 proc do_trace_test {tn sql expected} {
36 # Test that the list of string passed to the trace callback when $sql
37 # is executed is equivalent to the list of strings in $expected.
41 uplevel do_test $tn [list {set ::trace}] [list [list {*}$expected]]
44 proc do_trace_select_test {tn sql expected} {
46 uplevel [list do_trace_test ${tn}.a $sql $expected]
48 # Now execute each SQL statement passed to the trace callback in the
49 # block above. Check that this causes the same set of strings to be
50 # passed to the trace callback again. i.e. that executing the output
51 # of the trace callback is equivalent to the SQL script in $sql.
55 foreach item $sqllist { execsql $item }
56 uplevel do_test $tn.b [list {set ::trace}] [list $sqllist]
59 do_trace_select_test 1.1 {
65 do_trace_select_test 1.2 {
66 SELECT sql('SELECT 1, 2, 3');
68 "SELECT sql('SELECT 1, 2, 3');"
72 do_trace_select_test 1.3 {
78 "SELECT sql('SELECT 1,
87 do_trace_select_test 1.4 {
94 "SELECT sql('SELECT 1,
105 do_trace_select_test 1.5 {
106 SELECT $var, sql('SELECT 1,
111 "SELECT NULL, sql('SELECT 1,
121 do_execsql_test 2.1 {
122 CREATE VIRTUAL TABLE x1 USING fts4;
123 INSERT INTO x1 VALUES('Cloudy, with a high near 16');
124 INSERT INTO x1 VALUES('Wind chill values as low as -13');
128 INSERT INTO x1 VALUES('North northwest wind between 8 and 14 mph');
130 "INSERT INTO x1 VALUES('North northwest wind between 8 and 14 mph');"
131 "-- DELETE FROM 'main'.'x1_segdir' WHERE level = ?"
132 "-- INSERT INTO 'main'.'x1_content' VALUES(?,(?))"
133 "-- REPLACE INTO 'main'.'x1_docsize' VALUES(?,?)"
134 "-- SELECT value FROM 'main'.'x1_stat' WHERE id=?"
135 "-- REPLACE INTO 'main'.'x1_stat' VALUES(?,?)"
136 "-- SELECT (SELECT max(idx) FROM 'main'.'x1_segdir' WHERE level = ?) + 1"
137 "-- SELECT coalesce((SELECT max(blockid) FROM 'main'.'x1_segments') + 1, 1)"
138 "-- REPLACE INTO 'main'.'x1_segdir' VALUES(?,?,?,?,?,?)"
139 "-- SELECT level, idx, end_block FROM 'main'.'x1_segdir' WHERE level BETWEEN ? AND ? ORDER BY level DESC, idx ASC"
143 INSERT INTO x1(x1) VALUES('optimize');
145 "INSERT INTO x1(x1) VALUES('optimize');"
146 "-- SELECT ? UNION SELECT level / (1024 * ?) FROM 'main'.'x1_segdir'"
147 "-- SELECT idx, start_block, leaves_end_block, end_block, root FROM 'main'.'x1_segdir' WHERE level BETWEEN ? AND ?ORDER BY level DESC, idx ASC"
148 "-- SELECT max(level) FROM 'main'.'x1_segdir' WHERE level BETWEEN ? AND ?"
149 "-- SELECT coalesce((SELECT max(blockid) FROM 'main'.'x1_segments') + 1, 1)"
150 "-- DELETE FROM 'main'.'x1_segdir' WHERE level BETWEEN ? AND ?"
151 "-- REPLACE INTO 'main'.'x1_segdir' VALUES(?,?,?,?,?,?)"