blob: 562f10e65ae8406ab7bbadcb525afbb3f7625162 [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}
48# error on extra options
49do_test shell1-1.1.2 {
50 set res [catchcmd "-bad test.db \"select 3\" \"select 4\"" ""]
51 set rc [lindex $res 0]
52 list $rc \
53 [regexp {Error: too many options: "select 4"} $res]
54} {1 1}
55# error on extra options
shanehca7dfda2009-12-17 21:07:54 +000056do_test shell1-1.1.3 {
shaneh5fc25012009-11-11 04:17:07 +000057 set res [catchcmd "-bad FOO test.db BAD" ".quit"]
58 set rc [lindex $res 0]
59 list $rc \
60 [regexp {Error: too many options: "BAD"} $res]
61} {1 1}
62
63# -help
64do_test shell1-1.2.1 {
65 set res [catchcmd "-help test.db" ""]
66 set rc [lindex $res 0]
67 list $rc \
68 [regexp {Usage} $res] \
69 [regexp {\-init} $res] \
70 [regexp {\-version} $res]
71} {1 1 1 1}
72
73# -init filename read/process named file
74do_test shell1-1.3.1 {
shanehca7dfda2009-12-17 21:07:54 +000075 catchcmd "-init FOO test.db" ""
shaneh5fc25012009-11-11 04:17:07 +000076} {0 {}}
77do_test shell1-1.3.2 {
78 set res [catchcmd "-init FOO test.db .quit BAD" ""]
79 set rc [lindex $res 0]
80 list $rc \
81 [regexp {Error: too many options: "BAD"} $res]
82} {1 1}
83
84# -echo print commands before execution
85do_test shell1-1.4.1 {
86 catchcmd "-echo test.db" ""
87} {0 {}}
88
89# -[no]header turn headers on or off
90do_test shell1-1.5.1 {
91 catchcmd "-header test.db" ""
92} {0 {}}
93do_test shell1-1.5.2 {
94 catchcmd "-noheader test.db" ""
95} {0 {}}
96
97# -bail stop after hitting an error
98do_test shell1-1.6.1 {
99 catchcmd "-bail test.db" ""
100} {0 {}}
101
102# -interactive force interactive I/O
103do_test shell1-1.7.1 {
104 set res [catchcmd "-interactive test.db" ".quit"]
105 set rc [lindex $res 0]
106 list $rc \
107 [regexp {SQLite version} $res] \
108 [regexp {Enter SQL statements} $res]
109} {0 1 1}
110
111# -batch force batch I/O
112do_test shell1-1.8.1 {
113 catchcmd "-batch test.db" ""
114} {0 {}}
115
116# -column set output mode to 'column'
117do_test shell1-1.9.1 {
118 catchcmd "-column test.db" ""
119} {0 {}}
120
121# -csv set output mode to 'csv'
122do_test shell1-1.10.1 {
123 catchcmd "-csv test.db" ""
124} {0 {}}
125
126# -html set output mode to HTML
127do_test shell1-1.11.1 {
128 catchcmd "-html test.db" ""
129} {0 {}}
130
131# -line set output mode to 'line'
132do_test shell1-1.12.1 {
133 catchcmd "-line test.db" ""
134} {0 {}}
135
136# -list set output mode to 'list'
137do_test shell1-1.13.1 {
138 catchcmd "-list test.db" ""
139} {0 {}}
140
141# -separator 'x' set output field separator (|)
142do_test shell1-1.14.1 {
143 catchcmd "-separator 'x' test.db" ""
144} {0 {}}
145do_test shell1-1.14.2 {
146 catchcmd "-separator x test.db" ""
147} {0 {}}
148do_test shell1-1.14.3 {
149 set res [catchcmd "-separator" ""]
150 set rc [lindex $res 0]
151 list $rc \
drh98d312f2012-10-25 15:23:14 +0000152 [regexp {Error: missing argument to -separator} $res]
shaneh5fc25012009-11-11 04:17:07 +0000153} {1 1}
154
shaneh642d8b82010-07-28 16:05:34 +0000155# -stats print memory stats before each finalize
156do_test shell1-1.14b.1 {
157 catchcmd "-stats test.db" ""
158} {0 {}}
159
shaneh5fc25012009-11-11 04:17:07 +0000160# -nullvalue 'text' set text string for NULL values
161do_test shell1-1.15.1 {
162 catchcmd "-nullvalue 'x' test.db" ""
163} {0 {}}
164do_test shell1-1.15.2 {
165 catchcmd "-nullvalue x test.db" ""
166} {0 {}}
167do_test shell1-1.15.3 {
168 set res [catchcmd "-nullvalue" ""]
169 set rc [lindex $res 0]
170 list $rc \
drh98d312f2012-10-25 15:23:14 +0000171 [regexp {Error: missing argument to -nullvalue} $res]
shaneh5fc25012009-11-11 04:17:07 +0000172} {1 1}
173
174# -version show SQLite version
175do_test shell1-1.16.1 {
drh9fd301b2011-06-03 13:28:22 +0000176 set x [catchcmd "-version test.db" ""]
drhb24c61a2012-05-21 22:45:35 +0000177} {/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 +0000178
shaneha05e0c42009-11-06 03:22:54 +0000179#----------------------------------------------------------------------------
shaneh5fc25012009-11-11 04:17:07 +0000180# Test cases shell1-2.*: Basic "dot" command token parsing.
shanehe2aa9d72009-11-06 17:20:17 +0000181#
182
183# check first token handling
shaneh5fc25012009-11-11 04:17:07 +0000184do_test shell1-2.1.1 {
shanehca7dfda2009-12-17 21:07:54 +0000185 catchcmd "test.db" ".foo"
shanehe2aa9d72009-11-06 17:20:17 +0000186} {1 {Error: unknown command or invalid arguments: "foo". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000187do_test shell1-2.1.2 {
shanehca7dfda2009-12-17 21:07:54 +0000188 catchcmd "test.db" ".\"foo OFF\""
shanehe2aa9d72009-11-06 17:20:17 +0000189} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000190do_test shell1-2.1.3 {
shanehca7dfda2009-12-17 21:07:54 +0000191 catchcmd "test.db" ".\'foo OFF\'"
shanehe2aa9d72009-11-06 17:20:17 +0000192} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}}
193
194# unbalanced quotes
shaneh5fc25012009-11-11 04:17:07 +0000195do_test shell1-2.2.1 {
shanehca7dfda2009-12-17 21:07:54 +0000196 catchcmd "test.db" ".\"foo OFF"
shanehe2aa9d72009-11-06 17:20:17 +0000197} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000198do_test shell1-2.2.2 {
shanehca7dfda2009-12-17 21:07:54 +0000199 catchcmd "test.db" ".\'foo OFF"
shanehe2aa9d72009-11-06 17:20:17 +0000200} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000201do_test shell1-2.2.3 {
shanehca7dfda2009-12-17 21:07:54 +0000202 catchcmd "test.db" ".explain \"OFF"
shanehe2aa9d72009-11-06 17:20:17 +0000203} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000204do_test shell1-2.2.4 {
shanehca7dfda2009-12-17 21:07:54 +0000205 catchcmd "test.db" ".explain \'OFF"
shanehe2aa9d72009-11-06 17:20:17 +0000206} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000207do_test shell1-2.2.5 {
shanehca7dfda2009-12-17 21:07:54 +0000208 catchcmd "test.db" ".mode \"insert FOO"
shanehe2aa9d72009-11-06 17:20:17 +0000209} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
shaneh5fc25012009-11-11 04:17:07 +0000210do_test shell1-2.2.6 {
shanehca7dfda2009-12-17 21:07:54 +0000211 catchcmd "test.db" ".mode \'insert FOO"
shanehe2aa9d72009-11-06 17:20:17 +0000212} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
213
214# check multiple tokens, and quoted tokens
shaneh5fc25012009-11-11 04:17:07 +0000215do_test shell1-2.3.1 {
shanehca7dfda2009-12-17 21:07:54 +0000216 catchcmd "test.db" ".explain 1"
shanehe2aa9d72009-11-06 17:20:17 +0000217} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000218do_test shell1-2.3.2 {
shanehca7dfda2009-12-17 21:07:54 +0000219 catchcmd "test.db" ".explain on"
shanehe2aa9d72009-11-06 17:20:17 +0000220} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000221do_test shell1-2.3.3 {
shanehca7dfda2009-12-17 21:07:54 +0000222 catchcmd "test.db" ".explain \"1 2 3\""
drh173ba092013-01-28 18:18:26 +0000223} {1 {ERROR: Not a boolean value: "1 2 3". Assuming "no".}}
shaneh5fc25012009-11-11 04:17:07 +0000224do_test shell1-2.3.4 {
shanehca7dfda2009-12-17 21:07:54 +0000225 catchcmd "test.db" ".explain \"OFF\""
shanehe2aa9d72009-11-06 17:20:17 +0000226} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000227do_test shell1-2.3.5 {
shanehca7dfda2009-12-17 21:07:54 +0000228 catchcmd "test.db" ".\'explain\' \'OFF\'"
shanehe2aa9d72009-11-06 17:20:17 +0000229} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000230do_test shell1-2.3.6 {
shanehca7dfda2009-12-17 21:07:54 +0000231 catchcmd "test.db" ".explain \'OFF\'"
shanehe2aa9d72009-11-06 17:20:17 +0000232} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000233do_test shell1-2.3.7 {
shanehca7dfda2009-12-17 21:07:54 +0000234 catchcmd "test.db" ".\'explain\' \'OFF\'"
shanehe2aa9d72009-11-06 17:20:17 +0000235} {0 {}}
236
237# check quoted args are unquoted
shaneh5fc25012009-11-11 04:17:07 +0000238do_test shell1-2.4.1 {
shanehca7dfda2009-12-17 21:07:54 +0000239 catchcmd "test.db" ".mode FOO"
shanehe2aa9d72009-11-06 17:20:17 +0000240} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
shaneh5fc25012009-11-11 04:17:07 +0000241do_test shell1-2.4.2 {
shanehca7dfda2009-12-17 21:07:54 +0000242 catchcmd "test.db" ".mode csv"
shanehe2aa9d72009-11-06 17:20:17 +0000243} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000244do_test shell1-2.4.2 {
shanehca7dfda2009-12-17 21:07:54 +0000245 catchcmd "test.db" ".mode \"csv\""
shanehe2aa9d72009-11-06 17:20:17 +0000246} {0 {}}
247
248
249#----------------------------------------------------------------------------
shaneh5fc25012009-11-11 04:17:07 +0000250# Test cases shell1-3.*: Basic test that "dot" command can be called.
shaneha05e0c42009-11-06 03:22:54 +0000251#
252
253# .backup ?DB? FILE Backup DB (default "main") to FILE
shaneh5fc25012009-11-11 04:17:07 +0000254do_test shell1-3.1.1 {
shanehca7dfda2009-12-17 21:07:54 +0000255 catchcmd "test.db" ".backup"
drhbc46f022013-01-23 18:53:23 +0000256} {1 {missing FILENAME argument on .backup}}
shaneh5fc25012009-11-11 04:17:07 +0000257do_test shell1-3.1.2 {
shanehca7dfda2009-12-17 21:07:54 +0000258 catchcmd "test.db" ".backup FOO"
259} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000260do_test shell1-3.1.3 {
shanehca7dfda2009-12-17 21:07:54 +0000261 catchcmd "test.db" ".backup FOO BAR"
shanehe2aa9d72009-11-06 17:20:17 +0000262} {1 {Error: unknown database FOO}}
shaneh5fc25012009-11-11 04:17:07 +0000263do_test shell1-3.1.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000264 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000265 catchcmd "test.db" ".backup FOO BAR BAD"
drhbc46f022013-01-23 18:53:23 +0000266} {1 {too many arguments to .backup}}
shaneha05e0c42009-11-06 03:22:54 +0000267
268# .bail ON|OFF Stop after hitting an error. Default OFF
shaneh5fc25012009-11-11 04:17:07 +0000269do_test shell1-3.2.1 {
shanehca7dfda2009-12-17 21:07:54 +0000270 catchcmd "test.db" ".bail"
shaneha05e0c42009-11-06 03:22:54 +0000271} {1 {Error: unknown command or invalid arguments: "bail". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000272do_test shell1-3.2.2 {
shanehca7dfda2009-12-17 21:07:54 +0000273 catchcmd "test.db" ".bail ON"
shaneha05e0c42009-11-06 03:22:54 +0000274} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000275do_test shell1-3.2.3 {
shanehca7dfda2009-12-17 21:07:54 +0000276 catchcmd "test.db" ".bail OFF"
shaneha05e0c42009-11-06 03:22:54 +0000277} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000278do_test shell1-3.2.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000279 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000280 catchcmd "test.db" ".bail OFF BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000281} {1 {Error: unknown command or invalid arguments: "bail". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000282
283# .databases List names and files of attached databases
shaneh5fc25012009-11-11 04:17:07 +0000284do_test shell1-3.3.1 {
drhe4d31952012-05-12 01:14:27 +0000285 catchcmd "-csv test.db" ".databases"
mistachkin86ab48f2012-05-22 19:25:51 +0000286} "/0 +.*main +[string map {/ .} [string range [get_pwd] 0 10]].*/"
shaneh5fc25012009-11-11 04:17:07 +0000287do_test shell1-3.3.2 {
shanehe2aa9d72009-11-06 17:20:17 +0000288 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000289 catchcmd "test.db" ".databases BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000290} {1 {Error: unknown command or invalid arguments: "databases". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000291
292# .dump ?TABLE? ... Dump the database in an SQL text format
293# If TABLE specified, only dump tables matching
294# LIKE pattern TABLE.
shaneh5fc25012009-11-11 04:17:07 +0000295do_test shell1-3.4.1 {
shanehca7dfda2009-12-17 21:07:54 +0000296 set res [catchcmd "test.db" ".dump"]
shaneha05e0c42009-11-06 03:22:54 +0000297 list [regexp {BEGIN TRANSACTION;} $res] \
298 [regexp {COMMIT;} $res]
299} {1 1}
shaneh5fc25012009-11-11 04:17:07 +0000300do_test shell1-3.4.2 {
shanehca7dfda2009-12-17 21:07:54 +0000301 set res [catchcmd "test.db" ".dump FOO"]
shaneha05e0c42009-11-06 03:22:54 +0000302 list [regexp {BEGIN TRANSACTION;} $res] \
303 [regexp {COMMIT;} $res]
304} {1 1}
shaneh5fc25012009-11-11 04:17:07 +0000305do_test shell1-3.4.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000306 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000307 catchcmd "test.db" ".dump FOO BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000308} {1 {Error: unknown command or invalid arguments: "dump". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000309
310# .echo ON|OFF Turn command echo on or off
shaneh5fc25012009-11-11 04:17:07 +0000311do_test shell1-3.5.1 {
shanehca7dfda2009-12-17 21:07:54 +0000312 catchcmd "test.db" ".echo"
shaneha05e0c42009-11-06 03:22:54 +0000313} {1 {Error: unknown command or invalid arguments: "echo". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000314do_test shell1-3.5.2 {
shanehca7dfda2009-12-17 21:07:54 +0000315 catchcmd "test.db" ".echo ON"
shaneha05e0c42009-11-06 03:22:54 +0000316} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000317do_test shell1-3.5.3 {
shanehca7dfda2009-12-17 21:07:54 +0000318 catchcmd "test.db" ".echo OFF"
shaneha05e0c42009-11-06 03:22:54 +0000319} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000320do_test shell1-3.5.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000321 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000322 catchcmd "test.db" ".echo OFF BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000323} {1 {Error: unknown command or invalid arguments: "echo". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000324
325# .exit Exit this program
shaneh5fc25012009-11-11 04:17:07 +0000326do_test shell1-3.6.1 {
shanehca7dfda2009-12-17 21:07:54 +0000327 catchcmd "test.db" ".exit"
shaneha05e0c42009-11-06 03:22:54 +0000328} {0 {}}
329
330# .explain ON|OFF Turn output mode suitable for EXPLAIN on or off.
shaneh5fc25012009-11-11 04:17:07 +0000331do_test shell1-3.7.1 {
shanehca7dfda2009-12-17 21:07:54 +0000332 catchcmd "test.db" ".explain"
shanehe2aa9d72009-11-06 17:20:17 +0000333 # explain is the exception to the booleans. without an option, it turns it on.
334} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000335do_test shell1-3.7.2 {
shanehca7dfda2009-12-17 21:07:54 +0000336 catchcmd "test.db" ".explain ON"
shaneha05e0c42009-11-06 03:22:54 +0000337} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000338do_test shell1-3.7.3 {
shanehca7dfda2009-12-17 21:07:54 +0000339 catchcmd "test.db" ".explain OFF"
shaneha05e0c42009-11-06 03:22:54 +0000340} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000341do_test shell1-3.7.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000342 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000343 catchcmd "test.db" ".explain OFF BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000344} {1 {Error: unknown command or invalid arguments: "explain". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000345
shaneha05e0c42009-11-06 03:22:54 +0000346
347# .header(s) ON|OFF Turn display of headers on or off
shaneh5fc25012009-11-11 04:17:07 +0000348do_test shell1-3.9.1 {
shanehca7dfda2009-12-17 21:07:54 +0000349 catchcmd "test.db" ".header"
shaneha05e0c42009-11-06 03:22:54 +0000350} {1 {Error: unknown command or invalid arguments: "header". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000351do_test shell1-3.9.2 {
shanehca7dfda2009-12-17 21:07:54 +0000352 catchcmd "test.db" ".header ON"
shaneha05e0c42009-11-06 03:22:54 +0000353} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000354do_test shell1-3.9.3 {
shanehca7dfda2009-12-17 21:07:54 +0000355 catchcmd "test.db" ".header OFF"
shaneha05e0c42009-11-06 03:22:54 +0000356} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000357do_test shell1-3.9.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000358 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000359 catchcmd "test.db" ".header OFF BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000360} {1 {Error: unknown command or invalid arguments: "header". Enter ".help" for help}}
361
shaneh5fc25012009-11-11 04:17:07 +0000362do_test shell1-3.9.5 {
shanehca7dfda2009-12-17 21:07:54 +0000363 catchcmd "test.db" ".headers"
shaneha05e0c42009-11-06 03:22:54 +0000364} {1 {Error: unknown command or invalid arguments: "headers". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000365do_test shell1-3.9.6 {
shanehca7dfda2009-12-17 21:07:54 +0000366 catchcmd "test.db" ".headers ON"
shaneha05e0c42009-11-06 03:22:54 +0000367} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000368do_test shell1-3.9.7 {
shanehca7dfda2009-12-17 21:07:54 +0000369 catchcmd "test.db" ".headers OFF"
shaneha05e0c42009-11-06 03:22:54 +0000370} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000371do_test shell1-3.9.8 {
shanehe2aa9d72009-11-06 17:20:17 +0000372 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000373 catchcmd "test.db" ".headers OFF BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000374} {1 {Error: unknown command or invalid arguments: "headers". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000375
376# .help Show this message
shaneh5fc25012009-11-11 04:17:07 +0000377do_test shell1-3.10.1 {
shanehca7dfda2009-12-17 21:07:54 +0000378 set res [catchcmd "test.db" ".help"]
shaneha05e0c42009-11-06 03:22:54 +0000379 # look for a few of the possible help commands
380 list [regexp {.help} $res] \
381 [regexp {.quit} $res] \
382 [regexp {.show} $res]
383} {1 1 1}
shaneh5fc25012009-11-11 04:17:07 +0000384do_test shell1-3.10.2 {
shanehe2aa9d72009-11-06 17:20:17 +0000385 # we allow .help to take extra args (it is help after all)
shanehca7dfda2009-12-17 21:07:54 +0000386 set res [catchcmd "test.db" ".help BAD"]
shanehe2aa9d72009-11-06 17:20:17 +0000387 # look for a few of the possible help commands
388 list [regexp {.help} $res] \
389 [regexp {.quit} $res] \
390 [regexp {.show} $res]
391} {1 1 1}
shaneha05e0c42009-11-06 03:22:54 +0000392
393# .import FILE TABLE Import data from FILE into TABLE
shaneh5fc25012009-11-11 04:17:07 +0000394do_test shell1-3.11.1 {
shanehca7dfda2009-12-17 21:07:54 +0000395 catchcmd "test.db" ".import"
shaneha05e0c42009-11-06 03:22:54 +0000396} {1 {Error: unknown command or invalid arguments: "import". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000397do_test shell1-3.11.2 {
shanehca7dfda2009-12-17 21:07:54 +0000398 catchcmd "test.db" ".import FOO"
shaneha05e0c42009-11-06 03:22:54 +0000399} {1 {Error: unknown command or invalid arguments: "import". Enter ".help" for help}}
drhdb95f682013-06-26 22:46:00 +0000400#do_test shell1-3.11.2 {
401# catchcmd "test.db" ".import FOO BAR"
402#} {1 {Error: no such table: BAR}}
shaneh5fc25012009-11-11 04:17:07 +0000403do_test shell1-3.11.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000404 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000405 catchcmd "test.db" ".import FOO BAR BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000406} {1 {Error: unknown command or invalid arguments: "import". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000407
408# .indices ?TABLE? Show names of all indices
409# If TABLE specified, only show indices for tables
410# matching LIKE pattern TABLE.
shaneh5fc25012009-11-11 04:17:07 +0000411do_test shell1-3.12.1 {
shanehca7dfda2009-12-17 21:07:54 +0000412 catchcmd "test.db" ".indices"
shaneha05e0c42009-11-06 03:22:54 +0000413} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000414do_test shell1-3.12.2 {
shanehca7dfda2009-12-17 21:07:54 +0000415 catchcmd "test.db" ".indices FOO"
shaneha05e0c42009-11-06 03:22:54 +0000416} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000417do_test shell1-3.12.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000418 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000419 catchcmd "test.db" ".indices FOO BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000420} {1 {Error: unknown command or invalid arguments: "indices". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000421
422# .mode MODE ?TABLE? Set output mode where MODE is one of:
423# csv Comma-separated values
424# column Left-aligned columns. (See .width)
425# html HTML <table> code
426# insert SQL insert statements for TABLE
427# line One value per line
428# list Values delimited by .separator string
429# tabs Tab-separated values
430# tcl TCL list elements
shaneh5fc25012009-11-11 04:17:07 +0000431do_test shell1-3.13.1 {
shanehca7dfda2009-12-17 21:07:54 +0000432 catchcmd "test.db" ".mode"
shaneha05e0c42009-11-06 03:22:54 +0000433} {1 {Error: unknown command or invalid arguments: "mode". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000434do_test shell1-3.13.2 {
shanehca7dfda2009-12-17 21:07:54 +0000435 catchcmd "test.db" ".mode FOO"
shaneha05e0c42009-11-06 03:22:54 +0000436} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
shaneh5fc25012009-11-11 04:17:07 +0000437do_test shell1-3.13.3 {
shanehca7dfda2009-12-17 21:07:54 +0000438 catchcmd "test.db" ".mode csv"
shaneha05e0c42009-11-06 03:22:54 +0000439} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000440do_test shell1-3.13.4 {
shanehca7dfda2009-12-17 21:07:54 +0000441 catchcmd "test.db" ".mode column"
shaneha05e0c42009-11-06 03:22:54 +0000442} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000443do_test shell1-3.13.5 {
shanehca7dfda2009-12-17 21:07:54 +0000444 catchcmd "test.db" ".mode html"
shaneha05e0c42009-11-06 03:22:54 +0000445} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000446do_test shell1-3.13.6 {
shanehca7dfda2009-12-17 21:07:54 +0000447 catchcmd "test.db" ".mode insert"
shaneha05e0c42009-11-06 03:22:54 +0000448} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000449do_test shell1-3.13.7 {
shanehca7dfda2009-12-17 21:07:54 +0000450 catchcmd "test.db" ".mode line"
shaneha05e0c42009-11-06 03:22:54 +0000451} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000452do_test shell1-3.13.8 {
shanehca7dfda2009-12-17 21:07:54 +0000453 catchcmd "test.db" ".mode list"
shaneha05e0c42009-11-06 03:22:54 +0000454} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000455do_test shell1-3.13.9 {
shanehca7dfda2009-12-17 21:07:54 +0000456 catchcmd "test.db" ".mode tabs"
shaneha05e0c42009-11-06 03:22:54 +0000457} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000458do_test shell1-3.13.10 {
shanehca7dfda2009-12-17 21:07:54 +0000459 catchcmd "test.db" ".mode tcl"
shaneha05e0c42009-11-06 03:22:54 +0000460} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000461do_test shell1-3.13.11 {
shanehe2aa9d72009-11-06 17:20:17 +0000462 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000463 catchcmd "test.db" ".mode tcl BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000464} {1 {Error: invalid arguments: "BAD". Enter ".help" for help}}
465
466# don't allow partial mode type matches
shaneh5fc25012009-11-11 04:17:07 +0000467do_test shell1-3.13.12 {
shanehca7dfda2009-12-17 21:07:54 +0000468 catchcmd "test.db" ".mode l"
shanehe2aa9d72009-11-06 17:20:17 +0000469} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
shaneh5fc25012009-11-11 04:17:07 +0000470do_test shell1-3.13.13 {
shanehca7dfda2009-12-17 21:07:54 +0000471 catchcmd "test.db" ".mode li"
shanehe2aa9d72009-11-06 17:20:17 +0000472} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
shaneh5fc25012009-11-11 04:17:07 +0000473do_test shell1-3.13.14 {
shanehca7dfda2009-12-17 21:07:54 +0000474 catchcmd "test.db" ".mode lin"
shanehe2aa9d72009-11-06 17:20:17 +0000475} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
shaneha05e0c42009-11-06 03:22:54 +0000476
477# .nullvalue STRING Print STRING in place of NULL values
shaneh5fc25012009-11-11 04:17:07 +0000478do_test shell1-3.14.1 {
shanehca7dfda2009-12-17 21:07:54 +0000479 catchcmd "test.db" ".nullvalue"
shaneha05e0c42009-11-06 03:22:54 +0000480} {1 {Error: unknown command or invalid arguments: "nullvalue". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000481do_test shell1-3.14.2 {
shanehca7dfda2009-12-17 21:07:54 +0000482 catchcmd "test.db" ".nullvalue FOO"
shaneha05e0c42009-11-06 03:22:54 +0000483} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000484do_test shell1-3.14.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000485 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000486 catchcmd "test.db" ".nullvalue FOO BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000487} {1 {Error: unknown command or invalid arguments: "nullvalue". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000488
489# .output FILENAME Send output to FILENAME
shaneh5fc25012009-11-11 04:17:07 +0000490do_test shell1-3.15.1 {
shanehca7dfda2009-12-17 21:07:54 +0000491 catchcmd "test.db" ".output"
shaneha05e0c42009-11-06 03:22:54 +0000492} {1 {Error: unknown command or invalid arguments: "output". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000493do_test shell1-3.15.2 {
shanehca7dfda2009-12-17 21:07:54 +0000494 catchcmd "test.db" ".output FOO"
shaneha05e0c42009-11-06 03:22:54 +0000495} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000496do_test shell1-3.15.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000497 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000498 catchcmd "test.db" ".output FOO BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000499} {1 {Error: unknown command or invalid arguments: "output". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000500
501# .output stdout Send output to the screen
shaneh5fc25012009-11-11 04:17:07 +0000502do_test shell1-3.16.1 {
shanehca7dfda2009-12-17 21:07:54 +0000503 catchcmd "test.db" ".output stdout"
shaneha05e0c42009-11-06 03:22:54 +0000504} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000505do_test shell1-3.16.2 {
shanehe2aa9d72009-11-06 17:20:17 +0000506 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000507 catchcmd "test.db" ".output stdout BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000508} {1 {Error: unknown command or invalid arguments: "output". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000509
510# .prompt MAIN CONTINUE Replace the standard prompts
shaneh5fc25012009-11-11 04:17:07 +0000511do_test shell1-3.17.1 {
shanehca7dfda2009-12-17 21:07:54 +0000512 catchcmd "test.db" ".prompt"
shaneha05e0c42009-11-06 03:22:54 +0000513} {1 {Error: unknown command or invalid arguments: "prompt". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000514do_test shell1-3.17.2 {
shanehca7dfda2009-12-17 21:07:54 +0000515 catchcmd "test.db" ".prompt FOO"
shaneha05e0c42009-11-06 03:22:54 +0000516} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000517do_test shell1-3.17.3 {
shanehca7dfda2009-12-17 21:07:54 +0000518 catchcmd "test.db" ".prompt FOO BAR"
shaneha05e0c42009-11-06 03:22:54 +0000519} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000520do_test shell1-3.17.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000521 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000522 catchcmd "test.db" ".prompt FOO BAR BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000523} {1 {Error: unknown command or invalid arguments: "prompt". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000524
525# .quit Exit this program
shaneh5fc25012009-11-11 04:17:07 +0000526do_test shell1-3.18.1 {
shanehca7dfda2009-12-17 21:07:54 +0000527 catchcmd "test.db" ".quit"
shaneha05e0c42009-11-06 03:22:54 +0000528} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000529do_test shell1-3.18.2 {
shanehe2aa9d72009-11-06 17:20:17 +0000530 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000531 catchcmd "test.db" ".quit BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000532} {1 {Error: unknown command or invalid arguments: "quit". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000533
534# .read FILENAME Execute SQL in FILENAME
shaneh5fc25012009-11-11 04:17:07 +0000535do_test shell1-3.19.1 {
shanehca7dfda2009-12-17 21:07:54 +0000536 catchcmd "test.db" ".read"
shaneha05e0c42009-11-06 03:22:54 +0000537} {1 {Error: unknown command or invalid arguments: "read". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000538do_test shell1-3.19.2 {
shaneha05e0c42009-11-06 03:22:54 +0000539 file delete -force FOO
shanehca7dfda2009-12-17 21:07:54 +0000540 catchcmd "test.db" ".read FOO"
shaneha05e0c42009-11-06 03:22:54 +0000541} {1 {Error: cannot open "FOO"}}
shaneh5fc25012009-11-11 04:17:07 +0000542do_test shell1-3.19.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000543 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000544 catchcmd "test.db" ".read FOO BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000545} {1 {Error: unknown command or invalid arguments: "read". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000546
547# .restore ?DB? FILE Restore content of DB (default "main") from FILE
shaneh5fc25012009-11-11 04:17:07 +0000548do_test shell1-3.20.1 {
shanehca7dfda2009-12-17 21:07:54 +0000549 catchcmd "test.db" ".restore"
shaneha05e0c42009-11-06 03:22:54 +0000550} {1 {Error: unknown command or invalid arguments: "restore". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000551do_test shell1-3.20.2 {
shanehca7dfda2009-12-17 21:07:54 +0000552 catchcmd "test.db" ".restore FOO"
553} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000554do_test shell1-3.20.3 {
shanehca7dfda2009-12-17 21:07:54 +0000555 catchcmd "test.db" ".restore FOO BAR"
shanehe2aa9d72009-11-06 17:20:17 +0000556} {1 {Error: unknown database FOO}}
shaneh5fc25012009-11-11 04:17:07 +0000557do_test shell1-3.20.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000558 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000559 catchcmd "test.db" ".restore FOO BAR BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000560} {1 {Error: unknown command or invalid arguments: "restore". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000561
562# .schema ?TABLE? Show the CREATE statements
563# If TABLE specified, only show tables matching
564# LIKE pattern TABLE.
shaneh5fc25012009-11-11 04:17:07 +0000565do_test shell1-3.21.1 {
shanehca7dfda2009-12-17 21:07:54 +0000566 catchcmd "test.db" ".schema"
shaneha05e0c42009-11-06 03:22:54 +0000567} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000568do_test shell1-3.21.2 {
shanehca7dfda2009-12-17 21:07:54 +0000569 catchcmd "test.db" ".schema FOO"
shaneha05e0c42009-11-06 03:22:54 +0000570} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000571do_test shell1-3.21.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000572 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000573 catchcmd "test.db" ".schema FOO BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000574} {1 {Error: unknown command or invalid arguments: "schema". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000575
drhac43e982012-05-21 03:15:06 +0000576do_test shell1-3.21.4 {
577 catchcmd "test.db" {
578 CREATE TABLE t1(x);
579 CREATE VIEW v2 AS SELECT x+1 AS y FROM t1;
580 CREATE VIEW v1 AS SELECT y+1 FROM v2;
581 }
582 catchcmd "test.db" ".schema"
583} {0 {CREATE TABLE t1(x);
584CREATE VIEW v2 AS SELECT x+1 AS y FROM t1;
585CREATE VIEW v1 AS SELECT y+1 FROM v2;}}
586db eval {DROP VIEW v1; DROP VIEW v2; DROP TABLE t1;}
587
shaneha05e0c42009-11-06 03:22:54 +0000588# .separator STRING Change separator used by output mode and .import
shaneh5fc25012009-11-11 04:17:07 +0000589do_test shell1-3.22.1 {
shanehca7dfda2009-12-17 21:07:54 +0000590 catchcmd "test.db" ".separator"
shaneha05e0c42009-11-06 03:22:54 +0000591} {1 {Error: unknown command or invalid arguments: "separator". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000592do_test shell1-3.22.2 {
shanehca7dfda2009-12-17 21:07:54 +0000593 catchcmd "test.db" ".separator FOO"
shaneha05e0c42009-11-06 03:22:54 +0000594} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000595do_test shell1-3.22.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000596 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000597 catchcmd "test.db" ".separator FOO BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000598} {1 {Error: unknown command or invalid arguments: "separator". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000599
600# .show Show the current values for various settings
shaneh5fc25012009-11-11 04:17:07 +0000601do_test shell1-3.23.1 {
shanehca7dfda2009-12-17 21:07:54 +0000602 set res [catchcmd "test.db" ".show"]
shaneha05e0c42009-11-06 03:22:54 +0000603 list [regexp {echo:} $res] \
604 [regexp {explain:} $res] \
605 [regexp {headers:} $res] \
606 [regexp {mode:} $res] \
607 [regexp {nullvalue:} $res] \
608 [regexp {output:} $res] \
609 [regexp {separator:} $res] \
shaneh642d8b82010-07-28 16:05:34 +0000610 [regexp {stats:} $res] \
shaneha05e0c42009-11-06 03:22:54 +0000611 [regexp {width:} $res]
shaneh642d8b82010-07-28 16:05:34 +0000612} {1 1 1 1 1 1 1 1 1}
shaneh5fc25012009-11-11 04:17:07 +0000613do_test shell1-3.23.2 {
shanehe2aa9d72009-11-06 17:20:17 +0000614 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000615 catchcmd "test.db" ".show BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000616} {1 {Error: unknown command or invalid arguments: "show". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000617
shaneh642d8b82010-07-28 16:05:34 +0000618# .stats ON|OFF Turn stats on or off
619do_test shell1-3.23b.1 {
620 catchcmd "test.db" ".stats"
621} {1 {Error: unknown command or invalid arguments: "stats". Enter ".help" for help}}
622do_test shell1-3.23b.2 {
623 catchcmd "test.db" ".stats ON"
624} {0 {}}
625do_test shell1-3.23b.3 {
626 catchcmd "test.db" ".stats OFF"
627} {0 {}}
628do_test shell1-3.23b.4 {
629 # too many arguments
630 catchcmd "test.db" ".stats OFF BAD"
631} {1 {Error: unknown command or invalid arguments: "stats". Enter ".help" for help}}
632
shaneha05e0c42009-11-06 03:22:54 +0000633# .tables ?TABLE? List names of tables
634# If TABLE specified, only list tables matching
635# LIKE pattern TABLE.
shaneh5fc25012009-11-11 04:17:07 +0000636do_test shell1-3.24.1 {
shanehca7dfda2009-12-17 21:07:54 +0000637 catchcmd "test.db" ".tables"
shaneha05e0c42009-11-06 03:22:54 +0000638} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000639do_test shell1-3.24.2 {
shanehca7dfda2009-12-17 21:07:54 +0000640 catchcmd "test.db" ".tables FOO"
shaneha05e0c42009-11-06 03:22:54 +0000641} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000642do_test shell1-3.24.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000643 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000644 catchcmd "test.db" ".tables FOO BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000645} {1 {Error: unknown command or invalid arguments: "tables". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000646
647# .timeout MS Try opening locked tables for MS milliseconds
shaneh5fc25012009-11-11 04:17:07 +0000648do_test shell1-3.25.1 {
shanehca7dfda2009-12-17 21:07:54 +0000649 catchcmd "test.db" ".timeout"
shaneha05e0c42009-11-06 03:22:54 +0000650} {1 {Error: unknown command or invalid arguments: "timeout". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000651do_test shell1-3.25.2 {
shanehca7dfda2009-12-17 21:07:54 +0000652 catchcmd "test.db" ".timeout zzz"
shanehe2aa9d72009-11-06 17:20:17 +0000653 # this should be treated the same as a '0' timeout
shaneha05e0c42009-11-06 03:22:54 +0000654} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000655do_test shell1-3.25.3 {
shanehca7dfda2009-12-17 21:07:54 +0000656 catchcmd "test.db" ".timeout 1"
shaneha05e0c42009-11-06 03:22:54 +0000657} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000658do_test shell1-3.25.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000659 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000660 catchcmd "test.db" ".timeout 1 BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000661} {1 {Error: unknown command or invalid arguments: "timeout". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000662
663# .width NUM NUM ... Set column widths for "column" mode
shaneh5fc25012009-11-11 04:17:07 +0000664do_test shell1-3.26.1 {
shanehca7dfda2009-12-17 21:07:54 +0000665 catchcmd "test.db" ".width"
shanehe2aa9d72009-11-06 17:20:17 +0000666} {1 {Error: unknown command or invalid arguments: "width". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000667do_test shell1-3.26.2 {
shanehca7dfda2009-12-17 21:07:54 +0000668 catchcmd "test.db" ".width xxx"
shanehe2aa9d72009-11-06 17:20:17 +0000669 # this should be treated the same as a '0' width for col 1
shaneha05e0c42009-11-06 03:22:54 +0000670} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000671do_test shell1-3.26.3 {
shanehca7dfda2009-12-17 21:07:54 +0000672 catchcmd "test.db" ".width xxx yyy"
shanehe2aa9d72009-11-06 17:20:17 +0000673 # this should be treated the same as a '0' width for col 1 and 2
shaneha05e0c42009-11-06 03:22:54 +0000674} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000675do_test shell1-3.26.4 {
shanehca7dfda2009-12-17 21:07:54 +0000676 catchcmd "test.db" ".width 1 1"
shanehe2aa9d72009-11-06 17:20:17 +0000677 # this should be treated the same as a '1' width for col 1 and 2
shaneha05e0c42009-11-06 03:22:54 +0000678} {0 {}}
drh078b1fd2012-09-21 13:40:02 +0000679do_test shell1-3.26.5 {
680 catchcmd "test.db" ".mode column\n.width 10 -10\nSELECT 'abcdefg', 123456;"
681 # this should be treated the same as a '1' width for col 1 and 2
682} {0 {abcdefg 123456}}
683do_test shell1-3.26.6 {
684 catchcmd "test.db" ".mode column\n.width -10 10\nSELECT 'abcdefg', 123456;"
685 # this should be treated the same as a '1' width for col 1 and 2
686} {0 { abcdefg 123456 }}
687
shaneha05e0c42009-11-06 03:22:54 +0000688
689# .timer ON|OFF Turn the CPU timer measurement on or off
shaneh5fc25012009-11-11 04:17:07 +0000690do_test shell1-3.27.1 {
shanehca7dfda2009-12-17 21:07:54 +0000691 catchcmd "test.db" ".timer"
shaneha05e0c42009-11-06 03:22:54 +0000692} {1 {Error: unknown command or invalid arguments: "timer". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000693do_test shell1-3.27.2 {
shanehca7dfda2009-12-17 21:07:54 +0000694 catchcmd "test.db" ".timer ON"
shaneha05e0c42009-11-06 03:22:54 +0000695} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000696do_test shell1-3.27.3 {
shanehca7dfda2009-12-17 21:07:54 +0000697 catchcmd "test.db" ".timer OFF"
shaneha05e0c42009-11-06 03:22:54 +0000698} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000699do_test shell1-3.27.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000700 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000701 catchcmd "test.db" ".timer OFF BAD"
shanehe2aa9d72009-11-06 17:20:17 +0000702} {1 {Error: unknown command or invalid arguments: "timer". Enter ".help" for help}}
shaneha05e0c42009-11-06 03:22:54 +0000703
drh53a9d152011-04-25 18:20:04 +0000704do_test shell1-3-28.1 {
705 catchcmd test.db \
706 ".log stdout\nSELECT coalesce(sqlite_log(123,'hello'),'456');"
707} "0 {(123) hello\n456}"
708
drh078b1fd2012-09-21 13:40:02 +0000709do_test shell1-3-29.1 {
710 catchcmd "test.db" ".print this is a test"
711} {0 {this is a test}}
712
drh4c56b992013-06-27 13:26:55 +0000713# dot-command argument quoting
714do_test shell1-3-30.1 {
715 catchcmd {test.db} {.print "this\"is'a\055test" 'this\"is\\a\055test'}
716} {0 {this"is'a-test this\"is\\a\055test}}
717do_test shell1-3-31.1 {
718 catchcmd {test.db} {.print "this\nis\ta\\test" 'this\nis\ta\\test'}
719} [list 0 "this\nis\ta\\test this\\nis\\ta\\\\test"]
720
721
drh5128e852012-04-24 13:14:49 +0000722# Test the output of the ".dump" command
723#
724do_test shell1-4.1 {
drh55a1b302013-09-04 16:08:50 +0000725 db close
726 forcedelete test.db
727 sqlite3 db test.db
drh5128e852012-04-24 13:14:49 +0000728 db eval {
drh55a1b302013-09-04 16:08:50 +0000729 PRAGMA encoding=UTF16;
drh5128e852012-04-24 13:14:49 +0000730 CREATE TABLE t1(x);
mistachkin585dcb22012-12-04 00:23:43 +0000731 INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f');
drh5128e852012-04-24 13:14:49 +0000732 }
733 catchcmd test.db {.dump}
734} {0 {PRAGMA foreign_keys=OFF;
735BEGIN TRANSACTION;
736CREATE TABLE t1(x);
737INSERT INTO "t1" VALUES(NULL);
mistachkin585dcb22012-12-04 00:23:43 +0000738INSERT INTO "t1" VALUES('');
drh5128e852012-04-24 13:14:49 +0000739INSERT INTO "t1" VALUES(1);
740INSERT INTO "t1" VALUES(2.25);
741INSERT INTO "t1" VALUES('hello');
742INSERT INTO "t1" VALUES(X'807F');
743COMMIT;}}
744
745# Test the output of ".mode insert"
746#
747do_test shell1-4.2 {
748 catchcmd test.db ".mode insert t1\nselect * from t1;"
749} {0 {INSERT 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');}}
755
mistachkin585dcb22012-12-04 00:23:43 +0000756# Test the output of ".mode tcl"
757#
758do_test shell1-4.3 {
drh55a1b302013-09-04 16:08:50 +0000759 db close
760 forcedelete test.db
761 sqlite3 db test.db
762 db eval {
763 PRAGMA encoding=UTF8;
764 CREATE TABLE t1(x);
765 INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f');
766 }
mistachkin585dcb22012-12-04 00:23:43 +0000767 catchcmd test.db ".mode tcl\nselect * from t1;"
768} {0 {""
769""
770"1"
771"2.25"
772"hello"
773"\200\177"}}
774
775# Test the output of ".mode tcl" with multiple columns
776#
777do_test shell1-4.4 {
778 db eval {
779 CREATE TABLE t2(x,y);
780 INSERT INTO t2 VALUES(null, ''), (1, 2.25), ('hello', x'807f');
781 }
782 catchcmd test.db ".mode tcl\nselect * from t2;"
783} {0 {"" ""
784"1" "2.25"
785"hello" "\200\177"}}
786
787# Test the output of ".mode tcl" with ".nullvalue"
788#
789do_test shell1-4.5 {
790 catchcmd test.db ".mode tcl\n.nullvalue NULL\nselect * from t2;"
791} {0 {"NULL" ""
792"1" "2.25"
793"hello" "\200\177"}}
794
795# Test the output of ".mode tcl" with Tcl reserved characters
796#
797do_test shell1-4.6 {
798 db eval {
799 CREATE TABLE tcl1(x);
800 INSERT INTO tcl1 VALUES('"'), ('['), (']'), ('\{'), ('\}'), (';'), ('$');
801 }
802 foreach {x y} [catchcmd test.db ".mode tcl\nselect * from tcl1;"] break
803 list $x $y [llength $y]
804} {0 {"\""
805"["
806"]"
807"\\{"
808"\\}"
809";"
810"$"} 7}
drh5128e852012-04-24 13:14:49 +0000811
drh8df91852012-04-24 12:46:05 +0000812finish_test