xref: /sqlite-3.40.0/test/shell1.test (revision b43be55e)
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: ascii 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: ascii 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: ascii 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#                          ascii    Columns/rows delimited by 0x1F and 0x1E
425#                          csv      Comma-separated values
426#                          column   Left-aligned columns.  (See .width)
427#                          html     HTML <table> code
428#                          insert   SQL insert statements for TABLE
429#                          line     One value per line
430#                          list     Values delimited by .separator strings
431#                          tabs     Tab-separated values
432#                          tcl      TCL list elements
433do_test shell1-3.13.1 {
434  catchcmd "test.db" ".mode"
435} {1 {Error: mode should be one of: ascii column csv html insert line list tabs tcl}}
436do_test shell1-3.13.2 {
437  catchcmd "test.db" ".mode FOO"
438} {1 {Error: mode should be one of: ascii column csv html insert line list tabs tcl}}
439do_test shell1-3.13.3 {
440  catchcmd "test.db" ".mode csv"
441} {0 {}}
442do_test shell1-3.13.4 {
443  catchcmd "test.db" ".mode column"
444} {0 {}}
445do_test shell1-3.13.5 {
446  catchcmd "test.db" ".mode html"
447} {0 {}}
448do_test shell1-3.13.6 {
449  catchcmd "test.db" ".mode insert"
450} {0 {}}
451do_test shell1-3.13.7 {
452  catchcmd "test.db" ".mode line"
453} {0 {}}
454do_test shell1-3.13.8 {
455  catchcmd "test.db" ".mode list"
456} {0 {}}
457do_test shell1-3.13.9 {
458  catchcmd "test.db" ".mode tabs"
459} {0 {}}
460do_test shell1-3.13.10 {
461  catchcmd "test.db" ".mode tcl"
462} {0 {}}
463do_test shell1-3.13.11 {
464  # extra arguments ignored
465  catchcmd "test.db" ".mode tcl BAD"
466} {0 {}}
467
468# don't allow partial mode type matches
469do_test shell1-3.13.12 {
470  catchcmd "test.db" ".mode l"
471} {1 {Error: mode should be one of: ascii column csv html insert line list tabs tcl}}
472do_test shell1-3.13.13 {
473  catchcmd "test.db" ".mode li"
474} {1 {Error: mode should be one of: ascii column csv html insert line list tabs tcl}}
475do_test shell1-3.13.14 {
476  catchcmd "test.db" ".mode lin"
477} {0 {}}
478
479# .nullvalue STRING      Print STRING in place of NULL values
480do_test shell1-3.14.1 {
481  catchcmd "test.db" ".nullvalue"
482} {1 {Usage: .nullvalue STRING}}
483do_test shell1-3.14.2 {
484  catchcmd "test.db" ".nullvalue FOO"
485} {0 {}}
486do_test shell1-3.14.3 {
487  # too many arguments
488  catchcmd "test.db" ".nullvalue FOO BAD"
489} {1 {Usage: .nullvalue STRING}}
490
491# .output FILENAME       Send output to FILENAME
492do_test shell1-3.15.1 {
493  catchcmd "test.db" ".output"
494} {0 {}}
495do_test shell1-3.15.2 {
496  catchcmd "test.db" ".output FOO"
497} {0 {}}
498do_test shell1-3.15.3 {
499  # too many arguments
500  catchcmd "test.db" ".output FOO BAD"
501} {1 {Usage: .output FILE}}
502
503# .output stdout         Send output to the screen
504do_test shell1-3.16.1 {
505  catchcmd "test.db" ".output stdout"
506} {0 {}}
507do_test shell1-3.16.2 {
508  # too many arguments
509  catchcmd "test.db" ".output stdout BAD"
510} {1 {Usage: .output FILE}}
511
512# .prompt MAIN CONTINUE  Replace the standard prompts
513do_test shell1-3.17.1 {
514  catchcmd "test.db" ".prompt"
515} {0 {}}
516do_test shell1-3.17.2 {
517  catchcmd "test.db" ".prompt FOO"
518} {0 {}}
519do_test shell1-3.17.3 {
520  catchcmd "test.db" ".prompt FOO BAR"
521} {0 {}}
522do_test shell1-3.17.4 {
523  # too many arguments
524  catchcmd "test.db" ".prompt FOO BAR BAD"
525} {0 {}}
526
527# .quit                  Exit this program
528do_test shell1-3.18.1 {
529  catchcmd "test.db" ".quit"
530} {0 {}}
531do_test shell1-3.18.2 {
532  # too many arguments
533  catchcmd "test.db" ".quit BAD"
534} {0 {}}
535
536# .read FILENAME         Execute SQL in FILENAME
537do_test shell1-3.19.1 {
538  catchcmd "test.db" ".read"
539} {1 {Usage: .read FILE}}
540do_test shell1-3.19.2 {
541  forcedelete FOO
542  catchcmd "test.db" ".read FOO"
543} {1 {Error: cannot open "FOO"}}
544do_test shell1-3.19.3 {
545  # too many arguments
546  catchcmd "test.db" ".read FOO BAD"
547} {1 {Usage: .read FILE}}
548
549# .restore ?DB? FILE     Restore content of DB (default "main") from FILE
550do_test shell1-3.20.1 {
551  catchcmd "test.db" ".restore"
552} {1 {Usage: .restore ?DB? FILE}}
553do_test shell1-3.20.2 {
554  catchcmd "test.db" ".restore FOO"
555} {0 {}}
556do_test shell1-3.20.3 {
557  catchcmd "test.db" ".restore FOO BAR"
558} {1 {Error: unknown database FOO}}
559do_test shell1-3.20.4 {
560  # too many arguments
561  catchcmd "test.db" ".restore FOO BAR BAD"
562} {1 {Usage: .restore ?DB? FILE}}
563
564# .schema ?TABLE?        Show the CREATE statements
565#                          If TABLE specified, only show tables matching
566#                          LIKE pattern TABLE.
567do_test shell1-3.21.1 {
568  catchcmd "test.db" ".schema"
569} {0 {}}
570do_test shell1-3.21.2 {
571  catchcmd "test.db" ".schema FOO"
572} {0 {}}
573do_test shell1-3.21.3 {
574  # too many arguments
575  catchcmd "test.db" ".schema FOO BAD"
576} {1 {Usage: .schema ?LIKE-PATTERN?}}
577
578do_test shell1-3.21.4 {
579  catchcmd "test.db" {
580     CREATE TABLE t1(x);
581     CREATE VIEW v2 AS SELECT x+1 AS y FROM t1;
582     CREATE VIEW v1 AS SELECT y+1 FROM v2;
583  }
584  catchcmd "test.db" ".schema"
585} {0 {CREATE TABLE t1(x);
586CREATE VIEW v2 AS SELECT x+1 AS y FROM t1;
587CREATE VIEW v1 AS SELECT y+1 FROM v2;}}
588db eval {DROP VIEW v1; DROP VIEW v2; DROP TABLE t1;}
589
590# .separator STRING  Change column separator used by output and .import
591do_test shell1-3.22.1 {
592  catchcmd "test.db" ".separator"
593} {1 {Usage: .separator COL ?ROW?}}
594do_test shell1-3.22.2 {
595  catchcmd "test.db" ".separator FOO"
596} {0 {}}
597do_test shell1-3.22.3 {
598  catchcmd "test.db" ".separator ABC XYZ"
599} {0 {}}
600do_test shell1-3.22.4 {
601  # too many arguments
602  catchcmd "test.db" ".separator FOO BAD BAD2"
603} {1 {Usage: .separator COL ?ROW?}}
604
605# .show                  Show the current values for various settings
606do_test shell1-3.23.1 {
607  set res [catchcmd "test.db" ".show"]
608  list [regexp {echo:} $res] \
609       [regexp {explain:} $res] \
610       [regexp {headers:} $res] \
611       [regexp {mode:} $res] \
612       [regexp {nullvalue:} $res] \
613       [regexp {output:} $res] \
614       [regexp {colseparator:} $res] \
615       [regexp {rowseparator:} $res] \
616       [regexp {stats:} $res] \
617       [regexp {width:} $res]
618} {1 1 1 1 1 1 1 1 1 1}
619do_test shell1-3.23.2 {
620  # too many arguments
621  catchcmd "test.db" ".show BAD"
622} {1 {Usage: .show}}
623
624# .stats ON|OFF          Turn stats on or off
625do_test shell1-3.23b.1 {
626  catchcmd "test.db" ".stats"
627} {1 {Usage: .stats on|off}}
628do_test shell1-3.23b.2 {
629  catchcmd "test.db" ".stats ON"
630} {0 {}}
631do_test shell1-3.23b.3 {
632  catchcmd "test.db" ".stats OFF"
633} {0 {}}
634do_test shell1-3.23b.4 {
635  # too many arguments
636  catchcmd "test.db" ".stats OFF BAD"
637} {1 {Usage: .stats on|off}}
638
639# .tables ?TABLE?        List names of tables
640#                          If TABLE specified, only list tables matching
641#                          LIKE pattern TABLE.
642do_test shell1-3.24.1 {
643  catchcmd "test.db" ".tables"
644} {0 {}}
645do_test shell1-3.24.2 {
646  catchcmd "test.db" ".tables FOO"
647} {0 {}}
648do_test shell1-3.24.3 {
649  # too many arguments
650  catchcmd "test.db" ".tables FOO BAD"
651} {0 {}}
652
653# .timeout MS            Try opening locked tables for MS milliseconds
654do_test shell1-3.25.1 {
655  catchcmd "test.db" ".timeout"
656} {0 {}}
657do_test shell1-3.25.2 {
658  catchcmd "test.db" ".timeout zzz"
659  # this should be treated the same as a '0' timeout
660} {0 {}}
661do_test shell1-3.25.3 {
662  catchcmd "test.db" ".timeout 1"
663} {0 {}}
664do_test shell1-3.25.4 {
665  # too many arguments
666  catchcmd "test.db" ".timeout 1 BAD"
667} {0 {}}
668
669# .width NUM NUM ...     Set column widths for "column" mode
670do_test shell1-3.26.1 {
671  catchcmd "test.db" ".width"
672} {0 {}}
673do_test shell1-3.26.2 {
674  catchcmd "test.db" ".width xxx"
675  # this should be treated the same as a '0' width for col 1
676} {0 {}}
677do_test shell1-3.26.3 {
678  catchcmd "test.db" ".width xxx yyy"
679  # this should be treated the same as a '0' width for col 1 and 2
680} {0 {}}
681do_test shell1-3.26.4 {
682  catchcmd "test.db" ".width 1 1"
683  # this should be treated the same as a '1' width for col 1 and 2
684} {0 {}}
685do_test shell1-3.26.5 {
686  catchcmd "test.db" ".mode column\n.width 10 -10\nSELECT 'abcdefg', 123456;"
687  # this should be treated the same as a '1' width for col 1 and 2
688} {0 {abcdefg         123456}}
689do_test shell1-3.26.6 {
690  catchcmd "test.db" ".mode column\n.width -10 10\nSELECT 'abcdefg', 123456;"
691  # this should be treated the same as a '1' width for col 1 and 2
692} {0 {   abcdefg  123456    }}
693
694
695# .timer ON|OFF          Turn the CPU timer measurement on or off
696do_test shell1-3.27.1 {
697  catchcmd "test.db" ".timer"
698} {1 {Usage: .timer on|off}}
699do_test shell1-3.27.2 {
700  catchcmd "test.db" ".timer ON"
701} {0 {}}
702do_test shell1-3.27.3 {
703  catchcmd "test.db" ".timer OFF"
704} {0 {}}
705do_test shell1-3.27.4 {
706  # too many arguments
707  catchcmd "test.db" ".timer OFF BAD"
708} {1 {Usage: .timer on|off}}
709
710do_test shell1-3-28.1 {
711  catchcmd test.db \
712     ".log stdout\nSELECT coalesce(sqlite_log(123,'hello'),'456');"
713} "0 {(123) hello\n456}"
714
715do_test shell1-3-29.1 {
716  catchcmd "test.db" ".print this is a test"
717} {0 {this is a test}}
718
719# dot-command argument quoting
720do_test shell1-3-30.1 {
721  catchcmd {test.db} {.print "this\"is'a\055test" 'this\"is\\a\055test'}
722} {0 {this"is'a-test this\"is\\a\055test}}
723do_test shell1-3-31.1 {
724  catchcmd {test.db} {.print "this\nis\ta\\test" 'this\nis\ta\\test'}
725} [list 0 "this\nis\ta\\test this\\nis\\ta\\\\test"]
726
727
728# Test the output of the ".dump" command
729#
730do_test shell1-4.1 {
731  db close
732  forcedelete test.db
733  sqlite3 db test.db
734  db eval {
735    PRAGMA encoding=UTF16;
736    CREATE TABLE t1(x);
737    INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f');
738  }
739  catchcmd test.db {.dump}
740} {0 {PRAGMA foreign_keys=OFF;
741BEGIN TRANSACTION;
742CREATE TABLE t1(x);
743INSERT INTO "t1" VALUES(NULL);
744INSERT INTO "t1" VALUES('');
745INSERT INTO "t1" VALUES(1);
746INSERT INTO "t1" VALUES(2.25);
747INSERT INTO "t1" VALUES('hello');
748INSERT INTO "t1" VALUES(X'807F');
749COMMIT;}}
750
751# Test the output of ".mode insert"
752#
753do_test shell1-4.2 {
754  catchcmd test.db ".mode insert t1\nselect * from t1;"
755} {0 {INSERT INTO t1 VALUES(NULL);
756INSERT INTO t1 VALUES('');
757INSERT INTO t1 VALUES(1);
758INSERT INTO t1 VALUES(2.25);
759INSERT INTO t1 VALUES('hello');
760INSERT INTO t1 VALUES(X'807f');}}
761
762# Test the output of ".mode tcl"
763#
764do_test shell1-4.3 {
765  db close
766  forcedelete test.db
767  sqlite3 db test.db
768  db eval {
769    PRAGMA encoding=UTF8;
770    CREATE TABLE t1(x);
771    INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f');
772  }
773  catchcmd test.db ".mode tcl\nselect * from t1;"
774} {0 {""
775""
776"1"
777"2.25"
778"hello"
779"\200\177"}}
780
781# Test the output of ".mode tcl" with multiple columns
782#
783do_test shell1-4.4 {
784  db eval {
785    CREATE TABLE t2(x,y);
786    INSERT INTO t2 VALUES(null, ''), (1, 2.25), ('hello', x'807f');
787  }
788  catchcmd test.db ".mode tcl\nselect * from t2;"
789} {0 {"" ""
790"1" "2.25"
791"hello" "\200\177"}}
792
793# Test the output of ".mode tcl" with ".nullvalue"
794#
795do_test shell1-4.5 {
796  catchcmd test.db ".mode tcl\n.nullvalue NULL\nselect * from t2;"
797} {0 {"NULL" ""
798"1" "2.25"
799"hello" "\200\177"}}
800
801# Test the output of ".mode tcl" with Tcl reserved characters
802#
803do_test shell1-4.6 {
804  db eval {
805    CREATE TABLE tcl1(x);
806    INSERT INTO tcl1 VALUES('"'), ('['), (']'), ('\{'), ('\}'), (';'), ('$');
807  }
808  foreach {x y} [catchcmd test.db ".mode tcl\nselect * from tcl1;"] break
809  list $x $y [llength $y]
810} {0 {"\""
811"["
812"]"
813"\\{"
814"\\}"
815";"
816"$"} 7}
817
818finish_test
819