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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
|
# 2016 July 14
#
# 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. The focus of
# this test file is the "sqlite3_trace_v2()" and "sqlite3_expanded_sql()"
# APIs.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
ifcapable !trace { finish_test ; return }
set ::testprefix trace3
proc trace_v2_error { args } {
lappend ::stmtlist(error) [string trim $args]
error "trace error"; # this will be ignored.
}
proc trace_v2_record { args } {
lappend ::stmtlist(record) [string trim $args]
}
proc trace_v2_nop { args } {}; # do nothing.
do_test trace3-1.0 {
execsql {
CREATE TABLE t1(a,b);
INSERT INTO t1 VALUES(1,NULL);
INSERT INTO t1 VALUES(2,-1);
INSERT INTO t1 VALUES(3,0);
INSERT INTO t1 VALUES(4,1);
INSERT INTO t1 VALUES(5,-2147483648);
INSERT INTO t1 VALUES(6,2147483647);
INSERT INTO t1 VALUES(7,-9223372036854775808);
INSERT INTO t1 VALUES(8,9223372036854775807);
INSERT INTO t1 VALUES(9,-1.0);
INSERT INTO t1 VALUES(10,0.0);
INSERT INTO t1 VALUES(11,1.0);
INSERT INTO t1 VALUES(12,'');
INSERT INTO t1 VALUES(13,'1');
INSERT INTO t1 VALUES(14,'one');
INSERT INTO t1 VALUES(15,x'abcd0123');
INSERT INTO t1 VALUES(16,x'4567cdef');
}
} {}
do_test trace3-1.1 {
set rc [catch {db trace_v2 1 2 3} msg]
lappend rc $msg
} {1 {wrong # args: should be "db trace_v2 ?CALLBACK? ?MASK?"}}
do_test trace3-1.2 {
set rc [catch {db trace_v2 1 bad} msg]
lappend rc $msg
} {1 {bad trace type "bad": must be statement, profile, row, or close}}
do_test trace3-2.1 {
db trace_v2 trace_v2_nop
db trace_v2
} {trace_v2_nop}
do_test trace3-3.1 {
unset -nocomplain ::stmtlist
db trace_v2 trace_v2_nop
execsql {
SELECT a, b FROM t1 ORDER BY a;
}
array get ::stmtlist
} {}
do_test trace3-3.2 {
set ::stmtlist(error) {}
db trace_v2 trace_v2_error
execsql {
SELECT a, b FROM t1 ORDER BY a;
}
set ::stmtlist(error)
} {/^\{-?\d+ \{SELECT a, b FROM t1 ORDER BY a;\}\}$/}
do_test trace3-3.3 {
set ::stmtlist(record) {}
db trace_v2 trace_v2_record
execsql {
SELECT a, b FROM t1 ORDER BY a;
}
set ::stmtlist(record)
} {/^\{-?\d+ \{SELECT a, b FROM t1 ORDER BY a;\}\}$/}
do_test trace3-3.4 {
set ::stmtlist(record) {}
db trace_v2 trace_v2_record statement
execsql {
SELECT a, b FROM t1 ORDER BY a;
}
set ::stmtlist(record)
} {/^\{-?\d+ \{SELECT a, b FROM t1 ORDER BY a;\}\}$/}
do_test trace3-3.5 {
set ::stmtlist(record) {}
db trace_v2 trace_v2_record 1
execsql {
SELECT a, b FROM t1 ORDER BY a;
}
set ::stmtlist(record)
} {/^\{-?\d+ \{SELECT a, b FROM t1 ORDER BY a;\}\}$/}
do_test trace3-4.1 {
set ::stmtlist(record) {}
db trace_v2 trace_v2_record profile
execsql {
SELECT a, b FROM t1 ORDER BY a;
}
set ::stmtlist(record)
} {/^\{-?\d+ -?\d+\}$/}
do_test trace3-4.2 {
set ::stmtlist(record) {}
db trace_v2 trace_v2_record 2
execsql {
SELECT a, b FROM t1 ORDER BY a;
}
set ::stmtlist(record)
} {/^\{-?\d+ -?\d+\}$/}
do_test trace3-5.1 {
set ::stmtlist(record) {}
db trace_v2 trace_v2_record row
execsql {
SELECT a, b FROM t1 ORDER BY a;
}
set ::stmtlist(record)
} "/^[string trim [string repeat {-?\d+ } 16]]\$/"
do_test trace3-5.2 {
set ::stmtlist(record) {}
db trace_v2 trace_v2_record 4
execsql {
SELECT a, b FROM t1 ORDER BY a;
}
set ::stmtlist(record)
} "/^[string trim [string repeat {-?\d+ } 16]]\$/"
do_test trace3-6.1 {
set ::stmtlist(record) {}
db trace_v2 trace_v2_record {profile row}
execsql {
SELECT a, b FROM t1 ORDER BY a;
}
set ::stmtlist(record)
} "/^[string trim [string repeat {-?\d+ } 16]] \\\{-?\\d+ -?\\d+\\\}\$/"
do_test trace3-6.2 {
set ::stmtlist(record) {}
db trace_v2 trace_v2_record {statement profile row}
execsql {
SELECT a, b FROM t1 ORDER BY a;
}
set ::stmtlist(record)
} "/^\\\{-?\\d+ \\\{SELECT a, b FROM t1 ORDER BY a;\\\}\\\} [string trim \
[string repeat {-?\d+ } 16]] \\\{-?\\d+ -?\\d+\\\}\$/"
do_test trace3-7.1 {
set DB [sqlite3_connection_pointer db]
set STMT [sqlite3_prepare_v2 $DB \
"SELECT a, b FROM t1 WHERE b = ? ORDER BY a;" -1 TAIL]
} {/^[0-9A-Fa-f]+$/}
do_test trace3-8.1 {
list [sqlite3_bind_null $STMT 1] [sqlite3_expanded_sql $STMT]
} {{} {SELECT a, b FROM t1 WHERE b = NULL ORDER BY a;}}
do_test trace3-8.2 {
list [sqlite3_bind_int $STMT 1 123] [sqlite3_expanded_sql $STMT]
} {{} {SELECT a, b FROM t1 WHERE b = 123 ORDER BY a;}}
do_test trace3-8.3 {
list [sqlite3_bind_int64 $STMT 1 123] [sqlite3_expanded_sql $STMT]
} {{} {SELECT a, b FROM t1 WHERE b = 123 ORDER BY a;}}
do_test trace3-8.4 {
list [sqlite3_bind_text $STMT 1 "some string" 11] \
[sqlite3_expanded_sql $STMT]
} {{} {SELECT a, b FROM t1 WHERE b = 'some string' ORDER BY a;}}
do_test trace3-8.5 {
list [sqlite3_bind_text $STMT 1 "some 'bad' string" 17] \
[sqlite3_expanded_sql $STMT]
} {{} {SELECT a, b FROM t1 WHERE b = 'some ''bad'' string' ORDER BY a;}}
do_test trace3-8.6 {
list [sqlite3_bind_double $STMT 1 123] [sqlite3_expanded_sql $STMT]
} {{} {SELECT a, b FROM t1 WHERE b = 123.0 ORDER BY a;}}
do_test trace3-8.7 {
list [sqlite3_bind_text16 $STMT 1 \
[encoding convertto unicode hi\000yall\000] 16] \
[sqlite3_expanded_sql $STMT]
} {{} {SELECT a, b FROM t1 WHERE b = 'hi' ORDER BY a;}}
do_test trace3-8.8 {
list [sqlite3_bind_blob $STMT 1 "\x12\x34\x56" 3] \
[sqlite3_expanded_sql $STMT]
} {{} {SELECT a, b FROM t1 WHERE b = x'123456' ORDER BY a;}}
do_test trace3-8.9 {
list [sqlite3_bind_blob $STMT 1 "\xAB\xCD\xEF" 3] \
[sqlite3_expanded_sql $STMT]
} {{} {SELECT a, b FROM t1 WHERE b = x'abcdef' ORDER BY a;}}
do_test trace3-9.1 {
sqlite3_finalize $STMT
} {SQLITE_OK}
do_test trace3-10.1 {
db trace_v2 ""
db trace_v2
} {}
do_test trace3-10.2 {
unset -nocomplain ::stmtlist
db trace_v2 "" {statement profile row}
execsql {
SELECT a, b FROM t1 ORDER BY a;
}
array get ::stmtlist
} {}
do_test trace3-11.1 {
set ::stmtlist(record) {}
db trace_v2 trace_v2_record close
db close
set ::stmtlist(record)
} {/^-?\d+$/}
reset_db
do_test trace3-11.2 {
set ::stmtlist(record) {}
db trace_v2 trace_v2_record 8
db close
set ::stmtlist(record)
} {/^-?\d+$/}
finish_test
|