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 focus of
12 # this test file is the "sqlite3_trace_v2()" and "sqlite3_expanded_sql()"
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
18 ifcapable !trace { finish_test ; return }
19 set ::testprefix trace3
21 proc trace_v2_error { args } {
22 lappend ::stmtlist(error) [string trim $args]
23 error "trace error"; # this will be ignored.
25 proc trace_v2_record { args } {
26 lappend ::stmtlist(record) [string trim $args]
28 proc trace_v2_nop { args } {}; # do nothing.
33 INSERT INTO t1 VALUES(1,NULL);
34 INSERT INTO t1 VALUES(2,-1);
35 INSERT INTO t1 VALUES(3,0);
36 INSERT INTO t1 VALUES(4,1);
37 INSERT INTO t1 VALUES(5,-2147483648);
38 INSERT INTO t1 VALUES(6,2147483647);
39 INSERT INTO t1 VALUES(7,-9223372036854775808);
40 INSERT INTO t1 VALUES(8,9223372036854775807);
41 INSERT INTO t1 VALUES(9,-1.0);
42 INSERT INTO t1 VALUES(10,0.0);
43 INSERT INTO t1 VALUES(11,1.0);
44 INSERT INTO t1 VALUES(12,'');
45 INSERT INTO t1 VALUES(13,'1');
46 INSERT INTO t1 VALUES(14,'one');
47 INSERT INTO t1 VALUES(15,x'abcd0123');
48 INSERT INTO t1 VALUES(16,x'4567cdef');
53 set rc [catch {db trace_v2 1 2 3} msg]
55 } {1 {wrong # args: should be "db trace_v2 ?CALLBACK? ?MASK?"}}
57 set rc [catch {db trace_v2 1 bad} msg]
59 } {1 {bad trace type "bad": must be statement, profile, row, or close}}
62 db trace_v2 trace_v2_nop
67 unset -nocomplain ::stmtlist
68 db trace_v2 trace_v2_nop
70 SELECT a, b FROM t1 ORDER BY a;
75 set ::stmtlist(error) {}
76 db trace_v2 trace_v2_error
78 SELECT a, b FROM t1 ORDER BY a;
81 } {/^\{-?\d+ \{SELECT a, b FROM t1 ORDER BY a;\}\}$/}
83 set ::stmtlist(record) {}
84 db trace_v2 trace_v2_record
86 SELECT a, b FROM t1 ORDER BY a;
88 set ::stmtlist(record)
89 } {/^\{-?\d+ \{SELECT a, b FROM t1 ORDER BY a;\}\}$/}
91 set ::stmtlist(record) {}
92 db trace_v2 trace_v2_record statement
94 SELECT a, b FROM t1 ORDER BY a;
96 set ::stmtlist(record)
97 } {/^\{-?\d+ \{SELECT a, b FROM t1 ORDER BY a;\}\}$/}
99 set ::stmtlist(record) {}
100 db trace_v2 trace_v2_record 1
102 SELECT a, b FROM t1 ORDER BY a;
104 set ::stmtlist(record)
105 } {/^\{-?\d+ \{SELECT a, b FROM t1 ORDER BY a;\}\}$/}
108 set ::stmtlist(record) {}
109 db trace_v2 trace_v2_record profile
111 SELECT a, b FROM t1 ORDER BY a;
113 set ::stmtlist(record)
114 } {/^\{-?\d+ -?\d+\}$/}
116 set ::stmtlist(record) {}
117 db trace_v2 trace_v2_record 2
119 SELECT a, b FROM t1 ORDER BY a;
121 set ::stmtlist(record)
122 } {/^\{-?\d+ -?\d+\}$/}
125 set ::stmtlist(record) {}
126 db trace_v2 trace_v2_record row
128 SELECT a, b FROM t1 ORDER BY a;
130 set ::stmtlist(record)
131 } "/^[string trim [string repeat {-?\d+ } 16]]\$/"
133 set ::stmtlist(record) {}
134 db trace_v2 trace_v2_record 4
136 SELECT a, b FROM t1 ORDER BY a;
138 set ::stmtlist(record)
139 } "/^[string trim [string repeat {-?\d+ } 16]]\$/"
142 set ::stmtlist(record) {}
143 db trace_v2 trace_v2_record {profile row}
145 SELECT a, b FROM t1 ORDER BY a;
147 set ::stmtlist(record)
148 } "/^[string trim [string repeat {-?\d+ } 16]] \\\{-?\\d+ -?\\d+\\\}\$/"
150 set ::stmtlist(record) {}
151 db trace_v2 trace_v2_record {statement profile row}
153 SELECT a, b FROM t1 ORDER BY a;
155 set ::stmtlist(record)
156 } "/^\\\{-?\\d+ \\\{SELECT a, b FROM t1 ORDER BY a;\\\}\\\} [string trim \
157 [string repeat {-?\d+ } 16]] \\\{-?\\d+ -?\\d+\\\}\$/"
160 set DB [sqlite3_connection_pointer db]
162 set STMT [sqlite3_prepare_v2 $DB \
163 "SELECT a, b FROM t1 WHERE b = ? ORDER BY a;" -1 TAIL]
167 list [sqlite3_bind_null $STMT 1] [sqlite3_expanded_sql $STMT]
168 } {{} {SELECT a, b FROM t1 WHERE b = NULL ORDER BY a;}}
170 list [sqlite3_bind_int $STMT 1 123] [sqlite3_expanded_sql $STMT]
171 } {{} {SELECT a, b FROM t1 WHERE b = 123 ORDER BY a;}}
173 list [sqlite3_bind_int64 $STMT 1 123] [sqlite3_expanded_sql $STMT]
174 } {{} {SELECT a, b FROM t1 WHERE b = 123 ORDER BY a;}}
176 list [sqlite3_bind_text $STMT 1 "some string" 11] \
177 [sqlite3_expanded_sql $STMT]
178 } {{} {SELECT a, b FROM t1 WHERE b = 'some string' ORDER BY a;}}
180 list [sqlite3_bind_text $STMT 1 "some 'bad' string" 17] \
181 [sqlite3_expanded_sql $STMT]
182 } {{} {SELECT a, b FROM t1 WHERE b = 'some ''bad'' string' ORDER BY a;}}
184 list [sqlite3_bind_double $STMT 1 123] [sqlite3_expanded_sql $STMT]
185 } {{} {SELECT a, b FROM t1 WHERE b = 123.0 ORDER BY a;}}
187 list [sqlite3_bind_text16 $STMT 1 \
188 [encoding convertto unicode hi\000yall\000] 16] \
189 [sqlite3_expanded_sql $STMT]
190 } {{} {SELECT a, b FROM t1 WHERE b = 'hi' ORDER BY a;}}
192 list [sqlite3_bind_blob $STMT 1 "\x12\x34\x56" 3] \
193 [sqlite3_expanded_sql $STMT]
194 } {{} {SELECT a, b FROM t1 WHERE b = x'123456' ORDER BY a;}}
196 list [sqlite3_bind_blob $STMT 1 "\xAB\xCD\xEF" 3] \
197 [sqlite3_expanded_sql $STMT]
198 } {{} {SELECT a, b FROM t1 WHERE b = x'abcdef' ORDER BY a;}}
201 sqlite3_finalize $STMT
204 do_test trace3-10.1 {
208 do_test trace3-10.2 {
209 unset -nocomplain ::stmtlist
210 db trace_v2 "" {statement profile row}
212 SELECT a, b FROM t1 ORDER BY a;
217 do_test trace3-11.1 {
218 set ::stmtlist(record) {}
219 db trace_v2 trace_v2_record close
221 set ::stmtlist(record)
226 do_test trace3-11.2 {
227 set ::stmtlist(record) {}
228 db trace_v2 trace_v2_record 8
230 set ::stmtlist(record)