blob: cbbadc58c9e1b4d83745e503473be9d81e1b73c3 [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.
larrybrd797d6b2021-10-03 22:03:59 +000021# shell1-{4-8}.*: Test various "dot" commands's functionality.
22# shell1-9.*: Basic test that "dot" commands and SQL intermix ok.
shaneha05e0c42009-11-06 03:22:54 +000023#
drh8df91852012-04-24 12:46:05 +000024set testdir [file dirname $argv0]
25source $testdir/tester.tcl
dan089555c2016-03-15 09:55:44 +000026set CLI [test_find_cli]
drh8df91852012-04-24 12:46:05 +000027db close
28forcedelete test.db test.db-journal test.db-wal
shaneha05e0c42009-11-06 03:22:54 +000029sqlite3 db test.db
30
shaneh5fc25012009-11-11 04:17:07 +000031#----------------------------------------------------------------------------
32# Test cases shell1-1.*: Basic command line option handling.
33#
34
35# invalid option
36do_test shell1-1.1.1 {
37 set res [catchcmd "-bad test.db" ""]
38 set rc [lindex $res 0]
39 list $rc \
40 [regexp {Error: unknown option: -bad} $res]
41} {1 1}
drhac5649a2014-11-28 13:35:03 +000042do_test shell1-1.1.1b {
43 set res [catchcmd "test.db -bad" ""]
44 set rc [lindex $res 0]
45 list $rc \
46 [regexp {Error: unknown option: -bad} $res]
47} {1 1}
shaneh5fc25012009-11-11 04:17:07 +000048# error on extra options
49do_test shell1-1.1.2 {
drh60c42492016-03-26 15:36:36 +000050 catchcmd "test.db \"select+3\" \"select+4\"" ""
drhac5649a2014-11-28 13:35:03 +000051} {0 {3
524}}
shaneh5fc25012009-11-11 04:17:07 +000053# error on extra options
shanehca7dfda2009-12-17 21:07:54 +000054do_test shell1-1.1.3 {
drhac5649a2014-11-28 13:35:03 +000055 catchcmd "test.db FOO test.db BAD" ".quit"
drh633c7982022-02-08 12:13:16 +000056} {/1 .Error: in prepare, near "FOO": syntax error*/}
shaneh5fc25012009-11-11 04:17:07 +000057
58# -help
59do_test shell1-1.2.1 {
60 set res [catchcmd "-help test.db" ""]
61 set rc [lindex $res 0]
62 list $rc \
63 [regexp {Usage} $res] \
64 [regexp {\-init} $res] \
65 [regexp {\-version} $res]
66} {1 1 1 1}
67
68# -init filename read/process named file
drhb7c46aa2020-11-25 13:59:47 +000069forcedelete FOO
70set out [open FOO w]
71puts $out ""
72close $out
shaneh5fc25012009-11-11 04:17:07 +000073do_test shell1-1.3.1 {
shanehca7dfda2009-12-17 21:07:54 +000074 catchcmd "-init FOO test.db" ""
shaneh5fc25012009-11-11 04:17:07 +000075} {0 {}}
76do_test shell1-1.3.2 {
drhac5649a2014-11-28 13:35:03 +000077 catchcmd "-init FOO test.db .quit BAD" ""
78} {0 {}}
79do_test shell1-1.3.3 {
80 catchcmd "-init FOO test.db BAD .quit" ""
drh633c7982022-02-08 12:13:16 +000081} {/1 .Error: in prepare, near "BAD": syntax error*/}
shaneh5fc25012009-11-11 04:17:07 +000082
83# -echo print commands before execution
84do_test shell1-1.4.1 {
mistachkin1fe36bb2016-04-04 02:16:44 +000085 catchcmd "-echo test.db" ""
shaneh5fc25012009-11-11 04:17:07 +000086} {0 {}}
87
88# -[no]header turn headers on or off
89do_test shell1-1.5.1 {
mistachkin1fe36bb2016-04-04 02:16:44 +000090 catchcmd "-header test.db" ""
shaneh5fc25012009-11-11 04:17:07 +000091} {0 {}}
92do_test shell1-1.5.2 {
mistachkin1fe36bb2016-04-04 02:16:44 +000093 catchcmd "-noheader test.db" ""
shaneh5fc25012009-11-11 04:17:07 +000094} {0 {}}
95
96# -bail stop after hitting an error
97do_test shell1-1.6.1 {
mistachkin1fe36bb2016-04-04 02:16:44 +000098 catchcmd "-bail test.db" ""
shaneh5fc25012009-11-11 04:17:07 +000099} {0 {}}
100
101# -interactive force interactive I/O
102do_test shell1-1.7.1 {
103 set res [catchcmd "-interactive test.db" ".quit"]
104 set rc [lindex $res 0]
105 list $rc \
106 [regexp {SQLite version} $res] \
drh39a30882014-02-11 16:22:18 +0000107 [regexp {Enter ".help" for usage hints} $res]
shaneh5fc25012009-11-11 04:17:07 +0000108} {0 1 1}
109
110# -batch force batch I/O
111do_test shell1-1.8.1 {
mistachkin1fe36bb2016-04-04 02:16:44 +0000112 catchcmd "-batch test.db" ""
shaneh5fc25012009-11-11 04:17:07 +0000113} {0 {}}
114
115# -column set output mode to 'column'
116do_test shell1-1.9.1 {
mistachkin1fe36bb2016-04-04 02:16:44 +0000117 catchcmd "-column test.db" ""
shaneh5fc25012009-11-11 04:17:07 +0000118} {0 {}}
119
120# -csv set output mode to 'csv'
121do_test shell1-1.10.1 {
mistachkin1fe36bb2016-04-04 02:16:44 +0000122 catchcmd "-csv test.db" ""
shaneh5fc25012009-11-11 04:17:07 +0000123} {0 {}}
124
125# -html set output mode to HTML
126do_test shell1-1.11.1 {
mistachkin1fe36bb2016-04-04 02:16:44 +0000127 catchcmd "-html test.db" ""
shaneh5fc25012009-11-11 04:17:07 +0000128} {0 {}}
129
130# -line set output mode to 'line'
131do_test shell1-1.12.1 {
mistachkin1fe36bb2016-04-04 02:16:44 +0000132 catchcmd "-line test.db" ""
shaneh5fc25012009-11-11 04:17:07 +0000133} {0 {}}
134
135# -list set output mode to 'list'
136do_test shell1-1.13.1 {
mistachkin1fe36bb2016-04-04 02:16:44 +0000137 catchcmd "-list test.db" ""
shaneh5fc25012009-11-11 04:17:07 +0000138} {0 {}}
139
140# -separator 'x' set output field separator (|)
141do_test shell1-1.14.1 {
mistachkin1fe36bb2016-04-04 02:16:44 +0000142 catchcmd "-separator 'x' test.db" ""
shaneh5fc25012009-11-11 04:17:07 +0000143} {0 {}}
144do_test shell1-1.14.2 {
mistachkin1fe36bb2016-04-04 02:16:44 +0000145 catchcmd "-separator x test.db" ""
shaneh5fc25012009-11-11 04:17:07 +0000146} {0 {}}
147do_test shell1-1.14.3 {
148 set res [catchcmd "-separator" ""]
149 set rc [lindex $res 0]
150 list $rc \
drh98d312f2012-10-25 15:23:14 +0000151 [regexp {Error: missing argument to -separator} $res]
shaneh5fc25012009-11-11 04:17:07 +0000152} {1 1}
153
shaneh642d8b82010-07-28 16:05:34 +0000154# -stats print memory stats before each finalize
155do_test shell1-1.14b.1 {
mistachkin1fe36bb2016-04-04 02:16:44 +0000156 catchcmd "-stats test.db" ""
shaneh642d8b82010-07-28 16:05:34 +0000157} {0 {}}
158
shaneh5fc25012009-11-11 04:17:07 +0000159# -nullvalue 'text' set text string for NULL values
160do_test shell1-1.15.1 {
161 catchcmd "-nullvalue 'x' test.db" ""
162} {0 {}}
163do_test shell1-1.15.2 {
164 catchcmd "-nullvalue x test.db" ""
165} {0 {}}
166do_test shell1-1.15.3 {
167 set res [catchcmd "-nullvalue" ""]
168 set rc [lindex $res 0]
169 list $rc \
drh98d312f2012-10-25 15:23:14 +0000170 [regexp {Error: missing argument to -nullvalue} $res]
shaneh5fc25012009-11-11 04:17:07 +0000171} {1 1}
172
173# -version show SQLite version
174do_test shell1-1.16.1 {
drh9fd301b2011-06-03 13:28:22 +0000175 set x [catchcmd "-version test.db" ""]
drhb24c61a2012-05-21 22:45:35 +0000176} {/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 +0000177
shaneha05e0c42009-11-06 03:22:54 +0000178#----------------------------------------------------------------------------
shaneh5fc25012009-11-11 04:17:07 +0000179# Test cases shell1-2.*: Basic "dot" command token parsing.
shanehe2aa9d72009-11-06 17:20:17 +0000180#
181
182# check first token handling
shaneh5fc25012009-11-11 04:17:07 +0000183do_test shell1-2.1.1 {
mistachkin1fe36bb2016-04-04 02:16:44 +0000184 catchcmd "test.db" ".foo"
shanehe2aa9d72009-11-06 17:20:17 +0000185} {1 {Error: unknown command or invalid arguments: "foo". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000186do_test shell1-2.1.2 {
shanehca7dfda2009-12-17 21:07:54 +0000187 catchcmd "test.db" ".\"foo OFF\""
shanehe2aa9d72009-11-06 17:20:17 +0000188} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000189do_test shell1-2.1.3 {
shanehca7dfda2009-12-17 21:07:54 +0000190 catchcmd "test.db" ".\'foo OFF\'"
shanehe2aa9d72009-11-06 17:20:17 +0000191} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}}
192
193# unbalanced quotes
shaneh5fc25012009-11-11 04:17:07 +0000194do_test shell1-2.2.1 {
shanehca7dfda2009-12-17 21:07:54 +0000195 catchcmd "test.db" ".\"foo OFF"
shanehe2aa9d72009-11-06 17:20:17 +0000196} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000197do_test shell1-2.2.2 {
shanehca7dfda2009-12-17 21:07:54 +0000198 catchcmd "test.db" ".\'foo OFF"
shanehe2aa9d72009-11-06 17:20:17 +0000199} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}}
shaneh5fc25012009-11-11 04:17:07 +0000200do_test shell1-2.2.3 {
shanehca7dfda2009-12-17 21:07:54 +0000201 catchcmd "test.db" ".explain \"OFF"
shanehe2aa9d72009-11-06 17:20:17 +0000202} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000203do_test shell1-2.2.4 {
shanehca7dfda2009-12-17 21:07:54 +0000204 catchcmd "test.db" ".explain \'OFF"
shanehe2aa9d72009-11-06 17:20:17 +0000205} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000206do_test shell1-2.2.5 {
shanehca7dfda2009-12-17 21:07:54 +0000207 catchcmd "test.db" ".mode \"insert FOO"
drhca1776b2022-02-01 12:28:17 +0000208} {1 {Error: mode should be one of: ascii box column csv html insert json line list markdown qbox quote table tabs tcl}}
shaneh5fc25012009-11-11 04:17:07 +0000209do_test shell1-2.2.6 {
shanehca7dfda2009-12-17 21:07:54 +0000210 catchcmd "test.db" ".mode \'insert FOO"
drhca1776b2022-02-01 12:28:17 +0000211} {1 {Error: mode should be one of: ascii box column csv html insert json line list markdown qbox quote table tabs tcl}}
shanehe2aa9d72009-11-06 17:20:17 +0000212
213# check multiple tokens, and quoted tokens
shaneh5fc25012009-11-11 04:17:07 +0000214do_test shell1-2.3.1 {
shanehca7dfda2009-12-17 21:07:54 +0000215 catchcmd "test.db" ".explain 1"
shanehe2aa9d72009-11-06 17:20:17 +0000216} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000217do_test shell1-2.3.2 {
shanehca7dfda2009-12-17 21:07:54 +0000218 catchcmd "test.db" ".explain on"
shanehe2aa9d72009-11-06 17:20:17 +0000219} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000220do_test shell1-2.3.3 {
shanehca7dfda2009-12-17 21:07:54 +0000221 catchcmd "test.db" ".explain \"1 2 3\""
drh173ba092013-01-28 18:18:26 +0000222} {1 {ERROR: Not a boolean value: "1 2 3". Assuming "no".}}
shaneh5fc25012009-11-11 04:17:07 +0000223do_test shell1-2.3.4 {
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.5 {
shanehca7dfda2009-12-17 21:07:54 +0000227 catchcmd "test.db" ".\'explain\' \'OFF\'"
shanehe2aa9d72009-11-06 17:20:17 +0000228} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000229do_test shell1-2.3.6 {
shanehca7dfda2009-12-17 21:07:54 +0000230 catchcmd "test.db" ".explain \'OFF\'"
shanehe2aa9d72009-11-06 17:20:17 +0000231} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000232do_test shell1-2.3.7 {
shanehca7dfda2009-12-17 21:07:54 +0000233 catchcmd "test.db" ".\'explain\' \'OFF\'"
shanehe2aa9d72009-11-06 17:20:17 +0000234} {0 {}}
235
236# check quoted args are unquoted
shaneh5fc25012009-11-11 04:17:07 +0000237do_test shell1-2.4.1 {
shanehca7dfda2009-12-17 21:07:54 +0000238 catchcmd "test.db" ".mode FOO"
drhca1776b2022-02-01 12:28:17 +0000239} {1 {Error: mode should be one of: ascii box column csv html insert json line list markdown qbox quote table tabs tcl}}
shaneh5fc25012009-11-11 04:17:07 +0000240do_test shell1-2.4.2 {
shanehca7dfda2009-12-17 21:07:54 +0000241 catchcmd "test.db" ".mode csv"
shanehe2aa9d72009-11-06 17:20:17 +0000242} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000243do_test shell1-2.4.2 {
shanehca7dfda2009-12-17 21:07:54 +0000244 catchcmd "test.db" ".mode \"csv\""
shanehe2aa9d72009-11-06 17:20:17 +0000245} {0 {}}
246
247
248#----------------------------------------------------------------------------
shaneh5fc25012009-11-11 04:17:07 +0000249# Test cases shell1-3.*: Basic test that "dot" command can be called.
shaneha05e0c42009-11-06 03:22:54 +0000250#
251
252# .backup ?DB? FILE Backup DB (default "main") to FILE
shaneh5fc25012009-11-11 04:17:07 +0000253do_test shell1-3.1.1 {
shanehca7dfda2009-12-17 21:07:54 +0000254 catchcmd "test.db" ".backup"
drhbc46f022013-01-23 18:53:23 +0000255} {1 {missing FILENAME argument on .backup}}
drhf82d78e2020-11-25 14:50:42 +0000256forcedelete FOO
shaneh5fc25012009-11-11 04:17:07 +0000257do_test shell1-3.1.2 {
shanehca7dfda2009-12-17 21:07:54 +0000258 catchcmd "test.db" ".backup FOO"
259} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000260do_test shell1-3.1.3 {
shanehca7dfda2009-12-17 21:07:54 +0000261 catchcmd "test.db" ".backup FOO BAR"
shanehe2aa9d72009-11-06 17:20:17 +0000262} {1 {Error: unknown database FOO}}
shaneh5fc25012009-11-11 04:17:07 +0000263do_test shell1-3.1.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000264 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000265 catchcmd "test.db" ".backup FOO BAR BAD"
drh4d342822018-12-10 00:41:28 +0000266} {1 {Usage: .backup ?DB? ?OPTIONS? FILENAME}}
shaneha05e0c42009-11-06 03:22:54 +0000267
268# .bail ON|OFF Stop after hitting an error. Default OFF
shaneh5fc25012009-11-11 04:17:07 +0000269do_test shell1-3.2.1 {
shanehca7dfda2009-12-17 21:07:54 +0000270 catchcmd "test.db" ".bail"
drhc2ce0be2014-05-29 12:36:14 +0000271} {1 {Usage: .bail on|off}}
shaneh5fc25012009-11-11 04:17:07 +0000272do_test shell1-3.2.2 {
shanehca7dfda2009-12-17 21:07:54 +0000273 catchcmd "test.db" ".bail ON"
shaneha05e0c42009-11-06 03:22:54 +0000274} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000275do_test shell1-3.2.3 {
shanehca7dfda2009-12-17 21:07:54 +0000276 catchcmd "test.db" ".bail OFF"
shaneha05e0c42009-11-06 03:22:54 +0000277} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000278do_test shell1-3.2.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000279 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000280 catchcmd "test.db" ".bail OFF BAD"
drhc2ce0be2014-05-29 12:36:14 +0000281} {1 {Usage: .bail on|off}}
shaneha05e0c42009-11-06 03:22:54 +0000282
drhc5954192016-12-27 02:43:47 +0000283ifcapable vtab {
shaneha05e0c42009-11-06 03:22:54 +0000284# .databases List names and files of attached databases
shaneh5fc25012009-11-11 04:17:07 +0000285do_test shell1-3.3.1 {
drheaa544d2016-03-26 14:41:13 +0000286 catchcmd "-csv test.db" ".databases"
drh15707ac2016-03-26 13:26:35 +0000287} "/0.+main.+[string map {/ ".{1,2}"} [string range [get_pwd] 0 10]].*/"
shaneh5fc25012009-11-11 04:17:07 +0000288do_test shell1-3.3.2 {
drhc2ce0be2014-05-29 12:36:14 +0000289 # extra arguments ignored
drheaa544d2016-03-26 14:41:13 +0000290 catchcmd "test.db" ".databases BAD"
drh15707ac2016-03-26 13:26:35 +0000291} "/0.+main.+[string map {/ ".{1,2}"} [string range [get_pwd] 0 10]].*/"
drhc5954192016-12-27 02:43:47 +0000292}
shaneha05e0c42009-11-06 03:22:54 +0000293
294# .dump ?TABLE? ... Dump the database in an SQL text format
295# If TABLE specified, only dump tables matching
296# LIKE pattern TABLE.
shaneh5fc25012009-11-11 04:17:07 +0000297do_test shell1-3.4.1 {
shanehca7dfda2009-12-17 21:07:54 +0000298 set res [catchcmd "test.db" ".dump"]
shaneha05e0c42009-11-06 03:22:54 +0000299 list [regexp {BEGIN TRANSACTION;} $res] \
300 [regexp {COMMIT;} $res]
301} {1 1}
shaneh5fc25012009-11-11 04:17:07 +0000302do_test shell1-3.4.2 {
shanehca7dfda2009-12-17 21:07:54 +0000303 set res [catchcmd "test.db" ".dump FOO"]
shaneha05e0c42009-11-06 03:22:54 +0000304 list [regexp {BEGIN TRANSACTION;} $res] \
305 [regexp {COMMIT;} $res]
306} {1 1}
drh8e9297f2020-03-25 12:50:13 +0000307# The .dump command now accepts multiple arguments
308#do_test shell1-3.4.3 {
309# # too many arguments
310# catchcmd "test.db" ".dump FOO BAD"
311#} {1 {Usage: .dump ?--preserve-rowids? ?--newlines? ?LIKE-PATTERN?}}
shaneha05e0c42009-11-06 03:22:54 +0000312
313# .echo ON|OFF Turn command echo on or off
shaneh5fc25012009-11-11 04:17:07 +0000314do_test shell1-3.5.1 {
shanehca7dfda2009-12-17 21:07:54 +0000315 catchcmd "test.db" ".echo"
drhc2ce0be2014-05-29 12:36:14 +0000316} {1 {Usage: .echo on|off}}
shaneh5fc25012009-11-11 04:17:07 +0000317do_test shell1-3.5.2 {
shanehca7dfda2009-12-17 21:07:54 +0000318 catchcmd "test.db" ".echo ON"
shaneha05e0c42009-11-06 03:22:54 +0000319} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000320do_test shell1-3.5.3 {
shanehca7dfda2009-12-17 21:07:54 +0000321 catchcmd "test.db" ".echo OFF"
shaneha05e0c42009-11-06 03:22:54 +0000322} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000323do_test shell1-3.5.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000324 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000325 catchcmd "test.db" ".echo OFF BAD"
drhc2ce0be2014-05-29 12:36:14 +0000326} {1 {Usage: .echo on|off}}
shaneha05e0c42009-11-06 03:22:54 +0000327
328# .exit Exit this program
shaneh5fc25012009-11-11 04:17:07 +0000329do_test shell1-3.6.1 {
shanehca7dfda2009-12-17 21:07:54 +0000330 catchcmd "test.db" ".exit"
shaneha05e0c42009-11-06 03:22:54 +0000331} {0 {}}
332
333# .explain ON|OFF Turn output mode suitable for EXPLAIN on or off.
shaneh5fc25012009-11-11 04:17:07 +0000334do_test shell1-3.7.1 {
shanehca7dfda2009-12-17 21:07:54 +0000335 catchcmd "test.db" ".explain"
shanehe2aa9d72009-11-06 17:20:17 +0000336 # explain is the exception to the booleans. without an option, it turns it on.
337} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000338do_test shell1-3.7.2 {
shanehca7dfda2009-12-17 21:07:54 +0000339 catchcmd "test.db" ".explain ON"
shaneha05e0c42009-11-06 03:22:54 +0000340} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000341do_test shell1-3.7.3 {
shanehca7dfda2009-12-17 21:07:54 +0000342 catchcmd "test.db" ".explain OFF"
shaneha05e0c42009-11-06 03:22:54 +0000343} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000344do_test shell1-3.7.4 {
drhc2ce0be2014-05-29 12:36:14 +0000345 # extra arguments ignored
shanehca7dfda2009-12-17 21:07:54 +0000346 catchcmd "test.db" ".explain OFF BAD"
drhc2ce0be2014-05-29 12:36:14 +0000347} {0 {}}
shaneha05e0c42009-11-06 03:22:54 +0000348
shaneha05e0c42009-11-06 03:22:54 +0000349
350# .header(s) ON|OFF Turn display of headers on or off
shaneh5fc25012009-11-11 04:17:07 +0000351do_test shell1-3.9.1 {
shanehca7dfda2009-12-17 21:07:54 +0000352 catchcmd "test.db" ".header"
drhc2ce0be2014-05-29 12:36:14 +0000353} {1 {Usage: .headers on|off}}
shaneh5fc25012009-11-11 04:17:07 +0000354do_test shell1-3.9.2 {
shanehca7dfda2009-12-17 21:07:54 +0000355 catchcmd "test.db" ".header ON"
shaneha05e0c42009-11-06 03:22:54 +0000356} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000357do_test shell1-3.9.3 {
shanehca7dfda2009-12-17 21:07:54 +0000358 catchcmd "test.db" ".header OFF"
shaneha05e0c42009-11-06 03:22:54 +0000359} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000360do_test shell1-3.9.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000361 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000362 catchcmd "test.db" ".header OFF BAD"
drhc2ce0be2014-05-29 12:36:14 +0000363} {1 {Usage: .headers on|off}}
shanehe2aa9d72009-11-06 17:20:17 +0000364
shaneh5fc25012009-11-11 04:17:07 +0000365do_test shell1-3.9.5 {
shanehca7dfda2009-12-17 21:07:54 +0000366 catchcmd "test.db" ".headers"
drhc2ce0be2014-05-29 12:36:14 +0000367} {1 {Usage: .headers on|off}}
shaneh5fc25012009-11-11 04:17:07 +0000368do_test shell1-3.9.6 {
shanehca7dfda2009-12-17 21:07:54 +0000369 catchcmd "test.db" ".headers ON"
shaneha05e0c42009-11-06 03:22:54 +0000370} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000371do_test shell1-3.9.7 {
shanehca7dfda2009-12-17 21:07:54 +0000372 catchcmd "test.db" ".headers OFF"
shaneha05e0c42009-11-06 03:22:54 +0000373} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000374do_test shell1-3.9.8 {
shanehe2aa9d72009-11-06 17:20:17 +0000375 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000376 catchcmd "test.db" ".headers OFF BAD"
drhc2ce0be2014-05-29 12:36:14 +0000377} {1 {Usage: .headers on|off}}
shaneha05e0c42009-11-06 03:22:54 +0000378
379# .help Show this message
shaneh5fc25012009-11-11 04:17:07 +0000380do_test shell1-3.10.1 {
shanehca7dfda2009-12-17 21:07:54 +0000381 set res [catchcmd "test.db" ".help"]
shaneha05e0c42009-11-06 03:22:54 +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}
shaneh5fc25012009-11-11 04:17:07 +0000387do_test shell1-3.10.2 {
shanehe2aa9d72009-11-06 17:20:17 +0000388 # we allow .help to take extra args (it is help after all)
drh98aa2ab2018-09-26 16:53:51 +0000389 set res [catchcmd "test.db" ".help *"]
shanehe2aa9d72009-11-06 17:20:17 +0000390 # look for a few of the possible help commands
391 list [regexp {.help} $res] \
392 [regexp {.quit} $res] \
393 [regexp {.show} $res]
394} {1 1 1}
shaneha05e0c42009-11-06 03:22:54 +0000395
396# .import FILE TABLE Import data from FILE into TABLE
shaneh5fc25012009-11-11 04:17:07 +0000397do_test shell1-3.11.1 {
shanehca7dfda2009-12-17 21:07:54 +0000398 catchcmd "test.db" ".import"
drhccb37812020-03-09 15:39:39 +0000399} {/1 .ERROR: missing FILE argument.*/}
shaneh5fc25012009-11-11 04:17:07 +0000400do_test shell1-3.11.2 {
shanehca7dfda2009-12-17 21:07:54 +0000401 catchcmd "test.db" ".import FOO"
drhccb37812020-03-09 15:39:39 +0000402} {/1 .ERROR: missing TABLE argument.*/}
shaneh5fc25012009-11-11 04:17:07 +0000403do_test shell1-3.11.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000404 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000405 catchcmd "test.db" ".import FOO BAR BAD"
drhccb37812020-03-09 15:39:39 +0000406} {/1 .ERROR: extra argument: "BAD".*./}
shaneha05e0c42009-11-06 03:22:54 +0000407
drh0e55db12015-02-06 14:51:13 +0000408# .indexes ?TABLE? Show names of all indexes
409# If TABLE specified, only show indexes for tables
shaneha05e0c42009-11-06 03:22:54 +0000410# matching LIKE pattern TABLE.
shaneh5fc25012009-11-11 04:17:07 +0000411do_test shell1-3.12.1 {
drh0e55db12015-02-06 14:51:13 +0000412 catchcmd "test.db" ".indexes"
shaneha05e0c42009-11-06 03:22:54 +0000413} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000414do_test shell1-3.12.2 {
drh0e55db12015-02-06 14:51:13 +0000415 catchcmd "test.db" ".indexes FOO"
416} {0 {}}
417do_test shell1-3.12.2-legacy {
shanehca7dfda2009-12-17 21:07:54 +0000418 catchcmd "test.db" ".indices FOO"
shaneha05e0c42009-11-06 03:22:54 +0000419} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000420do_test shell1-3.12.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000421 # too many arguments
drh0e55db12015-02-06 14:51:13 +0000422 catchcmd "test.db" ".indexes FOO BAD"
423} {1 {Usage: .indexes ?LIKE-PATTERN?}}
shaneha05e0c42009-11-06 03:22:54 +0000424
425# .mode MODE ?TABLE? Set output mode where MODE is one of:
mistachkine0d68852014-12-11 03:12:33 +0000426# ascii Columns/rows delimited by 0x1F and 0x1E
shaneha05e0c42009-11-06 03:22:54 +0000427# csv Comma-separated values
428# column Left-aligned columns. (See .width)
429# html HTML <table> code
430# insert SQL insert statements for TABLE
431# line One value per line
mistachkine0d68852014-12-11 03:12:33 +0000432# list Values delimited by .separator strings
shaneha05e0c42009-11-06 03:22:54 +0000433# tabs Tab-separated values
434# tcl TCL list elements
shaneh5fc25012009-11-11 04:17:07 +0000435do_test shell1-3.13.1 {
shanehca7dfda2009-12-17 21:07:54 +0000436 catchcmd "test.db" ".mode"
drha501f7d2017-06-29 21:33:25 +0000437} {0 {current output mode: list}}
shaneh5fc25012009-11-11 04:17:07 +0000438do_test shell1-3.13.2 {
shanehca7dfda2009-12-17 21:07:54 +0000439 catchcmd "test.db" ".mode FOO"
drhca1776b2022-02-01 12:28:17 +0000440} {1 {Error: mode should be one of: ascii box column csv html insert json line list markdown qbox quote table tabs tcl}}
shaneh5fc25012009-11-11 04:17:07 +0000441do_test shell1-3.13.3 {
shanehca7dfda2009-12-17 21:07:54 +0000442 catchcmd "test.db" ".mode csv"
shaneha05e0c42009-11-06 03:22:54 +0000443} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000444do_test shell1-3.13.4 {
shanehca7dfda2009-12-17 21:07:54 +0000445 catchcmd "test.db" ".mode column"
shaneha05e0c42009-11-06 03:22:54 +0000446} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000447do_test shell1-3.13.5 {
shanehca7dfda2009-12-17 21:07:54 +0000448 catchcmd "test.db" ".mode html"
shaneha05e0c42009-11-06 03:22:54 +0000449} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000450do_test shell1-3.13.6 {
shanehca7dfda2009-12-17 21:07:54 +0000451 catchcmd "test.db" ".mode insert"
shaneha05e0c42009-11-06 03:22:54 +0000452} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000453do_test shell1-3.13.7 {
shanehca7dfda2009-12-17 21:07:54 +0000454 catchcmd "test.db" ".mode line"
shaneha05e0c42009-11-06 03:22:54 +0000455} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000456do_test shell1-3.13.8 {
shanehca7dfda2009-12-17 21:07:54 +0000457 catchcmd "test.db" ".mode list"
shaneha05e0c42009-11-06 03:22:54 +0000458} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000459do_test shell1-3.13.9 {
shanehca7dfda2009-12-17 21:07:54 +0000460 catchcmd "test.db" ".mode tabs"
shaneha05e0c42009-11-06 03:22:54 +0000461} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000462do_test shell1-3.13.10 {
shanehca7dfda2009-12-17 21:07:54 +0000463 catchcmd "test.db" ".mode tcl"
shaneha05e0c42009-11-06 03:22:54 +0000464} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000465do_test shell1-3.13.11 {
drhc2ce0be2014-05-29 12:36:14 +0000466 # extra arguments ignored
shanehca7dfda2009-12-17 21:07:54 +0000467 catchcmd "test.db" ".mode tcl BAD"
drhc2ce0be2014-05-29 12:36:14 +0000468} {0 {}}
shanehe2aa9d72009-11-06 17:20:17 +0000469
shaneha05e0c42009-11-06 03:22:54 +0000470# .nullvalue STRING Print STRING in place of NULL values
shaneh5fc25012009-11-11 04:17:07 +0000471do_test shell1-3.14.1 {
shanehca7dfda2009-12-17 21:07:54 +0000472 catchcmd "test.db" ".nullvalue"
drhc2ce0be2014-05-29 12:36:14 +0000473} {1 {Usage: .nullvalue STRING}}
shaneh5fc25012009-11-11 04:17:07 +0000474do_test shell1-3.14.2 {
shanehca7dfda2009-12-17 21:07:54 +0000475 catchcmd "test.db" ".nullvalue FOO"
shaneha05e0c42009-11-06 03:22:54 +0000476} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000477do_test shell1-3.14.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000478 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000479 catchcmd "test.db" ".nullvalue FOO BAD"
drhc2ce0be2014-05-29 12:36:14 +0000480} {1 {Usage: .nullvalue STRING}}
shaneha05e0c42009-11-06 03:22:54 +0000481
482# .output FILENAME Send output to FILENAME
shaneh5fc25012009-11-11 04:17:07 +0000483do_test shell1-3.15.1 {
shanehca7dfda2009-12-17 21:07:54 +0000484 catchcmd "test.db" ".output"
drhc2ce0be2014-05-29 12:36:14 +0000485} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000486do_test shell1-3.15.2 {
shanehca7dfda2009-12-17 21:07:54 +0000487 catchcmd "test.db" ".output FOO"
shaneha05e0c42009-11-06 03:22:54 +0000488} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000489do_test shell1-3.15.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000490 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000491 catchcmd "test.db" ".output FOO BAD"
drh541ef2c2020-04-20 16:21:30 +0000492} {1 {ERROR: extra parameter: "BAD". Usage:
493.output ?FILE? Send output to FILE or stdout if FILE is omitted
494 If FILE begins with '|' then open it as a pipe.
495 Options:
496 --bom Prefix output with a UTF8 byte-order mark
497 -e Send output to the system text editor
498 -x Send output as CSV to a spreadsheet
499child process exited abnormally}}
shaneha05e0c42009-11-06 03:22:54 +0000500
501# .output stdout Send output to the screen
shaneh5fc25012009-11-11 04:17:07 +0000502do_test shell1-3.16.1 {
shanehca7dfda2009-12-17 21:07:54 +0000503 catchcmd "test.db" ".output stdout"
shaneha05e0c42009-11-06 03:22:54 +0000504} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000505do_test shell1-3.16.2 {
shanehe2aa9d72009-11-06 17:20:17 +0000506 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000507 catchcmd "test.db" ".output stdout BAD"
drh541ef2c2020-04-20 16:21:30 +0000508} {1 {ERROR: extra parameter: "BAD". Usage:
509.output ?FILE? Send output to FILE or stdout if FILE is omitted
510 If FILE begins with '|' then open it as a pipe.
511 Options:
512 --bom Prefix output with a UTF8 byte-order mark
513 -e Send output to the system text editor
514 -x Send output as CSV to a spreadsheet
515child process exited abnormally}}
shaneha05e0c42009-11-06 03:22:54 +0000516
517# .prompt MAIN CONTINUE Replace the standard prompts
shaneh5fc25012009-11-11 04:17:07 +0000518do_test shell1-3.17.1 {
shanehca7dfda2009-12-17 21:07:54 +0000519 catchcmd "test.db" ".prompt"
drhc2ce0be2014-05-29 12:36:14 +0000520} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000521do_test shell1-3.17.2 {
shanehca7dfda2009-12-17 21:07:54 +0000522 catchcmd "test.db" ".prompt FOO"
shaneha05e0c42009-11-06 03:22:54 +0000523} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000524do_test shell1-3.17.3 {
shanehca7dfda2009-12-17 21:07:54 +0000525 catchcmd "test.db" ".prompt FOO BAR"
shaneha05e0c42009-11-06 03:22:54 +0000526} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000527do_test shell1-3.17.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000528 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000529 catchcmd "test.db" ".prompt FOO BAR BAD"
drhc2ce0be2014-05-29 12:36:14 +0000530} {0 {}}
shaneha05e0c42009-11-06 03:22:54 +0000531
532# .quit Exit this program
shaneh5fc25012009-11-11 04:17:07 +0000533do_test shell1-3.18.1 {
shanehca7dfda2009-12-17 21:07:54 +0000534 catchcmd "test.db" ".quit"
shaneha05e0c42009-11-06 03:22:54 +0000535} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000536do_test shell1-3.18.2 {
shanehe2aa9d72009-11-06 17:20:17 +0000537 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000538 catchcmd "test.db" ".quit BAD"
drhc2ce0be2014-05-29 12:36:14 +0000539} {0 {}}
shaneha05e0c42009-11-06 03:22:54 +0000540
541# .read FILENAME Execute SQL in FILENAME
shaneh5fc25012009-11-11 04:17:07 +0000542do_test shell1-3.19.1 {
shanehca7dfda2009-12-17 21:07:54 +0000543 catchcmd "test.db" ".read"
drhc2ce0be2014-05-29 12:36:14 +0000544} {1 {Usage: .read FILE}}
shaneh5fc25012009-11-11 04:17:07 +0000545do_test shell1-3.19.2 {
mistachkin9ac99312013-09-13 23:26:47 +0000546 forcedelete FOO
shanehca7dfda2009-12-17 21:07:54 +0000547 catchcmd "test.db" ".read FOO"
shaneha05e0c42009-11-06 03:22:54 +0000548} {1 {Error: cannot open "FOO"}}
shaneh5fc25012009-11-11 04:17:07 +0000549do_test shell1-3.19.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000550 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000551 catchcmd "test.db" ".read FOO BAD"
drhc2ce0be2014-05-29 12:36:14 +0000552} {1 {Usage: .read FILE}}
shaneha05e0c42009-11-06 03:22:54 +0000553
554# .restore ?DB? FILE Restore content of DB (default "main") from FILE
shaneh5fc25012009-11-11 04:17:07 +0000555do_test shell1-3.20.1 {
shanehca7dfda2009-12-17 21:07:54 +0000556 catchcmd "test.db" ".restore"
drhc2ce0be2014-05-29 12:36:14 +0000557} {1 {Usage: .restore ?DB? FILE}}
shaneh5fc25012009-11-11 04:17:07 +0000558do_test shell1-3.20.2 {
shanehca7dfda2009-12-17 21:07:54 +0000559 catchcmd "test.db" ".restore FOO"
560} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000561do_test shell1-3.20.3 {
shanehca7dfda2009-12-17 21:07:54 +0000562 catchcmd "test.db" ".restore FOO BAR"
shanehe2aa9d72009-11-06 17:20:17 +0000563} {1 {Error: unknown database FOO}}
shaneh5fc25012009-11-11 04:17:07 +0000564do_test shell1-3.20.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000565 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000566 catchcmd "test.db" ".restore FOO BAR BAD"
drhc2ce0be2014-05-29 12:36:14 +0000567} {1 {Usage: .restore ?DB? FILE}}
shaneha05e0c42009-11-06 03:22:54 +0000568
drha22dd382017-06-24 19:21:48 +0000569ifcapable vtab {
shaneha05e0c42009-11-06 03:22:54 +0000570# .schema ?TABLE? Show the CREATE statements
571# If TABLE specified, only show tables matching
572# LIKE pattern TABLE.
shaneh5fc25012009-11-11 04:17:07 +0000573do_test shell1-3.21.1 {
shanehca7dfda2009-12-17 21:07:54 +0000574 catchcmd "test.db" ".schema"
shaneha05e0c42009-11-06 03:22:54 +0000575} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000576do_test shell1-3.21.2 {
shanehca7dfda2009-12-17 21:07:54 +0000577 catchcmd "test.db" ".schema FOO"
shaneha05e0c42009-11-06 03:22:54 +0000578} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000579do_test shell1-3.21.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000580 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000581 catchcmd "test.db" ".schema FOO BAD"
drhbbb29ec2020-10-12 14:56:47 +0000582} {1 {Usage: .schema ?--indent? ?--nosys? ?LIKE-PATTERN?}}
shaneha05e0c42009-11-06 03:22:54 +0000583
drhac43e982012-05-21 03:15:06 +0000584do_test shell1-3.21.4 {
585 catchcmd "test.db" {
586 CREATE TABLE t1(x);
587 CREATE VIEW v2 AS SELECT x+1 AS y FROM t1;
588 CREATE VIEW v1 AS SELECT y+1 FROM v2;
589 }
590 catchcmd "test.db" ".schema"
591} {0 {CREATE TABLE t1(x);
drhceba7922018-01-01 21:28:25 +0000592CREATE VIEW v2 AS SELECT x+1 AS y FROM t1
drh1d315cf2018-01-01 21:49:43 +0000593/* v2(y) */;
drhceba7922018-01-01 21:28:25 +0000594CREATE VIEW v1 AS SELECT y+1 FROM v2
drh1d315cf2018-01-01 21:49:43 +0000595/* v1("y+1") */;}}
larrybr4c5c6212022-02-11 01:21:09 +0000596
597 catch {db eval {DROP VIEW v1; DROP VIEW v2; DROP TABLE t1;}}
drha22dd382017-06-24 19:21:48 +0000598}
drhac43e982012-05-21 03:15:06 +0000599
mistachkin636bf9f2014-07-19 20:15:16 +0000600# .separator STRING Change column separator used by output and .import
shaneh5fc25012009-11-11 04:17:07 +0000601do_test shell1-3.22.1 {
shanehca7dfda2009-12-17 21:07:54 +0000602 catchcmd "test.db" ".separator"
mistachkine0d68852014-12-11 03:12:33 +0000603} {1 {Usage: .separator COL ?ROW?}}
shaneh5fc25012009-11-11 04:17:07 +0000604do_test shell1-3.22.2 {
shanehca7dfda2009-12-17 21:07:54 +0000605 catchcmd "test.db" ".separator FOO"
shaneha05e0c42009-11-06 03:22:54 +0000606} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000607do_test shell1-3.22.3 {
drh6976c212014-07-24 12:09:47 +0000608 catchcmd "test.db" ".separator ABC XYZ"
609} {0 {}}
610do_test shell1-3.22.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000611 # too many arguments
drh6976c212014-07-24 12:09:47 +0000612 catchcmd "test.db" ".separator FOO BAD BAD2"
mistachkine0d68852014-12-11 03:12:33 +0000613} {1 {Usage: .separator COL ?ROW?}}
shaneha05e0c42009-11-06 03:22:54 +0000614
615# .show Show the current values for various settings
shaneh5fc25012009-11-11 04:17:07 +0000616do_test shell1-3.23.1 {
shanehca7dfda2009-12-17 21:07:54 +0000617 set res [catchcmd "test.db" ".show"]
shaneha05e0c42009-11-06 03:22:54 +0000618 list [regexp {echo:} $res] \
619 [regexp {explain:} $res] \
620 [regexp {headers:} $res] \
621 [regexp {mode:} $res] \
622 [regexp {nullvalue:} $res] \
623 [regexp {output:} $res] \
mistachkin636bf9f2014-07-19 20:15:16 +0000624 [regexp {colseparator:} $res] \
625 [regexp {rowseparator:} $res] \
shaneh642d8b82010-07-28 16:05:34 +0000626 [regexp {stats:} $res] \
shaneha05e0c42009-11-06 03:22:54 +0000627 [regexp {width:} $res]
mistachkine0d68852014-12-11 03:12:33 +0000628} {1 1 1 1 1 1 1 1 1 1}
shaneh5fc25012009-11-11 04:17:07 +0000629do_test shell1-3.23.2 {
shanehe2aa9d72009-11-06 17:20:17 +0000630 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000631 catchcmd "test.db" ".show BAD"
drhc2ce0be2014-05-29 12:36:14 +0000632} {1 {Usage: .show}}
shaneha05e0c42009-11-06 03:22:54 +0000633
shaneh642d8b82010-07-28 16:05:34 +0000634# .stats ON|OFF Turn stats on or off
drh34784902016-02-27 17:12:36 +0000635#do_test shell1-3.23b.1 {
636# catchcmd "test.db" ".stats"
drha6e6cf22021-01-09 19:10:04 +0000637#} {1 {Usage: .stats on|off|stmt|vmstep}}
shaneh642d8b82010-07-28 16:05:34 +0000638do_test shell1-3.23b.2 {
639 catchcmd "test.db" ".stats ON"
640} {0 {}}
641do_test shell1-3.23b.3 {
642 catchcmd "test.db" ".stats OFF"
643} {0 {}}
644do_test shell1-3.23b.4 {
645 # too many arguments
646 catchcmd "test.db" ".stats OFF BAD"
drha6e6cf22021-01-09 19:10:04 +0000647} {1 {Usage: .stats ?on|off|stmt|vmstep?}}
shaneh642d8b82010-07-28 16:05:34 +0000648
drh3c49eaf2018-06-07 15:23:43 +0000649# Ticket 7be932dfa60a8a6b3b26bcf7623ec46e0a403ddb 2018-06-07
650# Adverse interaction between .stats and .eqp
651#
652do_test shell1-3.23b.5 {
653 catchcmd "test.db" [string map {"\n " "\n"} {
654 CREATE TEMP TABLE t1(x);
655 INSERT INTO t1 VALUES(1),(2);
656 .stats on
657 .eqp full
658 SELECT * FROM t1;
659 }]
660} {/1\n2\n/}
661
shaneha05e0c42009-11-06 03:22:54 +0000662# .tables ?TABLE? List names of tables
663# If TABLE specified, only list tables matching
664# LIKE pattern TABLE.
shaneh5fc25012009-11-11 04:17:07 +0000665do_test shell1-3.24.1 {
shanehca7dfda2009-12-17 21:07:54 +0000666 catchcmd "test.db" ".tables"
shaneha05e0c42009-11-06 03:22:54 +0000667} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000668do_test shell1-3.24.2 {
shanehca7dfda2009-12-17 21:07:54 +0000669 catchcmd "test.db" ".tables FOO"
shaneha05e0c42009-11-06 03:22:54 +0000670} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000671do_test shell1-3.24.3 {
shanehe2aa9d72009-11-06 17:20:17 +0000672 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000673 catchcmd "test.db" ".tables FOO BAD"
drhc2ce0be2014-05-29 12:36:14 +0000674} {0 {}}
shaneha05e0c42009-11-06 03:22:54 +0000675
676# .timeout MS Try opening locked tables for MS milliseconds
shaneh5fc25012009-11-11 04:17:07 +0000677do_test shell1-3.25.1 {
shanehca7dfda2009-12-17 21:07:54 +0000678 catchcmd "test.db" ".timeout"
drhc2ce0be2014-05-29 12:36:14 +0000679} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000680do_test shell1-3.25.2 {
shanehca7dfda2009-12-17 21:07:54 +0000681 catchcmd "test.db" ".timeout zzz"
shanehe2aa9d72009-11-06 17:20:17 +0000682 # this should be treated the same as a '0' timeout
shaneha05e0c42009-11-06 03:22:54 +0000683} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000684do_test shell1-3.25.3 {
shanehca7dfda2009-12-17 21:07:54 +0000685 catchcmd "test.db" ".timeout 1"
shaneha05e0c42009-11-06 03:22:54 +0000686} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000687do_test shell1-3.25.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000688 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000689 catchcmd "test.db" ".timeout 1 BAD"
drhc2ce0be2014-05-29 12:36:14 +0000690} {0 {}}
shaneha05e0c42009-11-06 03:22:54 +0000691
692# .width NUM NUM ... Set column widths for "column" mode
shaneh5fc25012009-11-11 04:17:07 +0000693do_test shell1-3.26.1 {
shanehca7dfda2009-12-17 21:07:54 +0000694 catchcmd "test.db" ".width"
drhc2ce0be2014-05-29 12:36:14 +0000695} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000696do_test shell1-3.26.2 {
shanehca7dfda2009-12-17 21:07:54 +0000697 catchcmd "test.db" ".width xxx"
shanehe2aa9d72009-11-06 17:20:17 +0000698 # this should be treated the same as a '0' width for col 1
shaneha05e0c42009-11-06 03:22:54 +0000699} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000700do_test shell1-3.26.3 {
shanehca7dfda2009-12-17 21:07:54 +0000701 catchcmd "test.db" ".width xxx yyy"
shanehe2aa9d72009-11-06 17:20:17 +0000702 # this should be treated the same as a '0' width for col 1 and 2
shaneha05e0c42009-11-06 03:22:54 +0000703} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000704do_test shell1-3.26.4 {
shanehca7dfda2009-12-17 21:07:54 +0000705 catchcmd "test.db" ".width 1 1"
shanehe2aa9d72009-11-06 17:20:17 +0000706 # this should be treated the same as a '1' width for col 1 and 2
shaneha05e0c42009-11-06 03:22:54 +0000707} {0 {}}
drh078b1fd2012-09-21 13:40:02 +0000708do_test shell1-3.26.5 {
drhc0605082020-06-05 00:54:27 +0000709 catchcmd "test.db" ".mode column\n.header off\n.width 10 -10\nSELECT 'abcdefg', 123456;"
drh078b1fd2012-09-21 13:40:02 +0000710 # this should be treated the same as a '1' width for col 1 and 2
711} {0 {abcdefg 123456}}
712do_test shell1-3.26.6 {
drhc0605082020-06-05 00:54:27 +0000713 catchcmd "test.db" ".mode column\n.header off\n.width -10 10\nSELECT 'abcdefg', 123456;"
drh078b1fd2012-09-21 13:40:02 +0000714 # this should be treated the same as a '1' width for col 1 and 2
715} {0 { abcdefg 123456 }}
716
shaneha05e0c42009-11-06 03:22:54 +0000717
718# .timer ON|OFF Turn the CPU timer measurement on or off
shaneh5fc25012009-11-11 04:17:07 +0000719do_test shell1-3.27.1 {
shanehca7dfda2009-12-17 21:07:54 +0000720 catchcmd "test.db" ".timer"
drhc2ce0be2014-05-29 12:36:14 +0000721} {1 {Usage: .timer on|off}}
shaneh5fc25012009-11-11 04:17:07 +0000722do_test shell1-3.27.2 {
shanehca7dfda2009-12-17 21:07:54 +0000723 catchcmd "test.db" ".timer ON"
shaneha05e0c42009-11-06 03:22:54 +0000724} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000725do_test shell1-3.27.3 {
shanehca7dfda2009-12-17 21:07:54 +0000726 catchcmd "test.db" ".timer OFF"
shaneha05e0c42009-11-06 03:22:54 +0000727} {0 {}}
shaneh5fc25012009-11-11 04:17:07 +0000728do_test shell1-3.27.4 {
shanehe2aa9d72009-11-06 17:20:17 +0000729 # too many arguments
shanehca7dfda2009-12-17 21:07:54 +0000730 catchcmd "test.db" ".timer OFF BAD"
drhc2ce0be2014-05-29 12:36:14 +0000731} {1 {Usage: .timer on|off}}
shaneha05e0c42009-11-06 03:22:54 +0000732
drh53a9d152011-04-25 18:20:04 +0000733do_test shell1-3-28.1 {
734 catchcmd test.db \
735 ".log stdout\nSELECT coalesce(sqlite_log(123,'hello'),'456');"
736} "0 {(123) hello\n456}"
737
drh078b1fd2012-09-21 13:40:02 +0000738do_test shell1-3-29.1 {
739 catchcmd "test.db" ".print this is a test"
740} {0 {this is a test}}
741
drh4c56b992013-06-27 13:26:55 +0000742# dot-command argument quoting
743do_test shell1-3-30.1 {
744 catchcmd {test.db} {.print "this\"is'a\055test" 'this\"is\\a\055test'}
745} {0 {this"is'a-test this\"is\\a\055test}}
746do_test shell1-3-31.1 {
747 catchcmd {test.db} {.print "this\nis\ta\\test" 'this\nis\ta\\test'}
748} [list 0 "this\nis\ta\\test this\\nis\\ta\\\\test"]
749
750
drh5128e852012-04-24 13:14:49 +0000751# Test the output of the ".dump" command
752#
753do_test shell1-4.1 {
drh55a1b302013-09-04 16:08:50 +0000754 db close
755 forcedelete test.db
756 sqlite3 db test.db
drh5128e852012-04-24 13:14:49 +0000757 db eval {
drh55a1b302013-09-04 16:08:50 +0000758 PRAGMA encoding=UTF16;
drh5128e852012-04-24 13:14:49 +0000759 CREATE TABLE t1(x);
mistachkin585dcb22012-12-04 00:23:43 +0000760 INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f');
mistachkin151c75a2015-04-07 21:16:40 +0000761 CREATE TABLE t3(x,y);
762 INSERT INTO t3 VALUES(1,null), (2,''), (3,1),
763 (4,2.25), (5,'hello'), (6,x'807f');
drh5128e852012-04-24 13:14:49 +0000764 }
765 catchcmd test.db {.dump}
766} {0 {PRAGMA foreign_keys=OFF;
767BEGIN TRANSACTION;
768CREATE TABLE t1(x);
drhf42d3182017-03-08 12:25:18 +0000769INSERT INTO t1 VALUES(NULL);
770INSERT INTO t1 VALUES('');
771INSERT INTO t1 VALUES(1);
772INSERT INTO t1 VALUES(2.25);
773INSERT INTO t1 VALUES('hello');
774INSERT INTO t1 VALUES(X'807f');
mistachkin151c75a2015-04-07 21:16:40 +0000775CREATE TABLE t3(x,y);
drhf42d3182017-03-08 12:25:18 +0000776INSERT INTO t3 VALUES(1,NULL);
777INSERT INTO t3 VALUES(2,'');
778INSERT INTO t3 VALUES(3,1);
779INSERT INTO t3 VALUES(4,2.25);
780INSERT INTO t3 VALUES(5,'hello');
781INSERT INTO t3 VALUES(6,X'807f');
drh5128e852012-04-24 13:14:49 +0000782COMMIT;}}
783
danb9cd86a2017-03-25 18:31:42 +0000784
785ifcapable vtab {
786
drhf42d3182017-03-08 12:25:18 +0000787# The --preserve-rowids option to .dump
788#
drhe611f142017-03-08 11:44:00 +0000789do_test shell1-4.1.1 {
790 catchcmd test.db {.dump --preserve-rowids}
791} {0 {PRAGMA foreign_keys=OFF;
792BEGIN TRANSACTION;
793CREATE TABLE t1(x);
drhf42d3182017-03-08 12:25:18 +0000794INSERT INTO t1(rowid,x) VALUES(1,NULL);
795INSERT INTO t1(rowid,x) VALUES(2,'');
796INSERT INTO t1(rowid,x) VALUES(3,1);
797INSERT INTO t1(rowid,x) VALUES(4,2.25);
798INSERT INTO t1(rowid,x) VALUES(5,'hello');
799INSERT INTO t1(rowid,x) VALUES(6,X'807f');
drhe611f142017-03-08 11:44:00 +0000800CREATE TABLE t3(x,y);
drhf42d3182017-03-08 12:25:18 +0000801INSERT INTO t3(rowid,x,y) VALUES(1,1,NULL);
802INSERT INTO t3(rowid,x,y) VALUES(2,2,'');
803INSERT INTO t3(rowid,x,y) VALUES(3,3,1);
804INSERT INTO t3(rowid,x,y) VALUES(4,4,2.25);
805INSERT INTO t3(rowid,x,y) VALUES(5,5,'hello');
806INSERT INTO t3(rowid,x,y) VALUES(6,6,X'807f');
drhe611f142017-03-08 11:44:00 +0000807COMMIT;}}
808
drhf42d3182017-03-08 12:25:18 +0000809# If the table contains an INTEGER PRIMARY KEY, do not record a separate
810# rowid column in the output.
811#
drhe611f142017-03-08 11:44:00 +0000812do_test shell1-4.1.2 {
813 db close
814 forcedelete test2.db
815 sqlite3 db test2.db
816 db eval {
817 CREATE TABLE t1(x INTEGER PRIMARY KEY, y);
818 INSERT INTO t1 VALUES(1,null), (2,''), (3,1),
819 (4,2.25), (5,'hello'), (6,x'807f');
820 }
821 catchcmd test2.db {.dump --preserve-rowids}
822} {0 {PRAGMA foreign_keys=OFF;
823BEGIN TRANSACTION;
824CREATE TABLE t1(x INTEGER PRIMARY KEY, y);
drhf42d3182017-03-08 12:25:18 +0000825INSERT INTO t1 VALUES(1,NULL);
826INSERT INTO t1 VALUES(2,'');
827INSERT INTO t1 VALUES(3,1);
828INSERT INTO t1 VALUES(4,2.25);
829INSERT INTO t1 VALUES(5,'hello');
830INSERT INTO t1 VALUES(6,X'807f');
drhe611f142017-03-08 11:44:00 +0000831COMMIT;}}
832
drhf42d3182017-03-08 12:25:18 +0000833# Verify that the table named [table] is correctly quoted and that
834# an INTEGER PRIMARY KEY DESC is not an alias for the rowid.
835#
836do_test shell1-4.1.3 {
837 db close
838 forcedelete test2.db
839 sqlite3 db test2.db
840 db eval {
841 CREATE TABLE [table](x INTEGER PRIMARY KEY DESC, y);
842 INSERT INTO [table] VALUES(1,null), (12,''), (23,1),
843 (34,2.25), (45,'hello'), (56,x'807f');
844 }
845 catchcmd test2.db {.dump --preserve-rowids}
846} {0 {PRAGMA foreign_keys=OFF;
847BEGIN TRANSACTION;
848CREATE TABLE [table](x INTEGER PRIMARY KEY DESC, y);
849INSERT INTO "table"(rowid,x,y) VALUES(1,1,NULL);
850INSERT INTO "table"(rowid,x,y) VALUES(2,12,'');
851INSERT INTO "table"(rowid,x,y) VALUES(3,23,1);
852INSERT INTO "table"(rowid,x,y) VALUES(4,34,2.25);
853INSERT INTO "table"(rowid,x,y) VALUES(5,45,'hello');
854INSERT INTO "table"(rowid,x,y) VALUES(6,56,X'807f');
855COMMIT;}}
856
857# Do not record rowids for a WITHOUT ROWID table. Also check correct quoting
858# of table names that contain odd characters.
859#
860do_test shell1-4.1.4 {
861 db close
862 forcedelete test2.db
863 sqlite3 db test2.db
864 db eval {
865 CREATE TABLE [ta<>ble](x INTEGER PRIMARY KEY, y) WITHOUT ROWID;
866 INSERT INTO [ta<>ble] VALUES(1,null), (12,''), (23,1),
867 (34,2.25), (45,'hello'), (56,x'807f');
868 }
869 catchcmd test2.db {.dump --preserve-rowids}
870} {0 {PRAGMA foreign_keys=OFF;
871BEGIN TRANSACTION;
872CREATE TABLE [ta<>ble](x INTEGER PRIMARY KEY, y) WITHOUT ROWID;
873INSERT INTO "ta<>ble" VALUES(1,NULL);
874INSERT INTO "ta<>ble" VALUES(12,'');
875INSERT INTO "ta<>ble" VALUES(23,1);
876INSERT INTO "ta<>ble" VALUES(34,2.25);
877INSERT INTO "ta<>ble" VALUES(45,'hello');
878INSERT INTO "ta<>ble" VALUES(56,X'807f');
879COMMIT;}}
880
881# Do not record rowids if the rowid is inaccessible
882#
883do_test shell1-4.1.5 {
884 db close
885 forcedelete test2.db
886 sqlite3 db test2.db
887 db eval {
888 CREATE TABLE t1(_ROWID_,rowid,oid);
889 INSERT INTO t1 VALUES(1,null,'alpha'), (12,'',99), (23,1,x'b0b1b2');
890 }
891 catchcmd test2.db {.dump --preserve-rowids}
892} {0 {PRAGMA foreign_keys=OFF;
893BEGIN TRANSACTION;
894CREATE TABLE t1(_ROWID_,rowid,oid);
895INSERT INTO t1 VALUES(1,NULL,'alpha');
896INSERT INTO t1 VALUES(12,'',99);
897INSERT INTO t1 VALUES(23,1,X'b0b1b2');
898COMMIT;}}
drhe611f142017-03-08 11:44:00 +0000899
danb9cd86a2017-03-25 18:31:42 +0000900} else {
901
902do_test shell1-4.1.6 {
903 db close
904 forcedelete test2.db
905 sqlite3 db test2.db
906 db eval {
907 CREATE TABLE t1(x INTEGER PRIMARY KEY, y);
908 INSERT INTO t1 VALUES(1,null), (2,''), (3,1),
909 (4,2.25), (5,'hello'), (6,x'807f');
910 }
911 catchcmd test2.db {.dump --preserve-rowids}
912} {1 {The --preserve-rowids option is not compatible with SQLITE_OMIT_VIRTUALTABLE}}
913
914}
915
916
drh5128e852012-04-24 13:14:49 +0000917# Test the output of ".mode insert"
918#
mistachkin151c75a2015-04-07 21:16:40 +0000919do_test shell1-4.2.1 {
drh5128e852012-04-24 13:14:49 +0000920 catchcmd test.db ".mode insert t1\nselect * from t1;"
921} {0 {INSERT INTO t1 VALUES(NULL);
mistachkin585dcb22012-12-04 00:23:43 +0000922INSERT INTO t1 VALUES('');
drh5128e852012-04-24 13:14:49 +0000923INSERT INTO t1 VALUES(1);
924INSERT INTO t1 VALUES(2.25);
925INSERT INTO t1 VALUES('hello');
926INSERT INTO t1 VALUES(X'807f');}}
927
mistachkin151c75a2015-04-07 21:16:40 +0000928# Test the output of ".mode insert" with headers
929#
930do_test shell1-4.2.2 {
931 catchcmd test.db ".mode insert t1\n.headers on\nselect * from t1;"
932} {0 {INSERT INTO t1(x) VALUES(NULL);
933INSERT INTO t1(x) VALUES('');
934INSERT INTO t1(x) VALUES(1);
935INSERT INTO t1(x) VALUES(2.25);
936INSERT INTO t1(x) VALUES('hello');
937INSERT INTO t1(x) VALUES(X'807f');}}
938
939# Test the output of ".mode insert"
940#
941do_test shell1-4.2.3 {
942 catchcmd test.db ".mode insert t3\nselect * from t3;"
943} {0 {INSERT INTO t3 VALUES(1,NULL);
944INSERT INTO t3 VALUES(2,'');
945INSERT INTO t3 VALUES(3,1);
946INSERT INTO t3 VALUES(4,2.25);
947INSERT INTO t3 VALUES(5,'hello');
948INSERT INTO t3 VALUES(6,X'807f');}}
949
950# Test the output of ".mode insert" with headers
951#
mistachkincc445402015-04-07 21:17:53 +0000952do_test shell1-4.2.4 {
mistachkin151c75a2015-04-07 21:16:40 +0000953 catchcmd test.db ".mode insert t3\n.headers on\nselect * from t3;"
954} {0 {INSERT INTO t3(x,y) VALUES(1,NULL);
955INSERT INTO t3(x,y) VALUES(2,'');
956INSERT INTO t3(x,y) VALUES(3,1);
957INSERT INTO t3(x,y) VALUES(4,2.25);
958INSERT INTO t3(x,y) VALUES(5,'hello');
959INSERT INTO t3(x,y) VALUES(6,X'807f');}}
960
mistachkin585dcb22012-12-04 00:23:43 +0000961# Test the output of ".mode tcl"
962#
963do_test shell1-4.3 {
drh55a1b302013-09-04 16:08:50 +0000964 db close
965 forcedelete test.db
966 sqlite3 db test.db
967 db eval {
968 PRAGMA encoding=UTF8;
969 CREATE TABLE t1(x);
970 INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f');
971 }
mistachkin585dcb22012-12-04 00:23:43 +0000972 catchcmd test.db ".mode tcl\nselect * from t1;"
973} {0 {""
974""
975"1"
976"2.25"
977"hello"
978"\200\177"}}
979
980# Test the output of ".mode tcl" with multiple columns
981#
982do_test shell1-4.4 {
983 db eval {
984 CREATE TABLE t2(x,y);
985 INSERT INTO t2 VALUES(null, ''), (1, 2.25), ('hello', x'807f');
986 }
987 catchcmd test.db ".mode tcl\nselect * from t2;"
988} {0 {"" ""
989"1" "2.25"
990"hello" "\200\177"}}
991
992# Test the output of ".mode tcl" with ".nullvalue"
993#
994do_test shell1-4.5 {
995 catchcmd test.db ".mode tcl\n.nullvalue NULL\nselect * from t2;"
996} {0 {"NULL" ""
997"1" "2.25"
998"hello" "\200\177"}}
999
1000# Test the output of ".mode tcl" with Tcl reserved characters
1001#
1002do_test shell1-4.6 {
1003 db eval {
1004 CREATE TABLE tcl1(x);
1005 INSERT INTO tcl1 VALUES('"'), ('['), (']'), ('\{'), ('\}'), (';'), ('$');
1006 }
1007 foreach {x y} [catchcmd test.db ".mode tcl\nselect * from tcl1;"] break
1008 list $x $y [llength $y]
1009} {0 {"\""
1010"["
1011"]"
1012"\\{"
1013"\\}"
1014";"
1015"$"} 7}
drh5128e852012-04-24 13:14:49 +00001016
larrybrd0a9a462022-01-03 19:33:44 +00001017# Test the output of ".mode quote"
1018#
1019do_test shell1-4.7 {
1020 catchcmd test.db ".mode quote\nselect x'0123456789ABCDEF';"
1021} {0 X'0123456789abcdef'}
1022
mistachkinf21979d2015-01-18 05:35:01 +00001023# Test using arbitrary byte data with the shell via standard input/output.
1024#
1025do_test shell1-5.0 {
1026 #
1027 # NOTE: Skip NUL byte because it appears to be incompatible with command
1028 # shell argument parsing.
1029 #
1030 for {set i 1} {$i < 256} {incr i} {
1031 #
mistachkin46a6b992015-01-18 09:02:57 +00001032 # NOTE: Due to how the Tcl [exec] command works (i.e. where it treats
1033 # command channels opened for it as textual ones), the carriage
1034 # return character (and on Windows, the end-of-file character)
1035 # cannot be used here.
mistachkinf21979d2015-01-18 05:35:01 +00001036 #
mistachkin46a6b992015-01-18 09:02:57 +00001037 if {$i==0x0D || ($tcl_platform(platform)=="windows" && $i==0x1A)} {
mistachkinf21979d2015-01-18 05:35:01 +00001038 continue
1039 }
drh158931a2019-04-12 16:25:42 +00001040 # Tcl 8.7 maps 0x80 through 0x9f into valid UTF8. So skip those tests.
1041 if {$i>=0x80 && $i<=0x9f} continue
drh01725682016-07-25 14:20:01 +00001042 if {$i>=0xE0 && $tcl_platform(os)=="OpenBSD"} continue
mistachkinbe56ad32016-07-29 04:12:18 +00001043 if {$i>=0xE0 && $i<=0xEF && $tcl_platform(os)=="Linux"} continue
mistachkinf21979d2015-01-18 05:35:01 +00001044 set hex [format %02X $i]
1045 set char [subst \\x$hex]; set oldChar $char
mistachkin0acee512015-01-19 21:11:31 +00001046 set escapes [list]
1047 if {$tcl_platform(platform)=="windows"} {
1048 #
1049 # NOTE: On Windows, we need to escape all the whitespace characters,
1050 # the alarm (\a) character, and those with special meaning to
1051 # the SQLite shell itself.
1052 #
1053 set escapes [list \
1054 \a \\a \b \\b \t \\t \n \\n \v \\v \f \\f \r \\r \
1055 " " "\" \"" \" \\\" ' \"'\" \\ \\\\]
1056 } else {
1057 #
1058 # NOTE: On Unix, we need to escape most of the whitespace characters
1059 # and those with special meaning to the SQLite shell itself.
1060 # The alarm (\a), backspace (\b), and carriage-return (\r)
1061 # characters do not appear to require escaping on Unix. For
1062 # the alarm and backspace characters, this is probably due to
1063 # differences in the command shell. For the carriage-return,
1064 # it is probably due to differences in how Tcl handles command
1065 # channel end-of-line translations.
1066 #
1067 set escapes [list \
1068 \t \\t \n \\n \v \\v \f \\f \
1069 " " "\" \"" \" \\\" ' \"'\" \\ \\\\]
1070 }
1071 set char [string map $escapes $char]
mistachkinbfefa4c2015-01-19 21:27:46 +00001072 set x [catchcmdex test.db ".print $char\n"]
mistachkinf21979d2015-01-18 05:35:01 +00001073 set code [lindex $x 0]
1074 set res [lindex $x 1]
1075 if {$code ne "0"} {
1076 error "failed with error: $res"
1077 }
1078 if {$res ne "$oldChar\n"} {
mistachkin48dcf2b2016-04-04 17:59:37 +00001079 if {[llength $res] > 0} {
1080 set got [format %02X [scan $res %c]]
1081 } else {
1082 set got <empty>
1083 }
1084 error "failed with byte $hex mismatch, got $got"
mistachkinf21979d2015-01-18 05:35:01 +00001085 }
1086 }
1087} {}
1088
drh697c9ea2016-05-16 11:55:09 +00001089# These test cases do not work on MinGW
1090if 0 {
1091
mistachkin49e11252016-04-04 15:47:46 +00001092# The string used here is the word "test" in Chinese.
1093# In UTF-8, it is encoded as: \xE6\xB5\x8B\xE8\xAF\x95
1094set test \u6D4B\u8BD5
1095
mistachkin1fe36bb2016-04-04 02:16:44 +00001096do_test shell1-6.0 {
mistachkin49e11252016-04-04 15:47:46 +00001097 set fileName $test; append fileName .db
1098 catch {forcedelete $fileName}
mistachkin1fe36bb2016-04-04 02:16:44 +00001099 set x [catchcmdex $fileName "CREATE TABLE t1(x);\n.schema\n"]
1100 set code [lindex $x 0]
1101 set res [string trim [lindex $x 1]]
1102 if {$code ne "0"} {
1103 error "failed with error: $res"
1104 }
1105 if {$res ne "CREATE TABLE t1(x);"} {
1106 error "failed with mismatch: $res"
1107 }
1108 if {![file exists $fileName]} {
mistachkin1810f222016-04-04 02:33:34 +00001109 error "file \"$fileName\" (Unicode) does not exist"
mistachkin1fe36bb2016-04-04 02:16:44 +00001110 }
1111 forcedelete $fileName
1112} {}
1113
mistachkin49e11252016-04-04 15:47:46 +00001114do_test shell1-6.1 {
1115 catch {forcedelete test3.db}
1116 set x [catchcmdex test3.db \
1117 "CREATE TABLE [encoding convertto utf-8 $test](x);\n.schema\n"]
1118 set code [lindex $x 0]
1119 set res [string trim [lindex $x 1]]
1120 if {$code ne "0"} {
1121 error "failed with error: $res"
1122 }
1123 if {$res ne "CREATE TABLE ${test}(x);"} {
1124 error "failed with mismatch: $res"
1125 }
1126 forcedelete test3.db
1127} {}
drh697c9ea2016-05-16 11:55:09 +00001128}
mistachkin49e11252016-04-04 15:47:46 +00001129
mistachkin9d107262018-03-23 14:24:34 +00001130db close
1131forcedelete test.db test.db-journal test.db-wal
1132sqlite3 db test.db
1133
dan07f119e2018-03-24 15:08:48 +00001134# The shell tool ".schema" command uses virtual table "pragma_database_list"
1135#
1136ifcapable vtab {
1137
mistachkin9d107262018-03-23 14:24:34 +00001138do_test shell1-7.1.1 {
1139 db eval {
1140 CREATE TABLE Z (x TEXT PRIMARY KEY);
1141 CREATE TABLE _ (x TEXT PRIMARY KEY);
1142 CREATE TABLE YY (x TEXT PRIMARY KEY);
1143 CREATE TABLE __ (x TEXT PRIMARY KEY);
1144 CREATE TABLE WWW (x TEXT PRIMARY KEY);
1145 CREATE TABLE ___ (x TEXT PRIMARY KEY);
1146 }
1147} {}
1148do_test shell1-7.1.2 {
1149 catchcmd "test.db" ".schema _"
1150} {0 {CREATE TABLE Z (x TEXT PRIMARY KEY);
1151CREATE TABLE _ (x TEXT PRIMARY KEY);}}
1152do_test shell1-7.1.3 {
1153 catchcmd "test.db" ".schema \\\\_"
1154} {0 {CREATE TABLE _ (x TEXT PRIMARY KEY);}}
1155do_test shell1-7.1.4 {
1156 catchcmd "test.db" ".schema __"
1157} {0 {CREATE TABLE YY (x TEXT PRIMARY KEY);
1158CREATE TABLE __ (x TEXT PRIMARY KEY);}}
1159do_test shell1-7.1.5 {
1160 catchcmd "test.db" ".schema \\\\_\\\\_"
1161} {0 {CREATE TABLE __ (x TEXT PRIMARY KEY);}}
1162do_test shell1-7.1.6 {
1163 catchcmd "test.db" ".schema ___"
1164} {0 {CREATE TABLE WWW (x TEXT PRIMARY KEY);
1165CREATE TABLE ___ (x TEXT PRIMARY KEY);}}
1166do_test shell1-7.1.7 {
1167 catchcmd "test.db" ".schema \\\\_\\\\_\\\\_"
1168} {0 {CREATE TABLE ___ (x TEXT PRIMARY KEY);}}
1169
dan07f119e2018-03-24 15:08:48 +00001170}
1171
drh4dfdb862020-08-11 18:17:04 +00001172# Test case for the ieee754 and decimal extensions in the shell.
1173# See the "floatingpoint.html" file in the documentation for more
1174# information.
1175#
1176do_test shell1-8.1 {
1177 catchcmd ":memory:" {
1178 -- The pow2 table will hold all the necessary powers of two.
1179 CREATE TABLE pow2(x INTEGER PRIMARY KEY, v TEXT);
1180 WITH RECURSIVE c(x,v) AS (
1181 VALUES(0,'1')
1182 UNION ALL
1183 SELECT x+1, decimal_mul(v,'2') FROM c WHERE x+1<=971
1184 ) INSERT INTO pow2(x,v) SELECT x, v FROM c;
1185 WITH RECURSIVE c(x,v) AS (
1186 VALUES(-1,'0.5')
1187 UNION ALL
1188 SELECT x-1, decimal_mul(v,'0.5') FROM c WHERE x-1>=-1075
1189 ) INSERT INTO pow2(x,v) SELECT x, v FROM c;
1190
1191 -- This query finds the decimal representation of each value in the "c" table.
1192 WITH c(n) AS (VALUES(47.49))
1193 ----XXXXX----------- Replace with whatever you want
1194 SELECT decimal_mul(ieee754_mantissa(c.n),pow2.v)
1195 FROM pow2, c WHERE pow2.x=ieee754_exponent(c.n);
1196 }
1197} {0 47.49000000000000198951966012828052043914794921875}
1198do_test shell1-8.2 {
1199 catchcmd :memory: {
1200.mode box
1201SELECT ieee754(47.49) AS x;
1202 }
1203} {0 {┌───────────────────────────────┐
1204│ x │
1205├───────────────────────────────┤
1206│ ieee754(6683623321994527,-47) │
1207└───────────────────────────────┘}}
1208do_test shell1-8.3 {
1209 catchcmd ":memory: --box" {
1210 select ieee754(6683623321994527,-47) as x;
1211 }
1212} {0 {┌───────┐
1213│ x │
1214├───────┤
1215│ 47.49 │
1216└───────┘}}
1217do_test shell1-8.4 {
1218 catchcmd ":memory: --table" {SELECT ieee754_mantissa(47.49) AS M, ieee754_exponent(47.49) AS E;}
1219} {0 {+------------------+-----+
1220| M | E |
1221+------------------+-----+
1222| 6683623321994527 | -47 |
1223+------------------+-----+}}
1224
larrybrd797d6b2021-10-03 22:03:59 +00001225#----------------------------------------------------------------------------
1226# Test cases shell1-9.*: Basic test that "dot" commands and SQL intermix ok.
1227#
1228do_test shell1-9.1 {
1229 catchcmd :memory: {
1230.mode csv
1231/*
1232x */ select 1,2; --x
1233 -- .nada
1234;
1235.mode csv
1236--x
1237select 2,1; select 3,4;
1238}
1239} {0 {1,2
12402,1
12413,4}}
1242
drh8df91852012-04-24 12:46:05 +00001243finish_test