Update tests in returning1.test to account for [c7896e88].
[sqlite.git] / test / shell1.test
blob206fb0a4fd8bbe0a1a4a8718e188d81e124a119a
1 # 2009 Nov 11
3 # The author disclaims copyright to this source code.  In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
12 # The focus of this file is testing the CLI shell tool.
14 # TESTRUNNER: shell
17 # Test plan:
19 #   shell1-1.*: Basic command line option handling.
20 #   shell1-2.*: Basic "dot" command token parsing.
21 #   shell1-3.*: Basic test that "dot" command can be called.
22 #   shell1-{4-8}.*: Test various "dot" commands's functionality.
23 #   shell1-9.*: Basic test that "dot" commands and SQL intermix ok.
25 set testdir [file dirname $argv0]
26 source $testdir/tester.tcl
27 set CLI [test_cli_invocation]
28 db close
29 forcedelete test.db test.db-journal test.db-wal
30 sqlite3 db test.db
32 #----------------------------------------------------------------------------
33 # Test cases shell1-1.*: Basic command line option handling.
36 # invalid option
37 do_test shell1-1.1.1 {
38   set res [catchcmd "-bad test.db" ""]
39   set rc [lindex $res 0]
40   list $rc \
41        [regexp {Error: unknown option: -bad} $res]
42 } {1 1}
43 do_test shell1-1.1.1b {
44   set res [catchcmd "test.db -bad" ""]
45   set rc [lindex $res 0]
46   list $rc \
47        [regexp {Error: unknown option: -bad} $res]
48 } {1 1}
49 # error on extra options
50 do_test shell1-1.1.2 {
51   catchcmd "test.db \"select+3\" \"select+4\"" ""
52 } {0 {3
53 4}}
54 # error on extra options
55 do_test shell1-1.1.3 {
56   catchcmd "test.db FOO test.db BAD" ".quit"
57 } {/1 .Error: in prepare, near "FOO": syntax error*/}
59 # -help
60 do_test shell1-1.2.1 {
61   set res [catchcmd "-help test.db" ""]
62   set rc [lindex $res 0]
63   list $rc \
64        [regexp {Usage} $res] \
65        [regexp {\-init} $res] \
66        [regexp {\-version} $res]
67 } {1 1 1 1}
69 # -init filename       read/process named file
70 forcedelete FOO
71 set out [open FOO w]
72 puts $out ""
73 close $out
74 do_test shell1-1.3.1 {
75   catchcmd "-init FOO test.db" ""
76 } {0 {}}
77 do_test shell1-1.3.2 {
78   catchcmd "-init FOO test.db .quit BAD" ""
79 } {0 {}}
80 do_test shell1-1.3.3 {
81   catchcmd "-init FOO test.db BAD .quit" ""
82 } {/1 .Error: in prepare, near "BAD": syntax error*/}
84 # -echo                print commands before execution
85 do_test shell1-1.4.1 {
86   catchcmd "-echo test.db" ""
87 } {0 {}}
89 # -[no]header          turn headers on or off
90 do_test shell1-1.5.1 {
91   catchcmd "-header test.db" ""
92 } {0 {}}
93 do_test shell1-1.5.2 {
94   catchcmd "-noheader test.db" ""
95 } {0 {}}
97 # -bail                stop after hitting an error
98 do_test shell1-1.6.1 {
99   catchcmd "-bail test.db" ""
100 } {0 {}}
102 # -interactive         force interactive I/O
103 do_test shell1-1.7.1 {
104   set res [catchcmd "-interactive test.db" ".quit"]
105   set rc [lindex $res 0]
106   list $rc \
107        [regexp {SQLite version} $res] \
108        [regexp {Enter ".help" for usage hints} $res]
109 } {0 1 1}
111 # -batch               force batch I/O
112 do_test shell1-1.8.1 {
113   catchcmd "-batch test.db" ""
114 } {0 {}}
116 # -column              set output mode to 'column'
117 do_test shell1-1.9.1 {
118   catchcmd "-column test.db" ""
119 } {0 {}}
121 # -csv                 set output mode to 'csv'
122 do_test shell1-1.10.1 {
123   catchcmd "-csv test.db" ""
124 } {0 {}}
126 # -html                set output mode to HTML
127 do_test shell1-1.11.1 {
128   catchcmd "-html test.db" ""
129 } {0 {}}
131 # -line                set output mode to 'line'
132 do_test shell1-1.12.1 {
133   catchcmd "-line test.db" ""
134 } {0 {}}
136 # -list                set output mode to 'list'
137 do_test shell1-1.13.1 {
138   catchcmd "-list test.db" ""
139 } {0 {}}
141 # -separator 'x'       set output field separator (|)
142 do_test shell1-1.14.1 {
143   catchcmd "-separator 'x' test.db" ""
144 } {0 {}}
145 do_test shell1-1.14.2 {
146   catchcmd "-separator x test.db" ""
147 } {0 {}}
148 do_test shell1-1.14.3 {
149   set res [catchcmd "-separator" ""]
150   set rc [lindex $res 0]
151   list $rc \
152        [regexp {Error: missing argument to -separator} $res]
153 } {1 1}
155 # -stats               print memory stats before each finalize
156 do_test shell1-1.14b.1 {
157   catchcmd "-stats test.db" ""
158 } {0 {}}
160 # -nullvalue 'text'    set text string for NULL values
161 do_test shell1-1.15.1 {
162   catchcmd "-nullvalue 'x' test.db" ""
163 } {0 {}}
164 do_test shell1-1.15.2 {
165   catchcmd "-nullvalue x test.db" ""
166 } {0 {}}
167 do_test shell1-1.15.3 {
168   set res [catchcmd "-nullvalue" ""]
169   set rc [lindex $res 0]
170   list $rc \
171        [regexp {Error: missing argument to -nullvalue} $res]
172 } {1 1}
174 # -version             show SQLite version
175 do_test shell1-1.16.1 {
176   set x [catchcmd "-version test.db" ""]
177 } {/3.[0-9.]+ 20\d\d-[01]\d-\d\d \d\d:\d\d:\d\d [0-9a-f]+/}
179 # Handle no-more-options option
180 forcedelete ./--db
181 do_test shell1-1.17.1 {
182   catchcmd {-- --db "CREATE TABLE T(c1);"}
183 } {0 {}}
184 do_test shell1-1.17.2 {
185   catchcmd {-- --db "SELECT name from sqlite_schema;"}
186 } {0 T}
187 forcedelete ./--db
189 #----------------------------------------------------------------------------
190 # Test cases shell1-2.*: Basic "dot" command token parsing.
193 # check first token handling
194 do_test shell1-2.1.1 {
195   catchcmd "test.db" ".foo"
196 } {1 {Error: unknown command or invalid arguments:  "foo". Enter ".help" for help}}
197 do_test shell1-2.1.2 {
198   catchcmd "test.db" ".\"foo OFF\""
199 } {1 {Error: unknown command or invalid arguments:  "foo OFF". Enter ".help" for help}}
200 do_test shell1-2.1.3 {
201   catchcmd "test.db" ".\'foo OFF\'"
202 } {1 {Error: unknown command or invalid arguments:  "foo OFF". Enter ".help" for help}}
204 # unbalanced quotes
205 do_test shell1-2.2.1 {
206   catchcmd "test.db" ".\"foo OFF"
207 } {1 {Error: unknown command or invalid arguments:  "foo OFF". Enter ".help" for help}}
208 do_test shell1-2.2.2 {
209   catchcmd "test.db" ".\'foo OFF"
210 } {1 {Error: unknown command or invalid arguments:  "foo OFF". Enter ".help" for help}}
211 do_test shell1-2.2.3 {
212   catchcmd "test.db" ".explain \"OFF"
213 } {0 {}}
214 do_test shell1-2.2.4 {
215   catchcmd "test.db" ".explain \'OFF"
216 } {0 {}}
217 do_test shell1-2.2.5 {
218   catchcmd "test.db" ".mode \"insert FOO"
219 } {1 {Error: mode should be one of: ascii box column csv html insert json line list markdown qbox quote table tabs tcl}}
220 do_test shell1-2.2.6 {
221   catchcmd "test.db" ".mode \'insert FOO"
222 } {1 {Error: mode should be one of: ascii box column csv html insert json line list markdown qbox quote table tabs tcl}}
224 # check multiple tokens, and quoted tokens
225 do_test shell1-2.3.1 {
226   catchcmd "test.db" ".explain 1"
227 } {0 {}}
228 do_test shell1-2.3.2 {
229   catchcmd "test.db" ".explain on"
230 } {0 {}}
231 do_test shell1-2.3.3 {
232   catchcmd "test.db" ".explain \"1 2 3\""
233 } {1 {ERROR: Not a boolean value: "1 2 3". Assuming "no".}}
234 do_test shell1-2.3.4 {
235   catchcmd "test.db" ".explain \"OFF\""
236 } {0 {}}
237 do_test shell1-2.3.5 {
238   catchcmd "test.db" ".\'explain\' \'OFF\'"
239 } {0 {}}
240 do_test shell1-2.3.6 {
241   catchcmd "test.db" ".explain \'OFF\'"
242 } {0 {}}
243 do_test shell1-2.3.7 {
244   catchcmd "test.db" ".\'explain\' \'OFF\'"
245 } {0 {}}
247 # check quoted args are unquoted
248 do_test shell1-2.4.1 {
249   catchcmd "test.db" ".mode FOO"
250 } {1 {Error: mode should be one of: ascii box column csv html insert json line list markdown qbox quote table tabs tcl}}
251 do_test shell1-2.4.2 {
252   catchcmd "test.db" ".mode csv"
253 } {0 {}}
254 do_test shell1-2.4.2 {
255   catchcmd "test.db" ".mode \"csv\""
256 } {0 {}}
258 # check that certain quoted arg escapes work
259 do_test shell1-2.5.1 {
260   catchcmd ":memory:" ".print \"\\060\\077 \\x3f\\x30 \\a\\t\""
261 } [list 0 "0? ?0 \a\t"]
264 #----------------------------------------------------------------------------
265 # Test cases shell1-3.*: Basic test that "dot" command can be called.
268 # .backup ?DB? FILE      Backup DB (default "main") to FILE
269 do_test shell1-3.1.1 {
270   catchcmd "test.db" ".backup"
271 } {1 {missing FILENAME argument on .backup}}
272 forcedelete FOO
273 do_test shell1-3.1.2 {
274   catchcmd "test.db" ".backup FOO"
275 } {0 {}}
276 do_test shell1-3.1.3 {
277   catchcmd "test.db" ".backup FOO BAR"
278 } {1 {Error: unknown database FOO}}
279 do_test shell1-3.1.4 {
280   # too many arguments
281   catchcmd "test.db" ".backup FOO BAR BAD"
282 } {1 {Usage: .backup ?DB? ?OPTIONS? FILENAME}}
284 # .bail ON|OFF           Stop after hitting an error.  Default OFF
285 do_test shell1-3.2.1 {
286   catchcmd "test.db" ".bail"
287 } {1 {Usage: .bail on|off}}
288 do_test shell1-3.2.2 {
289   catchcmd "test.db" ".bail ON"
290 } {0 {}}
291 do_test shell1-3.2.3 {
292   catchcmd "test.db" ".bail OFF"
293 } {0 {}}
294 do_test shell1-3.2.4 {
295   # too many arguments
296   catchcmd "test.db" ".bail OFF BAD"
297 } {1 {Usage: .bail on|off}}
299 ifcapable vtab {
300 # .databases             List names and files of attached databases
301 do_test shell1-3.3.1 {
302   catchcmd "-csv test.db" ".databases"
303 } "/0.+main.+[string map {/ ".{1,2}"} [string range [get_pwd] 0 10]].*/"
304 do_test shell1-3.3.2 {
305   # extra arguments ignored
306   catchcmd "test.db" ".databases BAD"
307 } "/0.+main.+[string map {/ ".{1,2}"} [string range [get_pwd] 0 10]].*/"
310 # .dump ?TABLE? ...      Dump the database in an SQL text format
311 #                          If TABLE specified, only dump tables matching
312 #                          LIKE pattern TABLE.
313 do_test shell1-3.4.1 {
314   set res [catchcmd "test.db" ".dump"]
315   list [regexp {BEGIN TRANSACTION;} $res] \
316        [regexp {COMMIT;} $res]
317 } {1 1}
318 do_test shell1-3.4.2 {
319   set res [catchcmd "test.db" ".dump FOO"]
320   list [regexp {BEGIN TRANSACTION;} $res] \
321        [regexp {COMMIT;} $res]
322 } {1 1}
323 # The .dump command now accepts multiple arguments
324 #do_test shell1-3.4.3 {
325 #  # too many arguments
326 #  catchcmd "test.db" ".dump FOO BAD"
327 #} {1 {Usage: .dump ?--preserve-rowids? ?--newlines? ?LIKE-PATTERN?}}
329 # .echo ON|OFF           Turn command echo on or off
330 do_test shell1-3.5.1 {
331   catchcmd "test.db" ".echo"
332 } {1 {Usage: .echo on|off}}
333 do_test shell1-3.5.2 {
334   catchcmd "test.db" ".echo ON"
335 } {0 {}}
336 do_test shell1-3.5.3 {
337   catchcmd "test.db" ".echo OFF"
338 } {0 {}}
339 do_test shell1-3.5.4 {
340   # too many arguments
341   catchcmd "test.db" ".echo OFF BAD"
342 } {1 {Usage: .echo on|off}}
344 # .exit                  Exit this program
345 do_test shell1-3.6.1 {
346   catchcmd "test.db" ".exit"
347 } {0 {}}
349 # .explain ON|OFF        Turn output mode suitable for EXPLAIN on or off.
350 do_test shell1-3.7.1 {
351   catchcmd "test.db" ".explain"
352   # explain is the exception to the booleans.  without an option, it turns it on.
353 } {0 {}}
354 do_test shell1-3.7.2 {
355   catchcmd "test.db" ".explain ON"
356 } {0 {}}
357 do_test shell1-3.7.3 {
358   catchcmd "test.db" ".explain OFF"
359 } {0 {}}
360 do_test shell1-3.7.4 {
361   # extra arguments ignored
362   catchcmd "test.db" ".explain OFF BAD"
363 } {0 {}}
366 # .header(s) ON|OFF      Turn display of headers on or off
367 do_test shell1-3.9.1 {
368   catchcmd "test.db" ".header"
369 } {1 {Usage: .headers on|off}}
370 do_test shell1-3.9.2 {
371   catchcmd "test.db" ".header ON"
372 } {0 {}}
373 do_test shell1-3.9.3 {
374   catchcmd "test.db" ".header OFF"
375 } {0 {}}
376 do_test shell1-3.9.4 {
377   # too many arguments
378   catchcmd "test.db" ".header OFF BAD"
379 } {1 {Usage: .headers on|off}}
381 do_test shell1-3.9.5 {
382   catchcmd "test.db" ".headers"
383 } {1 {Usage: .headers on|off}}
384 do_test shell1-3.9.6 {
385   catchcmd "test.db" ".headers ON"
386 } {0 {}}
387 do_test shell1-3.9.7 {
388   catchcmd "test.db" ".headers OFF"
389 } {0 {}}
390 do_test shell1-3.9.8 {
391   # too many arguments
392   catchcmd "test.db" ".headers OFF BAD"
393 } {1 {Usage: .headers on|off}}
395 # .help                  Show this message
396 do_test shell1-3.10.1 {
397   set res [catchcmd "test.db" ".help"]
398   # look for a few of the possible help commands
399   list [regexp {.help} $res] \
400        [regexp {.quit} $res] \
401        [regexp {.show} $res]
402 } {1 1 1}
403 do_test shell1-3.10.2 {
404   # we allow .help to take extra args (it is help after all)
405   set res [catchcmd "test.db" ".help *"]
406   # look for a few of the possible help commands
407   list [regexp {.help} $res] \
408        [regexp {.quit} $res] \
409        [regexp {.show} $res]
410 } {1 1 1}
412 # .import FILE TABLE     Import data from FILE into TABLE
413 do_test shell1-3.11.1 {
414   catchcmd "test.db" ".import"
415 } {/1 .ERROR: missing FILE argument.*/}
416 do_test shell1-3.11.2 {
417   catchcmd "test.db" ".import FOO"
418 } {/1 .ERROR: missing TABLE argument.*/}
419 do_test shell1-3.11.3 {
420   # too many arguments
421   catchcmd "test.db" ".import FOO BAR BAD"
422 } {/1 .ERROR: extra argument: "BAD".*./}
424 # .indexes ?TABLE?       Show names of all indexes
425 #                          If TABLE specified, only show indexes for tables
426 #                          matching LIKE pattern TABLE.
427 do_test shell1-3.12.1 {
428   catchcmd "test.db" ".indexes"
429 } {0 {}}
430 do_test shell1-3.12.2 {
431   catchcmd "test.db" ".indexes FOO"
432 } {0 {}}
433 do_test shell1-3.12.2-legacy {
434   catchcmd "test.db" ".indices FOO"
435 } {0 {}}
436 do_test shell1-3.12.3 {
437   # too many arguments
438   catchcmd "test.db" ".indexes FOO BAD"
439 } {1 {Usage: .indexes ?LIKE-PATTERN?}}
441 # .mode MODE ?TABLE?     Set output mode where MODE is one of:
442 #                          ascii    Columns/rows delimited by 0x1F and 0x1E
443 #                          csv      Comma-separated values
444 #                          column   Left-aligned columns.  (See .width)
445 #                          html     HTML <table> code
446 #                          insert   SQL insert statements for TABLE
447 #                          line     One value per line
448 #                          list     Values delimited by .separator strings
449 #                          tabs     Tab-separated values
450 #                          tcl      TCL list elements
451 do_test shell1-3.13.1 {
452   catchcmd "test.db" ".mode"
453 } {0 {current output mode: list}}
454 do_test shell1-3.13.2 {
455   catchcmd "test.db" ".mode FOO"
456 } {1 {Error: mode should be one of: ascii box column csv html insert json line list markdown qbox quote table tabs tcl}}
457 do_test shell1-3.13.3 {
458   catchcmd "test.db" ".mode csv"
459 } {0 {}}
460 do_test shell1-3.13.4 {
461   catchcmd "test.db" ".mode column"
462 } {0 {}}
463 do_test shell1-3.13.5 {
464   catchcmd "test.db" ".mode html"
465 } {0 {}}
466 do_test shell1-3.13.6 {
467   catchcmd "test.db" ".mode insert"
468 } {0 {}}
469 do_test shell1-3.13.7 {
470   catchcmd "test.db" ".mode line"
471 } {0 {}}
472 do_test shell1-3.13.8 {
473   catchcmd "test.db" ".mode list"
474 } {0 {}}
475 do_test shell1-3.13.9 {
476   catchcmd "test.db" ".mode tabs"
477 } {0 {}}
478 do_test shell1-3.13.10 {
479   catchcmd "test.db" ".mode tcl"
480 } {0 {}}
481 do_test shell1-3.13.11 {
482   # extra arguments ignored
483   catchcmd "test.db" ".mode tcl BAD"
484 } {0 {}}
486 # .nullvalue STRING      Print STRING in place of NULL values
487 do_test shell1-3.14.1 {
488   catchcmd "test.db" ".nullvalue"
489 } {1 {Usage: .nullvalue STRING}}
490 do_test shell1-3.14.2 {
491   catchcmd "test.db" ".nullvalue FOO"
492 } {0 {}}
493 do_test shell1-3.14.3 {
494   # too many arguments
495   catchcmd "test.db" ".nullvalue FOO BAD"
496 } {1 {Usage: .nullvalue STRING}}
498 # .output FILENAME       Send output to FILENAME
499 do_test shell1-3.15.1 {
500   catchcmd "test.db" ".output
501 .print x"
502 } {0 x}
503 do_test shell1-3.15.2 {
504   catchcmd "test.db" ".output FOO
505 .print x
506 .output
507 SELECT readfile('FOO');"
508 } {0 {x
510 do_test shell1-3.15.3 {
511   # too many arguments
512   catchcmd "test.db" ".output FOO BAD"
513 } {1 {ERROR: extra parameter: "BAD".  Usage:
514 .output ?FILE?           Send output to FILE or stdout if FILE is omitted
515    If FILE begins with '|' then open it as a pipe.
516    Options:
517      --bom                 Prefix output with a UTF8 byte-order mark
518      -e                    Send output to the system text editor
519      -x                    Send output as CSV to a spreadsheet
520 child process exited abnormally}}
522 # .output stdout         Send output to the screen
523 do_test shell1-3.16.1 {
524   catchcmd "test.db" ".output stdout"
525 } {0 {}}
526 do_test shell1-3.16.2 {
527   # too many arguments
528   catchcmd "test.db" ".output stdout BAD"
529 } {1 {ERROR: extra parameter: "BAD".  Usage:
530 .output ?FILE?           Send output to FILE or stdout if FILE is omitted
531    If FILE begins with '|' then open it as a pipe.
532    Options:
533      --bom                 Prefix output with a UTF8 byte-order mark
534      -e                    Send output to the system text editor
535      -x                    Send output as CSV to a spreadsheet
536 child process exited abnormally}}
538 # .prompt MAIN CONTINUE  Replace the standard prompts
539 do_test shell1-3.17.1 {
540   catchcmd "test.db" ".prompt"
541 } {0 {}}
542 do_test shell1-3.17.2 {
543   catchcmd "test.db" ".prompt FOO"
544 } {0 {}}
545 do_test shell1-3.17.3 {
546   catchcmd "test.db" ".prompt FOO BAR"
547 } {0 {}}
548 do_test shell1-3.17.4 {
549   # too many arguments
550   catchcmd "test.db" ".prompt FOO BAR BAD"
551 } {0 {}}
553 # .quit                  Exit this program
554 do_test shell1-3.18.1 {
555   catchcmd "test.db" ".quit"
556 } {0 {}}
557 do_test shell1-3.18.2 {
558   # too many arguments
559   catchcmd "test.db" ".quit BAD"
560 } {0 {}}
562 # .read FILENAME         Execute SQL in FILENAME
563 do_test shell1-3.19.1 {
564   catchcmd "test.db" ".read"
565 } {1 {Usage: .read FILE}}
566 do_test shell1-3.19.2 {
567   forcedelete FOO
568   catchcmd "test.db" ".read FOO"
569 } {1 {Error: cannot open "FOO"}}
570 do_test shell1-3.19.3 {
571   # too many arguments
572   catchcmd "test.db" ".read FOO BAD"
573 } {1 {Usage: .read FILE}}
575 # .restore ?DB? FILE     Restore content of DB (default "main") from FILE
576 do_test shell1-3.20.1 {
577   catchcmd "test.db" ".restore"
578 } {1 {Usage: .restore ?DB? FILE}}
579 do_test shell1-3.20.2 {
580   catchcmd "test.db" ".restore FOO"
581 } {0 {}}
582 do_test shell1-3.20.3 {
583   catchcmd "test.db" ".restore FOO BAR"
584 } {1 {Error: unknown database FOO}}
585 do_test shell1-3.20.4 {
586   # too many arguments
587   catchcmd "test.db" ".restore FOO BAR BAD"
588 } {1 {Usage: .restore ?DB? FILE}}
590 ifcapable vtab {
591 # .schema ?TABLE?        Show the CREATE statements
592 #                          If TABLE specified, only show tables matching
593 #                          LIKE pattern TABLE.
594 do_test shell1-3.21.1 {
595   catchcmd "test.db" ".schema"
596 } {0 {}}
597 do_test shell1-3.21.2 {
598   catchcmd "test.db" ".schema FOO"
599 } {0 {}}
600 do_test shell1-3.21.3 {
601   # too many arguments
602   catchcmd "test.db" ".schema FOO BAD"
603 } {1 {Usage: .schema ?--indent? ?--nosys? ?LIKE-PATTERN?}}
605 do_test shell1-3.21.4 {
606   catchcmd "test.db" {
607      CREATE TABLE t1(x);
608      CREATE VIEW v2 AS SELECT x+1 AS y FROM t1;
609      CREATE VIEW v1 AS SELECT y+1 FROM v2;
610   }
611   catchcmd "test.db" ".schema"
612 } {0 {CREATE TABLE t1(x);
613 CREATE VIEW v2 AS SELECT x+1 AS y FROM t1
614 /* v2(y) */;
615 CREATE VIEW v1 AS SELECT y+1 FROM v2
616 /* v1("y+1") */;}}
618   catch {db eval {DROP VIEW v1; DROP VIEW v2; DROP TABLE t1;}}
621 # .separator STRING  Change column separator used by output and .import
622 do_test shell1-3.22.1 {
623   catchcmd "test.db" ".separator"
624 } {1 {Usage: .separator COL ?ROW?}}
625 do_test shell1-3.22.2 {
626   catchcmd "test.db" ".separator FOO"
627 } {0 {}}
628 do_test shell1-3.22.3 {
629   catchcmd "test.db" ".separator ABC XYZ"
630 } {0 {}}
631 do_test shell1-3.22.4 {
632   # too many arguments
633   catchcmd "test.db" ".separator FOO BAD BAD2"
634 } {1 {Usage: .separator COL ?ROW?}}
636 # .show                  Show the current values for various settings
637 do_test shell1-3.23.1 {
638   set res [catchcmd "test.db" ".show"]
639   list [regexp {echo:} $res] \
640        [regexp {explain:} $res] \
641        [regexp {headers:} $res] \
642        [regexp {mode:} $res] \
643        [regexp {nullvalue:} $res] \
644        [regexp {output:} $res] \
645        [regexp {colseparator:} $res] \
646        [regexp {rowseparator:} $res] \
647        [regexp {stats:} $res] \
648        [regexp {width:} $res]
649 } {1 1 1 1 1 1 1 1 1 1}
650 do_test shell1-3.23.2 {
651   # too many arguments
652   catchcmd "test.db" ".show BAD"
653 } {1 {Usage: .show}}
655 # .stats ON|OFF          Turn stats on or off
656 #do_test shell1-3.23b.1 {
657 #  catchcmd "test.db" ".stats"
658 #} {1 {Usage: .stats on|off|stmt|vmstep}}
659 do_test shell1-3.23b.2 {
660   catchcmd "test.db" ".stats ON"
661 } {0 {}}
662 do_test shell1-3.23b.3 {
663   catchcmd "test.db" ".stats OFF"
664 } {0 {}}
665 do_test shell1-3.23b.4 {
666   # too many arguments
667   catchcmd "test.db" ".stats OFF BAD"
668 } {1 {Usage: .stats ?on|off|stmt|vmstep?}}
670 # Ticket 7be932dfa60a8a6b3b26bcf7623ec46e0a403ddb 2018-06-07
671 # Adverse interaction between .stats and .eqp
673 do_test shell1-3.23b.5 {
674   catchcmd "test.db" [string map {"\n    " "\n"} {
675     CREATE TEMP TABLE t1(x);
676     INSERT INTO t1 VALUES(1),(2);
677     .stats on
678     .eqp full
679     SELECT * FROM t1;
680   }]
681 } {/1\n2\n/}
683 # .tables ?TABLE?        List names of tables
684 #                          If TABLE specified, only list tables matching
685 #                          LIKE pattern TABLE.
686 do_test shell1-3.24.1 {
687   catchcmd "test.db" ".tables"
688 } {0 {}}
689 do_test shell1-3.24.2 {
690   catchcmd "test.db" ".tables FOO"
691 } {0 {}}
692 do_test shell1-3.24.3 {
693   # too many arguments
694   catchcmd "test.db" ".tables FOO BAD"
695 } {0 {}}
697 # .timeout MS            Try opening locked tables for MS milliseconds
698 do_test shell1-3.25.1 {
699   catchcmd "test.db" ".timeout"
700 } {0 {}}
701 do_test shell1-3.25.2 {
702   catchcmd "test.db" ".timeout zzz"
703   # this should be treated the same as a '0' timeout
704 } {0 {}}
705 do_test shell1-3.25.3 {
706   catchcmd "test.db" ".timeout 1"
707 } {0 {}}
708 do_test shell1-3.25.4 {
709   # too many arguments
710   catchcmd "test.db" ".timeout 1 BAD"
711 } {0 {}}
713 # .width NUM NUM ...     Set column widths for "column" mode
714 do_test shell1-3.26.1 {
715   catchcmd "test.db" ".width"
716 } {0 {}}
717 do_test shell1-3.26.2 {
718   catchcmd "test.db" ".width xxx"
719   # this should be treated the same as a '0' width for col 1
720 } {0 {}}
721 do_test shell1-3.26.3 {
722   catchcmd "test.db" ".width xxx yyy"
723   # this should be treated the same as a '0' width for col 1 and 2
724 } {0 {}}
725 do_test shell1-3.26.4 {
726   catchcmd "test.db" ".width 1 1"
727   # this should be treated the same as a '1' width for col 1 and 2
728 } {0 {}}
729 do_test shell1-3.26.5 {
730   catchcmd "test.db" ".mode column\n.header off\n.width 10 -10\nSELECT 'abcdefg', 123456;"
731   # this should be treated the same as a '1' width for col 1 and 2
732 } {0 {abcdefg         123456}}
733 do_test shell1-3.26.6 {
734   catchcmd "test.db" ".mode column\n.header off\n.width -10 10\nSELECT 'abcdefg', 123456;"
735   # this should be treated the same as a '1' width for col 1 and 2
736 } {0 {   abcdefg  123456    }}
739 # .timer ON|OFF          Turn the CPU timer measurement on or off
740 do_test shell1-3.27.1 {
741   catchcmd "test.db" ".timer"
742 } {1 {Usage: .timer on|off}}
743 do_test shell1-3.27.2 {
744   catchcmd "test.db" ".timer ON"
745 } {0 {}}
746 do_test shell1-3.27.3 {
747   catchcmd "test.db" ".timer OFF"
748 } {0 {}}
749 do_test shell1-3.27.4 {
750   # too many arguments
751   catchcmd "test.db" ".timer OFF BAD"
752 } {1 {Usage: .timer on|off}}
754 do_test shell1-3-28.1 {
755   catchcmd test.db \
756      ".log stdout\nSELECT coalesce(sqlite_log(123,'hello'),'456');"
757 } "0 {(123) hello\n456}"
759 do_test shell1-3-29.1 {
760   catchcmd "test.db" ".print this is a test"
761 } {0 {this is a test}}
763 # dot-command argument quoting
764 do_test shell1-3-30.1 {
765   catchcmd {test.db} {.print "this\"is'a\055test" 'this\"is\\a\055test'}
766 } {0 {this"is'a-test this\"is\\a\055test}}
767 do_test shell1-3-31.1 {
768   catchcmd {test.db} {.print "this\nis\ta\\test" 'this\nis\ta\\test'}
769 } [list 0 "this\nis\ta\\test this\\nis\\ta\\\\test"]
772 # Test the output of the ".dump" command
774 do_test shell1-4.1 {
775   db close
776   forcedelete test.db
777   sqlite3 db test.db
778   db eval {
779     PRAGMA encoding=UTF16;
780     CREATE TABLE t1(x);
781     INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f');
782     CREATE TABLE t3(x,y);
783     INSERT INTO t3 VALUES(1,null), (2,''), (3,1),
784                          (4,2.25), (5,'hello'), (6,x'807f');
785   }
786   catchcmd test.db {.dump}
787 } {0 {PRAGMA foreign_keys=OFF;
788 BEGIN TRANSACTION;
789 CREATE TABLE t1(x);
790 INSERT INTO t1 VALUES(NULL);
791 INSERT INTO t1 VALUES('');
792 INSERT INTO t1 VALUES(1);
793 INSERT INTO t1 VALUES(2.25);
794 INSERT INTO t1 VALUES('hello');
795 INSERT INTO t1 VALUES(X'807f');
796 CREATE TABLE t3(x,y);
797 INSERT INTO t3 VALUES(1,NULL);
798 INSERT INTO t3 VALUES(2,'');
799 INSERT INTO t3 VALUES(3,1);
800 INSERT INTO t3 VALUES(4,2.25);
801 INSERT INTO t3 VALUES(5,'hello');
802 INSERT INTO t3 VALUES(6,X'807f');
803 COMMIT;}}
806 ifcapable vtab {
808 # The --preserve-rowids option to .dump
810 do_test shell1-4.1.1 {
811   catchcmd test.db {.dump --preserve-rowids}
812 } {0 {PRAGMA foreign_keys=OFF;
813 BEGIN TRANSACTION;
814 CREATE TABLE t1(x);
815 INSERT INTO t1(rowid,x) VALUES(1,NULL);
816 INSERT INTO t1(rowid,x) VALUES(2,'');
817 INSERT INTO t1(rowid,x) VALUES(3,1);
818 INSERT INTO t1(rowid,x) VALUES(4,2.25);
819 INSERT INTO t1(rowid,x) VALUES(5,'hello');
820 INSERT INTO t1(rowid,x) VALUES(6,X'807f');
821 CREATE TABLE t3(x,y);
822 INSERT INTO t3(rowid,x,y) VALUES(1,1,NULL);
823 INSERT INTO t3(rowid,x,y) VALUES(2,2,'');
824 INSERT INTO t3(rowid,x,y) VALUES(3,3,1);
825 INSERT INTO t3(rowid,x,y) VALUES(4,4,2.25);
826 INSERT INTO t3(rowid,x,y) VALUES(5,5,'hello');
827 INSERT INTO t3(rowid,x,y) VALUES(6,6,X'807f');
828 COMMIT;}}
830 # If the table contains an INTEGER PRIMARY KEY, do not record a separate
831 # rowid column in the output.
833 do_test shell1-4.1.2 {
834   db close
835   forcedelete test2.db
836   sqlite3 db test2.db
837   db eval {
838     CREATE TABLE t1(x INTEGER PRIMARY KEY, y);
839     INSERT INTO t1 VALUES(1,null), (2,''), (3,1),
840                          (4,2.25), (5,'hello'), (6,x'807f');
841   }
842   catchcmd test2.db {.dump --preserve-rowids}
843 } {0 {PRAGMA foreign_keys=OFF;
844 BEGIN TRANSACTION;
845 CREATE TABLE t1(x INTEGER PRIMARY KEY, y);
846 INSERT INTO t1 VALUES(1,NULL);
847 INSERT INTO t1 VALUES(2,'');
848 INSERT INTO t1 VALUES(3,1);
849 INSERT INTO t1 VALUES(4,2.25);
850 INSERT INTO t1 VALUES(5,'hello');
851 INSERT INTO t1 VALUES(6,X'807f');
852 COMMIT;}}
854 # Verify that the table named [table] is correctly quoted and that
855 # an INTEGER PRIMARY KEY DESC is not an alias for the rowid.
857 do_test shell1-4.1.3 {
858   db close
859   forcedelete test2.db
860   sqlite3 db test2.db
861   db eval {
862     CREATE TABLE [table](x INTEGER PRIMARY KEY DESC, y);
863     INSERT INTO [table] VALUES(1,null), (12,''), (23,1),
864                          (34,2.25), (45,'hello'), (56,x'807f');
865   }
866   catchcmd test2.db {.dump --preserve-rowids}
867 } {0 {PRAGMA foreign_keys=OFF;
868 BEGIN TRANSACTION;
869 CREATE TABLE [table](x INTEGER PRIMARY KEY DESC, y);
870 INSERT INTO "table"(rowid,x,y) VALUES(1,1,NULL);
871 INSERT INTO "table"(rowid,x,y) VALUES(2,12,'');
872 INSERT INTO "table"(rowid,x,y) VALUES(3,23,1);
873 INSERT INTO "table"(rowid,x,y) VALUES(4,34,2.25);
874 INSERT INTO "table"(rowid,x,y) VALUES(5,45,'hello');
875 INSERT INTO "table"(rowid,x,y) VALUES(6,56,X'807f');
876 COMMIT;}}
878 # Do not record rowids for a WITHOUT ROWID table.  Also check correct quoting
879 # of table names that contain odd characters.
881 do_test shell1-4.1.4 {
882   db close
883   forcedelete test2.db
884   sqlite3 db test2.db
885   db eval {
886     CREATE TABLE [ta<>ble](x INTEGER PRIMARY KEY, y) WITHOUT ROWID;
887     INSERT INTO [ta<>ble] VALUES(1,null), (12,''), (23,1),
888                          (34,2.25), (45,'hello'), (56,x'807f');
889   }
890   catchcmd test2.db {.dump --preserve-rowids}
891 } {0 {PRAGMA foreign_keys=OFF;
892 BEGIN TRANSACTION;
893 CREATE TABLE [ta<>ble](x INTEGER PRIMARY KEY, y) WITHOUT ROWID;
894 INSERT INTO "ta<>ble" VALUES(1,NULL);
895 INSERT INTO "ta<>ble" VALUES(12,'');
896 INSERT INTO "ta<>ble" VALUES(23,1);
897 INSERT INTO "ta<>ble" VALUES(34,2.25);
898 INSERT INTO "ta<>ble" VALUES(45,'hello');
899 INSERT INTO "ta<>ble" VALUES(56,X'807f');
900 COMMIT;}}
902 # Do not record rowids if the rowid is inaccessible
904 do_test shell1-4.1.5 {
905   db close
906   forcedelete test2.db
907   sqlite3 db test2.db
908   db eval {
909     CREATE TABLE t1(_ROWID_,rowid,oid);
910     INSERT INTO t1 VALUES(1,null,'alpha'), (12,'',99), (23,1,x'b0b1b2');
911   }
912   catchcmd test2.db {.dump --preserve-rowids}
913 } {0 {PRAGMA foreign_keys=OFF;
914 BEGIN TRANSACTION;
915 CREATE TABLE t1(_ROWID_,rowid,oid);
916 INSERT INTO t1 VALUES(1,NULL,'alpha');
917 INSERT INTO t1 VALUES(12,'',99);
918 INSERT INTO t1 VALUES(23,1,X'b0b1b2');
919 COMMIT;}}
921 } else {
923 do_test shell1-4.1.6 {
924   db close
925   forcedelete test2.db
926   sqlite3 db test2.db
927   db eval {
928     CREATE TABLE t1(x INTEGER PRIMARY KEY, y);
929     INSERT INTO t1 VALUES(1,null), (2,''), (3,1),
930                          (4,2.25), (5,'hello'), (6,x'807f');
931   }
932   catchcmd test2.db {.dump --preserve-rowids}
933 } {1 {The --preserve-rowids option is not compatible with SQLITE_OMIT_VIRTUALTABLE}}
938 # Test the output of ".mode insert"
940 do_test shell1-4.2.1 {
941   catchcmd test.db ".mode insert t1\nselect * from t1;"
942 } {0 {INSERT INTO t1 VALUES(NULL);
943 INSERT INTO t1 VALUES('');
944 INSERT INTO t1 VALUES(1);
945 INSERT INTO t1 VALUES(2.25);
946 INSERT INTO t1 VALUES('hello');
947 INSERT INTO t1 VALUES(X'807f');}}
949 # Test the output of ".mode insert" with headers
951 do_test shell1-4.2.2 {
952   catchcmd test.db ".mode insert t1\n.headers on\nselect * from t1;"
953 } {0 {INSERT INTO t1(x) VALUES(NULL);
954 INSERT INTO t1(x) VALUES('');
955 INSERT INTO t1(x) VALUES(1);
956 INSERT INTO t1(x) VALUES(2.25);
957 INSERT INTO t1(x) VALUES('hello');
958 INSERT INTO t1(x) VALUES(X'807f');}}
960 # Test the output of ".mode insert"
962 do_test shell1-4.2.3 {
963   catchcmd test.db ".mode insert t3\nselect * from t3;"
964 } {0 {INSERT INTO t3 VALUES(1,NULL);
965 INSERT INTO t3 VALUES(2,'');
966 INSERT INTO t3 VALUES(3,1);
967 INSERT INTO t3 VALUES(4,2.25);
968 INSERT INTO t3 VALUES(5,'hello');
969 INSERT INTO t3 VALUES(6,X'807f');}}
971 # Test the output of ".mode insert" with headers
973 do_test shell1-4.2.4 {
974   catchcmd test.db ".mode insert t3\n.headers on\nselect * from t3;"
975 } {0 {INSERT INTO t3(x,y) VALUES(1,NULL);
976 INSERT INTO t3(x,y) VALUES(2,'');
977 INSERT INTO t3(x,y) VALUES(3,1);
978 INSERT INTO t3(x,y) VALUES(4,2.25);
979 INSERT INTO t3(x,y) VALUES(5,'hello');
980 INSERT INTO t3(x,y) VALUES(6,X'807f');}}
982 # Test the output of ".mode tcl"
984 do_test shell1-4.3 {
985   db close
986   forcedelete test.db
987   sqlite3 db test.db
988   db eval {
989     PRAGMA encoding=UTF8;
990     CREATE TABLE t1(x);
991     INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f');
992   }
993   catchcmd test.db ".mode tcl\nselect * from t1;"
994 } {0 {""
997 "2.25"
998 "hello"
999 "\200\177"}}
1001 # Test the output of ".mode tcl" with multiple columns
1003 do_test shell1-4.4 {
1004   db eval {
1005     CREATE TABLE t2(x,y);
1006     INSERT INTO t2 VALUES(null, ''), (1, 2.25), ('hello', x'807f');
1007   }
1008   catchcmd test.db ".mode tcl\nselect * from t2;"
1009 } {0 {"" ""
1010 "1" "2.25"
1011 "hello" "\200\177"}}
1013 # Test the output of ".mode tcl" with ".nullvalue"
1015 do_test shell1-4.5 {
1016   catchcmd test.db ".mode tcl\n.nullvalue NULL\nselect * from t2;"
1017 } {0 {"NULL" ""
1018 "1" "2.25"
1019 "hello" "\200\177"}}
1021 # Test the output of ".mode tcl" with Tcl reserved characters
1023 do_test shell1-4.6 {
1024   db eval {
1025     CREATE TABLE tcl1(x);
1026     INSERT INTO tcl1 VALUES('"'), ('['), (']'), ('\{'), ('\}'), (';'), ('$');
1027   }
1028   foreach {x y} [catchcmd test.db ".mode tcl\nselect * from tcl1;"] break
1029   list $x $y [llength $y]
1030 } {0 {"\""
1033 "\\{"
1034 "\\}"
1036 "$"} 7}
1038 # Test the output of ".mode quote"
1040 do_test shell1-4.7 {
1041   catchcmd test.db ".mode quote\nselect x'0123456789ABCDEF';"
1042 } {0 X'0123456789abcdef'}
1044 # Test using arbitrary byte data with the shell via standard input/output.
1046 do_test shell1-5.0 {
1047   #
1048   # NOTE: Skip NUL byte because it appears to be incompatible with command
1049   #       shell argument parsing.
1050   #
1051   for {set i 1} {$i < 256} {incr i} {
1052     #
1053     # NOTE: Due to how the Tcl [exec] command works (i.e. where it treats
1054     #       command channels opened for it as textual ones), the carriage
1055     #       return character (and on Windows, the end-of-file character)
1056     #       cannot be used here.
1057     #
1058     if {$i==0x0D || ($tcl_platform(platform)=="windows" && $i==0x1A)} {
1059       continue
1060     }
1061     # Tcl 8.7 maps 0x80 through 0x9f into valid UTF8.  So skip those tests.
1062     if {$i>=0x80 && $i<=0x9f} continue
1063     if {$i>=0xE0 && $tcl_platform(os)=="OpenBSD"}  continue
1064     if {$i>=0xE0 && $i<=0xEF && $tcl_platform(os)=="Linux"}  continue
1065     set hex [format %02X $i]
1066     set char [subst \\x$hex]; set oldChar $char
1067     set escapes [list]
1068     if {$tcl_platform(platform)=="windows"} {
1069       #
1070       # NOTE: On Windows, we need to escape all the whitespace characters,
1071       #       the alarm (\a) character, and those with special meaning to
1072       #       the SQLite shell itself.
1073       #
1074       set escapes [list \
1075           \a \\a \b \\b \t \\t \n \\n \v \\v \f \\f \r \\r \
1076           " " "\" \"" \" \\\" \\ \\\\]
1077     } else {
1078       #
1079       # NOTE: On Unix, we need to escape most of the whitespace characters
1080       #       and those with special meaning to the SQLite shell itself.
1081       #       The alarm (\a), backspace (\b), and carriage-return (\r)
1082       #       characters do not appear to require escaping on Unix.  For
1083       #       the alarm and backspace characters, this is probably due to
1084       #       differences in the command shell.  For the carriage-return,
1085       #       it is probably due to differences in how Tcl handles command
1086       #       channel end-of-line translations.
1087       #
1088       set escapes [list \
1089           \t \\t \n \\n \v \\v \f \\f \
1090           " " "\" \"" \" \\\" \\ \\\\]
1091     }
1092     set char [string map $escapes $char]
1093     set x [catchcmdex test.db ".print \"$char\"\n"]
1094     set code [lindex $x 0]
1095     set res [lindex $x 1]
1096     if {$code ne "0"} {
1097       error "failed with error: $res"
1098     }
1099     if {$res ne "$oldChar\n"} {
1100       if {[llength $res] > 0} {
1101         set got [format %02X [scan $res %c]]
1102       } else {
1103         set got <empty>
1104       }
1105       error "failed with byte $hex mismatch, got $got"
1106     }
1107   }
1108 } {}
1110 # These test cases do not work on MinGW
1111 if 0 {
1113 # The string used here is the word "test" in Chinese.
1114 # In UTF-8, it is encoded as: \xE6\xB5\x8B\xE8\xAF\x95
1115 set test \u6D4B\u8BD5
1117 do_test shell1-6.0 {
1118   set fileName $test; append fileName .db
1119   catch {forcedelete $fileName}
1120   set x [catchcmdex $fileName "CREATE TABLE t1(x);\n.schema\n"]
1121   set code [lindex $x 0]
1122   set res [string trim [lindex $x 1]]
1123   if {$code ne "0"} {
1124     error "failed with error: $res"
1125   }
1126   if {$res ne "CREATE TABLE t1(x);"} {
1127     error "failed with mismatch: $res"
1128   }
1129   if {![file exists $fileName]} {
1130     error "file \"$fileName\" (Unicode) does not exist"
1131   }
1132   forcedelete $fileName
1133 } {}
1135 do_test shell1-6.1 {
1136   catch {forcedelete test3.db}
1137   set x [catchcmdex test3.db \
1138       "CREATE TABLE [encoding convertto utf-8 $test](x);\n.schema\n"]
1139   set code [lindex $x 0]
1140   set res [string trim [lindex $x 1]]
1141   if {$code ne "0"} {
1142     error "failed with error: $res"
1143   }
1144   if {$res ne "CREATE TABLE ${test}(x);"} {
1145     error "failed with mismatch: $res"
1146   }
1147   forcedelete test3.db
1148 } {}
1151 db close
1152 forcedelete test.db test.db-journal test.db-wal
1153 sqlite3 db test.db
1155 # The shell tool ".schema" command uses virtual table "pragma_database_list"
1157 ifcapable vtab {
1159 do_test shell1-7.1.1 {
1160   db eval {
1161     CREATE TABLE Z (x TEXT PRIMARY KEY);
1162     CREATE TABLE _ (x TEXT PRIMARY KEY);
1163     CREATE TABLE YY (x TEXT PRIMARY KEY);
1164     CREATE TABLE __ (x TEXT PRIMARY KEY);
1165     CREATE TABLE WWW (x TEXT PRIMARY KEY);
1166     CREATE TABLE ___ (x TEXT PRIMARY KEY);
1167   }
1168 } {}
1169 do_test shell1-7.1.2 {
1170   catchcmd "test.db" ".schema _"
1171 } {0 {CREATE TABLE Z (x TEXT PRIMARY KEY);
1172 CREATE TABLE _ (x TEXT PRIMARY KEY);}}
1173 do_test shell1-7.1.3 {
1174   catchcmd "test.db" ".schema \"\\\\_\""
1175 } {0 {CREATE TABLE _ (x TEXT PRIMARY KEY);}}
1176 do_test shell1-7.1.4 {
1177   catchcmd "test.db" ".schema __"
1178 } {0 {CREATE TABLE YY (x TEXT PRIMARY KEY);
1179 CREATE TABLE __ (x TEXT PRIMARY KEY);}}
1180 do_test shell1-7.1.5 {
1181   catchcmd "test.db" ".schema \"\\\\_\\\\_\""
1182 } {0 {CREATE TABLE __ (x TEXT PRIMARY KEY);}}
1183 do_test shell1-7.1.6 {
1184   catchcmd "test.db" ".schema ___"
1185 } {0 {CREATE TABLE WWW (x TEXT PRIMARY KEY);
1186 CREATE TABLE ___ (x TEXT PRIMARY KEY);}}
1187 do_test shell1-7.1.7 {
1188   catchcmd "test.db" ".schema \"\\\\_\\\\_\\\\_\""
1189 } {0 {CREATE TABLE ___ (x TEXT PRIMARY KEY);}}
1193 # Test case for the ieee754 and decimal extensions in the shell.
1194 # See the "floatingpoint.html" file in the documentation for more
1195 # information.
1197 do_test shell1-8.1 {
1198   catchcmd ":memory:" {
1199     -- The pow2 table will hold all the necessary powers of two.
1200     CREATE TABLE pow2(x INTEGER PRIMARY KEY, v TEXT);
1201     WITH RECURSIVE c(x,v) AS (
1202       VALUES(0,'1')
1203       UNION ALL
1204       SELECT x+1, decimal_mul(v,'2') FROM c WHERE x+1<=971
1205     ) INSERT INTO pow2(x,v) SELECT x, v FROM c;
1206     WITH RECURSIVE c(x,v) AS (
1207       VALUES(-1,'0.5')
1208       UNION ALL
1209       SELECT x-1, decimal_mul(v,'0.5') FROM c WHERE x-1>=-1075
1210     ) INSERT INTO pow2(x,v) SELECT x, v FROM c;
1211     
1212     -- This query finds the decimal representation of each value in the "c" table.
1213     WITH c(n) AS (VALUES(47.49))
1214                      ----XXXXX----------- Replace with whatever you want
1215     SELECT decimal_mul(ieee754_mantissa(c.n),pow2.v)
1216       FROM pow2, c WHERE pow2.x=ieee754_exponent(c.n);
1217   }
1218 } {0 47.49000000000000198951966012828052043914794921875}
1219 do_test shell1-8.2 {
1220   catchcmd :memory: {
1221 .mode box
1222 SELECT ieee754(47.49) AS x;
1223   }
1224 } {0 {┌───────────────────────────────┐
1225 │               x               │
1226 ├───────────────────────────────┤
1227 │ ieee754(6683623321994527,-47) │
1228 └───────────────────────────────┘}}
1229 do_test shell1-8.3 {
1230   catchcmd ":memory: --box" {
1231     select ieee754(6683623321994527,-47) as x;
1232   }
1233 } {0 {┌───────┐
1234 │   x   │
1235 ├───────┤
1236 │ 47.49 │
1237 └───────┘}}
1238 do_test shell1-8.4 {
1239   catchcmd ":memory: --table" {SELECT ieee754_mantissa(47.49) AS M, ieee754_exponent(47.49) AS E;}
1240 } {0 {+------------------+-----+
1241 |        M         |  E  |
1242 +------------------+-----+
1243 | 6683623321994527 | -47 |
1244 +------------------+-----+}}
1245 do_test shell1-8.5 {
1246   catchcmd ":memory: --box" {
1247 create table t(a text, b int);
1248 insert into t values ('too long for one line', 1), ('shorter', NULL);
1249 .header on
1250 .width 10 10
1251 .nullvalue NADA
1252 select * from t;}
1253 } {0 {┌────────────┬────────────┐
1254 │     a      │     b      │
1255 ├────────────┼────────────┤
1256 │ too long f │ 1          │
1257 │ or one lin │            │
1258 │ e          │            │
1259 ├────────────┼────────────┤
1260 │ shorter    │ NADA       │
1261 └────────────┴────────────┘}}
1263 #----------------------------------------------------------------------------
1264 # Test cases shell1-9.*: Basic test that "dot" commands and SQL intermix ok.
1266 do_test shell1-9.1 {
1267   catchcmd :memory: {
1268 .mode csv
1270 x */ select 1,2; --x
1271  -- .nada
1273 .mode csv
1275 select 2,1; select 3,4;
1277 } {0 {1,2
1279 3,4}}
1281 #----------------------------------------------------------------------------
1282 # Test cases shell1-10.*: Test that certain static extensions are there.
1284 do_test shell1-10.1 {
1285   catchcmd :memory: {
1286 .mode list
1287 .header off
1288 select base64(base64(cast('digity-doo' as blob))),
1289  base85(base85(cast('digity-doo' as blob)));
1291 } {0 digity-doo|digity-doo}
1293 finish_test