OLD | NEW |
1 # 2009 Nov 11 | 1 # 2009 Nov 11 |
2 # | 2 # |
3 # The author disclaims copyright to this source code. In place of | 3 # The author disclaims copyright to this source code. In place of |
4 # a legal notice, here is a blessing: | 4 # a legal notice, here is a blessing: |
5 # | 5 # |
6 # May you do good and not evil. | 6 # May you do good and not evil. |
7 # May you find forgiveness for yourself and forgive others. | 7 # May you find forgiveness for yourself and forgive others. |
8 # May you share freely, never taking more than you give. | 8 # May you share freely, never taking more than you give. |
9 # | 9 # |
10 #*********************************************************************** | 10 #*********************************************************************** |
11 # | 11 # |
12 # The focus of this file is testing the CLI shell tool. | 12 # The focus of this file is testing the CLI shell tool. |
13 # | 13 # |
14 # $Id: shell1.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $ | |
15 # | 14 # |
16 | 15 |
17 # Test plan: | 16 # Test plan: |
18 # | 17 # |
19 # shell1-1.*: Basic command line option handling. | 18 # shell1-1.*: Basic command line option handling. |
20 # shell1-2.*: Basic "dot" command token parsing. | 19 # shell1-2.*: Basic "dot" command token parsing. |
21 # shell1-3.*: Basic test that "dot" command can be called. | 20 # shell1-3.*: Basic test that "dot" command can be called. |
22 # | 21 # |
23 | 22 set testdir [file dirname $argv0] |
24 package require sqlite3 | 23 source $testdir/tester.tcl |
25 | 24 if {$tcl_platform(platform)=="windows"} { |
26 set CLI "./sqlite3" | 25 set CLI "sqlite3.exe" |
27 | 26 } else { |
28 proc do_test {name cmd expected} { | 27 set CLI "./sqlite3" |
29 puts -nonewline "$name ..." | |
30 set res [uplevel $cmd] | |
31 if {$res eq $expected} { | |
32 puts Ok | |
33 } else { | |
34 puts Error | |
35 puts " Got: $res" | |
36 puts " Expected: $expected" | |
37 exit | |
38 } | |
39 } | 28 } |
40 | 29 if {![file executable $CLI]} { |
41 proc execsql {sql} { | 30 finish_test |
42 uplevel [list db eval $sql] | 31 return |
43 } | 32 } |
44 | 33 db close |
45 proc catchsql {sql} { | 34 forcedelete test.db test.db-journal test.db-wal |
46 set rc [catch {uplevel [list db eval $sql]} msg] | |
47 list $rc $msg | |
48 } | |
49 | |
50 proc catchcmd {db {cmd ""}} { | |
51 global CLI | |
52 set out [open cmds.txt w] | |
53 puts $out $cmd | |
54 close $out | |
55 set line "exec $CLI $db < cmds.txt" | |
56 set rc [catch { eval $line } msg] | |
57 list $rc $msg | |
58 } | |
59 | |
60 file delete -force test.db test.db.journal | |
61 sqlite3 db test.db | 35 sqlite3 db test.db |
62 | 36 |
63 #---------------------------------------------------------------------------- | 37 #---------------------------------------------------------------------------- |
64 # Test cases shell1-1.*: Basic command line option handling. | 38 # Test cases shell1-1.*: Basic command line option handling. |
65 # | 39 # |
66 | 40 |
67 # invalid option | 41 # invalid option |
68 do_test shell1-1.1.1 { | 42 do_test shell1-1.1.1 { |
69 set res [catchcmd "-bad test.db" ""] | 43 set res [catchcmd "-bad test.db" ""] |
70 set rc [lindex $res 0] | 44 set rc [lindex $res 0] |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 do_test shell1-1.6.1 { | 98 do_test shell1-1.6.1 { |
125 catchcmd "-bail test.db" "" | 99 catchcmd "-bail test.db" "" |
126 } {0 {}} | 100 } {0 {}} |
127 | 101 |
128 # -interactive force interactive I/O | 102 # -interactive force interactive I/O |
129 do_test shell1-1.7.1 { | 103 do_test shell1-1.7.1 { |
130 set res [catchcmd "-interactive test.db" ".quit"] | 104 set res [catchcmd "-interactive test.db" ".quit"] |
131 set rc [lindex $res 0] | 105 set rc [lindex $res 0] |
132 list $rc \ | 106 list $rc \ |
133 [regexp {SQLite version} $res] \ | 107 [regexp {SQLite version} $res] \ |
134 [regexp {Enter SQL statements} $res] | 108 [regexp {Enter ".help" for usage hints} $res] |
135 } {0 1 1} | 109 } {0 1 1} |
136 | 110 |
137 # -batch force batch I/O | 111 # -batch force batch I/O |
138 do_test shell1-1.8.1 { | 112 do_test shell1-1.8.1 { |
139 catchcmd "-batch test.db" "" | 113 catchcmd "-batch test.db" "" |
140 } {0 {}} | 114 } {0 {}} |
141 | 115 |
142 # -column set output mode to 'column' | 116 # -column set output mode to 'column' |
143 do_test shell1-1.9.1 { | 117 do_test shell1-1.9.1 { |
144 catchcmd "-column test.db" "" | 118 catchcmd "-column test.db" "" |
(...skipping 23 matching lines...) Expand all Loading... |
168 do_test shell1-1.14.1 { | 142 do_test shell1-1.14.1 { |
169 catchcmd "-separator 'x' test.db" "" | 143 catchcmd "-separator 'x' test.db" "" |
170 } {0 {}} | 144 } {0 {}} |
171 do_test shell1-1.14.2 { | 145 do_test shell1-1.14.2 { |
172 catchcmd "-separator x test.db" "" | 146 catchcmd "-separator x test.db" "" |
173 } {0 {}} | 147 } {0 {}} |
174 do_test shell1-1.14.3 { | 148 do_test shell1-1.14.3 { |
175 set res [catchcmd "-separator" ""] | 149 set res [catchcmd "-separator" ""] |
176 set rc [lindex $res 0] | 150 set rc [lindex $res 0] |
177 list $rc \ | 151 list $rc \ |
178 [regexp {Error: missing argument for option: -separator} $res] | 152 [regexp {Error: missing argument to -separator} $res] |
179 } {1 1} | 153 } {1 1} |
180 | 154 |
181 # -stats print memory stats before each finalize | 155 # -stats print memory stats before each finalize |
182 do_test shell1-1.14b.1 { | 156 do_test shell1-1.14b.1 { |
183 catchcmd "-stats test.db" "" | 157 catchcmd "-stats test.db" "" |
184 } {0 {}} | 158 } {0 {}} |
185 | 159 |
186 # -nullvalue 'text' set text string for NULL values | 160 # -nullvalue 'text' set text string for NULL values |
187 do_test shell1-1.15.1 { | 161 do_test shell1-1.15.1 { |
188 catchcmd "-nullvalue 'x' test.db" "" | 162 catchcmd "-nullvalue 'x' test.db" "" |
189 } {0 {}} | 163 } {0 {}} |
190 do_test shell1-1.15.2 { | 164 do_test shell1-1.15.2 { |
191 catchcmd "-nullvalue x test.db" "" | 165 catchcmd "-nullvalue x test.db" "" |
192 } {0 {}} | 166 } {0 {}} |
193 do_test shell1-1.15.3 { | 167 do_test shell1-1.15.3 { |
194 set res [catchcmd "-nullvalue" ""] | 168 set res [catchcmd "-nullvalue" ""] |
195 set rc [lindex $res 0] | 169 set rc [lindex $res 0] |
196 list $rc \ | 170 list $rc \ |
197 [regexp {Error: missing argument for option: -nullvalue} $res] | 171 [regexp {Error: missing argument to -nullvalue} $res] |
198 } {1 1} | 172 } {1 1} |
199 | 173 |
200 # -version show SQLite version | 174 # -version show SQLite version |
201 do_test shell1-1.16.1 { | 175 do_test shell1-1.16.1 { |
202 catchcmd "-version test.db" "" | 176 set x [catchcmd "-version test.db" ""] |
203 } {0 3.7.6.3} | 177 } {/3.[0-9.]+ 20\d\d-[01]\d-\d\d \d\d:\d\d:\d\d [0-9a-f]+/} |
204 | 178 |
205 #---------------------------------------------------------------------------- | 179 #---------------------------------------------------------------------------- |
206 # Test cases shell1-2.*: Basic "dot" command token parsing. | 180 # Test cases shell1-2.*: Basic "dot" command token parsing. |
207 # | 181 # |
208 | 182 |
209 # check first token handling | 183 # check first token handling |
210 do_test shell1-2.1.1 { | 184 do_test shell1-2.1.1 { |
211 catchcmd "test.db" ".foo" | 185 catchcmd "test.db" ".foo" |
212 } {1 {Error: unknown command or invalid arguments: "foo". Enter ".help" for hel
p}} | 186 } {1 {Error: unknown command or invalid arguments: "foo". Enter ".help" for hel
p}} |
213 do_test shell1-2.1.2 { | 187 do_test shell1-2.1.2 { |
(...skipping 25 matching lines...) Expand all Loading... |
239 | 213 |
240 # check multiple tokens, and quoted tokens | 214 # check multiple tokens, and quoted tokens |
241 do_test shell1-2.3.1 { | 215 do_test shell1-2.3.1 { |
242 catchcmd "test.db" ".explain 1" | 216 catchcmd "test.db" ".explain 1" |
243 } {0 {}} | 217 } {0 {}} |
244 do_test shell1-2.3.2 { | 218 do_test shell1-2.3.2 { |
245 catchcmd "test.db" ".explain on" | 219 catchcmd "test.db" ".explain on" |
246 } {0 {}} | 220 } {0 {}} |
247 do_test shell1-2.3.3 { | 221 do_test shell1-2.3.3 { |
248 catchcmd "test.db" ".explain \"1 2 3\"" | 222 catchcmd "test.db" ".explain \"1 2 3\"" |
249 } {0 {}} | 223 } {1 {ERROR: Not a boolean value: "1 2 3". Assuming "no".}} |
250 do_test shell1-2.3.4 { | 224 do_test shell1-2.3.4 { |
251 catchcmd "test.db" ".explain \"OFF\"" | 225 catchcmd "test.db" ".explain \"OFF\"" |
252 } {0 {}} | 226 } {0 {}} |
253 do_test shell1-2.3.5 { | 227 do_test shell1-2.3.5 { |
254 catchcmd "test.db" ".\'explain\' \'OFF\'" | 228 catchcmd "test.db" ".\'explain\' \'OFF\'" |
255 } {0 {}} | 229 } {0 {}} |
256 do_test shell1-2.3.6 { | 230 do_test shell1-2.3.6 { |
257 catchcmd "test.db" ".explain \'OFF\'" | 231 catchcmd "test.db" ".explain \'OFF\'" |
258 } {0 {}} | 232 } {0 {}} |
259 do_test shell1-2.3.7 { | 233 do_test shell1-2.3.7 { |
(...skipping 12 matching lines...) Expand all Loading... |
272 } {0 {}} | 246 } {0 {}} |
273 | 247 |
274 | 248 |
275 #---------------------------------------------------------------------------- | 249 #---------------------------------------------------------------------------- |
276 # Test cases shell1-3.*: Basic test that "dot" command can be called. | 250 # Test cases shell1-3.*: Basic test that "dot" command can be called. |
277 # | 251 # |
278 | 252 |
279 # .backup ?DB? FILE Backup DB (default "main") to FILE | 253 # .backup ?DB? FILE Backup DB (default "main") to FILE |
280 do_test shell1-3.1.1 { | 254 do_test shell1-3.1.1 { |
281 catchcmd "test.db" ".backup" | 255 catchcmd "test.db" ".backup" |
282 } {1 {Error: unknown command or invalid arguments: "backup". Enter ".help" for
help}} | 256 } {1 {missing FILENAME argument on .backup}} |
283 do_test shell1-3.1.2 { | 257 do_test shell1-3.1.2 { |
284 catchcmd "test.db" ".backup FOO" | 258 catchcmd "test.db" ".backup FOO" |
285 } {0 {}} | 259 } {0 {}} |
286 do_test shell1-3.1.3 { | 260 do_test shell1-3.1.3 { |
287 catchcmd "test.db" ".backup FOO BAR" | 261 catchcmd "test.db" ".backup FOO BAR" |
288 } {1 {Error: unknown database FOO}} | 262 } {1 {Error: unknown database FOO}} |
289 do_test shell1-3.1.4 { | 263 do_test shell1-3.1.4 { |
290 # too many arguments | 264 # too many arguments |
291 catchcmd "test.db" ".backup FOO BAR BAD" | 265 catchcmd "test.db" ".backup FOO BAR BAD" |
292 } {1 {Error: unknown command or invalid arguments: "backup". Enter ".help" for
help}} | 266 } {1 {too many arguments to .backup}} |
293 | 267 |
294 # .bail ON|OFF Stop after hitting an error. Default OFF | 268 # .bail ON|OFF Stop after hitting an error. Default OFF |
295 do_test shell1-3.2.1 { | 269 do_test shell1-3.2.1 { |
296 catchcmd "test.db" ".bail" | 270 catchcmd "test.db" ".bail" |
297 } {1 {Error: unknown command or invalid arguments: "bail". Enter ".help" for he
lp}} | 271 } {1 {Usage: .bail on|off}} |
298 do_test shell1-3.2.2 { | 272 do_test shell1-3.2.2 { |
299 catchcmd "test.db" ".bail ON" | 273 catchcmd "test.db" ".bail ON" |
300 } {0 {}} | 274 } {0 {}} |
301 do_test shell1-3.2.3 { | 275 do_test shell1-3.2.3 { |
302 catchcmd "test.db" ".bail OFF" | 276 catchcmd "test.db" ".bail OFF" |
303 } {0 {}} | 277 } {0 {}} |
304 do_test shell1-3.2.4 { | 278 do_test shell1-3.2.4 { |
305 # too many arguments | 279 # too many arguments |
306 catchcmd "test.db" ".bail OFF BAD" | 280 catchcmd "test.db" ".bail OFF BAD" |
307 } {1 {Error: unknown command or invalid arguments: "bail". Enter ".help" for he
lp}} | 281 } {1 {Usage: .bail on|off}} |
308 | 282 |
309 # .databases List names and files of attached databases | 283 # .databases List names and files of attached databases |
310 do_test shell1-3.3.1 { | 284 do_test shell1-3.3.1 { |
311 set res [catchcmd "test.db" ".databases"] | 285 catchcmd "-csv test.db" ".databases" |
312 regexp {0.*main.*test\.db} $res | 286 } "/0 +.*main +[string map {/ .} [string range [get_pwd] 0 10]].*/" |
313 } {1} | |
314 do_test shell1-3.3.2 { | 287 do_test shell1-3.3.2 { |
315 # too many arguments | 288 # extra arguments ignored |
316 catchcmd "test.db" ".databases BAD" | 289 catchcmd "test.db" ".databases BAD" |
317 } {1 {Error: unknown command or invalid arguments: "databases". Enter ".help" f
or help}} | 290 } "/0 +.*main +[string map {/ .} [string range [get_pwd] 0 10]].*/" |
318 | 291 |
319 # .dump ?TABLE? ... Dump the database in an SQL text format | 292 # .dump ?TABLE? ... Dump the database in an SQL text format |
320 # If TABLE specified, only dump tables matching | 293 # If TABLE specified, only dump tables matching |
321 # LIKE pattern TABLE. | 294 # LIKE pattern TABLE. |
322 do_test shell1-3.4.1 { | 295 do_test shell1-3.4.1 { |
323 set res [catchcmd "test.db" ".dump"] | 296 set res [catchcmd "test.db" ".dump"] |
324 list [regexp {BEGIN TRANSACTION;} $res] \ | 297 list [regexp {BEGIN TRANSACTION;} $res] \ |
325 [regexp {COMMIT;} $res] | 298 [regexp {COMMIT;} $res] |
326 } {1 1} | 299 } {1 1} |
327 do_test shell1-3.4.2 { | 300 do_test shell1-3.4.2 { |
328 set res [catchcmd "test.db" ".dump FOO"] | 301 set res [catchcmd "test.db" ".dump FOO"] |
329 list [regexp {BEGIN TRANSACTION;} $res] \ | 302 list [regexp {BEGIN TRANSACTION;} $res] \ |
330 [regexp {COMMIT;} $res] | 303 [regexp {COMMIT;} $res] |
331 } {1 1} | 304 } {1 1} |
332 do_test shell1-3.4.3 { | 305 do_test shell1-3.4.3 { |
333 # too many arguments | 306 # too many arguments |
334 catchcmd "test.db" ".dump FOO BAD" | 307 catchcmd "test.db" ".dump FOO BAD" |
335 } {1 {Error: unknown command or invalid arguments: "dump". Enter ".help" for he
lp}} | 308 } {1 {Usage: .dump ?LIKE-PATTERN?}} |
336 | 309 |
337 # .echo ON|OFF Turn command echo on or off | 310 # .echo ON|OFF Turn command echo on or off |
338 do_test shell1-3.5.1 { | 311 do_test shell1-3.5.1 { |
339 catchcmd "test.db" ".echo" | 312 catchcmd "test.db" ".echo" |
340 } {1 {Error: unknown command or invalid arguments: "echo". Enter ".help" for he
lp}} | 313 } {1 {Usage: .echo on|off}} |
341 do_test shell1-3.5.2 { | 314 do_test shell1-3.5.2 { |
342 catchcmd "test.db" ".echo ON" | 315 catchcmd "test.db" ".echo ON" |
343 } {0 {}} | 316 } {0 {}} |
344 do_test shell1-3.5.3 { | 317 do_test shell1-3.5.3 { |
345 catchcmd "test.db" ".echo OFF" | 318 catchcmd "test.db" ".echo OFF" |
346 } {0 {}} | 319 } {0 {}} |
347 do_test shell1-3.5.4 { | 320 do_test shell1-3.5.4 { |
348 # too many arguments | 321 # too many arguments |
349 catchcmd "test.db" ".echo OFF BAD" | 322 catchcmd "test.db" ".echo OFF BAD" |
350 } {1 {Error: unknown command or invalid arguments: "echo". Enter ".help" for he
lp}} | 323 } {1 {Usage: .echo on|off}} |
351 | 324 |
352 # .exit Exit this program | 325 # .exit Exit this program |
353 do_test shell1-3.6.1 { | 326 do_test shell1-3.6.1 { |
354 catchcmd "test.db" ".exit" | 327 catchcmd "test.db" ".exit" |
355 } {0 {}} | 328 } {0 {}} |
356 do_test shell1-3.6.2 { | |
357 # too many arguments | |
358 catchcmd "test.db" ".exit BAD" | |
359 } {1 {Error: unknown command or invalid arguments: "exit". Enter ".help" for he
lp}} | |
360 | 329 |
361 # .explain ON|OFF Turn output mode suitable for EXPLAIN on or off. | 330 # .explain ON|OFF Turn output mode suitable for EXPLAIN on or off. |
362 do_test shell1-3.7.1 { | 331 do_test shell1-3.7.1 { |
363 catchcmd "test.db" ".explain" | 332 catchcmd "test.db" ".explain" |
364 # explain is the exception to the booleans. without an option, it turns it on
. | 333 # explain is the exception to the booleans. without an option, it turns it on
. |
365 } {0 {}} | 334 } {0 {}} |
366 do_test shell1-3.7.2 { | 335 do_test shell1-3.7.2 { |
367 catchcmd "test.db" ".explain ON" | 336 catchcmd "test.db" ".explain ON" |
368 } {0 {}} | 337 } {0 {}} |
369 do_test shell1-3.7.3 { | 338 do_test shell1-3.7.3 { |
370 catchcmd "test.db" ".explain OFF" | 339 catchcmd "test.db" ".explain OFF" |
371 } {0 {}} | 340 } {0 {}} |
372 do_test shell1-3.7.4 { | 341 do_test shell1-3.7.4 { |
373 # too many arguments | 342 # extra arguments ignored |
374 catchcmd "test.db" ".explain OFF BAD" | 343 catchcmd "test.db" ".explain OFF BAD" |
375 } {1 {Error: unknown command or invalid arguments: "explain". Enter ".help" for
help}} | 344 } {0 {}} |
376 | 345 |
377 | 346 |
378 # .header(s) ON|OFF Turn display of headers on or off | 347 # .header(s) ON|OFF Turn display of headers on or off |
379 do_test shell1-3.9.1 { | 348 do_test shell1-3.9.1 { |
380 catchcmd "test.db" ".header" | 349 catchcmd "test.db" ".header" |
381 } {1 {Error: unknown command or invalid arguments: "header". Enter ".help" for
help}} | 350 } {1 {Usage: .headers on|off}} |
382 do_test shell1-3.9.2 { | 351 do_test shell1-3.9.2 { |
383 catchcmd "test.db" ".header ON" | 352 catchcmd "test.db" ".header ON" |
384 } {0 {}} | 353 } {0 {}} |
385 do_test shell1-3.9.3 { | 354 do_test shell1-3.9.3 { |
386 catchcmd "test.db" ".header OFF" | 355 catchcmd "test.db" ".header OFF" |
387 } {0 {}} | 356 } {0 {}} |
388 do_test shell1-3.9.4 { | 357 do_test shell1-3.9.4 { |
389 # too many arguments | 358 # too many arguments |
390 catchcmd "test.db" ".header OFF BAD" | 359 catchcmd "test.db" ".header OFF BAD" |
391 } {1 {Error: unknown command or invalid arguments: "header". Enter ".help" for
help}} | 360 } {1 {Usage: .headers on|off}} |
392 | 361 |
393 do_test shell1-3.9.5 { | 362 do_test shell1-3.9.5 { |
394 catchcmd "test.db" ".headers" | 363 catchcmd "test.db" ".headers" |
395 } {1 {Error: unknown command or invalid arguments: "headers". Enter ".help" for
help}} | 364 } {1 {Usage: .headers on|off}} |
396 do_test shell1-3.9.6 { | 365 do_test shell1-3.9.6 { |
397 catchcmd "test.db" ".headers ON" | 366 catchcmd "test.db" ".headers ON" |
398 } {0 {}} | 367 } {0 {}} |
399 do_test shell1-3.9.7 { | 368 do_test shell1-3.9.7 { |
400 catchcmd "test.db" ".headers OFF" | 369 catchcmd "test.db" ".headers OFF" |
401 } {0 {}} | 370 } {0 {}} |
402 do_test shell1-3.9.8 { | 371 do_test shell1-3.9.8 { |
403 # too many arguments | 372 # too many arguments |
404 catchcmd "test.db" ".headers OFF BAD" | 373 catchcmd "test.db" ".headers OFF BAD" |
405 } {1 {Error: unknown command or invalid arguments: "headers". Enter ".help" for
help}} | 374 } {1 {Usage: .headers on|off}} |
406 | 375 |
407 # .help Show this message | 376 # .help Show this message |
408 do_test shell1-3.10.1 { | 377 do_test shell1-3.10.1 { |
409 set res [catchcmd "test.db" ".help"] | 378 set res [catchcmd "test.db" ".help"] |
410 # look for a few of the possible help commands | 379 # look for a few of the possible help commands |
411 list [regexp {.help} $res] \ | 380 list [regexp {.help} $res] \ |
412 [regexp {.quit} $res] \ | 381 [regexp {.quit} $res] \ |
413 [regexp {.show} $res] | 382 [regexp {.show} $res] |
414 } {1 1 1} | 383 } {1 1 1} |
415 do_test shell1-3.10.2 { | 384 do_test shell1-3.10.2 { |
416 # we allow .help to take extra args (it is help after all) | 385 # we allow .help to take extra args (it is help after all) |
417 set res [catchcmd "test.db" ".help BAD"] | 386 set res [catchcmd "test.db" ".help BAD"] |
418 # look for a few of the possible help commands | 387 # look for a few of the possible help commands |
419 list [regexp {.help} $res] \ | 388 list [regexp {.help} $res] \ |
420 [regexp {.quit} $res] \ | 389 [regexp {.quit} $res] \ |
421 [regexp {.show} $res] | 390 [regexp {.show} $res] |
422 } {1 1 1} | 391 } {1 1 1} |
423 | 392 |
424 # .import FILE TABLE Import data from FILE into TABLE | 393 # .import FILE TABLE Import data from FILE into TABLE |
425 do_test shell1-3.11.1 { | 394 do_test shell1-3.11.1 { |
426 catchcmd "test.db" ".import" | 395 catchcmd "test.db" ".import" |
427 } {1 {Error: unknown command or invalid arguments: "import". Enter ".help" for
help}} | 396 } {1 {Usage: .import FILE TABLE}} |
428 do_test shell1-3.11.2 { | 397 do_test shell1-3.11.2 { |
429 catchcmd "test.db" ".import FOO" | 398 catchcmd "test.db" ".import FOO" |
430 } {1 {Error: unknown command or invalid arguments: "import". Enter ".help" for
help}} | 399 } {1 {Usage: .import FILE TABLE}} |
431 do_test shell1-3.11.2 { | 400 #do_test shell1-3.11.2 { |
432 catchcmd "test.db" ".import FOO BAR" | 401 # catchcmd "test.db" ".import FOO BAR" |
433 } {1 {Error: no such table: BAR}} | 402 #} {1 {Error: no such table: BAR}} |
434 do_test shell1-3.11.3 { | 403 do_test shell1-3.11.3 { |
435 # too many arguments | 404 # too many arguments |
436 catchcmd "test.db" ".import FOO BAR BAD" | 405 catchcmd "test.db" ".import FOO BAR BAD" |
437 } {1 {Error: unknown command or invalid arguments: "import". Enter ".help" for
help}} | 406 } {1 {Usage: .import FILE TABLE}} |
438 | 407 |
439 # .indices ?TABLE? Show names of all indices | 408 # .indices ?TABLE? Show names of all indices |
440 # If TABLE specified, only show indices for tables | 409 # If TABLE specified, only show indices for tables |
441 # matching LIKE pattern TABLE. | 410 # matching LIKE pattern TABLE. |
442 do_test shell1-3.12.1 { | 411 do_test shell1-3.12.1 { |
443 catchcmd "test.db" ".indices" | 412 catchcmd "test.db" ".indices" |
444 } {0 {}} | 413 } {0 {}} |
445 do_test shell1-3.12.2 { | 414 do_test shell1-3.12.2 { |
446 catchcmd "test.db" ".indices FOO" | 415 catchcmd "test.db" ".indices FOO" |
447 } {0 {}} | 416 } {0 {}} |
448 do_test shell1-3.12.3 { | 417 do_test shell1-3.12.3 { |
449 # too many arguments | 418 # too many arguments |
450 catchcmd "test.db" ".indices FOO BAD" | 419 catchcmd "test.db" ".indices FOO BAD" |
451 } {1 {Error: unknown command or invalid arguments: "indices". Enter ".help" for
help}} | 420 } {1 {Usage: .indices ?LIKE-PATTERN?}} |
452 | 421 |
453 # .mode MODE ?TABLE? Set output mode where MODE is one of: | 422 # .mode MODE ?TABLE? Set output mode where MODE is one of: |
454 # csv Comma-separated values | 423 # csv Comma-separated values |
455 # column Left-aligned columns. (See .width) | 424 # column Left-aligned columns. (See .width) |
456 # html HTML <table> code | 425 # html HTML <table> code |
457 # insert SQL insert statements for TABLE | 426 # insert SQL insert statements for TABLE |
458 # line One value per line | 427 # line One value per line |
459 # list Values delimited by .separator string | 428 # list Values delimited by .separator string |
460 # tabs Tab-separated values | 429 # tabs Tab-separated values |
461 # tcl TCL list elements | 430 # tcl TCL list elements |
462 do_test shell1-3.13.1 { | 431 do_test shell1-3.13.1 { |
463 catchcmd "test.db" ".mode" | 432 catchcmd "test.db" ".mode" |
464 } {1 {Error: unknown command or invalid arguments: "mode". Enter ".help" for he
lp}} | 433 } {1 {Error: mode should be one of: column csv html insert line list tabs tcl}} |
465 do_test shell1-3.13.2 { | 434 do_test shell1-3.13.2 { |
466 catchcmd "test.db" ".mode FOO" | 435 catchcmd "test.db" ".mode FOO" |
467 } {1 {Error: mode should be one of: column csv html insert line list tabs tcl}} | 436 } {1 {Error: mode should be one of: column csv html insert line list tabs tcl}} |
468 do_test shell1-3.13.3 { | 437 do_test shell1-3.13.3 { |
469 catchcmd "test.db" ".mode csv" | 438 catchcmd "test.db" ".mode csv" |
470 } {0 {}} | 439 } {0 {}} |
471 do_test shell1-3.13.4 { | 440 do_test shell1-3.13.4 { |
472 catchcmd "test.db" ".mode column" | 441 catchcmd "test.db" ".mode column" |
473 } {0 {}} | 442 } {0 {}} |
474 do_test shell1-3.13.5 { | 443 do_test shell1-3.13.5 { |
475 catchcmd "test.db" ".mode html" | 444 catchcmd "test.db" ".mode html" |
476 } {0 {}} | 445 } {0 {}} |
477 do_test shell1-3.13.6 { | 446 do_test shell1-3.13.6 { |
478 catchcmd "test.db" ".mode insert" | 447 catchcmd "test.db" ".mode insert" |
479 } {0 {}} | 448 } {0 {}} |
480 do_test shell1-3.13.7 { | 449 do_test shell1-3.13.7 { |
481 catchcmd "test.db" ".mode line" | 450 catchcmd "test.db" ".mode line" |
482 } {0 {}} | 451 } {0 {}} |
483 do_test shell1-3.13.8 { | 452 do_test shell1-3.13.8 { |
484 catchcmd "test.db" ".mode list" | 453 catchcmd "test.db" ".mode list" |
485 } {0 {}} | 454 } {0 {}} |
486 do_test shell1-3.13.9 { | 455 do_test shell1-3.13.9 { |
487 catchcmd "test.db" ".mode tabs" | 456 catchcmd "test.db" ".mode tabs" |
488 } {0 {}} | 457 } {0 {}} |
489 do_test shell1-3.13.10 { | 458 do_test shell1-3.13.10 { |
490 catchcmd "test.db" ".mode tcl" | 459 catchcmd "test.db" ".mode tcl" |
491 } {0 {}} | 460 } {0 {}} |
492 do_test shell1-3.13.11 { | 461 do_test shell1-3.13.11 { |
493 # too many arguments | 462 # extra arguments ignored |
494 catchcmd "test.db" ".mode tcl BAD" | 463 catchcmd "test.db" ".mode tcl BAD" |
495 } {1 {Error: invalid arguments: "BAD". Enter ".help" for help}} | 464 } {0 {}} |
496 | 465 |
497 # don't allow partial mode type matches | 466 # don't allow partial mode type matches |
498 do_test shell1-3.13.12 { | 467 do_test shell1-3.13.12 { |
499 catchcmd "test.db" ".mode l" | 468 catchcmd "test.db" ".mode l" |
500 } {1 {Error: mode should be one of: column csv html insert line list tabs tcl}} | 469 } {1 {Error: mode should be one of: column csv html insert line list tabs tcl}} |
501 do_test shell1-3.13.13 { | 470 do_test shell1-3.13.13 { |
502 catchcmd "test.db" ".mode li" | 471 catchcmd "test.db" ".mode li" |
503 } {1 {Error: mode should be one of: column csv html insert line list tabs tcl}} | 472 } {1 {Error: mode should be one of: column csv html insert line list tabs tcl}} |
504 do_test shell1-3.13.14 { | 473 do_test shell1-3.13.14 { |
505 catchcmd "test.db" ".mode lin" | 474 catchcmd "test.db" ".mode lin" |
506 } {1 {Error: mode should be one of: column csv html insert line list tabs tcl}} | 475 } {0 {}} |
507 | 476 |
508 # .nullvalue STRING Print STRING in place of NULL values | 477 # .nullvalue STRING Print STRING in place of NULL values |
509 do_test shell1-3.14.1 { | 478 do_test shell1-3.14.1 { |
510 catchcmd "test.db" ".nullvalue" | 479 catchcmd "test.db" ".nullvalue" |
511 } {1 {Error: unknown command or invalid arguments: "nullvalue". Enter ".help" f
or help}} | 480 } {1 {Usage: .nullvalue STRING}} |
512 do_test shell1-3.14.2 { | 481 do_test shell1-3.14.2 { |
513 catchcmd "test.db" ".nullvalue FOO" | 482 catchcmd "test.db" ".nullvalue FOO" |
514 } {0 {}} | 483 } {0 {}} |
515 do_test shell1-3.14.3 { | 484 do_test shell1-3.14.3 { |
516 # too many arguments | 485 # too many arguments |
517 catchcmd "test.db" ".nullvalue FOO BAD" | 486 catchcmd "test.db" ".nullvalue FOO BAD" |
518 } {1 {Error: unknown command or invalid arguments: "nullvalue". Enter ".help" f
or help}} | 487 } {1 {Usage: .nullvalue STRING}} |
519 | 488 |
520 # .output FILENAME Send output to FILENAME | 489 # .output FILENAME Send output to FILENAME |
521 do_test shell1-3.15.1 { | 490 do_test shell1-3.15.1 { |
522 catchcmd "test.db" ".output" | 491 catchcmd "test.db" ".output" |
523 } {1 {Error: unknown command or invalid arguments: "output". Enter ".help" for
help}} | 492 } {0 {}} |
524 do_test shell1-3.15.2 { | 493 do_test shell1-3.15.2 { |
525 catchcmd "test.db" ".output FOO" | 494 catchcmd "test.db" ".output FOO" |
526 } {0 {}} | 495 } {0 {}} |
527 do_test shell1-3.15.3 { | 496 do_test shell1-3.15.3 { |
528 # too many arguments | 497 # too many arguments |
529 catchcmd "test.db" ".output FOO BAD" | 498 catchcmd "test.db" ".output FOO BAD" |
530 } {1 {Error: unknown command or invalid arguments: "output". Enter ".help" for
help}} | 499 } {1 {Usage: .output FILE}} |
531 | 500 |
532 # .output stdout Send output to the screen | 501 # .output stdout Send output to the screen |
533 do_test shell1-3.16.1 { | 502 do_test shell1-3.16.1 { |
534 catchcmd "test.db" ".output stdout" | 503 catchcmd "test.db" ".output stdout" |
535 } {0 {}} | 504 } {0 {}} |
536 do_test shell1-3.16.2 { | 505 do_test shell1-3.16.2 { |
537 # too many arguments | 506 # too many arguments |
538 catchcmd "test.db" ".output stdout BAD" | 507 catchcmd "test.db" ".output stdout BAD" |
539 } {1 {Error: unknown command or invalid arguments: "output". Enter ".help" for
help}} | 508 } {1 {Usage: .output FILE}} |
540 | 509 |
541 # .prompt MAIN CONTINUE Replace the standard prompts | 510 # .prompt MAIN CONTINUE Replace the standard prompts |
542 do_test shell1-3.17.1 { | 511 do_test shell1-3.17.1 { |
543 catchcmd "test.db" ".prompt" | 512 catchcmd "test.db" ".prompt" |
544 } {1 {Error: unknown command or invalid arguments: "prompt". Enter ".help" for
help}} | 513 } {0 {}} |
545 do_test shell1-3.17.2 { | 514 do_test shell1-3.17.2 { |
546 catchcmd "test.db" ".prompt FOO" | 515 catchcmd "test.db" ".prompt FOO" |
547 } {0 {}} | 516 } {0 {}} |
548 do_test shell1-3.17.3 { | 517 do_test shell1-3.17.3 { |
549 catchcmd "test.db" ".prompt FOO BAR" | 518 catchcmd "test.db" ".prompt FOO BAR" |
550 } {0 {}} | 519 } {0 {}} |
551 do_test shell1-3.17.4 { | 520 do_test shell1-3.17.4 { |
552 # too many arguments | 521 # too many arguments |
553 catchcmd "test.db" ".prompt FOO BAR BAD" | 522 catchcmd "test.db" ".prompt FOO BAR BAD" |
554 } {1 {Error: unknown command or invalid arguments: "prompt". Enter ".help" for
help}} | 523 } {0 {}} |
555 | 524 |
556 # .quit Exit this program | 525 # .quit Exit this program |
557 do_test shell1-3.18.1 { | 526 do_test shell1-3.18.1 { |
558 catchcmd "test.db" ".quit" | 527 catchcmd "test.db" ".quit" |
559 } {0 {}} | 528 } {0 {}} |
560 do_test shell1-3.18.2 { | 529 do_test shell1-3.18.2 { |
561 # too many arguments | 530 # too many arguments |
562 catchcmd "test.db" ".quit BAD" | 531 catchcmd "test.db" ".quit BAD" |
563 } {1 {Error: unknown command or invalid arguments: "quit". Enter ".help" for he
lp}} | 532 } {0 {}} |
564 | 533 |
565 # .read FILENAME Execute SQL in FILENAME | 534 # .read FILENAME Execute SQL in FILENAME |
566 do_test shell1-3.19.1 { | 535 do_test shell1-3.19.1 { |
567 catchcmd "test.db" ".read" | 536 catchcmd "test.db" ".read" |
568 } {1 {Error: unknown command or invalid arguments: "read". Enter ".help" for he
lp}} | 537 } {1 {Usage: .read FILE}} |
569 do_test shell1-3.19.2 { | 538 do_test shell1-3.19.2 { |
570 file delete -force FOO | 539 forcedelete FOO |
571 catchcmd "test.db" ".read FOO" | 540 catchcmd "test.db" ".read FOO" |
572 } {1 {Error: cannot open "FOO"}} | 541 } {1 {Error: cannot open "FOO"}} |
573 do_test shell1-3.19.3 { | 542 do_test shell1-3.19.3 { |
574 # too many arguments | 543 # too many arguments |
575 catchcmd "test.db" ".read FOO BAD" | 544 catchcmd "test.db" ".read FOO BAD" |
576 } {1 {Error: unknown command or invalid arguments: "read". Enter ".help" for he
lp}} | 545 } {1 {Usage: .read FILE}} |
577 | 546 |
578 # .restore ?DB? FILE Restore content of DB (default "main") from FILE | 547 # .restore ?DB? FILE Restore content of DB (default "main") from FILE |
579 do_test shell1-3.20.1 { | 548 do_test shell1-3.20.1 { |
580 catchcmd "test.db" ".restore" | 549 catchcmd "test.db" ".restore" |
581 } {1 {Error: unknown command or invalid arguments: "restore". Enter ".help" for
help}} | 550 } {1 {Usage: .restore ?DB? FILE}} |
582 do_test shell1-3.20.2 { | 551 do_test shell1-3.20.2 { |
583 catchcmd "test.db" ".restore FOO" | 552 catchcmd "test.db" ".restore FOO" |
584 } {0 {}} | 553 } {0 {}} |
585 do_test shell1-3.20.3 { | 554 do_test shell1-3.20.3 { |
586 catchcmd "test.db" ".restore FOO BAR" | 555 catchcmd "test.db" ".restore FOO BAR" |
587 } {1 {Error: unknown database FOO}} | 556 } {1 {Error: unknown database FOO}} |
588 do_test shell1-3.20.4 { | 557 do_test shell1-3.20.4 { |
589 # too many arguments | 558 # too many arguments |
590 catchcmd "test.db" ".restore FOO BAR BAD" | 559 catchcmd "test.db" ".restore FOO BAR BAD" |
591 } {1 {Error: unknown command or invalid arguments: "restore". Enter ".help" for
help}} | 560 } {1 {Usage: .restore ?DB? FILE}} |
592 | 561 |
593 # .schema ?TABLE? Show the CREATE statements | 562 # .schema ?TABLE? Show the CREATE statements |
594 # If TABLE specified, only show tables matching | 563 # If TABLE specified, only show tables matching |
595 # LIKE pattern TABLE. | 564 # LIKE pattern TABLE. |
596 do_test shell1-3.21.1 { | 565 do_test shell1-3.21.1 { |
597 catchcmd "test.db" ".schema" | 566 catchcmd "test.db" ".schema" |
598 } {0 {}} | 567 } {0 {}} |
599 do_test shell1-3.21.2 { | 568 do_test shell1-3.21.2 { |
600 catchcmd "test.db" ".schema FOO" | 569 catchcmd "test.db" ".schema FOO" |
601 } {0 {}} | 570 } {0 {}} |
602 do_test shell1-3.21.3 { | 571 do_test shell1-3.21.3 { |
603 # too many arguments | 572 # too many arguments |
604 catchcmd "test.db" ".schema FOO BAD" | 573 catchcmd "test.db" ".schema FOO BAD" |
605 } {1 {Error: unknown command or invalid arguments: "schema". Enter ".help" for
help}} | 574 } {1 {Usage: .schema ?LIKE-PATTERN?}} |
| 575 |
| 576 do_test shell1-3.21.4 { |
| 577 catchcmd "test.db" { |
| 578 CREATE TABLE t1(x); |
| 579 CREATE VIEW v2 AS SELECT x+1 AS y FROM t1; |
| 580 CREATE VIEW v1 AS SELECT y+1 FROM v2; |
| 581 } |
| 582 catchcmd "test.db" ".schema" |
| 583 } {0 {CREATE TABLE t1(x); |
| 584 CREATE VIEW v2 AS SELECT x+1 AS y FROM t1; |
| 585 CREATE VIEW v1 AS SELECT y+1 FROM v2;}} |
| 586 db eval {DROP VIEW v1; DROP VIEW v2; DROP TABLE t1;} |
606 | 587 |
607 # .separator STRING Change separator used by output mode and .import | 588 # .separator STRING Change separator used by output mode and .import |
608 do_test shell1-3.22.1 { | 589 do_test shell1-3.22.1 { |
609 catchcmd "test.db" ".separator" | 590 catchcmd "test.db" ".separator" |
610 } {1 {Error: unknown command or invalid arguments: "separator". Enter ".help" f
or help}} | 591 } {1 {Usage: .separator SEPARATOR ?NEWLINE?}} |
611 do_test shell1-3.22.2 { | 592 do_test shell1-3.22.2 { |
612 catchcmd "test.db" ".separator FOO" | 593 catchcmd "test.db" ".separator FOO" |
613 } {0 {}} | 594 } {0 {}} |
614 do_test shell1-3.22.3 { | 595 do_test shell1-3.22.3 { |
| 596 catchcmd "test.db" ".separator ABC XYZ" |
| 597 } {0 {}} |
| 598 do_test shell1-3.22.4 { |
615 # too many arguments | 599 # too many arguments |
616 catchcmd "test.db" ".separator FOO BAD" | 600 catchcmd "test.db" ".separator FOO BAD BAD2" |
617 } {1 {Error: unknown command or invalid arguments: "separator". Enter ".help" f
or help}} | 601 } {1 {Usage: .separator SEPARATOR ?NEWLINE?}} |
618 | 602 |
619 # .show Show the current values for various settings | 603 # .show Show the current values for various settings |
620 do_test shell1-3.23.1 { | 604 do_test shell1-3.23.1 { |
621 set res [catchcmd "test.db" ".show"] | 605 set res [catchcmd "test.db" ".show"] |
622 list [regexp {echo:} $res] \ | 606 list [regexp {echo:} $res] \ |
623 [regexp {explain:} $res] \ | 607 [regexp {explain:} $res] \ |
624 [regexp {headers:} $res] \ | 608 [regexp {headers:} $res] \ |
625 [regexp {mode:} $res] \ | 609 [regexp {mode:} $res] \ |
626 [regexp {nullvalue:} $res] \ | 610 [regexp {nullvalue:} $res] \ |
627 [regexp {output:} $res] \ | 611 [regexp {output:} $res] \ |
628 [regexp {separator:} $res] \ | 612 [regexp {separator:} $res] \ |
629 [regexp {stats:} $res] \ | 613 [regexp {stats:} $res] \ |
630 [regexp {width:} $res] | 614 [regexp {width:} $res] |
631 } {1 1 1 1 1 1 1 1 1} | 615 } {1 1 1 1 1 1 1 1 1} |
632 do_test shell1-3.23.2 { | 616 do_test shell1-3.23.2 { |
633 # too many arguments | 617 # too many arguments |
634 catchcmd "test.db" ".show BAD" | 618 catchcmd "test.db" ".show BAD" |
635 } {1 {Error: unknown command or invalid arguments: "show". Enter ".help" for he
lp}} | 619 } {1 {Usage: .show}} |
636 | 620 |
637 # .stats ON|OFF Turn stats on or off | 621 # .stats ON|OFF Turn stats on or off |
638 do_test shell1-3.23b.1 { | 622 do_test shell1-3.23b.1 { |
639 catchcmd "test.db" ".stats" | 623 catchcmd "test.db" ".stats" |
640 } {1 {Error: unknown command or invalid arguments: "stats". Enter ".help" for h
elp}} | 624 } {1 {Usage: .stats on|off}} |
641 do_test shell1-3.23b.2 { | 625 do_test shell1-3.23b.2 { |
642 catchcmd "test.db" ".stats ON" | 626 catchcmd "test.db" ".stats ON" |
643 } {0 {}} | 627 } {0 {}} |
644 do_test shell1-3.23b.3 { | 628 do_test shell1-3.23b.3 { |
645 catchcmd "test.db" ".stats OFF" | 629 catchcmd "test.db" ".stats OFF" |
646 } {0 {}} | 630 } {0 {}} |
647 do_test shell1-3.23b.4 { | 631 do_test shell1-3.23b.4 { |
648 # too many arguments | 632 # too many arguments |
649 catchcmd "test.db" ".stats OFF BAD" | 633 catchcmd "test.db" ".stats OFF BAD" |
650 } {1 {Error: unknown command or invalid arguments: "stats". Enter ".help" for h
elp}} | 634 } {1 {Usage: .stats on|off}} |
651 | 635 |
652 # .tables ?TABLE? List names of tables | 636 # .tables ?TABLE? List names of tables |
653 # If TABLE specified, only list tables matching | 637 # If TABLE specified, only list tables matching |
654 # LIKE pattern TABLE. | 638 # LIKE pattern TABLE. |
655 do_test shell1-3.24.1 { | 639 do_test shell1-3.24.1 { |
656 catchcmd "test.db" ".tables" | 640 catchcmd "test.db" ".tables" |
657 } {0 {}} | 641 } {0 {}} |
658 do_test shell1-3.24.2 { | 642 do_test shell1-3.24.2 { |
659 catchcmd "test.db" ".tables FOO" | 643 catchcmd "test.db" ".tables FOO" |
660 } {0 {}} | 644 } {0 {}} |
661 do_test shell1-3.24.3 { | 645 do_test shell1-3.24.3 { |
662 # too many arguments | 646 # too many arguments |
663 catchcmd "test.db" ".tables FOO BAD" | 647 catchcmd "test.db" ".tables FOO BAD" |
664 } {1 {Error: unknown command or invalid arguments: "tables". Enter ".help" for
help}} | 648 } {0 {}} |
665 | 649 |
666 # .timeout MS Try opening locked tables for MS milliseconds | 650 # .timeout MS Try opening locked tables for MS milliseconds |
667 do_test shell1-3.25.1 { | 651 do_test shell1-3.25.1 { |
668 catchcmd "test.db" ".timeout" | 652 catchcmd "test.db" ".timeout" |
669 } {1 {Error: unknown command or invalid arguments: "timeout". Enter ".help" for
help}} | 653 } {0 {}} |
670 do_test shell1-3.25.2 { | 654 do_test shell1-3.25.2 { |
671 catchcmd "test.db" ".timeout zzz" | 655 catchcmd "test.db" ".timeout zzz" |
672 # this should be treated the same as a '0' timeout | 656 # this should be treated the same as a '0' timeout |
673 } {0 {}} | 657 } {0 {}} |
674 do_test shell1-3.25.3 { | 658 do_test shell1-3.25.3 { |
675 catchcmd "test.db" ".timeout 1" | 659 catchcmd "test.db" ".timeout 1" |
676 } {0 {}} | 660 } {0 {}} |
677 do_test shell1-3.25.4 { | 661 do_test shell1-3.25.4 { |
678 # too many arguments | 662 # too many arguments |
679 catchcmd "test.db" ".timeout 1 BAD" | 663 catchcmd "test.db" ".timeout 1 BAD" |
680 } {1 {Error: unknown command or invalid arguments: "timeout". Enter ".help" for
help}} | 664 } {0 {}} |
681 | 665 |
682 # .width NUM NUM ... Set column widths for "column" mode | 666 # .width NUM NUM ... Set column widths for "column" mode |
683 do_test shell1-3.26.1 { | 667 do_test shell1-3.26.1 { |
684 catchcmd "test.db" ".width" | 668 catchcmd "test.db" ".width" |
685 } {1 {Error: unknown command or invalid arguments: "width". Enter ".help" for h
elp}} | 669 } {0 {}} |
686 do_test shell1-3.26.2 { | 670 do_test shell1-3.26.2 { |
687 catchcmd "test.db" ".width xxx" | 671 catchcmd "test.db" ".width xxx" |
688 # this should be treated the same as a '0' width for col 1 | 672 # this should be treated the same as a '0' width for col 1 |
689 } {0 {}} | 673 } {0 {}} |
690 do_test shell1-3.26.3 { | 674 do_test shell1-3.26.3 { |
691 catchcmd "test.db" ".width xxx yyy" | 675 catchcmd "test.db" ".width xxx yyy" |
692 # this should be treated the same as a '0' width for col 1 and 2 | 676 # this should be treated the same as a '0' width for col 1 and 2 |
693 } {0 {}} | 677 } {0 {}} |
694 do_test shell1-3.26.4 { | 678 do_test shell1-3.26.4 { |
695 catchcmd "test.db" ".width 1 1" | 679 catchcmd "test.db" ".width 1 1" |
696 # this should be treated the same as a '1' width for col 1 and 2 | 680 # this should be treated the same as a '1' width for col 1 and 2 |
697 } {0 {}} | 681 } {0 {}} |
| 682 do_test shell1-3.26.5 { |
| 683 catchcmd "test.db" ".mode column\n.width 10 -10\nSELECT 'abcdefg', 123456;" |
| 684 # this should be treated the same as a '1' width for col 1 and 2 |
| 685 } {0 {abcdefg 123456}} |
| 686 do_test shell1-3.26.6 { |
| 687 catchcmd "test.db" ".mode column\n.width -10 10\nSELECT 'abcdefg', 123456;" |
| 688 # this should be treated the same as a '1' width for col 1 and 2 |
| 689 } {0 { abcdefg 123456 }} |
| 690 |
698 | 691 |
699 # .timer ON|OFF Turn the CPU timer measurement on or off | 692 # .timer ON|OFF Turn the CPU timer measurement on or off |
700 do_test shell1-3.27.1 { | 693 do_test shell1-3.27.1 { |
701 catchcmd "test.db" ".timer" | 694 catchcmd "test.db" ".timer" |
702 } {1 {Error: unknown command or invalid arguments: "timer". Enter ".help" for h
elp}} | 695 } {1 {Usage: .timer on|off}} |
703 do_test shell1-3.27.2 { | 696 do_test shell1-3.27.2 { |
704 catchcmd "test.db" ".timer ON" | 697 catchcmd "test.db" ".timer ON" |
705 } {0 {}} | 698 } {0 {}} |
706 do_test shell1-3.27.3 { | 699 do_test shell1-3.27.3 { |
707 catchcmd "test.db" ".timer OFF" | 700 catchcmd "test.db" ".timer OFF" |
708 } {0 {}} | 701 } {0 {}} |
709 do_test shell1-3.27.4 { | 702 do_test shell1-3.27.4 { |
710 # too many arguments | 703 # too many arguments |
711 catchcmd "test.db" ".timer OFF BAD" | 704 catchcmd "test.db" ".timer OFF BAD" |
712 } {1 {Error: unknown command or invalid arguments: "timer". Enter ".help" for h
elp}} | 705 } {1 {Usage: .timer on|off}} |
713 | 706 |
714 puts "CLI tests completed successfully" | 707 do_test shell1-3-28.1 { |
| 708 catchcmd test.db \ |
| 709 ".log stdout\nSELECT coalesce(sqlite_log(123,'hello'),'456');" |
| 710 } "0 {(123) hello\n456}" |
| 711 |
| 712 do_test shell1-3-29.1 { |
| 713 catchcmd "test.db" ".print this is a test" |
| 714 } {0 {this is a test}} |
| 715 |
| 716 # dot-command argument quoting |
| 717 do_test shell1-3-30.1 { |
| 718 catchcmd {test.db} {.print "this\"is'a\055test" 'this\"is\\a\055test'} |
| 719 } {0 {this"is'a-test this\"is\\a\055test}} |
| 720 do_test shell1-3-31.1 { |
| 721 catchcmd {test.db} {.print "this\nis\ta\\test" 'this\nis\ta\\test'} |
| 722 } [list 0 "this\nis\ta\\test this\\nis\\ta\\\\test"] |
| 723 |
| 724 |
| 725 # Test the output of the ".dump" command |
| 726 # |
| 727 do_test shell1-4.1 { |
| 728 db close |
| 729 forcedelete test.db |
| 730 sqlite3 db test.db |
| 731 db eval { |
| 732 PRAGMA encoding=UTF16; |
| 733 CREATE TABLE t1(x); |
| 734 INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f'); |
| 735 } |
| 736 catchcmd test.db {.dump} |
| 737 } {0 {PRAGMA foreign_keys=OFF; |
| 738 BEGIN TRANSACTION; |
| 739 CREATE TABLE t1(x); |
| 740 INSERT INTO "t1" VALUES(NULL); |
| 741 INSERT INTO "t1" VALUES(''); |
| 742 INSERT INTO "t1" VALUES(1); |
| 743 INSERT INTO "t1" VALUES(2.25); |
| 744 INSERT INTO "t1" VALUES('hello'); |
| 745 INSERT INTO "t1" VALUES(X'807F'); |
| 746 COMMIT;}} |
| 747 |
| 748 # Test the output of ".mode insert" |
| 749 # |
| 750 do_test shell1-4.2 { |
| 751 catchcmd test.db ".mode insert t1\nselect * from t1;" |
| 752 } {0 {INSERT INTO t1 VALUES(NULL); |
| 753 INSERT INTO t1 VALUES(''); |
| 754 INSERT INTO t1 VALUES(1); |
| 755 INSERT INTO t1 VALUES(2.25); |
| 756 INSERT INTO t1 VALUES('hello'); |
| 757 INSERT INTO t1 VALUES(X'807f');}} |
| 758 |
| 759 # Test the output of ".mode tcl" |
| 760 # |
| 761 do_test shell1-4.3 { |
| 762 db close |
| 763 forcedelete test.db |
| 764 sqlite3 db test.db |
| 765 db eval { |
| 766 PRAGMA encoding=UTF8; |
| 767 CREATE TABLE t1(x); |
| 768 INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f'); |
| 769 } |
| 770 catchcmd test.db ".mode tcl\nselect * from t1;" |
| 771 } {0 {"" |
| 772 "" |
| 773 "1" |
| 774 "2.25" |
| 775 "hello" |
| 776 "\200\177"}} |
| 777 |
| 778 # Test the output of ".mode tcl" with multiple columns |
| 779 # |
| 780 do_test shell1-4.4 { |
| 781 db eval { |
| 782 CREATE TABLE t2(x,y); |
| 783 INSERT INTO t2 VALUES(null, ''), (1, 2.25), ('hello', x'807f'); |
| 784 } |
| 785 catchcmd test.db ".mode tcl\nselect * from t2;" |
| 786 } {0 {"" "" |
| 787 "1" "2.25" |
| 788 "hello" "\200\177"}} |
| 789 |
| 790 # Test the output of ".mode tcl" with ".nullvalue" |
| 791 # |
| 792 do_test shell1-4.5 { |
| 793 catchcmd test.db ".mode tcl\n.nullvalue NULL\nselect * from t2;" |
| 794 } {0 {"NULL" "" |
| 795 "1" "2.25" |
| 796 "hello" "\200\177"}} |
| 797 |
| 798 # Test the output of ".mode tcl" with Tcl reserved characters |
| 799 # |
| 800 do_test shell1-4.6 { |
| 801 db eval { |
| 802 CREATE TABLE tcl1(x); |
| 803 INSERT INTO tcl1 VALUES('"'), ('['), (']'), ('\{'), ('\}'), (';'), ('$'); |
| 804 } |
| 805 foreach {x y} [catchcmd test.db ".mode tcl\nselect * from tcl1;"] break |
| 806 list $x $y [llength $y] |
| 807 } {0 {"\"" |
| 808 "[" |
| 809 "]" |
| 810 "\\{" |
| 811 "\\}" |
| 812 ";" |
| 813 "$"} 7} |
| 814 |
| 815 finish_test |
OLD | NEW |