xref: /sqlite-3.40.0/test/shell1.test (revision bd41d566)
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}
48do_test shell1-1.1.1b {
49  set res [catchcmd "test.db -bad" ""]
50  set rc [lindex $res 0]
51  list $rc \
52       [regexp {Error: unknown option: -bad} $res]
53} {1 1}
54# error on extra options
55do_test shell1-1.1.2 {
56  catchcmd "test.db \"select 3\" \"select 4\"" ""
57} {0 {3
584}}
59# error on extra options
60do_test shell1-1.1.3 {
61  catchcmd "test.db FOO test.db BAD" ".quit"
62} {1 {Error: near "FOO": syntax error}}
63
64# -help
65do_test shell1-1.2.1 {
66  set res [catchcmd "-help test.db" ""]
67  set rc [lindex $res 0]
68  list $rc \
69       [regexp {Usage} $res] \
70       [regexp {\-init} $res] \
71       [regexp {\-version} $res]
72} {1 1 1 1}
73
74# -init filename       read/process named file
75do_test shell1-1.3.1 {
76  catchcmd "-init FOO test.db" ""
77} {0 {}}
78do_test shell1-1.3.2 {
79  catchcmd "-init FOO test.db .quit BAD" ""
80} {0 {}}
81do_test shell1-1.3.3 {
82  catchcmd "-init FOO test.db BAD .quit" ""
83} {1 {Error: near "BAD": syntax error}}
84
85# -echo                print commands before execution
86do_test shell1-1.4.1 {
87  catchcmd "-echo test.db" ""
88} {0 {}}
89
90# -[no]header          turn headers on or off
91do_test shell1-1.5.1 {
92  catchcmd "-header test.db" ""
93} {0 {}}
94do_test shell1-1.5.2 {
95  catchcmd "-noheader test.db" ""
96} {0 {}}
97
98# -bail                stop after hitting an error
99do_test shell1-1.6.1 {
100  catchcmd "-bail test.db" ""
101} {0 {}}
102
103# -interactive         force interactive I/O
104do_test shell1-1.7.1 {
105  set res [catchcmd "-interactive test.db" ".quit"]
106  set rc [lindex $res 0]
107  list $rc \
108       [regexp {SQLite version} $res] \
109       [regexp {Enter ".help" for usage hints} $res]
110} {0 1 1}
111
112# -batch               force batch I/O
113do_test shell1-1.8.1 {
114  catchcmd "-batch test.db" ""
115} {0 {}}
116
117# -column              set output mode to 'column'
118do_test shell1-1.9.1 {
119  catchcmd "-column test.db" ""
120} {0 {}}
121
122# -csv                 set output mode to 'csv'
123do_test shell1-1.10.1 {
124  catchcmd "-csv test.db" ""
125} {0 {}}
126
127# -html                set output mode to HTML
128do_test shell1-1.11.1 {
129  catchcmd "-html test.db" ""
130} {0 {}}
131
132# -line                set output mode to 'line'
133do_test shell1-1.12.1 {
134  catchcmd "-line test.db" ""
135} {0 {}}
136
137# -list                set output mode to 'list'
138do_test shell1-1.13.1 {
139  catchcmd "-list test.db" ""
140} {0 {}}
141
142# -separator 'x'       set output field separator (|)
143do_test shell1-1.14.1 {
144  catchcmd "-separator 'x' test.db" ""
145} {0 {}}
146do_test shell1-1.14.2 {
147  catchcmd "-separator x test.db" ""
148} {0 {}}
149do_test shell1-1.14.3 {
150  set res [catchcmd "-separator" ""]
151  set rc [lindex $res 0]
152  list $rc \
153       [regexp {Error: missing argument to -separator} $res]
154} {1 1}
155
156# -stats               print memory stats before each finalize
157do_test shell1-1.14b.1 {
158  catchcmd "-stats test.db" ""
159} {0 {}}
160
161# -nullvalue 'text'    set text string for NULL values
162do_test shell1-1.15.1 {
163  catchcmd "-nullvalue 'x' test.db" ""
164} {0 {}}
165do_test shell1-1.15.2 {
166  catchcmd "-nullvalue x test.db" ""
167} {0 {}}
168do_test shell1-1.15.3 {
169  set res [catchcmd "-nullvalue" ""]
170  set rc [lindex $res 0]
171  list $rc \
172       [regexp {Error: missing argument to -nullvalue} $res]
173} {1 1}
174
175# -version             show SQLite version
176do_test shell1-1.16.1 {
177  set x [catchcmd "-version test.db" ""]
178} {/3.[0-9.]+ 20\d\d-[01]\d-\d\d \d\d:\d\d:\d\d [0-9a-f]+/}
179
180#----------------------------------------------------------------------------
181# Test cases shell1-2.*: Basic "dot" command token parsing.
182#
183
184# check first token handling
185do_test shell1-2.1.1 {
186  catchcmd "test.db" ".foo"
187} {1 {Error: unknown command or invalid arguments:  "foo". Enter ".help" for help}}
188do_test shell1-2.1.2 {
189  catchcmd "test.db" ".\"foo OFF\""
190} {1 {Error: unknown command or invalid arguments:  "foo OFF". Enter ".help" for help}}
191do_test shell1-2.1.3 {
192  catchcmd "test.db" ".\'foo OFF\'"
193} {1 {Error: unknown command or invalid arguments:  "foo OFF". Enter ".help" for help}}
194
195# unbalanced quotes
196do_test shell1-2.2.1 {
197  catchcmd "test.db" ".\"foo OFF"
198} {1 {Error: unknown command or invalid arguments:  "foo OFF". Enter ".help" for help}}
199do_test shell1-2.2.2 {
200  catchcmd "test.db" ".\'foo OFF"
201} {1 {Error: unknown command or invalid arguments:  "foo OFF". Enter ".help" for help}}
202do_test shell1-2.2.3 {
203  catchcmd "test.db" ".explain \"OFF"
204} {0 {}}
205do_test shell1-2.2.4 {
206  catchcmd "test.db" ".explain \'OFF"
207} {0 {}}
208do_test shell1-2.2.5 {
209  catchcmd "test.db" ".mode \"insert FOO"
210} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
211do_test shell1-2.2.6 {
212  catchcmd "test.db" ".mode \'insert FOO"
213} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
214
215# check multiple tokens, and quoted tokens
216do_test shell1-2.3.1 {
217  catchcmd "test.db" ".explain 1"
218} {0 {}}
219do_test shell1-2.3.2 {
220  catchcmd "test.db" ".explain on"
221} {0 {}}
222do_test shell1-2.3.3 {
223  catchcmd "test.db" ".explain \"1 2 3\""
224} {1 {ERROR: Not a boolean value: "1 2 3". Assuming "no".}}
225do_test shell1-2.3.4 {
226  catchcmd "test.db" ".explain \"OFF\""
227} {0 {}}
228do_test shell1-2.3.5 {
229  catchcmd "test.db" ".\'explain\' \'OFF\'"
230} {0 {}}
231do_test shell1-2.3.6 {
232  catchcmd "test.db" ".explain \'OFF\'"
233} {0 {}}
234do_test shell1-2.3.7 {
235  catchcmd "test.db" ".\'explain\' \'OFF\'"
236} {0 {}}
237
238# check quoted args are unquoted
239do_test shell1-2.4.1 {
240  catchcmd "test.db" ".mode FOO"
241} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
242do_test shell1-2.4.2 {
243  catchcmd "test.db" ".mode csv"
244} {0 {}}
245do_test shell1-2.4.2 {
246  catchcmd "test.db" ".mode \"csv\""
247} {0 {}}
248
249
250#----------------------------------------------------------------------------
251# Test cases shell1-3.*: Basic test that "dot" command can be called.
252#
253
254# .backup ?DB? FILE      Backup DB (default "main") to FILE
255do_test shell1-3.1.1 {
256  catchcmd "test.db" ".backup"
257} {1 {missing FILENAME argument on .backup}}
258do_test shell1-3.1.2 {
259  catchcmd "test.db" ".backup FOO"
260} {0 {}}
261do_test shell1-3.1.3 {
262  catchcmd "test.db" ".backup FOO BAR"
263} {1 {Error: unknown database FOO}}
264do_test shell1-3.1.4 {
265  # too many arguments
266  catchcmd "test.db" ".backup FOO BAR BAD"
267} {1 {too many arguments to .backup}}
268
269# .bail ON|OFF           Stop after hitting an error.  Default OFF
270do_test shell1-3.2.1 {
271  catchcmd "test.db" ".bail"
272} {1 {Usage: .bail on|off}}
273do_test shell1-3.2.2 {
274  catchcmd "test.db" ".bail ON"
275} {0 {}}
276do_test shell1-3.2.3 {
277  catchcmd "test.db" ".bail OFF"
278} {0 {}}
279do_test shell1-3.2.4 {
280  # too many arguments
281  catchcmd "test.db" ".bail OFF BAD"
282} {1 {Usage: .bail on|off}}
283
284# .databases             List names and files of attached databases
285do_test shell1-3.3.1 {
286  catchcmd "-csv test.db" ".databases"
287} "/0 +.*main +[string map {/ .} [string range [get_pwd] 0 10]].*/"
288do_test shell1-3.3.2 {
289  # extra arguments ignored
290  catchcmd "test.db" ".databases BAD"
291} "/0 +.*main +[string map {/ .} [string range [get_pwd] 0 10]].*/"
292
293# .dump ?TABLE? ...      Dump the database in an SQL text format
294#                          If TABLE specified, only dump tables matching
295#                          LIKE pattern TABLE.
296do_test shell1-3.4.1 {
297  set res [catchcmd "test.db" ".dump"]
298  list [regexp {BEGIN TRANSACTION;} $res] \
299       [regexp {COMMIT;} $res]
300} {1 1}
301do_test shell1-3.4.2 {
302  set res [catchcmd "test.db" ".dump FOO"]
303  list [regexp {BEGIN TRANSACTION;} $res] \
304       [regexp {COMMIT;} $res]
305} {1 1}
306do_test shell1-3.4.3 {
307  # too many arguments
308  catchcmd "test.db" ".dump FOO BAD"
309} {1 {Usage: .dump ?LIKE-PATTERN?}}
310
311# .echo ON|OFF           Turn command echo on or off
312do_test shell1-3.5.1 {
313  catchcmd "test.db" ".echo"
314} {1 {Usage: .echo on|off}}
315do_test shell1-3.5.2 {
316  catchcmd "test.db" ".echo ON"
317} {0 {}}
318do_test shell1-3.5.3 {
319  catchcmd "test.db" ".echo OFF"
320} {0 {}}
321do_test shell1-3.5.4 {
322  # too many arguments
323  catchcmd "test.db" ".echo OFF BAD"
324} {1 {Usage: .echo on|off}}
325
326# .exit                  Exit this program
327do_test shell1-3.6.1 {
328  catchcmd "test.db" ".exit"
329} {0 {}}
330
331# .explain ON|OFF        Turn output mode suitable for EXPLAIN on or off.
332do_test shell1-3.7.1 {
333  catchcmd "test.db" ".explain"
334  # explain is the exception to the booleans.  without an option, it turns it on.
335} {0 {}}
336do_test shell1-3.7.2 {
337  catchcmd "test.db" ".explain ON"
338} {0 {}}
339do_test shell1-3.7.3 {
340  catchcmd "test.db" ".explain OFF"
341} {0 {}}
342do_test shell1-3.7.4 {
343  # extra arguments ignored
344  catchcmd "test.db" ".explain OFF BAD"
345} {0 {}}
346
347
348# .header(s) ON|OFF      Turn display of headers on or off
349do_test shell1-3.9.1 {
350  catchcmd "test.db" ".header"
351} {1 {Usage: .headers on|off}}
352do_test shell1-3.9.2 {
353  catchcmd "test.db" ".header ON"
354} {0 {}}
355do_test shell1-3.9.3 {
356  catchcmd "test.db" ".header OFF"
357} {0 {}}
358do_test shell1-3.9.4 {
359  # too many arguments
360  catchcmd "test.db" ".header OFF BAD"
361} {1 {Usage: .headers on|off}}
362
363do_test shell1-3.9.5 {
364  catchcmd "test.db" ".headers"
365} {1 {Usage: .headers on|off}}
366do_test shell1-3.9.6 {
367  catchcmd "test.db" ".headers ON"
368} {0 {}}
369do_test shell1-3.9.7 {
370  catchcmd "test.db" ".headers OFF"
371} {0 {}}
372do_test shell1-3.9.8 {
373  # too many arguments
374  catchcmd "test.db" ".headers OFF BAD"
375} {1 {Usage: .headers on|off}}
376
377# .help                  Show this message
378do_test shell1-3.10.1 {
379  set res [catchcmd "test.db" ".help"]
380  # look for a few of the possible help commands
381  list [regexp {.help} $res] \
382       [regexp {.quit} $res] \
383       [regexp {.show} $res]
384} {1 1 1}
385do_test shell1-3.10.2 {
386  # we allow .help to take extra args (it is help after all)
387  set res [catchcmd "test.db" ".help BAD"]
388  # look for a few of the possible help commands
389  list [regexp {.help} $res] \
390       [regexp {.quit} $res] \
391       [regexp {.show} $res]
392} {1 1 1}
393
394# .import FILE TABLE     Import data from FILE into TABLE
395do_test shell1-3.11.1 {
396  catchcmd "test.db" ".import"
397} {1 {Usage: .import FILE TABLE}}
398do_test shell1-3.11.2 {
399  catchcmd "test.db" ".import FOO"
400} {1 {Usage: .import FILE TABLE}}
401#do_test shell1-3.11.2 {
402#  catchcmd "test.db" ".import FOO BAR"
403#} {1 {Error: no such table: BAR}}
404do_test shell1-3.11.3 {
405  # too many arguments
406  catchcmd "test.db" ".import FOO BAR BAD"
407} {1 {Usage: .import FILE TABLE}}
408
409# .indices ?TABLE?       Show names of all indices
410#                          If TABLE specified, only show indices for tables
411#                          matching LIKE pattern TABLE.
412do_test shell1-3.12.1 {
413  catchcmd "test.db" ".indices"
414} {0 {}}
415do_test shell1-3.12.2 {
416  catchcmd "test.db" ".indices FOO"
417} {0 {}}
418do_test shell1-3.12.3 {
419  # too many arguments
420  catchcmd "test.db" ".indices FOO BAD"
421} {1 {Usage: .indices ?LIKE-PATTERN?}}
422
423# .mode MODE ?TABLE?     Set output mode where MODE is one of:
424#                          csv      Comma-separated values
425#                          column   Left-aligned columns.  (See .width)
426#                          html     HTML <table> code
427#                          insert   SQL insert statements for TABLE
428#                          line     One value per line
429#                          list     Values delimited by .separator string
430#                          tabs     Tab-separated values
431#                          tcl      TCL list elements
432do_test shell1-3.13.1 {
433  catchcmd "test.db" ".mode"
434} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
435do_test shell1-3.13.2 {
436  catchcmd "test.db" ".mode FOO"
437} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
438do_test shell1-3.13.3 {
439  catchcmd "test.db" ".mode csv"
440} {0 {}}
441do_test shell1-3.13.4 {
442  catchcmd "test.db" ".mode column"
443} {0 {}}
444do_test shell1-3.13.5 {
445  catchcmd "test.db" ".mode html"
446} {0 {}}
447do_test shell1-3.13.6 {
448  catchcmd "test.db" ".mode insert"
449} {0 {}}
450do_test shell1-3.13.7 {
451  catchcmd "test.db" ".mode line"
452} {0 {}}
453do_test shell1-3.13.8 {
454  catchcmd "test.db" ".mode list"
455} {0 {}}
456do_test shell1-3.13.9 {
457  catchcmd "test.db" ".mode tabs"
458} {0 {}}
459do_test shell1-3.13.10 {
460  catchcmd "test.db" ".mode tcl"
461} {0 {}}
462do_test shell1-3.13.11 {
463  # extra arguments ignored
464  catchcmd "test.db" ".mode tcl BAD"
465} {0 {}}
466
467# don't allow partial mode type matches
468do_test shell1-3.13.12 {
469  catchcmd "test.db" ".mode l"
470} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
471do_test shell1-3.13.13 {
472  catchcmd "test.db" ".mode li"
473} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
474do_test shell1-3.13.14 {
475  catchcmd "test.db" ".mode lin"
476} {0 {}}
477
478# .nullvalue STRING      Print STRING in place of NULL values
479do_test shell1-3.14.1 {
480  catchcmd "test.db" ".nullvalue"
481} {1 {Usage: .nullvalue STRING}}
482do_test shell1-3.14.2 {
483  catchcmd "test.db" ".nullvalue FOO"
484} {0 {}}
485do_test shell1-3.14.3 {
486  # too many arguments
487  catchcmd "test.db" ".nullvalue FOO BAD"
488} {1 {Usage: .nullvalue STRING}}
489
490# .output FILENAME       Send output to FILENAME
491do_test shell1-3.15.1 {
492  catchcmd "test.db" ".output"
493} {0 {}}
494do_test shell1-3.15.2 {
495  catchcmd "test.db" ".output FOO"
496} {0 {}}
497do_test shell1-3.15.3 {
498  # too many arguments
499  catchcmd "test.db" ".output FOO BAD"
500} {1 {Usage: .output FILE}}
501
502# .output stdout         Send output to the screen
503do_test shell1-3.16.1 {
504  catchcmd "test.db" ".output stdout"
505} {0 {}}
506do_test shell1-3.16.2 {
507  # too many arguments
508  catchcmd "test.db" ".output stdout BAD"
509} {1 {Usage: .output FILE}}
510
511# .prompt MAIN CONTINUE  Replace the standard prompts
512do_test shell1-3.17.1 {
513  catchcmd "test.db" ".prompt"
514} {0 {}}
515do_test shell1-3.17.2 {
516  catchcmd "test.db" ".prompt FOO"
517} {0 {}}
518do_test shell1-3.17.3 {
519  catchcmd "test.db" ".prompt FOO BAR"
520} {0 {}}
521do_test shell1-3.17.4 {
522  # too many arguments
523  catchcmd "test.db" ".prompt FOO BAR BAD"
524} {0 {}}
525
526# .quit                  Exit this program
527do_test shell1-3.18.1 {
528  catchcmd "test.db" ".quit"
529} {0 {}}
530do_test shell1-3.18.2 {
531  # too many arguments
532  catchcmd "test.db" ".quit BAD"
533} {0 {}}
534
535# .read FILENAME         Execute SQL in FILENAME
536do_test shell1-3.19.1 {
537  catchcmd "test.db" ".read"
538} {1 {Usage: .read FILE}}
539do_test shell1-3.19.2 {
540  forcedelete FOO
541  catchcmd "test.db" ".read FOO"
542} {1 {Error: cannot open "FOO"}}
543do_test shell1-3.19.3 {
544  # too many arguments
545  catchcmd "test.db" ".read FOO BAD"
546} {1 {Usage: .read FILE}}
547
548# .restore ?DB? FILE     Restore content of DB (default "main") from FILE
549do_test shell1-3.20.1 {
550  catchcmd "test.db" ".restore"
551} {1 {Usage: .restore ?DB? FILE}}
552do_test shell1-3.20.2 {
553  catchcmd "test.db" ".restore FOO"
554} {0 {}}
555do_test shell1-3.20.3 {
556  catchcmd "test.db" ".restore FOO BAR"
557} {1 {Error: unknown database FOO}}
558do_test shell1-3.20.4 {
559  # too many arguments
560  catchcmd "test.db" ".restore FOO BAR BAD"
561} {1 {Usage: .restore ?DB? FILE}}
562
563# .schema ?TABLE?        Show the CREATE statements
564#                          If TABLE specified, only show tables matching
565#                          LIKE pattern TABLE.
566do_test shell1-3.21.1 {
567  catchcmd "test.db" ".schema"
568} {0 {}}
569do_test shell1-3.21.2 {
570  catchcmd "test.db" ".schema FOO"
571} {0 {}}
572do_test shell1-3.21.3 {
573  # too many arguments
574  catchcmd "test.db" ".schema FOO BAD"
575} {1 {Usage: .schema ?LIKE-PATTERN?}}
576
577do_test shell1-3.21.4 {
578  catchcmd "test.db" {
579     CREATE TABLE t1(x);
580     CREATE VIEW v2 AS SELECT x+1 AS y FROM t1;
581     CREATE VIEW v1 AS SELECT y+1 FROM v2;
582  }
583  catchcmd "test.db" ".schema"
584} {0 {CREATE TABLE t1(x);
585CREATE VIEW v2 AS SELECT x+1 AS y FROM t1;
586CREATE VIEW v1 AS SELECT y+1 FROM v2;}}
587db eval {DROP VIEW v1; DROP VIEW v2; DROP TABLE t1;}
588
589# .separator STRING      Change separator used by output mode and .import
590do_test shell1-3.22.1 {
591  catchcmd "test.db" ".separator"
592} {1 {Usage: .separator SEPARATOR ?NEWLINE?}}
593do_test shell1-3.22.2 {
594  catchcmd "test.db" ".separator FOO"
595} {0 {}}
596do_test shell1-3.22.3 {
597  catchcmd "test.db" ".separator ABC XYZ"
598} {0 {}}
599do_test shell1-3.22.4 {
600  # too many arguments
601  catchcmd "test.db" ".separator FOO BAD BAD2"
602} {1 {Usage: .separator SEPARATOR ?NEWLINE?}}
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 {Usage: .show}}
621
622# .stats ON|OFF          Turn stats on or off
623do_test shell1-3.23b.1 {
624  catchcmd "test.db" ".stats"
625} {1 {Usage: .stats on|off}}
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 {Usage: .stats on|off}}
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} {0 {}}
650
651# .timeout MS            Try opening locked tables for MS milliseconds
652do_test shell1-3.25.1 {
653  catchcmd "test.db" ".timeout"
654} {0 {}}
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} {0 {}}
666
667# .width NUM NUM ...     Set column widths for "column" mode
668do_test shell1-3.26.1 {
669  catchcmd "test.db" ".width"
670} {0 {}}
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 {}}
683do_test shell1-3.26.5 {
684  catchcmd "test.db" ".mode column\n.width 10 -10\nSELECT 'abcdefg', 123456;"
685  # this should be treated the same as a '1' width for col 1 and 2
686} {0 {abcdefg         123456}}
687do_test shell1-3.26.6 {
688  catchcmd "test.db" ".mode column\n.width -10 10\nSELECT 'abcdefg', 123456;"
689  # this should be treated the same as a '1' width for col 1 and 2
690} {0 {   abcdefg  123456    }}
691
692
693# .timer ON|OFF          Turn the CPU timer measurement on or off
694do_test shell1-3.27.1 {
695  catchcmd "test.db" ".timer"
696} {1 {Usage: .timer on|off}}
697do_test shell1-3.27.2 {
698  catchcmd "test.db" ".timer ON"
699} {0 {}}
700do_test shell1-3.27.3 {
701  catchcmd "test.db" ".timer OFF"
702} {0 {}}
703do_test shell1-3.27.4 {
704  # too many arguments
705  catchcmd "test.db" ".timer OFF BAD"
706} {1 {Usage: .timer on|off}}
707
708do_test shell1-3-28.1 {
709  catchcmd test.db \
710     ".log stdout\nSELECT coalesce(sqlite_log(123,'hello'),'456');"
711} "0 {(123) hello\n456}"
712
713do_test shell1-3-29.1 {
714  catchcmd "test.db" ".print this is a test"
715} {0 {this is a test}}
716
717# dot-command argument quoting
718do_test shell1-3-30.1 {
719  catchcmd {test.db} {.print "this\"is'a\055test" 'this\"is\\a\055test'}
720} {0 {this"is'a-test this\"is\\a\055test}}
721do_test shell1-3-31.1 {
722  catchcmd {test.db} {.print "this\nis\ta\\test" 'this\nis\ta\\test'}
723} [list 0 "this\nis\ta\\test this\\nis\\ta\\\\test"]
724
725
726# Test the output of the ".dump" command
727#
728do_test shell1-4.1 {
729  db close
730  forcedelete test.db
731  sqlite3 db test.db
732  db eval {
733    PRAGMA encoding=UTF16;
734    CREATE TABLE t1(x);
735    INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f');
736  }
737  catchcmd test.db {.dump}
738} {0 {PRAGMA foreign_keys=OFF;
739BEGIN TRANSACTION;
740CREATE TABLE t1(x);
741INSERT INTO "t1" VALUES(NULL);
742INSERT INTO "t1" VALUES('');
743INSERT INTO "t1" VALUES(1);
744INSERT INTO "t1" VALUES(2.25);
745INSERT INTO "t1" VALUES('hello');
746INSERT INTO "t1" VALUES(X'807F');
747COMMIT;}}
748
749# Test the output of ".mode insert"
750#
751do_test shell1-4.2 {
752  catchcmd test.db ".mode insert t1\nselect * from t1;"
753} {0 {INSERT INTO t1 VALUES(NULL);
754INSERT INTO t1 VALUES('');
755INSERT INTO t1 VALUES(1);
756INSERT INTO t1 VALUES(2.25);
757INSERT INTO t1 VALUES('hello');
758INSERT INTO t1 VALUES(X'807f');}}
759
760# Test the output of ".mode tcl"
761#
762do_test shell1-4.3 {
763  db close
764  forcedelete test.db
765  sqlite3 db test.db
766  db eval {
767    PRAGMA encoding=UTF8;
768    CREATE TABLE t1(x);
769    INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f');
770  }
771  catchcmd test.db ".mode tcl\nselect * from t1;"
772} {0 {""
773""
774"1"
775"2.25"
776"hello"
777"\200\177"}}
778
779# Test the output of ".mode tcl" with multiple columns
780#
781do_test shell1-4.4 {
782  db eval {
783    CREATE TABLE t2(x,y);
784    INSERT INTO t2 VALUES(null, ''), (1, 2.25), ('hello', x'807f');
785  }
786  catchcmd test.db ".mode tcl\nselect * from t2;"
787} {0 {"" ""
788"1" "2.25"
789"hello" "\200\177"}}
790
791# Test the output of ".mode tcl" with ".nullvalue"
792#
793do_test shell1-4.5 {
794  catchcmd test.db ".mode tcl\n.nullvalue NULL\nselect * from t2;"
795} {0 {"NULL" ""
796"1" "2.25"
797"hello" "\200\177"}}
798
799# Test the output of ".mode tcl" with Tcl reserved characters
800#
801do_test shell1-4.6 {
802  db eval {
803    CREATE TABLE tcl1(x);
804    INSERT INTO tcl1 VALUES('"'), ('['), (']'), ('\{'), ('\}'), (';'), ('$');
805  }
806  foreach {x y} [catchcmd test.db ".mode tcl\nselect * from tcl1;"] break
807  list $x $y [llength $y]
808} {0 {"\""
809"["
810"]"
811"\\{"
812"\\}"
813";"
814"$"} 7}
815
816finish_test
817