blob: 95c3130bdd7dccf43a3c15fbadff564291d64c06 [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"
drh36f49d02016-11-23 23:18:45 +0000202} {1 {Error: mode should be one of: ascii column csv html insert line list quote 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"
drh36f49d02016-11-23 23:18:45 +0000205} {1 {Error: mode should be one of: ascii column csv html insert line list quote 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"
drh36f49d02016-11-23 23:18:45 +0000233} {1 {Error: mode should be one of: ascii column csv html insert line list quote 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
drhc5954192016-12-27 02:43:47 +0000276ifcapable vtab {
shaneha05e0c42009-11-06 03:22:54 +0000277# .databases List names and files of attached databases
shaneh5fc25012009-11-11 04:17:07 +0000278do_test shell1-3.3.1 {
drheaa544d2016-03-26 14:41:13 +0000279 catchcmd "-csv test.db" ".databases"
drh15707ac2016-03-26 13:26:35 +0000280} "/0.+main.+[string map {/ ".{1,2}"} [string range [get_pwd] 0 10]].*/"
shaneh5fc25012009-11-11 04:17:07 +0000281do_test shell1-3.3.2 {
drhc2ce0be2014-05-29 12:36:14 +0000282 # extra arguments ignored
drheaa544d2016-03-26 14:41:13 +0000283 catchcmd "test.db" ".databases BAD"
drh15707ac2016-03-26 13:26:35 +0000284} "/0.+main.+[string map {/ ".{1,2}"} [string range [get_pwd] 0 10]].*/"
drhc5954192016-12-27 02:43:47 +0000285}
shaneha05e0c42009-11-06 03:22:54 +0000286
287# .dump ?TABLE? ... Dump the database in an SQL text format
288# If TABLE specified, only dump tables matching
289# LIKE pattern TABLE.
shaneh5fc25012009-11-11 04:17:07 +0000290do_test shell1-3.4.1 {
shanehca7dfda2009-12-17 21:07:54 +0000291 set res [catchcmd "test.db" ".dump"]
shaneha05e0c42009-11-06 03:22:54 +0000292 list [regexp {BEGIN TRANSACTION;} $res] \
293 [regexp {COMMIT;} $res]
294} {1 1}
shaneh5fc25012009-11-11 04:17:07 +0000295do_test shell1-3.4.2 {
shanehca7dfda2009-12-17 21:07:54 +0000296 set res [catchcmd "test.db" ".dump FOO"]
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.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000301 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000302 catchcmd "test.db" ".dump FOO BAD"
drhc2ce0be2014-05-29 12:36:14 +0000303} {1 {Usage: .dump ?LIKE-PATTERN?}}
shaneha05e0c42009-11-06 03:22:54 +0000304
305# .echo ON|OFF Turn command echo on or off
shaneh5fc25012009-11-11 04:17:07 +0000306do_test shell1-3.5.1 {
shanehca7dfda2009-12-17 21:07:54 +0000307 catchcmd "test.db" ".echo"
drhc2ce0be2014-05-29 12:36:14 +0000308} {1 {Usage: .echo on|off}}
shaneh5fc25012009-11-11 04:17:07 +0000309do_test shell1-3.5.2 {
shanehca7dfda2009-12-17 21:07:54 +0000310 catchcmd "test.db" ".echo ON"
shaneha05e0c42009-11-06 03:22:54 +0000311} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000312do_test shell1-3.5.3 {
shanehca7dfda2009-12-17 21:07:54 +0000313 catchcmd "test.db" ".echo OFF"
shaneha05e0c42009-11-06 03:22:54 +0000314} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000315do_test shell1-3.5.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000316 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000317 catchcmd "test.db" ".echo OFF BAD"
drhc2ce0be2014-05-29 12:36:14 +0000318} {1 {Usage: .echo on|off}}
shaneha05e0c42009-11-06 03:22:54 +0000319
320# .exit Exit this program
shaneh5fc25012009-11-11 04:17:07 +0000321do_test shell1-3.6.1 {
shanehca7dfda2009-12-17 21:07:54 +0000322 catchcmd "test.db" ".exit"
shaneha05e0c42009-11-06 03:22:54 +0000323} {0 {}}
324
325# .explain ON|OFF Turn output mode suitable for EXPLAIN on or off.
shaneh5fc25012009-11-11 04:17:07 +0000326do_test shell1-3.7.1 {
shanehca7dfda2009-12-17 21:07:54 +0000327 catchcmd "test.db" ".explain"
shanehe2aa9d72009-11-06 17:20:17 +0000328 # explain is the exception to the booleans. without an option, it turns it on.
329} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000330do_test shell1-3.7.2 {
shanehca7dfda2009-12-17 21:07:54 +0000331 catchcmd "test.db" ".explain ON"
shaneha05e0c42009-11-06 03:22:54 +0000332} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000333do_test shell1-3.7.3 {
shanehca7dfda2009-12-17 21:07:54 +0000334 catchcmd "test.db" ".explain OFF"
shaneha05e0c42009-11-06 03:22:54 +0000335} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000336do_test shell1-3.7.4 {
drhc2ce0be2014-05-29 12:36:14 +0000337 # extra arguments ignored
shanehca7dfda2009-12-17 21:07:54 +0000338 catchcmd "test.db" ".explain OFF BAD"
drhc2ce0be2014-05-29 12:36:14 +0000339} {0 {}}
shaneha05e0c42009-11-06 03:22:54 +0000340
shaneha05e0c42009-11-06 03:22:54 +0000341
342# .header(s) ON|OFF Turn display of headers on or off
shaneh5fc25012009-11-11 04:17:07 +0000343do_test shell1-3.9.1 {
shanehca7dfda2009-12-17 21:07:54 +0000344 catchcmd "test.db" ".header"
drhc2ce0be2014-05-29 12:36:14 +0000345} {1 {Usage: .headers on|off}}
shaneh5fc25012009-11-11 04:17:07 +0000346do_test shell1-3.9.2 {
shanehca7dfda2009-12-17 21:07:54 +0000347 catchcmd "test.db" ".header ON"
shaneha05e0c42009-11-06 03:22:54 +0000348} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000349do_test shell1-3.9.3 {
shanehca7dfda2009-12-17 21:07:54 +0000350 catchcmd "test.db" ".header OFF"
shaneha05e0c42009-11-06 03:22:54 +0000351} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000352do_test shell1-3.9.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000353 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000354 catchcmd "test.db" ".header OFF BAD"
drhc2ce0be2014-05-29 12:36:14 +0000355} {1 {Usage: .headers on|off}}
shanehe2aa9d72009-11-06 17:20:17 +0000356
shaneh5fc25012009-11-11 04:17:07 +0000357do_test shell1-3.9.5 {
shanehca7dfda2009-12-17 21:07:54 +0000358 catchcmd "test.db" ".headers"
drhc2ce0be2014-05-29 12:36:14 +0000359} {1 {Usage: .headers on|off}}
shaneh5fc25012009-11-11 04:17:07 +0000360do_test shell1-3.9.6 {
shanehca7dfda2009-12-17 21:07:54 +0000361 catchcmd "test.db" ".headers ON"
shaneha05e0c42009-11-06 03:22:54 +0000362} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000363do_test shell1-3.9.7 {
shanehca7dfda2009-12-17 21:07:54 +0000364 catchcmd "test.db" ".headers OFF"
shaneha05e0c42009-11-06 03:22:54 +0000365} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000366do_test shell1-3.9.8 {
shanehe2aa9d72009-11-06 17:20:17 +0000367 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000368 catchcmd "test.db" ".headers OFF BAD"
drhc2ce0be2014-05-29 12:36:14 +0000369} {1 {Usage: .headers on|off}}
shaneha05e0c42009-11-06 03:22:54 +0000370
371# .help Show this message
shaneh5fc25012009-11-11 04:17:07 +0000372do_test shell1-3.10.1 {
shanehca7dfda2009-12-17 21:07:54 +0000373 set res [catchcmd "test.db" ".help"]
shaneha05e0c42009-11-06 03:22:54 +0000374 # look for a few of the possible help commands
375 list [regexp {.help} $res] \
376 [regexp {.quit} $res] \
377 [regexp {.show} $res]
378} {1 1 1}
shaneh5fc25012009-11-11 04:17:07 +0000379do_test shell1-3.10.2 {
shanehe2aa9d72009-11-06 17:20:17 +0000380 # we allow .help to take extra args (it is help after all)
shanehca7dfda2009-12-17 21:07:54 +0000381 set res [catchcmd "test.db" ".help BAD"]
shanehe2aa9d72009-11-06 17:20:17 +0000382 # look for a few of the possible help commands
383 list [regexp {.help} $res] \
384 [regexp {.quit} $res] \
385 [regexp {.show} $res]
386} {1 1 1}
shaneha05e0c42009-11-06 03:22:54 +0000387
388# .import FILE TABLE Import data from FILE into TABLE
shaneh5fc25012009-11-11 04:17:07 +0000389do_test shell1-3.11.1 {
shanehca7dfda2009-12-17 21:07:54 +0000390 catchcmd "test.db" ".import"
drhc2ce0be2014-05-29 12:36:14 +0000391} {1 {Usage: .import FILE TABLE}}
shaneh5fc25012009-11-11 04:17:07 +0000392do_test shell1-3.11.2 {
shanehca7dfda2009-12-17 21:07:54 +0000393 catchcmd "test.db" ".import FOO"
drhc2ce0be2014-05-29 12:36:14 +0000394} {1 {Usage: .import FILE TABLE}}
drhdb95f682013-06-26 22:46:00 +0000395#do_test shell1-3.11.2 {
396# catchcmd "test.db" ".import FOO BAR"
397#} {1 {Error: no such table: BAR}}
shaneh5fc25012009-11-11 04:17:07 +0000398do_test shell1-3.11.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000399 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000400 catchcmd "test.db" ".import FOO BAR BAD"
drhc2ce0be2014-05-29 12:36:14 +0000401} {1 {Usage: .import FILE TABLE}}
shaneha05e0c42009-11-06 03:22:54 +0000402
drh0e55db12015-02-06 14:51:13 +0000403# .indexes ?TABLE? Show names of all indexes
404# If TABLE specified, only show indexes for tables
shaneha05e0c42009-11-06 03:22:54 +0000405# matching LIKE pattern TABLE.
shaneh5fc25012009-11-11 04:17:07 +0000406do_test shell1-3.12.1 {
drh0e55db12015-02-06 14:51:13 +0000407 catchcmd "test.db" ".indexes"
shaneha05e0c42009-11-06 03:22:54 +0000408} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000409do_test shell1-3.12.2 {
drh0e55db12015-02-06 14:51:13 +0000410 catchcmd "test.db" ".indexes FOO"
411} {0 {}}
412do_test shell1-3.12.2-legacy {
shanehca7dfda2009-12-17 21:07:54 +0000413 catchcmd "test.db" ".indices FOO"
shaneha05e0c42009-11-06 03:22:54 +0000414} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000415do_test shell1-3.12.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000416 # too many arguments
drh0e55db12015-02-06 14:51:13 +0000417 catchcmd "test.db" ".indexes FOO BAD"
418} {1 {Usage: .indexes ?LIKE-PATTERN?}}
shaneha05e0c42009-11-06 03:22:54 +0000419
420# .mode MODE ?TABLE? Set output mode where MODE is one of:
mistachkine0d68852014-12-11 03:12:33 +0000421# ascii Columns/rows delimited by 0x1F and 0x1E
shaneha05e0c42009-11-06 03:22:54 +0000422# csv Comma-separated values
423# column Left-aligned columns. (See .width)
424# html HTML <table> code
425# insert SQL insert statements for TABLE
426# line One value per line
mistachkine0d68852014-12-11 03:12:33 +0000427# list Values delimited by .separator strings
shaneha05e0c42009-11-06 03:22:54 +0000428# tabs Tab-separated values
429# tcl TCL list elements
shaneh5fc25012009-11-11 04:17:07 +0000430do_test shell1-3.13.1 {
shanehca7dfda2009-12-17 21:07:54 +0000431 catchcmd "test.db" ".mode"
drh36f49d02016-11-23 23:18:45 +0000432} {1 {Error: mode should be one of: ascii column csv html insert line list quote tabs tcl}}
shaneh5fc25012009-11-11 04:17:07 +0000433do_test shell1-3.13.2 {
shanehca7dfda2009-12-17 21:07:54 +0000434 catchcmd "test.db" ".mode FOO"
drh36f49d02016-11-23 23:18:45 +0000435} {1 {Error: mode should be one of: ascii column csv html insert line list quote tabs tcl}}
shaneh5fc25012009-11-11 04:17:07 +0000436do_test shell1-3.13.3 {
shanehca7dfda2009-12-17 21:07:54 +0000437 catchcmd "test.db" ".mode csv"
shaneha05e0c42009-11-06 03:22:54 +0000438} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000439do_test shell1-3.13.4 {
shanehca7dfda2009-12-17 21:07:54 +0000440 catchcmd "test.db" ".mode column"
shaneha05e0c42009-11-06 03:22:54 +0000441} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000442do_test shell1-3.13.5 {
shanehca7dfda2009-12-17 21:07:54 +0000443 catchcmd "test.db" ".mode html"
shaneha05e0c42009-11-06 03:22:54 +0000444} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000445do_test shell1-3.13.6 {
shanehca7dfda2009-12-17 21:07:54 +0000446 catchcmd "test.db" ".mode insert"
shaneha05e0c42009-11-06 03:22:54 +0000447} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000448do_test shell1-3.13.7 {
shanehca7dfda2009-12-17 21:07:54 +0000449 catchcmd "test.db" ".mode line"
shaneha05e0c42009-11-06 03:22:54 +0000450} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000451do_test shell1-3.13.8 {
shanehca7dfda2009-12-17 21:07:54 +0000452 catchcmd "test.db" ".mode list"
shaneha05e0c42009-11-06 03:22:54 +0000453} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000454do_test shell1-3.13.9 {
shanehca7dfda2009-12-17 21:07:54 +0000455 catchcmd "test.db" ".mode tabs"
shaneha05e0c42009-11-06 03:22:54 +0000456} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000457do_test shell1-3.13.10 {
shanehca7dfda2009-12-17 21:07:54 +0000458 catchcmd "test.db" ".mode tcl"
shaneha05e0c42009-11-06 03:22:54 +0000459} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000460do_test shell1-3.13.11 {
drhc2ce0be2014-05-29 12:36:14 +0000461 # extra arguments ignored
shanehca7dfda2009-12-17 21:07:54 +0000462 catchcmd "test.db" ".mode tcl BAD"
drhc2ce0be2014-05-29 12:36:14 +0000463} {0 {}}
shanehe2aa9d72009-11-06 17:20:17 +0000464
465# don't allow partial mode type matches
shaneh5fc25012009-11-11 04:17:07 +0000466do_test shell1-3.13.12 {
shanehca7dfda2009-12-17 21:07:54 +0000467 catchcmd "test.db" ".mode l"
drh36f49d02016-11-23 23:18:45 +0000468} {1 {Error: mode should be one of: ascii column csv html insert line list quote tabs tcl}}
shaneh5fc25012009-11-11 04:17:07 +0000469do_test shell1-3.13.13 {
shanehca7dfda2009-12-17 21:07:54 +0000470 catchcmd "test.db" ".mode li"
drh36f49d02016-11-23 23:18:45 +0000471} {1 {Error: mode should be one of: ascii column csv html insert line list quote tabs tcl}}
shaneh5fc25012009-11-11 04:17:07 +0000472do_test shell1-3.13.14 {
shanehca7dfda2009-12-17 21:07:54 +0000473 catchcmd "test.db" ".mode lin"
drhc2ce0be2014-05-29 12:36:14 +0000474} {0 {}}
shaneha05e0c42009-11-06 03:22:54 +0000475
476# .nullvalue STRING Print STRING in place of NULL values
shaneh5fc25012009-11-11 04:17:07 +0000477do_test shell1-3.14.1 {
shanehca7dfda2009-12-17 21:07:54 +0000478 catchcmd "test.db" ".nullvalue"
drhc2ce0be2014-05-29 12:36:14 +0000479} {1 {Usage: .nullvalue STRING}}
shaneh5fc25012009-11-11 04:17:07 +0000480do_test shell1-3.14.2 {
shanehca7dfda2009-12-17 21:07:54 +0000481 catchcmd "test.db" ".nullvalue FOO"
shaneha05e0c42009-11-06 03:22:54 +0000482} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000483do_test shell1-3.14.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000484 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000485 catchcmd "test.db" ".nullvalue FOO BAD"
drhc2ce0be2014-05-29 12:36:14 +0000486} {1 {Usage: .nullvalue STRING}}
shaneha05e0c42009-11-06 03:22:54 +0000487
488# .output FILENAME Send output to FILENAME
shaneh5fc25012009-11-11 04:17:07 +0000489do_test shell1-3.15.1 {
shanehca7dfda2009-12-17 21:07:54 +0000490 catchcmd "test.db" ".output"
drhc2ce0be2014-05-29 12:36:14 +0000491} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000492do_test shell1-3.15.2 {
shanehca7dfda2009-12-17 21:07:54 +0000493 catchcmd "test.db" ".output FOO"
shaneha05e0c42009-11-06 03:22:54 +0000494} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000495do_test shell1-3.15.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000496 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000497 catchcmd "test.db" ".output FOO BAD"
drhc2ce0be2014-05-29 12:36:14 +0000498} {1 {Usage: .output FILE}}
shaneha05e0c42009-11-06 03:22:54 +0000499
500# .output stdout Send output to the screen
shaneh5fc25012009-11-11 04:17:07 +0000501do_test shell1-3.16.1 {
shanehca7dfda2009-12-17 21:07:54 +0000502 catchcmd "test.db" ".output stdout"
shaneha05e0c42009-11-06 03:22:54 +0000503} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000504do_test shell1-3.16.2 {
shanehe2aa9d72009-11-06 17:20:17 +0000505 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000506 catchcmd "test.db" ".output stdout BAD"
drhc2ce0be2014-05-29 12:36:14 +0000507} {1 {Usage: .output FILE}}
shaneha05e0c42009-11-06 03:22:54 +0000508
509# .prompt MAIN CONTINUE Replace the standard prompts
shaneh5fc25012009-11-11 04:17:07 +0000510do_test shell1-3.17.1 {
shanehca7dfda2009-12-17 21:07:54 +0000511 catchcmd "test.db" ".prompt"
drhc2ce0be2014-05-29 12:36:14 +0000512} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000513do_test shell1-3.17.2 {
shanehca7dfda2009-12-17 21:07:54 +0000514 catchcmd "test.db" ".prompt FOO"
shaneha05e0c42009-11-06 03:22:54 +0000515} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000516do_test shell1-3.17.3 {
shanehca7dfda2009-12-17 21:07:54 +0000517 catchcmd "test.db" ".prompt FOO BAR"
shaneha05e0c42009-11-06 03:22:54 +0000518} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000519do_test shell1-3.17.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000520 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000521 catchcmd "test.db" ".prompt FOO BAR BAD"
drhc2ce0be2014-05-29 12:36:14 +0000522} {0 {}}
shaneha05e0c42009-11-06 03:22:54 +0000523
524# .quit Exit this program
shaneh5fc25012009-11-11 04:17:07 +0000525do_test shell1-3.18.1 {
shanehca7dfda2009-12-17 21:07:54 +0000526 catchcmd "test.db" ".quit"
shaneha05e0c42009-11-06 03:22:54 +0000527} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000528do_test shell1-3.18.2 {
shanehe2aa9d72009-11-06 17:20:17 +0000529 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000530 catchcmd "test.db" ".quit BAD"
drhc2ce0be2014-05-29 12:36:14 +0000531} {0 {}}
shaneha05e0c42009-11-06 03:22:54 +0000532
533# .read FILENAME Execute SQL in FILENAME
shaneh5fc25012009-11-11 04:17:07 +0000534do_test shell1-3.19.1 {
shanehca7dfda2009-12-17 21:07:54 +0000535 catchcmd "test.db" ".read"
drhc2ce0be2014-05-29 12:36:14 +0000536} {1 {Usage: .read FILE}}
shaneh5fc25012009-11-11 04:17:07 +0000537do_test shell1-3.19.2 {
mistachkin9ac99312013-09-13 23:26:47 +0000538 forcedelete FOO
shanehca7dfda2009-12-17 21:07:54 +0000539 catchcmd "test.db" ".read FOO"
shaneha05e0c42009-11-06 03:22:54 +0000540} {1 {Error: cannot open "FOO"}}
shaneh5fc25012009-11-11 04:17:07 +0000541do_test shell1-3.19.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000542 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000543 catchcmd "test.db" ".read FOO BAD"
drhc2ce0be2014-05-29 12:36:14 +0000544} {1 {Usage: .read FILE}}
shaneha05e0c42009-11-06 03:22:54 +0000545
546# .restore ?DB? FILE Restore content of DB (default "main") from FILE
shaneh5fc25012009-11-11 04:17:07 +0000547do_test shell1-3.20.1 {
shanehca7dfda2009-12-17 21:07:54 +0000548 catchcmd "test.db" ".restore"
drhc2ce0be2014-05-29 12:36:14 +0000549} {1 {Usage: .restore ?DB? FILE}}
shaneh5fc25012009-11-11 04:17:07 +0000550do_test shell1-3.20.2 {
shanehca7dfda2009-12-17 21:07:54 +0000551 catchcmd "test.db" ".restore FOO"
552} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000553do_test shell1-3.20.3 {
shanehca7dfda2009-12-17 21:07:54 +0000554 catchcmd "test.db" ".restore FOO BAR"
shanehe2aa9d72009-11-06 17:20:17 +0000555} {1 {Error: unknown database FOO}}
shaneh5fc25012009-11-11 04:17:07 +0000556do_test shell1-3.20.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000557 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000558 catchcmd "test.db" ".restore FOO BAR BAD"
drhc2ce0be2014-05-29 12:36:14 +0000559} {1 {Usage: .restore ?DB? FILE}}
shaneha05e0c42009-11-06 03:22:54 +0000560
561# .schema ?TABLE? Show the CREATE statements
562# If TABLE specified, only show tables matching
563# LIKE pattern TABLE.
shaneh5fc25012009-11-11 04:17:07 +0000564do_test shell1-3.21.1 {
shanehca7dfda2009-12-17 21:07:54 +0000565 catchcmd "test.db" ".schema"
shaneha05e0c42009-11-06 03:22:54 +0000566} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000567do_test shell1-3.21.2 {
shanehca7dfda2009-12-17 21:07:54 +0000568 catchcmd "test.db" ".schema FOO"
shaneha05e0c42009-11-06 03:22:54 +0000569} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000570do_test shell1-3.21.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000571 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000572 catchcmd "test.db" ".schema FOO BAD"
drh4926fec2016-04-13 15:33:42 +0000573} {1 {Usage: .schema ?--indent? ?LIKE-PATTERN?}}
shaneha05e0c42009-11-06 03:22:54 +0000574
drhac43e982012-05-21 03:15:06 +0000575do_test shell1-3.21.4 {
576 catchcmd "test.db" {
577 CREATE TABLE t1(x);
578 CREATE VIEW v2 AS SELECT x+1 AS y FROM t1;
579 CREATE VIEW v1 AS SELECT y+1 FROM v2;
580 }
581 catchcmd "test.db" ".schema"
582} {0 {CREATE TABLE t1(x);
583CREATE VIEW v2 AS SELECT x+1 AS y FROM t1;
584CREATE VIEW v1 AS SELECT y+1 FROM v2;}}
585db eval {DROP VIEW v1; DROP VIEW v2; DROP TABLE t1;}
586
mistachkin636bf9f2014-07-19 20:15:16 +0000587# .separator STRING Change column separator used by output and .import
shaneh5fc25012009-11-11 04:17:07 +0000588do_test shell1-3.22.1 {
shanehca7dfda2009-12-17 21:07:54 +0000589 catchcmd "test.db" ".separator"
mistachkine0d68852014-12-11 03:12:33 +0000590} {1 {Usage: .separator COL ?ROW?}}
shaneh5fc25012009-11-11 04:17:07 +0000591do_test shell1-3.22.2 {
shanehca7dfda2009-12-17 21:07:54 +0000592 catchcmd "test.db" ".separator FOO"
shaneha05e0c42009-11-06 03:22:54 +0000593} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000594do_test shell1-3.22.3 {
drh6976c212014-07-24 12:09:47 +0000595 catchcmd "test.db" ".separator ABC XYZ"
596} {0 {}}
597do_test shell1-3.22.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000598 # too many arguments
drh6976c212014-07-24 12:09:47 +0000599 catchcmd "test.db" ".separator FOO BAD BAD2"
mistachkine0d68852014-12-11 03:12:33 +0000600} {1 {Usage: .separator COL ?ROW?}}
shaneha05e0c42009-11-06 03:22:54 +0000601
602# .show Show the current values for various settings
shaneh5fc25012009-11-11 04:17:07 +0000603do_test shell1-3.23.1 {
shanehca7dfda2009-12-17 21:07:54 +0000604 set res [catchcmd "test.db" ".show"]
shaneha05e0c42009-11-06 03:22:54 +0000605 list [regexp {echo:} $res] \
606 [regexp {explain:} $res] \
607 [regexp {headers:} $res] \
608 [regexp {mode:} $res] \
609 [regexp {nullvalue:} $res] \
610 [regexp {output:} $res] \
mistachkin636bf9f2014-07-19 20:15:16 +0000611 [regexp {colseparator:} $res] \
612 [regexp {rowseparator:} $res] \
shaneh642d8b82010-07-28 16:05:34 +0000613 [regexp {stats:} $res] \
shaneha05e0c42009-11-06 03:22:54 +0000614 [regexp {width:} $res]
mistachkine0d68852014-12-11 03:12:33 +0000615} {1 1 1 1 1 1 1 1 1 1}
shaneh5fc25012009-11-11 04:17:07 +0000616do_test shell1-3.23.2 {
shanehe2aa9d72009-11-06 17:20:17 +0000617 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000618 catchcmd "test.db" ".show BAD"
drhc2ce0be2014-05-29 12:36:14 +0000619} {1 {Usage: .show}}
shaneha05e0c42009-11-06 03:22:54 +0000620
shaneh642d8b82010-07-28 16:05:34 +0000621# .stats ON|OFF Turn stats on or off
drh34784902016-02-27 17:12:36 +0000622#do_test shell1-3.23b.1 {
623# catchcmd "test.db" ".stats"
624#} {1 {Usage: .stats on|off}}
shaneh642d8b82010-07-28 16:05:34 +0000625do_test shell1-3.23b.2 {
626 catchcmd "test.db" ".stats ON"
627} {0 {}}
628do_test shell1-3.23b.3 {
629 catchcmd "test.db" ".stats OFF"
630} {0 {}}
631do_test shell1-3.23b.4 {
632 # too many arguments
633 catchcmd "test.db" ".stats OFF BAD"
drh34784902016-02-27 17:12:36 +0000634} {1 {Usage: .stats ?on|off?}}
shaneh642d8b82010-07-28 16:05:34 +0000635
shaneha05e0c42009-11-06 03:22:54 +0000636# .tables ?TABLE? List names of tables
637# If TABLE specified, only list tables matching
638# LIKE pattern TABLE.
shaneh5fc25012009-11-11 04:17:07 +0000639do_test shell1-3.24.1 {
shanehca7dfda2009-12-17 21:07:54 +0000640 catchcmd "test.db" ".tables"
shaneha05e0c42009-11-06 03:22:54 +0000641} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000642do_test shell1-3.24.2 {
shanehca7dfda2009-12-17 21:07:54 +0000643 catchcmd "test.db" ".tables FOO"
shaneha05e0c42009-11-06 03:22:54 +0000644} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000645do_test shell1-3.24.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000646 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000647 catchcmd "test.db" ".tables FOO BAD"
drhc2ce0be2014-05-29 12:36:14 +0000648} {0 {}}
shaneha05e0c42009-11-06 03:22:54 +0000649
650# .timeout MS Try opening locked tables for MS milliseconds
shaneh5fc25012009-11-11 04:17:07 +0000651do_test shell1-3.25.1 {
shanehca7dfda2009-12-17 21:07:54 +0000652 catchcmd "test.db" ".timeout"
drhc2ce0be2014-05-29 12:36:14 +0000653} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000654do_test shell1-3.25.2 {
shanehca7dfda2009-12-17 21:07:54 +0000655 catchcmd "test.db" ".timeout zzz"
shanehe2aa9d72009-11-06 17:20:17 +0000656 # this should be treated the same as a '0' timeout
shaneha05e0c42009-11-06 03:22:54 +0000657} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000658do_test shell1-3.25.3 {
shanehca7dfda2009-12-17 21:07:54 +0000659 catchcmd "test.db" ".timeout 1"
shaneha05e0c42009-11-06 03:22:54 +0000660} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000661do_test shell1-3.25.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000662 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000663 catchcmd "test.db" ".timeout 1 BAD"
drhc2ce0be2014-05-29 12:36:14 +0000664} {0 {}}
shaneha05e0c42009-11-06 03:22:54 +0000665
666# .width NUM NUM ... Set column widths for "column" mode
shaneh5fc25012009-11-11 04:17:07 +0000667do_test shell1-3.26.1 {
shanehca7dfda2009-12-17 21:07:54 +0000668 catchcmd "test.db" ".width"
drhc2ce0be2014-05-29 12:36:14 +0000669} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000670do_test shell1-3.26.2 {
shanehca7dfda2009-12-17 21:07:54 +0000671 catchcmd "test.db" ".width xxx"
shanehe2aa9d72009-11-06 17:20:17 +0000672 # this should be treated the same as a '0' width for col 1
shaneha05e0c42009-11-06 03:22:54 +0000673} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000674do_test shell1-3.26.3 {
shanehca7dfda2009-12-17 21:07:54 +0000675 catchcmd "test.db" ".width xxx yyy"
shanehe2aa9d72009-11-06 17:20:17 +0000676 # this should be treated the same as a '0' width for col 1 and 2
shaneha05e0c42009-11-06 03:22:54 +0000677} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000678do_test shell1-3.26.4 {
shanehca7dfda2009-12-17 21:07:54 +0000679 catchcmd "test.db" ".width 1 1"
shanehe2aa9d72009-11-06 17:20:17 +0000680 # this should be treated the same as a '1' width for col 1 and 2
shaneha05e0c42009-11-06 03:22:54 +0000681} {0 {}}
drh078b1fd2012-09-21 13:40:02 +0000682do_test shell1-3.26.5 {
683 catchcmd "test.db" ".mode column\n.width 10 -10\nSELECT 'abcdefg', 123456;"
684 # this should be treated the same as a '1' width for col 1 and 2
685} {0 {abcdefg 123456}}
686do_test shell1-3.26.6 {
687 catchcmd "test.db" ".mode column\n.width -10 10\nSELECT 'abcdefg', 123456;"
688 # this should be treated the same as a '1' width for col 1 and 2
689} {0 { abcdefg 123456 }}
690
shaneha05e0c42009-11-06 03:22:54 +0000691
692# .timer ON|OFF Turn the CPU timer measurement on or off
shaneh5fc25012009-11-11 04:17:07 +0000693do_test shell1-3.27.1 {
shanehca7dfda2009-12-17 21:07:54 +0000694 catchcmd "test.db" ".timer"
drhc2ce0be2014-05-29 12:36:14 +0000695} {1 {Usage: .timer on|off}}
shaneh5fc25012009-11-11 04:17:07 +0000696do_test shell1-3.27.2 {
shanehca7dfda2009-12-17 21:07:54 +0000697 catchcmd "test.db" ".timer ON"
shaneha05e0c42009-11-06 03:22:54 +0000698} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000699do_test shell1-3.27.3 {
shanehca7dfda2009-12-17 21:07:54 +0000700 catchcmd "test.db" ".timer OFF"
shaneha05e0c42009-11-06 03:22:54 +0000701} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000702do_test shell1-3.27.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000703 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000704 catchcmd "test.db" ".timer OFF BAD"
drhc2ce0be2014-05-29 12:36:14 +0000705} {1 {Usage: .timer on|off}}
shaneha05e0c42009-11-06 03:22:54 +0000706
drh53a9d152011-04-25 18:20:04 +0000707do_test shell1-3-28.1 {
708 catchcmd test.db \
709 ".log stdout\nSELECT coalesce(sqlite_log(123,'hello'),'456');"
710} "0 {(123) hello\n456}"
711
drh078b1fd2012-09-21 13:40:02 +0000712do_test shell1-3-29.1 {
713 catchcmd "test.db" ".print this is a test"
714} {0 {this is a test}}
715
drh4c56b992013-06-27 13:26:55 +0000716# dot-command argument quoting
717do_test shell1-3-30.1 {
718 catchcmd {test.db} {.print "this\"is'a\055test" 'this\"is\\a\055test'}
719} {0 {this"is'a-test this\"is\\a\055test}}
720do_test shell1-3-31.1 {
721 catchcmd {test.db} {.print "this\nis\ta\\test" 'this\nis\ta\\test'}
722} [list 0 "this\nis\ta\\test this\\nis\\ta\\\\test"]
723
724
drh5128e852012-04-24 13:14:49 +0000725# Test the output of the ".dump" command
726#
727do_test shell1-4.1 {
drh55a1b302013-09-04 16:08:50 +0000728 db close
729 forcedelete test.db
730 sqlite3 db test.db
drh5128e852012-04-24 13:14:49 +0000731 db eval {
drh55a1b302013-09-04 16:08:50 +0000732 PRAGMA encoding=UTF16;
drh5128e852012-04-24 13:14:49 +0000733 CREATE TABLE t1(x);
mistachkin585dcb22012-12-04 00:23:43 +0000734 INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f');
mistachkin151c75a2015-04-07 21:16:40 +0000735 CREATE TABLE t3(x,y);
736 INSERT INTO t3 VALUES(1,null), (2,''), (3,1),
737 (4,2.25), (5,'hello'), (6,x'807f');
drh5128e852012-04-24 13:14:49 +0000738 }
739 catchcmd test.db {.dump}
740} {0 {PRAGMA foreign_keys=OFF;
741BEGIN TRANSACTION;
742CREATE TABLE t1(x);
743INSERT INTO "t1" VALUES(NULL);
mistachkin585dcb22012-12-04 00:23:43 +0000744INSERT INTO "t1" VALUES('');
drh5128e852012-04-24 13:14:49 +0000745INSERT INTO "t1" VALUES(1);
746INSERT INTO "t1" VALUES(2.25);
747INSERT INTO "t1" VALUES('hello');
748INSERT INTO "t1" VALUES(X'807F');
mistachkin151c75a2015-04-07 21:16:40 +0000749CREATE TABLE t3(x,y);
750INSERT INTO "t3" VALUES(1,NULL);
751INSERT INTO "t3" VALUES(2,'');
752INSERT INTO "t3" VALUES(3,1);
753INSERT INTO "t3" VALUES(4,2.25);
754INSERT INTO "t3" VALUES(5,'hello');
755INSERT INTO "t3" VALUES(6,X'807F');
drh5128e852012-04-24 13:14:49 +0000756COMMIT;}}
757
758# Test the output of ".mode insert"
759#
mistachkin151c75a2015-04-07 21:16:40 +0000760do_test shell1-4.2.1 {
drh5128e852012-04-24 13:14:49 +0000761 catchcmd test.db ".mode insert t1\nselect * from t1;"
762} {0 {INSERT INTO t1 VALUES(NULL);
mistachkin585dcb22012-12-04 00:23:43 +0000763INSERT INTO t1 VALUES('');
drh5128e852012-04-24 13:14:49 +0000764INSERT INTO t1 VALUES(1);
765INSERT INTO t1 VALUES(2.25);
766INSERT INTO t1 VALUES('hello');
767INSERT INTO t1 VALUES(X'807f');}}
768
mistachkin151c75a2015-04-07 21:16:40 +0000769# Test the output of ".mode insert" with headers
770#
771do_test shell1-4.2.2 {
772 catchcmd test.db ".mode insert t1\n.headers on\nselect * from t1;"
773} {0 {INSERT INTO t1(x) VALUES(NULL);
774INSERT INTO t1(x) VALUES('');
775INSERT INTO t1(x) VALUES(1);
776INSERT INTO t1(x) VALUES(2.25);
777INSERT INTO t1(x) VALUES('hello');
778INSERT INTO t1(x) VALUES(X'807f');}}
779
780# Test the output of ".mode insert"
781#
782do_test shell1-4.2.3 {
783 catchcmd test.db ".mode insert t3\nselect * from t3;"
784} {0 {INSERT INTO t3 VALUES(1,NULL);
785INSERT INTO t3 VALUES(2,'');
786INSERT INTO t3 VALUES(3,1);
787INSERT INTO t3 VALUES(4,2.25);
788INSERT INTO t3 VALUES(5,'hello');
789INSERT INTO t3 VALUES(6,X'807f');}}
790
791# Test the output of ".mode insert" with headers
792#
mistachkincc445402015-04-07 21:17:53 +0000793do_test shell1-4.2.4 {
mistachkin151c75a2015-04-07 21:16:40 +0000794 catchcmd test.db ".mode insert t3\n.headers on\nselect * from t3;"
795} {0 {INSERT INTO t3(x,y) VALUES(1,NULL);
796INSERT INTO t3(x,y) VALUES(2,'');
797INSERT INTO t3(x,y) VALUES(3,1);
798INSERT INTO t3(x,y) VALUES(4,2.25);
799INSERT INTO t3(x,y) VALUES(5,'hello');
800INSERT INTO t3(x,y) VALUES(6,X'807f');}}
801
mistachkin585dcb22012-12-04 00:23:43 +0000802# Test the output of ".mode tcl"
803#
804do_test shell1-4.3 {
drh55a1b302013-09-04 16:08:50 +0000805 db close
806 forcedelete test.db
807 sqlite3 db test.db
808 db eval {
809 PRAGMA encoding=UTF8;
810 CREATE TABLE t1(x);
811 INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f');
812 }
mistachkin585dcb22012-12-04 00:23:43 +0000813 catchcmd test.db ".mode tcl\nselect * from t1;"
814} {0 {""
815""
816"1"
817"2.25"
818"hello"
819"\200\177"}}
820
821# Test the output of ".mode tcl" with multiple columns
822#
823do_test shell1-4.4 {
824 db eval {
825 CREATE TABLE t2(x,y);
826 INSERT INTO t2 VALUES(null, ''), (1, 2.25), ('hello', x'807f');
827 }
828 catchcmd test.db ".mode tcl\nselect * from t2;"
829} {0 {"" ""
830"1" "2.25"
831"hello" "\200\177"}}
832
833# Test the output of ".mode tcl" with ".nullvalue"
834#
835do_test shell1-4.5 {
836 catchcmd test.db ".mode tcl\n.nullvalue NULL\nselect * from t2;"
837} {0 {"NULL" ""
838"1" "2.25"
839"hello" "\200\177"}}
840
841# Test the output of ".mode tcl" with Tcl reserved characters
842#
843do_test shell1-4.6 {
844 db eval {
845 CREATE TABLE tcl1(x);
846 INSERT INTO tcl1 VALUES('"'), ('['), (']'), ('\{'), ('\}'), (';'), ('$');
847 }
848 foreach {x y} [catchcmd test.db ".mode tcl\nselect * from tcl1;"] break
849 list $x $y [llength $y]
850} {0 {"\""
851"["
852"]"
853"\\{"
854"\\}"
855";"
856"$"} 7}
drh5128e852012-04-24 13:14:49 +0000857
mistachkinf21979d2015-01-18 05:35:01 +0000858# Test using arbitrary byte data with the shell via standard input/output.
859#
860do_test shell1-5.0 {
861 #
862 # NOTE: Skip NUL byte because it appears to be incompatible with command
863 # shell argument parsing.
864 #
865 for {set i 1} {$i < 256} {incr i} {
866 #
mistachkin46a6b992015-01-18 09:02:57 +0000867 # NOTE: Due to how the Tcl [exec] command works (i.e. where it treats
868 # command channels opened for it as textual ones), the carriage
869 # return character (and on Windows, the end-of-file character)
870 # cannot be used here.
mistachkinf21979d2015-01-18 05:35:01 +0000871 #
mistachkin46a6b992015-01-18 09:02:57 +0000872 if {$i==0x0D || ($tcl_platform(platform)=="windows" && $i==0x1A)} {
mistachkinf21979d2015-01-18 05:35:01 +0000873 continue
874 }
drh01725682016-07-25 14:20:01 +0000875 if {$i>=0xE0 && $tcl_platform(os)=="OpenBSD"} continue
mistachkinbe56ad32016-07-29 04:12:18 +0000876 if {$i>=0xE0 && $i<=0xEF && $tcl_platform(os)=="Linux"} continue
mistachkinf21979d2015-01-18 05:35:01 +0000877 set hex [format %02X $i]
878 set char [subst \\x$hex]; set oldChar $char
mistachkin0acee512015-01-19 21:11:31 +0000879 set escapes [list]
880 if {$tcl_platform(platform)=="windows"} {
881 #
882 # NOTE: On Windows, we need to escape all the whitespace characters,
883 # the alarm (\a) character, and those with special meaning to
884 # the SQLite shell itself.
885 #
886 set escapes [list \
887 \a \\a \b \\b \t \\t \n \\n \v \\v \f \\f \r \\r \
888 " " "\" \"" \" \\\" ' \"'\" \\ \\\\]
889 } else {
890 #
891 # NOTE: On Unix, we need to escape most of the whitespace characters
892 # and those with special meaning to the SQLite shell itself.
893 # The alarm (\a), backspace (\b), and carriage-return (\r)
894 # characters do not appear to require escaping on Unix. For
895 # the alarm and backspace characters, this is probably due to
896 # differences in the command shell. For the carriage-return,
897 # it is probably due to differences in how Tcl handles command
898 # channel end-of-line translations.
899 #
900 set escapes [list \
901 \t \\t \n \\n \v \\v \f \\f \
902 " " "\" \"" \" \\\" ' \"'\" \\ \\\\]
903 }
904 set char [string map $escapes $char]
mistachkinbfefa4c2015-01-19 21:27:46 +0000905 set x [catchcmdex test.db ".print $char\n"]
mistachkinf21979d2015-01-18 05:35:01 +0000906 set code [lindex $x 0]
907 set res [lindex $x 1]
908 if {$code ne "0"} {
909 error "failed with error: $res"
910 }
911 if {$res ne "$oldChar\n"} {
mistachkin48dcf2b2016-04-04 17:59:37 +0000912 if {[llength $res] > 0} {
913 set got [format %02X [scan $res %c]]
914 } else {
915 set got <empty>
916 }
917 error "failed with byte $hex mismatch, got $got"
mistachkinf21979d2015-01-18 05:35:01 +0000918 }
919 }
920} {}
921
drh697c9ea2016-05-16 11:55:09 +0000922# These test cases do not work on MinGW
923if 0 {
924
mistachkin49e11252016-04-04 15:47:46 +0000925# The string used here is the word "test" in Chinese.
926# In UTF-8, it is encoded as: \xE6\xB5\x8B\xE8\xAF\x95
927set test \u6D4B\u8BD5
928
mistachkin1fe36bb2016-04-04 02:16:44 +0000929do_test shell1-6.0 {
mistachkin49e11252016-04-04 15:47:46 +0000930 set fileName $test; append fileName .db
931 catch {forcedelete $fileName}
mistachkin1fe36bb2016-04-04 02:16:44 +0000932 set x [catchcmdex $fileName "CREATE TABLE t1(x);\n.schema\n"]
933 set code [lindex $x 0]
934 set res [string trim [lindex $x 1]]
935 if {$code ne "0"} {
936 error "failed with error: $res"
937 }
938 if {$res ne "CREATE TABLE t1(x);"} {
939 error "failed with mismatch: $res"
940 }
941 if {![file exists $fileName]} {
mistachkin1810f222016-04-04 02:33:34 +0000942 error "file \"$fileName\" (Unicode) does not exist"
mistachkin1fe36bb2016-04-04 02:16:44 +0000943 }
944 forcedelete $fileName
945} {}
946
mistachkin49e11252016-04-04 15:47:46 +0000947do_test shell1-6.1 {
948 catch {forcedelete test3.db}
949 set x [catchcmdex test3.db \
950 "CREATE TABLE [encoding convertto utf-8 $test](x);\n.schema\n"]
951 set code [lindex $x 0]
952 set res [string trim [lindex $x 1]]
953 if {$code ne "0"} {
954 error "failed with error: $res"
955 }
956 if {$res ne "CREATE TABLE ${test}(x);"} {
957 error "failed with mismatch: $res"
958 }
959 forcedelete test3.db
960} {}
drh697c9ea2016-05-16 11:55:09 +0000961}
mistachkin49e11252016-04-04 15:47:46 +0000962
drh8df91852012-04-24 12:46:05 +0000963finish_test