blob: 760c85fadc54a3db6af7d67553f09fb25bdb42ec [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
dan089555c2016-03-15 09:55:44 +000024set CLI [test_find_cli]
drh8df91852012-04-24 12:46:05 +000025db close
26forcedelete test.db test.db-journal test.db-wal
shaneha05e0c42009-11-06 03:22:54 +000027sqlite3 db test.db
28
shaneh5fc25012009-11-11 04:17:07 +000029#----------------------------------------------------------------------------
30# Test cases shell1-1.*: Basic command line option handling.
31#
32
33# invalid option
34do_test shell1-1.1.1 {
35 set res [catchcmd "-bad test.db" ""]
36 set rc [lindex $res 0]
37 list $rc \
38 [regexp {Error: unknown option: -bad} $res]
39} {1 1}
drhac5649a2014-11-28 13:35:03 +000040do_test shell1-1.1.1b {
41 set res [catchcmd "test.db -bad" ""]
42 set rc [lindex $res 0]
43 list $rc \
44 [regexp {Error: unknown option: -bad} $res]
45} {1 1}
shaneh5fc25012009-11-11 04:17:07 +000046# error on extra options
47do_test shell1-1.1.2 {
drh60c42492016-03-26 15:36:36 +000048 catchcmd "test.db \"select+3\" \"select+4\"" ""
drhac5649a2014-11-28 13:35:03 +000049} {0 {3
504}}
shaneh5fc25012009-11-11 04:17:07 +000051# error on extra options
shanehca7dfda2009-12-17 21:07:54 +000052do_test shell1-1.1.3 {
drhac5649a2014-11-28 13:35:03 +000053 catchcmd "test.db FOO test.db BAD" ".quit"
54} {1 {Error: near "FOO": syntax error}}
shaneh5fc25012009-11-11 04:17:07 +000055
56# -help
57do_test shell1-1.2.1 {
58 set res [catchcmd "-help test.db" ""]
59 set rc [lindex $res 0]
60 list $rc \
61 [regexp {Usage} $res] \
62 [regexp {\-init} $res] \
63 [regexp {\-version} $res]
64} {1 1 1 1}
65
66# -init filename read/process named file
67do_test shell1-1.3.1 {
shanehca7dfda2009-12-17 21:07:54 +000068 catchcmd "-init FOO test.db" ""
shaneh5fc25012009-11-11 04:17:07 +000069} {0 {}}
70do_test shell1-1.3.2 {
drhac5649a2014-11-28 13:35:03 +000071 catchcmd "-init FOO test.db .quit BAD" ""
72} {0 {}}
73do_test shell1-1.3.3 {
74 catchcmd "-init FOO test.db BAD .quit" ""
75} {1 {Error: near "BAD": syntax error}}
shaneh5fc25012009-11-11 04:17:07 +000076
77# -echo print commands before execution
78do_test shell1-1.4.1 {
mistachkin1fe36bb2016-04-04 02:16:44 +000079 catchcmd "-echo test.db" ""
shaneh5fc25012009-11-11 04:17:07 +000080} {0 {}}
81
82# -[no]header turn headers on or off
83do_test shell1-1.5.1 {
mistachkin1fe36bb2016-04-04 02:16:44 +000084 catchcmd "-header test.db" ""
shaneh5fc25012009-11-11 04:17:07 +000085} {0 {}}
86do_test shell1-1.5.2 {
mistachkin1fe36bb2016-04-04 02:16:44 +000087 catchcmd "-noheader test.db" ""
shaneh5fc25012009-11-11 04:17:07 +000088} {0 {}}
89
90# -bail stop after hitting an error
91do_test shell1-1.6.1 {
mistachkin1fe36bb2016-04-04 02:16:44 +000092 catchcmd "-bail test.db" ""
shaneh5fc25012009-11-11 04:17:07 +000093} {0 {}}
94
95# -interactive force interactive I/O
96do_test shell1-1.7.1 {
97 set res [catchcmd "-interactive test.db" ".quit"]
98 set rc [lindex $res 0]
99 list $rc \
100 [regexp {SQLite version} $res] \
drh39a30882014-02-11 16:22:18 +0000101 [regexp {Enter ".help" for usage hints} $res]
shaneh5fc25012009-11-11 04:17:07 +0000102} {0 1 1}
103
104# -batch force batch I/O
105do_test shell1-1.8.1 {
mistachkin1fe36bb2016-04-04 02:16:44 +0000106 catchcmd "-batch test.db" ""
shaneh5fc25012009-11-11 04:17:07 +0000107} {0 {}}
108
109# -column set output mode to 'column'
110do_test shell1-1.9.1 {
mistachkin1fe36bb2016-04-04 02:16:44 +0000111 catchcmd "-column test.db" ""
shaneh5fc25012009-11-11 04:17:07 +0000112} {0 {}}
113
114# -csv set output mode to 'csv'
115do_test shell1-1.10.1 {
mistachkin1fe36bb2016-04-04 02:16:44 +0000116 catchcmd "-csv test.db" ""
shaneh5fc25012009-11-11 04:17:07 +0000117} {0 {}}
118
119# -html set output mode to HTML
120do_test shell1-1.11.1 {
mistachkin1fe36bb2016-04-04 02:16:44 +0000121 catchcmd "-html test.db" ""
shaneh5fc25012009-11-11 04:17:07 +0000122} {0 {}}
123
124# -line set output mode to 'line'
125do_test shell1-1.12.1 {
mistachkin1fe36bb2016-04-04 02:16:44 +0000126 catchcmd "-line test.db" ""
shaneh5fc25012009-11-11 04:17:07 +0000127} {0 {}}
128
129# -list set output mode to 'list'
130do_test shell1-1.13.1 {
mistachkin1fe36bb2016-04-04 02:16:44 +0000131 catchcmd "-list test.db" ""
shaneh5fc25012009-11-11 04:17:07 +0000132} {0 {}}
133
134# -separator 'x' set output field separator (|)
135do_test shell1-1.14.1 {
mistachkin1fe36bb2016-04-04 02:16:44 +0000136 catchcmd "-separator 'x' test.db" ""
shaneh5fc25012009-11-11 04:17:07 +0000137} {0 {}}
138do_test shell1-1.14.2 {
mistachkin1fe36bb2016-04-04 02:16:44 +0000139 catchcmd "-separator x test.db" ""
shaneh5fc25012009-11-11 04:17:07 +0000140} {0 {}}
141do_test shell1-1.14.3 {
142 set res [catchcmd "-separator" ""]
143 set rc [lindex $res 0]
144 list $rc \
drh98d312f2012-10-25 15:23:14 +0000145 [regexp {Error: missing argument to -separator} $res]
shaneh5fc25012009-11-11 04:17:07 +0000146} {1 1}
147
shaneh642d8b82010-07-28 16:05:34 +0000148# -stats print memory stats before each finalize
149do_test shell1-1.14b.1 {
mistachkin1fe36bb2016-04-04 02:16:44 +0000150 catchcmd "-stats test.db" ""
shaneh642d8b82010-07-28 16:05:34 +0000151} {0 {}}
152
shaneh5fc25012009-11-11 04:17:07 +0000153# -nullvalue 'text' set text string for NULL values
154do_test shell1-1.15.1 {
155 catchcmd "-nullvalue 'x' test.db" ""
156} {0 {}}
157do_test shell1-1.15.2 {
158 catchcmd "-nullvalue x test.db" ""
159} {0 {}}
160do_test shell1-1.15.3 {
161 set res [catchcmd "-nullvalue" ""]
162 set rc [lindex $res 0]
163 list $rc \
drh98d312f2012-10-25 15:23:14 +0000164 [regexp {Error: missing argument to -nullvalue} $res]
shaneh5fc25012009-11-11 04:17:07 +0000165} {1 1}
166
167# -version show SQLite version
168do_test shell1-1.16.1 {
drh9fd301b2011-06-03 13:28:22 +0000169 set x [catchcmd "-version test.db" ""]
drhb24c61a2012-05-21 22:45:35 +0000170} {/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 +0000171
shaneha05e0c42009-11-06 03:22:54 +0000172#----------------------------------------------------------------------------
shaneh5fc25012009-11-11 04:17:07 +0000173# Test cases shell1-2.*: Basic "dot" command token parsing.
shanehe2aa9d72009-11-06 17:20:17 +0000174#
175
176# check first token handling
shaneh5fc25012009-11-11 04:17:07 +0000177do_test shell1-2.1.1 {
mistachkin1fe36bb2016-04-04 02:16:44 +0000178 catchcmd "test.db" ".foo"
shanehe2aa9d72009-11-06 17:20:17 +0000179} {1 {Error: unknown command or invalid arguments: "foo". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000180do_test shell1-2.1.2 {
shanehca7dfda2009-12-17 21:07:54 +0000181 catchcmd "test.db" ".\"foo OFF\""
shanehe2aa9d72009-11-06 17:20:17 +0000182} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000183do_test shell1-2.1.3 {
shanehca7dfda2009-12-17 21:07:54 +0000184 catchcmd "test.db" ".\'foo OFF\'"
shanehe2aa9d72009-11-06 17:20:17 +0000185} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}}
186
187# unbalanced quotes
shaneh5fc25012009-11-11 04:17:07 +0000188do_test shell1-2.2.1 {
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.2.2 {
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}}
shaneh5fc25012009-11-11 04:17:07 +0000194do_test shell1-2.2.3 {
shanehca7dfda2009-12-17 21:07:54 +0000195 catchcmd "test.db" ".explain \"OFF"
shanehe2aa9d72009-11-06 17:20:17 +0000196} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000197do_test shell1-2.2.4 {
shanehca7dfda2009-12-17 21:07:54 +0000198 catchcmd "test.db" ".explain \'OFF"
shanehe2aa9d72009-11-06 17:20:17 +0000199} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000200do_test shell1-2.2.5 {
shanehca7dfda2009-12-17 21:07:54 +0000201 catchcmd "test.db" ".mode \"insert FOO"
mistachkin636bf9f2014-07-19 20:15:16 +0000202} {1 {Error: mode should be one of: ascii column csv html insert line list tabs tcl}}
shaneh5fc25012009-11-11 04:17:07 +0000203do_test shell1-2.2.6 {
shanehca7dfda2009-12-17 21:07:54 +0000204 catchcmd "test.db" ".mode \'insert FOO"
mistachkin636bf9f2014-07-19 20:15:16 +0000205} {1 {Error: mode should be one of: ascii column csv html insert line list tabs tcl}}
shanehe2aa9d72009-11-06 17:20:17 +0000206
207# check multiple tokens, and quoted tokens
shaneh5fc25012009-11-11 04:17:07 +0000208do_test shell1-2.3.1 {
shanehca7dfda2009-12-17 21:07:54 +0000209 catchcmd "test.db" ".explain 1"
shanehe2aa9d72009-11-06 17:20:17 +0000210} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000211do_test shell1-2.3.2 {
shanehca7dfda2009-12-17 21:07:54 +0000212 catchcmd "test.db" ".explain on"
shanehe2aa9d72009-11-06 17:20:17 +0000213} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000214do_test shell1-2.3.3 {
shanehca7dfda2009-12-17 21:07:54 +0000215 catchcmd "test.db" ".explain \"1 2 3\""
drh173ba092013-01-28 18:18:26 +0000216} {1 {ERROR: Not a boolean value: "1 2 3". Assuming "no".}}
shaneh5fc25012009-11-11 04:17:07 +0000217do_test shell1-2.3.4 {
shanehca7dfda2009-12-17 21:07:54 +0000218 catchcmd "test.db" ".explain \"OFF\""
shanehe2aa9d72009-11-06 17:20:17 +0000219} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000220do_test shell1-2.3.5 {
shanehca7dfda2009-12-17 21:07:54 +0000221 catchcmd "test.db" ".\'explain\' \'OFF\'"
shanehe2aa9d72009-11-06 17:20:17 +0000222} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000223do_test shell1-2.3.6 {
shanehca7dfda2009-12-17 21:07:54 +0000224 catchcmd "test.db" ".explain \'OFF\'"
shanehe2aa9d72009-11-06 17:20:17 +0000225} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000226do_test shell1-2.3.7 {
shanehca7dfda2009-12-17 21:07:54 +0000227 catchcmd "test.db" ".\'explain\' \'OFF\'"
shanehe2aa9d72009-11-06 17:20:17 +0000228} {0 {}}
229
230# check quoted args are unquoted
shaneh5fc25012009-11-11 04:17:07 +0000231do_test shell1-2.4.1 {
shanehca7dfda2009-12-17 21:07:54 +0000232 catchcmd "test.db" ".mode FOO"
mistachkin636bf9f2014-07-19 20:15:16 +0000233} {1 {Error: mode should be one of: ascii column csv html insert line list tabs tcl}}
shaneh5fc25012009-11-11 04:17:07 +0000234do_test shell1-2.4.2 {
shanehca7dfda2009-12-17 21:07:54 +0000235 catchcmd "test.db" ".mode csv"
shanehe2aa9d72009-11-06 17:20:17 +0000236} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000237do_test shell1-2.4.2 {
shanehca7dfda2009-12-17 21:07:54 +0000238 catchcmd "test.db" ".mode \"csv\""
shanehe2aa9d72009-11-06 17:20:17 +0000239} {0 {}}
240
241
242#----------------------------------------------------------------------------
shaneh5fc25012009-11-11 04:17:07 +0000243# Test cases shell1-3.*: Basic test that "dot" command can be called.
shaneha05e0c42009-11-06 03:22:54 +0000244#
245
246# .backup ?DB? FILE Backup DB (default "main") to FILE
shaneh5fc25012009-11-11 04:17:07 +0000247do_test shell1-3.1.1 {
shanehca7dfda2009-12-17 21:07:54 +0000248 catchcmd "test.db" ".backup"
drhbc46f022013-01-23 18:53:23 +0000249} {1 {missing FILENAME argument on .backup}}
shaneh5fc25012009-11-11 04:17:07 +0000250do_test shell1-3.1.2 {
shanehca7dfda2009-12-17 21:07:54 +0000251 catchcmd "test.db" ".backup FOO"
252} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000253do_test shell1-3.1.3 {
shanehca7dfda2009-12-17 21:07:54 +0000254 catchcmd "test.db" ".backup FOO BAR"
shanehe2aa9d72009-11-06 17:20:17 +0000255} {1 {Error: unknown database FOO}}
shaneh5fc25012009-11-11 04:17:07 +0000256do_test shell1-3.1.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000257 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000258 catchcmd "test.db" ".backup FOO BAR BAD"
drhbc46f022013-01-23 18:53:23 +0000259} {1 {too many arguments to .backup}}
shaneha05e0c42009-11-06 03:22:54 +0000260
261# .bail ON|OFF Stop after hitting an error. Default OFF
shaneh5fc25012009-11-11 04:17:07 +0000262do_test shell1-3.2.1 {
shanehca7dfda2009-12-17 21:07:54 +0000263 catchcmd "test.db" ".bail"
drhc2ce0be2014-05-29 12:36:14 +0000264} {1 {Usage: .bail on|off}}
shaneh5fc25012009-11-11 04:17:07 +0000265do_test shell1-3.2.2 {
shanehca7dfda2009-12-17 21:07:54 +0000266 catchcmd "test.db" ".bail ON"
shaneha05e0c42009-11-06 03:22:54 +0000267} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000268do_test shell1-3.2.3 {
shanehca7dfda2009-12-17 21:07:54 +0000269 catchcmd "test.db" ".bail OFF"
shaneha05e0c42009-11-06 03:22:54 +0000270} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000271do_test shell1-3.2.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000272 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000273 catchcmd "test.db" ".bail OFF BAD"
drhc2ce0be2014-05-29 12:36:14 +0000274} {1 {Usage: .bail on|off}}
shaneha05e0c42009-11-06 03:22:54 +0000275
276# .databases List names and files of attached databases
shaneh5fc25012009-11-11 04:17:07 +0000277do_test shell1-3.3.1 {
drheaa544d2016-03-26 14:41:13 +0000278 catchcmd "-csv test.db" ".databases"
drh15707ac2016-03-26 13:26:35 +0000279} "/0.+main.+[string map {/ ".{1,2}"} [string range [get_pwd] 0 10]].*/"
shaneh5fc25012009-11-11 04:17:07 +0000280do_test shell1-3.3.2 {
drhc2ce0be2014-05-29 12:36:14 +0000281 # extra arguments ignored
drheaa544d2016-03-26 14:41:13 +0000282 catchcmd "test.db" ".databases BAD"
drh15707ac2016-03-26 13:26:35 +0000283} "/0.+main.+[string map {/ ".{1,2}"} [string range [get_pwd] 0 10]].*/"
shaneha05e0c42009-11-06 03:22:54 +0000284
285# .dump ?TABLE? ... Dump the database in an SQL text format
286# If TABLE specified, only dump tables matching
287# LIKE pattern TABLE.
shaneh5fc25012009-11-11 04:17:07 +0000288do_test shell1-3.4.1 {
shanehca7dfda2009-12-17 21:07:54 +0000289 set res [catchcmd "test.db" ".dump"]
shaneha05e0c42009-11-06 03:22:54 +0000290 list [regexp {BEGIN TRANSACTION;} $res] \
291 [regexp {COMMIT;} $res]
292} {1 1}
shaneh5fc25012009-11-11 04:17:07 +0000293do_test shell1-3.4.2 {
shanehca7dfda2009-12-17 21:07:54 +0000294 set res [catchcmd "test.db" ".dump FOO"]
shaneha05e0c42009-11-06 03:22:54 +0000295 list [regexp {BEGIN TRANSACTION;} $res] \
296 [regexp {COMMIT;} $res]
297} {1 1}
shaneh5fc25012009-11-11 04:17:07 +0000298do_test shell1-3.4.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000299 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000300 catchcmd "test.db" ".dump FOO BAD"
drhc2ce0be2014-05-29 12:36:14 +0000301} {1 {Usage: .dump ?LIKE-PATTERN?}}
shaneha05e0c42009-11-06 03:22:54 +0000302
303# .echo ON|OFF Turn command echo on or off
shaneh5fc25012009-11-11 04:17:07 +0000304do_test shell1-3.5.1 {
shanehca7dfda2009-12-17 21:07:54 +0000305 catchcmd "test.db" ".echo"
drhc2ce0be2014-05-29 12:36:14 +0000306} {1 {Usage: .echo on|off}}
shaneh5fc25012009-11-11 04:17:07 +0000307do_test shell1-3.5.2 {
shanehca7dfda2009-12-17 21:07:54 +0000308 catchcmd "test.db" ".echo ON"
shaneha05e0c42009-11-06 03:22:54 +0000309} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000310do_test shell1-3.5.3 {
shanehca7dfda2009-12-17 21:07:54 +0000311 catchcmd "test.db" ".echo OFF"
shaneha05e0c42009-11-06 03:22:54 +0000312} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000313do_test shell1-3.5.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000314 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000315 catchcmd "test.db" ".echo OFF BAD"
drhc2ce0be2014-05-29 12:36:14 +0000316} {1 {Usage: .echo on|off}}
shaneha05e0c42009-11-06 03:22:54 +0000317
318# .exit Exit this program
shaneh5fc25012009-11-11 04:17:07 +0000319do_test shell1-3.6.1 {
shanehca7dfda2009-12-17 21:07:54 +0000320 catchcmd "test.db" ".exit"
shaneha05e0c42009-11-06 03:22:54 +0000321} {0 {}}
322
323# .explain ON|OFF Turn output mode suitable for EXPLAIN on or off.
shaneh5fc25012009-11-11 04:17:07 +0000324do_test shell1-3.7.1 {
shanehca7dfda2009-12-17 21:07:54 +0000325 catchcmd "test.db" ".explain"
shanehe2aa9d72009-11-06 17:20:17 +0000326 # explain is the exception to the booleans. without an option, it turns it on.
327} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000328do_test shell1-3.7.2 {
shanehca7dfda2009-12-17 21:07:54 +0000329 catchcmd "test.db" ".explain ON"
shaneha05e0c42009-11-06 03:22:54 +0000330} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000331do_test shell1-3.7.3 {
shanehca7dfda2009-12-17 21:07:54 +0000332 catchcmd "test.db" ".explain OFF"
shaneha05e0c42009-11-06 03:22:54 +0000333} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000334do_test shell1-3.7.4 {
drhc2ce0be2014-05-29 12:36:14 +0000335 # extra arguments ignored
shanehca7dfda2009-12-17 21:07:54 +0000336 catchcmd "test.db" ".explain OFF BAD"
drhc2ce0be2014-05-29 12:36:14 +0000337} {0 {}}
shaneha05e0c42009-11-06 03:22:54 +0000338
shaneha05e0c42009-11-06 03:22:54 +0000339
340# .header(s) ON|OFF Turn display of headers on or off
shaneh5fc25012009-11-11 04:17:07 +0000341do_test shell1-3.9.1 {
shanehca7dfda2009-12-17 21:07:54 +0000342 catchcmd "test.db" ".header"
drhc2ce0be2014-05-29 12:36:14 +0000343} {1 {Usage: .headers on|off}}
shaneh5fc25012009-11-11 04:17:07 +0000344do_test shell1-3.9.2 {
shanehca7dfda2009-12-17 21:07:54 +0000345 catchcmd "test.db" ".header ON"
shaneha05e0c42009-11-06 03:22:54 +0000346} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000347do_test shell1-3.9.3 {
shanehca7dfda2009-12-17 21:07:54 +0000348 catchcmd "test.db" ".header OFF"
shaneha05e0c42009-11-06 03:22:54 +0000349} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000350do_test shell1-3.9.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000351 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000352 catchcmd "test.db" ".header OFF BAD"
drhc2ce0be2014-05-29 12:36:14 +0000353} {1 {Usage: .headers on|off}}
shanehe2aa9d72009-11-06 17:20:17 +0000354
shaneh5fc25012009-11-11 04:17:07 +0000355do_test shell1-3.9.5 {
shanehca7dfda2009-12-17 21:07:54 +0000356 catchcmd "test.db" ".headers"
drhc2ce0be2014-05-29 12:36:14 +0000357} {1 {Usage: .headers on|off}}
shaneh5fc25012009-11-11 04:17:07 +0000358do_test shell1-3.9.6 {
shanehca7dfda2009-12-17 21:07:54 +0000359 catchcmd "test.db" ".headers ON"
shaneha05e0c42009-11-06 03:22:54 +0000360} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000361do_test shell1-3.9.7 {
shanehca7dfda2009-12-17 21:07:54 +0000362 catchcmd "test.db" ".headers OFF"
shaneha05e0c42009-11-06 03:22:54 +0000363} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000364do_test shell1-3.9.8 {
shanehe2aa9d72009-11-06 17:20:17 +0000365 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000366 catchcmd "test.db" ".headers OFF BAD"
drhc2ce0be2014-05-29 12:36:14 +0000367} {1 {Usage: .headers on|off}}
shaneha05e0c42009-11-06 03:22:54 +0000368
369# .help Show this message
shaneh5fc25012009-11-11 04:17:07 +0000370do_test shell1-3.10.1 {
shanehca7dfda2009-12-17 21:07:54 +0000371 set res [catchcmd "test.db" ".help"]
shaneha05e0c42009-11-06 03:22:54 +0000372 # look for a few of the possible help commands
373 list [regexp {.help} $res] \
374 [regexp {.quit} $res] \
375 [regexp {.show} $res]
376} {1 1 1}
shaneh5fc25012009-11-11 04:17:07 +0000377do_test shell1-3.10.2 {
shanehe2aa9d72009-11-06 17:20:17 +0000378 # we allow .help to take extra args (it is help after all)
shanehca7dfda2009-12-17 21:07:54 +0000379 set res [catchcmd "test.db" ".help BAD"]
shanehe2aa9d72009-11-06 17:20:17 +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}
shaneha05e0c42009-11-06 03:22:54 +0000385
386# .import FILE TABLE Import data from FILE into TABLE
shaneh5fc25012009-11-11 04:17:07 +0000387do_test shell1-3.11.1 {
shanehca7dfda2009-12-17 21:07:54 +0000388 catchcmd "test.db" ".import"
drhc2ce0be2014-05-29 12:36:14 +0000389} {1 {Usage: .import FILE TABLE}}
shaneh5fc25012009-11-11 04:17:07 +0000390do_test shell1-3.11.2 {
shanehca7dfda2009-12-17 21:07:54 +0000391 catchcmd "test.db" ".import FOO"
drhc2ce0be2014-05-29 12:36:14 +0000392} {1 {Usage: .import FILE TABLE}}
drhdb95f682013-06-26 22:46:00 +0000393#do_test shell1-3.11.2 {
394# catchcmd "test.db" ".import FOO BAR"
395#} {1 {Error: no such table: BAR}}
shaneh5fc25012009-11-11 04:17:07 +0000396do_test shell1-3.11.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000397 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000398 catchcmd "test.db" ".import FOO BAR BAD"
drhc2ce0be2014-05-29 12:36:14 +0000399} {1 {Usage: .import FILE TABLE}}
shaneha05e0c42009-11-06 03:22:54 +0000400
drh0e55db12015-02-06 14:51:13 +0000401# .indexes ?TABLE? Show names of all indexes
402# If TABLE specified, only show indexes for tables
shaneha05e0c42009-11-06 03:22:54 +0000403# matching LIKE pattern TABLE.
shaneh5fc25012009-11-11 04:17:07 +0000404do_test shell1-3.12.1 {
drh0e55db12015-02-06 14:51:13 +0000405 catchcmd "test.db" ".indexes"
shaneha05e0c42009-11-06 03:22:54 +0000406} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000407do_test shell1-3.12.2 {
drh0e55db12015-02-06 14:51:13 +0000408 catchcmd "test.db" ".indexes FOO"
409} {0 {}}
410do_test shell1-3.12.2-legacy {
shanehca7dfda2009-12-17 21:07:54 +0000411 catchcmd "test.db" ".indices FOO"
shaneha05e0c42009-11-06 03:22:54 +0000412} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000413do_test shell1-3.12.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000414 # too many arguments
drh0e55db12015-02-06 14:51:13 +0000415 catchcmd "test.db" ".indexes FOO BAD"
416} {1 {Usage: .indexes ?LIKE-PATTERN?}}
shaneha05e0c42009-11-06 03:22:54 +0000417
418# .mode MODE ?TABLE? Set output mode where MODE is one of:
mistachkine0d68852014-12-11 03:12:33 +0000419# ascii Columns/rows delimited by 0x1F and 0x1E
shaneha05e0c42009-11-06 03:22:54 +0000420# csv Comma-separated values
421# column Left-aligned columns. (See .width)
422# html HTML <table> code
423# insert SQL insert statements for TABLE
424# line One value per line
mistachkine0d68852014-12-11 03:12:33 +0000425# list Values delimited by .separator strings
shaneha05e0c42009-11-06 03:22:54 +0000426# tabs Tab-separated values
427# tcl TCL list elements
shaneh5fc25012009-11-11 04:17:07 +0000428do_test shell1-3.13.1 {
shanehca7dfda2009-12-17 21:07:54 +0000429 catchcmd "test.db" ".mode"
mistachkin636bf9f2014-07-19 20:15:16 +0000430} {1 {Error: mode should be one of: ascii column csv html insert line list tabs tcl}}
shaneh5fc25012009-11-11 04:17:07 +0000431do_test shell1-3.13.2 {
shanehca7dfda2009-12-17 21:07:54 +0000432 catchcmd "test.db" ".mode FOO"
mistachkin636bf9f2014-07-19 20:15:16 +0000433} {1 {Error: mode should be one of: ascii column csv html insert line list tabs tcl}}
shaneh5fc25012009-11-11 04:17:07 +0000434do_test shell1-3.13.3 {
shanehca7dfda2009-12-17 21:07:54 +0000435 catchcmd "test.db" ".mode csv"
shaneha05e0c42009-11-06 03:22:54 +0000436} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000437do_test shell1-3.13.4 {
shanehca7dfda2009-12-17 21:07:54 +0000438 catchcmd "test.db" ".mode column"
shaneha05e0c42009-11-06 03:22:54 +0000439} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000440do_test shell1-3.13.5 {
shanehca7dfda2009-12-17 21:07:54 +0000441 catchcmd "test.db" ".mode html"
shaneha05e0c42009-11-06 03:22:54 +0000442} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000443do_test shell1-3.13.6 {
shanehca7dfda2009-12-17 21:07:54 +0000444 catchcmd "test.db" ".mode insert"
shaneha05e0c42009-11-06 03:22:54 +0000445} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000446do_test shell1-3.13.7 {
shanehca7dfda2009-12-17 21:07:54 +0000447 catchcmd "test.db" ".mode line"
shaneha05e0c42009-11-06 03:22:54 +0000448} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000449do_test shell1-3.13.8 {
shanehca7dfda2009-12-17 21:07:54 +0000450 catchcmd "test.db" ".mode list"
shaneha05e0c42009-11-06 03:22:54 +0000451} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000452do_test shell1-3.13.9 {
shanehca7dfda2009-12-17 21:07:54 +0000453 catchcmd "test.db" ".mode tabs"
shaneha05e0c42009-11-06 03:22:54 +0000454} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000455do_test shell1-3.13.10 {
shanehca7dfda2009-12-17 21:07:54 +0000456 catchcmd "test.db" ".mode tcl"
shaneha05e0c42009-11-06 03:22:54 +0000457} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000458do_test shell1-3.13.11 {
drhc2ce0be2014-05-29 12:36:14 +0000459 # extra arguments ignored
shanehca7dfda2009-12-17 21:07:54 +0000460 catchcmd "test.db" ".mode tcl BAD"
drhc2ce0be2014-05-29 12:36:14 +0000461} {0 {}}
shanehe2aa9d72009-11-06 17:20:17 +0000462
463# don't allow partial mode type matches
shaneh5fc25012009-11-11 04:17:07 +0000464do_test shell1-3.13.12 {
shanehca7dfda2009-12-17 21:07:54 +0000465 catchcmd "test.db" ".mode l"
mistachkin636bf9f2014-07-19 20:15:16 +0000466} {1 {Error: mode should be one of: ascii column csv html insert line list tabs tcl}}
shaneh5fc25012009-11-11 04:17:07 +0000467do_test shell1-3.13.13 {
shanehca7dfda2009-12-17 21:07:54 +0000468 catchcmd "test.db" ".mode li"
mistachkin636bf9f2014-07-19 20:15:16 +0000469} {1 {Error: mode should be one of: ascii column csv html insert line list tabs tcl}}
shaneh5fc25012009-11-11 04:17:07 +0000470do_test shell1-3.13.14 {
shanehca7dfda2009-12-17 21:07:54 +0000471 catchcmd "test.db" ".mode lin"
drhc2ce0be2014-05-29 12:36:14 +0000472} {0 {}}
shaneha05e0c42009-11-06 03:22:54 +0000473
474# .nullvalue STRING Print STRING in place of NULL values
shaneh5fc25012009-11-11 04:17:07 +0000475do_test shell1-3.14.1 {
shanehca7dfda2009-12-17 21:07:54 +0000476 catchcmd "test.db" ".nullvalue"
drhc2ce0be2014-05-29 12:36:14 +0000477} {1 {Usage: .nullvalue STRING}}
shaneh5fc25012009-11-11 04:17:07 +0000478do_test shell1-3.14.2 {
shanehca7dfda2009-12-17 21:07:54 +0000479 catchcmd "test.db" ".nullvalue FOO"
shaneha05e0c42009-11-06 03:22:54 +0000480} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000481do_test shell1-3.14.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000482 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000483 catchcmd "test.db" ".nullvalue FOO BAD"
drhc2ce0be2014-05-29 12:36:14 +0000484} {1 {Usage: .nullvalue STRING}}
shaneha05e0c42009-11-06 03:22:54 +0000485
486# .output FILENAME Send output to FILENAME
shaneh5fc25012009-11-11 04:17:07 +0000487do_test shell1-3.15.1 {
shanehca7dfda2009-12-17 21:07:54 +0000488 catchcmd "test.db" ".output"
drhc2ce0be2014-05-29 12:36:14 +0000489} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000490do_test shell1-3.15.2 {
shanehca7dfda2009-12-17 21:07:54 +0000491 catchcmd "test.db" ".output FOO"
shaneha05e0c42009-11-06 03:22:54 +0000492} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000493do_test shell1-3.15.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000494 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000495 catchcmd "test.db" ".output FOO BAD"
drhc2ce0be2014-05-29 12:36:14 +0000496} {1 {Usage: .output FILE}}
shaneha05e0c42009-11-06 03:22:54 +0000497
498# .output stdout Send output to the screen
shaneh5fc25012009-11-11 04:17:07 +0000499do_test shell1-3.16.1 {
shanehca7dfda2009-12-17 21:07:54 +0000500 catchcmd "test.db" ".output stdout"
shaneha05e0c42009-11-06 03:22:54 +0000501} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000502do_test shell1-3.16.2 {
shanehe2aa9d72009-11-06 17:20:17 +0000503 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000504 catchcmd "test.db" ".output stdout BAD"
drhc2ce0be2014-05-29 12:36:14 +0000505} {1 {Usage: .output FILE}}
shaneha05e0c42009-11-06 03:22:54 +0000506
507# .prompt MAIN CONTINUE Replace the standard prompts
shaneh5fc25012009-11-11 04:17:07 +0000508do_test shell1-3.17.1 {
shanehca7dfda2009-12-17 21:07:54 +0000509 catchcmd "test.db" ".prompt"
drhc2ce0be2014-05-29 12:36:14 +0000510} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000511do_test shell1-3.17.2 {
shanehca7dfda2009-12-17 21:07:54 +0000512 catchcmd "test.db" ".prompt FOO"
shaneha05e0c42009-11-06 03:22:54 +0000513} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000514do_test shell1-3.17.3 {
shanehca7dfda2009-12-17 21:07:54 +0000515 catchcmd "test.db" ".prompt FOO BAR"
shaneha05e0c42009-11-06 03:22:54 +0000516} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000517do_test shell1-3.17.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000518 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000519 catchcmd "test.db" ".prompt FOO BAR BAD"
drhc2ce0be2014-05-29 12:36:14 +0000520} {0 {}}
shaneha05e0c42009-11-06 03:22:54 +0000521
522# .quit Exit this program
shaneh5fc25012009-11-11 04:17:07 +0000523do_test shell1-3.18.1 {
shanehca7dfda2009-12-17 21:07:54 +0000524 catchcmd "test.db" ".quit"
shaneha05e0c42009-11-06 03:22:54 +0000525} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000526do_test shell1-3.18.2 {
shanehe2aa9d72009-11-06 17:20:17 +0000527 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000528 catchcmd "test.db" ".quit BAD"
drhc2ce0be2014-05-29 12:36:14 +0000529} {0 {}}
shaneha05e0c42009-11-06 03:22:54 +0000530
531# .read FILENAME Execute SQL in FILENAME
shaneh5fc25012009-11-11 04:17:07 +0000532do_test shell1-3.19.1 {
shanehca7dfda2009-12-17 21:07:54 +0000533 catchcmd "test.db" ".read"
drhc2ce0be2014-05-29 12:36:14 +0000534} {1 {Usage: .read FILE}}
shaneh5fc25012009-11-11 04:17:07 +0000535do_test shell1-3.19.2 {
mistachkin9ac99312013-09-13 23:26:47 +0000536 forcedelete FOO
shanehca7dfda2009-12-17 21:07:54 +0000537 catchcmd "test.db" ".read FOO"
shaneha05e0c42009-11-06 03:22:54 +0000538} {1 {Error: cannot open "FOO"}}
shaneh5fc25012009-11-11 04:17:07 +0000539do_test shell1-3.19.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000540 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000541 catchcmd "test.db" ".read FOO BAD"
drhc2ce0be2014-05-29 12:36:14 +0000542} {1 {Usage: .read FILE}}
shaneha05e0c42009-11-06 03:22:54 +0000543
544# .restore ?DB? FILE Restore content of DB (default "main") from FILE
shaneh5fc25012009-11-11 04:17:07 +0000545do_test shell1-3.20.1 {
shanehca7dfda2009-12-17 21:07:54 +0000546 catchcmd "test.db" ".restore"
drhc2ce0be2014-05-29 12:36:14 +0000547} {1 {Usage: .restore ?DB? FILE}}
shaneh5fc25012009-11-11 04:17:07 +0000548do_test shell1-3.20.2 {
shanehca7dfda2009-12-17 21:07:54 +0000549 catchcmd "test.db" ".restore FOO"
550} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000551do_test shell1-3.20.3 {
shanehca7dfda2009-12-17 21:07:54 +0000552 catchcmd "test.db" ".restore FOO BAR"
shanehe2aa9d72009-11-06 17:20:17 +0000553} {1 {Error: unknown database FOO}}
shaneh5fc25012009-11-11 04:17:07 +0000554do_test shell1-3.20.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000555 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000556 catchcmd "test.db" ".restore FOO BAR BAD"
drhc2ce0be2014-05-29 12:36:14 +0000557} {1 {Usage: .restore ?DB? FILE}}
shaneha05e0c42009-11-06 03:22:54 +0000558
559# .schema ?TABLE? Show the CREATE statements
560# If TABLE specified, only show tables matching
561# LIKE pattern TABLE.
shaneh5fc25012009-11-11 04:17:07 +0000562do_test shell1-3.21.1 {
shanehca7dfda2009-12-17 21:07:54 +0000563 catchcmd "test.db" ".schema"
shaneha05e0c42009-11-06 03:22:54 +0000564} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000565do_test shell1-3.21.2 {
shanehca7dfda2009-12-17 21:07:54 +0000566 catchcmd "test.db" ".schema FOO"
shaneha05e0c42009-11-06 03:22:54 +0000567} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000568do_test shell1-3.21.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000569 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000570 catchcmd "test.db" ".schema FOO BAD"
drh4926fec2016-04-13 15:33:42 +0000571} {1 {Usage: .schema ?--indent? ?LIKE-PATTERN?}}
shaneha05e0c42009-11-06 03:22:54 +0000572
drhac43e982012-05-21 03:15:06 +0000573do_test shell1-3.21.4 {
574 catchcmd "test.db" {
575 CREATE TABLE t1(x);
576 CREATE VIEW v2 AS SELECT x+1 AS y FROM t1;
577 CREATE VIEW v1 AS SELECT y+1 FROM v2;
578 }
579 catchcmd "test.db" ".schema"
580} {0 {CREATE TABLE t1(x);
581CREATE VIEW v2 AS SELECT x+1 AS y FROM t1;
582CREATE VIEW v1 AS SELECT y+1 FROM v2;}}
583db eval {DROP VIEW v1; DROP VIEW v2; DROP TABLE t1;}
584
mistachkin636bf9f2014-07-19 20:15:16 +0000585# .separator STRING Change column separator used by output and .import
shaneh5fc25012009-11-11 04:17:07 +0000586do_test shell1-3.22.1 {
shanehca7dfda2009-12-17 21:07:54 +0000587 catchcmd "test.db" ".separator"
mistachkine0d68852014-12-11 03:12:33 +0000588} {1 {Usage: .separator COL ?ROW?}}
shaneh5fc25012009-11-11 04:17:07 +0000589do_test shell1-3.22.2 {
shanehca7dfda2009-12-17 21:07:54 +0000590 catchcmd "test.db" ".separator FOO"
shaneha05e0c42009-11-06 03:22:54 +0000591} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000592do_test shell1-3.22.3 {
drh6976c212014-07-24 12:09:47 +0000593 catchcmd "test.db" ".separator ABC XYZ"
594} {0 {}}
595do_test shell1-3.22.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000596 # too many arguments
drh6976c212014-07-24 12:09:47 +0000597 catchcmd "test.db" ".separator FOO BAD BAD2"
mistachkine0d68852014-12-11 03:12:33 +0000598} {1 {Usage: .separator COL ?ROW?}}
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] \
mistachkin636bf9f2014-07-19 20:15:16 +0000609 [regexp {colseparator:} $res] \
610 [regexp {rowseparator:} $res] \
shaneh642d8b82010-07-28 16:05:34 +0000611 [regexp {stats:} $res] \
shaneha05e0c42009-11-06 03:22:54 +0000612 [regexp {width:} $res]
mistachkine0d68852014-12-11 03:12:33 +0000613} {1 1 1 1 1 1 1 1 1 1}
shaneh5fc25012009-11-11 04:17:07 +0000614do_test shell1-3.23.2 {
shanehe2aa9d72009-11-06 17:20:17 +0000615 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000616 catchcmd "test.db" ".show BAD"
drhc2ce0be2014-05-29 12:36:14 +0000617} {1 {Usage: .show}}
shaneha05e0c42009-11-06 03:22:54 +0000618
shaneh642d8b82010-07-28 16:05:34 +0000619# .stats ON|OFF Turn stats on or off
drh34784902016-02-27 17:12:36 +0000620#do_test shell1-3.23b.1 {
621# catchcmd "test.db" ".stats"
622#} {1 {Usage: .stats on|off}}
shaneh642d8b82010-07-28 16:05:34 +0000623do_test shell1-3.23b.2 {
624 catchcmd "test.db" ".stats ON"
625} {0 {}}
626do_test shell1-3.23b.3 {
627 catchcmd "test.db" ".stats OFF"
628} {0 {}}
629do_test shell1-3.23b.4 {
630 # too many arguments
631 catchcmd "test.db" ".stats OFF BAD"
drh34784902016-02-27 17:12:36 +0000632} {1 {Usage: .stats ?on|off?}}
shaneh642d8b82010-07-28 16:05:34 +0000633
shaneha05e0c42009-11-06 03:22:54 +0000634# .tables ?TABLE? List names of tables
635# If TABLE specified, only list tables matching
636# LIKE pattern TABLE.
shaneh5fc25012009-11-11 04:17:07 +0000637do_test shell1-3.24.1 {
shanehca7dfda2009-12-17 21:07:54 +0000638 catchcmd "test.db" ".tables"
shaneha05e0c42009-11-06 03:22:54 +0000639} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000640do_test shell1-3.24.2 {
shanehca7dfda2009-12-17 21:07:54 +0000641 catchcmd "test.db" ".tables FOO"
shaneha05e0c42009-11-06 03:22:54 +0000642} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000643do_test shell1-3.24.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000644 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000645 catchcmd "test.db" ".tables FOO BAD"
drhc2ce0be2014-05-29 12:36:14 +0000646} {0 {}}
shaneha05e0c42009-11-06 03:22:54 +0000647
648# .timeout MS Try opening locked tables for MS milliseconds
shaneh5fc25012009-11-11 04:17:07 +0000649do_test shell1-3.25.1 {
shanehca7dfda2009-12-17 21:07:54 +0000650 catchcmd "test.db" ".timeout"
drhc2ce0be2014-05-29 12:36:14 +0000651} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000652do_test shell1-3.25.2 {
shanehca7dfda2009-12-17 21:07:54 +0000653 catchcmd "test.db" ".timeout zzz"
shanehe2aa9d72009-11-06 17:20:17 +0000654 # this should be treated the same as a '0' timeout
shaneha05e0c42009-11-06 03:22:54 +0000655} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000656do_test shell1-3.25.3 {
shanehca7dfda2009-12-17 21:07:54 +0000657 catchcmd "test.db" ".timeout 1"
shaneha05e0c42009-11-06 03:22:54 +0000658} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000659do_test shell1-3.25.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000660 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000661 catchcmd "test.db" ".timeout 1 BAD"
drhc2ce0be2014-05-29 12:36:14 +0000662} {0 {}}
shaneha05e0c42009-11-06 03:22:54 +0000663
664# .width NUM NUM ... Set column widths for "column" mode
shaneh5fc25012009-11-11 04:17:07 +0000665do_test shell1-3.26.1 {
shanehca7dfda2009-12-17 21:07:54 +0000666 catchcmd "test.db" ".width"
drhc2ce0be2014-05-29 12:36:14 +0000667} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000668do_test shell1-3.26.2 {
shanehca7dfda2009-12-17 21:07:54 +0000669 catchcmd "test.db" ".width xxx"
shanehe2aa9d72009-11-06 17:20:17 +0000670 # this should be treated the same as a '0' width for col 1
shaneha05e0c42009-11-06 03:22:54 +0000671} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000672do_test shell1-3.26.3 {
shanehca7dfda2009-12-17 21:07:54 +0000673 catchcmd "test.db" ".width xxx yyy"
shanehe2aa9d72009-11-06 17:20:17 +0000674 # this should be treated the same as a '0' width for col 1 and 2
shaneha05e0c42009-11-06 03:22:54 +0000675} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000676do_test shell1-3.26.4 {
shanehca7dfda2009-12-17 21:07:54 +0000677 catchcmd "test.db" ".width 1 1"
shanehe2aa9d72009-11-06 17:20:17 +0000678 # this should be treated the same as a '1' width for col 1 and 2
shaneha05e0c42009-11-06 03:22:54 +0000679} {0 {}}
drh078b1fd2012-09-21 13:40:02 +0000680do_test shell1-3.26.5 {
681 catchcmd "test.db" ".mode column\n.width 10 -10\nSELECT 'abcdefg', 123456;"
682 # this should be treated the same as a '1' width for col 1 and 2
683} {0 {abcdefg 123456}}
684do_test shell1-3.26.6 {
685 catchcmd "test.db" ".mode column\n.width -10 10\nSELECT 'abcdefg', 123456;"
686 # this should be treated the same as a '1' width for col 1 and 2
687} {0 { abcdefg 123456 }}
688
shaneha05e0c42009-11-06 03:22:54 +0000689
690# .timer ON|OFF Turn the CPU timer measurement on or off
shaneh5fc25012009-11-11 04:17:07 +0000691do_test shell1-3.27.1 {
shanehca7dfda2009-12-17 21:07:54 +0000692 catchcmd "test.db" ".timer"
drhc2ce0be2014-05-29 12:36:14 +0000693} {1 {Usage: .timer on|off}}
shaneh5fc25012009-11-11 04:17:07 +0000694do_test shell1-3.27.2 {
shanehca7dfda2009-12-17 21:07:54 +0000695 catchcmd "test.db" ".timer ON"
shaneha05e0c42009-11-06 03:22:54 +0000696} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000697do_test shell1-3.27.3 {
shanehca7dfda2009-12-17 21:07:54 +0000698 catchcmd "test.db" ".timer OFF"
shaneha05e0c42009-11-06 03:22:54 +0000699} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000700do_test shell1-3.27.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000701 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000702 catchcmd "test.db" ".timer OFF BAD"
drhc2ce0be2014-05-29 12:36:14 +0000703} {1 {Usage: .timer on|off}}
shaneha05e0c42009-11-06 03:22:54 +0000704
drh53a9d152011-04-25 18:20:04 +0000705do_test shell1-3-28.1 {
706 catchcmd test.db \
707 ".log stdout\nSELECT coalesce(sqlite_log(123,'hello'),'456');"
708} "0 {(123) hello\n456}"
709
drh078b1fd2012-09-21 13:40:02 +0000710do_test shell1-3-29.1 {
711 catchcmd "test.db" ".print this is a test"
712} {0 {this is a test}}
713
drh4c56b992013-06-27 13:26:55 +0000714# dot-command argument quoting
715do_test shell1-3-30.1 {
716 catchcmd {test.db} {.print "this\"is'a\055test" 'this\"is\\a\055test'}
717} {0 {this"is'a-test this\"is\\a\055test}}
718do_test shell1-3-31.1 {
719 catchcmd {test.db} {.print "this\nis\ta\\test" 'this\nis\ta\\test'}
720} [list 0 "this\nis\ta\\test this\\nis\\ta\\\\test"]
721
722
drh5128e852012-04-24 13:14:49 +0000723# Test the output of the ".dump" command
724#
725do_test shell1-4.1 {
drh55a1b302013-09-04 16:08:50 +0000726 db close
727 forcedelete test.db
728 sqlite3 db test.db
drh5128e852012-04-24 13:14:49 +0000729 db eval {
drh55a1b302013-09-04 16:08:50 +0000730 PRAGMA encoding=UTF16;
drh5128e852012-04-24 13:14:49 +0000731 CREATE TABLE t1(x);
mistachkin585dcb22012-12-04 00:23:43 +0000732 INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f');
mistachkin151c75a2015-04-07 21:16:40 +0000733 CREATE TABLE t3(x,y);
734 INSERT INTO t3 VALUES(1,null), (2,''), (3,1),
735 (4,2.25), (5,'hello'), (6,x'807f');
drh5128e852012-04-24 13:14:49 +0000736 }
737 catchcmd test.db {.dump}
738} {0 {PRAGMA foreign_keys=OFF;
739BEGIN TRANSACTION;
740CREATE TABLE t1(x);
741INSERT INTO "t1" VALUES(NULL);
mistachkin585dcb22012-12-04 00:23:43 +0000742INSERT INTO "t1" VALUES('');
drh5128e852012-04-24 13:14:49 +0000743INSERT INTO "t1" VALUES(1);
744INSERT INTO "t1" VALUES(2.25);
745INSERT INTO "t1" VALUES('hello');
746INSERT INTO "t1" VALUES(X'807F');
mistachkin151c75a2015-04-07 21:16:40 +0000747CREATE TABLE t3(x,y);
748INSERT INTO "t3" VALUES(1,NULL);
749INSERT INTO "t3" VALUES(2,'');
750INSERT INTO "t3" VALUES(3,1);
751INSERT INTO "t3" VALUES(4,2.25);
752INSERT INTO "t3" VALUES(5,'hello');
753INSERT INTO "t3" VALUES(6,X'807F');
drh5128e852012-04-24 13:14:49 +0000754COMMIT;}}
755
756# Test the output of ".mode insert"
757#
mistachkin151c75a2015-04-07 21:16:40 +0000758do_test shell1-4.2.1 {
drh5128e852012-04-24 13:14:49 +0000759 catchcmd test.db ".mode insert t1\nselect * from t1;"
760} {0 {INSERT INTO t1 VALUES(NULL);
mistachkin585dcb22012-12-04 00:23:43 +0000761INSERT INTO t1 VALUES('');
drh5128e852012-04-24 13:14:49 +0000762INSERT INTO t1 VALUES(1);
763INSERT INTO t1 VALUES(2.25);
764INSERT INTO t1 VALUES('hello');
765INSERT INTO t1 VALUES(X'807f');}}
766
mistachkin151c75a2015-04-07 21:16:40 +0000767# Test the output of ".mode insert" with headers
768#
769do_test shell1-4.2.2 {
770 catchcmd test.db ".mode insert t1\n.headers on\nselect * from t1;"
771} {0 {INSERT INTO t1(x) VALUES(NULL);
772INSERT INTO t1(x) VALUES('');
773INSERT INTO t1(x) VALUES(1);
774INSERT INTO t1(x) VALUES(2.25);
775INSERT INTO t1(x) VALUES('hello');
776INSERT INTO t1(x) VALUES(X'807f');}}
777
778# Test the output of ".mode insert"
779#
780do_test shell1-4.2.3 {
781 catchcmd test.db ".mode insert t3\nselect * from t3;"
782} {0 {INSERT INTO t3 VALUES(1,NULL);
783INSERT INTO t3 VALUES(2,'');
784INSERT INTO t3 VALUES(3,1);
785INSERT INTO t3 VALUES(4,2.25);
786INSERT INTO t3 VALUES(5,'hello');
787INSERT INTO t3 VALUES(6,X'807f');}}
788
789# Test the output of ".mode insert" with headers
790#
mistachkincc445402015-04-07 21:17:53 +0000791do_test shell1-4.2.4 {
mistachkin151c75a2015-04-07 21:16:40 +0000792 catchcmd test.db ".mode insert t3\n.headers on\nselect * from t3;"
793} {0 {INSERT INTO t3(x,y) VALUES(1,NULL);
794INSERT INTO t3(x,y) VALUES(2,'');
795INSERT INTO t3(x,y) VALUES(3,1);
796INSERT INTO t3(x,y) VALUES(4,2.25);
797INSERT INTO t3(x,y) VALUES(5,'hello');
798INSERT INTO t3(x,y) VALUES(6,X'807f');}}
799
mistachkin585dcb22012-12-04 00:23:43 +0000800# Test the output of ".mode tcl"
801#
802do_test shell1-4.3 {
drh55a1b302013-09-04 16:08:50 +0000803 db close
804 forcedelete test.db
805 sqlite3 db test.db
806 db eval {
807 PRAGMA encoding=UTF8;
808 CREATE TABLE t1(x);
809 INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f');
810 }
mistachkin585dcb22012-12-04 00:23:43 +0000811 catchcmd test.db ".mode tcl\nselect * from t1;"
812} {0 {""
813""
814"1"
815"2.25"
816"hello"
817"\200\177"}}
818
819# Test the output of ".mode tcl" with multiple columns
820#
821do_test shell1-4.4 {
822 db eval {
823 CREATE TABLE t2(x,y);
824 INSERT INTO t2 VALUES(null, ''), (1, 2.25), ('hello', x'807f');
825 }
826 catchcmd test.db ".mode tcl\nselect * from t2;"
827} {0 {"" ""
828"1" "2.25"
829"hello" "\200\177"}}
830
831# Test the output of ".mode tcl" with ".nullvalue"
832#
833do_test shell1-4.5 {
834 catchcmd test.db ".mode tcl\n.nullvalue NULL\nselect * from t2;"
835} {0 {"NULL" ""
836"1" "2.25"
837"hello" "\200\177"}}
838
839# Test the output of ".mode tcl" with Tcl reserved characters
840#
841do_test shell1-4.6 {
842 db eval {
843 CREATE TABLE tcl1(x);
844 INSERT INTO tcl1 VALUES('"'), ('['), (']'), ('\{'), ('\}'), (';'), ('$');
845 }
846 foreach {x y} [catchcmd test.db ".mode tcl\nselect * from tcl1;"] break
847 list $x $y [llength $y]
848} {0 {"\""
849"["
850"]"
851"\\{"
852"\\}"
853";"
854"$"} 7}
drh5128e852012-04-24 13:14:49 +0000855
mistachkinf21979d2015-01-18 05:35:01 +0000856# Test using arbitrary byte data with the shell via standard input/output.
857#
858do_test shell1-5.0 {
859 #
860 # NOTE: Skip NUL byte because it appears to be incompatible with command
861 # shell argument parsing.
862 #
863 for {set i 1} {$i < 256} {incr i} {
864 #
mistachkin46a6b992015-01-18 09:02:57 +0000865 # NOTE: Due to how the Tcl [exec] command works (i.e. where it treats
866 # command channels opened for it as textual ones), the carriage
867 # return character (and on Windows, the end-of-file character)
868 # cannot be used here.
mistachkinf21979d2015-01-18 05:35:01 +0000869 #
mistachkin46a6b992015-01-18 09:02:57 +0000870 if {$i==0x0D || ($tcl_platform(platform)=="windows" && $i==0x1A)} {
mistachkinf21979d2015-01-18 05:35:01 +0000871 continue
872 }
873 set hex [format %02X $i]
874 set char [subst \\x$hex]; set oldChar $char
mistachkin0acee512015-01-19 21:11:31 +0000875 set escapes [list]
876 if {$tcl_platform(platform)=="windows"} {
877 #
878 # NOTE: On Windows, we need to escape all the whitespace characters,
879 # the alarm (\a) character, and those with special meaning to
880 # the SQLite shell itself.
881 #
882 set escapes [list \
883 \a \\a \b \\b \t \\t \n \\n \v \\v \f \\f \r \\r \
884 " " "\" \"" \" \\\" ' \"'\" \\ \\\\]
885 } else {
886 #
887 # NOTE: On Unix, we need to escape most of the whitespace characters
888 # and those with special meaning to the SQLite shell itself.
889 # The alarm (\a), backspace (\b), and carriage-return (\r)
890 # characters do not appear to require escaping on Unix. For
891 # the alarm and backspace characters, this is probably due to
892 # differences in the command shell. For the carriage-return,
893 # it is probably due to differences in how Tcl handles command
894 # channel end-of-line translations.
895 #
896 set escapes [list \
897 \t \\t \n \\n \v \\v \f \\f \
898 " " "\" \"" \" \\\" ' \"'\" \\ \\\\]
899 }
900 set char [string map $escapes $char]
mistachkinbfefa4c2015-01-19 21:27:46 +0000901 set x [catchcmdex test.db ".print $char\n"]
mistachkinf21979d2015-01-18 05:35:01 +0000902 set code [lindex $x 0]
903 set res [lindex $x 1]
904 if {$code ne "0"} {
905 error "failed with error: $res"
906 }
907 if {$res ne "$oldChar\n"} {
mistachkin48dcf2b2016-04-04 17:59:37 +0000908 if {[llength $res] > 0} {
909 set got [format %02X [scan $res %c]]
910 } else {
911 set got <empty>
912 }
913 error "failed with byte $hex mismatch, got $got"
mistachkinf21979d2015-01-18 05:35:01 +0000914 }
915 }
916} {}
917
mistachkin49e11252016-04-04 15:47:46 +0000918# The string used here is the word "test" in Chinese.
919# In UTF-8, it is encoded as: \xE6\xB5\x8B\xE8\xAF\x95
920set test \u6D4B\u8BD5
921
mistachkin1fe36bb2016-04-04 02:16:44 +0000922do_test shell1-6.0 {
mistachkin49e11252016-04-04 15:47:46 +0000923 set fileName $test; append fileName .db
924 catch {forcedelete $fileName}
mistachkin1fe36bb2016-04-04 02:16:44 +0000925 set x [catchcmdex $fileName "CREATE TABLE t1(x);\n.schema\n"]
926 set code [lindex $x 0]
927 set res [string trim [lindex $x 1]]
928 if {$code ne "0"} {
929 error "failed with error: $res"
930 }
931 if {$res ne "CREATE TABLE t1(x);"} {
932 error "failed with mismatch: $res"
933 }
934 if {![file exists $fileName]} {
mistachkin1810f222016-04-04 02:33:34 +0000935 error "file \"$fileName\" (Unicode) does not exist"
mistachkin1fe36bb2016-04-04 02:16:44 +0000936 }
937 forcedelete $fileName
938} {}
939
mistachkin49e11252016-04-04 15:47:46 +0000940do_test shell1-6.1 {
941 catch {forcedelete test3.db}
942 set x [catchcmdex test3.db \
943 "CREATE TABLE [encoding convertto utf-8 $test](x);\n.schema\n"]
944 set code [lindex $x 0]
945 set res [string trim [lindex $x 1]]
946 if {$code ne "0"} {
947 error "failed with error: $res"
948 }
949 if {$res ne "CREATE TABLE ${test}(x);"} {
950 error "failed with mismatch: $res"
951 }
952 forcedelete test3.db
953} {}
954
drh8df91852012-04-24 12:46:05 +0000955finish_test