Update test file walprotocol.test to account for the changes in the wal
[sqlite.git] / test / trace2.test
bloba3f0aeb878004104894099ddc80abd364b633a0d
1 # 2011 Jan 21
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
19 #      an SQL comment.
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 }
32 db func sql sql
33 db trace trace
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.
38   #
39   set ::trace [list]
40   execsql $sql
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.
52   #
53   set sqllist $::trace
54   set ::trace [list]
55   foreach item $sqllist { execsql $item }
56   uplevel do_test $tn.b [list {set ::trace}] [list $sqllist]
59 do_trace_select_test 1.1  {
60   SELECT 1, 2, 3;
61 } {
62   "SELECT 1, 2, 3;"
65 do_trace_select_test 1.2  {
66   SELECT sql('SELECT 1, 2, 3');
67 } {
68   "SELECT sql('SELECT 1, 2, 3');"
69   "-- SELECT 1, 2, 3"
72 do_trace_select_test 1.3  {
73   SELECT sql('SELECT 1, 
74     2, 
75     3'
76   );
77 } {
78   "SELECT sql('SELECT 1, 
79     2, 
80     3'
81   );"
82   "-- SELECT 1, 
83 --     2, 
84 --     3"
87 do_trace_select_test 1.4  {
88   SELECT sql('SELECT 1, 
91     3'
92   );
93 } {
94   "SELECT sql('SELECT 1, 
97     3'
98   );"
99   "-- SELECT 1, 
100 -- 
101 -- 
102 --     3"
105 do_trace_select_test 1.5  {
106   SELECT $var, sql('SELECT 1, 
107     $var, 
108     3'
109   );
110 } {
111   "SELECT NULL, sql('SELECT 1, 
112     $var, 
113     3'
114   );"
115   "-- SELECT 1, 
116 --     $var, 
117 --     3"
120 ifcapable fts3 {
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');
125   }
127   do_trace_test 2.2 {
128     INSERT INTO x1 VALUES('North northwest wind between 8 and 14 mph');
129   } {
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"
140   }
142   do_trace_test 2.3 {
143     INSERT INTO x1(x1) VALUES('optimize');
144   } {
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(?,?,?,?,?,?)"
152   }
155 finish_test