blob: 330276120d5e5944066c91e2973c8fb995b19a88 [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
drhb7c46aa2020-11-25 13:59:47 +000067forcedelete FOO
68set out [open FOO w]
69puts $out ""
70close $out
shaneh5fc25012009-11-11 04:17:07 +000071do_test shell1-1.3.1 {
shanehca7dfda2009-12-17 21:07:54 +000072 catchcmd "-init FOO test.db" ""
shaneh5fc25012009-11-11 04:17:07 +000073} {0 {}}
74do_test shell1-1.3.2 {
drhac5649a2014-11-28 13:35:03 +000075 catchcmd "-init FOO test.db .quit BAD" ""
76} {0 {}}
77do_test shell1-1.3.3 {
78 catchcmd "-init FOO test.db BAD .quit" ""
79} {1 {Error: near "BAD": syntax error}}
shaneh5fc25012009-11-11 04:17:07 +000080
81# -echo print commands before execution
82do_test shell1-1.4.1 {
mistachkin1fe36bb2016-04-04 02:16:44 +000083 catchcmd "-echo test.db" ""
shaneh5fc25012009-11-11 04:17:07 +000084} {0 {}}
85
86# -[no]header turn headers on or off
87do_test shell1-1.5.1 {
mistachkin1fe36bb2016-04-04 02:16:44 +000088 catchcmd "-header test.db" ""
shaneh5fc25012009-11-11 04:17:07 +000089} {0 {}}
90do_test shell1-1.5.2 {
mistachkin1fe36bb2016-04-04 02:16:44 +000091 catchcmd "-noheader test.db" ""
shaneh5fc25012009-11-11 04:17:07 +000092} {0 {}}
93
94# -bail stop after hitting an error
95do_test shell1-1.6.1 {
mistachkin1fe36bb2016-04-04 02:16:44 +000096 catchcmd "-bail test.db" ""
shaneh5fc25012009-11-11 04:17:07 +000097} {0 {}}
98
99# -interactive force interactive I/O
100do_test shell1-1.7.1 {
101 set res [catchcmd "-interactive test.db" ".quit"]
102 set rc [lindex $res 0]
103 list $rc \
104 [regexp {SQLite version} $res] \
drh39a30882014-02-11 16:22:18 +0000105 [regexp {Enter ".help" for usage hints} $res]
shaneh5fc25012009-11-11 04:17:07 +0000106} {0 1 1}
107
108# -batch force batch I/O
109do_test shell1-1.8.1 {
mistachkin1fe36bb2016-04-04 02:16:44 +0000110 catchcmd "-batch test.db" ""
shaneh5fc25012009-11-11 04:17:07 +0000111} {0 {}}
112
113# -column set output mode to 'column'
114do_test shell1-1.9.1 {
mistachkin1fe36bb2016-04-04 02:16:44 +0000115 catchcmd "-column test.db" ""
shaneh5fc25012009-11-11 04:17:07 +0000116} {0 {}}
117
118# -csv set output mode to 'csv'
119do_test shell1-1.10.1 {
mistachkin1fe36bb2016-04-04 02:16:44 +0000120 catchcmd "-csv test.db" ""
shaneh5fc25012009-11-11 04:17:07 +0000121} {0 {}}
122
123# -html set output mode to HTML
124do_test shell1-1.11.1 {
mistachkin1fe36bb2016-04-04 02:16:44 +0000125 catchcmd "-html test.db" ""
shaneh5fc25012009-11-11 04:17:07 +0000126} {0 {}}
127
128# -line set output mode to 'line'
129do_test shell1-1.12.1 {
mistachkin1fe36bb2016-04-04 02:16:44 +0000130 catchcmd "-line test.db" ""
shaneh5fc25012009-11-11 04:17:07 +0000131} {0 {}}
132
133# -list set output mode to 'list'
134do_test shell1-1.13.1 {
mistachkin1fe36bb2016-04-04 02:16:44 +0000135 catchcmd "-list test.db" ""
shaneh5fc25012009-11-11 04:17:07 +0000136} {0 {}}
137
138# -separator 'x' set output field separator (|)
139do_test shell1-1.14.1 {
mistachkin1fe36bb2016-04-04 02:16:44 +0000140 catchcmd "-separator 'x' test.db" ""
shaneh5fc25012009-11-11 04:17:07 +0000141} {0 {}}
142do_test shell1-1.14.2 {
mistachkin1fe36bb2016-04-04 02:16:44 +0000143 catchcmd "-separator x test.db" ""
shaneh5fc25012009-11-11 04:17:07 +0000144} {0 {}}
145do_test shell1-1.14.3 {
146 set res [catchcmd "-separator" ""]
147 set rc [lindex $res 0]
148 list $rc \
drh98d312f2012-10-25 15:23:14 +0000149 [regexp {Error: missing argument to -separator} $res]
shaneh5fc25012009-11-11 04:17:07 +0000150} {1 1}
151
shaneh642d8b82010-07-28 16:05:34 +0000152# -stats print memory stats before each finalize
153do_test shell1-1.14b.1 {
mistachkin1fe36bb2016-04-04 02:16:44 +0000154 catchcmd "-stats test.db" ""
shaneh642d8b82010-07-28 16:05:34 +0000155} {0 {}}
156
shaneh5fc25012009-11-11 04:17:07 +0000157# -nullvalue 'text' set text string for NULL values
158do_test shell1-1.15.1 {
159 catchcmd "-nullvalue 'x' test.db" ""
160} {0 {}}
161do_test shell1-1.15.2 {
162 catchcmd "-nullvalue x test.db" ""
163} {0 {}}
164do_test shell1-1.15.3 {
165 set res [catchcmd "-nullvalue" ""]
166 set rc [lindex $res 0]
167 list $rc \
drh98d312f2012-10-25 15:23:14 +0000168 [regexp {Error: missing argument to -nullvalue} $res]
shaneh5fc25012009-11-11 04:17:07 +0000169} {1 1}
170
171# -version show SQLite version
172do_test shell1-1.16.1 {
drh9fd301b2011-06-03 13:28:22 +0000173 set x [catchcmd "-version test.db" ""]
drhb24c61a2012-05-21 22:45:35 +0000174} {/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 +0000175
shaneha05e0c42009-11-06 03:22:54 +0000176#----------------------------------------------------------------------------
shaneh5fc25012009-11-11 04:17:07 +0000177# Test cases shell1-2.*: Basic "dot" command token parsing.
shanehe2aa9d72009-11-06 17:20:17 +0000178#
179
180# check first token handling
shaneh5fc25012009-11-11 04:17:07 +0000181do_test shell1-2.1.1 {
mistachkin1fe36bb2016-04-04 02:16:44 +0000182 catchcmd "test.db" ".foo"
shanehe2aa9d72009-11-06 17:20:17 +0000183} {1 {Error: unknown command or invalid arguments: "foo". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000184do_test shell1-2.1.2 {
shanehca7dfda2009-12-17 21:07:54 +0000185 catchcmd "test.db" ".\"foo OFF\""
shanehe2aa9d72009-11-06 17:20:17 +0000186} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000187do_test shell1-2.1.3 {
shanehca7dfda2009-12-17 21:07:54 +0000188 catchcmd "test.db" ".\'foo OFF\'"
shanehe2aa9d72009-11-06 17:20:17 +0000189} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}}
190
191# unbalanced quotes
shaneh5fc25012009-11-11 04:17:07 +0000192do_test shell1-2.2.1 {
shanehca7dfda2009-12-17 21:07:54 +0000193 catchcmd "test.db" ".\"foo OFF"
shanehe2aa9d72009-11-06 17:20:17 +0000194} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000195do_test shell1-2.2.2 {
shanehca7dfda2009-12-17 21:07:54 +0000196 catchcmd "test.db" ".\'foo OFF"
shanehe2aa9d72009-11-06 17:20:17 +0000197} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000198do_test shell1-2.2.3 {
shanehca7dfda2009-12-17 21:07:54 +0000199 catchcmd "test.db" ".explain \"OFF"
shanehe2aa9d72009-11-06 17:20:17 +0000200} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000201do_test shell1-2.2.4 {
shanehca7dfda2009-12-17 21:07:54 +0000202 catchcmd "test.db" ".explain \'OFF"
shanehe2aa9d72009-11-06 17:20:17 +0000203} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000204do_test shell1-2.2.5 {
shanehca7dfda2009-12-17 21:07:54 +0000205 catchcmd "test.db" ".mode \"insert FOO"
drh0908e382020-06-04 18:05:39 +0000206} {1 {Error: mode should be one of: ascii box column csv html insert json line list markdown quote table tabs tcl}}
shaneh5fc25012009-11-11 04:17:07 +0000207do_test shell1-2.2.6 {
shanehca7dfda2009-12-17 21:07:54 +0000208 catchcmd "test.db" ".mode \'insert FOO"
drh0908e382020-06-04 18:05:39 +0000209} {1 {Error: mode should be one of: ascii box column csv html insert json line list markdown quote table tabs tcl}}
shanehe2aa9d72009-11-06 17:20:17 +0000210
211# check multiple tokens, and quoted tokens
shaneh5fc25012009-11-11 04:17:07 +0000212do_test shell1-2.3.1 {
shanehca7dfda2009-12-17 21:07:54 +0000213 catchcmd "test.db" ".explain 1"
shanehe2aa9d72009-11-06 17:20:17 +0000214} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000215do_test shell1-2.3.2 {
shanehca7dfda2009-12-17 21:07:54 +0000216 catchcmd "test.db" ".explain on"
shanehe2aa9d72009-11-06 17:20:17 +0000217} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000218do_test shell1-2.3.3 {
shanehca7dfda2009-12-17 21:07:54 +0000219 catchcmd "test.db" ".explain \"1 2 3\""
drh173ba092013-01-28 18:18:26 +0000220} {1 {ERROR: Not a boolean value: "1 2 3". Assuming "no".}}
shaneh5fc25012009-11-11 04:17:07 +0000221do_test shell1-2.3.4 {
shanehca7dfda2009-12-17 21:07:54 +0000222 catchcmd "test.db" ".explain \"OFF\""
shanehe2aa9d72009-11-06 17:20:17 +0000223} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000224do_test shell1-2.3.5 {
shanehca7dfda2009-12-17 21:07:54 +0000225 catchcmd "test.db" ".\'explain\' \'OFF\'"
shanehe2aa9d72009-11-06 17:20:17 +0000226} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000227do_test shell1-2.3.6 {
shanehca7dfda2009-12-17 21:07:54 +0000228 catchcmd "test.db" ".explain \'OFF\'"
shanehe2aa9d72009-11-06 17:20:17 +0000229} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000230do_test shell1-2.3.7 {
shanehca7dfda2009-12-17 21:07:54 +0000231 catchcmd "test.db" ".\'explain\' \'OFF\'"
shanehe2aa9d72009-11-06 17:20:17 +0000232} {0 {}}
233
234# check quoted args are unquoted
shaneh5fc25012009-11-11 04:17:07 +0000235do_test shell1-2.4.1 {
shanehca7dfda2009-12-17 21:07:54 +0000236 catchcmd "test.db" ".mode FOO"
drh0908e382020-06-04 18:05:39 +0000237} {1 {Error: mode should be one of: ascii box column csv html insert json line list markdown quote table tabs tcl}}
shaneh5fc25012009-11-11 04:17:07 +0000238do_test shell1-2.4.2 {
shanehca7dfda2009-12-17 21:07:54 +0000239 catchcmd "test.db" ".mode csv"
shanehe2aa9d72009-11-06 17:20:17 +0000240} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000241do_test shell1-2.4.2 {
shanehca7dfda2009-12-17 21:07:54 +0000242 catchcmd "test.db" ".mode \"csv\""
shanehe2aa9d72009-11-06 17:20:17 +0000243} {0 {}}
244
245
246#----------------------------------------------------------------------------
shaneh5fc25012009-11-11 04:17:07 +0000247# Test cases shell1-3.*: Basic test that "dot" command can be called.
shaneha05e0c42009-11-06 03:22:54 +0000248#
249
250# .backup ?DB? FILE Backup DB (default "main") to FILE
shaneh5fc25012009-11-11 04:17:07 +0000251do_test shell1-3.1.1 {
shanehca7dfda2009-12-17 21:07:54 +0000252 catchcmd "test.db" ".backup"
drhbc46f022013-01-23 18:53:23 +0000253} {1 {missing FILENAME argument on .backup}}
drhf82d78e2020-11-25 14:50:42 +0000254forcedelete FOO
shaneh5fc25012009-11-11 04:17:07 +0000255do_test shell1-3.1.2 {
shanehca7dfda2009-12-17 21:07:54 +0000256 catchcmd "test.db" ".backup FOO"
257} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000258do_test shell1-3.1.3 {
shanehca7dfda2009-12-17 21:07:54 +0000259 catchcmd "test.db" ".backup FOO BAR"
shanehe2aa9d72009-11-06 17:20:17 +0000260} {1 {Error: unknown database FOO}}
shaneh5fc25012009-11-11 04:17:07 +0000261do_test shell1-3.1.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000262 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000263 catchcmd "test.db" ".backup FOO BAR BAD"
drh4d342822018-12-10 00:41:28 +0000264} {1 {Usage: .backup ?DB? ?OPTIONS? FILENAME}}
shaneha05e0c42009-11-06 03:22:54 +0000265
266# .bail ON|OFF Stop after hitting an error. Default OFF
shaneh5fc25012009-11-11 04:17:07 +0000267do_test shell1-3.2.1 {
shanehca7dfda2009-12-17 21:07:54 +0000268 catchcmd "test.db" ".bail"
drhc2ce0be2014-05-29 12:36:14 +0000269} {1 {Usage: .bail on|off}}
shaneh5fc25012009-11-11 04:17:07 +0000270do_test shell1-3.2.2 {
shanehca7dfda2009-12-17 21:07:54 +0000271 catchcmd "test.db" ".bail ON"
shaneha05e0c42009-11-06 03:22:54 +0000272} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000273do_test shell1-3.2.3 {
shanehca7dfda2009-12-17 21:07:54 +0000274 catchcmd "test.db" ".bail OFF"
shaneha05e0c42009-11-06 03:22:54 +0000275} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000276do_test shell1-3.2.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000277 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000278 catchcmd "test.db" ".bail OFF BAD"
drhc2ce0be2014-05-29 12:36:14 +0000279} {1 {Usage: .bail on|off}}
shaneha05e0c42009-11-06 03:22:54 +0000280
drhc5954192016-12-27 02:43:47 +0000281ifcapable vtab {
shaneha05e0c42009-11-06 03:22:54 +0000282# .databases List names and files of attached databases
shaneh5fc25012009-11-11 04:17:07 +0000283do_test shell1-3.3.1 {
drheaa544d2016-03-26 14:41:13 +0000284 catchcmd "-csv test.db" ".databases"
drh15707ac2016-03-26 13:26:35 +0000285} "/0.+main.+[string map {/ ".{1,2}"} [string range [get_pwd] 0 10]].*/"
shaneh5fc25012009-11-11 04:17:07 +0000286do_test shell1-3.3.2 {
drhc2ce0be2014-05-29 12:36:14 +0000287 # extra arguments ignored
drheaa544d2016-03-26 14:41:13 +0000288 catchcmd "test.db" ".databases BAD"
drh15707ac2016-03-26 13:26:35 +0000289} "/0.+main.+[string map {/ ".{1,2}"} [string range [get_pwd] 0 10]].*/"
drhc5954192016-12-27 02:43:47 +0000290}
shaneha05e0c42009-11-06 03:22:54 +0000291
292# .dump ?TABLE? ... Dump the database in an SQL text format
293# If TABLE specified, only dump tables matching
294# LIKE pattern TABLE.
shaneh5fc25012009-11-11 04:17:07 +0000295do_test shell1-3.4.1 {
shanehca7dfda2009-12-17 21:07:54 +0000296 set res [catchcmd "test.db" ".dump"]
shaneha05e0c42009-11-06 03:22:54 +0000297 list [regexp {BEGIN TRANSACTION;} $res] \
298 [regexp {COMMIT;} $res]
299} {1 1}
shaneh5fc25012009-11-11 04:17:07 +0000300do_test shell1-3.4.2 {
shanehca7dfda2009-12-17 21:07:54 +0000301 set res [catchcmd "test.db" ".dump FOO"]
shaneha05e0c42009-11-06 03:22:54 +0000302 list [regexp {BEGIN TRANSACTION;} $res] \
303 [regexp {COMMIT;} $res]
304} {1 1}
drh8e9297f2020-03-25 12:50:13 +0000305# The .dump command now accepts multiple arguments
306#do_test shell1-3.4.3 {
307# # too many arguments
308# catchcmd "test.db" ".dump FOO BAD"
309#} {1 {Usage: .dump ?--preserve-rowids? ?--newlines? ?LIKE-PATTERN?}}
shaneha05e0c42009-11-06 03:22:54 +0000310
311# .echo ON|OFF Turn command echo on or off
shaneh5fc25012009-11-11 04:17:07 +0000312do_test shell1-3.5.1 {
shanehca7dfda2009-12-17 21:07:54 +0000313 catchcmd "test.db" ".echo"
drhc2ce0be2014-05-29 12:36:14 +0000314} {1 {Usage: .echo on|off}}
shaneh5fc25012009-11-11 04:17:07 +0000315do_test shell1-3.5.2 {
shanehca7dfda2009-12-17 21:07:54 +0000316 catchcmd "test.db" ".echo ON"
shaneha05e0c42009-11-06 03:22:54 +0000317} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000318do_test shell1-3.5.3 {
shanehca7dfda2009-12-17 21:07:54 +0000319 catchcmd "test.db" ".echo OFF"
shaneha05e0c42009-11-06 03:22:54 +0000320} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000321do_test shell1-3.5.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000322 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000323 catchcmd "test.db" ".echo OFF BAD"
drhc2ce0be2014-05-29 12:36:14 +0000324} {1 {Usage: .echo on|off}}
shaneha05e0c42009-11-06 03:22:54 +0000325
326# .exit Exit this program
shaneh5fc25012009-11-11 04:17:07 +0000327do_test shell1-3.6.1 {
shanehca7dfda2009-12-17 21:07:54 +0000328 catchcmd "test.db" ".exit"
shaneha05e0c42009-11-06 03:22:54 +0000329} {0 {}}
330
331# .explain ON|OFF Turn output mode suitable for EXPLAIN on or off.
shaneh5fc25012009-11-11 04:17:07 +0000332do_test shell1-3.7.1 {
shanehca7dfda2009-12-17 21:07:54 +0000333 catchcmd "test.db" ".explain"
shanehe2aa9d72009-11-06 17:20:17 +0000334 # explain is the exception to the booleans. without an option, it turns it on.
335} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000336do_test shell1-3.7.2 {
shanehca7dfda2009-12-17 21:07:54 +0000337 catchcmd "test.db" ".explain ON"
shaneha05e0c42009-11-06 03:22:54 +0000338} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000339do_test shell1-3.7.3 {
shanehca7dfda2009-12-17 21:07:54 +0000340 catchcmd "test.db" ".explain OFF"
shaneha05e0c42009-11-06 03:22:54 +0000341} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000342do_test shell1-3.7.4 {
drhc2ce0be2014-05-29 12:36:14 +0000343 # extra arguments ignored
shanehca7dfda2009-12-17 21:07:54 +0000344 catchcmd "test.db" ".explain OFF BAD"
drhc2ce0be2014-05-29 12:36:14 +0000345} {0 {}}
shaneha05e0c42009-11-06 03:22:54 +0000346
shaneha05e0c42009-11-06 03:22:54 +0000347
348# .header(s) ON|OFF Turn display of headers on or off
shaneh5fc25012009-11-11 04:17:07 +0000349do_test shell1-3.9.1 {
shanehca7dfda2009-12-17 21:07:54 +0000350 catchcmd "test.db" ".header"
drhc2ce0be2014-05-29 12:36:14 +0000351} {1 {Usage: .headers on|off}}
shaneh5fc25012009-11-11 04:17:07 +0000352do_test shell1-3.9.2 {
shanehca7dfda2009-12-17 21:07:54 +0000353 catchcmd "test.db" ".header ON"
shaneha05e0c42009-11-06 03:22:54 +0000354} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000355do_test shell1-3.9.3 {
shanehca7dfda2009-12-17 21:07:54 +0000356 catchcmd "test.db" ".header OFF"
shaneha05e0c42009-11-06 03:22:54 +0000357} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000358do_test shell1-3.9.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000359 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000360 catchcmd "test.db" ".header OFF BAD"
drhc2ce0be2014-05-29 12:36:14 +0000361} {1 {Usage: .headers on|off}}
shanehe2aa9d72009-11-06 17:20:17 +0000362
shaneh5fc25012009-11-11 04:17:07 +0000363do_test shell1-3.9.5 {
shanehca7dfda2009-12-17 21:07:54 +0000364 catchcmd "test.db" ".headers"
drhc2ce0be2014-05-29 12:36:14 +0000365} {1 {Usage: .headers on|off}}
shaneh5fc25012009-11-11 04:17:07 +0000366do_test shell1-3.9.6 {
shanehca7dfda2009-12-17 21:07:54 +0000367 catchcmd "test.db" ".headers ON"
shaneha05e0c42009-11-06 03:22:54 +0000368} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000369do_test shell1-3.9.7 {
shanehca7dfda2009-12-17 21:07:54 +0000370 catchcmd "test.db" ".headers OFF"
shaneha05e0c42009-11-06 03:22:54 +0000371} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000372do_test shell1-3.9.8 {
shanehe2aa9d72009-11-06 17:20:17 +0000373 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000374 catchcmd "test.db" ".headers OFF BAD"
drhc2ce0be2014-05-29 12:36:14 +0000375} {1 {Usage: .headers on|off}}
shaneha05e0c42009-11-06 03:22:54 +0000376
377# .help Show this message
shaneh5fc25012009-11-11 04:17:07 +0000378do_test shell1-3.10.1 {
shanehca7dfda2009-12-17 21:07:54 +0000379 set res [catchcmd "test.db" ".help"]
shaneha05e0c42009-11-06 03:22:54 +0000380 # look for a few of the possible help commands
381 list [regexp {.help} $res] \
382 [regexp {.quit} $res] \
383 [regexp {.show} $res]
384} {1 1 1}
shaneh5fc25012009-11-11 04:17:07 +0000385do_test shell1-3.10.2 {
shanehe2aa9d72009-11-06 17:20:17 +0000386 # we allow .help to take extra args (it is help after all)
drh98aa2ab2018-09-26 16:53:51 +0000387 set res [catchcmd "test.db" ".help *"]
shanehe2aa9d72009-11-06 17:20:17 +0000388 # look for a few of the possible help commands
389 list [regexp {.help} $res] \
390 [regexp {.quit} $res] \
391 [regexp {.show} $res]
392} {1 1 1}
shaneha05e0c42009-11-06 03:22:54 +0000393
394# .import FILE TABLE Import data from FILE into TABLE
shaneh5fc25012009-11-11 04:17:07 +0000395do_test shell1-3.11.1 {
shanehca7dfda2009-12-17 21:07:54 +0000396 catchcmd "test.db" ".import"
drhccb37812020-03-09 15:39:39 +0000397} {/1 .ERROR: missing FILE argument.*/}
shaneh5fc25012009-11-11 04:17:07 +0000398do_test shell1-3.11.2 {
shanehca7dfda2009-12-17 21:07:54 +0000399 catchcmd "test.db" ".import FOO"
drhccb37812020-03-09 15:39:39 +0000400} {/1 .ERROR: missing TABLE argument.*/}
shaneh5fc25012009-11-11 04:17:07 +0000401do_test shell1-3.11.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000402 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000403 catchcmd "test.db" ".import FOO BAR BAD"
drhccb37812020-03-09 15:39:39 +0000404} {/1 .ERROR: extra argument: "BAD".*./}
shaneha05e0c42009-11-06 03:22:54 +0000405
drh0e55db12015-02-06 14:51:13 +0000406# .indexes ?TABLE? Show names of all indexes
407# If TABLE specified, only show indexes for tables
shaneha05e0c42009-11-06 03:22:54 +0000408# matching LIKE pattern TABLE.
shaneh5fc25012009-11-11 04:17:07 +0000409do_test shell1-3.12.1 {
drh0e55db12015-02-06 14:51:13 +0000410 catchcmd "test.db" ".indexes"
shaneha05e0c42009-11-06 03:22:54 +0000411} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000412do_test shell1-3.12.2 {
drh0e55db12015-02-06 14:51:13 +0000413 catchcmd "test.db" ".indexes FOO"
414} {0 {}}
415do_test shell1-3.12.2-legacy {
shanehca7dfda2009-12-17 21:07:54 +0000416 catchcmd "test.db" ".indices FOO"
shaneha05e0c42009-11-06 03:22:54 +0000417} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000418do_test shell1-3.12.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000419 # too many arguments
drh0e55db12015-02-06 14:51:13 +0000420 catchcmd "test.db" ".indexes FOO BAD"
421} {1 {Usage: .indexes ?LIKE-PATTERN?}}
shaneha05e0c42009-11-06 03:22:54 +0000422
423# .mode MODE ?TABLE? Set output mode where MODE is one of:
mistachkine0d68852014-12-11 03:12:33 +0000424# ascii Columns/rows delimited by 0x1F and 0x1E
shaneha05e0c42009-11-06 03:22:54 +0000425# csv Comma-separated values
426# column Left-aligned columns. (See .width)
427# html HTML <table> code
428# insert SQL insert statements for TABLE
429# line One value per line
mistachkine0d68852014-12-11 03:12:33 +0000430# list Values delimited by .separator strings
shaneha05e0c42009-11-06 03:22:54 +0000431# tabs Tab-separated values
432# tcl TCL list elements
shaneh5fc25012009-11-11 04:17:07 +0000433do_test shell1-3.13.1 {
shanehca7dfda2009-12-17 21:07:54 +0000434 catchcmd "test.db" ".mode"
drha501f7d2017-06-29 21:33:25 +0000435} {0 {current output mode: list}}
shaneh5fc25012009-11-11 04:17:07 +0000436do_test shell1-3.13.2 {
shanehca7dfda2009-12-17 21:07:54 +0000437 catchcmd "test.db" ".mode FOO"
drh0908e382020-06-04 18:05:39 +0000438} {1 {Error: mode should be one of: ascii box column csv html insert json line list markdown quote table tabs tcl}}
shaneh5fc25012009-11-11 04:17:07 +0000439do_test shell1-3.13.3 {
shanehca7dfda2009-12-17 21:07:54 +0000440 catchcmd "test.db" ".mode csv"
shaneha05e0c42009-11-06 03:22:54 +0000441} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000442do_test shell1-3.13.4 {
shanehca7dfda2009-12-17 21:07:54 +0000443 catchcmd "test.db" ".mode column"
shaneha05e0c42009-11-06 03:22:54 +0000444} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000445do_test shell1-3.13.5 {
shanehca7dfda2009-12-17 21:07:54 +0000446 catchcmd "test.db" ".mode html"
shaneha05e0c42009-11-06 03:22:54 +0000447} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000448do_test shell1-3.13.6 {
shanehca7dfda2009-12-17 21:07:54 +0000449 catchcmd "test.db" ".mode insert"
shaneha05e0c42009-11-06 03:22:54 +0000450} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000451do_test shell1-3.13.7 {
shanehca7dfda2009-12-17 21:07:54 +0000452 catchcmd "test.db" ".mode line"
shaneha05e0c42009-11-06 03:22:54 +0000453} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000454do_test shell1-3.13.8 {
shanehca7dfda2009-12-17 21:07:54 +0000455 catchcmd "test.db" ".mode list"
shaneha05e0c42009-11-06 03:22:54 +0000456} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000457do_test shell1-3.13.9 {
shanehca7dfda2009-12-17 21:07:54 +0000458 catchcmd "test.db" ".mode tabs"
shaneha05e0c42009-11-06 03:22:54 +0000459} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000460do_test shell1-3.13.10 {
shanehca7dfda2009-12-17 21:07:54 +0000461 catchcmd "test.db" ".mode tcl"
shaneha05e0c42009-11-06 03:22:54 +0000462} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000463do_test shell1-3.13.11 {
drhc2ce0be2014-05-29 12:36:14 +0000464 # extra arguments ignored
shanehca7dfda2009-12-17 21:07:54 +0000465 catchcmd "test.db" ".mode tcl BAD"
drhc2ce0be2014-05-29 12:36:14 +0000466} {0 {}}
shanehe2aa9d72009-11-06 17:20:17 +0000467
468# don't allow partial mode type matches
shaneh5fc25012009-11-11 04:17:07 +0000469do_test shell1-3.13.12 {
shanehca7dfda2009-12-17 21:07:54 +0000470 catchcmd "test.db" ".mode l"
drh0908e382020-06-04 18:05:39 +0000471} {1 {Error: mode should be one of: ascii box column csv html insert json line list markdown quote table tabs tcl}}
shaneh5fc25012009-11-11 04:17:07 +0000472do_test shell1-3.13.13 {
shanehca7dfda2009-12-17 21:07:54 +0000473 catchcmd "test.db" ".mode li"
drh0908e382020-06-04 18:05:39 +0000474} {1 {Error: mode should be one of: ascii box column csv html insert json line list markdown quote table tabs tcl}}
shaneh5fc25012009-11-11 04:17:07 +0000475do_test shell1-3.13.14 {
shanehca7dfda2009-12-17 21:07:54 +0000476 catchcmd "test.db" ".mode lin"
drhc2ce0be2014-05-29 12:36:14 +0000477} {0 {}}
shaneha05e0c42009-11-06 03:22:54 +0000478
479# .nullvalue STRING Print STRING in place of NULL values
shaneh5fc25012009-11-11 04:17:07 +0000480do_test shell1-3.14.1 {
shanehca7dfda2009-12-17 21:07:54 +0000481 catchcmd "test.db" ".nullvalue"
drhc2ce0be2014-05-29 12:36:14 +0000482} {1 {Usage: .nullvalue STRING}}
shaneh5fc25012009-11-11 04:17:07 +0000483do_test shell1-3.14.2 {
shanehca7dfda2009-12-17 21:07:54 +0000484 catchcmd "test.db" ".nullvalue FOO"
shaneha05e0c42009-11-06 03:22:54 +0000485} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000486do_test shell1-3.14.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000487 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000488 catchcmd "test.db" ".nullvalue FOO BAD"
drhc2ce0be2014-05-29 12:36:14 +0000489} {1 {Usage: .nullvalue STRING}}
shaneha05e0c42009-11-06 03:22:54 +0000490
491# .output FILENAME Send output to FILENAME
shaneh5fc25012009-11-11 04:17:07 +0000492do_test shell1-3.15.1 {
shanehca7dfda2009-12-17 21:07:54 +0000493 catchcmd "test.db" ".output"
drhc2ce0be2014-05-29 12:36:14 +0000494} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000495do_test shell1-3.15.2 {
shanehca7dfda2009-12-17 21:07:54 +0000496 catchcmd "test.db" ".output FOO"
shaneha05e0c42009-11-06 03:22:54 +0000497} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000498do_test shell1-3.15.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000499 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000500 catchcmd "test.db" ".output FOO BAD"
drh541ef2c2020-04-20 16:21:30 +0000501} {1 {ERROR: extra parameter: "BAD". Usage:
502.output ?FILE? Send output to FILE or stdout if FILE is omitted
503 If FILE begins with '|' then open it as a pipe.
504 Options:
505 --bom Prefix output with a UTF8 byte-order mark
506 -e Send output to the system text editor
507 -x Send output as CSV to a spreadsheet
508child process exited abnormally}}
shaneha05e0c42009-11-06 03:22:54 +0000509
510# .output stdout Send output to the screen
shaneh5fc25012009-11-11 04:17:07 +0000511do_test shell1-3.16.1 {
shanehca7dfda2009-12-17 21:07:54 +0000512 catchcmd "test.db" ".output stdout"
shaneha05e0c42009-11-06 03:22:54 +0000513} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000514do_test shell1-3.16.2 {
shanehe2aa9d72009-11-06 17:20:17 +0000515 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000516 catchcmd "test.db" ".output stdout BAD"
drh541ef2c2020-04-20 16:21:30 +0000517} {1 {ERROR: extra parameter: "BAD". Usage:
518.output ?FILE? Send output to FILE or stdout if FILE is omitted
519 If FILE begins with '|' then open it as a pipe.
520 Options:
521 --bom Prefix output with a UTF8 byte-order mark
522 -e Send output to the system text editor
523 -x Send output as CSV to a spreadsheet
524child process exited abnormally}}
shaneha05e0c42009-11-06 03:22:54 +0000525
526# .prompt MAIN CONTINUE Replace the standard prompts
shaneh5fc25012009-11-11 04:17:07 +0000527do_test shell1-3.17.1 {
shanehca7dfda2009-12-17 21:07:54 +0000528 catchcmd "test.db" ".prompt"
drhc2ce0be2014-05-29 12:36:14 +0000529} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000530do_test shell1-3.17.2 {
shanehca7dfda2009-12-17 21:07:54 +0000531 catchcmd "test.db" ".prompt FOO"
shaneha05e0c42009-11-06 03:22:54 +0000532} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000533do_test shell1-3.17.3 {
shanehca7dfda2009-12-17 21:07:54 +0000534 catchcmd "test.db" ".prompt FOO BAR"
shaneha05e0c42009-11-06 03:22:54 +0000535} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000536do_test shell1-3.17.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000537 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000538 catchcmd "test.db" ".prompt FOO BAR BAD"
drhc2ce0be2014-05-29 12:36:14 +0000539} {0 {}}
shaneha05e0c42009-11-06 03:22:54 +0000540
541# .quit Exit this program
shaneh5fc25012009-11-11 04:17:07 +0000542do_test shell1-3.18.1 {
shanehca7dfda2009-12-17 21:07:54 +0000543 catchcmd "test.db" ".quit"
shaneha05e0c42009-11-06 03:22:54 +0000544} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000545do_test shell1-3.18.2 {
shanehe2aa9d72009-11-06 17:20:17 +0000546 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000547 catchcmd "test.db" ".quit BAD"
drhc2ce0be2014-05-29 12:36:14 +0000548} {0 {}}
shaneha05e0c42009-11-06 03:22:54 +0000549
550# .read FILENAME Execute SQL in FILENAME
shaneh5fc25012009-11-11 04:17:07 +0000551do_test shell1-3.19.1 {
shanehca7dfda2009-12-17 21:07:54 +0000552 catchcmd "test.db" ".read"
drhc2ce0be2014-05-29 12:36:14 +0000553} {1 {Usage: .read FILE}}
shaneh5fc25012009-11-11 04:17:07 +0000554do_test shell1-3.19.2 {
mistachkin9ac99312013-09-13 23:26:47 +0000555 forcedelete FOO
shanehca7dfda2009-12-17 21:07:54 +0000556 catchcmd "test.db" ".read FOO"
shaneha05e0c42009-11-06 03:22:54 +0000557} {1 {Error: cannot open "FOO"}}
shaneh5fc25012009-11-11 04:17:07 +0000558do_test shell1-3.19.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000559 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000560 catchcmd "test.db" ".read FOO BAD"
drhc2ce0be2014-05-29 12:36:14 +0000561} {1 {Usage: .read FILE}}
shaneha05e0c42009-11-06 03:22:54 +0000562
563# .restore ?DB? FILE Restore content of DB (default "main") from FILE
shaneh5fc25012009-11-11 04:17:07 +0000564do_test shell1-3.20.1 {
shanehca7dfda2009-12-17 21:07:54 +0000565 catchcmd "test.db" ".restore"
drhc2ce0be2014-05-29 12:36:14 +0000566} {1 {Usage: .restore ?DB? FILE}}
shaneh5fc25012009-11-11 04:17:07 +0000567do_test shell1-3.20.2 {
shanehca7dfda2009-12-17 21:07:54 +0000568 catchcmd "test.db" ".restore FOO"
569} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000570do_test shell1-3.20.3 {
shanehca7dfda2009-12-17 21:07:54 +0000571 catchcmd "test.db" ".restore FOO BAR"
shanehe2aa9d72009-11-06 17:20:17 +0000572} {1 {Error: unknown database FOO}}
shaneh5fc25012009-11-11 04:17:07 +0000573do_test shell1-3.20.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000574 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000575 catchcmd "test.db" ".restore FOO BAR BAD"
drhc2ce0be2014-05-29 12:36:14 +0000576} {1 {Usage: .restore ?DB? FILE}}
shaneha05e0c42009-11-06 03:22:54 +0000577
drha22dd382017-06-24 19:21:48 +0000578ifcapable vtab {
shaneha05e0c42009-11-06 03:22:54 +0000579# .schema ?TABLE? Show the CREATE statements
580# If TABLE specified, only show tables matching
581# LIKE pattern TABLE.
shaneh5fc25012009-11-11 04:17:07 +0000582do_test shell1-3.21.1 {
shanehca7dfda2009-12-17 21:07:54 +0000583 catchcmd "test.db" ".schema"
shaneha05e0c42009-11-06 03:22:54 +0000584} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000585do_test shell1-3.21.2 {
shanehca7dfda2009-12-17 21:07:54 +0000586 catchcmd "test.db" ".schema FOO"
shaneha05e0c42009-11-06 03:22:54 +0000587} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000588do_test shell1-3.21.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000589 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000590 catchcmd "test.db" ".schema FOO BAD"
drhbbb29ec2020-10-12 14:56:47 +0000591} {1 {Usage: .schema ?--indent? ?--nosys? ?LIKE-PATTERN?}}
shaneha05e0c42009-11-06 03:22:54 +0000592
drhac43e982012-05-21 03:15:06 +0000593do_test shell1-3.21.4 {
594 catchcmd "test.db" {
595 CREATE TABLE t1(x);
596 CREATE VIEW v2 AS SELECT x+1 AS y FROM t1;
597 CREATE VIEW v1 AS SELECT y+1 FROM v2;
598 }
599 catchcmd "test.db" ".schema"
600} {0 {CREATE TABLE t1(x);
drhceba7922018-01-01 21:28:25 +0000601CREATE VIEW v2 AS SELECT x+1 AS y FROM t1
drh1d315cf2018-01-01 21:49:43 +0000602/* v2(y) */;
drhceba7922018-01-01 21:28:25 +0000603CREATE VIEW v1 AS SELECT y+1 FROM v2
drh1d315cf2018-01-01 21:49:43 +0000604/* v1("y+1") */;}}
drhac43e982012-05-21 03:15:06 +0000605db eval {DROP VIEW v1; DROP VIEW v2; DROP TABLE t1;}
drha22dd382017-06-24 19:21:48 +0000606}
drhac43e982012-05-21 03:15:06 +0000607
mistachkin636bf9f2014-07-19 20:15:16 +0000608# .separator STRING Change column separator used by output and .import
shaneh5fc25012009-11-11 04:17:07 +0000609do_test shell1-3.22.1 {
shanehca7dfda2009-12-17 21:07:54 +0000610 catchcmd "test.db" ".separator"
mistachkine0d68852014-12-11 03:12:33 +0000611} {1 {Usage: .separator COL ?ROW?}}
shaneh5fc25012009-11-11 04:17:07 +0000612do_test shell1-3.22.2 {
shanehca7dfda2009-12-17 21:07:54 +0000613 catchcmd "test.db" ".separator FOO"
shaneha05e0c42009-11-06 03:22:54 +0000614} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000615do_test shell1-3.22.3 {
drh6976c212014-07-24 12:09:47 +0000616 catchcmd "test.db" ".separator ABC XYZ"
617} {0 {}}
618do_test shell1-3.22.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000619 # too many arguments
drh6976c212014-07-24 12:09:47 +0000620 catchcmd "test.db" ".separator FOO BAD BAD2"
mistachkine0d68852014-12-11 03:12:33 +0000621} {1 {Usage: .separator COL ?ROW?}}
shaneha05e0c42009-11-06 03:22:54 +0000622
623# .show Show the current values for various settings
shaneh5fc25012009-11-11 04:17:07 +0000624do_test shell1-3.23.1 {
shanehca7dfda2009-12-17 21:07:54 +0000625 set res [catchcmd "test.db" ".show"]
shaneha05e0c42009-11-06 03:22:54 +0000626 list [regexp {echo:} $res] \
627 [regexp {explain:} $res] \
628 [regexp {headers:} $res] \
629 [regexp {mode:} $res] \
630 [regexp {nullvalue:} $res] \
631 [regexp {output:} $res] \
mistachkin636bf9f2014-07-19 20:15:16 +0000632 [regexp {colseparator:} $res] \
633 [regexp {rowseparator:} $res] \
shaneh642d8b82010-07-28 16:05:34 +0000634 [regexp {stats:} $res] \
shaneha05e0c42009-11-06 03:22:54 +0000635 [regexp {width:} $res]
mistachkine0d68852014-12-11 03:12:33 +0000636} {1 1 1 1 1 1 1 1 1 1}
shaneh5fc25012009-11-11 04:17:07 +0000637do_test shell1-3.23.2 {
shanehe2aa9d72009-11-06 17:20:17 +0000638 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000639 catchcmd "test.db" ".show BAD"
drhc2ce0be2014-05-29 12:36:14 +0000640} {1 {Usage: .show}}
shaneha05e0c42009-11-06 03:22:54 +0000641
shaneh642d8b82010-07-28 16:05:34 +0000642# .stats ON|OFF Turn stats on or off
drh34784902016-02-27 17:12:36 +0000643#do_test shell1-3.23b.1 {
644# catchcmd "test.db" ".stats"
drha6e6cf22021-01-09 19:10:04 +0000645#} {1 {Usage: .stats on|off|stmt|vmstep}}
shaneh642d8b82010-07-28 16:05:34 +0000646do_test shell1-3.23b.2 {
647 catchcmd "test.db" ".stats ON"
648} {0 {}}
649do_test shell1-3.23b.3 {
650 catchcmd "test.db" ".stats OFF"
651} {0 {}}
652do_test shell1-3.23b.4 {
653 # too many arguments
654 catchcmd "test.db" ".stats OFF BAD"
drha6e6cf22021-01-09 19:10:04 +0000655} {1 {Usage: .stats ?on|off|stmt|vmstep?}}
shaneh642d8b82010-07-28 16:05:34 +0000656
drh3c49eaf2018-06-07 15:23:43 +0000657# Ticket 7be932dfa60a8a6b3b26bcf7623ec46e0a403ddb 2018-06-07
658# Adverse interaction between .stats and .eqp
659#
660do_test shell1-3.23b.5 {
661 catchcmd "test.db" [string map {"\n " "\n"} {
662 CREATE TEMP TABLE t1(x);
663 INSERT INTO t1 VALUES(1),(2);
664 .stats on
665 .eqp full
666 SELECT * FROM t1;
667 }]
668} {/1\n2\n/}
669
shaneha05e0c42009-11-06 03:22:54 +0000670# .tables ?TABLE? List names of tables
671# If TABLE specified, only list tables matching
672# LIKE pattern TABLE.
shaneh5fc25012009-11-11 04:17:07 +0000673do_test shell1-3.24.1 {
shanehca7dfda2009-12-17 21:07:54 +0000674 catchcmd "test.db" ".tables"
shaneha05e0c42009-11-06 03:22:54 +0000675} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000676do_test shell1-3.24.2 {
shanehca7dfda2009-12-17 21:07:54 +0000677 catchcmd "test.db" ".tables FOO"
shaneha05e0c42009-11-06 03:22:54 +0000678} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000679do_test shell1-3.24.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000680 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000681 catchcmd "test.db" ".tables FOO BAD"
drhc2ce0be2014-05-29 12:36:14 +0000682} {0 {}}
shaneha05e0c42009-11-06 03:22:54 +0000683
684# .timeout MS Try opening locked tables for MS milliseconds
shaneh5fc25012009-11-11 04:17:07 +0000685do_test shell1-3.25.1 {
shanehca7dfda2009-12-17 21:07:54 +0000686 catchcmd "test.db" ".timeout"
drhc2ce0be2014-05-29 12:36:14 +0000687} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000688do_test shell1-3.25.2 {
shanehca7dfda2009-12-17 21:07:54 +0000689 catchcmd "test.db" ".timeout zzz"
shanehe2aa9d72009-11-06 17:20:17 +0000690 # this should be treated the same as a '0' timeout
shaneha05e0c42009-11-06 03:22:54 +0000691} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000692do_test shell1-3.25.3 {
shanehca7dfda2009-12-17 21:07:54 +0000693 catchcmd "test.db" ".timeout 1"
shaneha05e0c42009-11-06 03:22:54 +0000694} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000695do_test shell1-3.25.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000696 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000697 catchcmd "test.db" ".timeout 1 BAD"
drhc2ce0be2014-05-29 12:36:14 +0000698} {0 {}}
shaneha05e0c42009-11-06 03:22:54 +0000699
700# .width NUM NUM ... Set column widths for "column" mode
shaneh5fc25012009-11-11 04:17:07 +0000701do_test shell1-3.26.1 {
shanehca7dfda2009-12-17 21:07:54 +0000702 catchcmd "test.db" ".width"
drhc2ce0be2014-05-29 12:36:14 +0000703} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000704do_test shell1-3.26.2 {
shanehca7dfda2009-12-17 21:07:54 +0000705 catchcmd "test.db" ".width xxx"
shanehe2aa9d72009-11-06 17:20:17 +0000706 # this should be treated the same as a '0' width for col 1
shaneha05e0c42009-11-06 03:22:54 +0000707} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000708do_test shell1-3.26.3 {
shanehca7dfda2009-12-17 21:07:54 +0000709 catchcmd "test.db" ".width xxx yyy"
shanehe2aa9d72009-11-06 17:20:17 +0000710 # this should be treated the same as a '0' width for col 1 and 2
shaneha05e0c42009-11-06 03:22:54 +0000711} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000712do_test shell1-3.26.4 {
shanehca7dfda2009-12-17 21:07:54 +0000713 catchcmd "test.db" ".width 1 1"
shanehe2aa9d72009-11-06 17:20:17 +0000714 # this should be treated the same as a '1' width for col 1 and 2
shaneha05e0c42009-11-06 03:22:54 +0000715} {0 {}}
drh078b1fd2012-09-21 13:40:02 +0000716do_test shell1-3.26.5 {
drhc0605082020-06-05 00:54:27 +0000717 catchcmd "test.db" ".mode column\n.header off\n.width 10 -10\nSELECT 'abcdefg', 123456;"
drh078b1fd2012-09-21 13:40:02 +0000718 # this should be treated the same as a '1' width for col 1 and 2
719} {0 {abcdefg 123456}}
720do_test shell1-3.26.6 {
drhc0605082020-06-05 00:54:27 +0000721 catchcmd "test.db" ".mode column\n.header off\n.width -10 10\nSELECT 'abcdefg', 123456;"
drh078b1fd2012-09-21 13:40:02 +0000722 # this should be treated the same as a '1' width for col 1 and 2
723} {0 { abcdefg 123456 }}
724
shaneha05e0c42009-11-06 03:22:54 +0000725
726# .timer ON|OFF Turn the CPU timer measurement on or off
shaneh5fc25012009-11-11 04:17:07 +0000727do_test shell1-3.27.1 {
shanehca7dfda2009-12-17 21:07:54 +0000728 catchcmd "test.db" ".timer"
drhc2ce0be2014-05-29 12:36:14 +0000729} {1 {Usage: .timer on|off}}
shaneh5fc25012009-11-11 04:17:07 +0000730do_test shell1-3.27.2 {
shanehca7dfda2009-12-17 21:07:54 +0000731 catchcmd "test.db" ".timer ON"
shaneha05e0c42009-11-06 03:22:54 +0000732} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000733do_test shell1-3.27.3 {
shanehca7dfda2009-12-17 21:07:54 +0000734 catchcmd "test.db" ".timer OFF"
shaneha05e0c42009-11-06 03:22:54 +0000735} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000736do_test shell1-3.27.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000737 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000738 catchcmd "test.db" ".timer OFF BAD"
drhc2ce0be2014-05-29 12:36:14 +0000739} {1 {Usage: .timer on|off}}
shaneha05e0c42009-11-06 03:22:54 +0000740
drh53a9d152011-04-25 18:20:04 +0000741do_test shell1-3-28.1 {
742 catchcmd test.db \
743 ".log stdout\nSELECT coalesce(sqlite_log(123,'hello'),'456');"
744} "0 {(123) hello\n456}"
745
drh078b1fd2012-09-21 13:40:02 +0000746do_test shell1-3-29.1 {
747 catchcmd "test.db" ".print this is a test"
748} {0 {this is a test}}
749
drh4c56b992013-06-27 13:26:55 +0000750# dot-command argument quoting
751do_test shell1-3-30.1 {
752 catchcmd {test.db} {.print "this\"is'a\055test" 'this\"is\\a\055test'}
753} {0 {this"is'a-test this\"is\\a\055test}}
754do_test shell1-3-31.1 {
755 catchcmd {test.db} {.print "this\nis\ta\\test" 'this\nis\ta\\test'}
756} [list 0 "this\nis\ta\\test this\\nis\\ta\\\\test"]
757
758
drh5128e852012-04-24 13:14:49 +0000759# Test the output of the ".dump" command
760#
761do_test shell1-4.1 {
drh55a1b302013-09-04 16:08:50 +0000762 db close
763 forcedelete test.db
764 sqlite3 db test.db
drh5128e852012-04-24 13:14:49 +0000765 db eval {
drh55a1b302013-09-04 16:08:50 +0000766 PRAGMA encoding=UTF16;
drh5128e852012-04-24 13:14:49 +0000767 CREATE TABLE t1(x);
mistachkin585dcb22012-12-04 00:23:43 +0000768 INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f');
mistachkin151c75a2015-04-07 21:16:40 +0000769 CREATE TABLE t3(x,y);
770 INSERT INTO t3 VALUES(1,null), (2,''), (3,1),
771 (4,2.25), (5,'hello'), (6,x'807f');
drh5128e852012-04-24 13:14:49 +0000772 }
773 catchcmd test.db {.dump}
774} {0 {PRAGMA foreign_keys=OFF;
775BEGIN TRANSACTION;
776CREATE TABLE t1(x);
drhf42d3182017-03-08 12:25:18 +0000777INSERT INTO t1 VALUES(NULL);
778INSERT INTO t1 VALUES('');
779INSERT INTO t1 VALUES(1);
780INSERT INTO t1 VALUES(2.25);
781INSERT INTO t1 VALUES('hello');
782INSERT INTO t1 VALUES(X'807f');
mistachkin151c75a2015-04-07 21:16:40 +0000783CREATE TABLE t3(x,y);
drhf42d3182017-03-08 12:25:18 +0000784INSERT 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');
drh5128e852012-04-24 13:14:49 +0000790COMMIT;}}
791
danb9cd86a2017-03-25 18:31:42 +0000792
793ifcapable vtab {
794
drhf42d3182017-03-08 12:25:18 +0000795# The --preserve-rowids option to .dump
796#
drhe611f142017-03-08 11:44:00 +0000797do_test shell1-4.1.1 {
798 catchcmd test.db {.dump --preserve-rowids}
799} {0 {PRAGMA foreign_keys=OFF;
800BEGIN TRANSACTION;
801CREATE TABLE t1(x);
drhf42d3182017-03-08 12:25:18 +0000802INSERT INTO t1(rowid,x) VALUES(1,NULL);
803INSERT INTO t1(rowid,x) VALUES(2,'');
804INSERT INTO t1(rowid,x) VALUES(3,1);
805INSERT INTO t1(rowid,x) VALUES(4,2.25);
806INSERT INTO t1(rowid,x) VALUES(5,'hello');
807INSERT INTO t1(rowid,x) VALUES(6,X'807f');
drhe611f142017-03-08 11:44:00 +0000808CREATE TABLE t3(x,y);
drhf42d3182017-03-08 12:25:18 +0000809INSERT INTO t3(rowid,x,y) VALUES(1,1,NULL);
810INSERT INTO t3(rowid,x,y) VALUES(2,2,'');
811INSERT INTO t3(rowid,x,y) VALUES(3,3,1);
812INSERT INTO t3(rowid,x,y) VALUES(4,4,2.25);
813INSERT INTO t3(rowid,x,y) VALUES(5,5,'hello');
814INSERT INTO t3(rowid,x,y) VALUES(6,6,X'807f');
drhe611f142017-03-08 11:44:00 +0000815COMMIT;}}
816
drhf42d3182017-03-08 12:25:18 +0000817# If the table contains an INTEGER PRIMARY KEY, do not record a separate
818# rowid column in the output.
819#
drhe611f142017-03-08 11:44:00 +0000820do_test shell1-4.1.2 {
821 db close
822 forcedelete test2.db
823 sqlite3 db test2.db
824 db eval {
825 CREATE TABLE t1(x INTEGER PRIMARY KEY, y);
826 INSERT INTO t1 VALUES(1,null), (2,''), (3,1),
827 (4,2.25), (5,'hello'), (6,x'807f');
828 }
829 catchcmd test2.db {.dump --preserve-rowids}
830} {0 {PRAGMA foreign_keys=OFF;
831BEGIN TRANSACTION;
832CREATE TABLE t1(x INTEGER PRIMARY KEY, y);
drhf42d3182017-03-08 12:25:18 +0000833INSERT INTO t1 VALUES(1,NULL);
834INSERT INTO t1 VALUES(2,'');
835INSERT INTO t1 VALUES(3,1);
836INSERT INTO t1 VALUES(4,2.25);
837INSERT INTO t1 VALUES(5,'hello');
838INSERT INTO t1 VALUES(6,X'807f');
drhe611f142017-03-08 11:44:00 +0000839COMMIT;}}
840
drhf42d3182017-03-08 12:25:18 +0000841# Verify that the table named [table] is correctly quoted and that
842# an INTEGER PRIMARY KEY DESC is not an alias for the rowid.
843#
844do_test shell1-4.1.3 {
845 db close
846 forcedelete test2.db
847 sqlite3 db test2.db
848 db eval {
849 CREATE TABLE [table](x INTEGER PRIMARY KEY DESC, y);
850 INSERT INTO [table] VALUES(1,null), (12,''), (23,1),
851 (34,2.25), (45,'hello'), (56,x'807f');
852 }
853 catchcmd test2.db {.dump --preserve-rowids}
854} {0 {PRAGMA foreign_keys=OFF;
855BEGIN TRANSACTION;
856CREATE TABLE [table](x INTEGER PRIMARY KEY DESC, y);
857INSERT INTO "table"(rowid,x,y) VALUES(1,1,NULL);
858INSERT INTO "table"(rowid,x,y) VALUES(2,12,'');
859INSERT INTO "table"(rowid,x,y) VALUES(3,23,1);
860INSERT INTO "table"(rowid,x,y) VALUES(4,34,2.25);
861INSERT INTO "table"(rowid,x,y) VALUES(5,45,'hello');
862INSERT INTO "table"(rowid,x,y) VALUES(6,56,X'807f');
863COMMIT;}}
864
865# Do not record rowids for a WITHOUT ROWID table. Also check correct quoting
866# of table names that contain odd characters.
867#
868do_test shell1-4.1.4 {
869 db close
870 forcedelete test2.db
871 sqlite3 db test2.db
872 db eval {
873 CREATE TABLE [ta<>ble](x INTEGER PRIMARY KEY, y) WITHOUT ROWID;
874 INSERT INTO [ta<>ble] VALUES(1,null), (12,''), (23,1),
875 (34,2.25), (45,'hello'), (56,x'807f');
876 }
877 catchcmd test2.db {.dump --preserve-rowids}
878} {0 {PRAGMA foreign_keys=OFF;
879BEGIN TRANSACTION;
880CREATE TABLE [ta<>ble](x INTEGER PRIMARY KEY, y) WITHOUT ROWID;
881INSERT INTO "ta<>ble" VALUES(1,NULL);
882INSERT INTO "ta<>ble" VALUES(12,'');
883INSERT INTO "ta<>ble" VALUES(23,1);
884INSERT INTO "ta<>ble" VALUES(34,2.25);
885INSERT INTO "ta<>ble" VALUES(45,'hello');
886INSERT INTO "ta<>ble" VALUES(56,X'807f');
887COMMIT;}}
888
889# Do not record rowids if the rowid is inaccessible
890#
891do_test shell1-4.1.5 {
892 db close
893 forcedelete test2.db
894 sqlite3 db test2.db
895 db eval {
896 CREATE TABLE t1(_ROWID_,rowid,oid);
897 INSERT INTO t1 VALUES(1,null,'alpha'), (12,'',99), (23,1,x'b0b1b2');
898 }
899 catchcmd test2.db {.dump --preserve-rowids}
900} {0 {PRAGMA foreign_keys=OFF;
901BEGIN TRANSACTION;
902CREATE TABLE t1(_ROWID_,rowid,oid);
903INSERT INTO t1 VALUES(1,NULL,'alpha');
904INSERT INTO t1 VALUES(12,'',99);
905INSERT INTO t1 VALUES(23,1,X'b0b1b2');
906COMMIT;}}
drhe611f142017-03-08 11:44:00 +0000907
danb9cd86a2017-03-25 18:31:42 +0000908} else {
909
910do_test shell1-4.1.6 {
911 db close
912 forcedelete test2.db
913 sqlite3 db test2.db
914 db eval {
915 CREATE TABLE t1(x INTEGER PRIMARY KEY, y);
916 INSERT INTO t1 VALUES(1,null), (2,''), (3,1),
917 (4,2.25), (5,'hello'), (6,x'807f');
918 }
919 catchcmd test2.db {.dump --preserve-rowids}
920} {1 {The --preserve-rowids option is not compatible with SQLITE_OMIT_VIRTUALTABLE}}
921
922}
923
924
drh5128e852012-04-24 13:14:49 +0000925# Test the output of ".mode insert"
926#
mistachkin151c75a2015-04-07 21:16:40 +0000927do_test shell1-4.2.1 {
drh5128e852012-04-24 13:14:49 +0000928 catchcmd test.db ".mode insert t1\nselect * from t1;"
929} {0 {INSERT INTO t1 VALUES(NULL);
mistachkin585dcb22012-12-04 00:23:43 +0000930INSERT INTO t1 VALUES('');
drh5128e852012-04-24 13:14:49 +0000931INSERT INTO t1 VALUES(1);
932INSERT INTO t1 VALUES(2.25);
933INSERT INTO t1 VALUES('hello');
934INSERT INTO t1 VALUES(X'807f');}}
935
mistachkin151c75a2015-04-07 21:16:40 +0000936# Test the output of ".mode insert" with headers
937#
938do_test shell1-4.2.2 {
939 catchcmd test.db ".mode insert t1\n.headers on\nselect * from t1;"
940} {0 {INSERT INTO t1(x) VALUES(NULL);
941INSERT INTO t1(x) VALUES('');
942INSERT INTO t1(x) VALUES(1);
943INSERT INTO t1(x) VALUES(2.25);
944INSERT INTO t1(x) VALUES('hello');
945INSERT INTO t1(x) VALUES(X'807f');}}
946
947# Test the output of ".mode insert"
948#
949do_test shell1-4.2.3 {
950 catchcmd test.db ".mode insert t3\nselect * from t3;"
951} {0 {INSERT INTO t3 VALUES(1,NULL);
952INSERT INTO t3 VALUES(2,'');
953INSERT INTO t3 VALUES(3,1);
954INSERT INTO t3 VALUES(4,2.25);
955INSERT INTO t3 VALUES(5,'hello');
956INSERT INTO t3 VALUES(6,X'807f');}}
957
958# Test the output of ".mode insert" with headers
959#
mistachkincc445402015-04-07 21:17:53 +0000960do_test shell1-4.2.4 {
mistachkin151c75a2015-04-07 21:16:40 +0000961 catchcmd test.db ".mode insert t3\n.headers on\nselect * from t3;"
962} {0 {INSERT INTO t3(x,y) VALUES(1,NULL);
963INSERT INTO t3(x,y) VALUES(2,'');
964INSERT INTO t3(x,y) VALUES(3,1);
965INSERT INTO t3(x,y) VALUES(4,2.25);
966INSERT INTO t3(x,y) VALUES(5,'hello');
967INSERT INTO t3(x,y) VALUES(6,X'807f');}}
968
mistachkin585dcb22012-12-04 00:23:43 +0000969# Test the output of ".mode tcl"
970#
971do_test shell1-4.3 {
drh55a1b302013-09-04 16:08:50 +0000972 db close
973 forcedelete test.db
974 sqlite3 db test.db
975 db eval {
976 PRAGMA encoding=UTF8;
977 CREATE TABLE t1(x);
978 INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f');
979 }
mistachkin585dcb22012-12-04 00:23:43 +0000980 catchcmd test.db ".mode tcl\nselect * from t1;"
981} {0 {""
982""
983"1"
984"2.25"
985"hello"
986"\200\177"}}
987
988# Test the output of ".mode tcl" with multiple columns
989#
990do_test shell1-4.4 {
991 db eval {
992 CREATE TABLE t2(x,y);
993 INSERT INTO t2 VALUES(null, ''), (1, 2.25), ('hello', x'807f');
994 }
995 catchcmd test.db ".mode tcl\nselect * from t2;"
996} {0 {"" ""
997"1" "2.25"
998"hello" "\200\177"}}
999
1000# Test the output of ".mode tcl" with ".nullvalue"
1001#
1002do_test shell1-4.5 {
1003 catchcmd test.db ".mode tcl\n.nullvalue NULL\nselect * from t2;"
1004} {0 {"NULL" ""
1005"1" "2.25"
1006"hello" "\200\177"}}
1007
1008# Test the output of ".mode tcl" with Tcl reserved characters
1009#
1010do_test shell1-4.6 {
1011 db eval {
1012 CREATE TABLE tcl1(x);
1013 INSERT INTO tcl1 VALUES('"'), ('['), (']'), ('\{'), ('\}'), (';'), ('$');
1014 }
1015 foreach {x y} [catchcmd test.db ".mode tcl\nselect * from tcl1;"] break
1016 list $x $y [llength $y]
1017} {0 {"\""
1018"["
1019"]"
1020"\\{"
1021"\\}"
1022";"
1023"$"} 7}
drh5128e852012-04-24 13:14:49 +00001024
mistachkinf21979d2015-01-18 05:35:01 +00001025# Test using arbitrary byte data with the shell via standard input/output.
1026#
1027do_test shell1-5.0 {
1028 #
1029 # NOTE: Skip NUL byte because it appears to be incompatible with command
1030 # shell argument parsing.
1031 #
1032 for {set i 1} {$i < 256} {incr i} {
1033 #
mistachkin46a6b992015-01-18 09:02:57 +00001034 # NOTE: Due to how the Tcl [exec] command works (i.e. where it treats
1035 # command channels opened for it as textual ones), the carriage
1036 # return character (and on Windows, the end-of-file character)
1037 # cannot be used here.
mistachkinf21979d2015-01-18 05:35:01 +00001038 #
mistachkin46a6b992015-01-18 09:02:57 +00001039 if {$i==0x0D || ($tcl_platform(platform)=="windows" && $i==0x1A)} {
mistachkinf21979d2015-01-18 05:35:01 +00001040 continue
1041 }
drh158931a2019-04-12 16:25:42 +00001042 # Tcl 8.7 maps 0x80 through 0x9f into valid UTF8. So skip those tests.
1043 if {$i>=0x80 && $i<=0x9f} continue
drh01725682016-07-25 14:20:01 +00001044 if {$i>=0xE0 && $tcl_platform(os)=="OpenBSD"} continue
mistachkinbe56ad32016-07-29 04:12:18 +00001045 if {$i>=0xE0 && $i<=0xEF && $tcl_platform(os)=="Linux"} continue
mistachkinf21979d2015-01-18 05:35:01 +00001046 set hex [format %02X $i]
1047 set char [subst \\x$hex]; set oldChar $char
mistachkin0acee512015-01-19 21:11:31 +00001048 set escapes [list]
1049 if {$tcl_platform(platform)=="windows"} {
1050 #
1051 # NOTE: On Windows, we need to escape all the whitespace characters,
1052 # the alarm (\a) character, and those with special meaning to
1053 # the SQLite shell itself.
1054 #
1055 set escapes [list \
1056 \a \\a \b \\b \t \\t \n \\n \v \\v \f \\f \r \\r \
1057 " " "\" \"" \" \\\" ' \"'\" \\ \\\\]
1058 } else {
1059 #
1060 # NOTE: On Unix, we need to escape most of the whitespace characters
1061 # and those with special meaning to the SQLite shell itself.
1062 # The alarm (\a), backspace (\b), and carriage-return (\r)
1063 # characters do not appear to require escaping on Unix. For
1064 # the alarm and backspace characters, this is probably due to
1065 # differences in the command shell. For the carriage-return,
1066 # it is probably due to differences in how Tcl handles command
1067 # channel end-of-line translations.
1068 #
1069 set escapes [list \
1070 \t \\t \n \\n \v \\v \f \\f \
1071 " " "\" \"" \" \\\" ' \"'\" \\ \\\\]
1072 }
1073 set char [string map $escapes $char]
mistachkinbfefa4c2015-01-19 21:27:46 +00001074 set x [catchcmdex test.db ".print $char\n"]
mistachkinf21979d2015-01-18 05:35:01 +00001075 set code [lindex $x 0]
1076 set res [lindex $x 1]
1077 if {$code ne "0"} {
1078 error "failed with error: $res"
1079 }
1080 if {$res ne "$oldChar\n"} {
mistachkin48dcf2b2016-04-04 17:59:37 +00001081 if {[llength $res] > 0} {
1082 set got [format %02X [scan $res %c]]
1083 } else {
1084 set got <empty>
1085 }
1086 error "failed with byte $hex mismatch, got $got"
mistachkinf21979d2015-01-18 05:35:01 +00001087 }
1088 }
1089} {}
1090
drh697c9ea2016-05-16 11:55:09 +00001091# These test cases do not work on MinGW
1092if 0 {
1093
mistachkin49e11252016-04-04 15:47:46 +00001094# The string used here is the word "test" in Chinese.
1095# In UTF-8, it is encoded as: \xE6\xB5\x8B\xE8\xAF\x95
1096set test \u6D4B\u8BD5
1097
mistachkin1fe36bb2016-04-04 02:16:44 +00001098do_test shell1-6.0 {
mistachkin49e11252016-04-04 15:47:46 +00001099 set fileName $test; append fileName .db
1100 catch {forcedelete $fileName}
mistachkin1fe36bb2016-04-04 02:16:44 +00001101 set x [catchcmdex $fileName "CREATE TABLE t1(x);\n.schema\n"]
1102 set code [lindex $x 0]
1103 set res [string trim [lindex $x 1]]
1104 if {$code ne "0"} {
1105 error "failed with error: $res"
1106 }
1107 if {$res ne "CREATE TABLE t1(x);"} {
1108 error "failed with mismatch: $res"
1109 }
1110 if {![file exists $fileName]} {
mistachkin1810f222016-04-04 02:33:34 +00001111 error "file \"$fileName\" (Unicode) does not exist"
mistachkin1fe36bb2016-04-04 02:16:44 +00001112 }
1113 forcedelete $fileName
1114} {}
1115
mistachkin49e11252016-04-04 15:47:46 +00001116do_test shell1-6.1 {
1117 catch {forcedelete test3.db}
1118 set x [catchcmdex test3.db \
1119 "CREATE TABLE [encoding convertto utf-8 $test](x);\n.schema\n"]
1120 set code [lindex $x 0]
1121 set res [string trim [lindex $x 1]]
1122 if {$code ne "0"} {
1123 error "failed with error: $res"
1124 }
1125 if {$res ne "CREATE TABLE ${test}(x);"} {
1126 error "failed with mismatch: $res"
1127 }
1128 forcedelete test3.db
1129} {}
drh697c9ea2016-05-16 11:55:09 +00001130}
mistachkin49e11252016-04-04 15:47:46 +00001131
mistachkin9d107262018-03-23 14:24:34 +00001132db close
1133forcedelete test.db test.db-journal test.db-wal
1134sqlite3 db test.db
1135
dan07f119e2018-03-24 15:08:48 +00001136# The shell tool ".schema" command uses virtual table "pragma_database_list"
1137#
1138ifcapable vtab {
1139
mistachkin9d107262018-03-23 14:24:34 +00001140do_test shell1-7.1.1 {
1141 db eval {
1142 CREATE TABLE Z (x TEXT PRIMARY KEY);
1143 CREATE TABLE _ (x TEXT PRIMARY KEY);
1144 CREATE TABLE YY (x TEXT PRIMARY KEY);
1145 CREATE TABLE __ (x TEXT PRIMARY KEY);
1146 CREATE TABLE WWW (x TEXT PRIMARY KEY);
1147 CREATE TABLE ___ (x TEXT PRIMARY KEY);
1148 }
1149} {}
1150do_test shell1-7.1.2 {
1151 catchcmd "test.db" ".schema _"
1152} {0 {CREATE TABLE Z (x TEXT PRIMARY KEY);
1153CREATE TABLE _ (x TEXT PRIMARY KEY);}}
1154do_test shell1-7.1.3 {
1155 catchcmd "test.db" ".schema \\\\_"
1156} {0 {CREATE TABLE _ (x TEXT PRIMARY KEY);}}
1157do_test shell1-7.1.4 {
1158 catchcmd "test.db" ".schema __"
1159} {0 {CREATE TABLE YY (x TEXT PRIMARY KEY);
1160CREATE TABLE __ (x TEXT PRIMARY KEY);}}
1161do_test shell1-7.1.5 {
1162 catchcmd "test.db" ".schema \\\\_\\\\_"
1163} {0 {CREATE TABLE __ (x TEXT PRIMARY KEY);}}
1164do_test shell1-7.1.6 {
1165 catchcmd "test.db" ".schema ___"
1166} {0 {CREATE TABLE WWW (x TEXT PRIMARY KEY);
1167CREATE TABLE ___ (x TEXT PRIMARY KEY);}}
1168do_test shell1-7.1.7 {
1169 catchcmd "test.db" ".schema \\\\_\\\\_\\\\_"
1170} {0 {CREATE TABLE ___ (x TEXT PRIMARY KEY);}}
1171
dan07f119e2018-03-24 15:08:48 +00001172}
1173
drh4dfdb862020-08-11 18:17:04 +00001174# Test case for the ieee754 and decimal extensions in the shell.
1175# See the "floatingpoint.html" file in the documentation for more
1176# information.
1177#
1178do_test shell1-8.1 {
1179 catchcmd ":memory:" {
1180 -- The pow2 table will hold all the necessary powers of two.
1181 CREATE TABLE pow2(x INTEGER PRIMARY KEY, v TEXT);
1182 WITH RECURSIVE c(x,v) AS (
1183 VALUES(0,'1')
1184 UNION ALL
1185 SELECT x+1, decimal_mul(v,'2') FROM c WHERE x+1<=971
1186 ) INSERT INTO pow2(x,v) SELECT x, v FROM c;
1187 WITH RECURSIVE c(x,v) AS (
1188 VALUES(-1,'0.5')
1189 UNION ALL
1190 SELECT x-1, decimal_mul(v,'0.5') FROM c WHERE x-1>=-1075
1191 ) INSERT INTO pow2(x,v) SELECT x, v FROM c;
1192
1193 -- This query finds the decimal representation of each value in the "c" table.
1194 WITH c(n) AS (VALUES(47.49))
1195 ----XXXXX----------- Replace with whatever you want
1196 SELECT decimal_mul(ieee754_mantissa(c.n),pow2.v)
1197 FROM pow2, c WHERE pow2.x=ieee754_exponent(c.n);
1198 }
1199} {0 47.49000000000000198951966012828052043914794921875}
1200do_test shell1-8.2 {
1201 catchcmd :memory: {
1202.mode box
1203SELECT ieee754(47.49) AS x;
1204 }
1205} {0 {┌───────────────────────────────┐
1206│ x │
1207├───────────────────────────────┤
1208│ ieee754(6683623321994527,-47) │
1209└───────────────────────────────┘}}
1210do_test shell1-8.3 {
1211 catchcmd ":memory: --box" {
1212 select ieee754(6683623321994527,-47) as x;
1213 }
1214} {0 {┌───────┐
1215│ x │
1216├───────┤
1217│ 47.49 │
1218└───────┘}}
1219do_test shell1-8.4 {
1220 catchcmd ":memory: --table" {SELECT ieee754_mantissa(47.49) AS M, ieee754_exponent(47.49) AS E;}
1221} {0 {+------------------+-----+
1222| M | E |
1223+------------------+-----+
1224| 6683623321994527 | -47 |
1225+------------------+-----+}}
1226
drh8df91852012-04-24 12:46:05 +00001227finish_test