1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/bind.test Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,670 @@
1.4 +# 2003 September 6
1.5 +#
1.6 +# Portions Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiaries. All rights reserved.
1.7 +#
1.8 +# The author disclaims copyright to this source code. In place of
1.9 +# a legal notice, here is a blessing:
1.10 +#
1.11 +# May you do good and not evil.
1.12 +# May you find forgiveness for yourself and forgive others.
1.13 +# May you share freely, never taking more than you give.
1.14 +#
1.15 +#***********************************************************************
1.16 +# This file implements regression tests for SQLite library. The
1.17 +# focus of this script testing the sqlite_bind API.
1.18 +#
1.19 +# $Id: bind.test,v 1.44 2008/07/09 01:39:44 drh Exp $
1.20 +#
1.21 +
1.22 +set testdir [file dirname $argv0]
1.23 +source $testdir/tester.tcl
1.24 +
1.25 +proc sqlite_step {stmt N VALS COLS} {
1.26 + upvar VALS vals
1.27 + upvar COLS cols
1.28 + set vals [list]
1.29 + set cols [list]
1.30 +
1.31 + set rc [sqlite3_step $stmt]
1.32 + for {set i 0} {$i < [sqlite3_column_count $stmt]} {incr i} {
1.33 + lappend cols [sqlite3_column_name $stmt $i]
1.34 + }
1.35 + for {set i 0} {$i < [sqlite3_data_count $stmt]} {incr i} {
1.36 + lappend vals [sqlite3_column_text $stmt $i]
1.37 + }
1.38 +
1.39 + return $rc
1.40 +}
1.41 +
1.42 +do_test bind-1.1 {
1.43 + set DB [sqlite3_connection_pointer db]
1.44 + execsql {CREATE TABLE t1(a,b,c);}
1.45 + set VM [sqlite3_prepare $DB {INSERT INTO t1 VALUES(:1,?,:abc)} -1 TAIL]
1.46 + set TAIL
1.47 +} {}
1.48 +do_test bind-1.1.1 {
1.49 + sqlite3_bind_parameter_count $VM
1.50 +} 3
1.51 +do_test bind-1.1.2 {
1.52 + sqlite3_bind_parameter_name $VM 1
1.53 +} {:1}
1.54 +do_test bind-1.1.3 {
1.55 + sqlite3_bind_parameter_name $VM 2
1.56 +} {}
1.57 +do_test bind-1.1.4 {
1.58 + sqlite3_bind_parameter_name $VM 3
1.59 +} {:abc}
1.60 +do_test bind-1.2 {
1.61 + sqlite_step $VM N VALUES COLNAMES
1.62 +} {SQLITE_DONE}
1.63 +do_test bind-1.3 {
1.64 + execsql {SELECT rowid, * FROM t1}
1.65 +} {1 {} {} {}}
1.66 +do_test bind-1.4 {
1.67 + sqlite3_reset $VM
1.68 + sqlite_bind $VM 1 {test value 1} normal
1.69 + sqlite_step $VM N VALUES COLNAMES
1.70 +} SQLITE_DONE
1.71 +do_test bind-1.5 {
1.72 + execsql {SELECT rowid, * FROM t1}
1.73 +} {1 {} {} {} 2 {test value 1} {} {}}
1.74 +do_test bind-1.6 {
1.75 + sqlite3_reset $VM
1.76 + sqlite_bind $VM 3 {'test value 2'} normal
1.77 + sqlite_step $VM N VALUES COLNAMES
1.78 +} SQLITE_DONE
1.79 +do_test bind-1.7 {
1.80 + execsql {SELECT rowid, * FROM t1}
1.81 +} {1 {} {} {} 2 {test value 1} {} {} 3 {test value 1} {} {'test value 2'}}
1.82 +do_test bind-1.8 {
1.83 + sqlite3_reset $VM
1.84 + set sqlite_static_bind_value 123
1.85 + sqlite_bind $VM 1 {} static
1.86 + sqlite_bind $VM 2 {abcdefg} normal
1.87 + sqlite_bind $VM 3 {} null
1.88 + execsql {DELETE FROM t1}
1.89 + sqlite_step $VM N VALUES COLNAMES
1.90 + execsql {SELECT rowid, * FROM t1}
1.91 +} {1 123 abcdefg {}}
1.92 +do_test bind-1.9 {
1.93 + sqlite3_reset $VM
1.94 + sqlite_bind $VM 1 {456} normal
1.95 + sqlite_step $VM N VALUES COLNAMES
1.96 + execsql {SELECT rowid, * FROM t1}
1.97 +} {1 123 abcdefg {} 2 456 abcdefg {}}
1.98 +
1.99 +do_test bind-1.10 {
1.100 + set rc [catch {
1.101 + sqlite3_prepare db {INSERT INTO t1 VALUES($abc:123,?,:abc)} -1 TAIL
1.102 + } msg]
1.103 + lappend rc $msg
1.104 +} {1 {(1) near ":123": syntax error}}
1.105 +do_test bind-1.11 {
1.106 + set rc [catch {
1.107 + sqlite3_prepare db {INSERT INTO t1 VALUES(@abc:xyz,?,:abc)} -1 TAIL
1.108 + } msg]
1.109 + lappend rc $msg
1.110 +} {1 {(1) near ":xyz": syntax error}}
1.111 +
1.112 +do_test bind-1.99 {
1.113 + sqlite3_finalize $VM
1.114 +} SQLITE_OK
1.115 +
1.116 +# Prepare the statement in different ways depending on whether or not
1.117 +# the $var processing is compiled into the library.
1.118 +#
1.119 +ifcapable {tclvar} {
1.120 + do_test bind-2.1 {
1.121 + execsql {
1.122 + DELETE FROM t1;
1.123 + }
1.124 + set VM [sqlite3_prepare $DB {INSERT INTO t1 VALUES($one,$::two,$x(-z-))}\
1.125 + -1 TX]
1.126 + set TX
1.127 + } {}
1.128 + set v1 {$one}
1.129 + set v2 {$::two}
1.130 + set v3 {$x(-z-)}
1.131 +}
1.132 +ifcapable {!tclvar} {
1.133 + do_test bind-2.1 {
1.134 + execsql {
1.135 + DELETE FROM t1;
1.136 + }
1.137 + set VM [sqlite3_prepare $DB {INSERT INTO t1 VALUES(:one,:two,:_)} -1 TX]
1.138 + set TX
1.139 + } {}
1.140 + set v1 {:one}
1.141 + set v2 {:two}
1.142 + set v3 {:_}
1.143 +}
1.144 +
1.145 +do_test bind-2.1.1 {
1.146 + sqlite3_bind_parameter_count $VM
1.147 +} 3
1.148 +do_test bind-2.1.2 {
1.149 + sqlite3_bind_parameter_name $VM 1
1.150 +} $v1
1.151 +do_test bind-2.1.3 {
1.152 + sqlite3_bind_parameter_name $VM 2
1.153 +} $v2
1.154 +do_test bind-2.1.4 {
1.155 + sqlite3_bind_parameter_name $VM 3
1.156 +} $v3
1.157 +do_test bind-2.1.5 {
1.158 + sqlite3_bind_parameter_index $VM $v1
1.159 +} 1
1.160 +do_test bind-2.1.6 {
1.161 + sqlite3_bind_parameter_index $VM $v2
1.162 +} 2
1.163 +do_test bind-2.1.7 {
1.164 + sqlite3_bind_parameter_index $VM $v3
1.165 +} 3
1.166 +do_test bind-2.1.8 {
1.167 + sqlite3_bind_parameter_index $VM {:hi}
1.168 +} 0
1.169 +
1.170 +# 32 bit Integers
1.171 +do_test bind-2.2 {
1.172 + sqlite3_bind_int $VM 1 123
1.173 + sqlite3_bind_int $VM 2 456
1.174 + sqlite3_bind_int $VM 3 789
1.175 + sqlite_step $VM N VALUES COLNAMES
1.176 + sqlite3_reset $VM
1.177 + execsql {SELECT rowid, * FROM t1}
1.178 +} {1 123 456 789}
1.179 +do_test bind-2.3 {
1.180 + sqlite3_bind_int $VM 2 -2000000000
1.181 + sqlite3_bind_int $VM 3 2000000000
1.182 + sqlite_step $VM N VALUES COLNAMES
1.183 + sqlite3_reset $VM
1.184 + execsql {SELECT rowid, * FROM t1}
1.185 +} {1 123 456 789 2 123 -2000000000 2000000000}
1.186 +do_test bind-2.4 {
1.187 + execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1}
1.188 +} {integer integer integer integer integer integer}
1.189 +do_test bind-2.5 {
1.190 + execsql {
1.191 + DELETE FROM t1;
1.192 + }
1.193 +} {}
1.194 +
1.195 +# 64 bit Integers
1.196 +do_test bind-3.1 {
1.197 + sqlite3_bind_int64 $VM 1 32
1.198 + sqlite3_bind_int64 $VM 2 -2000000000000
1.199 + sqlite3_bind_int64 $VM 3 2000000000000
1.200 + sqlite_step $VM N VALUES COLNAMES
1.201 + sqlite3_reset $VM
1.202 + execsql {SELECT rowid, * FROM t1}
1.203 +} {1 32 -2000000000000 2000000000000}
1.204 +do_test bind-3.2 {
1.205 + execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1}
1.206 +} {integer integer integer}
1.207 +do_test bind-3.3 {
1.208 + execsql {
1.209 + DELETE FROM t1;
1.210 + }
1.211 +} {}
1.212 +
1.213 +# Doubles
1.214 +do_test bind-4.1 {
1.215 + sqlite3_bind_double $VM 1 1234.1234
1.216 + sqlite3_bind_double $VM 2 0.00001
1.217 + sqlite3_bind_double $VM 3 123456789
1.218 + sqlite_step $VM N VALUES COLNAMES
1.219 + sqlite3_reset $VM
1.220 + set x [execsql {SELECT rowid, * FROM t1}]
1.221 + regsub {1e-005} $x {1e-05} y
1.222 + set y
1.223 +} {1 1234.1234 1e-05 123456789.0}
1.224 +do_test bind-4.2 {
1.225 + execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1}
1.226 +} {real real real}
1.227 +do_test bind-4.3 {
1.228 + execsql {
1.229 + DELETE FROM t1;
1.230 + }
1.231 +} {}
1.232 +#
1.233 +#Symbian OS: this test is failing due to problems in printf format spec implementation
1.234 +#
1.235 +if {$::tcl_platform(platform)!="symbian"} {
1.236 + do_test bind-4.4 {
1.237 + sqlite3_bind_double $VM 1 NaN
1.238 + sqlite3_bind_double $VM 2 1e300
1.239 + sqlite3_bind_double $VM 3 -1e-300
1.240 + sqlite_step $VM N VALUES COLNAMES
1.241 + sqlite3_reset $VM
1.242 + set x [execsql {SELECT rowid, * FROM t1}]
1.243 + regsub {1e-005} $x {1e-05} y
1.244 + set y
1.245 + } {1 {} 1e+300 -1e-300}
1.246 +#
1.247 +#Symbian OS: this test is commented because depends on 4.4
1.248 +#
1.249 + do_test bind-4.5 {
1.250 + execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1}
1.251 + } {null real real}
1.252 +}
1.253 +do_test bind-4.6 {
1.254 + execsql {
1.255 + DELETE FROM t1;
1.256 + }
1.257 +} {}
1.258 +
1.259 +# NULL
1.260 +do_test bind-5.1 {
1.261 + sqlite3_bind_null $VM 1
1.262 + sqlite3_bind_null $VM 2
1.263 + sqlite3_bind_null $VM 3
1.264 + sqlite_step $VM N VALUES COLNAMES
1.265 + sqlite3_reset $VM
1.266 + execsql {SELECT rowid, * FROM t1}
1.267 +} {1 {} {} {}}
1.268 +do_test bind-5.2 {
1.269 + execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1}
1.270 +} {null null null}
1.271 +do_test bind-5.3 {
1.272 + execsql {
1.273 + DELETE FROM t1;
1.274 + }
1.275 +} {}
1.276 +
1.277 +# UTF-8 text
1.278 +do_test bind-6.1 {
1.279 + sqlite3_bind_text $VM 1 hellothere 5
1.280 + sqlite3_bind_text $VM 2 ".." 1
1.281 + sqlite3_bind_text $VM 3 world\000 -1
1.282 + sqlite_step $VM N VALUES COLNAMES
1.283 + sqlite3_reset $VM
1.284 + execsql {SELECT rowid, * FROM t1}
1.285 +} {1 hello . world}
1.286 +do_test bind-6.2 {
1.287 + execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1}
1.288 +} {text text text}
1.289 +do_test bind-6.3 {
1.290 + execsql {
1.291 + DELETE FROM t1;
1.292 + }
1.293 +} {}
1.294 +
1.295 +# Make sure zeros in a string work.
1.296 +#
1.297 +do_test bind-6.4 {
1.298 + db eval {DELETE FROM t1}
1.299 + sqlite3_bind_text $VM 1 hello\000there\000 12
1.300 + sqlite3_bind_text $VM 2 hello\000there\000 11
1.301 + sqlite3_bind_text $VM 3 hello\000there\000 -1
1.302 + sqlite_step $VM N VALUES COLNAMES
1.303 + sqlite3_reset $VM
1.304 + execsql {SELECT * FROM t1}
1.305 +} {hello hello hello}
1.306 +set enc [db eval {PRAGMA encoding}]
1.307 +if {$enc=="UTF-8"} {
1.308 + do_test bind-6.5 {
1.309 + execsql {SELECT hex(a), hex(b), hex(c) FROM t1}
1.310 + } {68656C6C6F00746865726500 68656C6C6F007468657265 68656C6C6F}
1.311 +} elseif {$enc=="UTF-16le"} {
1.312 + do_test bind-6.5 {
1.313 + execsql {SELECT hex(a), hex(b), hex(c) FROM t1}
1.314 + } {680065006C006C006F000000740068006500720065000000 680065006C006C006F00000074006800650072006500 680065006C006C006F00}
1.315 +} elseif {$enc=="UTF-16be"} {
1.316 + do_test bind-6.5 {
1.317 + execsql {SELECT hex(a), hex(b), hex(c) FROM t1}
1.318 + } {00680065006C006C006F0000007400680065007200650000 00680065006C006C006F000000740068006500720065 00680065006C006C006F}
1.319 +} else {
1.320 + do_test bind-6.5 {
1.321 + set "Unknown database encoding: $::enc"
1.322 + } {}
1.323 +}
1.324 +do_test bind-6.6 {
1.325 + execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1}
1.326 +} {text text text}
1.327 +do_test bind-6.7 {
1.328 + execsql {
1.329 + DELETE FROM t1;
1.330 + }
1.331 +} {}
1.332 +
1.333 +# UTF-16 text
1.334 +ifcapable {utf16} {
1.335 + do_test bind-7.1 {
1.336 + sqlite3_bind_text16 $VM 1 [encoding convertto unicode hellothere] 10
1.337 + sqlite3_bind_text16 $VM 2 [encoding convertto unicode ""] 0
1.338 + sqlite3_bind_text16 $VM 3 [encoding convertto unicode world] 10
1.339 + sqlite_step $VM N VALUES COLNAMES
1.340 + sqlite3_reset $VM
1.341 + execsql {SELECT rowid, * FROM t1}
1.342 + } {1 hello {} world}
1.343 + do_test bind-7.2 {
1.344 + execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1}
1.345 + } {text text text}
1.346 + do_test bind-7.3 {
1.347 + db eval {DELETE FROM t1}
1.348 + sqlite3_bind_text16 $VM 1 [encoding convertto unicode hi\000yall\000] 16
1.349 + sqlite3_bind_text16 $VM 2 [encoding convertto unicode hi\000yall\000] 14
1.350 + sqlite3_bind_text16 $VM 3 [encoding convertto unicode hi\000yall\000] -1
1.351 + sqlite_step $VM N VALUES COLNAMES
1.352 + sqlite3_reset $VM
1.353 + execsql {SELECT * FROM t1}
1.354 + } {hi hi hi}
1.355 + if {$enc=="UTF-8"} {
1.356 + do_test bind-7.4 {
1.357 + execsql {SELECT hex(a), hex(b), hex(c) FROM t1}
1.358 + } {68690079616C6C00 68690079616C6C 6869}
1.359 + } elseif {$enc=="UTF-16le"} {
1.360 + do_test bind-7.4 {
1.361 + execsql {SELECT hex(a), hex(b), hex(c) FROM t1}
1.362 + } {680069000000790061006C006C000000 680069000000790061006C006C00 68006900}
1.363 + } elseif {$enc=="UTF-16be"} {
1.364 + do_test bind-7.4 {
1.365 + execsql {SELECT hex(a), hex(b), hex(c) FROM t1}
1.366 + } {00680069000000790061006C006C0000 00680069000000790061006C006C 00680069}
1.367 + }
1.368 + do_test bind-7.5 {
1.369 + execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1}
1.370 + } {text text text}
1.371 +}
1.372 +do_test bind-7.99 {
1.373 + execsql {DELETE FROM t1;}
1.374 +} {}
1.375 +
1.376 +# Test that the 'out of range' error works.
1.377 +do_test bind-8.1 {
1.378 + catch { sqlite3_bind_null $VM 0 }
1.379 +} {1}
1.380 +do_test bind-8.2 {
1.381 + sqlite3_errmsg $DB
1.382 +} {bind or column index out of range}
1.383 +ifcapable {utf16} {
1.384 + do_test bind-8.3 {
1.385 + encoding convertfrom unicode [sqlite3_errmsg16 $DB]
1.386 + } {bind or column index out of range}
1.387 +}
1.388 +do_test bind-8.4 {
1.389 + sqlite3_bind_null $VM 1
1.390 + sqlite3_errmsg $DB
1.391 +} {not an error}
1.392 +do_test bind-8.5 {
1.393 + catch { sqlite3_bind_null $VM 4 }
1.394 +} {1}
1.395 +do_test bind-8.6 {
1.396 + sqlite3_errmsg $DB
1.397 +} {bind or column index out of range}
1.398 +ifcapable {utf16} {
1.399 + do_test bind-8.7 {
1.400 + encoding convertfrom unicode [sqlite3_errmsg16 $DB]
1.401 + } {bind or column index out of range}
1.402 +}
1.403 +
1.404 +do_test bind-8.8 {
1.405 + catch { sqlite3_bind_blob $VM 0 "abc" 3 }
1.406 +} {1}
1.407 +do_test bind-8.9 {
1.408 + catch { sqlite3_bind_blob $VM 4 "abc" 3 }
1.409 +} {1}
1.410 +do_test bind-8.10 {
1.411 + catch { sqlite3_bind_text $VM 0 "abc" 3 }
1.412 +} {1}
1.413 +ifcapable {utf16} {
1.414 + do_test bind-8.11 {
1.415 + catch { sqlite3_bind_text16 $VM 4 "abc" 2 }
1.416 + } {1}
1.417 +}
1.418 +do_test bind-8.12 {
1.419 + catch { sqlite3_bind_int $VM 0 5 }
1.420 +} {1}
1.421 +do_test bind-8.13 {
1.422 + catch { sqlite3_bind_int $VM 4 5 }
1.423 +} {1}
1.424 +do_test bind-8.14 {
1.425 + catch { sqlite3_bind_double $VM 0 5.0 }
1.426 +} {1}
1.427 +do_test bind-8.15 {
1.428 + catch { sqlite3_bind_double $VM 4 6.0 }
1.429 +} {1}
1.430 +
1.431 +do_test bind-8.99 {
1.432 + sqlite3_finalize $VM
1.433 +} SQLITE_OK
1.434 +
1.435 +do_test bind-9.1 {
1.436 + execsql {
1.437 + CREATE TABLE t2(a,b,c,d,e,f);
1.438 + }
1.439 + set rc [catch {
1.440 + sqlite3_prepare $DB {
1.441 + INSERT INTO t2(a) VALUES(?0)
1.442 + } -1 TAIL
1.443 + } msg]
1.444 + lappend rc $msg
1.445 +} {1 {(1) variable number must be between ?1 and ?999}}
1.446 +do_test bind-9.2 {
1.447 + set rc [catch {
1.448 + sqlite3_prepare $DB {
1.449 + INSERT INTO t2(a) VALUES(?1000)
1.450 + } -1 TAIL
1.451 + } msg]
1.452 + lappend rc $msg
1.453 +} {1 {(1) variable number must be between ?1 and ?999}}
1.454 +do_test bind-9.3.1 {
1.455 + set VM [
1.456 + sqlite3_prepare $DB {
1.457 + INSERT INTO t2(a,b) VALUES(?1,?999)
1.458 + } -1 TAIL
1.459 + ]
1.460 + sqlite3_bind_parameter_count $VM
1.461 +} {999}
1.462 +catch {sqlite3_finalize $VM}
1.463 +do_test bind-9.3.2 {
1.464 + set VM [
1.465 + sqlite3_prepare $DB {
1.466 + INSERT INTO t2(a,b) VALUES(?2,?998)
1.467 + } -1 TAIL
1.468 + ]
1.469 + sqlite3_bind_parameter_count $VM
1.470 +} {998}
1.471 +catch {sqlite3_finalize $VM}
1.472 +do_test bind-9.4 {
1.473 + set VM [
1.474 + sqlite3_prepare $DB {
1.475 + INSERT INTO t2(a,b,c,d) VALUES(?1,?997,?,?)
1.476 + } -1 TAIL
1.477 + ]
1.478 + sqlite3_bind_parameter_count $VM
1.479 +} {999}
1.480 +do_test bind-9.5 {
1.481 + sqlite3_bind_int $VM 1 1
1.482 + sqlite3_bind_int $VM 997 999
1.483 + sqlite3_bind_int $VM 998 1000
1.484 + sqlite3_bind_int $VM 999 1001
1.485 + sqlite3_step $VM
1.486 +} SQLITE_DONE
1.487 +do_test bind-9.6 {
1.488 + sqlite3_finalize $VM
1.489 +} SQLITE_OK
1.490 +do_test bind-9.7 {
1.491 + execsql {SELECT * FROM t2}
1.492 +} {1 999 1000 1001 {} {}}
1.493 +
1.494 +ifcapable {tclvar} {
1.495 + do_test bind-10.1 {
1.496 + set VM [
1.497 + sqlite3_prepare $DB {
1.498 + INSERT INTO t2(a,b,c,d,e,f) VALUES(:abc,$abc,:abc,$ab,$abc,:abc)
1.499 + } -1 TAIL
1.500 + ]
1.501 + sqlite3_bind_parameter_count $VM
1.502 + } 3
1.503 + set v1 {$abc}
1.504 + set v2 {$ab}
1.505 +}
1.506 +ifcapable {!tclvar} {
1.507 + do_test bind-10.1 {
1.508 + set VM [
1.509 + sqlite3_prepare $DB {
1.510 + INSERT INTO t2(a,b,c,d,e,f) VALUES(:abc,:xyz,:abc,:xy,:xyz,:abc)
1.511 + } -1 TAIL
1.512 + ]
1.513 + sqlite3_bind_parameter_count $VM
1.514 + } 3
1.515 + set v1 {:xyz}
1.516 + set v2 {:xy}
1.517 +}
1.518 +do_test bind-10.2 {
1.519 + sqlite3_bind_parameter_index $VM :abc
1.520 +} 1
1.521 +do_test bind-10.3 {
1.522 + sqlite3_bind_parameter_index $VM $v1
1.523 +} 2
1.524 +do_test bind-10.4 {
1.525 + sqlite3_bind_parameter_index $VM $v2
1.526 +} 3
1.527 +do_test bind-10.5 {
1.528 + sqlite3_bind_parameter_name $VM 1
1.529 +} :abc
1.530 +do_test bind-10.6 {
1.531 + sqlite3_bind_parameter_name $VM 2
1.532 +} $v1
1.533 +do_test bind-10.7 {
1.534 + sqlite3_bind_parameter_name $VM 3
1.535 +} $v2
1.536 +do_test bind-10.7.1 {
1.537 + sqlite3_bind_parameter_name 0 1 ;# Ignore if VM is NULL
1.538 +} {}
1.539 +do_test bind-10.7.2 {
1.540 + sqlite3_bind_parameter_name $VM 0 ;# Ignore if index too small
1.541 +} {}
1.542 +do_test bind-10.7.3 {
1.543 + sqlite3_bind_parameter_name $VM 4 ;# Ignore if index is too big
1.544 +} {}
1.545 +do_test bind-10.8 {
1.546 + sqlite3_bind_int $VM 1 1
1.547 + sqlite3_bind_int $VM 2 2
1.548 + sqlite3_bind_int $VM 3 3
1.549 + sqlite3_step $VM
1.550 +} SQLITE_DONE
1.551 +do_test bind-10.8.1 {
1.552 + # Binding attempts after program start should fail
1.553 + set rc [catch {
1.554 + sqlite3_bind_int $VM 1 1
1.555 + } msg]
1.556 + lappend rc $msg
1.557 +} {1 {}}
1.558 +do_test bind-10.9 {
1.559 + sqlite3_finalize $VM
1.560 +} SQLITE_OK
1.561 +do_test bind-10.10 {
1.562 + execsql {SELECT * FROM t2}
1.563 +} {1 999 1000 1001 {} {} 1 2 1 3 2 1}
1.564 +
1.565 +# Ticket #918
1.566 +#
1.567 +do_test bind-10.11 {
1.568 + # catch {sqlite3_finalize $VM}
1.569 + set VM [
1.570 + sqlite3_prepare $DB {
1.571 + INSERT INTO t2(a,b,c,d,e,f) VALUES(:abc,?,?4,:pqr,:abc,?4)
1.572 + } -1 TAIL
1.573 + ]
1.574 + sqlite3_bind_parameter_count $VM
1.575 +} 5
1.576 +do_test bind-10.11.1 {
1.577 + sqlite3_bind_parameter_index 0 :xyz ;# ignore NULL VM arguments
1.578 +} 0
1.579 +do_test bind-10.12 {
1.580 + sqlite3_bind_parameter_index $VM :xyz
1.581 +} 0
1.582 +do_test bind-10.13 {
1.583 + sqlite3_bind_parameter_index $VM {}
1.584 +} 0
1.585 +do_test bind-10.14 {
1.586 + sqlite3_bind_parameter_index $VM :pqr
1.587 +} 5
1.588 +do_test bind-10.15 {
1.589 + sqlite3_bind_parameter_index $VM ?4
1.590 +} 4
1.591 +do_test bind-10.16 {
1.592 + sqlite3_bind_parameter_name $VM 1
1.593 +} :abc
1.594 +do_test bind-10.17 {
1.595 + sqlite3_bind_parameter_name $VM 2
1.596 +} {}
1.597 +do_test bind-10.18 {
1.598 + sqlite3_bind_parameter_name $VM 3
1.599 +} {}
1.600 +do_test bind-10.19 {
1.601 + sqlite3_bind_parameter_name $VM 4
1.602 +} {?4}
1.603 +do_test bind-10.20 {
1.604 + sqlite3_bind_parameter_name $VM 5
1.605 +} :pqr
1.606 +catch {sqlite3_finalize $VM}
1.607 +
1.608 +# Make sure we catch an unterminated "(" in a Tcl-style variable name
1.609 +#
1.610 +ifcapable tclvar {
1.611 + do_test bind-11.1 {
1.612 + catchsql {SELECT * FROM sqlite_master WHERE name=$abc(123 and sql NOT NULL;}
1.613 + } {1 {unrecognized token: "$abc(123"}}
1.614 +}
1.615 +
1.616 +if {[execsql {pragma encoding}]=="UTF-8"} {
1.617 + # Test the ability to bind text that contains embedded '\000' characters.
1.618 + # Make sure we can recover the entire input string.
1.619 + #
1.620 + do_test bind-12.1 {
1.621 + execsql {
1.622 + CREATE TABLE t3(x BLOB);
1.623 + }
1.624 + set VM [sqlite3_prepare $DB {INSERT INTO t3 VALUES(?)} -1 TAIL]
1.625 + sqlite_bind $VM 1 not-used blob10
1.626 + sqlite3_step $VM
1.627 + sqlite3_finalize $VM
1.628 + execsql {
1.629 + SELECT typeof(x), length(x), quote(x),
1.630 + length(cast(x AS BLOB)), quote(cast(x AS BLOB)) FROM t3
1.631 + }
1.632 + } {text 3 'abc' 10 X'6162630078797A007071'}
1.633 + do_test bind-12.2 {
1.634 + sqlite3_create_function $DB
1.635 + execsql {
1.636 + SELECT quote(cast(x_coalesce(x) AS blob)) FROM t3
1.637 + }
1.638 + } {X'6162630078797A007071'}
1.639 +}
1.640 +
1.641 +# Test the operation of sqlite3_clear_bindings
1.642 +#
1.643 +do_test bind-13.1 {
1.644 + set VM [sqlite3_prepare $DB {SELECT ?,?,?} -1 TAIL]
1.645 + sqlite3_step $VM
1.646 + list [sqlite3_column_type $VM 0] [sqlite3_column_type $VM 1] \
1.647 + [sqlite3_column_type $VM 2]
1.648 +} {NULL NULL NULL}
1.649 +do_test bind-13.2 {
1.650 + sqlite3_reset $VM
1.651 + sqlite3_bind_int $VM 1 1
1.652 + sqlite3_bind_int $VM 2 2
1.653 + sqlite3_bind_int $VM 3 3
1.654 + sqlite3_step $VM
1.655 + list [sqlite3_column_type $VM 0] [sqlite3_column_type $VM 1] \
1.656 + [sqlite3_column_type $VM 2]
1.657 +} {INTEGER INTEGER INTEGER}
1.658 +do_test bind-13.3 {
1.659 + sqlite3_reset $VM
1.660 + sqlite3_step $VM
1.661 + list [sqlite3_column_type $VM 0] [sqlite3_column_type $VM 1] \
1.662 + [sqlite3_column_type $VM 2]
1.663 +} {INTEGER INTEGER INTEGER}
1.664 +do_test bind-13.4 {
1.665 + sqlite3_reset $VM
1.666 + sqlite3_clear_bindings $VM
1.667 + sqlite3_step $VM
1.668 + list [sqlite3_column_type $VM 0] [sqlite3_column_type $VM 1] \
1.669 + [sqlite3_column_type $VM 2]
1.670 +} {NULL NULL NULL}
1.671 +sqlite3_finalize $VM
1.672 +
1.673 +finish_test