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