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