blob: 81883a8d189d6e6ac7e5826c9944300e2722171a [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"
drhdbc26722017-07-10 18:04:41 +0000303} {1 {Usage: .dump ?--preserve-rowids? ?--newlines? ?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"
drha501f7d2017-06-29 21:33:25 +0000432} {0 {current output mode: list}}
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"
drh6c9dcc42018-01-10 23:27:30 +0000498} {1 {Usage: .output [-e|-x|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"
drh6c9dcc42018-01-10 23:27:30 +0000507} {1 {Usage: .output [-e|-x|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
drha22dd382017-06-24 19:21:48 +0000561ifcapable vtab {
shaneha05e0c42009-11-06 03:22:54 +0000562# .schema ?TABLE? Show the CREATE statements
563# If TABLE specified, only show tables matching
564# LIKE pattern TABLE.
shaneh5fc25012009-11-11 04:17:07 +0000565do_test shell1-3.21.1 {
shanehca7dfda2009-12-17 21:07:54 +0000566 catchcmd "test.db" ".schema"
shaneha05e0c42009-11-06 03:22:54 +0000567} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000568do_test shell1-3.21.2 {
shanehca7dfda2009-12-17 21:07:54 +0000569 catchcmd "test.db" ".schema FOO"
shaneha05e0c42009-11-06 03:22:54 +0000570} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000571do_test shell1-3.21.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000572 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000573 catchcmd "test.db" ".schema FOO BAD"
drh4926fec2016-04-13 15:33:42 +0000574} {1 {Usage: .schema ?--indent? ?LIKE-PATTERN?}}
shaneha05e0c42009-11-06 03:22:54 +0000575
drhac43e982012-05-21 03:15:06 +0000576do_test shell1-3.21.4 {
577 catchcmd "test.db" {
578 CREATE TABLE t1(x);
579 CREATE VIEW v2 AS SELECT x+1 AS y FROM t1;
580 CREATE VIEW v1 AS SELECT y+1 FROM v2;
581 }
582 catchcmd "test.db" ".schema"
583} {0 {CREATE TABLE t1(x);
drhceba7922018-01-01 21:28:25 +0000584CREATE VIEW v2 AS SELECT x+1 AS y FROM t1
drh1d315cf2018-01-01 21:49:43 +0000585/* v2(y) */;
drhceba7922018-01-01 21:28:25 +0000586CREATE VIEW v1 AS SELECT y+1 FROM v2
drh1d315cf2018-01-01 21:49:43 +0000587/* v1("y+1") */;}}
drhac43e982012-05-21 03:15:06 +0000588db eval {DROP VIEW v1; DROP VIEW v2; DROP TABLE t1;}
drha22dd382017-06-24 19:21:48 +0000589}
drhac43e982012-05-21 03:15:06 +0000590
mistachkin636bf9f2014-07-19 20:15:16 +0000591# .separator STRING Change column separator used by output and .import
shaneh5fc25012009-11-11 04:17:07 +0000592do_test shell1-3.22.1 {
shanehca7dfda2009-12-17 21:07:54 +0000593 catchcmd "test.db" ".separator"
mistachkine0d68852014-12-11 03:12:33 +0000594} {1 {Usage: .separator COL ?ROW?}}
shaneh5fc25012009-11-11 04:17:07 +0000595do_test shell1-3.22.2 {
shanehca7dfda2009-12-17 21:07:54 +0000596 catchcmd "test.db" ".separator FOO"
shaneha05e0c42009-11-06 03:22:54 +0000597} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000598do_test shell1-3.22.3 {
drh6976c212014-07-24 12:09:47 +0000599 catchcmd "test.db" ".separator ABC XYZ"
600} {0 {}}
601do_test shell1-3.22.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000602 # too many arguments
drh6976c212014-07-24 12:09:47 +0000603 catchcmd "test.db" ".separator FOO BAD BAD2"
mistachkine0d68852014-12-11 03:12:33 +0000604} {1 {Usage: .separator COL ?ROW?}}
shaneha05e0c42009-11-06 03:22:54 +0000605
606# .show Show the current values for various settings
shaneh5fc25012009-11-11 04:17:07 +0000607do_test shell1-3.23.1 {
shanehca7dfda2009-12-17 21:07:54 +0000608 set res [catchcmd "test.db" ".show"]
shaneha05e0c42009-11-06 03:22:54 +0000609 list [regexp {echo:} $res] \
610 [regexp {explain:} $res] \
611 [regexp {headers:} $res] \
612 [regexp {mode:} $res] \
613 [regexp {nullvalue:} $res] \
614 [regexp {output:} $res] \
mistachkin636bf9f2014-07-19 20:15:16 +0000615 [regexp {colseparator:} $res] \
616 [regexp {rowseparator:} $res] \
shaneh642d8b82010-07-28 16:05:34 +0000617 [regexp {stats:} $res] \
shaneha05e0c42009-11-06 03:22:54 +0000618 [regexp {width:} $res]
mistachkine0d68852014-12-11 03:12:33 +0000619} {1 1 1 1 1 1 1 1 1 1}
shaneh5fc25012009-11-11 04:17:07 +0000620do_test shell1-3.23.2 {
shanehe2aa9d72009-11-06 17:20:17 +0000621 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000622 catchcmd "test.db" ".show BAD"
drhc2ce0be2014-05-29 12:36:14 +0000623} {1 {Usage: .show}}
shaneha05e0c42009-11-06 03:22:54 +0000624
shaneh642d8b82010-07-28 16:05:34 +0000625# .stats ON|OFF Turn stats on or off
drh34784902016-02-27 17:12:36 +0000626#do_test shell1-3.23b.1 {
627# catchcmd "test.db" ".stats"
628#} {1 {Usage: .stats on|off}}
shaneh642d8b82010-07-28 16:05:34 +0000629do_test shell1-3.23b.2 {
630 catchcmd "test.db" ".stats ON"
631} {0 {}}
632do_test shell1-3.23b.3 {
633 catchcmd "test.db" ".stats OFF"
634} {0 {}}
635do_test shell1-3.23b.4 {
636 # too many arguments
637 catchcmd "test.db" ".stats OFF BAD"
drh34784902016-02-27 17:12:36 +0000638} {1 {Usage: .stats ?on|off?}}
shaneh642d8b82010-07-28 16:05:34 +0000639
shaneha05e0c42009-11-06 03:22:54 +0000640# .tables ?TABLE? List names of tables
641# If TABLE specified, only list tables matching
642# LIKE pattern TABLE.
shaneh5fc25012009-11-11 04:17:07 +0000643do_test shell1-3.24.1 {
shanehca7dfda2009-12-17 21:07:54 +0000644 catchcmd "test.db" ".tables"
shaneha05e0c42009-11-06 03:22:54 +0000645} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000646do_test shell1-3.24.2 {
shanehca7dfda2009-12-17 21:07:54 +0000647 catchcmd "test.db" ".tables FOO"
shaneha05e0c42009-11-06 03:22:54 +0000648} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000649do_test shell1-3.24.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000650 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000651 catchcmd "test.db" ".tables FOO BAD"
drhc2ce0be2014-05-29 12:36:14 +0000652} {0 {}}
shaneha05e0c42009-11-06 03:22:54 +0000653
654# .timeout MS Try opening locked tables for MS milliseconds
shaneh5fc25012009-11-11 04:17:07 +0000655do_test shell1-3.25.1 {
shanehca7dfda2009-12-17 21:07:54 +0000656 catchcmd "test.db" ".timeout"
drhc2ce0be2014-05-29 12:36:14 +0000657} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000658do_test shell1-3.25.2 {
shanehca7dfda2009-12-17 21:07:54 +0000659 catchcmd "test.db" ".timeout zzz"
shanehe2aa9d72009-11-06 17:20:17 +0000660 # this should be treated the same as a '0' timeout
shaneha05e0c42009-11-06 03:22:54 +0000661} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000662do_test shell1-3.25.3 {
shanehca7dfda2009-12-17 21:07:54 +0000663 catchcmd "test.db" ".timeout 1"
shaneha05e0c42009-11-06 03:22:54 +0000664} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000665do_test shell1-3.25.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000666 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000667 catchcmd "test.db" ".timeout 1 BAD"
drhc2ce0be2014-05-29 12:36:14 +0000668} {0 {}}
shaneha05e0c42009-11-06 03:22:54 +0000669
670# .width NUM NUM ... Set column widths for "column" mode
shaneh5fc25012009-11-11 04:17:07 +0000671do_test shell1-3.26.1 {
shanehca7dfda2009-12-17 21:07:54 +0000672 catchcmd "test.db" ".width"
drhc2ce0be2014-05-29 12:36:14 +0000673} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000674do_test shell1-3.26.2 {
shanehca7dfda2009-12-17 21:07:54 +0000675 catchcmd "test.db" ".width xxx"
shanehe2aa9d72009-11-06 17:20:17 +0000676 # this should be treated the same as a '0' width for col 1
shaneha05e0c42009-11-06 03:22:54 +0000677} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000678do_test shell1-3.26.3 {
shanehca7dfda2009-12-17 21:07:54 +0000679 catchcmd "test.db" ".width xxx yyy"
shanehe2aa9d72009-11-06 17:20:17 +0000680 # this should be treated the same as a '0' width for col 1 and 2
shaneha05e0c42009-11-06 03:22:54 +0000681} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000682do_test shell1-3.26.4 {
shanehca7dfda2009-12-17 21:07:54 +0000683 catchcmd "test.db" ".width 1 1"
shanehe2aa9d72009-11-06 17:20:17 +0000684 # this should be treated the same as a '1' width for col 1 and 2
shaneha05e0c42009-11-06 03:22:54 +0000685} {0 {}}
drh078b1fd2012-09-21 13:40:02 +0000686do_test shell1-3.26.5 {
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}}
690do_test shell1-3.26.6 {
691 catchcmd "test.db" ".mode column\n.width -10 10\nSELECT 'abcdefg', 123456;"
692 # this should be treated the same as a '1' width for col 1 and 2
693} {0 { abcdefg 123456 }}
694
shaneha05e0c42009-11-06 03:22:54 +0000695
696# .timer ON|OFF Turn the CPU timer measurement on or off
shaneh5fc25012009-11-11 04:17:07 +0000697do_test shell1-3.27.1 {
shanehca7dfda2009-12-17 21:07:54 +0000698 catchcmd "test.db" ".timer"
drhc2ce0be2014-05-29 12:36:14 +0000699} {1 {Usage: .timer on|off}}
shaneh5fc25012009-11-11 04:17:07 +0000700do_test shell1-3.27.2 {
shanehca7dfda2009-12-17 21:07:54 +0000701 catchcmd "test.db" ".timer ON"
shaneha05e0c42009-11-06 03:22:54 +0000702} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000703do_test shell1-3.27.3 {
shanehca7dfda2009-12-17 21:07:54 +0000704 catchcmd "test.db" ".timer OFF"
shaneha05e0c42009-11-06 03:22:54 +0000705} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000706do_test shell1-3.27.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000707 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000708 catchcmd "test.db" ".timer OFF BAD"
drhc2ce0be2014-05-29 12:36:14 +0000709} {1 {Usage: .timer on|off}}
shaneha05e0c42009-11-06 03:22:54 +0000710
drh53a9d152011-04-25 18:20:04 +0000711do_test shell1-3-28.1 {
712 catchcmd test.db \
713 ".log stdout\nSELECT coalesce(sqlite_log(123,'hello'),'456');"
714} "0 {(123) hello\n456}"
715
drh078b1fd2012-09-21 13:40:02 +0000716do_test shell1-3-29.1 {
717 catchcmd "test.db" ".print this is a test"
718} {0 {this is a test}}
719
drh4c56b992013-06-27 13:26:55 +0000720# dot-command argument quoting
721do_test shell1-3-30.1 {
722 catchcmd {test.db} {.print "this\"is'a\055test" 'this\"is\\a\055test'}
723} {0 {this"is'a-test this\"is\\a\055test}}
724do_test shell1-3-31.1 {
725 catchcmd {test.db} {.print "this\nis\ta\\test" 'this\nis\ta\\test'}
726} [list 0 "this\nis\ta\\test this\\nis\\ta\\\\test"]
727
728
drh5128e852012-04-24 13:14:49 +0000729# Test the output of the ".dump" command
730#
731do_test shell1-4.1 {
drh55a1b302013-09-04 16:08:50 +0000732 db close
733 forcedelete test.db
734 sqlite3 db test.db
drh5128e852012-04-24 13:14:49 +0000735 db eval {
drh55a1b302013-09-04 16:08:50 +0000736 PRAGMA encoding=UTF16;
drh5128e852012-04-24 13:14:49 +0000737 CREATE TABLE t1(x);
mistachkin585dcb22012-12-04 00:23:43 +0000738 INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f');
mistachkin151c75a2015-04-07 21:16:40 +0000739 CREATE TABLE t3(x,y);
740 INSERT INTO t3 VALUES(1,null), (2,''), (3,1),
741 (4,2.25), (5,'hello'), (6,x'807f');
drh5128e852012-04-24 13:14:49 +0000742 }
743 catchcmd test.db {.dump}
744} {0 {PRAGMA foreign_keys=OFF;
745BEGIN TRANSACTION;
746CREATE TABLE t1(x);
drhf42d3182017-03-08 12:25:18 +0000747INSERT INTO t1 VALUES(NULL);
748INSERT INTO t1 VALUES('');
749INSERT INTO t1 VALUES(1);
750INSERT INTO t1 VALUES(2.25);
751INSERT INTO t1 VALUES('hello');
752INSERT INTO t1 VALUES(X'807f');
mistachkin151c75a2015-04-07 21:16:40 +0000753CREATE TABLE t3(x,y);
drhf42d3182017-03-08 12:25:18 +0000754INSERT INTO t3 VALUES(1,NULL);
755INSERT INTO t3 VALUES(2,'');
756INSERT INTO t3 VALUES(3,1);
757INSERT INTO t3 VALUES(4,2.25);
758INSERT INTO t3 VALUES(5,'hello');
759INSERT INTO t3 VALUES(6,X'807f');
drh5128e852012-04-24 13:14:49 +0000760COMMIT;}}
761
danb9cd86a2017-03-25 18:31:42 +0000762
763ifcapable vtab {
764
drhf42d3182017-03-08 12:25:18 +0000765# The --preserve-rowids option to .dump
766#
drhe611f142017-03-08 11:44:00 +0000767do_test shell1-4.1.1 {
768 catchcmd test.db {.dump --preserve-rowids}
769} {0 {PRAGMA foreign_keys=OFF;
770BEGIN TRANSACTION;
771CREATE TABLE t1(x);
drhf42d3182017-03-08 12:25:18 +0000772INSERT INTO t1(rowid,x) VALUES(1,NULL);
773INSERT INTO t1(rowid,x) VALUES(2,'');
774INSERT INTO t1(rowid,x) VALUES(3,1);
775INSERT INTO t1(rowid,x) VALUES(4,2.25);
776INSERT INTO t1(rowid,x) VALUES(5,'hello');
777INSERT INTO t1(rowid,x) VALUES(6,X'807f');
drhe611f142017-03-08 11:44:00 +0000778CREATE TABLE t3(x,y);
drhf42d3182017-03-08 12:25:18 +0000779INSERT INTO t3(rowid,x,y) VALUES(1,1,NULL);
780INSERT INTO t3(rowid,x,y) VALUES(2,2,'');
781INSERT INTO t3(rowid,x,y) VALUES(3,3,1);
782INSERT INTO t3(rowid,x,y) VALUES(4,4,2.25);
783INSERT INTO t3(rowid,x,y) VALUES(5,5,'hello');
784INSERT INTO t3(rowid,x,y) VALUES(6,6,X'807f');
drhe611f142017-03-08 11:44:00 +0000785COMMIT;}}
786
drhf42d3182017-03-08 12:25:18 +0000787# If the table contains an INTEGER PRIMARY KEY, do not record a separate
788# rowid column in the output.
789#
drhe611f142017-03-08 11:44:00 +0000790do_test shell1-4.1.2 {
791 db close
792 forcedelete test2.db
793 sqlite3 db test2.db
794 db eval {
795 CREATE TABLE t1(x INTEGER PRIMARY KEY, y);
796 INSERT INTO t1 VALUES(1,null), (2,''), (3,1),
797 (4,2.25), (5,'hello'), (6,x'807f');
798 }
799 catchcmd test2.db {.dump --preserve-rowids}
800} {0 {PRAGMA foreign_keys=OFF;
801BEGIN TRANSACTION;
802CREATE TABLE t1(x INTEGER PRIMARY KEY, y);
drhf42d3182017-03-08 12:25:18 +0000803INSERT INTO t1 VALUES(1,NULL);
804INSERT INTO t1 VALUES(2,'');
805INSERT INTO t1 VALUES(3,1);
806INSERT INTO t1 VALUES(4,2.25);
807INSERT INTO t1 VALUES(5,'hello');
808INSERT INTO t1 VALUES(6,X'807f');
drhe611f142017-03-08 11:44:00 +0000809COMMIT;}}
810
drhf42d3182017-03-08 12:25:18 +0000811# Verify that the table named [table] is correctly quoted and that
812# an INTEGER PRIMARY KEY DESC is not an alias for the rowid.
813#
814do_test shell1-4.1.3 {
815 db close
816 forcedelete test2.db
817 sqlite3 db test2.db
818 db eval {
819 CREATE TABLE [table](x INTEGER PRIMARY KEY DESC, y);
820 INSERT INTO [table] VALUES(1,null), (12,''), (23,1),
821 (34,2.25), (45,'hello'), (56,x'807f');
822 }
823 catchcmd test2.db {.dump --preserve-rowids}
824} {0 {PRAGMA foreign_keys=OFF;
825BEGIN TRANSACTION;
826CREATE TABLE [table](x INTEGER PRIMARY KEY DESC, y);
827INSERT INTO "table"(rowid,x,y) VALUES(1,1,NULL);
828INSERT INTO "table"(rowid,x,y) VALUES(2,12,'');
829INSERT INTO "table"(rowid,x,y) VALUES(3,23,1);
830INSERT INTO "table"(rowid,x,y) VALUES(4,34,2.25);
831INSERT INTO "table"(rowid,x,y) VALUES(5,45,'hello');
832INSERT INTO "table"(rowid,x,y) VALUES(6,56,X'807f');
833COMMIT;}}
834
835# Do not record rowids for a WITHOUT ROWID table. Also check correct quoting
836# of table names that contain odd characters.
837#
838do_test shell1-4.1.4 {
839 db close
840 forcedelete test2.db
841 sqlite3 db test2.db
842 db eval {
843 CREATE TABLE [ta<>ble](x INTEGER PRIMARY KEY, y) WITHOUT ROWID;
844 INSERT INTO [ta<>ble] VALUES(1,null), (12,''), (23,1),
845 (34,2.25), (45,'hello'), (56,x'807f');
846 }
847 catchcmd test2.db {.dump --preserve-rowids}
848} {0 {PRAGMA foreign_keys=OFF;
849BEGIN TRANSACTION;
850CREATE TABLE [ta<>ble](x INTEGER PRIMARY KEY, y) WITHOUT ROWID;
851INSERT INTO "ta<>ble" VALUES(1,NULL);
852INSERT INTO "ta<>ble" VALUES(12,'');
853INSERT INTO "ta<>ble" VALUES(23,1);
854INSERT INTO "ta<>ble" VALUES(34,2.25);
855INSERT INTO "ta<>ble" VALUES(45,'hello');
856INSERT INTO "ta<>ble" VALUES(56,X'807f');
857COMMIT;}}
858
859# Do not record rowids if the rowid is inaccessible
860#
861do_test shell1-4.1.5 {
862 db close
863 forcedelete test2.db
864 sqlite3 db test2.db
865 db eval {
866 CREATE TABLE t1(_ROWID_,rowid,oid);
867 INSERT INTO t1 VALUES(1,null,'alpha'), (12,'',99), (23,1,x'b0b1b2');
868 }
869 catchcmd test2.db {.dump --preserve-rowids}
870} {0 {PRAGMA foreign_keys=OFF;
871BEGIN TRANSACTION;
872CREATE TABLE t1(_ROWID_,rowid,oid);
873INSERT INTO t1 VALUES(1,NULL,'alpha');
874INSERT INTO t1 VALUES(12,'',99);
875INSERT INTO t1 VALUES(23,1,X'b0b1b2');
876COMMIT;}}
drhe611f142017-03-08 11:44:00 +0000877
danb9cd86a2017-03-25 18:31:42 +0000878} else {
879
880do_test shell1-4.1.6 {
881 db close
882 forcedelete test2.db
883 sqlite3 db test2.db
884 db eval {
885 CREATE TABLE t1(x INTEGER PRIMARY KEY, y);
886 INSERT INTO t1 VALUES(1,null), (2,''), (3,1),
887 (4,2.25), (5,'hello'), (6,x'807f');
888 }
889 catchcmd test2.db {.dump --preserve-rowids}
890} {1 {The --preserve-rowids option is not compatible with SQLITE_OMIT_VIRTUALTABLE}}
891
892}
893
894
drh5128e852012-04-24 13:14:49 +0000895# Test the output of ".mode insert"
896#
mistachkin151c75a2015-04-07 21:16:40 +0000897do_test shell1-4.2.1 {
drh5128e852012-04-24 13:14:49 +0000898 catchcmd test.db ".mode insert t1\nselect * from t1;"
899} {0 {INSERT INTO t1 VALUES(NULL);
mistachkin585dcb22012-12-04 00:23:43 +0000900INSERT INTO t1 VALUES('');
drh5128e852012-04-24 13:14:49 +0000901INSERT INTO t1 VALUES(1);
902INSERT INTO t1 VALUES(2.25);
903INSERT INTO t1 VALUES('hello');
904INSERT INTO t1 VALUES(X'807f');}}
905
mistachkin151c75a2015-04-07 21:16:40 +0000906# Test the output of ".mode insert" with headers
907#
908do_test shell1-4.2.2 {
909 catchcmd test.db ".mode insert t1\n.headers on\nselect * from t1;"
910} {0 {INSERT INTO t1(x) VALUES(NULL);
911INSERT INTO t1(x) VALUES('');
912INSERT INTO t1(x) VALUES(1);
913INSERT INTO t1(x) VALUES(2.25);
914INSERT INTO t1(x) VALUES('hello');
915INSERT INTO t1(x) VALUES(X'807f');}}
916
917# Test the output of ".mode insert"
918#
919do_test shell1-4.2.3 {
920 catchcmd test.db ".mode insert t3\nselect * from t3;"
921} {0 {INSERT INTO t3 VALUES(1,NULL);
922INSERT INTO t3 VALUES(2,'');
923INSERT INTO t3 VALUES(3,1);
924INSERT INTO t3 VALUES(4,2.25);
925INSERT INTO t3 VALUES(5,'hello');
926INSERT INTO t3 VALUES(6,X'807f');}}
927
928# Test the output of ".mode insert" with headers
929#
mistachkincc445402015-04-07 21:17:53 +0000930do_test shell1-4.2.4 {
mistachkin151c75a2015-04-07 21:16:40 +0000931 catchcmd test.db ".mode insert t3\n.headers on\nselect * from t3;"
932} {0 {INSERT INTO t3(x,y) VALUES(1,NULL);
933INSERT INTO t3(x,y) VALUES(2,'');
934INSERT INTO t3(x,y) VALUES(3,1);
935INSERT INTO t3(x,y) VALUES(4,2.25);
936INSERT INTO t3(x,y) VALUES(5,'hello');
937INSERT INTO t3(x,y) VALUES(6,X'807f');}}
938
mistachkin585dcb22012-12-04 00:23:43 +0000939# Test the output of ".mode tcl"
940#
941do_test shell1-4.3 {
drh55a1b302013-09-04 16:08:50 +0000942 db close
943 forcedelete test.db
944 sqlite3 db test.db
945 db eval {
946 PRAGMA encoding=UTF8;
947 CREATE TABLE t1(x);
948 INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f');
949 }
mistachkin585dcb22012-12-04 00:23:43 +0000950 catchcmd test.db ".mode tcl\nselect * from t1;"
951} {0 {""
952""
953"1"
954"2.25"
955"hello"
956"\200\177"}}
957
958# Test the output of ".mode tcl" with multiple columns
959#
960do_test shell1-4.4 {
961 db eval {
962 CREATE TABLE t2(x,y);
963 INSERT INTO t2 VALUES(null, ''), (1, 2.25), ('hello', x'807f');
964 }
965 catchcmd test.db ".mode tcl\nselect * from t2;"
966} {0 {"" ""
967"1" "2.25"
968"hello" "\200\177"}}
969
970# Test the output of ".mode tcl" with ".nullvalue"
971#
972do_test shell1-4.5 {
973 catchcmd test.db ".mode tcl\n.nullvalue NULL\nselect * from t2;"
974} {0 {"NULL" ""
975"1" "2.25"
976"hello" "\200\177"}}
977
978# Test the output of ".mode tcl" with Tcl reserved characters
979#
980do_test shell1-4.6 {
981 db eval {
982 CREATE TABLE tcl1(x);
983 INSERT INTO tcl1 VALUES('"'), ('['), (']'), ('\{'), ('\}'), (';'), ('$');
984 }
985 foreach {x y} [catchcmd test.db ".mode tcl\nselect * from tcl1;"] break
986 list $x $y [llength $y]
987} {0 {"\""
988"["
989"]"
990"\\{"
991"\\}"
992";"
993"$"} 7}
drh5128e852012-04-24 13:14:49 +0000994
mistachkinf21979d2015-01-18 05:35:01 +0000995# Test using arbitrary byte data with the shell via standard input/output.
996#
997do_test shell1-5.0 {
998 #
999 # NOTE: Skip NUL byte because it appears to be incompatible with command
1000 # shell argument parsing.
1001 #
1002 for {set i 1} {$i < 256} {incr i} {
1003 #
mistachkin46a6b992015-01-18 09:02:57 +00001004 # NOTE: Due to how the Tcl [exec] command works (i.e. where it treats
1005 # command channels opened for it as textual ones), the carriage
1006 # return character (and on Windows, the end-of-file character)
1007 # cannot be used here.
mistachkinf21979d2015-01-18 05:35:01 +00001008 #
mistachkin46a6b992015-01-18 09:02:57 +00001009 if {$i==0x0D || ($tcl_platform(platform)=="windows" && $i==0x1A)} {
mistachkinf21979d2015-01-18 05:35:01 +00001010 continue
1011 }
drh01725682016-07-25 14:20:01 +00001012 if {$i>=0xE0 && $tcl_platform(os)=="OpenBSD"} continue
mistachkinbe56ad32016-07-29 04:12:18 +00001013 if {$i>=0xE0 && $i<=0xEF && $tcl_platform(os)=="Linux"} continue
mistachkinf21979d2015-01-18 05:35:01 +00001014 set hex [format %02X $i]
1015 set char [subst \\x$hex]; set oldChar $char
mistachkin0acee512015-01-19 21:11:31 +00001016 set escapes [list]
1017 if {$tcl_platform(platform)=="windows"} {
1018 #
1019 # NOTE: On Windows, we need to escape all the whitespace characters,
1020 # the alarm (\a) character, and those with special meaning to
1021 # the SQLite shell itself.
1022 #
1023 set escapes [list \
1024 \a \\a \b \\b \t \\t \n \\n \v \\v \f \\f \r \\r \
1025 " " "\" \"" \" \\\" ' \"'\" \\ \\\\]
1026 } else {
1027 #
1028 # NOTE: On Unix, we need to escape most of the whitespace characters
1029 # and those with special meaning to the SQLite shell itself.
1030 # The alarm (\a), backspace (\b), and carriage-return (\r)
1031 # characters do not appear to require escaping on Unix. For
1032 # the alarm and backspace characters, this is probably due to
1033 # differences in the command shell. For the carriage-return,
1034 # it is probably due to differences in how Tcl handles command
1035 # channel end-of-line translations.
1036 #
1037 set escapes [list \
1038 \t \\t \n \\n \v \\v \f \\f \
1039 " " "\" \"" \" \\\" ' \"'\" \\ \\\\]
1040 }
1041 set char [string map $escapes $char]
mistachkinbfefa4c2015-01-19 21:27:46 +00001042 set x [catchcmdex test.db ".print $char\n"]
mistachkinf21979d2015-01-18 05:35:01 +00001043 set code [lindex $x 0]
1044 set res [lindex $x 1]
1045 if {$code ne "0"} {
1046 error "failed with error: $res"
1047 }
1048 if {$res ne "$oldChar\n"} {
mistachkin48dcf2b2016-04-04 17:59:37 +00001049 if {[llength $res] > 0} {
1050 set got [format %02X [scan $res %c]]
1051 } else {
1052 set got <empty>
1053 }
1054 error "failed with byte $hex mismatch, got $got"
mistachkinf21979d2015-01-18 05:35:01 +00001055 }
1056 }
1057} {}
1058
drh697c9ea2016-05-16 11:55:09 +00001059# These test cases do not work on MinGW
1060if 0 {
1061
mistachkin49e11252016-04-04 15:47:46 +00001062# The string used here is the word "test" in Chinese.
1063# In UTF-8, it is encoded as: \xE6\xB5\x8B\xE8\xAF\x95
1064set test \u6D4B\u8BD5
1065
mistachkin1fe36bb2016-04-04 02:16:44 +00001066do_test shell1-6.0 {
mistachkin49e11252016-04-04 15:47:46 +00001067 set fileName $test; append fileName .db
1068 catch {forcedelete $fileName}
mistachkin1fe36bb2016-04-04 02:16:44 +00001069 set x [catchcmdex $fileName "CREATE TABLE t1(x);\n.schema\n"]
1070 set code [lindex $x 0]
1071 set res [string trim [lindex $x 1]]
1072 if {$code ne "0"} {
1073 error "failed with error: $res"
1074 }
1075 if {$res ne "CREATE TABLE t1(x);"} {
1076 error "failed with mismatch: $res"
1077 }
1078 if {![file exists $fileName]} {
mistachkin1810f222016-04-04 02:33:34 +00001079 error "file \"$fileName\" (Unicode) does not exist"
mistachkin1fe36bb2016-04-04 02:16:44 +00001080 }
1081 forcedelete $fileName
1082} {}
1083
mistachkin49e11252016-04-04 15:47:46 +00001084do_test shell1-6.1 {
1085 catch {forcedelete test3.db}
1086 set x [catchcmdex test3.db \
1087 "CREATE TABLE [encoding convertto utf-8 $test](x);\n.schema\n"]
1088 set code [lindex $x 0]
1089 set res [string trim [lindex $x 1]]
1090 if {$code ne "0"} {
1091 error "failed with error: $res"
1092 }
1093 if {$res ne "CREATE TABLE ${test}(x);"} {
1094 error "failed with mismatch: $res"
1095 }
1096 forcedelete test3.db
1097} {}
drh697c9ea2016-05-16 11:55:09 +00001098}
mistachkin49e11252016-04-04 15:47:46 +00001099
drh8df91852012-04-24 12:46:05 +00001100finish_test