sl@0
|
1 |
# 2001 September 15
|
sl@0
|
2 |
#
|
sl@0
|
3 |
# Portions Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiaries. All rights reserved.
|
sl@0
|
4 |
#
|
sl@0
|
5 |
# The author disclaims copyright to this source code. In place of
|
sl@0
|
6 |
# a legal notice, here is a blessing:
|
sl@0
|
7 |
#
|
sl@0
|
8 |
# May you do good and not evil.
|
sl@0
|
9 |
# May you find forgiveness for yourself and forgive others.
|
sl@0
|
10 |
# May you share freely, never taking more than you give.
|
sl@0
|
11 |
#
|
sl@0
|
12 |
#***********************************************************************
|
sl@0
|
13 |
# This file implements regression tests for TCL interface to the
|
sl@0
|
14 |
# SQLite library.
|
sl@0
|
15 |
#
|
sl@0
|
16 |
# Actually, all tests are based on the TCL interface, so the main
|
sl@0
|
17 |
# interface is pretty well tested. This file contains some addition
|
sl@0
|
18 |
# tests for fringe issues that the main test suite does not cover.
|
sl@0
|
19 |
#
|
sl@0
|
20 |
# $Id: tclsqlite.test,v 1.69 2008/09/09 12:31:34 drh Exp $
|
sl@0
|
21 |
|
sl@0
|
22 |
set testdir [file dirname $argv0]
|
sl@0
|
23 |
source $testdir/tester.tcl
|
sl@0
|
24 |
|
sl@0
|
25 |
# Check the error messages generated by tclsqlite
|
sl@0
|
26 |
#
|
sl@0
|
27 |
if {[sqlite3 -has-codec]} {
|
sl@0
|
28 |
set r "sqlite_orig HANDLE FILENAME ?-key CODEC-KEY?"
|
sl@0
|
29 |
} else {
|
sl@0
|
30 |
set r "sqlite3 HANDLE FILENAME ?-vfs VFSNAME? ?-readonly BOOLEAN? ?-create BOOLEAN? ?-nomutex BOOLEAN? ?-fullmutex BOOLEAN?"
|
sl@0
|
31 |
}
|
sl@0
|
32 |
do_test tcl-1.1 {
|
sl@0
|
33 |
set v [catch {sqlite3 bogus} msg]
|
sl@0
|
34 |
regsub {really_sqlite3} $msg {sqlite3} msg
|
sl@0
|
35 |
lappend v $msg
|
sl@0
|
36 |
} [list 1 "wrong # args: should be \"$r\""]
|
sl@0
|
37 |
do_test tcl-1.2 {
|
sl@0
|
38 |
set v [catch {db bogus} msg]
|
sl@0
|
39 |
lappend v $msg
|
sl@0
|
40 |
} {1 {bad option "bogus": must be authorizer, busy, cache, changes, close, collate, collation_needed, commit_hook, complete, copy, enable_load_extension, errorcode, eval, exists, function, incrblob, interrupt, last_insert_rowid, nullvalue, onecolumn, profile, progress, rekey, rollback_hook, timeout, total_changes, trace, transaction, update_hook, or version}}
|
sl@0
|
41 |
do_test tcl-1.2.1 {
|
sl@0
|
42 |
set v [catch {db cache bogus} msg]
|
sl@0
|
43 |
lappend v $msg
|
sl@0
|
44 |
} {1 {bad option "bogus": must be flush or size}}
|
sl@0
|
45 |
do_test tcl-1.2.2 {
|
sl@0
|
46 |
set v [catch {db cache} msg]
|
sl@0
|
47 |
lappend v $msg
|
sl@0
|
48 |
} {1 {wrong # args: should be "db cache option ?arg?"}}
|
sl@0
|
49 |
do_test tcl-1.3 {
|
sl@0
|
50 |
execsql {CREATE TABLE t1(a int, b int)}
|
sl@0
|
51 |
execsql {INSERT INTO t1 VALUES(10,20)}
|
sl@0
|
52 |
set v [catch {
|
sl@0
|
53 |
db eval {SELECT * FROM t1} data {
|
sl@0
|
54 |
error "The error message"
|
sl@0
|
55 |
}
|
sl@0
|
56 |
} msg]
|
sl@0
|
57 |
lappend v $msg
|
sl@0
|
58 |
} {1 {The error message}}
|
sl@0
|
59 |
do_test tcl-1.4 {
|
sl@0
|
60 |
set v [catch {
|
sl@0
|
61 |
db eval {SELECT * FROM t2} data {
|
sl@0
|
62 |
error "The error message"
|
sl@0
|
63 |
}
|
sl@0
|
64 |
} msg]
|
sl@0
|
65 |
lappend v $msg
|
sl@0
|
66 |
} {1 {no such table: t2}}
|
sl@0
|
67 |
do_test tcl-1.5 {
|
sl@0
|
68 |
set v [catch {
|
sl@0
|
69 |
db eval {SELECT * FROM t1} data {
|
sl@0
|
70 |
break
|
sl@0
|
71 |
}
|
sl@0
|
72 |
} msg]
|
sl@0
|
73 |
lappend v $msg
|
sl@0
|
74 |
} {0 {}}
|
sl@0
|
75 |
catch {expr x*} msg
|
sl@0
|
76 |
do_test tcl-1.6 {
|
sl@0
|
77 |
set v [catch {
|
sl@0
|
78 |
db eval {SELECT * FROM t1} data {
|
sl@0
|
79 |
expr x*
|
sl@0
|
80 |
}
|
sl@0
|
81 |
} msg]
|
sl@0
|
82 |
lappend v $msg
|
sl@0
|
83 |
} [list 1 $msg]
|
sl@0
|
84 |
do_test tcl-1.7 {
|
sl@0
|
85 |
set v [catch {db} msg]
|
sl@0
|
86 |
lappend v $msg
|
sl@0
|
87 |
} {1 {wrong # args: should be "db SUBCOMMAND ..."}}
|
sl@0
|
88 |
if {[catch {db auth {}}]==0} {
|
sl@0
|
89 |
do_test tcl-1.8 {
|
sl@0
|
90 |
set v [catch {db authorizer 1 2 3} msg]
|
sl@0
|
91 |
lappend v $msg
|
sl@0
|
92 |
} {1 {wrong # args: should be "db authorizer ?CALLBACK?"}}
|
sl@0
|
93 |
}
|
sl@0
|
94 |
do_test tcl-1.9 {
|
sl@0
|
95 |
set v [catch {db busy 1 2 3} msg]
|
sl@0
|
96 |
lappend v $msg
|
sl@0
|
97 |
} {1 {wrong # args: should be "db busy CALLBACK"}}
|
sl@0
|
98 |
do_test tcl-1.10 {
|
sl@0
|
99 |
set v [catch {db progress 1} msg]
|
sl@0
|
100 |
lappend v $msg
|
sl@0
|
101 |
} {1 {wrong # args: should be "db progress N CALLBACK"}}
|
sl@0
|
102 |
do_test tcl-1.11 {
|
sl@0
|
103 |
set v [catch {db changes xyz} msg]
|
sl@0
|
104 |
lappend v $msg
|
sl@0
|
105 |
} {1 {wrong # args: should be "db changes "}}
|
sl@0
|
106 |
do_test tcl-1.12 {
|
sl@0
|
107 |
set v [catch {db commit_hook a b c} msg]
|
sl@0
|
108 |
lappend v $msg
|
sl@0
|
109 |
} {1 {wrong # args: should be "db commit_hook ?CALLBACK?"}}
|
sl@0
|
110 |
ifcapable {complete} {
|
sl@0
|
111 |
do_test tcl-1.13 {
|
sl@0
|
112 |
set v [catch {db complete} msg]
|
sl@0
|
113 |
lappend v $msg
|
sl@0
|
114 |
} {1 {wrong # args: should be "db complete SQL"}}
|
sl@0
|
115 |
}
|
sl@0
|
116 |
do_test tcl-1.14 {
|
sl@0
|
117 |
set v [catch {db eval} msg]
|
sl@0
|
118 |
lappend v $msg
|
sl@0
|
119 |
} {1 {wrong # args: should be "db eval SQL ?ARRAY-NAME? ?SCRIPT?"}}
|
sl@0
|
120 |
do_test tcl-1.15 {
|
sl@0
|
121 |
set v [catch {db function} msg]
|
sl@0
|
122 |
lappend v $msg
|
sl@0
|
123 |
} {1 {wrong # args: should be "db function NAME [-argcount N] SCRIPT"}}
|
sl@0
|
124 |
do_test tcl-1.16 {
|
sl@0
|
125 |
set v [catch {db last_insert_rowid xyz} msg]
|
sl@0
|
126 |
lappend v $msg
|
sl@0
|
127 |
} {1 {wrong # args: should be "db last_insert_rowid "}}
|
sl@0
|
128 |
do_test tcl-1.17 {
|
sl@0
|
129 |
set v [catch {db rekey} msg]
|
sl@0
|
130 |
lappend v $msg
|
sl@0
|
131 |
} {1 {wrong # args: should be "db rekey KEY"}}
|
sl@0
|
132 |
do_test tcl-1.18 {
|
sl@0
|
133 |
set v [catch {db timeout} msg]
|
sl@0
|
134 |
lappend v $msg
|
sl@0
|
135 |
} {1 {wrong # args: should be "db timeout MILLISECONDS"}}
|
sl@0
|
136 |
do_test tcl-1.19 {
|
sl@0
|
137 |
set v [catch {db collate} msg]
|
sl@0
|
138 |
lappend v $msg
|
sl@0
|
139 |
} {1 {wrong # args: should be "db collate NAME SCRIPT"}}
|
sl@0
|
140 |
do_test tcl-1.20 {
|
sl@0
|
141 |
set v [catch {db collation_needed} msg]
|
sl@0
|
142 |
lappend v $msg
|
sl@0
|
143 |
} {1 {wrong # args: should be "db collation_needed SCRIPT"}}
|
sl@0
|
144 |
do_test tcl-1.21 {
|
sl@0
|
145 |
set v [catch {db total_changes xyz} msg]
|
sl@0
|
146 |
lappend v $msg
|
sl@0
|
147 |
} {1 {wrong # args: should be "db total_changes "}}
|
sl@0
|
148 |
do_test tcl-1.20 {
|
sl@0
|
149 |
set v [catch {db copy} msg]
|
sl@0
|
150 |
lappend v $msg
|
sl@0
|
151 |
} {1 {wrong # args: should be "db copy CONFLICT-ALGORITHM TABLE FILENAME ?SEPARATOR? ?NULLINDICATOR?"}}
|
sl@0
|
152 |
do_test tcl-1.21 {
|
sl@0
|
153 |
set v [catch {sqlite3 db2 test.db -vfs nosuchvfs} msg]
|
sl@0
|
154 |
lappend v $msg
|
sl@0
|
155 |
} {1 {no such vfs: nosuchvfs}}
|
sl@0
|
156 |
|
sl@0
|
157 |
catch {unset ::result}
|
sl@0
|
158 |
do_test tcl-2.1 {
|
sl@0
|
159 |
execsql "CREATE TABLE t\u0123x(a int, b\u1235 float)"
|
sl@0
|
160 |
} {}
|
sl@0
|
161 |
ifcapable schema_pragmas {
|
sl@0
|
162 |
do_test tcl-2.2 {
|
sl@0
|
163 |
execsql "PRAGMA table_info(t\u0123x)"
|
sl@0
|
164 |
} "0 a int 0 {} 0 1 b\u1235 float 0 {} 0"
|
sl@0
|
165 |
}
|
sl@0
|
166 |
do_test tcl-2.3 {
|
sl@0
|
167 |
execsql "INSERT INTO t\u0123x VALUES(1,2.3)"
|
sl@0
|
168 |
db eval "SELECT * FROM t\u0123x" result break
|
sl@0
|
169 |
set result(*)
|
sl@0
|
170 |
} "a b\u1235"
|
sl@0
|
171 |
|
sl@0
|
172 |
|
sl@0
|
173 |
# Test the onecolumn method
|
sl@0
|
174 |
#
|
sl@0
|
175 |
do_test tcl-3.1 {
|
sl@0
|
176 |
execsql {
|
sl@0
|
177 |
INSERT INTO t1 SELECT a*2, b*2 FROM t1;
|
sl@0
|
178 |
INSERT INTO t1 SELECT a*2+1, b*2+1 FROM t1;
|
sl@0
|
179 |
INSERT INTO t1 SELECT a*2+3, b*2+3 FROM t1;
|
sl@0
|
180 |
}
|
sl@0
|
181 |
set rc [catch {db onecolumn {SELECT * FROM t1 ORDER BY a}} msg]
|
sl@0
|
182 |
lappend rc $msg
|
sl@0
|
183 |
} {0 10}
|
sl@0
|
184 |
do_test tcl-3.2 {
|
sl@0
|
185 |
db onecolumn {SELECT * FROM t1 WHERE a<0}
|
sl@0
|
186 |
} {}
|
sl@0
|
187 |
do_test tcl-3.3 {
|
sl@0
|
188 |
set rc [catch {db onecolumn} errmsg]
|
sl@0
|
189 |
lappend rc $errmsg
|
sl@0
|
190 |
} {1 {wrong # args: should be "db onecolumn SQL"}}
|
sl@0
|
191 |
do_test tcl-3.4 {
|
sl@0
|
192 |
set rc [catch {db onecolumn {SELECT bogus}} errmsg]
|
sl@0
|
193 |
lappend rc $errmsg
|
sl@0
|
194 |
} {1 {no such column: bogus}}
|
sl@0
|
195 |
ifcapable {tclvar} {
|
sl@0
|
196 |
do_test tcl-3.5 {
|
sl@0
|
197 |
set b 50
|
sl@0
|
198 |
set rc [catch {db one {SELECT * FROM t1 WHERE b>$b}} msg]
|
sl@0
|
199 |
lappend rc $msg
|
sl@0
|
200 |
} {0 41}
|
sl@0
|
201 |
do_test tcl-3.6 {
|
sl@0
|
202 |
set b 500
|
sl@0
|
203 |
set rc [catch {db one {SELECT * FROM t1 WHERE b>$b}} msg]
|
sl@0
|
204 |
lappend rc $msg
|
sl@0
|
205 |
} {0 {}}
|
sl@0
|
206 |
do_test tcl-3.7 {
|
sl@0
|
207 |
set b 500
|
sl@0
|
208 |
set rc [catch {db one {
|
sl@0
|
209 |
INSERT INTO t1 VALUES(99,510);
|
sl@0
|
210 |
SELECT * FROM t1 WHERE b>$b
|
sl@0
|
211 |
}} msg]
|
sl@0
|
212 |
lappend rc $msg
|
sl@0
|
213 |
} {0 99}
|
sl@0
|
214 |
}
|
sl@0
|
215 |
ifcapable {!tclvar} {
|
sl@0
|
216 |
execsql {INSERT INTO t1 VALUES(99,510)}
|
sl@0
|
217 |
}
|
sl@0
|
218 |
|
sl@0
|
219 |
# Turn the busy handler on and off
|
sl@0
|
220 |
#
|
sl@0
|
221 |
do_test tcl-4.1 {
|
sl@0
|
222 |
proc busy_callback {cnt} {
|
sl@0
|
223 |
break
|
sl@0
|
224 |
}
|
sl@0
|
225 |
db busy busy_callback
|
sl@0
|
226 |
db busy
|
sl@0
|
227 |
} {busy_callback}
|
sl@0
|
228 |
do_test tcl-4.2 {
|
sl@0
|
229 |
db busy {}
|
sl@0
|
230 |
db busy
|
sl@0
|
231 |
} {}
|
sl@0
|
232 |
|
sl@0
|
233 |
ifcapable {tclvar} {
|
sl@0
|
234 |
# Parsing of TCL variable names within SQL into bound parameters.
|
sl@0
|
235 |
#
|
sl@0
|
236 |
do_test tcl-5.1 {
|
sl@0
|
237 |
execsql {CREATE TABLE t3(a,b,c)}
|
sl@0
|
238 |
catch {unset x}
|
sl@0
|
239 |
set x(1) A
|
sl@0
|
240 |
set x(2) B
|
sl@0
|
241 |
execsql {
|
sl@0
|
242 |
INSERT INTO t3 VALUES($::x(1),$::x(2),$::x(3));
|
sl@0
|
243 |
SELECT * FROM t3
|
sl@0
|
244 |
}
|
sl@0
|
245 |
} {A B {}}
|
sl@0
|
246 |
do_test tcl-5.2 {
|
sl@0
|
247 |
execsql {
|
sl@0
|
248 |
SELECT typeof(a), typeof(b), typeof(c) FROM t3
|
sl@0
|
249 |
}
|
sl@0
|
250 |
} {text text null}
|
sl@0
|
251 |
do_test tcl-5.3 {
|
sl@0
|
252 |
catch {unset x}
|
sl@0
|
253 |
set x [binary format h12 686900686f00]
|
sl@0
|
254 |
execsql {
|
sl@0
|
255 |
UPDATE t3 SET a=$::x;
|
sl@0
|
256 |
}
|
sl@0
|
257 |
db eval {
|
sl@0
|
258 |
SELECT a FROM t3
|
sl@0
|
259 |
} break
|
sl@0
|
260 |
binary scan $a h12 adata
|
sl@0
|
261 |
set adata
|
sl@0
|
262 |
} {686900686f00}
|
sl@0
|
263 |
do_test tcl-5.4 {
|
sl@0
|
264 |
execsql {
|
sl@0
|
265 |
SELECT typeof(a), typeof(b), typeof(c) FROM t3
|
sl@0
|
266 |
}
|
sl@0
|
267 |
} {blob text null}
|
sl@0
|
268 |
}
|
sl@0
|
269 |
|
sl@0
|
270 |
# Operation of "break" and "continue" within row scripts
|
sl@0
|
271 |
#
|
sl@0
|
272 |
do_test tcl-6.1 {
|
sl@0
|
273 |
db eval {SELECT * FROM t1} {
|
sl@0
|
274 |
break
|
sl@0
|
275 |
}
|
sl@0
|
276 |
lappend a $b
|
sl@0
|
277 |
} {10 20}
|
sl@0
|
278 |
do_test tcl-6.2 {
|
sl@0
|
279 |
set cnt 0
|
sl@0
|
280 |
db eval {SELECT * FROM t1} {
|
sl@0
|
281 |
if {$a>40} continue
|
sl@0
|
282 |
incr cnt
|
sl@0
|
283 |
}
|
sl@0
|
284 |
set cnt
|
sl@0
|
285 |
} {4}
|
sl@0
|
286 |
do_test tcl-6.3 {
|
sl@0
|
287 |
set cnt 0
|
sl@0
|
288 |
db eval {SELECT * FROM t1} {
|
sl@0
|
289 |
if {$a<40} continue
|
sl@0
|
290 |
incr cnt
|
sl@0
|
291 |
}
|
sl@0
|
292 |
set cnt
|
sl@0
|
293 |
} {5}
|
sl@0
|
294 |
do_test tcl-6.4 {
|
sl@0
|
295 |
proc return_test {x} {
|
sl@0
|
296 |
db eval {SELECT * FROM t1} {
|
sl@0
|
297 |
if {$a==$x} {return $b}
|
sl@0
|
298 |
}
|
sl@0
|
299 |
}
|
sl@0
|
300 |
return_test 10
|
sl@0
|
301 |
} 20
|
sl@0
|
302 |
do_test tcl-6.5 {
|
sl@0
|
303 |
return_test 20
|
sl@0
|
304 |
} 40
|
sl@0
|
305 |
do_test tcl-6.6 {
|
sl@0
|
306 |
return_test 99
|
sl@0
|
307 |
} 510
|
sl@0
|
308 |
do_test tcl-6.7 {
|
sl@0
|
309 |
return_test 0
|
sl@0
|
310 |
} {}
|
sl@0
|
311 |
|
sl@0
|
312 |
do_test tcl-7.1 {
|
sl@0
|
313 |
db version
|
sl@0
|
314 |
expr 0
|
sl@0
|
315 |
} {0}
|
sl@0
|
316 |
|
sl@0
|
317 |
# modify and reset the NULL representation
|
sl@0
|
318 |
#
|
sl@0
|
319 |
do_test tcl-8.1 {
|
sl@0
|
320 |
db nullvalue NaN
|
sl@0
|
321 |
execsql {INSERT INTO t1 VALUES(30,NULL)}
|
sl@0
|
322 |
db eval {SELECT * FROM t1 WHERE b IS NULL}
|
sl@0
|
323 |
} {30 NaN}
|
sl@0
|
324 |
do_test tcl-8.2 {
|
sl@0
|
325 |
db nullvalue NULL
|
sl@0
|
326 |
db nullvalue
|
sl@0
|
327 |
} {NULL}
|
sl@0
|
328 |
do_test tcl-8.3 {
|
sl@0
|
329 |
db nullvalue {}
|
sl@0
|
330 |
db eval {SELECT * FROM t1 WHERE b IS NULL}
|
sl@0
|
331 |
} {30 {}}
|
sl@0
|
332 |
|
sl@0
|
333 |
# Test the return type of user-defined functions
|
sl@0
|
334 |
#
|
sl@0
|
335 |
do_test tcl-9.1 {
|
sl@0
|
336 |
db function ret_str {return "hi"}
|
sl@0
|
337 |
execsql {SELECT typeof(ret_str())}
|
sl@0
|
338 |
} {text}
|
sl@0
|
339 |
do_test tcl-9.2 {
|
sl@0
|
340 |
db function ret_dbl {return [expr {rand()*0.5}]}
|
sl@0
|
341 |
execsql {SELECT typeof(ret_dbl())}
|
sl@0
|
342 |
} {real}
|
sl@0
|
343 |
do_test tcl-9.3 {
|
sl@0
|
344 |
db function ret_int {return [expr {int(rand()*200)}]}
|
sl@0
|
345 |
execsql {SELECT typeof(ret_int())}
|
sl@0
|
346 |
} {integer}
|
sl@0
|
347 |
|
sl@0
|
348 |
# Recursive calls to the same user-defined function
|
sl@0
|
349 |
#
|
sl@0
|
350 |
ifcapable tclvar {
|
sl@0
|
351 |
do_test tcl-9.10 {
|
sl@0
|
352 |
proc userfunc_r1 {n} {
|
sl@0
|
353 |
if {$n<=0} {return 0}
|
sl@0
|
354 |
set nm1 [expr {$n-1}]
|
sl@0
|
355 |
return [expr {[db eval {SELECT r1($nm1)}]+$n}]
|
sl@0
|
356 |
}
|
sl@0
|
357 |
db function r1 userfunc_r1
|
sl@0
|
358 |
execsql {SELECT r1(10)}
|
sl@0
|
359 |
} {55}
|
sl@0
|
360 |
if {$::tcl_platform(platform)!="symbian"} {
|
sl@0
|
361 |
do_test tcl-9.11 {
|
sl@0
|
362 |
execsql {SELECT r1(100)}
|
sl@0
|
363 |
} {5050}
|
sl@0
|
364 |
}
|
sl@0
|
365 |
}
|
sl@0
|
366 |
|
sl@0
|
367 |
# Tests for the new transaction method
|
sl@0
|
368 |
#
|
sl@0
|
369 |
do_test tcl-10.1 {
|
sl@0
|
370 |
db transaction {}
|
sl@0
|
371 |
} {}
|
sl@0
|
372 |
do_test tcl-10.2 {
|
sl@0
|
373 |
db transaction deferred {}
|
sl@0
|
374 |
} {}
|
sl@0
|
375 |
do_test tcl-10.3 {
|
sl@0
|
376 |
db transaction immediate {}
|
sl@0
|
377 |
} {}
|
sl@0
|
378 |
do_test tcl-10.4 {
|
sl@0
|
379 |
db transaction exclusive {}
|
sl@0
|
380 |
} {}
|
sl@0
|
381 |
do_test tcl-10.5 {
|
sl@0
|
382 |
set rc [catch {db transaction xyzzy {}} msg]
|
sl@0
|
383 |
lappend rc $msg
|
sl@0
|
384 |
} {1 {bad transaction type "xyzzy": must be deferred, exclusive, or immediate}}
|
sl@0
|
385 |
do_test tcl-10.6 {
|
sl@0
|
386 |
set rc [catch {db transaction {error test-error}} msg]
|
sl@0
|
387 |
lappend rc $msg
|
sl@0
|
388 |
} {1 test-error}
|
sl@0
|
389 |
do_test tcl-10.7 {
|
sl@0
|
390 |
db transaction {
|
sl@0
|
391 |
db eval {CREATE TABLE t4(x)}
|
sl@0
|
392 |
db transaction {
|
sl@0
|
393 |
db eval {INSERT INTO t4 VALUES(1)}
|
sl@0
|
394 |
}
|
sl@0
|
395 |
}
|
sl@0
|
396 |
db eval {SELECT * FROM t4}
|
sl@0
|
397 |
} 1
|
sl@0
|
398 |
do_test tcl-10.8 {
|
sl@0
|
399 |
catch {
|
sl@0
|
400 |
db transaction {
|
sl@0
|
401 |
db eval {INSERT INTO t4 VALUES(2)}
|
sl@0
|
402 |
db eval {INSERT INTO t4 VALUES(3)}
|
sl@0
|
403 |
db eval {INSERT INTO t4 VALUES(4)}
|
sl@0
|
404 |
error test-error
|
sl@0
|
405 |
}
|
sl@0
|
406 |
}
|
sl@0
|
407 |
db eval {SELECT * FROM t4}
|
sl@0
|
408 |
} 1
|
sl@0
|
409 |
do_test tcl-10.9 {
|
sl@0
|
410 |
db transaction {
|
sl@0
|
411 |
db eval {INSERT INTO t4 VALUES(2)}
|
sl@0
|
412 |
catch {
|
sl@0
|
413 |
db transaction {
|
sl@0
|
414 |
db eval {INSERT INTO t4 VALUES(3)}
|
sl@0
|
415 |
db eval {INSERT INTO t4 VALUES(4)}
|
sl@0
|
416 |
error test-error
|
sl@0
|
417 |
}
|
sl@0
|
418 |
}
|
sl@0
|
419 |
}
|
sl@0
|
420 |
db eval {SELECT * FROM t4}
|
sl@0
|
421 |
} {1 2 3 4}
|
sl@0
|
422 |
do_test tcl-10.10 {
|
sl@0
|
423 |
for {set i 0} {$i<1} {incr i} {
|
sl@0
|
424 |
db transaction {
|
sl@0
|
425 |
db eval {INSERT INTO t4 VALUES(5)}
|
sl@0
|
426 |
continue
|
sl@0
|
427 |
}
|
sl@0
|
428 |
}
|
sl@0
|
429 |
db eval {SELECT * FROM t4}
|
sl@0
|
430 |
} {1 2 3 4 5}
|
sl@0
|
431 |
do_test tcl-10.11 {
|
sl@0
|
432 |
for {set i 0} {$i<10} {incr i} {
|
sl@0
|
433 |
db transaction {
|
sl@0
|
434 |
db eval {INSERT INTO t4 VALUES(6)}
|
sl@0
|
435 |
break
|
sl@0
|
436 |
}
|
sl@0
|
437 |
}
|
sl@0
|
438 |
db eval {SELECT * FROM t4}
|
sl@0
|
439 |
} {1 2 3 4 5 6}
|
sl@0
|
440 |
do_test tcl-10.12 {
|
sl@0
|
441 |
set rc [catch {
|
sl@0
|
442 |
for {set i 0} {$i<10} {incr i} {
|
sl@0
|
443 |
db transaction {
|
sl@0
|
444 |
db eval {INSERT INTO t4 VALUES(7)}
|
sl@0
|
445 |
return
|
sl@0
|
446 |
}
|
sl@0
|
447 |
}
|
sl@0
|
448 |
}]
|
sl@0
|
449 |
} {2}
|
sl@0
|
450 |
do_test tcl-10.13 {
|
sl@0
|
451 |
db eval {SELECT * FROM t4}
|
sl@0
|
452 |
} {1 2 3 4 5 6 7}
|
sl@0
|
453 |
|
sl@0
|
454 |
do_test tcl-11.1 {
|
sl@0
|
455 |
db exists {SELECT x,x*2,x+x FROM t4 WHERE x==4}
|
sl@0
|
456 |
} {1}
|
sl@0
|
457 |
do_test tcl-11.2 {
|
sl@0
|
458 |
db exists {SELECT 0 FROM t4 WHERE x==4}
|
sl@0
|
459 |
} {1}
|
sl@0
|
460 |
do_test tcl-11.3 {
|
sl@0
|
461 |
db exists {SELECT 1 FROM t4 WHERE x==8}
|
sl@0
|
462 |
} {0}
|
sl@0
|
463 |
|
sl@0
|
464 |
do_test tcl-12.1 {
|
sl@0
|
465 |
unset -nocomplain a b c version
|
sl@0
|
466 |
set version [db version]
|
sl@0
|
467 |
scan $version "%d.%d.%d" a b c
|
sl@0
|
468 |
expr $a*1000000 + $b*1000 + $c
|
sl@0
|
469 |
} [sqlite3_libversion_number]
|
sl@0
|
470 |
|
sl@0
|
471 |
|
sl@0
|
472 |
# Check to see that when bindings of the form @aaa are used instead
|
sl@0
|
473 |
# of $aaa, that objects are treated as bytearray and are inserted
|
sl@0
|
474 |
# as BLOBs.
|
sl@0
|
475 |
#
|
sl@0
|
476 |
ifcapable tclvar {
|
sl@0
|
477 |
do_test tcl-13.1 {
|
sl@0
|
478 |
db eval {CREATE TABLE t5(x BLOB)}
|
sl@0
|
479 |
set x abc123
|
sl@0
|
480 |
db eval {INSERT INTO t5 VALUES($x)}
|
sl@0
|
481 |
db eval {SELECT typeof(x) FROM t5}
|
sl@0
|
482 |
} {text}
|
sl@0
|
483 |
do_test tcl-13.2 {
|
sl@0
|
484 |
binary scan $x H notUsed
|
sl@0
|
485 |
db eval {
|
sl@0
|
486 |
DELETE FROM t5;
|
sl@0
|
487 |
INSERT INTO t5 VALUES($x);
|
sl@0
|
488 |
SELECT typeof(x) FROM t5;
|
sl@0
|
489 |
}
|
sl@0
|
490 |
} {text}
|
sl@0
|
491 |
do_test tcl-13.3 {
|
sl@0
|
492 |
db eval {
|
sl@0
|
493 |
DELETE FROM t5;
|
sl@0
|
494 |
INSERT INTO t5 VALUES(@x);
|
sl@0
|
495 |
SELECT typeof(x) FROM t5;
|
sl@0
|
496 |
}
|
sl@0
|
497 |
} {blob}
|
sl@0
|
498 |
do_test tcl-13.4 {
|
sl@0
|
499 |
set y 1234
|
sl@0
|
500 |
db eval {
|
sl@0
|
501 |
DELETE FROM t5;
|
sl@0
|
502 |
INSERT INTO t5 VALUES(@y);
|
sl@0
|
503 |
SELECT hex(x), typeof(x) FROM t5
|
sl@0
|
504 |
}
|
sl@0
|
505 |
} {31323334 blob}
|
sl@0
|
506 |
}
|
sl@0
|
507 |
|
sl@0
|
508 |
|
sl@0
|
509 |
finish_test
|