1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
# 2011 Jan 21
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests for the "sqlite3_trace()" API. Specifically,
# it tests the special handling of nested SQL statements (those executed
# by virtual table or user function callbacks). These statements are treated
# differently in two respects:
#
# 1. Each line of the statement is prefixed with "-- " to turn it into
# an SQL comment.
#
# 2. Parameter expansion is not performed.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
ifcapable !trace { finish_test ; return }
set ::testprefix trace2
proc sql {zSql} { db one $zSql }
proc trace {zSql} { lappend ::trace $zSql }
db func sql sql
db trace trace
proc do_trace_test {tn sql expected} {
# Test that the list of string passed to the trace callback when $sql
# is executed is equivalent to the list of strings in $expected.
#
set ::trace [list]
execsql $sql
uplevel do_test $tn [list {set ::trace}] [list [list {*}$expected]]
}
proc do_trace_select_test {tn sql expected} {
uplevel [list do_trace_test ${tn}.a $sql $expected]
# Now execute each SQL statement passed to the trace callback in the
# block above. Check that this causes the same set of strings to be
# passed to the trace callback again. i.e. that executing the output
# of the trace callback is equivalent to the SQL script in $sql.
#
set sqllist $::trace
set ::trace [list]
foreach item $sqllist { execsql $item }
uplevel do_test $tn.b [list {set ::trace}] [list $sqllist]
}
do_trace_select_test 1.1 {
SELECT 1, 2, 3;
} {
"SELECT 1, 2, 3;"
}
do_trace_select_test 1.2 {
SELECT sql('SELECT 1, 2, 3');
} {
"SELECT sql('SELECT 1, 2, 3');"
"-- SELECT 1, 2, 3"
}
do_trace_select_test 1.3 {
SELECT sql('SELECT 1,
2,
3'
);
} {
"SELECT sql('SELECT 1,
2,
3'
);"
"-- SELECT 1,
-- 2,
-- 3"
}
do_trace_select_test 1.4 {
SELECT sql('SELECT 1,
3'
);
} {
"SELECT sql('SELECT 1,
3'
);"
"-- SELECT 1,
--
--
-- 3"
}
do_trace_select_test 1.5 {
SELECT $var, sql('SELECT 1,
$var,
3'
);
} {
"SELECT NULL, sql('SELECT 1,
$var,
3'
);"
"-- SELECT 1,
-- $var,
-- 3"
}
ifcapable fts3 {
do_execsql_test 2.1 {
CREATE VIRTUAL TABLE x1 USING fts4;
INSERT INTO x1 VALUES('Cloudy, with a high near 16');
INSERT INTO x1 VALUES('Wind chill values as low as -13');
}
do_trace_test 2.2 {
INSERT INTO x1 VALUES('North northwest wind between 8 and 14 mph');
} {
"INSERT INTO x1 VALUES('North northwest wind between 8 and 14 mph');"
"-- DELETE FROM 'main'.'x1_segdir' WHERE level = ?"
"-- INSERT INTO 'main'.'x1_content' VALUES(?,(?))"
"-- REPLACE INTO 'main'.'x1_docsize' VALUES(?,?)"
"-- SELECT value FROM 'main'.'x1_stat' WHERE id=?"
"-- REPLACE INTO 'main'.'x1_stat' VALUES(?,?)"
"-- SELECT (SELECT max(idx) FROM 'main'.'x1_segdir' WHERE level = ?) + 1"
"-- SELECT coalesce((SELECT max(blockid) FROM 'main'.'x1_segments') + 1, 1)"
"-- REPLACE INTO 'main'.'x1_segdir' VALUES(?,?,?,?,?,?)"
"-- SELECT level, idx, end_block FROM 'main'.'x1_segdir' WHERE level BETWEEN ? AND ? ORDER BY level DESC, idx ASC"
}
do_trace_test 2.3 {
INSERT INTO x1(x1) VALUES('optimize');
} {
"INSERT INTO x1(x1) VALUES('optimize');"
"-- SELECT ? UNION SELECT level / (1024 * ?) FROM 'main'.'x1_segdir'"
"-- SELECT idx, start_block, leaves_end_block, end_block, root FROM 'main'.'x1_segdir' WHERE level BETWEEN ? AND ?ORDER BY level DESC, idx ASC"
"-- SELECT max(level) FROM 'main'.'x1_segdir' WHERE level BETWEEN ? AND ?"
"-- SELECT coalesce((SELECT max(blockid) FROM 'main'.'x1_segments') + 1, 1)"
"-- DELETE FROM 'main'.'x1_segdir' WHERE level BETWEEN ? AND ?"
"-- REPLACE INTO 'main'.'x1_segdir' VALUES(?,?,?,?,?,?)"
}
}
finish_test
|