blob: 6e454746e10c1fd12575aeefcf52e5e8b3a20c27 [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#
14# $Id: shell1.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $
15#
16
17# Test plan:
18#
shaneh5fc25012009-11-11 04:17:07 +000019# shell1-1.*: Basic command line option handling.
20# shell1-2.*: Basic "dot" command token parsing.
21# shell1-3.*: Basic test that "dot" command can be called.
shaneha05e0c42009-11-06 03:22:54 +000022#
23
24package require sqlite3
25
shaneh5fc25012009-11-11 04:17:07 +000026set CLI "./sqlite"
27
shaneha05e0c42009-11-06 03:22:54 +000028proc do_test {name cmd expected} {
29 puts -nonewline "$name ..."
30 set res [uplevel $cmd]
31 if {$res eq $expected} {
32 puts Ok
33 } else {
34 puts Error
35 puts " Got: $res"
36 puts " Expected: $expected"
shanehe2aa9d72009-11-06 17:20:17 +000037 exit
shaneha05e0c42009-11-06 03:22:54 +000038 }
39}
40
41proc execsql {sql} {
42 uplevel [list db eval $sql]
43}
44
45proc catchsql {sql} {
46 set rc [catch {uplevel [list db eval $sql]} msg]
47 list $rc $msg
48}
49
shaneh5fc25012009-11-11 04:17:07 +000050proc catchcmd {db cmd} {
51 global CLI
shaneha05e0c42009-11-06 03:22:54 +000052 set out [open cmds.txt w]
53 puts $out $cmd
54 close $out
shaneh5fc25012009-11-11 04:17:07 +000055 set line "exec $CLI $db < cmds.txt"
56 set rc [catch { eval $line } msg]
shaneha05e0c42009-11-06 03:22:54 +000057 list $rc $msg
58}
59
60file delete -force test.db test.db.journal
61sqlite3 db test.db
62
shaneh5fc25012009-11-11 04:17:07 +000063#----------------------------------------------------------------------------
64# Test cases shell1-1.*: Basic command line option handling.
65#
66
67# invalid option
68do_test shell1-1.1.1 {
69 set res [catchcmd "-bad test.db" ""]
70 set rc [lindex $res 0]
71 list $rc \
72 [regexp {Error: unknown option: -bad} $res]
73} {1 1}
74# error on extra options
75do_test shell1-1.1.2 {
76 set res [catchcmd "-bad test.db \"select 3\" \"select 4\"" ""]
77 set rc [lindex $res 0]
78 list $rc \
79 [regexp {Error: too many options: "select 4"} $res]
80} {1 1}
81# error on extra options
82do_test shell1-1.3.2 {
83 set res [catchcmd "-bad FOO test.db BAD" ".quit"]
84 set rc [lindex $res 0]
85 list $rc \
86 [regexp {Error: too many options: "BAD"} $res]
87} {1 1}
88
89# -help
90do_test shell1-1.2.1 {
91 set res [catchcmd "-help test.db" ""]
92 set rc [lindex $res 0]
93 list $rc \
94 [regexp {Usage} $res] \
95 [regexp {\-init} $res] \
96 [regexp {\-version} $res]
97} {1 1 1 1}
98
99# -init filename read/process named file
100do_test shell1-1.3.1 {
101 catchcmd "-init FOO test.db" ""
102} {0 {}}
103do_test shell1-1.3.2 {
104 set res [catchcmd "-init FOO test.db .quit BAD" ""]
105 set rc [lindex $res 0]
106 list $rc \
107 [regexp {Error: too many options: "BAD"} $res]
108} {1 1}
109
110# -echo print commands before execution
111do_test shell1-1.4.1 {
112 catchcmd "-echo test.db" ""
113} {0 {}}
114
115# -[no]header turn headers on or off
116do_test shell1-1.5.1 {
117 catchcmd "-header test.db" ""
118} {0 {}}
119do_test shell1-1.5.2 {
120 catchcmd "-noheader test.db" ""
121} {0 {}}
122
123# -bail stop after hitting an error
124do_test shell1-1.6.1 {
125 catchcmd "-bail test.db" ""
126} {0 {}}
127
128# -interactive force interactive I/O
129do_test shell1-1.7.1 {
130 set res [catchcmd "-interactive test.db" ".quit"]
131 set rc [lindex $res 0]
132 list $rc \
133 [regexp {SQLite version} $res] \
134 [regexp {Enter SQL statements} $res]
135} {0 1 1}
136
137# -batch force batch I/O
138do_test shell1-1.8.1 {
139 catchcmd "-batch test.db" ""
140} {0 {}}
141
142# -column set output mode to 'column'
143do_test shell1-1.9.1 {
144 catchcmd "-column test.db" ""
145} {0 {}}
146
147# -csv set output mode to 'csv'
148do_test shell1-1.10.1 {
149 catchcmd "-csv test.db" ""
150} {0 {}}
151
152# -html set output mode to HTML
153do_test shell1-1.11.1 {
154 catchcmd "-html test.db" ""
155} {0 {}}
156
157# -line set output mode to 'line'
158do_test shell1-1.12.1 {
159 catchcmd "-line test.db" ""
160} {0 {}}
161
162# -list set output mode to 'list'
163do_test shell1-1.13.1 {
164 catchcmd "-list test.db" ""
165} {0 {}}
166
167# -separator 'x' set output field separator (|)
168do_test shell1-1.14.1 {
169 catchcmd "-separator 'x' test.db" ""
170} {0 {}}
171do_test shell1-1.14.2 {
172 catchcmd "-separator x test.db" ""
173} {0 {}}
174do_test shell1-1.14.3 {
175 set res [catchcmd "-separator" ""]
176 set rc [lindex $res 0]
177 list $rc \
178 [regexp {Error: missing argument for option: -separator} $res]
179} {1 1}
180
181# -nullvalue 'text' set text string for NULL values
182do_test shell1-1.15.1 {
183 catchcmd "-nullvalue 'x' test.db" ""
184} {0 {}}
185do_test shell1-1.15.2 {
186 catchcmd "-nullvalue x test.db" ""
187} {0 {}}
188do_test shell1-1.15.3 {
189 set res [catchcmd "-nullvalue" ""]
190 set rc [lindex $res 0]
191 list $rc \
192 [regexp {Error: missing argument for option: -nullvalue} $res]
193} {1 1}
194
195# -version show SQLite version
196do_test shell1-1.16.1 {
197 catchcmd "-version test.db" ""
198} {0 3.6.20}
shanehe2aa9d72009-11-06 17:20:17 +0000199
shaneha05e0c42009-11-06 03:22:54 +0000200#----------------------------------------------------------------------------
shaneh5fc25012009-11-11 04:17:07 +0000201# Test cases shell1-2.*: Basic "dot" command token parsing.
shanehe2aa9d72009-11-06 17:20:17 +0000202#
203
204# check first token handling
shaneh5fc25012009-11-11 04:17:07 +0000205do_test shell1-2.1.1 {
206 catchcmd " test.db" ".foo"
shanehe2aa9d72009-11-06 17:20:17 +0000207} {1 {Error: unknown command or invalid arguments: "foo". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000208do_test shell1-2.1.2 {
209 catchcmd " test.db" ".\"foo OFF\""
shanehe2aa9d72009-11-06 17:20:17 +0000210} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000211do_test shell1-2.1.3 {
212 catchcmd " test.db" ".\'foo OFF\'"
shanehe2aa9d72009-11-06 17:20:17 +0000213} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}}
214
215# unbalanced quotes
shaneh5fc25012009-11-11 04:17:07 +0000216do_test shell1-2.2.1 {
217 catchcmd " test.db" ".\"foo OFF"
shanehe2aa9d72009-11-06 17:20:17 +0000218} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000219do_test shell1-2.2.2 {
220 catchcmd " test.db" ".\'foo OFF"
shanehe2aa9d72009-11-06 17:20:17 +0000221} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000222do_test shell1-2.2.3 {
223 catchcmd " test.db" ".explain \"OFF"
shanehe2aa9d72009-11-06 17:20:17 +0000224} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000225do_test shell1-2.2.4 {
226 catchcmd " test.db" ".explain \'OFF"
shanehe2aa9d72009-11-06 17:20:17 +0000227} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000228do_test shell1-2.2.5 {
229 catchcmd " test.db" ".mode \"insert FOO"
shanehe2aa9d72009-11-06 17:20:17 +0000230} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
shaneh5fc25012009-11-11 04:17:07 +0000231do_test shell1-2.2.6 {
232 catchcmd " test.db" ".mode \'insert FOO"
shanehe2aa9d72009-11-06 17:20:17 +0000233} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
234
235# check multiple tokens, and quoted tokens
shaneh5fc25012009-11-11 04:17:07 +0000236do_test shell1-2.3.1 {
237 catchcmd " test.db" ".explain 1"
shanehe2aa9d72009-11-06 17:20:17 +0000238} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000239do_test shell1-2.3.2 {
240 catchcmd " test.db" ".explain on"
shanehe2aa9d72009-11-06 17:20:17 +0000241} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000242do_test shell1-2.3.3 {
243 catchcmd " test.db" ".explain \"1 2 3\""
shanehe2aa9d72009-11-06 17:20:17 +0000244} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000245do_test shell1-2.3.4 {
246 catchcmd " test.db" ".explain \"OFF\""
shanehe2aa9d72009-11-06 17:20:17 +0000247} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000248do_test shell1-2.3.5 {
249 catchcmd " test.db" ".\'explain\' \'OFF\'"
shanehe2aa9d72009-11-06 17:20:17 +0000250} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000251do_test shell1-2.3.6 {
252 catchcmd " test.db" ".explain \'OFF\'"
shanehe2aa9d72009-11-06 17:20:17 +0000253} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000254do_test shell1-2.3.7 {
255 catchcmd " test.db" ".\'explain\' \'OFF\'"
shanehe2aa9d72009-11-06 17:20:17 +0000256} {0 {}}
257
258# check quoted args are unquoted
shaneh5fc25012009-11-11 04:17:07 +0000259do_test shell1-2.4.1 {
260 catchcmd " test.db" ".mode FOO"
shanehe2aa9d72009-11-06 17:20:17 +0000261} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
shaneh5fc25012009-11-11 04:17:07 +0000262do_test shell1-2.4.2 {
263 catchcmd " test.db" ".mode csv"
shanehe2aa9d72009-11-06 17:20:17 +0000264} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000265do_test shell1-2.4.2 {
266 catchcmd " test.db" ".mode \"csv\""
shanehe2aa9d72009-11-06 17:20:17 +0000267} {0 {}}
268
269
270#----------------------------------------------------------------------------
shaneh5fc25012009-11-11 04:17:07 +0000271# Test cases shell1-3.*: Basic test that "dot" command can be called.
shaneha05e0c42009-11-06 03:22:54 +0000272#
273
274# .backup ?DB? FILE Backup DB (default "main") to FILE
shaneh5fc25012009-11-11 04:17:07 +0000275do_test shell1-3.1.1 {
276 catchcmd " test.db" ".backup"
shanehe2aa9d72009-11-06 17:20:17 +0000277} {1 {Error: unknown command or invalid arguments: "backup". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000278do_test shell1-3.1.2 {
279 # catchcmd " test.db" ".backup FOO"
shanehe2aa9d72009-11-06 17:20:17 +0000280 #TBD!!! this asserts currently
shaneha05e0c42009-11-06 03:22:54 +0000281} {}
shaneh5fc25012009-11-11 04:17:07 +0000282do_test shell1-3.1.3 {
283 catchcmd " test.db" ".backup FOO BAR"
shanehe2aa9d72009-11-06 17:20:17 +0000284} {1 {Error: unknown database FOO}}
shaneh5fc25012009-11-11 04:17:07 +0000285do_test shell1-3.1.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000286 # too many arguments
shaneh5fc25012009-11-11 04:17:07 +0000287 catchcmd " test.db" ".backup FOO BAR BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000288} {1 {Error: unknown command or invalid arguments: "backup". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000289
290# .bail ON|OFF Stop after hitting an error. Default OFF
shaneh5fc25012009-11-11 04:17:07 +0000291do_test shell1-3.2.1 {
292 catchcmd " test.db" ".bail"
shaneha05e0c42009-11-06 03:22:54 +0000293} {1 {Error: unknown command or invalid arguments: "bail". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000294do_test shell1-3.2.2 {
295 catchcmd " test.db" ".bail ON"
shaneha05e0c42009-11-06 03:22:54 +0000296} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000297do_test shell1-3.2.3 {
298 catchcmd " test.db" ".bail OFF"
shaneha05e0c42009-11-06 03:22:54 +0000299} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000300do_test shell1-3.2.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000301 # too many arguments
shaneh5fc25012009-11-11 04:17:07 +0000302 catchcmd " test.db" ".bail OFF BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000303} {1 {Error: unknown command or invalid arguments: "bail". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000304
305# .databases List names and files of attached databases
shaneh5fc25012009-11-11 04:17:07 +0000306do_test shell1-3.3.1 {
307 set res [catchcmd " test.db" ".databases"]
shaneha05e0c42009-11-06 03:22:54 +0000308 regexp {0.*main.*test\.db} $res
309} {1}
shaneh5fc25012009-11-11 04:17:07 +0000310do_test shell1-3.3.2 {
shanehe2aa9d72009-11-06 17:20:17 +0000311 # too many arguments
shaneh5fc25012009-11-11 04:17:07 +0000312 catchcmd " test.db" ".databases BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000313} {1 {Error: unknown command or invalid arguments: "databases". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000314
315# .dump ?TABLE? ... Dump the database in an SQL text format
316# If TABLE specified, only dump tables matching
317# LIKE pattern TABLE.
shaneh5fc25012009-11-11 04:17:07 +0000318do_test shell1-3.4.1 {
319 set res [catchcmd " test.db" ".dump"]
shaneha05e0c42009-11-06 03:22:54 +0000320 list [regexp {BEGIN TRANSACTION;} $res] \
321 [regexp {COMMIT;} $res]
322} {1 1}
shaneh5fc25012009-11-11 04:17:07 +0000323do_test shell1-3.4.2 {
324 set res [catchcmd " test.db" ".dump FOO"]
shaneha05e0c42009-11-06 03:22:54 +0000325 list [regexp {BEGIN TRANSACTION;} $res] \
326 [regexp {COMMIT;} $res]
327} {1 1}
shaneh5fc25012009-11-11 04:17:07 +0000328do_test shell1-3.4.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000329 # too many arguments
shaneh5fc25012009-11-11 04:17:07 +0000330 catchcmd " test.db" ".dump FOO BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000331} {1 {Error: unknown command or invalid arguments: "dump". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000332
333# .echo ON|OFF Turn command echo on or off
shaneh5fc25012009-11-11 04:17:07 +0000334do_test shell1-3.5.1 {
335 catchcmd " test.db" ".echo"
shaneha05e0c42009-11-06 03:22:54 +0000336} {1 {Error: unknown command or invalid arguments: "echo". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000337do_test shell1-3.5.2 {
338 catchcmd " test.db" ".echo ON"
shaneha05e0c42009-11-06 03:22:54 +0000339} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000340do_test shell1-3.5.3 {
341 catchcmd " test.db" ".echo OFF"
shaneha05e0c42009-11-06 03:22:54 +0000342} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000343do_test shell1-3.5.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000344 # too many arguments
shaneh5fc25012009-11-11 04:17:07 +0000345 catchcmd " test.db" ".echo OFF BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000346} {1 {Error: unknown command or invalid arguments: "echo". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000347
348# .exit Exit this program
shaneh5fc25012009-11-11 04:17:07 +0000349do_test shell1-3.6.1 {
350 catchcmd " test.db" ".exit"
shaneha05e0c42009-11-06 03:22:54 +0000351} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000352do_test shell1-3.6.2 {
shanehe2aa9d72009-11-06 17:20:17 +0000353 # too many arguments
shaneh5fc25012009-11-11 04:17:07 +0000354 catchcmd " test.db" ".exit BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000355} {1 {Error: unknown command or invalid arguments: "exit". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000356
357# .explain ON|OFF Turn output mode suitable for EXPLAIN on or off.
shaneh5fc25012009-11-11 04:17:07 +0000358do_test shell1-3.7.1 {
359 catchcmd " test.db" ".explain"
shanehe2aa9d72009-11-06 17:20:17 +0000360 # explain is the exception to the booleans. without an option, it turns it on.
361} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000362do_test shell1-3.7.2 {
363 catchcmd " test.db" ".explain ON"
shaneha05e0c42009-11-06 03:22:54 +0000364} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000365do_test shell1-3.7.3 {
366 catchcmd " test.db" ".explain OFF"
shaneha05e0c42009-11-06 03:22:54 +0000367} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000368do_test shell1-3.7.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000369 # too many arguments
shaneh5fc25012009-11-11 04:17:07 +0000370 catchcmd " test.db" ".explain OFF BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000371} {1 {Error: unknown command or invalid arguments: "explain". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000372
373# .genfkey ?OPTIONS? Options are:
374# --no-drop: Do not drop old fkey triggers.
375# --ignore-errors: Ignore tables with fkey errors
376# --exec: Execute generated SQL immediately
377# See file tool/genfkey.README in the source
378# distribution for further information.
shaneh5fc25012009-11-11 04:17:07 +0000379do_test shell1-3.8.1 {
380 catchcmd " test.db" ".genfkey"
shanehe2aa9d72009-11-06 17:20:17 +0000381} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000382do_test shell1-3.8.2 {
383 catchcmd " test.db" ".genfkey FOO"
shanehe2aa9d72009-11-06 17:20:17 +0000384} {1 {unknown option: FOO}}
shaneha05e0c42009-11-06 03:22:54 +0000385
386# .header(s) ON|OFF Turn display of headers on or off
shaneh5fc25012009-11-11 04:17:07 +0000387do_test shell1-3.9.1 {
388 catchcmd " test.db" ".header"
shaneha05e0c42009-11-06 03:22:54 +0000389} {1 {Error: unknown command or invalid arguments: "header". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000390do_test shell1-3.9.2 {
391 catchcmd " test.db" ".header ON"
shaneha05e0c42009-11-06 03:22:54 +0000392} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000393do_test shell1-3.9.3 {
394 catchcmd " test.db" ".header OFF"
shaneha05e0c42009-11-06 03:22:54 +0000395} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000396do_test shell1-3.9.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000397 # too many arguments
shaneh5fc25012009-11-11 04:17:07 +0000398 catchcmd " test.db" ".header OFF BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000399} {1 {Error: unknown command or invalid arguments: "header". Enter ".help" for help}}
400
shaneh5fc25012009-11-11 04:17:07 +0000401do_test shell1-3.9.5 {
402 catchcmd " test.db" ".headers"
shaneha05e0c42009-11-06 03:22:54 +0000403} {1 {Error: unknown command or invalid arguments: "headers". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000404do_test shell1-3.9.6 {
405 catchcmd " test.db" ".headers ON"
shaneha05e0c42009-11-06 03:22:54 +0000406} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000407do_test shell1-3.9.7 {
408 catchcmd " test.db" ".headers OFF"
shaneha05e0c42009-11-06 03:22:54 +0000409} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000410do_test shell1-3.9.8 {
shanehe2aa9d72009-11-06 17:20:17 +0000411 # too many arguments
shaneh5fc25012009-11-11 04:17:07 +0000412 catchcmd " test.db" ".headers OFF BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000413} {1 {Error: unknown command or invalid arguments: "headers". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000414
415# .help Show this message
shaneh5fc25012009-11-11 04:17:07 +0000416do_test shell1-3.10.1 {
417 set res [catchcmd " test.db" ".help"]
shaneha05e0c42009-11-06 03:22:54 +0000418 # look for a few of the possible help commands
419 list [regexp {.help} $res] \
420 [regexp {.quit} $res] \
421 [regexp {.show} $res]
422} {1 1 1}
shaneh5fc25012009-11-11 04:17:07 +0000423do_test shell1-3.10.2 {
shanehe2aa9d72009-11-06 17:20:17 +0000424 # we allow .help to take extra args (it is help after all)
shaneh5fc25012009-11-11 04:17:07 +0000425 set res [catchcmd " test.db" ".help BAD"]
shanehe2aa9d72009-11-06 17:20:17 +0000426 # look for a few of the possible help commands
427 list [regexp {.help} $res] \
428 [regexp {.quit} $res] \
429 [regexp {.show} $res]
430} {1 1 1}
shaneha05e0c42009-11-06 03:22:54 +0000431
432# .import FILE TABLE Import data from FILE into TABLE
shaneh5fc25012009-11-11 04:17:07 +0000433do_test shell1-3.11.1 {
434 catchcmd " test.db" ".import"
shaneha05e0c42009-11-06 03:22:54 +0000435} {1 {Error: unknown command or invalid arguments: "import". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000436do_test shell1-3.11.2 {
437 catchcmd " test.db" ".import FOO"
shaneha05e0c42009-11-06 03:22:54 +0000438} {1 {Error: unknown command or invalid arguments: "import". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000439do_test shell1-3.11.2 {
440 catchcmd " test.db" ".import FOO BAR"
shaneha05e0c42009-11-06 03:22:54 +0000441} {1 {Error: no such table: BAR}}
shaneh5fc25012009-11-11 04:17:07 +0000442do_test shell1-3.11.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000443 # too many arguments
shaneh5fc25012009-11-11 04:17:07 +0000444 catchcmd " test.db" ".import FOO BAR BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000445} {1 {Error: unknown command or invalid arguments: "import". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000446
447# .indices ?TABLE? Show names of all indices
448# If TABLE specified, only show indices for tables
449# matching LIKE pattern TABLE.
shaneh5fc25012009-11-11 04:17:07 +0000450do_test shell1-3.12.1 {
451 catchcmd " test.db" ".indices"
shaneha05e0c42009-11-06 03:22:54 +0000452} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000453do_test shell1-3.12.2 {
454 catchcmd " test.db" ".indices FOO"
shaneha05e0c42009-11-06 03:22:54 +0000455} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000456do_test shell1-3.12.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000457 # too many arguments
shaneh5fc25012009-11-11 04:17:07 +0000458 catchcmd " test.db" ".indices FOO BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000459} {1 {Error: unknown command or invalid arguments: "indices". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000460
461# .mode MODE ?TABLE? Set output mode where MODE is one of:
462# csv Comma-separated values
463# column Left-aligned columns. (See .width)
464# html HTML <table> code
465# insert SQL insert statements for TABLE
466# line One value per line
467# list Values delimited by .separator string
468# tabs Tab-separated values
469# tcl TCL list elements
shaneh5fc25012009-11-11 04:17:07 +0000470do_test shell1-3.13.1 {
471 catchcmd " test.db" ".mode"
shaneha05e0c42009-11-06 03:22:54 +0000472} {1 {Error: unknown command or invalid arguments: "mode". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000473do_test shell1-3.13.2 {
474 catchcmd " test.db" ".mode FOO"
shaneha05e0c42009-11-06 03:22:54 +0000475} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
shaneh5fc25012009-11-11 04:17:07 +0000476do_test shell1-3.13.3 {
477 catchcmd " test.db" ".mode csv"
shaneha05e0c42009-11-06 03:22:54 +0000478} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000479do_test shell1-3.13.4 {
480 catchcmd " test.db" ".mode column"
shaneha05e0c42009-11-06 03:22:54 +0000481} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000482do_test shell1-3.13.5 {
483 catchcmd " test.db" ".mode html"
shaneha05e0c42009-11-06 03:22:54 +0000484} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000485do_test shell1-3.13.6 {
486 catchcmd " test.db" ".mode insert"
shaneha05e0c42009-11-06 03:22:54 +0000487} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000488do_test shell1-3.13.7 {
489 catchcmd " test.db" ".mode line"
shaneha05e0c42009-11-06 03:22:54 +0000490} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000491do_test shell1-3.13.8 {
492 catchcmd " test.db" ".mode list"
shaneha05e0c42009-11-06 03:22:54 +0000493} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000494do_test shell1-3.13.9 {
495 catchcmd " test.db" ".mode tabs"
shaneha05e0c42009-11-06 03:22:54 +0000496} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000497do_test shell1-3.13.10 {
498 catchcmd " test.db" ".mode tcl"
shaneha05e0c42009-11-06 03:22:54 +0000499} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000500do_test shell1-3.13.11 {
shanehe2aa9d72009-11-06 17:20:17 +0000501 # too many arguments
shaneh5fc25012009-11-11 04:17:07 +0000502 catchcmd " test.db" ".mode tcl BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000503} {1 {Error: invalid arguments: "BAD". Enter ".help" for help}}
504
505# don't allow partial mode type matches
shaneh5fc25012009-11-11 04:17:07 +0000506do_test shell1-3.13.12 {
507 catchcmd " test.db" ".mode l"
shanehe2aa9d72009-11-06 17:20:17 +0000508} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
shaneh5fc25012009-11-11 04:17:07 +0000509do_test shell1-3.13.13 {
510 catchcmd " test.db" ".mode li"
shanehe2aa9d72009-11-06 17:20:17 +0000511} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
shaneh5fc25012009-11-11 04:17:07 +0000512do_test shell1-3.13.14 {
513 catchcmd " test.db" ".mode lin"
shanehe2aa9d72009-11-06 17:20:17 +0000514} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
shaneha05e0c42009-11-06 03:22:54 +0000515
516# .nullvalue STRING Print STRING in place of NULL values
shaneh5fc25012009-11-11 04:17:07 +0000517do_test shell1-3.14.1 {
518 catchcmd " test.db" ".nullvalue"
shaneha05e0c42009-11-06 03:22:54 +0000519} {1 {Error: unknown command or invalid arguments: "nullvalue". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000520do_test shell1-3.14.2 {
521 catchcmd " test.db" ".nullvalue FOO"
shaneha05e0c42009-11-06 03:22:54 +0000522} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000523do_test shell1-3.14.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000524 # too many arguments
shaneh5fc25012009-11-11 04:17:07 +0000525 catchcmd " test.db" ".nullvalue FOO BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000526} {1 {Error: unknown command or invalid arguments: "nullvalue". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000527
528# .output FILENAME Send output to FILENAME
shaneh5fc25012009-11-11 04:17:07 +0000529do_test shell1-3.15.1 {
530 catchcmd " test.db" ".output"
shaneha05e0c42009-11-06 03:22:54 +0000531} {1 {Error: unknown command or invalid arguments: "output". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000532do_test shell1-3.15.2 {
533 catchcmd " test.db" ".output FOO"
shaneha05e0c42009-11-06 03:22:54 +0000534} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000535do_test shell1-3.15.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000536 # too many arguments
shaneh5fc25012009-11-11 04:17:07 +0000537 catchcmd " test.db" ".output FOO BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000538} {1 {Error: unknown command or invalid arguments: "output". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000539
540# .output stdout Send output to the screen
shaneh5fc25012009-11-11 04:17:07 +0000541do_test shell1-3.16.1 {
542 catchcmd " test.db" ".output stdout"
shaneha05e0c42009-11-06 03:22:54 +0000543} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000544do_test shell1-3.16.2 {
shanehe2aa9d72009-11-06 17:20:17 +0000545 # too many arguments
shaneh5fc25012009-11-11 04:17:07 +0000546 catchcmd " test.db" ".output stdout BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000547} {1 {Error: unknown command or invalid arguments: "output". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000548
549# .prompt MAIN CONTINUE Replace the standard prompts
shaneh5fc25012009-11-11 04:17:07 +0000550do_test shell1-3.17.1 {
551 catchcmd " test.db" ".prompt"
shaneha05e0c42009-11-06 03:22:54 +0000552} {1 {Error: unknown command or invalid arguments: "prompt". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000553do_test shell1-3.17.2 {
554 catchcmd " test.db" ".prompt FOO"
shaneha05e0c42009-11-06 03:22:54 +0000555} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000556do_test shell1-3.17.3 {
557 catchcmd " test.db" ".prompt FOO BAR"
shaneha05e0c42009-11-06 03:22:54 +0000558} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000559do_test shell1-3.17.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000560 # too many arguments
shaneh5fc25012009-11-11 04:17:07 +0000561 catchcmd " test.db" ".prompt FOO BAR BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000562} {1 {Error: unknown command or invalid arguments: "prompt". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000563
564# .quit Exit this program
shaneh5fc25012009-11-11 04:17:07 +0000565do_test shell1-3.18.1 {
566 catchcmd " test.db" ".quit"
shaneha05e0c42009-11-06 03:22:54 +0000567} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000568do_test shell1-3.18.2 {
shanehe2aa9d72009-11-06 17:20:17 +0000569 # too many arguments
shaneh5fc25012009-11-11 04:17:07 +0000570 catchcmd " test.db" ".quit BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000571} {1 {Error: unknown command or invalid arguments: "quit". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000572
573# .read FILENAME Execute SQL in FILENAME
shaneh5fc25012009-11-11 04:17:07 +0000574do_test shell1-3.19.1 {
575 catchcmd " test.db" ".read"
shaneha05e0c42009-11-06 03:22:54 +0000576} {1 {Error: unknown command or invalid arguments: "read". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000577do_test shell1-3.19.2 {
shaneha05e0c42009-11-06 03:22:54 +0000578 file delete -force FOO
shaneh5fc25012009-11-11 04:17:07 +0000579 catchcmd " test.db" ".read FOO"
shaneha05e0c42009-11-06 03:22:54 +0000580} {1 {Error: cannot open "FOO"}}
shaneh5fc25012009-11-11 04:17:07 +0000581do_test shell1-3.19.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000582 # too many arguments
shaneh5fc25012009-11-11 04:17:07 +0000583 catchcmd " test.db" ".read FOO BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000584} {1 {Error: unknown command or invalid arguments: "read". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000585
586# .restore ?DB? FILE Restore content of DB (default "main") from FILE
shaneh5fc25012009-11-11 04:17:07 +0000587do_test shell1-3.20.1 {
588 catchcmd " test.db" ".restore"
shaneha05e0c42009-11-06 03:22:54 +0000589} {1 {Error: unknown command or invalid arguments: "restore". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000590do_test shell1-3.20.2 {
591 # catchcmd " test.db" ".restore FOO"
shaneha05e0c42009-11-06 03:22:54 +0000592 #TBD!!! this asserts currently
593} {}
shaneh5fc25012009-11-11 04:17:07 +0000594do_test shell1-3.20.3 {
595 catchcmd " test.db" ".restore FOO BAR"
shanehe2aa9d72009-11-06 17:20:17 +0000596} {1 {Error: unknown database FOO}}
shaneh5fc25012009-11-11 04:17:07 +0000597do_test shell1-3.20.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000598 # too many arguments
shaneh5fc25012009-11-11 04:17:07 +0000599 catchcmd " test.db" ".restore FOO BAR BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000600} {1 {Error: unknown command or invalid arguments: "restore". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000601
602# .schema ?TABLE? Show the CREATE statements
603# If TABLE specified, only show tables matching
604# LIKE pattern TABLE.
shaneh5fc25012009-11-11 04:17:07 +0000605do_test shell1-3.21.1 {
606 catchcmd " test.db" ".schema"
shaneha05e0c42009-11-06 03:22:54 +0000607} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000608do_test shell1-3.21.2 {
609 catchcmd " test.db" ".schema FOO"
shaneha05e0c42009-11-06 03:22:54 +0000610} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000611do_test shell1-3.21.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000612 # too many arguments
shaneh5fc25012009-11-11 04:17:07 +0000613 catchcmd " test.db" ".schema FOO BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000614} {1 {Error: unknown command or invalid arguments: "schema". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000615
616# .separator STRING Change separator used by output mode and .import
shaneh5fc25012009-11-11 04:17:07 +0000617do_test shell1-3.22.1 {
618 catchcmd " test.db" ".separator"
shaneha05e0c42009-11-06 03:22:54 +0000619} {1 {Error: unknown command or invalid arguments: "separator". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000620do_test shell1-3.22.2 {
621 catchcmd " test.db" ".separator FOO"
shaneha05e0c42009-11-06 03:22:54 +0000622} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000623do_test shell1-3.22.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000624 # too many arguments
shaneh5fc25012009-11-11 04:17:07 +0000625 catchcmd " test.db" ".separator FOO BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000626} {1 {Error: unknown command or invalid arguments: "separator". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000627
628# .show Show the current values for various settings
shaneh5fc25012009-11-11 04:17:07 +0000629do_test shell1-3.23.1 {
630 set res [catchcmd " test.db" ".show"]
shaneha05e0c42009-11-06 03:22:54 +0000631 list [regexp {echo:} $res] \
632 [regexp {explain:} $res] \
633 [regexp {headers:} $res] \
634 [regexp {mode:} $res] \
635 [regexp {nullvalue:} $res] \
636 [regexp {output:} $res] \
637 [regexp {separator:} $res] \
638 [regexp {width:} $res]
639} {1 1 1 1 1 1 1 1}
shaneh5fc25012009-11-11 04:17:07 +0000640do_test shell1-3.23.2 {
shanehe2aa9d72009-11-06 17:20:17 +0000641 # too many arguments
shaneh5fc25012009-11-11 04:17:07 +0000642 catchcmd " test.db" ".show BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000643} {1 {Error: unknown command or invalid arguments: "show". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000644
645# .tables ?TABLE? List names of tables
646# If TABLE specified, only list tables matching
647# LIKE pattern TABLE.
shaneh5fc25012009-11-11 04:17:07 +0000648do_test shell1-3.24.1 {
649 catchcmd " test.db" ".tables"
shaneha05e0c42009-11-06 03:22:54 +0000650} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000651do_test shell1-3.24.2 {
652 catchcmd " test.db" ".tables FOO"
shaneha05e0c42009-11-06 03:22:54 +0000653} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000654do_test shell1-3.24.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000655 # too many arguments
shaneh5fc25012009-11-11 04:17:07 +0000656 catchcmd " test.db" ".tables FOO BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000657} {1 {Error: unknown command or invalid arguments: "tables". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000658
659# .timeout MS Try opening locked tables for MS milliseconds
shaneh5fc25012009-11-11 04:17:07 +0000660do_test shell1-3.25.1 {
661 catchcmd " test.db" ".timeout"
shaneha05e0c42009-11-06 03:22:54 +0000662} {1 {Error: unknown command or invalid arguments: "timeout". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000663do_test shell1-3.25.2 {
664 catchcmd " test.db" ".timeout zzz"
shanehe2aa9d72009-11-06 17:20:17 +0000665 # this should be treated the same as a '0' timeout
shaneha05e0c42009-11-06 03:22:54 +0000666} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000667do_test shell1-3.25.3 {
668 catchcmd " test.db" ".timeout 1"
shaneha05e0c42009-11-06 03:22:54 +0000669} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000670do_test shell1-3.25.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000671 # too many arguments
shaneh5fc25012009-11-11 04:17:07 +0000672 catchcmd " test.db" ".timeout 1 BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000673} {1 {Error: unknown command or invalid arguments: "timeout". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000674
675# .width NUM NUM ... Set column widths for "column" mode
shaneh5fc25012009-11-11 04:17:07 +0000676do_test shell1-3.26.1 {
677 catchcmd " test.db" ".width"
shanehe2aa9d72009-11-06 17:20:17 +0000678} {1 {Error: unknown command or invalid arguments: "width". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000679do_test shell1-3.26.2 {
680 catchcmd " test.db" ".width xxx"
shanehe2aa9d72009-11-06 17:20:17 +0000681 # this should be treated the same as a '0' width for col 1
shaneha05e0c42009-11-06 03:22:54 +0000682} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000683do_test shell1-3.26.3 {
684 catchcmd " test.db" ".width xxx yyy"
shanehe2aa9d72009-11-06 17:20:17 +0000685 # this should be treated the same as a '0' width for col 1 and 2
shaneha05e0c42009-11-06 03:22:54 +0000686} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000687do_test shell1-3.26.4 {
688 catchcmd " test.db" ".width 1 1"
shanehe2aa9d72009-11-06 17:20:17 +0000689 # this should be treated the same as a '1' width for col 1 and 2
shaneha05e0c42009-11-06 03:22:54 +0000690} {0 {}}
691
692# .timer ON|OFF Turn the CPU timer measurement on or off
shaneh5fc25012009-11-11 04:17:07 +0000693do_test shell1-3.27.1 {
694 catchcmd " test.db" ".timer"
shaneha05e0c42009-11-06 03:22:54 +0000695} {1 {Error: unknown command or invalid arguments: "timer". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000696do_test shell1-3.27.2 {
697 catchcmd " test.db" ".timer ON"
shaneha05e0c42009-11-06 03:22:54 +0000698} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000699do_test shell1-3.27.3 {
700 catchcmd " test.db" ".timer OFF"
shaneha05e0c42009-11-06 03:22:54 +0000701} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000702do_test shell1-3.27.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000703 # too many arguments
shaneh5fc25012009-11-11 04:17:07 +0000704 catchcmd " test.db" ".timer OFF BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000705} {1 {Error: unknown command or invalid arguments: "timer". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000706
707#