drh | 82a4851 | 2003-09-06 22:45:20 +0000 | [diff] [blame] | 1 | # 2003 September 6 |
| 2 | # |
| 3 | # The author disclaims copyright to this source code. In place of |
| 4 | # a legal notice, here is a blessing: |
| 5 | # |
| 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. |
| 9 | # |
| 10 | #*********************************************************************** |
| 11 | # This file implements regression tests for SQLite library. The |
| 12 | # focus of this script testing the sqlite_bind API. |
| 13 | # |
drh | 6bf8957 | 2004-11-03 16:27:01 +0000 | [diff] [blame^] | 14 | # $Id: bind.test,v 1.21 2004/11/03 16:27:02 drh Exp $ |
drh | 82a4851 | 2003-09-06 22:45:20 +0000 | [diff] [blame] | 15 | # |
| 16 | |
| 17 | set testdir [file dirname $argv0] |
| 18 | source $testdir/tester.tcl |
| 19 | |
danielk1977 | 17240fd | 2004-05-26 00:07:25 +0000 | [diff] [blame] | 20 | proc sqlite_step {stmt N VALS COLS} { |
| 21 | upvar VALS vals |
| 22 | upvar COLS cols |
| 23 | set vals [list] |
| 24 | set cols [list] |
| 25 | |
| 26 | set rc [sqlite3_step $stmt] |
| 27 | for {set i 0} {$i < [sqlite3_column_count $stmt]} {incr i} { |
| 28 | lappend cols [sqlite3_column_name $stmt $i] |
| 29 | } |
| 30 | for {set i 0} {$i < [sqlite3_data_count $stmt]} {incr i} { |
drh | eb2e176 | 2004-05-27 01:53:56 +0000 | [diff] [blame] | 31 | lappend vals [sqlite3_column_text $stmt $i] |
danielk1977 | 17240fd | 2004-05-26 00:07:25 +0000 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | return $rc |
| 35 | } |
| 36 | |
drh | 82a4851 | 2003-09-06 22:45:20 +0000 | [diff] [blame] | 37 | do_test bind-1.1 { |
| 38 | db close |
drh | ef4ac8f | 2004-06-19 00:16:31 +0000 | [diff] [blame] | 39 | set DB [sqlite3 db test.db] |
drh | 2c6674c | 2004-08-25 04:07:01 +0000 | [diff] [blame] | 40 | execsql {CREATE TABLE t1(a,b,c);} |
| 41 | set VM [sqlite3_prepare $DB {INSERT INTO t1 VALUES(:1,?,:abc)} -1 TAIL] |
drh | 82a4851 | 2003-09-06 22:45:20 +0000 | [diff] [blame] | 42 | set TAIL |
| 43 | } {} |
drh | 75f6a03 | 2004-07-15 14:15:00 +0000 | [diff] [blame] | 44 | do_test bind-1.1.1 { |
| 45 | sqlite3_bind_parameter_count $VM |
| 46 | } 3 |
drh | 895d747 | 2004-08-20 16:02:39 +0000 | [diff] [blame] | 47 | do_test bind-1.1.2 { |
| 48 | sqlite3_bind_parameter_name $VM 1 |
drh | 2c6674c | 2004-08-25 04:07:01 +0000 | [diff] [blame] | 49 | } {:1} |
drh | 895d747 | 2004-08-20 16:02:39 +0000 | [diff] [blame] | 50 | do_test bind-1.1.3 { |
| 51 | sqlite3_bind_parameter_name $VM 2 |
| 52 | } {} |
| 53 | do_test bind-1.1.4 { |
| 54 | sqlite3_bind_parameter_name $VM 3 |
drh | 2c6674c | 2004-08-25 04:07:01 +0000 | [diff] [blame] | 55 | } {:abc} |
drh | 82a4851 | 2003-09-06 22:45:20 +0000 | [diff] [blame] | 56 | do_test bind-1.2 { |
| 57 | sqlite_step $VM N VALUES COLNAMES |
| 58 | } {SQLITE_DONE} |
| 59 | do_test bind-1.3 { |
| 60 | execsql {SELECT rowid, * FROM t1} |
| 61 | } {1 {} {} {}} |
| 62 | do_test bind-1.4 { |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 63 | sqlite3_reset $VM |
drh | 82a4851 | 2003-09-06 22:45:20 +0000 | [diff] [blame] | 64 | sqlite_bind $VM 1 {test value 1} normal |
| 65 | sqlite_step $VM N VALUES COLNAMES |
| 66 | } SQLITE_DONE |
| 67 | do_test bind-1.5 { |
| 68 | execsql {SELECT rowid, * FROM t1} |
| 69 | } {1 {} {} {} 2 {test value 1} {} {}} |
| 70 | do_test bind-1.6 { |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 71 | sqlite3_reset $VM |
drh | 82a4851 | 2003-09-06 22:45:20 +0000 | [diff] [blame] | 72 | sqlite_bind $VM 3 {'test value 2'} normal |
| 73 | sqlite_step $VM N VALUES COLNAMES |
| 74 | } SQLITE_DONE |
| 75 | do_test bind-1.7 { |
| 76 | execsql {SELECT rowid, * FROM t1} |
| 77 | } {1 {} {} {} 2 {test value 1} {} {} 3 {test value 1} {} {'test value 2'}} |
| 78 | do_test bind-1.8 { |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 79 | sqlite3_reset $VM |
drh | 82a4851 | 2003-09-06 22:45:20 +0000 | [diff] [blame] | 80 | set sqlite_static_bind_value 123 |
| 81 | sqlite_bind $VM 1 {} static |
| 82 | sqlite_bind $VM 2 {abcdefg} normal |
| 83 | sqlite_bind $VM 3 {} null |
| 84 | execsql {DELETE FROM t1} |
| 85 | sqlite_step $VM N VALUES COLNAMES |
| 86 | execsql {SELECT rowid, * FROM t1} |
| 87 | } {1 123 abcdefg {}} |
| 88 | do_test bind-1.9 { |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 89 | sqlite3_reset $VM |
drh | 82a4851 | 2003-09-06 22:45:20 +0000 | [diff] [blame] | 90 | sqlite_bind $VM 1 {456} normal |
| 91 | sqlite_step $VM N VALUES COLNAMES |
| 92 | execsql {SELECT rowid, * FROM t1} |
| 93 | } {1 123 abcdefg {} 2 456 abcdefg {}} |
| 94 | |
drh | 82a4851 | 2003-09-06 22:45:20 +0000 | [diff] [blame] | 95 | do_test bind-1.99 { |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 96 | sqlite3_finalize $VM |
danielk1977 | 3cf8606 | 2004-05-26 10:11:05 +0000 | [diff] [blame] | 97 | } SQLITE_OK |
drh | 82a4851 | 2003-09-06 22:45:20 +0000 | [diff] [blame] | 98 | |
drh | 6bf8957 | 2004-11-03 16:27:01 +0000 | [diff] [blame^] | 99 | # Prepare the statement in different ways depending on whether or not |
| 100 | # the $var processing is compiled into the library. |
| 101 | # |
| 102 | ifcapable {tclvar} { |
| 103 | do_test bind-2.1 { |
| 104 | execsql { |
| 105 | DELETE FROM t1; |
| 106 | } |
| 107 | set VM [sqlite3_prepare $DB {INSERT INTO t1 VALUES($one,$::two,${x})} -1 TX] |
| 108 | set TX |
| 109 | } {} |
| 110 | set v1 {$one} |
| 111 | set v2 {$::two} |
| 112 | set v3 {${x}} |
| 113 | } |
| 114 | ifcapable {!tclvar} { |
| 115 | do_test bind-2.1 { |
| 116 | execsql { |
| 117 | DELETE FROM t1; |
| 118 | } |
| 119 | set VM [sqlite3_prepare $DB {INSERT INTO t1 VALUES(:one,:two,:_)} -1 TX] |
| 120 | set TX |
| 121 | } {} |
| 122 | set v1 {:one} |
| 123 | set v2 {:two} |
| 124 | set v3 {:_} |
| 125 | } |
| 126 | |
drh | 895d747 | 2004-08-20 16:02:39 +0000 | [diff] [blame] | 127 | do_test bind-2.1.1 { |
| 128 | sqlite3_bind_parameter_count $VM |
| 129 | } 3 |
| 130 | do_test bind-2.1.2 { |
| 131 | sqlite3_bind_parameter_name $VM 1 |
drh | 6bf8957 | 2004-11-03 16:27:01 +0000 | [diff] [blame^] | 132 | } $v1 |
drh | 895d747 | 2004-08-20 16:02:39 +0000 | [diff] [blame] | 133 | do_test bind-2.1.3 { |
| 134 | sqlite3_bind_parameter_name $VM 2 |
drh | 6bf8957 | 2004-11-03 16:27:01 +0000 | [diff] [blame^] | 135 | } $v2 |
drh | 895d747 | 2004-08-20 16:02:39 +0000 | [diff] [blame] | 136 | do_test bind-2.1.4 { |
| 137 | sqlite3_bind_parameter_name $VM 3 |
drh | 6bf8957 | 2004-11-03 16:27:01 +0000 | [diff] [blame^] | 138 | } $v3 |
drh | fa6bc00 | 2004-09-07 16:19:52 +0000 | [diff] [blame] | 139 | do_test bind-2.1.5 { |
drh | 6bf8957 | 2004-11-03 16:27:01 +0000 | [diff] [blame^] | 140 | sqlite3_bind_parameter_index $VM $v1 |
drh | fa6bc00 | 2004-09-07 16:19:52 +0000 | [diff] [blame] | 141 | } 1 |
| 142 | do_test bind-2.1.6 { |
drh | 6bf8957 | 2004-11-03 16:27:01 +0000 | [diff] [blame^] | 143 | sqlite3_bind_parameter_index $VM $v2 |
drh | fa6bc00 | 2004-09-07 16:19:52 +0000 | [diff] [blame] | 144 | } 2 |
| 145 | do_test bind-2.1.7 { |
drh | 6bf8957 | 2004-11-03 16:27:01 +0000 | [diff] [blame^] | 146 | sqlite3_bind_parameter_index $VM $v3 |
drh | fa6bc00 | 2004-09-07 16:19:52 +0000 | [diff] [blame] | 147 | } 3 |
| 148 | do_test bind-2.1.8 { |
| 149 | sqlite3_bind_parameter_index $VM {:hi} |
| 150 | } 0 |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 151 | |
| 152 | # 32 bit Integers |
| 153 | do_test bind-2.2 { |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 154 | sqlite3_bind_int $VM 1 123 |
| 155 | sqlite3_bind_int $VM 2 456 |
| 156 | sqlite3_bind_int $VM 3 789 |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 157 | sqlite_step $VM N VALUES COLNAMES |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 158 | sqlite3_reset $VM |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 159 | execsql {SELECT rowid, * FROM t1} |
| 160 | } {1 123 456 789} |
| 161 | do_test bind-2.3 { |
drh | 241db31 | 2004-06-22 12:46:53 +0000 | [diff] [blame] | 162 | sqlite3_bind_int $VM 2 -2000000000 |
| 163 | sqlite3_bind_int $VM 3 2000000000 |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 164 | sqlite_step $VM N VALUES COLNAMES |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 165 | sqlite3_reset $VM |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 166 | execsql {SELECT rowid, * FROM t1} |
| 167 | } {1 123 456 789 2 123 -2000000000 2000000000} |
| 168 | do_test bind-2.4 { |
danielk1977 | 35bb9d0 | 2004-05-24 12:55:54 +0000 | [diff] [blame] | 169 | execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1} |
| 170 | } {integer integer integer integer integer integer} |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 171 | do_test bind-2.5 { |
| 172 | execsql { |
| 173 | DELETE FROM t1; |
| 174 | } |
| 175 | } {} |
| 176 | |
| 177 | # 64 bit Integers |
| 178 | do_test bind-3.1 { |
| 179 | sqlite3_bind_int64 $VM 1 32 |
| 180 | sqlite3_bind_int64 $VM 2 -2000000000000 |
| 181 | sqlite3_bind_int64 $VM 3 2000000000000 |
| 182 | sqlite_step $VM N VALUES COLNAMES |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 183 | sqlite3_reset $VM |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 184 | execsql {SELECT rowid, * FROM t1} |
| 185 | } {1 32 -2000000000000 2000000000000} |
| 186 | do_test bind-3.2 { |
danielk1977 | 35bb9d0 | 2004-05-24 12:55:54 +0000 | [diff] [blame] | 187 | execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1} |
| 188 | } {integer integer integer} |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 189 | do_test bind-3.3 { |
| 190 | execsql { |
| 191 | DELETE FROM t1; |
| 192 | } |
| 193 | } {} |
| 194 | |
| 195 | # Doubles |
| 196 | do_test bind-4.1 { |
| 197 | sqlite3_bind_double $VM 1 1234.1234 |
| 198 | sqlite3_bind_double $VM 2 0.00001 |
| 199 | sqlite3_bind_double $VM 3 123456789 |
| 200 | sqlite_step $VM N VALUES COLNAMES |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 201 | sqlite3_reset $VM |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 202 | execsql {SELECT rowid, * FROM t1} |
drh | 92febd9 | 2004-08-20 18:34:20 +0000 | [diff] [blame] | 203 | } {1 1234.1234 1e-05 123456789.0} |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 204 | do_test bind-4.2 { |
danielk1977 | 35bb9d0 | 2004-05-24 12:55:54 +0000 | [diff] [blame] | 205 | execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1} |
| 206 | } {real real real} |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 207 | do_test bind-4.3 { |
| 208 | execsql { |
| 209 | DELETE FROM t1; |
| 210 | } |
| 211 | } {} |
| 212 | |
| 213 | # NULL |
| 214 | do_test bind-5.1 { |
| 215 | sqlite3_bind_null $VM 1 |
| 216 | sqlite3_bind_null $VM 2 |
| 217 | sqlite3_bind_null $VM 3 |
| 218 | sqlite_step $VM N VALUES COLNAMES |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 219 | sqlite3_reset $VM |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 220 | execsql {SELECT rowid, * FROM t1} |
| 221 | } {1 {} {} {}} |
| 222 | do_test bind-5.2 { |
danielk1977 | 35bb9d0 | 2004-05-24 12:55:54 +0000 | [diff] [blame] | 223 | execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1} |
| 224 | } {null null null} |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 225 | do_test bind-5.3 { |
| 226 | execsql { |
| 227 | DELETE FROM t1; |
| 228 | } |
| 229 | } {} |
| 230 | |
| 231 | # UTF-8 text |
| 232 | do_test bind-6.1 { |
| 233 | sqlite3_bind_text $VM 1 hellothere 5 |
danielk1977 | c572ef7 | 2004-05-27 09:28:41 +0000 | [diff] [blame] | 234 | sqlite3_bind_text $VM 2 ".." 1 |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 235 | sqlite3_bind_text $VM 3 world -1 |
| 236 | sqlite_step $VM N VALUES COLNAMES |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 237 | sqlite3_reset $VM |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 238 | execsql {SELECT rowid, * FROM t1} |
| 239 | } {1 hello . world} |
| 240 | do_test bind-6.2 { |
danielk1977 | 35bb9d0 | 2004-05-24 12:55:54 +0000 | [diff] [blame] | 241 | execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1} |
| 242 | } {text text text} |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 243 | do_test bind-6.3 { |
| 244 | execsql { |
| 245 | DELETE FROM t1; |
| 246 | } |
| 247 | } {} |
| 248 | |
| 249 | # UTF-16 text |
| 250 | do_test bind-7.1 { |
| 251 | sqlite3_bind_text16 $VM 1 [encoding convertto unicode hellothere] 10 |
| 252 | sqlite3_bind_text16 $VM 2 [encoding convertto unicode ""] 0 |
| 253 | sqlite3_bind_text16 $VM 3 [encoding convertto unicode world] 10 |
| 254 | sqlite_step $VM N VALUES COLNAMES |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 255 | sqlite3_reset $VM |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 256 | execsql {SELECT rowid, * FROM t1} |
| 257 | } {1 hello {} world} |
| 258 | do_test bind-7.2 { |
danielk1977 | 35bb9d0 | 2004-05-24 12:55:54 +0000 | [diff] [blame] | 259 | execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1} |
| 260 | } {text text text} |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 261 | do_test bind-7.3 { |
| 262 | execsql { |
| 263 | DELETE FROM t1; |
| 264 | } |
| 265 | } {} |
| 266 | |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 267 | # Test that the 'out of range' error works. |
| 268 | do_test bind-8.1 { |
| 269 | catch { sqlite3_bind_null $VM 0 } |
| 270 | } {1} |
| 271 | do_test bind-8.2 { |
| 272 | sqlite3_errmsg $DB |
| 273 | } {bind index out of range} |
| 274 | do_test bind-8.3 { |
| 275 | encoding convertfrom unicode [sqlite3_errmsg16 $DB] |
| 276 | } {bind index out of range} |
| 277 | do_test bind-8.4 { |
| 278 | sqlite3_bind_null $VM 1 |
| 279 | sqlite3_errmsg $DB |
| 280 | } {not an error} |
| 281 | do_test bind-8.5 { |
| 282 | catch { sqlite3_bind_null $VM 4 } |
| 283 | } {1} |
| 284 | do_test bind-8.6 { |
| 285 | sqlite3_errmsg $DB |
| 286 | } {bind index out of range} |
| 287 | do_test bind-8.7 { |
| 288 | encoding convertfrom unicode [sqlite3_errmsg16 $DB] |
| 289 | } {bind index out of range} |
| 290 | |
danielk1977 | f461889 | 2004-06-28 13:09:11 +0000 | [diff] [blame] | 291 | do_test bind-8.8 { |
| 292 | catch { sqlite3_bind_blob $VM 0 "abc" 3 } |
| 293 | } {1} |
| 294 | do_test bind-8.9 { |
| 295 | catch { sqlite3_bind_blob $VM 4 "abc" 3 } |
| 296 | } {1} |
| 297 | do_test bind-8.10 { |
| 298 | catch { sqlite3_bind_text $VM 0 "abc" 3 } |
| 299 | } {1} |
| 300 | do_test bind-8.11 { |
| 301 | catch { sqlite3_bind_text16 $VM 4 "abc" 2 } |
| 302 | } {1} |
| 303 | do_test bind-8.12 { |
| 304 | catch { sqlite3_bind_int $VM 0 5 } |
| 305 | } {1} |
| 306 | do_test bind-8.13 { |
| 307 | catch { sqlite3_bind_int $VM 4 5 } |
| 308 | } {1} |
| 309 | do_test bind-8.14 { |
| 310 | catch { sqlite3_bind_double $VM 0 5.0 } |
| 311 | } {1} |
| 312 | do_test bind-8.15 { |
| 313 | catch { sqlite3_bind_double $VM 4 6.0 } |
| 314 | } {1} |
danielk1977 | 6622cce | 2004-05-20 11:00:52 +0000 | [diff] [blame] | 315 | |
drh | fa6bc00 | 2004-09-07 16:19:52 +0000 | [diff] [blame] | 316 | do_test bind-8.99 { |
danielk1977 | 106bb23 | 2004-05-21 10:08:53 +0000 | [diff] [blame] | 317 | sqlite3_finalize $VM |
danielk1977 | 3cf8606 | 2004-05-26 10:11:05 +0000 | [diff] [blame] | 318 | } SQLITE_OK |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 319 | |
drh | fa6bc00 | 2004-09-07 16:19:52 +0000 | [diff] [blame] | 320 | do_test bind-9.1 { |
| 321 | execsql { |
| 322 | CREATE TABLE t2(a,b,c,d,e,f); |
| 323 | } |
| 324 | set rc [catch { |
| 325 | sqlite3_prepare $DB { |
| 326 | INSERT INTO t2(a) VALUES(?0) |
| 327 | } -1 TAIL |
| 328 | } msg] |
| 329 | lappend rc $msg |
| 330 | } {1 {(1) variable number must be between ?1 and ?999}} |
| 331 | do_test bind-9.2 { |
| 332 | set rc [catch { |
| 333 | sqlite3_prepare $DB { |
| 334 | INSERT INTO t2(a) VALUES(?1000) |
| 335 | } -1 TAIL |
| 336 | } msg] |
| 337 | lappend rc $msg |
| 338 | } {1 {(1) variable number must be between ?1 and ?999}} |
| 339 | do_test bind-9.3 { |
| 340 | set VM [ |
| 341 | sqlite3_prepare $DB { |
| 342 | INSERT INTO t2(a,b) VALUES(?1,?999) |
| 343 | } -1 TAIL |
| 344 | ] |
| 345 | sqlite3_bind_parameter_count $VM |
| 346 | } {999} |
| 347 | catch {sqlite3_finalize $VM} |
| 348 | do_test bind-9.4 { |
| 349 | set VM [ |
| 350 | sqlite3_prepare $DB { |
| 351 | INSERT INTO t2(a,b,c,d) VALUES(?1,?999,?,?) |
| 352 | } -1 TAIL |
| 353 | ] |
| 354 | sqlite3_bind_parameter_count $VM |
| 355 | } {1001} |
| 356 | do_test bind-9.5 { |
| 357 | sqlite3_bind_int $VM 1 1 |
| 358 | sqlite3_bind_int $VM 999 999 |
| 359 | sqlite3_bind_int $VM 1000 1000 |
| 360 | sqlite3_bind_int $VM 1001 1001 |
| 361 | sqlite3_step $VM |
| 362 | } SQLITE_DONE |
| 363 | do_test bind-9.6 { |
| 364 | sqlite3_finalize $VM |
| 365 | } SQLITE_OK |
| 366 | do_test bind-9.7 { |
| 367 | execsql {SELECT * FROM t2} |
| 368 | } {1 999 1000 1001 {} {}} |
danielk1977 | 51e3d8e | 2004-05-20 01:12:34 +0000 | [diff] [blame] | 369 | |
drh | 6bf8957 | 2004-11-03 16:27:01 +0000 | [diff] [blame^] | 370 | ifcapable {tclvar} { |
| 371 | do_test bind-10.1 { |
| 372 | catch {sqlite3_finalize $VM} |
| 373 | set VM [ |
| 374 | sqlite3_prepare $DB { |
| 375 | INSERT INTO t2(a,b,c,d,e,f) VALUES(:abc,$abc,:abc,$ab,$abc,:abc) |
| 376 | } -1 TAIL |
| 377 | ] |
| 378 | sqlite3_bind_parameter_count $VM |
| 379 | } 3 |
| 380 | set v1 {$abc} |
| 381 | set v2 {$ab} |
| 382 | } |
| 383 | ifcapable {!tclvar} { |
| 384 | do_test bind-10.1 { |
| 385 | catch {sqlite3_finalize $VM} |
| 386 | set VM [ |
| 387 | sqlite3_prepare $DB { |
| 388 | INSERT INTO t2(a,b,c,d,e,f) VALUES(:abc,:xyz,:abc,:xy,:xyz,:abc) |
| 389 | } -1 TAIL |
| 390 | ] |
| 391 | sqlite3_bind_parameter_count $VM |
| 392 | } 3 |
| 393 | set v1 {:xyz} |
| 394 | set v2 {:xy} |
| 395 | } |
drh | fa6bc00 | 2004-09-07 16:19:52 +0000 | [diff] [blame] | 396 | do_test bind-10.2 { |
| 397 | sqlite3_bind_parameter_index $VM :abc |
| 398 | } 1 |
| 399 | do_test bind-10.3 { |
drh | 6bf8957 | 2004-11-03 16:27:01 +0000 | [diff] [blame^] | 400 | sqlite3_bind_parameter_index $VM $v1 |
drh | fa6bc00 | 2004-09-07 16:19:52 +0000 | [diff] [blame] | 401 | } 2 |
| 402 | do_test bind-10.4 { |
drh | 6bf8957 | 2004-11-03 16:27:01 +0000 | [diff] [blame^] | 403 | sqlite3_bind_parameter_index $VM $v2 |
drh | fa6bc00 | 2004-09-07 16:19:52 +0000 | [diff] [blame] | 404 | } 3 |
| 405 | do_test bind-10.5 { |
| 406 | sqlite3_bind_parameter_name $VM 1 |
| 407 | } :abc |
| 408 | do_test bind-10.6 { |
| 409 | sqlite3_bind_parameter_name $VM 2 |
drh | 6bf8957 | 2004-11-03 16:27:01 +0000 | [diff] [blame^] | 410 | } $v1 |
drh | fa6bc00 | 2004-09-07 16:19:52 +0000 | [diff] [blame] | 411 | do_test bind-10.7 { |
| 412 | sqlite3_bind_parameter_name $VM 3 |
drh | 6bf8957 | 2004-11-03 16:27:01 +0000 | [diff] [blame^] | 413 | } $v2 |
drh | fa6bc00 | 2004-09-07 16:19:52 +0000 | [diff] [blame] | 414 | do_test bind-10.8 { |
| 415 | sqlite3_bind_int $VM 1 1 |
| 416 | sqlite3_bind_int $VM 2 2 |
| 417 | sqlite3_bind_int $VM 3 3 |
| 418 | sqlite3_step $VM |
| 419 | } SQLITE_DONE |
| 420 | do_test bind-10.9 { |
| 421 | sqlite3_finalize $VM |
| 422 | } SQLITE_OK |
| 423 | do_test bind-10.10 { |
| 424 | execsql {SELECT * FROM t2} |
| 425 | } {1 999 1000 1001 {} {} 1 2 1 3 2 1} |
drh | 82a4851 | 2003-09-06 22:45:20 +0000 | [diff] [blame] | 426 | |
drh | 971a7c8 | 2004-09-24 12:48:12 +0000 | [diff] [blame] | 427 | # Ticket #918 |
| 428 | # |
| 429 | do_test bind-10.11 { |
| 430 | catch {sqlite3_finalize $VM} |
| 431 | set VM [ |
| 432 | sqlite3_prepare $DB { |
| 433 | INSERT INTO t2(a,b,c,d,e,f) VALUES(:abc,?,?4,:pqr,:abc,?4) |
| 434 | } -1 TAIL |
| 435 | ] |
| 436 | sqlite3_bind_parameter_count $VM |
| 437 | } 5 |
| 438 | do_test bind-10.12 { |
| 439 | sqlite3_bind_parameter_index $VM :xyz |
| 440 | } 0 |
| 441 | do_test bind-10.13 { |
| 442 | sqlite3_bind_parameter_index $VM {} |
| 443 | } 0 |
| 444 | do_test bind-10.14 { |
| 445 | sqlite3_bind_parameter_index $VM :pqr |
| 446 | } 5 |
| 447 | do_test bind-10.15 { |
| 448 | sqlite3_bind_parameter_index $VM ?4 |
| 449 | } 4 |
| 450 | do_test bind-10.16 { |
| 451 | sqlite3_bind_parameter_name $VM 1 |
| 452 | } :abc |
| 453 | do_test bind-10.16 { |
| 454 | sqlite3_bind_parameter_name $VM 2 |
| 455 | } {} |
| 456 | do_test bind-10.16 { |
| 457 | sqlite3_bind_parameter_name $VM 3 |
| 458 | } {} |
| 459 | do_test bind-10.16 { |
| 460 | sqlite3_bind_parameter_name $VM 4 |
| 461 | } {?4} |
| 462 | do_test bind-10.16 { |
| 463 | sqlite3_bind_parameter_name $VM 5 |
| 464 | } :pqr |
| 465 | catch {sqlite3_finalize $VM} |
| 466 | |
drh | 82a4851 | 2003-09-06 22:45:20 +0000 | [diff] [blame] | 467 | finish_test |