blob: 2fda62ee13f1ba53f605c06b020c25c15b951d21 [file] [log] [blame]
shaneha05e0c42009-11-06 03:22:54 +00001# 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#
shaneha05e0c42009-11-06 03:22:54 +000014#
15
16# Test plan:
17#
shaneh5fc25012009-11-11 04:17:07 +000018# 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.
shaneha05e0c42009-11-06 03:22:54 +000021#
drh8df91852012-04-24 12:46:05 +000022set testdir [file dirname $argv0]
23source $testdir/tester.tcl
24if {$tcl_platform(platform)=="windows"} {
25 set CLI "sqlite3.exe"
26} else {
27 set CLI "./sqlite3"
shaneha05e0c42009-11-06 03:22:54 +000028}
drh8df91852012-04-24 12:46:05 +000029if {![file executable $CLI]} {
30 finish_test
31 return
shaneha05e0c42009-11-06 03:22:54 +000032}
drh8df91852012-04-24 12:46:05 +000033db close
34forcedelete test.db test.db-journal test.db-wal
shaneha05e0c42009-11-06 03:22:54 +000035sqlite3 db test.db
36
shaneh5fc25012009-11-11 04:17:07 +000037#----------------------------------------------------------------------------
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}
drhac5649a2014-11-28 13:35:03 +000048do_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}
shaneh5fc25012009-11-11 04:17:07 +000054# error on extra options
55do_test shell1-1.1.2 {
drhac5649a2014-11-28 13:35:03 +000056 catchcmd "test.db \"select 3\" \"select 4\"" ""
57} {0 {3
584}}
shaneh5fc25012009-11-11 04:17:07 +000059# error on extra options
shanehca7dfda2009-12-17 21:07:54 +000060do_test shell1-1.1.3 {
drhac5649a2014-11-28 13:35:03 +000061 catchcmd "test.db FOO test.db BAD" ".quit"
62} {1 {Error: near "FOO": syntax error}}
shaneh5fc25012009-11-11 04:17:07 +000063
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 {
shanehca7dfda2009-12-17 21:07:54 +000076 catchcmd "-init FOO test.db" ""
shaneh5fc25012009-11-11 04:17:07 +000077} {0 {}}
78do_test shell1-1.3.2 {
drhac5649a2014-11-28 13:35:03 +000079 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}}
shaneh5fc25012009-11-11 04:17:07 +000084
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] \
drh39a30882014-02-11 16:22:18 +0000109 [regexp {Enter ".help" for usage hints} $res]
shaneh5fc25012009-11-11 04:17:07 +0000110} {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 \
drh98d312f2012-10-25 15:23:14 +0000153 [regexp {Error: missing argument to -separator} $res]
shaneh5fc25012009-11-11 04:17:07 +0000154} {1 1}
155
shaneh642d8b82010-07-28 16:05:34 +0000156# -stats print memory stats before each finalize
157do_test shell1-1.14b.1 {
158 catchcmd "-stats test.db" ""
159} {0 {}}
160
shaneh5fc25012009-11-11 04:17:07 +0000161# -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 \
drh98d312f2012-10-25 15:23:14 +0000172 [regexp {Error: missing argument to -nullvalue} $res]
shaneh5fc25012009-11-11 04:17:07 +0000173} {1 1}
174
175# -version show SQLite version
176do_test shell1-1.16.1 {
drh9fd301b2011-06-03 13:28:22 +0000177 set x [catchcmd "-version test.db" ""]
drhb24c61a2012-05-21 22:45:35 +0000178} {/3.[0-9.]+ 20\d\d-[01]\d-\d\d \d\d:\d\d:\d\d [0-9a-f]+/}
shanehe2aa9d72009-11-06 17:20:17 +0000179
shaneha05e0c42009-11-06 03:22:54 +0000180#----------------------------------------------------------------------------
shaneh5fc25012009-11-11 04:17:07 +0000181# Test cases shell1-2.*: Basic "dot" command token parsing.
shanehe2aa9d72009-11-06 17:20:17 +0000182#
183
184# check first token handling
shaneh5fc25012009-11-11 04:17:07 +0000185do_test shell1-2.1.1 {
shanehca7dfda2009-12-17 21:07:54 +0000186 catchcmd "test.db" ".foo"
shanehe2aa9d72009-11-06 17:20:17 +0000187} {1 {Error: unknown command or invalid arguments: "foo". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000188do_test shell1-2.1.2 {
shanehca7dfda2009-12-17 21:07:54 +0000189 catchcmd "test.db" ".\"foo OFF\""
shanehe2aa9d72009-11-06 17:20:17 +0000190} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000191do_test shell1-2.1.3 {
shanehca7dfda2009-12-17 21:07:54 +0000192 catchcmd "test.db" ".\'foo OFF\'"
shanehe2aa9d72009-11-06 17:20:17 +0000193} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}}
194
195# unbalanced quotes
shaneh5fc25012009-11-11 04:17:07 +0000196do_test shell1-2.2.1 {
shanehca7dfda2009-12-17 21:07:54 +0000197 catchcmd "test.db" ".\"foo OFF"
shanehe2aa9d72009-11-06 17:20:17 +0000198} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000199do_test shell1-2.2.2 {
shanehca7dfda2009-12-17 21:07:54 +0000200 catchcmd "test.db" ".\'foo OFF"
shanehe2aa9d72009-11-06 17:20:17 +0000201} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000202do_test shell1-2.2.3 {
shanehca7dfda2009-12-17 21:07:54 +0000203 catchcmd "test.db" ".explain \"OFF"
shanehe2aa9d72009-11-06 17:20:17 +0000204} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000205do_test shell1-2.2.4 {
shanehca7dfda2009-12-17 21:07:54 +0000206 catchcmd "test.db" ".explain \'OFF"
shanehe2aa9d72009-11-06 17:20:17 +0000207} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000208do_test shell1-2.2.5 {
shanehca7dfda2009-12-17 21:07:54 +0000209 catchcmd "test.db" ".mode \"insert FOO"
mistachkin636bf9f2014-07-19 20:15:16 +0000210} {1 {Error: mode should be one of: ascii column csv html insert line list tabs tcl}}
shaneh5fc25012009-11-11 04:17:07 +0000211do_test shell1-2.2.6 {
shanehca7dfda2009-12-17 21:07:54 +0000212 catchcmd "test.db" ".mode \'insert FOO"
mistachkin636bf9f2014-07-19 20:15:16 +0000213} {1 {Error: mode should be one of: ascii column csv html insert line list tabs tcl}}
shanehe2aa9d72009-11-06 17:20:17 +0000214
215# check multiple tokens, and quoted tokens
shaneh5fc25012009-11-11 04:17:07 +0000216do_test shell1-2.3.1 {
shanehca7dfda2009-12-17 21:07:54 +0000217 catchcmd "test.db" ".explain 1"
shanehe2aa9d72009-11-06 17:20:17 +0000218} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000219do_test shell1-2.3.2 {
shanehca7dfda2009-12-17 21:07:54 +0000220 catchcmd "test.db" ".explain on"
shanehe2aa9d72009-11-06 17:20:17 +0000221} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000222do_test shell1-2.3.3 {
shanehca7dfda2009-12-17 21:07:54 +0000223 catchcmd "test.db" ".explain \"1 2 3\""
drh173ba092013-01-28 18:18:26 +0000224} {1 {ERROR: Not a boolean value: "1 2 3". Assuming "no".}}
shaneh5fc25012009-11-11 04:17:07 +0000225do_test shell1-2.3.4 {
shanehca7dfda2009-12-17 21:07:54 +0000226 catchcmd "test.db" ".explain \"OFF\""
shanehe2aa9d72009-11-06 17:20:17 +0000227} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000228do_test shell1-2.3.5 {
shanehca7dfda2009-12-17 21:07:54 +0000229 catchcmd "test.db" ".\'explain\' \'OFF\'"
shanehe2aa9d72009-11-06 17:20:17 +0000230} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000231do_test shell1-2.3.6 {
shanehca7dfda2009-12-17 21:07:54 +0000232 catchcmd "test.db" ".explain \'OFF\'"
shanehe2aa9d72009-11-06 17:20:17 +0000233} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000234do_test shell1-2.3.7 {
shanehca7dfda2009-12-17 21:07:54 +0000235 catchcmd "test.db" ".\'explain\' \'OFF\'"
shanehe2aa9d72009-11-06 17:20:17 +0000236} {0 {}}
237
238# check quoted args are unquoted
shaneh5fc25012009-11-11 04:17:07 +0000239do_test shell1-2.4.1 {
shanehca7dfda2009-12-17 21:07:54 +0000240 catchcmd "test.db" ".mode FOO"
mistachkin636bf9f2014-07-19 20:15:16 +0000241} {1 {Error: mode should be one of: ascii column csv html insert line list tabs tcl}}
shaneh5fc25012009-11-11 04:17:07 +0000242do_test shell1-2.4.2 {
shanehca7dfda2009-12-17 21:07:54 +0000243 catchcmd "test.db" ".mode csv"
shanehe2aa9d72009-11-06 17:20:17 +0000244} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000245do_test shell1-2.4.2 {
shanehca7dfda2009-12-17 21:07:54 +0000246 catchcmd "test.db" ".mode \"csv\""
shanehe2aa9d72009-11-06 17:20:17 +0000247} {0 {}}
248
249
250#----------------------------------------------------------------------------
shaneh5fc25012009-11-11 04:17:07 +0000251# Test cases shell1-3.*: Basic test that "dot" command can be called.
shaneha05e0c42009-11-06 03:22:54 +0000252#
253
254# .backup ?DB? FILE Backup DB (default "main") to FILE
shaneh5fc25012009-11-11 04:17:07 +0000255do_test shell1-3.1.1 {
shanehca7dfda2009-12-17 21:07:54 +0000256 catchcmd "test.db" ".backup"
drhbc46f022013-01-23 18:53:23 +0000257} {1 {missing FILENAME argument on .backup}}
shaneh5fc25012009-11-11 04:17:07 +0000258do_test shell1-3.1.2 {
shanehca7dfda2009-12-17 21:07:54 +0000259 catchcmd "test.db" ".backup FOO"
260} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000261do_test shell1-3.1.3 {
shanehca7dfda2009-12-17 21:07:54 +0000262 catchcmd "test.db" ".backup FOO BAR"
shanehe2aa9d72009-11-06 17:20:17 +0000263} {1 {Error: unknown database FOO}}
shaneh5fc25012009-11-11 04:17:07 +0000264do_test shell1-3.1.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000265 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000266 catchcmd "test.db" ".backup FOO BAR BAD"
drhbc46f022013-01-23 18:53:23 +0000267} {1 {too many arguments to .backup}}
shaneha05e0c42009-11-06 03:22:54 +0000268
269# .bail ON|OFF Stop after hitting an error. Default OFF
shaneh5fc25012009-11-11 04:17:07 +0000270do_test shell1-3.2.1 {
shanehca7dfda2009-12-17 21:07:54 +0000271 catchcmd "test.db" ".bail"
drhc2ce0be2014-05-29 12:36:14 +0000272} {1 {Usage: .bail on|off}}
shaneh5fc25012009-11-11 04:17:07 +0000273do_test shell1-3.2.2 {
shanehca7dfda2009-12-17 21:07:54 +0000274 catchcmd "test.db" ".bail ON"
shaneha05e0c42009-11-06 03:22:54 +0000275} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000276do_test shell1-3.2.3 {
shanehca7dfda2009-12-17 21:07:54 +0000277 catchcmd "test.db" ".bail OFF"
shaneha05e0c42009-11-06 03:22:54 +0000278} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000279do_test shell1-3.2.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000280 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000281 catchcmd "test.db" ".bail OFF BAD"
drhc2ce0be2014-05-29 12:36:14 +0000282} {1 {Usage: .bail on|off}}
shaneha05e0c42009-11-06 03:22:54 +0000283
284# .databases List names and files of attached databases
shaneh5fc25012009-11-11 04:17:07 +0000285do_test shell1-3.3.1 {
drhe4d31952012-05-12 01:14:27 +0000286 catchcmd "-csv test.db" ".databases"
mistachkin86ab48f2012-05-22 19:25:51 +0000287} "/0 +.*main +[string map {/ .} [string range [get_pwd] 0 10]].*/"
shaneh5fc25012009-11-11 04:17:07 +0000288do_test shell1-3.3.2 {
drhc2ce0be2014-05-29 12:36:14 +0000289 # extra arguments ignored
shanehca7dfda2009-12-17 21:07:54 +0000290 catchcmd "test.db" ".databases BAD"
drhc2ce0be2014-05-29 12:36:14 +0000291} "/0 +.*main +[string map {/ .} [string range [get_pwd] 0 10]].*/"
shaneha05e0c42009-11-06 03:22:54 +0000292
293# .dump ?TABLE? ... Dump the database in an SQL text format
294# If TABLE specified, only dump tables matching
295# LIKE pattern TABLE.
shaneh5fc25012009-11-11 04:17:07 +0000296do_test shell1-3.4.1 {
shanehca7dfda2009-12-17 21:07:54 +0000297 set res [catchcmd "test.db" ".dump"]
shaneha05e0c42009-11-06 03:22:54 +0000298 list [regexp {BEGIN TRANSACTION;} $res] \
299 [regexp {COMMIT;} $res]
300} {1 1}
shaneh5fc25012009-11-11 04:17:07 +0000301do_test shell1-3.4.2 {
shanehca7dfda2009-12-17 21:07:54 +0000302 set res [catchcmd "test.db" ".dump FOO"]
shaneha05e0c42009-11-06 03:22:54 +0000303 list [regexp {BEGIN TRANSACTION;} $res] \
304 [regexp {COMMIT;} $res]
305} {1 1}
shaneh5fc25012009-11-11 04:17:07 +0000306do_test shell1-3.4.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000307 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000308 catchcmd "test.db" ".dump FOO BAD"
drhc2ce0be2014-05-29 12:36:14 +0000309} {1 {Usage: .dump ?LIKE-PATTERN?}}
shaneha05e0c42009-11-06 03:22:54 +0000310
311# .echo ON|OFF Turn command echo on or off
shaneh5fc25012009-11-11 04:17:07 +0000312do_test shell1-3.5.1 {
shanehca7dfda2009-12-17 21:07:54 +0000313 catchcmd "test.db" ".echo"
drhc2ce0be2014-05-29 12:36:14 +0000314} {1 {Usage: .echo on|off}}
shaneh5fc25012009-11-11 04:17:07 +0000315do_test shell1-3.5.2 {
shanehca7dfda2009-12-17 21:07:54 +0000316 catchcmd "test.db" ".echo ON"
shaneha05e0c42009-11-06 03:22:54 +0000317} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000318do_test shell1-3.5.3 {
shanehca7dfda2009-12-17 21:07:54 +0000319 catchcmd "test.db" ".echo OFF"
shaneha05e0c42009-11-06 03:22:54 +0000320} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000321do_test shell1-3.5.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000322 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000323 catchcmd "test.db" ".echo OFF BAD"
drhc2ce0be2014-05-29 12:36:14 +0000324} {1 {Usage: .echo on|off}}
shaneha05e0c42009-11-06 03:22:54 +0000325
326# .exit Exit this program
shaneh5fc25012009-11-11 04:17:07 +0000327do_test shell1-3.6.1 {
shanehca7dfda2009-12-17 21:07:54 +0000328 catchcmd "test.db" ".exit"
shaneha05e0c42009-11-06 03:22:54 +0000329} {0 {}}
330
331# .explain ON|OFF Turn output mode suitable for EXPLAIN on or off.
shaneh5fc25012009-11-11 04:17:07 +0000332do_test shell1-3.7.1 {
shanehca7dfda2009-12-17 21:07:54 +0000333 catchcmd "test.db" ".explain"
shanehe2aa9d72009-11-06 17:20:17 +0000334 # explain is the exception to the booleans. without an option, it turns it on.
335} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000336do_test shell1-3.7.2 {
shanehca7dfda2009-12-17 21:07:54 +0000337 catchcmd "test.db" ".explain ON"
shaneha05e0c42009-11-06 03:22:54 +0000338} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000339do_test shell1-3.7.3 {
shanehca7dfda2009-12-17 21:07:54 +0000340 catchcmd "test.db" ".explain OFF"
shaneha05e0c42009-11-06 03:22:54 +0000341} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000342do_test shell1-3.7.4 {
drhc2ce0be2014-05-29 12:36:14 +0000343 # extra arguments ignored
shanehca7dfda2009-12-17 21:07:54 +0000344 catchcmd "test.db" ".explain OFF BAD"
drhc2ce0be2014-05-29 12:36:14 +0000345} {0 {}}
shaneha05e0c42009-11-06 03:22:54 +0000346
shaneha05e0c42009-11-06 03:22:54 +0000347
348# .header(s) ON|OFF Turn display of headers on or off
shaneh5fc25012009-11-11 04:17:07 +0000349do_test shell1-3.9.1 {
shanehca7dfda2009-12-17 21:07:54 +0000350 catchcmd "test.db" ".header"
drhc2ce0be2014-05-29 12:36:14 +0000351} {1 {Usage: .headers on|off}}
shaneh5fc25012009-11-11 04:17:07 +0000352do_test shell1-3.9.2 {
shanehca7dfda2009-12-17 21:07:54 +0000353 catchcmd "test.db" ".header ON"
shaneha05e0c42009-11-06 03:22:54 +0000354} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000355do_test shell1-3.9.3 {
shanehca7dfda2009-12-17 21:07:54 +0000356 catchcmd "test.db" ".header OFF"
shaneha05e0c42009-11-06 03:22:54 +0000357} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000358do_test shell1-3.9.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000359 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000360 catchcmd "test.db" ".header OFF BAD"
drhc2ce0be2014-05-29 12:36:14 +0000361} {1 {Usage: .headers on|off}}
shanehe2aa9d72009-11-06 17:20:17 +0000362
shaneh5fc25012009-11-11 04:17:07 +0000363do_test shell1-3.9.5 {
shanehca7dfda2009-12-17 21:07:54 +0000364 catchcmd "test.db" ".headers"
drhc2ce0be2014-05-29 12:36:14 +0000365} {1 {Usage: .headers on|off}}
shaneh5fc25012009-11-11 04:17:07 +0000366do_test shell1-3.9.6 {
shanehca7dfda2009-12-17 21:07:54 +0000367 catchcmd "test.db" ".headers ON"
shaneha05e0c42009-11-06 03:22:54 +0000368} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000369do_test shell1-3.9.7 {
shanehca7dfda2009-12-17 21:07:54 +0000370 catchcmd "test.db" ".headers OFF"
shaneha05e0c42009-11-06 03:22:54 +0000371} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000372do_test shell1-3.9.8 {
shanehe2aa9d72009-11-06 17:20:17 +0000373 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000374 catchcmd "test.db" ".headers OFF BAD"
drhc2ce0be2014-05-29 12:36:14 +0000375} {1 {Usage: .headers on|off}}
shaneha05e0c42009-11-06 03:22:54 +0000376
377# .help Show this message
shaneh5fc25012009-11-11 04:17:07 +0000378do_test shell1-3.10.1 {
shanehca7dfda2009-12-17 21:07:54 +0000379 set res [catchcmd "test.db" ".help"]
shaneha05e0c42009-11-06 03:22:54 +0000380 # 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}
shaneh5fc25012009-11-11 04:17:07 +0000385do_test shell1-3.10.2 {
shanehe2aa9d72009-11-06 17:20:17 +0000386 # we allow .help to take extra args (it is help after all)
shanehca7dfda2009-12-17 21:07:54 +0000387 set res [catchcmd "test.db" ".help BAD"]
shanehe2aa9d72009-11-06 17:20:17 +0000388 # 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}
shaneha05e0c42009-11-06 03:22:54 +0000393
394# .import FILE TABLE Import data from FILE into TABLE
shaneh5fc25012009-11-11 04:17:07 +0000395do_test shell1-3.11.1 {
shanehca7dfda2009-12-17 21:07:54 +0000396 catchcmd "test.db" ".import"
drhc2ce0be2014-05-29 12:36:14 +0000397} {1 {Usage: .import FILE TABLE}}
shaneh5fc25012009-11-11 04:17:07 +0000398do_test shell1-3.11.2 {
shanehca7dfda2009-12-17 21:07:54 +0000399 catchcmd "test.db" ".import FOO"
drhc2ce0be2014-05-29 12:36:14 +0000400} {1 {Usage: .import FILE TABLE}}
drhdb95f682013-06-26 22:46:00 +0000401#do_test shell1-3.11.2 {
402# catchcmd "test.db" ".import FOO BAR"
403#} {1 {Error: no such table: BAR}}
shaneh5fc25012009-11-11 04:17:07 +0000404do_test shell1-3.11.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000405 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000406 catchcmd "test.db" ".import FOO BAR BAD"
drhc2ce0be2014-05-29 12:36:14 +0000407} {1 {Usage: .import FILE TABLE}}
shaneha05e0c42009-11-06 03:22:54 +0000408
drh0e55db12015-02-06 14:51:13 +0000409# .indexes ?TABLE? Show names of all indexes
410# If TABLE specified, only show indexes for tables
shaneha05e0c42009-11-06 03:22:54 +0000411# matching LIKE pattern TABLE.
shaneh5fc25012009-11-11 04:17:07 +0000412do_test shell1-3.12.1 {
drh0e55db12015-02-06 14:51:13 +0000413 catchcmd "test.db" ".indexes"
shaneha05e0c42009-11-06 03:22:54 +0000414} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000415do_test shell1-3.12.2 {
drh0e55db12015-02-06 14:51:13 +0000416 catchcmd "test.db" ".indexes FOO"
417} {0 {}}
418do_test shell1-3.12.2-legacy {
shanehca7dfda2009-12-17 21:07:54 +0000419 catchcmd "test.db" ".indices FOO"
shaneha05e0c42009-11-06 03:22:54 +0000420} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000421do_test shell1-3.12.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000422 # too many arguments
drh0e55db12015-02-06 14:51:13 +0000423 catchcmd "test.db" ".indexes FOO BAD"
424} {1 {Usage: .indexes ?LIKE-PATTERN?}}
shaneha05e0c42009-11-06 03:22:54 +0000425
426# .mode MODE ?TABLE? Set output mode where MODE is one of:
mistachkine0d68852014-12-11 03:12:33 +0000427# ascii Columns/rows delimited by 0x1F and 0x1E
shaneha05e0c42009-11-06 03:22:54 +0000428# csv Comma-separated values
429# column Left-aligned columns. (See .width)
430# html HTML <table> code
431# insert SQL insert statements for TABLE
432# line One value per line
mistachkine0d68852014-12-11 03:12:33 +0000433# list Values delimited by .separator strings
shaneha05e0c42009-11-06 03:22:54 +0000434# tabs Tab-separated values
435# tcl TCL list elements
shaneh5fc25012009-11-11 04:17:07 +0000436do_test shell1-3.13.1 {
shanehca7dfda2009-12-17 21:07:54 +0000437 catchcmd "test.db" ".mode"
mistachkin636bf9f2014-07-19 20:15:16 +0000438} {1 {Error: mode should be one of: ascii column csv html insert line list tabs tcl}}
shaneh5fc25012009-11-11 04:17:07 +0000439do_test shell1-3.13.2 {
shanehca7dfda2009-12-17 21:07:54 +0000440 catchcmd "test.db" ".mode FOO"
mistachkin636bf9f2014-07-19 20:15:16 +0000441} {1 {Error: mode should be one of: ascii column csv html insert line list tabs tcl}}
shaneh5fc25012009-11-11 04:17:07 +0000442do_test shell1-3.13.3 {
shanehca7dfda2009-12-17 21:07:54 +0000443 catchcmd "test.db" ".mode csv"
shaneha05e0c42009-11-06 03:22:54 +0000444} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000445do_test shell1-3.13.4 {
shanehca7dfda2009-12-17 21:07:54 +0000446 catchcmd "test.db" ".mode column"
shaneha05e0c42009-11-06 03:22:54 +0000447} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000448do_test shell1-3.13.5 {
shanehca7dfda2009-12-17 21:07:54 +0000449 catchcmd "test.db" ".mode html"
shaneha05e0c42009-11-06 03:22:54 +0000450} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000451do_test shell1-3.13.6 {
shanehca7dfda2009-12-17 21:07:54 +0000452 catchcmd "test.db" ".mode insert"
shaneha05e0c42009-11-06 03:22:54 +0000453} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000454do_test shell1-3.13.7 {
shanehca7dfda2009-12-17 21:07:54 +0000455 catchcmd "test.db" ".mode line"
shaneha05e0c42009-11-06 03:22:54 +0000456} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000457do_test shell1-3.13.8 {
shanehca7dfda2009-12-17 21:07:54 +0000458 catchcmd "test.db" ".mode list"
shaneha05e0c42009-11-06 03:22:54 +0000459} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000460do_test shell1-3.13.9 {
shanehca7dfda2009-12-17 21:07:54 +0000461 catchcmd "test.db" ".mode tabs"
shaneha05e0c42009-11-06 03:22:54 +0000462} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000463do_test shell1-3.13.10 {
shanehca7dfda2009-12-17 21:07:54 +0000464 catchcmd "test.db" ".mode tcl"
shaneha05e0c42009-11-06 03:22:54 +0000465} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000466do_test shell1-3.13.11 {
drhc2ce0be2014-05-29 12:36:14 +0000467 # extra arguments ignored
shanehca7dfda2009-12-17 21:07:54 +0000468 catchcmd "test.db" ".mode tcl BAD"
drhc2ce0be2014-05-29 12:36:14 +0000469} {0 {}}
shanehe2aa9d72009-11-06 17:20:17 +0000470
471# don't allow partial mode type matches
shaneh5fc25012009-11-11 04:17:07 +0000472do_test shell1-3.13.12 {
shanehca7dfda2009-12-17 21:07:54 +0000473 catchcmd "test.db" ".mode l"
mistachkin636bf9f2014-07-19 20:15:16 +0000474} {1 {Error: mode should be one of: ascii column csv html insert line list tabs tcl}}
shaneh5fc25012009-11-11 04:17:07 +0000475do_test shell1-3.13.13 {
shanehca7dfda2009-12-17 21:07:54 +0000476 catchcmd "test.db" ".mode li"
mistachkin636bf9f2014-07-19 20:15:16 +0000477} {1 {Error: mode should be one of: ascii column csv html insert line list tabs tcl}}
shaneh5fc25012009-11-11 04:17:07 +0000478do_test shell1-3.13.14 {
shanehca7dfda2009-12-17 21:07:54 +0000479 catchcmd "test.db" ".mode lin"
drhc2ce0be2014-05-29 12:36:14 +0000480} {0 {}}
shaneha05e0c42009-11-06 03:22:54 +0000481
482# .nullvalue STRING Print STRING in place of NULL values
shaneh5fc25012009-11-11 04:17:07 +0000483do_test shell1-3.14.1 {
shanehca7dfda2009-12-17 21:07:54 +0000484 catchcmd "test.db" ".nullvalue"
drhc2ce0be2014-05-29 12:36:14 +0000485} {1 {Usage: .nullvalue STRING}}
shaneh5fc25012009-11-11 04:17:07 +0000486do_test shell1-3.14.2 {
shanehca7dfda2009-12-17 21:07:54 +0000487 catchcmd "test.db" ".nullvalue FOO"
shaneha05e0c42009-11-06 03:22:54 +0000488} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000489do_test shell1-3.14.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000490 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000491 catchcmd "test.db" ".nullvalue FOO BAD"
drhc2ce0be2014-05-29 12:36:14 +0000492} {1 {Usage: .nullvalue STRING}}
shaneha05e0c42009-11-06 03:22:54 +0000493
494# .output FILENAME Send output to FILENAME
shaneh5fc25012009-11-11 04:17:07 +0000495do_test shell1-3.15.1 {
shanehca7dfda2009-12-17 21:07:54 +0000496 catchcmd "test.db" ".output"
drhc2ce0be2014-05-29 12:36:14 +0000497} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000498do_test shell1-3.15.2 {
shanehca7dfda2009-12-17 21:07:54 +0000499 catchcmd "test.db" ".output FOO"
shaneha05e0c42009-11-06 03:22:54 +0000500} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000501do_test shell1-3.15.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000502 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000503 catchcmd "test.db" ".output FOO BAD"
drhc2ce0be2014-05-29 12:36:14 +0000504} {1 {Usage: .output FILE}}
shaneha05e0c42009-11-06 03:22:54 +0000505
506# .output stdout Send output to the screen
shaneh5fc25012009-11-11 04:17:07 +0000507do_test shell1-3.16.1 {
shanehca7dfda2009-12-17 21:07:54 +0000508 catchcmd "test.db" ".output stdout"
shaneha05e0c42009-11-06 03:22:54 +0000509} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000510do_test shell1-3.16.2 {
shanehe2aa9d72009-11-06 17:20:17 +0000511 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000512 catchcmd "test.db" ".output stdout BAD"
drhc2ce0be2014-05-29 12:36:14 +0000513} {1 {Usage: .output FILE}}
shaneha05e0c42009-11-06 03:22:54 +0000514
515# .prompt MAIN CONTINUE Replace the standard prompts
shaneh5fc25012009-11-11 04:17:07 +0000516do_test shell1-3.17.1 {
shanehca7dfda2009-12-17 21:07:54 +0000517 catchcmd "test.db" ".prompt"
drhc2ce0be2014-05-29 12:36:14 +0000518} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000519do_test shell1-3.17.2 {
shanehca7dfda2009-12-17 21:07:54 +0000520 catchcmd "test.db" ".prompt FOO"
shaneha05e0c42009-11-06 03:22:54 +0000521} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000522do_test shell1-3.17.3 {
shanehca7dfda2009-12-17 21:07:54 +0000523 catchcmd "test.db" ".prompt FOO BAR"
shaneha05e0c42009-11-06 03:22:54 +0000524} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000525do_test shell1-3.17.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000526 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000527 catchcmd "test.db" ".prompt FOO BAR BAD"
drhc2ce0be2014-05-29 12:36:14 +0000528} {0 {}}
shaneha05e0c42009-11-06 03:22:54 +0000529
530# .quit Exit this program
shaneh5fc25012009-11-11 04:17:07 +0000531do_test shell1-3.18.1 {
shanehca7dfda2009-12-17 21:07:54 +0000532 catchcmd "test.db" ".quit"
shaneha05e0c42009-11-06 03:22:54 +0000533} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000534do_test shell1-3.18.2 {
shanehe2aa9d72009-11-06 17:20:17 +0000535 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000536 catchcmd "test.db" ".quit BAD"
drhc2ce0be2014-05-29 12:36:14 +0000537} {0 {}}
shaneha05e0c42009-11-06 03:22:54 +0000538
539# .read FILENAME Execute SQL in FILENAME
shaneh5fc25012009-11-11 04:17:07 +0000540do_test shell1-3.19.1 {
shanehca7dfda2009-12-17 21:07:54 +0000541 catchcmd "test.db" ".read"
drhc2ce0be2014-05-29 12:36:14 +0000542} {1 {Usage: .read FILE}}
shaneh5fc25012009-11-11 04:17:07 +0000543do_test shell1-3.19.2 {
mistachkin9ac99312013-09-13 23:26:47 +0000544 forcedelete FOO
shanehca7dfda2009-12-17 21:07:54 +0000545 catchcmd "test.db" ".read FOO"
shaneha05e0c42009-11-06 03:22:54 +0000546} {1 {Error: cannot open "FOO"}}
shaneh5fc25012009-11-11 04:17:07 +0000547do_test shell1-3.19.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000548 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000549 catchcmd "test.db" ".read FOO BAD"
drhc2ce0be2014-05-29 12:36:14 +0000550} {1 {Usage: .read FILE}}
shaneha05e0c42009-11-06 03:22:54 +0000551
552# .restore ?DB? FILE Restore content of DB (default "main") from FILE
shaneh5fc25012009-11-11 04:17:07 +0000553do_test shell1-3.20.1 {
shanehca7dfda2009-12-17 21:07:54 +0000554 catchcmd "test.db" ".restore"
drhc2ce0be2014-05-29 12:36:14 +0000555} {1 {Usage: .restore ?DB? FILE}}
shaneh5fc25012009-11-11 04:17:07 +0000556do_test shell1-3.20.2 {
shanehca7dfda2009-12-17 21:07:54 +0000557 catchcmd "test.db" ".restore FOO"
558} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000559do_test shell1-3.20.3 {
shanehca7dfda2009-12-17 21:07:54 +0000560 catchcmd "test.db" ".restore FOO BAR"
shanehe2aa9d72009-11-06 17:20:17 +0000561} {1 {Error: unknown database FOO}}
shaneh5fc25012009-11-11 04:17:07 +0000562do_test shell1-3.20.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000563 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000564 catchcmd "test.db" ".restore FOO BAR BAD"
drhc2ce0be2014-05-29 12:36:14 +0000565} {1 {Usage: .restore ?DB? FILE}}
shaneha05e0c42009-11-06 03:22:54 +0000566
567# .schema ?TABLE? Show the CREATE statements
568# If TABLE specified, only show tables matching
569# LIKE pattern TABLE.
shaneh5fc25012009-11-11 04:17:07 +0000570do_test shell1-3.21.1 {
shanehca7dfda2009-12-17 21:07:54 +0000571 catchcmd "test.db" ".schema"
shaneha05e0c42009-11-06 03:22:54 +0000572} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000573do_test shell1-3.21.2 {
shanehca7dfda2009-12-17 21:07:54 +0000574 catchcmd "test.db" ".schema FOO"
shaneha05e0c42009-11-06 03:22:54 +0000575} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000576do_test shell1-3.21.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000577 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000578 catchcmd "test.db" ".schema FOO BAD"
drhc2ce0be2014-05-29 12:36:14 +0000579} {1 {Usage: .schema ?LIKE-PATTERN?}}
shaneha05e0c42009-11-06 03:22:54 +0000580
drhac43e982012-05-21 03:15:06 +0000581do_test shell1-3.21.4 {
582 catchcmd "test.db" {
583 CREATE TABLE t1(x);
584 CREATE VIEW v2 AS SELECT x+1 AS y FROM t1;
585 CREATE VIEW v1 AS SELECT y+1 FROM v2;
586 }
587 catchcmd "test.db" ".schema"
588} {0 {CREATE TABLE t1(x);
589CREATE VIEW v2 AS SELECT x+1 AS y FROM t1;
590CREATE VIEW v1 AS SELECT y+1 FROM v2;}}
591db eval {DROP VIEW v1; DROP VIEW v2; DROP TABLE t1;}
592
mistachkin636bf9f2014-07-19 20:15:16 +0000593# .separator STRING Change column separator used by output and .import
shaneh5fc25012009-11-11 04:17:07 +0000594do_test shell1-3.22.1 {
shanehca7dfda2009-12-17 21:07:54 +0000595 catchcmd "test.db" ".separator"
mistachkine0d68852014-12-11 03:12:33 +0000596} {1 {Usage: .separator COL ?ROW?}}
shaneh5fc25012009-11-11 04:17:07 +0000597do_test shell1-3.22.2 {
shanehca7dfda2009-12-17 21:07:54 +0000598 catchcmd "test.db" ".separator FOO"
shaneha05e0c42009-11-06 03:22:54 +0000599} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000600do_test shell1-3.22.3 {
drh6976c212014-07-24 12:09:47 +0000601 catchcmd "test.db" ".separator ABC XYZ"
602} {0 {}}
603do_test shell1-3.22.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000604 # too many arguments
drh6976c212014-07-24 12:09:47 +0000605 catchcmd "test.db" ".separator FOO BAD BAD2"
mistachkine0d68852014-12-11 03:12:33 +0000606} {1 {Usage: .separator COL ?ROW?}}
shaneha05e0c42009-11-06 03:22:54 +0000607
608# .show Show the current values for various settings
shaneh5fc25012009-11-11 04:17:07 +0000609do_test shell1-3.23.1 {
shanehca7dfda2009-12-17 21:07:54 +0000610 set res [catchcmd "test.db" ".show"]
shaneha05e0c42009-11-06 03:22:54 +0000611 list [regexp {echo:} $res] \
612 [regexp {explain:} $res] \
613 [regexp {headers:} $res] \
614 [regexp {mode:} $res] \
615 [regexp {nullvalue:} $res] \
616 [regexp {output:} $res] \
mistachkin636bf9f2014-07-19 20:15:16 +0000617 [regexp {colseparator:} $res] \
618 [regexp {rowseparator:} $res] \
shaneh642d8b82010-07-28 16:05:34 +0000619 [regexp {stats:} $res] \
shaneha05e0c42009-11-06 03:22:54 +0000620 [regexp {width:} $res]
mistachkine0d68852014-12-11 03:12:33 +0000621} {1 1 1 1 1 1 1 1 1 1}
shaneh5fc25012009-11-11 04:17:07 +0000622do_test shell1-3.23.2 {
shanehe2aa9d72009-11-06 17:20:17 +0000623 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000624 catchcmd "test.db" ".show BAD"
drhc2ce0be2014-05-29 12:36:14 +0000625} {1 {Usage: .show}}
shaneha05e0c42009-11-06 03:22:54 +0000626
shaneh642d8b82010-07-28 16:05:34 +0000627# .stats ON|OFF Turn stats on or off
628do_test shell1-3.23b.1 {
629 catchcmd "test.db" ".stats"
drhc2ce0be2014-05-29 12:36:14 +0000630} {1 {Usage: .stats on|off}}
shaneh642d8b82010-07-28 16:05:34 +0000631do_test shell1-3.23b.2 {
632 catchcmd "test.db" ".stats ON"
633} {0 {}}
634do_test shell1-3.23b.3 {
635 catchcmd "test.db" ".stats OFF"
636} {0 {}}
637do_test shell1-3.23b.4 {
638 # too many arguments
639 catchcmd "test.db" ".stats OFF BAD"
drhc2ce0be2014-05-29 12:36:14 +0000640} {1 {Usage: .stats on|off}}
shaneh642d8b82010-07-28 16:05:34 +0000641
shaneha05e0c42009-11-06 03:22:54 +0000642# .tables ?TABLE? List names of tables
643# If TABLE specified, only list tables matching
644# LIKE pattern TABLE.
shaneh5fc25012009-11-11 04:17:07 +0000645do_test shell1-3.24.1 {
shanehca7dfda2009-12-17 21:07:54 +0000646 catchcmd "test.db" ".tables"
shaneha05e0c42009-11-06 03:22:54 +0000647} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000648do_test shell1-3.24.2 {
shanehca7dfda2009-12-17 21:07:54 +0000649 catchcmd "test.db" ".tables FOO"
shaneha05e0c42009-11-06 03:22:54 +0000650} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000651do_test shell1-3.24.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000652 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000653 catchcmd "test.db" ".tables FOO BAD"
drhc2ce0be2014-05-29 12:36:14 +0000654} {0 {}}
shaneha05e0c42009-11-06 03:22:54 +0000655
656# .timeout MS Try opening locked tables for MS milliseconds
shaneh5fc25012009-11-11 04:17:07 +0000657do_test shell1-3.25.1 {
shanehca7dfda2009-12-17 21:07:54 +0000658 catchcmd "test.db" ".timeout"
drhc2ce0be2014-05-29 12:36:14 +0000659} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000660do_test shell1-3.25.2 {
shanehca7dfda2009-12-17 21:07:54 +0000661 catchcmd "test.db" ".timeout zzz"
shanehe2aa9d72009-11-06 17:20:17 +0000662 # this should be treated the same as a '0' timeout
shaneha05e0c42009-11-06 03:22:54 +0000663} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000664do_test shell1-3.25.3 {
shanehca7dfda2009-12-17 21:07:54 +0000665 catchcmd "test.db" ".timeout 1"
shaneha05e0c42009-11-06 03:22:54 +0000666} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000667do_test shell1-3.25.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000668 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000669 catchcmd "test.db" ".timeout 1 BAD"
drhc2ce0be2014-05-29 12:36:14 +0000670} {0 {}}
shaneha05e0c42009-11-06 03:22:54 +0000671
672# .width NUM NUM ... Set column widths for "column" mode
shaneh5fc25012009-11-11 04:17:07 +0000673do_test shell1-3.26.1 {
shanehca7dfda2009-12-17 21:07:54 +0000674 catchcmd "test.db" ".width"
drhc2ce0be2014-05-29 12:36:14 +0000675} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000676do_test shell1-3.26.2 {
shanehca7dfda2009-12-17 21:07:54 +0000677 catchcmd "test.db" ".width xxx"
shanehe2aa9d72009-11-06 17:20:17 +0000678 # this should be treated the same as a '0' width for col 1
shaneha05e0c42009-11-06 03:22:54 +0000679} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000680do_test shell1-3.26.3 {
shanehca7dfda2009-12-17 21:07:54 +0000681 catchcmd "test.db" ".width xxx yyy"
shanehe2aa9d72009-11-06 17:20:17 +0000682 # this should be treated the same as a '0' width for col 1 and 2
shaneha05e0c42009-11-06 03:22:54 +0000683} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000684do_test shell1-3.26.4 {
shanehca7dfda2009-12-17 21:07:54 +0000685 catchcmd "test.db" ".width 1 1"
shanehe2aa9d72009-11-06 17:20:17 +0000686 # this should be treated the same as a '1' width for col 1 and 2
shaneha05e0c42009-11-06 03:22:54 +0000687} {0 {}}
drh078b1fd2012-09-21 13:40:02 +0000688do_test shell1-3.26.5 {
689 catchcmd "test.db" ".mode column\n.width 10 -10\nSELECT 'abcdefg', 123456;"
690 # this should be treated the same as a '1' width for col 1 and 2
691} {0 {abcdefg 123456}}
692do_test shell1-3.26.6 {
693 catchcmd "test.db" ".mode column\n.width -10 10\nSELECT 'abcdefg', 123456;"
694 # this should be treated the same as a '1' width for col 1 and 2
695} {0 { abcdefg 123456 }}
696
shaneha05e0c42009-11-06 03:22:54 +0000697
698# .timer ON|OFF Turn the CPU timer measurement on or off
shaneh5fc25012009-11-11 04:17:07 +0000699do_test shell1-3.27.1 {
shanehca7dfda2009-12-17 21:07:54 +0000700 catchcmd "test.db" ".timer"
drhc2ce0be2014-05-29 12:36:14 +0000701} {1 {Usage: .timer on|off}}
shaneh5fc25012009-11-11 04:17:07 +0000702do_test shell1-3.27.2 {
shanehca7dfda2009-12-17 21:07:54 +0000703 catchcmd "test.db" ".timer ON"
shaneha05e0c42009-11-06 03:22:54 +0000704} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000705do_test shell1-3.27.3 {
shanehca7dfda2009-12-17 21:07:54 +0000706 catchcmd "test.db" ".timer OFF"
shaneha05e0c42009-11-06 03:22:54 +0000707} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000708do_test shell1-3.27.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000709 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000710 catchcmd "test.db" ".timer OFF BAD"
drhc2ce0be2014-05-29 12:36:14 +0000711} {1 {Usage: .timer on|off}}
shaneha05e0c42009-11-06 03:22:54 +0000712
drh53a9d152011-04-25 18:20:04 +0000713do_test shell1-3-28.1 {
714 catchcmd test.db \
715 ".log stdout\nSELECT coalesce(sqlite_log(123,'hello'),'456');"
716} "0 {(123) hello\n456}"
717
drh078b1fd2012-09-21 13:40:02 +0000718do_test shell1-3-29.1 {
719 catchcmd "test.db" ".print this is a test"
720} {0 {this is a test}}
721
drh4c56b992013-06-27 13:26:55 +0000722# dot-command argument quoting
723do_test shell1-3-30.1 {
724 catchcmd {test.db} {.print "this\"is'a\055test" 'this\"is\\a\055test'}
725} {0 {this"is'a-test this\"is\\a\055test}}
726do_test shell1-3-31.1 {
727 catchcmd {test.db} {.print "this\nis\ta\\test" 'this\nis\ta\\test'}
728} [list 0 "this\nis\ta\\test this\\nis\\ta\\\\test"]
729
730
drh5128e852012-04-24 13:14:49 +0000731# Test the output of the ".dump" command
732#
733do_test shell1-4.1 {
drh55a1b302013-09-04 16:08:50 +0000734 db close
735 forcedelete test.db
736 sqlite3 db test.db
drh5128e852012-04-24 13:14:49 +0000737 db eval {
drh55a1b302013-09-04 16:08:50 +0000738 PRAGMA encoding=UTF16;
drh5128e852012-04-24 13:14:49 +0000739 CREATE TABLE t1(x);
mistachkin585dcb22012-12-04 00:23:43 +0000740 INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f');
mistachkin151c75a2015-04-07 21:16:40 +0000741 CREATE TABLE t3(x,y);
742 INSERT INTO t3 VALUES(1,null), (2,''), (3,1),
743 (4,2.25), (5,'hello'), (6,x'807f');
drh5128e852012-04-24 13:14:49 +0000744 }
745 catchcmd test.db {.dump}
746} {0 {PRAGMA foreign_keys=OFF;
747BEGIN TRANSACTION;
748CREATE TABLE t1(x);
749INSERT INTO "t1" VALUES(NULL);
mistachkin585dcb22012-12-04 00:23:43 +0000750INSERT INTO "t1" VALUES('');
drh5128e852012-04-24 13:14:49 +0000751INSERT INTO "t1" VALUES(1);
752INSERT INTO "t1" VALUES(2.25);
753INSERT INTO "t1" VALUES('hello');
754INSERT INTO "t1" VALUES(X'807F');
mistachkin151c75a2015-04-07 21:16:40 +0000755CREATE TABLE t3(x,y);
756INSERT INTO "t3" VALUES(1,NULL);
757INSERT INTO "t3" VALUES(2,'');
758INSERT INTO "t3" VALUES(3,1);
759INSERT INTO "t3" VALUES(4,2.25);
760INSERT INTO "t3" VALUES(5,'hello');
761INSERT INTO "t3" VALUES(6,X'807F');
drh5128e852012-04-24 13:14:49 +0000762COMMIT;}}
763
764# Test the output of ".mode insert"
765#
mistachkin151c75a2015-04-07 21:16:40 +0000766do_test shell1-4.2.1 {
drh5128e852012-04-24 13:14:49 +0000767 catchcmd test.db ".mode insert t1\nselect * from t1;"
768} {0 {INSERT INTO t1 VALUES(NULL);
mistachkin585dcb22012-12-04 00:23:43 +0000769INSERT INTO t1 VALUES('');
drh5128e852012-04-24 13:14:49 +0000770INSERT INTO t1 VALUES(1);
771INSERT INTO t1 VALUES(2.25);
772INSERT INTO t1 VALUES('hello');
773INSERT INTO t1 VALUES(X'807f');}}
774
mistachkin151c75a2015-04-07 21:16:40 +0000775# Test the output of ".mode insert" with headers
776#
777do_test shell1-4.2.2 {
778 catchcmd test.db ".mode insert t1\n.headers on\nselect * from t1;"
779} {0 {INSERT INTO t1(x) VALUES(NULL);
780INSERT INTO t1(x) VALUES('');
781INSERT INTO t1(x) VALUES(1);
782INSERT INTO t1(x) VALUES(2.25);
783INSERT INTO t1(x) VALUES('hello');
784INSERT INTO t1(x) VALUES(X'807f');}}
785
786# Test the output of ".mode insert"
787#
788do_test shell1-4.2.3 {
789 catchcmd test.db ".mode insert t3\nselect * from t3;"
790} {0 {INSERT INTO t3 VALUES(1,NULL);
791INSERT INTO t3 VALUES(2,'');
792INSERT INTO t3 VALUES(3,1);
793INSERT INTO t3 VALUES(4,2.25);
794INSERT INTO t3 VALUES(5,'hello');
795INSERT INTO t3 VALUES(6,X'807f');}}
796
797# Test the output of ".mode insert" with headers
798#
mistachkincc445402015-04-07 21:17:53 +0000799do_test shell1-4.2.4 {
mistachkin151c75a2015-04-07 21:16:40 +0000800 catchcmd test.db ".mode insert t3\n.headers on\nselect * from t3;"
801} {0 {INSERT INTO t3(x,y) VALUES(1,NULL);
802INSERT INTO t3(x,y) VALUES(2,'');
803INSERT INTO t3(x,y) VALUES(3,1);
804INSERT INTO t3(x,y) VALUES(4,2.25);
805INSERT INTO t3(x,y) VALUES(5,'hello');
806INSERT INTO t3(x,y) VALUES(6,X'807f');}}
807
mistachkin585dcb22012-12-04 00:23:43 +0000808# Test the output of ".mode tcl"
809#
810do_test shell1-4.3 {
drh55a1b302013-09-04 16:08:50 +0000811 db close
812 forcedelete test.db
813 sqlite3 db test.db
814 db eval {
815 PRAGMA encoding=UTF8;
816 CREATE TABLE t1(x);
817 INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f');
818 }
mistachkin585dcb22012-12-04 00:23:43 +0000819 catchcmd test.db ".mode tcl\nselect * from t1;"
820} {0 {""
821""
822"1"
823"2.25"
824"hello"
825"\200\177"}}
826
827# Test the output of ".mode tcl" with multiple columns
828#
829do_test shell1-4.4 {
830 db eval {
831 CREATE TABLE t2(x,y);
832 INSERT INTO t2 VALUES(null, ''), (1, 2.25), ('hello', x'807f');
833 }
834 catchcmd test.db ".mode tcl\nselect * from t2;"
835} {0 {"" ""
836"1" "2.25"
837"hello" "\200\177"}}
838
839# Test the output of ".mode tcl" with ".nullvalue"
840#
841do_test shell1-4.5 {
842 catchcmd test.db ".mode tcl\n.nullvalue NULL\nselect * from t2;"
843} {0 {"NULL" ""
844"1" "2.25"
845"hello" "\200\177"}}
846
847# Test the output of ".mode tcl" with Tcl reserved characters
848#
849do_test shell1-4.6 {
850 db eval {
851 CREATE TABLE tcl1(x);
852 INSERT INTO tcl1 VALUES('"'), ('['), (']'), ('\{'), ('\}'), (';'), ('$');
853 }
854 foreach {x y} [catchcmd test.db ".mode tcl\nselect * from tcl1;"] break
855 list $x $y [llength $y]
856} {0 {"\""
857"["
858"]"
859"\\{"
860"\\}"
861";"
862"$"} 7}
drh5128e852012-04-24 13:14:49 +0000863
mistachkinf21979d2015-01-18 05:35:01 +0000864# Test using arbitrary byte data with the shell via standard input/output.
865#
866do_test shell1-5.0 {
867 #
868 # NOTE: Skip NUL byte because it appears to be incompatible with command
869 # shell argument parsing.
870 #
871 for {set i 1} {$i < 256} {incr i} {
872 #
mistachkin46a6b992015-01-18 09:02:57 +0000873 # NOTE: Due to how the Tcl [exec] command works (i.e. where it treats
874 # command channels opened for it as textual ones), the carriage
875 # return character (and on Windows, the end-of-file character)
876 # cannot be used here.
mistachkinf21979d2015-01-18 05:35:01 +0000877 #
mistachkin46a6b992015-01-18 09:02:57 +0000878 if {$i==0x0D || ($tcl_platform(platform)=="windows" && $i==0x1A)} {
mistachkinf21979d2015-01-18 05:35:01 +0000879 continue
880 }
881 set hex [format %02X $i]
882 set char [subst \\x$hex]; set oldChar $char
mistachkin0acee512015-01-19 21:11:31 +0000883 set escapes [list]
884 if {$tcl_platform(platform)=="windows"} {
885 #
886 # NOTE: On Windows, we need to escape all the whitespace characters,
887 # the alarm (\a) character, and those with special meaning to
888 # the SQLite shell itself.
889 #
890 set escapes [list \
891 \a \\a \b \\b \t \\t \n \\n \v \\v \f \\f \r \\r \
892 " " "\" \"" \" \\\" ' \"'\" \\ \\\\]
893 } else {
894 #
895 # NOTE: On Unix, we need to escape most of the whitespace characters
896 # and those with special meaning to the SQLite shell itself.
897 # The alarm (\a), backspace (\b), and carriage-return (\r)
898 # characters do not appear to require escaping on Unix. For
899 # the alarm and backspace characters, this is probably due to
900 # differences in the command shell. For the carriage-return,
901 # it is probably due to differences in how Tcl handles command
902 # channel end-of-line translations.
903 #
904 set escapes [list \
905 \t \\t \n \\n \v \\v \f \\f \
906 " " "\" \"" \" \\\" ' \"'\" \\ \\\\]
907 }
908 set char [string map $escapes $char]
mistachkinbfefa4c2015-01-19 21:27:46 +0000909 set x [catchcmdex test.db ".print $char\n"]
mistachkinf21979d2015-01-18 05:35:01 +0000910 set code [lindex $x 0]
911 set res [lindex $x 1]
912 if {$code ne "0"} {
913 error "failed with error: $res"
914 }
915 if {$res ne "$oldChar\n"} {
916 error "failed with byte $hex mismatch"
917 }
918 }
919} {}
920
drh8df91852012-04-24 12:46:05 +0000921finish_test