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