shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 1 | # 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 | # |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 14 | # |
| 15 | |
| 16 | # Test plan: |
| 17 | # |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 18 | # 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. |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 21 | # |
drh | 8df9185 | 2012-04-24 12:46:05 +0000 | [diff] [blame] | 22 | set testdir [file dirname $argv0] |
| 23 | source $testdir/tester.tcl |
dan | 089555c | 2016-03-15 09:55:44 +0000 | [diff] [blame] | 24 | set CLI [test_find_cli] |
drh | 8df9185 | 2012-04-24 12:46:05 +0000 | [diff] [blame] | 25 | db close |
| 26 | forcedelete test.db test.db-journal test.db-wal |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 27 | sqlite3 db test.db |
| 28 | |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 29 | #---------------------------------------------------------------------------- |
| 30 | # Test cases shell1-1.*: Basic command line option handling. |
| 31 | # |
| 32 | |
| 33 | # invalid option |
| 34 | do_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} |
drh | ac5649a | 2014-11-28 13:35:03 +0000 | [diff] [blame] | 40 | do_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} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 46 | # error on extra options |
| 47 | do_test shell1-1.1.2 { |
drh | 60c4249 | 2016-03-26 15:36:36 +0000 | [diff] [blame] | 48 | catchcmd "test.db \"select+3\" \"select+4\"" "" |
drh | ac5649a | 2014-11-28 13:35:03 +0000 | [diff] [blame] | 49 | } {0 {3 |
| 50 | 4}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 51 | # error on extra options |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 52 | do_test shell1-1.1.3 { |
drh | ac5649a | 2014-11-28 13:35:03 +0000 | [diff] [blame] | 53 | catchcmd "test.db FOO test.db BAD" ".quit" |
| 54 | } {1 {Error: near "FOO": syntax error}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 55 | |
| 56 | # -help |
| 57 | do_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 |
drh | b7c46aa | 2020-11-25 13:59:47 +0000 | [diff] [blame] | 67 | forcedelete FOO |
| 68 | set out [open FOO w] |
| 69 | puts $out "" |
| 70 | close $out |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 71 | do_test shell1-1.3.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 72 | catchcmd "-init FOO test.db" "" |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 73 | } {0 {}} |
| 74 | do_test shell1-1.3.2 { |
drh | ac5649a | 2014-11-28 13:35:03 +0000 | [diff] [blame] | 75 | catchcmd "-init FOO test.db .quit BAD" "" |
| 76 | } {0 {}} |
| 77 | do_test shell1-1.3.3 { |
| 78 | catchcmd "-init FOO test.db BAD .quit" "" |
| 79 | } {1 {Error: near "BAD": syntax error}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 80 | |
| 81 | # -echo print commands before execution |
| 82 | do_test shell1-1.4.1 { |
mistachkin | 1fe36bb | 2016-04-04 02:16:44 +0000 | [diff] [blame] | 83 | catchcmd "-echo test.db" "" |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 84 | } {0 {}} |
| 85 | |
| 86 | # -[no]header turn headers on or off |
| 87 | do_test shell1-1.5.1 { |
mistachkin | 1fe36bb | 2016-04-04 02:16:44 +0000 | [diff] [blame] | 88 | catchcmd "-header test.db" "" |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 89 | } {0 {}} |
| 90 | do_test shell1-1.5.2 { |
mistachkin | 1fe36bb | 2016-04-04 02:16:44 +0000 | [diff] [blame] | 91 | catchcmd "-noheader test.db" "" |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 92 | } {0 {}} |
| 93 | |
| 94 | # -bail stop after hitting an error |
| 95 | do_test shell1-1.6.1 { |
mistachkin | 1fe36bb | 2016-04-04 02:16:44 +0000 | [diff] [blame] | 96 | catchcmd "-bail test.db" "" |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 97 | } {0 {}} |
| 98 | |
| 99 | # -interactive force interactive I/O |
| 100 | do_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] \ |
drh | 39a3088 | 2014-02-11 16:22:18 +0000 | [diff] [blame] | 105 | [regexp {Enter ".help" for usage hints} $res] |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 106 | } {0 1 1} |
| 107 | |
| 108 | # -batch force batch I/O |
| 109 | do_test shell1-1.8.1 { |
mistachkin | 1fe36bb | 2016-04-04 02:16:44 +0000 | [diff] [blame] | 110 | catchcmd "-batch test.db" "" |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 111 | } {0 {}} |
| 112 | |
| 113 | # -column set output mode to 'column' |
| 114 | do_test shell1-1.9.1 { |
mistachkin | 1fe36bb | 2016-04-04 02:16:44 +0000 | [diff] [blame] | 115 | catchcmd "-column test.db" "" |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 116 | } {0 {}} |
| 117 | |
| 118 | # -csv set output mode to 'csv' |
| 119 | do_test shell1-1.10.1 { |
mistachkin | 1fe36bb | 2016-04-04 02:16:44 +0000 | [diff] [blame] | 120 | catchcmd "-csv test.db" "" |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 121 | } {0 {}} |
| 122 | |
| 123 | # -html set output mode to HTML |
| 124 | do_test shell1-1.11.1 { |
mistachkin | 1fe36bb | 2016-04-04 02:16:44 +0000 | [diff] [blame] | 125 | catchcmd "-html test.db" "" |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 126 | } {0 {}} |
| 127 | |
| 128 | # -line set output mode to 'line' |
| 129 | do_test shell1-1.12.1 { |
mistachkin | 1fe36bb | 2016-04-04 02:16:44 +0000 | [diff] [blame] | 130 | catchcmd "-line test.db" "" |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 131 | } {0 {}} |
| 132 | |
| 133 | # -list set output mode to 'list' |
| 134 | do_test shell1-1.13.1 { |
mistachkin | 1fe36bb | 2016-04-04 02:16:44 +0000 | [diff] [blame] | 135 | catchcmd "-list test.db" "" |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 136 | } {0 {}} |
| 137 | |
| 138 | # -separator 'x' set output field separator (|) |
| 139 | do_test shell1-1.14.1 { |
mistachkin | 1fe36bb | 2016-04-04 02:16:44 +0000 | [diff] [blame] | 140 | catchcmd "-separator 'x' test.db" "" |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 141 | } {0 {}} |
| 142 | do_test shell1-1.14.2 { |
mistachkin | 1fe36bb | 2016-04-04 02:16:44 +0000 | [diff] [blame] | 143 | catchcmd "-separator x test.db" "" |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 144 | } {0 {}} |
| 145 | do_test shell1-1.14.3 { |
| 146 | set res [catchcmd "-separator" ""] |
| 147 | set rc [lindex $res 0] |
| 148 | list $rc \ |
drh | 98d312f | 2012-10-25 15:23:14 +0000 | [diff] [blame] | 149 | [regexp {Error: missing argument to -separator} $res] |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 150 | } {1 1} |
| 151 | |
shaneh | 642d8b8 | 2010-07-28 16:05:34 +0000 | [diff] [blame] | 152 | # -stats print memory stats before each finalize |
| 153 | do_test shell1-1.14b.1 { |
mistachkin | 1fe36bb | 2016-04-04 02:16:44 +0000 | [diff] [blame] | 154 | catchcmd "-stats test.db" "" |
shaneh | 642d8b8 | 2010-07-28 16:05:34 +0000 | [diff] [blame] | 155 | } {0 {}} |
| 156 | |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 157 | # -nullvalue 'text' set text string for NULL values |
| 158 | do_test shell1-1.15.1 { |
| 159 | catchcmd "-nullvalue 'x' test.db" "" |
| 160 | } {0 {}} |
| 161 | do_test shell1-1.15.2 { |
| 162 | catchcmd "-nullvalue x test.db" "" |
| 163 | } {0 {}} |
| 164 | do_test shell1-1.15.3 { |
| 165 | set res [catchcmd "-nullvalue" ""] |
| 166 | set rc [lindex $res 0] |
| 167 | list $rc \ |
drh | 98d312f | 2012-10-25 15:23:14 +0000 | [diff] [blame] | 168 | [regexp {Error: missing argument to -nullvalue} $res] |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 169 | } {1 1} |
| 170 | |
| 171 | # -version show SQLite version |
| 172 | do_test shell1-1.16.1 { |
drh | 9fd301b | 2011-06-03 13:28:22 +0000 | [diff] [blame] | 173 | set x [catchcmd "-version test.db" ""] |
drh | b24c61a | 2012-05-21 22:45:35 +0000 | [diff] [blame] | 174 | } {/3.[0-9.]+ 20\d\d-[01]\d-\d\d \d\d:\d\d:\d\d [0-9a-f]+/} |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 175 | |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 176 | #---------------------------------------------------------------------------- |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 177 | # Test cases shell1-2.*: Basic "dot" command token parsing. |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 178 | # |
| 179 | |
| 180 | # check first token handling |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 181 | do_test shell1-2.1.1 { |
mistachkin | 1fe36bb | 2016-04-04 02:16:44 +0000 | [diff] [blame] | 182 | catchcmd "test.db" ".foo" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 183 | } {1 {Error: unknown command or invalid arguments: "foo". Enter ".help" for help}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 184 | do_test shell1-2.1.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 185 | catchcmd "test.db" ".\"foo OFF\"" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 186 | } {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 187 | do_test shell1-2.1.3 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 188 | catchcmd "test.db" ".\'foo OFF\'" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 189 | } {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}} |
| 190 | |
| 191 | # unbalanced quotes |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 192 | do_test shell1-2.2.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 193 | catchcmd "test.db" ".\"foo OFF" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 194 | } {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 195 | do_test shell1-2.2.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 196 | catchcmd "test.db" ".\'foo OFF" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 197 | } {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 198 | do_test shell1-2.2.3 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 199 | catchcmd "test.db" ".explain \"OFF" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 200 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 201 | do_test shell1-2.2.4 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 202 | catchcmd "test.db" ".explain \'OFF" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 203 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 204 | do_test shell1-2.2.5 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 205 | catchcmd "test.db" ".mode \"insert FOO" |
drh | 0908e38 | 2020-06-04 18:05:39 +0000 | [diff] [blame] | 206 | } {1 {Error: mode should be one of: ascii box column csv html insert json line list markdown quote table tabs tcl}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 207 | do_test shell1-2.2.6 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 208 | catchcmd "test.db" ".mode \'insert FOO" |
drh | 0908e38 | 2020-06-04 18:05:39 +0000 | [diff] [blame] | 209 | } {1 {Error: mode should be one of: ascii box column csv html insert json line list markdown quote table tabs tcl}} |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 210 | |
| 211 | # check multiple tokens, and quoted tokens |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 212 | do_test shell1-2.3.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 213 | catchcmd "test.db" ".explain 1" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 214 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 215 | do_test shell1-2.3.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 216 | catchcmd "test.db" ".explain on" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 217 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 218 | do_test shell1-2.3.3 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 219 | catchcmd "test.db" ".explain \"1 2 3\"" |
drh | 173ba09 | 2013-01-28 18:18:26 +0000 | [diff] [blame] | 220 | } {1 {ERROR: Not a boolean value: "1 2 3". Assuming "no".}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 221 | do_test shell1-2.3.4 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 222 | catchcmd "test.db" ".explain \"OFF\"" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 223 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 224 | do_test shell1-2.3.5 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 225 | catchcmd "test.db" ".\'explain\' \'OFF\'" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 226 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 227 | do_test shell1-2.3.6 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 228 | catchcmd "test.db" ".explain \'OFF\'" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 229 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 230 | do_test shell1-2.3.7 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 231 | catchcmd "test.db" ".\'explain\' \'OFF\'" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 232 | } {0 {}} |
| 233 | |
| 234 | # check quoted args are unquoted |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 235 | do_test shell1-2.4.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 236 | catchcmd "test.db" ".mode FOO" |
drh | 0908e38 | 2020-06-04 18:05:39 +0000 | [diff] [blame] | 237 | } {1 {Error: mode should be one of: ascii box column csv html insert json line list markdown quote table tabs tcl}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 238 | do_test shell1-2.4.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 239 | catchcmd "test.db" ".mode csv" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 240 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 241 | do_test shell1-2.4.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 242 | catchcmd "test.db" ".mode \"csv\"" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 243 | } {0 {}} |
| 244 | |
| 245 | |
| 246 | #---------------------------------------------------------------------------- |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 247 | # Test cases shell1-3.*: Basic test that "dot" command can be called. |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 248 | # |
| 249 | |
| 250 | # .backup ?DB? FILE Backup DB (default "main") to FILE |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 251 | do_test shell1-3.1.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 252 | catchcmd "test.db" ".backup" |
drh | bc46f02 | 2013-01-23 18:53:23 +0000 | [diff] [blame] | 253 | } {1 {missing FILENAME argument on .backup}} |
drh | f82d78e | 2020-11-25 14:50:42 +0000 | [diff] [blame] | 254 | forcedelete FOO |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 255 | do_test shell1-3.1.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 256 | catchcmd "test.db" ".backup FOO" |
| 257 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 258 | do_test shell1-3.1.3 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 259 | catchcmd "test.db" ".backup FOO BAR" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 260 | } {1 {Error: unknown database FOO}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 261 | do_test shell1-3.1.4 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 262 | # too many arguments |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 263 | catchcmd "test.db" ".backup FOO BAR BAD" |
drh | 4d34282 | 2018-12-10 00:41:28 +0000 | [diff] [blame] | 264 | } {1 {Usage: .backup ?DB? ?OPTIONS? FILENAME}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 265 | |
| 266 | # .bail ON|OFF Stop after hitting an error. Default OFF |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 267 | do_test shell1-3.2.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 268 | catchcmd "test.db" ".bail" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 269 | } {1 {Usage: .bail on|off}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 270 | do_test shell1-3.2.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 271 | catchcmd "test.db" ".bail ON" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 272 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 273 | do_test shell1-3.2.3 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 274 | catchcmd "test.db" ".bail OFF" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 275 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 276 | do_test shell1-3.2.4 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 277 | # too many arguments |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 278 | catchcmd "test.db" ".bail OFF BAD" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 279 | } {1 {Usage: .bail on|off}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 280 | |
drh | c595419 | 2016-12-27 02:43:47 +0000 | [diff] [blame] | 281 | ifcapable vtab { |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 282 | # .databases List names and files of attached databases |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 283 | do_test shell1-3.3.1 { |
drh | eaa544d | 2016-03-26 14:41:13 +0000 | [diff] [blame] | 284 | catchcmd "-csv test.db" ".databases" |
drh | 15707ac | 2016-03-26 13:26:35 +0000 | [diff] [blame] | 285 | } "/0.+main.+[string map {/ ".{1,2}"} [string range [get_pwd] 0 10]].*/" |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 286 | do_test shell1-3.3.2 { |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 287 | # extra arguments ignored |
drh | eaa544d | 2016-03-26 14:41:13 +0000 | [diff] [blame] | 288 | catchcmd "test.db" ".databases BAD" |
drh | 15707ac | 2016-03-26 13:26:35 +0000 | [diff] [blame] | 289 | } "/0.+main.+[string map {/ ".{1,2}"} [string range [get_pwd] 0 10]].*/" |
drh | c595419 | 2016-12-27 02:43:47 +0000 | [diff] [blame] | 290 | } |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 291 | |
| 292 | # .dump ?TABLE? ... Dump the database in an SQL text format |
| 293 | # If TABLE specified, only dump tables matching |
| 294 | # LIKE pattern TABLE. |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 295 | do_test shell1-3.4.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 296 | set res [catchcmd "test.db" ".dump"] |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 297 | list [regexp {BEGIN TRANSACTION;} $res] \ |
| 298 | [regexp {COMMIT;} $res] |
| 299 | } {1 1} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 300 | do_test shell1-3.4.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 301 | set res [catchcmd "test.db" ".dump FOO"] |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 302 | list [regexp {BEGIN TRANSACTION;} $res] \ |
| 303 | [regexp {COMMIT;} $res] |
| 304 | } {1 1} |
drh | 8e9297f | 2020-03-25 12:50:13 +0000 | [diff] [blame] | 305 | # 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?}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 310 | |
| 311 | # .echo ON|OFF Turn command echo on or off |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 312 | do_test shell1-3.5.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 313 | catchcmd "test.db" ".echo" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 314 | } {1 {Usage: .echo on|off}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 315 | do_test shell1-3.5.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 316 | catchcmd "test.db" ".echo ON" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 317 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 318 | do_test shell1-3.5.3 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 319 | catchcmd "test.db" ".echo OFF" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 320 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 321 | do_test shell1-3.5.4 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 322 | # too many arguments |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 323 | catchcmd "test.db" ".echo OFF BAD" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 324 | } {1 {Usage: .echo on|off}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 325 | |
| 326 | # .exit Exit this program |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 327 | do_test shell1-3.6.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 328 | catchcmd "test.db" ".exit" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 329 | } {0 {}} |
| 330 | |
| 331 | # .explain ON|OFF Turn output mode suitable for EXPLAIN on or off. |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 332 | do_test shell1-3.7.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 333 | catchcmd "test.db" ".explain" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 334 | # explain is the exception to the booleans. without an option, it turns it on. |
| 335 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 336 | do_test shell1-3.7.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 337 | catchcmd "test.db" ".explain ON" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 338 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 339 | do_test shell1-3.7.3 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 340 | catchcmd "test.db" ".explain OFF" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 341 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 342 | do_test shell1-3.7.4 { |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 343 | # extra arguments ignored |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 344 | catchcmd "test.db" ".explain OFF BAD" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 345 | } {0 {}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 346 | |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 347 | |
| 348 | # .header(s) ON|OFF Turn display of headers on or off |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 349 | do_test shell1-3.9.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 350 | catchcmd "test.db" ".header" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 351 | } {1 {Usage: .headers on|off}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 352 | do_test shell1-3.9.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 353 | catchcmd "test.db" ".header ON" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 354 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 355 | do_test shell1-3.9.3 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 356 | catchcmd "test.db" ".header OFF" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 357 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 358 | do_test shell1-3.9.4 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 359 | # too many arguments |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 360 | catchcmd "test.db" ".header OFF BAD" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 361 | } {1 {Usage: .headers on|off}} |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 362 | |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 363 | do_test shell1-3.9.5 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 364 | catchcmd "test.db" ".headers" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 365 | } {1 {Usage: .headers on|off}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 366 | do_test shell1-3.9.6 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 367 | catchcmd "test.db" ".headers ON" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 368 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 369 | do_test shell1-3.9.7 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 370 | catchcmd "test.db" ".headers OFF" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 371 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 372 | do_test shell1-3.9.8 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 373 | # too many arguments |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 374 | catchcmd "test.db" ".headers OFF BAD" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 375 | } {1 {Usage: .headers on|off}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 376 | |
| 377 | # .help Show this message |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 378 | do_test shell1-3.10.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 379 | set res [catchcmd "test.db" ".help"] |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 380 | # 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} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 385 | do_test shell1-3.10.2 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 386 | # we allow .help to take extra args (it is help after all) |
drh | 98aa2ab | 2018-09-26 16:53:51 +0000 | [diff] [blame] | 387 | set res [catchcmd "test.db" ".help *"] |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 388 | # 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} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 393 | |
| 394 | # .import FILE TABLE Import data from FILE into TABLE |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 395 | do_test shell1-3.11.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 396 | catchcmd "test.db" ".import" |
drh | ccb3781 | 2020-03-09 15:39:39 +0000 | [diff] [blame] | 397 | } {/1 .ERROR: missing FILE argument.*/} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 398 | do_test shell1-3.11.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 399 | catchcmd "test.db" ".import FOO" |
drh | ccb3781 | 2020-03-09 15:39:39 +0000 | [diff] [blame] | 400 | } {/1 .ERROR: missing TABLE argument.*/} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 401 | do_test shell1-3.11.3 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 402 | # too many arguments |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 403 | catchcmd "test.db" ".import FOO BAR BAD" |
drh | ccb3781 | 2020-03-09 15:39:39 +0000 | [diff] [blame] | 404 | } {/1 .ERROR: extra argument: "BAD".*./} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 405 | |
drh | 0e55db1 | 2015-02-06 14:51:13 +0000 | [diff] [blame] | 406 | # .indexes ?TABLE? Show names of all indexes |
| 407 | # If TABLE specified, only show indexes for tables |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 408 | # matching LIKE pattern TABLE. |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 409 | do_test shell1-3.12.1 { |
drh | 0e55db1 | 2015-02-06 14:51:13 +0000 | [diff] [blame] | 410 | catchcmd "test.db" ".indexes" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 411 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 412 | do_test shell1-3.12.2 { |
drh | 0e55db1 | 2015-02-06 14:51:13 +0000 | [diff] [blame] | 413 | catchcmd "test.db" ".indexes FOO" |
| 414 | } {0 {}} |
| 415 | do_test shell1-3.12.2-legacy { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 416 | catchcmd "test.db" ".indices FOO" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 417 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 418 | do_test shell1-3.12.3 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 419 | # too many arguments |
drh | 0e55db1 | 2015-02-06 14:51:13 +0000 | [diff] [blame] | 420 | catchcmd "test.db" ".indexes FOO BAD" |
| 421 | } {1 {Usage: .indexes ?LIKE-PATTERN?}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 422 | |
| 423 | # .mode MODE ?TABLE? Set output mode where MODE is one of: |
mistachkin | e0d6885 | 2014-12-11 03:12:33 +0000 | [diff] [blame] | 424 | # ascii Columns/rows delimited by 0x1F and 0x1E |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 425 | # 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 |
mistachkin | e0d6885 | 2014-12-11 03:12:33 +0000 | [diff] [blame] | 430 | # list Values delimited by .separator strings |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 431 | # tabs Tab-separated values |
| 432 | # tcl TCL list elements |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 433 | do_test shell1-3.13.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 434 | catchcmd "test.db" ".mode" |
drh | a501f7d | 2017-06-29 21:33:25 +0000 | [diff] [blame] | 435 | } {0 {current output mode: list}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 436 | do_test shell1-3.13.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 437 | catchcmd "test.db" ".mode FOO" |
drh | 0908e38 | 2020-06-04 18:05:39 +0000 | [diff] [blame] | 438 | } {1 {Error: mode should be one of: ascii box column csv html insert json line list markdown quote table tabs tcl}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 439 | do_test shell1-3.13.3 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 440 | catchcmd "test.db" ".mode csv" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 441 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 442 | do_test shell1-3.13.4 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 443 | catchcmd "test.db" ".mode column" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 444 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 445 | do_test shell1-3.13.5 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 446 | catchcmd "test.db" ".mode html" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 447 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 448 | do_test shell1-3.13.6 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 449 | catchcmd "test.db" ".mode insert" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 450 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 451 | do_test shell1-3.13.7 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 452 | catchcmd "test.db" ".mode line" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 453 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 454 | do_test shell1-3.13.8 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 455 | catchcmd "test.db" ".mode list" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 456 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 457 | do_test shell1-3.13.9 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 458 | catchcmd "test.db" ".mode tabs" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 459 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 460 | do_test shell1-3.13.10 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 461 | catchcmd "test.db" ".mode tcl" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 462 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 463 | do_test shell1-3.13.11 { |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 464 | # extra arguments ignored |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 465 | catchcmd "test.db" ".mode tcl BAD" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 466 | } {0 {}} |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 467 | |
| 468 | # don't allow partial mode type matches |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 469 | do_test shell1-3.13.12 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 470 | catchcmd "test.db" ".mode l" |
drh | 0908e38 | 2020-06-04 18:05:39 +0000 | [diff] [blame] | 471 | } {1 {Error: mode should be one of: ascii box column csv html insert json line list markdown quote table tabs tcl}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 472 | do_test shell1-3.13.13 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 473 | catchcmd "test.db" ".mode li" |
drh | 0908e38 | 2020-06-04 18:05:39 +0000 | [diff] [blame] | 474 | } {1 {Error: mode should be one of: ascii box column csv html insert json line list markdown quote table tabs tcl}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 475 | do_test shell1-3.13.14 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 476 | catchcmd "test.db" ".mode lin" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 477 | } {0 {}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 478 | |
| 479 | # .nullvalue STRING Print STRING in place of NULL values |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 480 | do_test shell1-3.14.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 481 | catchcmd "test.db" ".nullvalue" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 482 | } {1 {Usage: .nullvalue STRING}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 483 | do_test shell1-3.14.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 484 | catchcmd "test.db" ".nullvalue FOO" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 485 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 486 | do_test shell1-3.14.3 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 487 | # too many arguments |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 488 | catchcmd "test.db" ".nullvalue FOO BAD" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 489 | } {1 {Usage: .nullvalue STRING}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 490 | |
| 491 | # .output FILENAME Send output to FILENAME |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 492 | do_test shell1-3.15.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 493 | catchcmd "test.db" ".output" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 494 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 495 | do_test shell1-3.15.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 496 | catchcmd "test.db" ".output FOO" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 497 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 498 | do_test shell1-3.15.3 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 499 | # too many arguments |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 500 | catchcmd "test.db" ".output FOO BAD" |
drh | 541ef2c | 2020-04-20 16:21:30 +0000 | [diff] [blame] | 501 | } {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 |
| 508 | child process exited abnormally}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 509 | |
| 510 | # .output stdout Send output to the screen |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 511 | do_test shell1-3.16.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 512 | catchcmd "test.db" ".output stdout" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 513 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 514 | do_test shell1-3.16.2 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 515 | # too many arguments |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 516 | catchcmd "test.db" ".output stdout BAD" |
drh | 541ef2c | 2020-04-20 16:21:30 +0000 | [diff] [blame] | 517 | } {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 |
| 524 | child process exited abnormally}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 525 | |
| 526 | # .prompt MAIN CONTINUE Replace the standard prompts |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 527 | do_test shell1-3.17.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 528 | catchcmd "test.db" ".prompt" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 529 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 530 | do_test shell1-3.17.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 531 | catchcmd "test.db" ".prompt FOO" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 532 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 533 | do_test shell1-3.17.3 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 534 | catchcmd "test.db" ".prompt FOO BAR" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 535 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 536 | do_test shell1-3.17.4 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 537 | # too many arguments |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 538 | catchcmd "test.db" ".prompt FOO BAR BAD" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 539 | } {0 {}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 540 | |
| 541 | # .quit Exit this program |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 542 | do_test shell1-3.18.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 543 | catchcmd "test.db" ".quit" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 544 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 545 | do_test shell1-3.18.2 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 546 | # too many arguments |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 547 | catchcmd "test.db" ".quit BAD" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 548 | } {0 {}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 549 | |
| 550 | # .read FILENAME Execute SQL in FILENAME |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 551 | do_test shell1-3.19.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 552 | catchcmd "test.db" ".read" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 553 | } {1 {Usage: .read FILE}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 554 | do_test shell1-3.19.2 { |
mistachkin | 9ac9931 | 2013-09-13 23:26:47 +0000 | [diff] [blame] | 555 | forcedelete FOO |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 556 | catchcmd "test.db" ".read FOO" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 557 | } {1 {Error: cannot open "FOO"}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 558 | do_test shell1-3.19.3 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 559 | # too many arguments |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 560 | catchcmd "test.db" ".read FOO BAD" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 561 | } {1 {Usage: .read FILE}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 562 | |
| 563 | # .restore ?DB? FILE Restore content of DB (default "main") from FILE |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 564 | do_test shell1-3.20.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 565 | catchcmd "test.db" ".restore" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 566 | } {1 {Usage: .restore ?DB? FILE}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 567 | do_test shell1-3.20.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 568 | catchcmd "test.db" ".restore FOO" |
| 569 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 570 | do_test shell1-3.20.3 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 571 | catchcmd "test.db" ".restore FOO BAR" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 572 | } {1 {Error: unknown database FOO}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 573 | do_test shell1-3.20.4 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 574 | # too many arguments |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 575 | catchcmd "test.db" ".restore FOO BAR BAD" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 576 | } {1 {Usage: .restore ?DB? FILE}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 577 | |
drh | a22dd38 | 2017-06-24 19:21:48 +0000 | [diff] [blame] | 578 | ifcapable vtab { |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 579 | # .schema ?TABLE? Show the CREATE statements |
| 580 | # If TABLE specified, only show tables matching |
| 581 | # LIKE pattern TABLE. |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 582 | do_test shell1-3.21.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 583 | catchcmd "test.db" ".schema" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 584 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 585 | do_test shell1-3.21.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 586 | catchcmd "test.db" ".schema FOO" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 587 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 588 | do_test shell1-3.21.3 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 589 | # too many arguments |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 590 | catchcmd "test.db" ".schema FOO BAD" |
drh | bbb29ec | 2020-10-12 14:56:47 +0000 | [diff] [blame] | 591 | } {1 {Usage: .schema ?--indent? ?--nosys? ?LIKE-PATTERN?}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 592 | |
drh | ac43e98 | 2012-05-21 03:15:06 +0000 | [diff] [blame] | 593 | do_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); |
drh | ceba792 | 2018-01-01 21:28:25 +0000 | [diff] [blame] | 601 | CREATE VIEW v2 AS SELECT x+1 AS y FROM t1 |
drh | 1d315cf | 2018-01-01 21:49:43 +0000 | [diff] [blame] | 602 | /* v2(y) */; |
drh | ceba792 | 2018-01-01 21:28:25 +0000 | [diff] [blame] | 603 | CREATE VIEW v1 AS SELECT y+1 FROM v2 |
drh | 1d315cf | 2018-01-01 21:49:43 +0000 | [diff] [blame] | 604 | /* v1("y+1") */;}} |
drh | ac43e98 | 2012-05-21 03:15:06 +0000 | [diff] [blame] | 605 | db eval {DROP VIEW v1; DROP VIEW v2; DROP TABLE t1;} |
drh | a22dd38 | 2017-06-24 19:21:48 +0000 | [diff] [blame] | 606 | } |
drh | ac43e98 | 2012-05-21 03:15:06 +0000 | [diff] [blame] | 607 | |
mistachkin | 636bf9f | 2014-07-19 20:15:16 +0000 | [diff] [blame] | 608 | # .separator STRING Change column separator used by output and .import |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 609 | do_test shell1-3.22.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 610 | catchcmd "test.db" ".separator" |
mistachkin | e0d6885 | 2014-12-11 03:12:33 +0000 | [diff] [blame] | 611 | } {1 {Usage: .separator COL ?ROW?}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 612 | do_test shell1-3.22.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 613 | catchcmd "test.db" ".separator FOO" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 614 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 615 | do_test shell1-3.22.3 { |
drh | 6976c21 | 2014-07-24 12:09:47 +0000 | [diff] [blame] | 616 | catchcmd "test.db" ".separator ABC XYZ" |
| 617 | } {0 {}} |
| 618 | do_test shell1-3.22.4 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 619 | # too many arguments |
drh | 6976c21 | 2014-07-24 12:09:47 +0000 | [diff] [blame] | 620 | catchcmd "test.db" ".separator FOO BAD BAD2" |
mistachkin | e0d6885 | 2014-12-11 03:12:33 +0000 | [diff] [blame] | 621 | } {1 {Usage: .separator COL ?ROW?}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 622 | |
| 623 | # .show Show the current values for various settings |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 624 | do_test shell1-3.23.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 625 | set res [catchcmd "test.db" ".show"] |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 626 | list [regexp {echo:} $res] \ |
| 627 | [regexp {explain:} $res] \ |
| 628 | [regexp {headers:} $res] \ |
| 629 | [regexp {mode:} $res] \ |
| 630 | [regexp {nullvalue:} $res] \ |
| 631 | [regexp {output:} $res] \ |
mistachkin | 636bf9f | 2014-07-19 20:15:16 +0000 | [diff] [blame] | 632 | [regexp {colseparator:} $res] \ |
| 633 | [regexp {rowseparator:} $res] \ |
shaneh | 642d8b8 | 2010-07-28 16:05:34 +0000 | [diff] [blame] | 634 | [regexp {stats:} $res] \ |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 635 | [regexp {width:} $res] |
mistachkin | e0d6885 | 2014-12-11 03:12:33 +0000 | [diff] [blame] | 636 | } {1 1 1 1 1 1 1 1 1 1} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 637 | do_test shell1-3.23.2 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 638 | # too many arguments |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 639 | catchcmd "test.db" ".show BAD" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 640 | } {1 {Usage: .show}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 641 | |
shaneh | 642d8b8 | 2010-07-28 16:05:34 +0000 | [diff] [blame] | 642 | # .stats ON|OFF Turn stats on or off |
drh | 3478490 | 2016-02-27 17:12:36 +0000 | [diff] [blame] | 643 | #do_test shell1-3.23b.1 { |
| 644 | # catchcmd "test.db" ".stats" |
drh | a6e6cf2 | 2021-01-09 19:10:04 +0000 | [diff] [blame] | 645 | #} {1 {Usage: .stats on|off|stmt|vmstep}} |
shaneh | 642d8b8 | 2010-07-28 16:05:34 +0000 | [diff] [blame] | 646 | do_test shell1-3.23b.2 { |
| 647 | catchcmd "test.db" ".stats ON" |
| 648 | } {0 {}} |
| 649 | do_test shell1-3.23b.3 { |
| 650 | catchcmd "test.db" ".stats OFF" |
| 651 | } {0 {}} |
| 652 | do_test shell1-3.23b.4 { |
| 653 | # too many arguments |
| 654 | catchcmd "test.db" ".stats OFF BAD" |
drh | a6e6cf2 | 2021-01-09 19:10:04 +0000 | [diff] [blame] | 655 | } {1 {Usage: .stats ?on|off|stmt|vmstep?}} |
shaneh | 642d8b8 | 2010-07-28 16:05:34 +0000 | [diff] [blame] | 656 | |
drh | 3c49eaf | 2018-06-07 15:23:43 +0000 | [diff] [blame] | 657 | # Ticket 7be932dfa60a8a6b3b26bcf7623ec46e0a403ddb 2018-06-07 |
| 658 | # Adverse interaction between .stats and .eqp |
| 659 | # |
| 660 | do_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 | |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 670 | # .tables ?TABLE? List names of tables |
| 671 | # If TABLE specified, only list tables matching |
| 672 | # LIKE pattern TABLE. |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 673 | do_test shell1-3.24.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 674 | catchcmd "test.db" ".tables" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 675 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 676 | do_test shell1-3.24.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 677 | catchcmd "test.db" ".tables FOO" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 678 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 679 | do_test shell1-3.24.3 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 680 | # too many arguments |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 681 | catchcmd "test.db" ".tables FOO BAD" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 682 | } {0 {}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 683 | |
| 684 | # .timeout MS Try opening locked tables for MS milliseconds |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 685 | do_test shell1-3.25.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 686 | catchcmd "test.db" ".timeout" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 687 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 688 | do_test shell1-3.25.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 689 | catchcmd "test.db" ".timeout zzz" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 690 | # this should be treated the same as a '0' timeout |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 691 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 692 | do_test shell1-3.25.3 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 693 | catchcmd "test.db" ".timeout 1" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 694 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 695 | do_test shell1-3.25.4 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 696 | # too many arguments |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 697 | catchcmd "test.db" ".timeout 1 BAD" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 698 | } {0 {}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 699 | |
| 700 | # .width NUM NUM ... Set column widths for "column" mode |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 701 | do_test shell1-3.26.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 702 | catchcmd "test.db" ".width" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 703 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 704 | do_test shell1-3.26.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 705 | catchcmd "test.db" ".width xxx" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 706 | # this should be treated the same as a '0' width for col 1 |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 707 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 708 | do_test shell1-3.26.3 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 709 | catchcmd "test.db" ".width xxx yyy" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 710 | # this should be treated the same as a '0' width for col 1 and 2 |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 711 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 712 | do_test shell1-3.26.4 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 713 | catchcmd "test.db" ".width 1 1" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 714 | # this should be treated the same as a '1' width for col 1 and 2 |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 715 | } {0 {}} |
drh | 078b1fd | 2012-09-21 13:40:02 +0000 | [diff] [blame] | 716 | do_test shell1-3.26.5 { |
drh | c060508 | 2020-06-05 00:54:27 +0000 | [diff] [blame] | 717 | catchcmd "test.db" ".mode column\n.header off\n.width 10 -10\nSELECT 'abcdefg', 123456;" |
drh | 078b1fd | 2012-09-21 13:40:02 +0000 | [diff] [blame] | 718 | # this should be treated the same as a '1' width for col 1 and 2 |
| 719 | } {0 {abcdefg 123456}} |
| 720 | do_test shell1-3.26.6 { |
drh | c060508 | 2020-06-05 00:54:27 +0000 | [diff] [blame] | 721 | catchcmd "test.db" ".mode column\n.header off\n.width -10 10\nSELECT 'abcdefg', 123456;" |
drh | 078b1fd | 2012-09-21 13:40:02 +0000 | [diff] [blame] | 722 | # this should be treated the same as a '1' width for col 1 and 2 |
| 723 | } {0 { abcdefg 123456 }} |
| 724 | |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 725 | |
| 726 | # .timer ON|OFF Turn the CPU timer measurement on or off |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 727 | do_test shell1-3.27.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 728 | catchcmd "test.db" ".timer" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 729 | } {1 {Usage: .timer on|off}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 730 | do_test shell1-3.27.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 731 | catchcmd "test.db" ".timer ON" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 732 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 733 | do_test shell1-3.27.3 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 734 | catchcmd "test.db" ".timer OFF" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 735 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 736 | do_test shell1-3.27.4 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 737 | # too many arguments |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 738 | catchcmd "test.db" ".timer OFF BAD" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 739 | } {1 {Usage: .timer on|off}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 740 | |
drh | 53a9d15 | 2011-04-25 18:20:04 +0000 | [diff] [blame] | 741 | do_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 | |
drh | 078b1fd | 2012-09-21 13:40:02 +0000 | [diff] [blame] | 746 | do_test shell1-3-29.1 { |
| 747 | catchcmd "test.db" ".print this is a test" |
| 748 | } {0 {this is a test}} |
| 749 | |
drh | 4c56b99 | 2013-06-27 13:26:55 +0000 | [diff] [blame] | 750 | # dot-command argument quoting |
| 751 | do_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}} |
| 754 | do_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 | |
drh | 5128e85 | 2012-04-24 13:14:49 +0000 | [diff] [blame] | 759 | # Test the output of the ".dump" command |
| 760 | # |
| 761 | do_test shell1-4.1 { |
drh | 55a1b30 | 2013-09-04 16:08:50 +0000 | [diff] [blame] | 762 | db close |
| 763 | forcedelete test.db |
| 764 | sqlite3 db test.db |
drh | 5128e85 | 2012-04-24 13:14:49 +0000 | [diff] [blame] | 765 | db eval { |
drh | 55a1b30 | 2013-09-04 16:08:50 +0000 | [diff] [blame] | 766 | PRAGMA encoding=UTF16; |
drh | 5128e85 | 2012-04-24 13:14:49 +0000 | [diff] [blame] | 767 | CREATE TABLE t1(x); |
mistachkin | 585dcb2 | 2012-12-04 00:23:43 +0000 | [diff] [blame] | 768 | INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f'); |
mistachkin | 151c75a | 2015-04-07 21:16:40 +0000 | [diff] [blame] | 769 | CREATE TABLE t3(x,y); |
| 770 | INSERT INTO t3 VALUES(1,null), (2,''), (3,1), |
| 771 | (4,2.25), (5,'hello'), (6,x'807f'); |
drh | 5128e85 | 2012-04-24 13:14:49 +0000 | [diff] [blame] | 772 | } |
| 773 | catchcmd test.db {.dump} |
| 774 | } {0 {PRAGMA foreign_keys=OFF; |
| 775 | BEGIN TRANSACTION; |
| 776 | CREATE TABLE t1(x); |
drh | f42d318 | 2017-03-08 12:25:18 +0000 | [diff] [blame] | 777 | INSERT INTO t1 VALUES(NULL); |
| 778 | INSERT INTO t1 VALUES(''); |
| 779 | INSERT INTO t1 VALUES(1); |
| 780 | INSERT INTO t1 VALUES(2.25); |
| 781 | INSERT INTO t1 VALUES('hello'); |
| 782 | INSERT INTO t1 VALUES(X'807f'); |
mistachkin | 151c75a | 2015-04-07 21:16:40 +0000 | [diff] [blame] | 783 | CREATE TABLE t3(x,y); |
drh | f42d318 | 2017-03-08 12:25:18 +0000 | [diff] [blame] | 784 | INSERT INTO t3 VALUES(1,NULL); |
| 785 | INSERT INTO t3 VALUES(2,''); |
| 786 | INSERT INTO t3 VALUES(3,1); |
| 787 | INSERT INTO t3 VALUES(4,2.25); |
| 788 | INSERT INTO t3 VALUES(5,'hello'); |
| 789 | INSERT INTO t3 VALUES(6,X'807f'); |
drh | 5128e85 | 2012-04-24 13:14:49 +0000 | [diff] [blame] | 790 | COMMIT;}} |
| 791 | |
dan | b9cd86a | 2017-03-25 18:31:42 +0000 | [diff] [blame] | 792 | |
| 793 | ifcapable vtab { |
| 794 | |
drh | f42d318 | 2017-03-08 12:25:18 +0000 | [diff] [blame] | 795 | # The --preserve-rowids option to .dump |
| 796 | # |
drh | e611f14 | 2017-03-08 11:44:00 +0000 | [diff] [blame] | 797 | do_test shell1-4.1.1 { |
| 798 | catchcmd test.db {.dump --preserve-rowids} |
| 799 | } {0 {PRAGMA foreign_keys=OFF; |
| 800 | BEGIN TRANSACTION; |
| 801 | CREATE TABLE t1(x); |
drh | f42d318 | 2017-03-08 12:25:18 +0000 | [diff] [blame] | 802 | INSERT INTO t1(rowid,x) VALUES(1,NULL); |
| 803 | INSERT INTO t1(rowid,x) VALUES(2,''); |
| 804 | INSERT INTO t1(rowid,x) VALUES(3,1); |
| 805 | INSERT INTO t1(rowid,x) VALUES(4,2.25); |
| 806 | INSERT INTO t1(rowid,x) VALUES(5,'hello'); |
| 807 | INSERT INTO t1(rowid,x) VALUES(6,X'807f'); |
drh | e611f14 | 2017-03-08 11:44:00 +0000 | [diff] [blame] | 808 | CREATE TABLE t3(x,y); |
drh | f42d318 | 2017-03-08 12:25:18 +0000 | [diff] [blame] | 809 | INSERT INTO t3(rowid,x,y) VALUES(1,1,NULL); |
| 810 | INSERT INTO t3(rowid,x,y) VALUES(2,2,''); |
| 811 | INSERT INTO t3(rowid,x,y) VALUES(3,3,1); |
| 812 | INSERT INTO t3(rowid,x,y) VALUES(4,4,2.25); |
| 813 | INSERT INTO t3(rowid,x,y) VALUES(5,5,'hello'); |
| 814 | INSERT INTO t3(rowid,x,y) VALUES(6,6,X'807f'); |
drh | e611f14 | 2017-03-08 11:44:00 +0000 | [diff] [blame] | 815 | COMMIT;}} |
| 816 | |
drh | f42d318 | 2017-03-08 12:25:18 +0000 | [diff] [blame] | 817 | # If the table contains an INTEGER PRIMARY KEY, do not record a separate |
| 818 | # rowid column in the output. |
| 819 | # |
drh | e611f14 | 2017-03-08 11:44:00 +0000 | [diff] [blame] | 820 | do_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; |
| 831 | BEGIN TRANSACTION; |
| 832 | CREATE TABLE t1(x INTEGER PRIMARY KEY, y); |
drh | f42d318 | 2017-03-08 12:25:18 +0000 | [diff] [blame] | 833 | INSERT INTO t1 VALUES(1,NULL); |
| 834 | INSERT INTO t1 VALUES(2,''); |
| 835 | INSERT INTO t1 VALUES(3,1); |
| 836 | INSERT INTO t1 VALUES(4,2.25); |
| 837 | INSERT INTO t1 VALUES(5,'hello'); |
| 838 | INSERT INTO t1 VALUES(6,X'807f'); |
drh | e611f14 | 2017-03-08 11:44:00 +0000 | [diff] [blame] | 839 | COMMIT;}} |
| 840 | |
drh | f42d318 | 2017-03-08 12:25:18 +0000 | [diff] [blame] | 841 | # 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 | # |
| 844 | do_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; |
| 855 | BEGIN TRANSACTION; |
| 856 | CREATE TABLE [table](x INTEGER PRIMARY KEY DESC, y); |
| 857 | INSERT INTO "table"(rowid,x,y) VALUES(1,1,NULL); |
| 858 | INSERT INTO "table"(rowid,x,y) VALUES(2,12,''); |
| 859 | INSERT INTO "table"(rowid,x,y) VALUES(3,23,1); |
| 860 | INSERT INTO "table"(rowid,x,y) VALUES(4,34,2.25); |
| 861 | INSERT INTO "table"(rowid,x,y) VALUES(5,45,'hello'); |
| 862 | INSERT INTO "table"(rowid,x,y) VALUES(6,56,X'807f'); |
| 863 | COMMIT;}} |
| 864 | |
| 865 | # Do not record rowids for a WITHOUT ROWID table. Also check correct quoting |
| 866 | # of table names that contain odd characters. |
| 867 | # |
| 868 | do_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; |
| 879 | BEGIN TRANSACTION; |
| 880 | CREATE TABLE [ta<>ble](x INTEGER PRIMARY KEY, y) WITHOUT ROWID; |
| 881 | INSERT INTO "ta<>ble" VALUES(1,NULL); |
| 882 | INSERT INTO "ta<>ble" VALUES(12,''); |
| 883 | INSERT INTO "ta<>ble" VALUES(23,1); |
| 884 | INSERT INTO "ta<>ble" VALUES(34,2.25); |
| 885 | INSERT INTO "ta<>ble" VALUES(45,'hello'); |
| 886 | INSERT INTO "ta<>ble" VALUES(56,X'807f'); |
| 887 | COMMIT;}} |
| 888 | |
| 889 | # Do not record rowids if the rowid is inaccessible |
| 890 | # |
| 891 | do_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; |
| 901 | BEGIN TRANSACTION; |
| 902 | CREATE TABLE t1(_ROWID_,rowid,oid); |
| 903 | INSERT INTO t1 VALUES(1,NULL,'alpha'); |
| 904 | INSERT INTO t1 VALUES(12,'',99); |
| 905 | INSERT INTO t1 VALUES(23,1,X'b0b1b2'); |
| 906 | COMMIT;}} |
drh | e611f14 | 2017-03-08 11:44:00 +0000 | [diff] [blame] | 907 | |
dan | b9cd86a | 2017-03-25 18:31:42 +0000 | [diff] [blame] | 908 | } else { |
| 909 | |
| 910 | do_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 | |
drh | 5128e85 | 2012-04-24 13:14:49 +0000 | [diff] [blame] | 925 | # Test the output of ".mode insert" |
| 926 | # |
mistachkin | 151c75a | 2015-04-07 21:16:40 +0000 | [diff] [blame] | 927 | do_test shell1-4.2.1 { |
drh | 5128e85 | 2012-04-24 13:14:49 +0000 | [diff] [blame] | 928 | catchcmd test.db ".mode insert t1\nselect * from t1;" |
| 929 | } {0 {INSERT INTO t1 VALUES(NULL); |
mistachkin | 585dcb2 | 2012-12-04 00:23:43 +0000 | [diff] [blame] | 930 | INSERT INTO t1 VALUES(''); |
drh | 5128e85 | 2012-04-24 13:14:49 +0000 | [diff] [blame] | 931 | INSERT INTO t1 VALUES(1); |
| 932 | INSERT INTO t1 VALUES(2.25); |
| 933 | INSERT INTO t1 VALUES('hello'); |
| 934 | INSERT INTO t1 VALUES(X'807f');}} |
| 935 | |
mistachkin | 151c75a | 2015-04-07 21:16:40 +0000 | [diff] [blame] | 936 | # Test the output of ".mode insert" with headers |
| 937 | # |
| 938 | do_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); |
| 941 | INSERT INTO t1(x) VALUES(''); |
| 942 | INSERT INTO t1(x) VALUES(1); |
| 943 | INSERT INTO t1(x) VALUES(2.25); |
| 944 | INSERT INTO t1(x) VALUES('hello'); |
| 945 | INSERT INTO t1(x) VALUES(X'807f');}} |
| 946 | |
| 947 | # Test the output of ".mode insert" |
| 948 | # |
| 949 | do_test shell1-4.2.3 { |
| 950 | catchcmd test.db ".mode insert t3\nselect * from t3;" |
| 951 | } {0 {INSERT INTO t3 VALUES(1,NULL); |
| 952 | INSERT INTO t3 VALUES(2,''); |
| 953 | INSERT INTO t3 VALUES(3,1); |
| 954 | INSERT INTO t3 VALUES(4,2.25); |
| 955 | INSERT INTO t3 VALUES(5,'hello'); |
| 956 | INSERT INTO t3 VALUES(6,X'807f');}} |
| 957 | |
| 958 | # Test the output of ".mode insert" with headers |
| 959 | # |
mistachkin | cc44540 | 2015-04-07 21:17:53 +0000 | [diff] [blame] | 960 | do_test shell1-4.2.4 { |
mistachkin | 151c75a | 2015-04-07 21:16:40 +0000 | [diff] [blame] | 961 | catchcmd test.db ".mode insert t3\n.headers on\nselect * from t3;" |
| 962 | } {0 {INSERT INTO t3(x,y) VALUES(1,NULL); |
| 963 | INSERT INTO t3(x,y) VALUES(2,''); |
| 964 | INSERT INTO t3(x,y) VALUES(3,1); |
| 965 | INSERT INTO t3(x,y) VALUES(4,2.25); |
| 966 | INSERT INTO t3(x,y) VALUES(5,'hello'); |
| 967 | INSERT INTO t3(x,y) VALUES(6,X'807f');}} |
| 968 | |
mistachkin | 585dcb2 | 2012-12-04 00:23:43 +0000 | [diff] [blame] | 969 | # Test the output of ".mode tcl" |
| 970 | # |
| 971 | do_test shell1-4.3 { |
drh | 55a1b30 | 2013-09-04 16:08:50 +0000 | [diff] [blame] | 972 | 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 | } |
mistachkin | 585dcb2 | 2012-12-04 00:23:43 +0000 | [diff] [blame] | 980 | 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 | # |
| 990 | do_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 | # |
| 1002 | do_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 | # |
| 1010 | do_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} |
drh | 5128e85 | 2012-04-24 13:14:49 +0000 | [diff] [blame] | 1024 | |
mistachkin | f21979d | 2015-01-18 05:35:01 +0000 | [diff] [blame] | 1025 | # Test using arbitrary byte data with the shell via standard input/output. |
| 1026 | # |
| 1027 | do_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 | # |
mistachkin | 46a6b99 | 2015-01-18 09:02:57 +0000 | [diff] [blame] | 1034 | # 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. |
mistachkin | f21979d | 2015-01-18 05:35:01 +0000 | [diff] [blame] | 1038 | # |
mistachkin | 46a6b99 | 2015-01-18 09:02:57 +0000 | [diff] [blame] | 1039 | if {$i==0x0D || ($tcl_platform(platform)=="windows" && $i==0x1A)} { |
mistachkin | f21979d | 2015-01-18 05:35:01 +0000 | [diff] [blame] | 1040 | continue |
| 1041 | } |
drh | 158931a | 2019-04-12 16:25:42 +0000 | [diff] [blame] | 1042 | # Tcl 8.7 maps 0x80 through 0x9f into valid UTF8. So skip those tests. |
| 1043 | if {$i>=0x80 && $i<=0x9f} continue |
drh | 0172568 | 2016-07-25 14:20:01 +0000 | [diff] [blame] | 1044 | if {$i>=0xE0 && $tcl_platform(os)=="OpenBSD"} continue |
mistachkin | be56ad3 | 2016-07-29 04:12:18 +0000 | [diff] [blame] | 1045 | if {$i>=0xE0 && $i<=0xEF && $tcl_platform(os)=="Linux"} continue |
mistachkin | f21979d | 2015-01-18 05:35:01 +0000 | [diff] [blame] | 1046 | set hex [format %02X $i] |
| 1047 | set char [subst \\x$hex]; set oldChar $char |
mistachkin | 0acee51 | 2015-01-19 21:11:31 +0000 | [diff] [blame] | 1048 | 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] |
mistachkin | bfefa4c | 2015-01-19 21:27:46 +0000 | [diff] [blame] | 1074 | set x [catchcmdex test.db ".print $char\n"] |
mistachkin | f21979d | 2015-01-18 05:35:01 +0000 | [diff] [blame] | 1075 | 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"} { |
mistachkin | 48dcf2b | 2016-04-04 17:59:37 +0000 | [diff] [blame] | 1081 | 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" |
mistachkin | f21979d | 2015-01-18 05:35:01 +0000 | [diff] [blame] | 1087 | } |
| 1088 | } |
| 1089 | } {} |
| 1090 | |
drh | 697c9ea | 2016-05-16 11:55:09 +0000 | [diff] [blame] | 1091 | # These test cases do not work on MinGW |
| 1092 | if 0 { |
| 1093 | |
mistachkin | 49e1125 | 2016-04-04 15:47:46 +0000 | [diff] [blame] | 1094 | # The string used here is the word "test" in Chinese. |
| 1095 | # In UTF-8, it is encoded as: \xE6\xB5\x8B\xE8\xAF\x95 |
| 1096 | set test \u6D4B\u8BD5 |
| 1097 | |
mistachkin | 1fe36bb | 2016-04-04 02:16:44 +0000 | [diff] [blame] | 1098 | do_test shell1-6.0 { |
mistachkin | 49e1125 | 2016-04-04 15:47:46 +0000 | [diff] [blame] | 1099 | set fileName $test; append fileName .db |
| 1100 | catch {forcedelete $fileName} |
mistachkin | 1fe36bb | 2016-04-04 02:16:44 +0000 | [diff] [blame] | 1101 | 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]} { |
mistachkin | 1810f22 | 2016-04-04 02:33:34 +0000 | [diff] [blame] | 1111 | error "file \"$fileName\" (Unicode) does not exist" |
mistachkin | 1fe36bb | 2016-04-04 02:16:44 +0000 | [diff] [blame] | 1112 | } |
| 1113 | forcedelete $fileName |
| 1114 | } {} |
| 1115 | |
mistachkin | 49e1125 | 2016-04-04 15:47:46 +0000 | [diff] [blame] | 1116 | do_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 | } {} |
drh | 697c9ea | 2016-05-16 11:55:09 +0000 | [diff] [blame] | 1130 | } |
mistachkin | 49e1125 | 2016-04-04 15:47:46 +0000 | [diff] [blame] | 1131 | |
mistachkin | 9d10726 | 2018-03-23 14:24:34 +0000 | [diff] [blame] | 1132 | db close |
| 1133 | forcedelete test.db test.db-journal test.db-wal |
| 1134 | sqlite3 db test.db |
| 1135 | |
dan | 07f119e | 2018-03-24 15:08:48 +0000 | [diff] [blame] | 1136 | # The shell tool ".schema" command uses virtual table "pragma_database_list" |
| 1137 | # |
| 1138 | ifcapable vtab { |
| 1139 | |
mistachkin | 9d10726 | 2018-03-23 14:24:34 +0000 | [diff] [blame] | 1140 | do_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 | } {} |
| 1150 | do_test shell1-7.1.2 { |
| 1151 | catchcmd "test.db" ".schema _" |
| 1152 | } {0 {CREATE TABLE Z (x TEXT PRIMARY KEY); |
| 1153 | CREATE TABLE _ (x TEXT PRIMARY KEY);}} |
| 1154 | do_test shell1-7.1.3 { |
| 1155 | catchcmd "test.db" ".schema \\\\_" |
| 1156 | } {0 {CREATE TABLE _ (x TEXT PRIMARY KEY);}} |
| 1157 | do_test shell1-7.1.4 { |
| 1158 | catchcmd "test.db" ".schema __" |
| 1159 | } {0 {CREATE TABLE YY (x TEXT PRIMARY KEY); |
| 1160 | CREATE TABLE __ (x TEXT PRIMARY KEY);}} |
| 1161 | do_test shell1-7.1.5 { |
| 1162 | catchcmd "test.db" ".schema \\\\_\\\\_" |
| 1163 | } {0 {CREATE TABLE __ (x TEXT PRIMARY KEY);}} |
| 1164 | do_test shell1-7.1.6 { |
| 1165 | catchcmd "test.db" ".schema ___" |
| 1166 | } {0 {CREATE TABLE WWW (x TEXT PRIMARY KEY); |
| 1167 | CREATE TABLE ___ (x TEXT PRIMARY KEY);}} |
| 1168 | do_test shell1-7.1.7 { |
| 1169 | catchcmd "test.db" ".schema \\\\_\\\\_\\\\_" |
| 1170 | } {0 {CREATE TABLE ___ (x TEXT PRIMARY KEY);}} |
| 1171 | |
dan | 07f119e | 2018-03-24 15:08:48 +0000 | [diff] [blame] | 1172 | } |
| 1173 | |
drh | 4dfdb86 | 2020-08-11 18:17:04 +0000 | [diff] [blame] | 1174 | # 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 | # |
| 1178 | do_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} |
| 1200 | do_test shell1-8.2 { |
| 1201 | catchcmd :memory: { |
| 1202 | .mode box |
| 1203 | SELECT ieee754(47.49) AS x; |
| 1204 | } |
| 1205 | } {0 {┌───────────────────────────────┐ |
| 1206 | │ x │ |
| 1207 | ├───────────────────────────────┤ |
| 1208 | │ ieee754(6683623321994527,-47) │ |
| 1209 | └───────────────────────────────┘}} |
| 1210 | do_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 | └───────┘}} |
| 1219 | do_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 | |
drh | 8df9185 | 2012-04-24 12:46:05 +0000 | [diff] [blame] | 1227 | finish_test |