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 |
| 24 | if {$tcl_platform(platform)=="windows"} { |
| 25 | set CLI "sqlite3.exe" |
| 26 | } else { |
| 27 | set CLI "./sqlite3" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 28 | } |
drh | 8df9185 | 2012-04-24 12:46:05 +0000 | [diff] [blame] | 29 | if {![file executable $CLI]} { |
| 30 | finish_test |
| 31 | return |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 32 | } |
drh | 8df9185 | 2012-04-24 12:46:05 +0000 | [diff] [blame] | 33 | db close |
| 34 | forcedelete test.db test.db-journal test.db-wal |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 35 | sqlite3 db test.db |
| 36 | |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 37 | #---------------------------------------------------------------------------- |
| 38 | # Test cases shell1-1.*: Basic command line option handling. |
| 39 | # |
| 40 | |
| 41 | # invalid option |
| 42 | do_test shell1-1.1.1 { |
| 43 | set res [catchcmd "-bad test.db" ""] |
| 44 | set rc [lindex $res 0] |
| 45 | list $rc \ |
| 46 | [regexp {Error: unknown option: -bad} $res] |
| 47 | } {1 1} |
drh | ac5649a | 2014-11-28 13:35:03 +0000 | [diff] [blame] | 48 | do_test shell1-1.1.1b { |
| 49 | set res [catchcmd "test.db -bad" ""] |
| 50 | set rc [lindex $res 0] |
| 51 | list $rc \ |
| 52 | [regexp {Error: unknown option: -bad} $res] |
| 53 | } {1 1} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 54 | # error on extra options |
| 55 | do_test shell1-1.1.2 { |
drh | ac5649a | 2014-11-28 13:35:03 +0000 | [diff] [blame] | 56 | catchcmd "test.db \"select 3\" \"select 4\"" "" |
| 57 | } {0 {3 |
| 58 | 4}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 59 | # error on extra options |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 60 | do_test shell1-1.1.3 { |
drh | ac5649a | 2014-11-28 13:35:03 +0000 | [diff] [blame] | 61 | catchcmd "test.db FOO test.db BAD" ".quit" |
| 62 | } {1 {Error: near "FOO": syntax error}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 63 | |
| 64 | # -help |
| 65 | do_test shell1-1.2.1 { |
| 66 | set res [catchcmd "-help test.db" ""] |
| 67 | set rc [lindex $res 0] |
| 68 | list $rc \ |
| 69 | [regexp {Usage} $res] \ |
| 70 | [regexp {\-init} $res] \ |
| 71 | [regexp {\-version} $res] |
| 72 | } {1 1 1 1} |
| 73 | |
| 74 | # -init filename read/process named file |
| 75 | do_test shell1-1.3.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 76 | catchcmd "-init FOO test.db" "" |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 77 | } {0 {}} |
| 78 | do_test shell1-1.3.2 { |
drh | ac5649a | 2014-11-28 13:35:03 +0000 | [diff] [blame] | 79 | catchcmd "-init FOO test.db .quit BAD" "" |
| 80 | } {0 {}} |
| 81 | do_test shell1-1.3.3 { |
| 82 | catchcmd "-init FOO test.db BAD .quit" "" |
| 83 | } {1 {Error: near "BAD": syntax error}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 84 | |
| 85 | # -echo print commands before execution |
| 86 | do_test shell1-1.4.1 { |
| 87 | catchcmd "-echo test.db" "" |
| 88 | } {0 {}} |
| 89 | |
| 90 | # -[no]header turn headers on or off |
| 91 | do_test shell1-1.5.1 { |
| 92 | catchcmd "-header test.db" "" |
| 93 | } {0 {}} |
| 94 | do_test shell1-1.5.2 { |
| 95 | catchcmd "-noheader test.db" "" |
| 96 | } {0 {}} |
| 97 | |
| 98 | # -bail stop after hitting an error |
| 99 | do_test shell1-1.6.1 { |
| 100 | catchcmd "-bail test.db" "" |
| 101 | } {0 {}} |
| 102 | |
| 103 | # -interactive force interactive I/O |
| 104 | do_test shell1-1.7.1 { |
| 105 | set res [catchcmd "-interactive test.db" ".quit"] |
| 106 | set rc [lindex $res 0] |
| 107 | list $rc \ |
| 108 | [regexp {SQLite version} $res] \ |
drh | 39a3088 | 2014-02-11 16:22:18 +0000 | [diff] [blame] | 109 | [regexp {Enter ".help" for usage hints} $res] |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 110 | } {0 1 1} |
| 111 | |
| 112 | # -batch force batch I/O |
| 113 | do_test shell1-1.8.1 { |
| 114 | catchcmd "-batch test.db" "" |
| 115 | } {0 {}} |
| 116 | |
| 117 | # -column set output mode to 'column' |
| 118 | do_test shell1-1.9.1 { |
| 119 | catchcmd "-column test.db" "" |
| 120 | } {0 {}} |
| 121 | |
| 122 | # -csv set output mode to 'csv' |
| 123 | do_test shell1-1.10.1 { |
| 124 | catchcmd "-csv test.db" "" |
| 125 | } {0 {}} |
| 126 | |
| 127 | # -html set output mode to HTML |
| 128 | do_test shell1-1.11.1 { |
| 129 | catchcmd "-html test.db" "" |
| 130 | } {0 {}} |
| 131 | |
| 132 | # -line set output mode to 'line' |
| 133 | do_test shell1-1.12.1 { |
| 134 | catchcmd "-line test.db" "" |
| 135 | } {0 {}} |
| 136 | |
| 137 | # -list set output mode to 'list' |
| 138 | do_test shell1-1.13.1 { |
| 139 | catchcmd "-list test.db" "" |
| 140 | } {0 {}} |
| 141 | |
| 142 | # -separator 'x' set output field separator (|) |
| 143 | do_test shell1-1.14.1 { |
| 144 | catchcmd "-separator 'x' test.db" "" |
| 145 | } {0 {}} |
| 146 | do_test shell1-1.14.2 { |
| 147 | catchcmd "-separator x test.db" "" |
| 148 | } {0 {}} |
| 149 | do_test shell1-1.14.3 { |
| 150 | set res [catchcmd "-separator" ""] |
| 151 | set rc [lindex $res 0] |
| 152 | list $rc \ |
drh | 98d312f | 2012-10-25 15:23:14 +0000 | [diff] [blame] | 153 | [regexp {Error: missing argument to -separator} $res] |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 154 | } {1 1} |
| 155 | |
shaneh | 642d8b8 | 2010-07-28 16:05:34 +0000 | [diff] [blame] | 156 | # -stats print memory stats before each finalize |
| 157 | do_test shell1-1.14b.1 { |
| 158 | catchcmd "-stats test.db" "" |
| 159 | } {0 {}} |
| 160 | |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 161 | # -nullvalue 'text' set text string for NULL values |
| 162 | do_test shell1-1.15.1 { |
| 163 | catchcmd "-nullvalue 'x' test.db" "" |
| 164 | } {0 {}} |
| 165 | do_test shell1-1.15.2 { |
| 166 | catchcmd "-nullvalue x test.db" "" |
| 167 | } {0 {}} |
| 168 | do_test shell1-1.15.3 { |
| 169 | set res [catchcmd "-nullvalue" ""] |
| 170 | set rc [lindex $res 0] |
| 171 | list $rc \ |
drh | 98d312f | 2012-10-25 15:23:14 +0000 | [diff] [blame] | 172 | [regexp {Error: missing argument to -nullvalue} $res] |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 173 | } {1 1} |
| 174 | |
| 175 | # -version show SQLite version |
| 176 | do_test shell1-1.16.1 { |
drh | 9fd301b | 2011-06-03 13:28:22 +0000 | [diff] [blame] | 177 | set x [catchcmd "-version test.db" ""] |
drh | b24c61a | 2012-05-21 22:45:35 +0000 | [diff] [blame] | 178 | } {/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] | 179 | |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 180 | #---------------------------------------------------------------------------- |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 181 | # Test cases shell1-2.*: Basic "dot" command token parsing. |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 182 | # |
| 183 | |
| 184 | # check first token handling |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 185 | do_test shell1-2.1.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 186 | catchcmd "test.db" ".foo" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 187 | } {1 {Error: unknown command or invalid arguments: "foo". Enter ".help" for help}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 188 | do_test shell1-2.1.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 189 | catchcmd "test.db" ".\"foo OFF\"" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 190 | } {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 191 | do_test shell1-2.1.3 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 192 | catchcmd "test.db" ".\'foo OFF\'" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 193 | } {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}} |
| 194 | |
| 195 | # unbalanced quotes |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 196 | do_test shell1-2.2.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 197 | catchcmd "test.db" ".\"foo OFF" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 198 | } {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 199 | do_test shell1-2.2.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 200 | catchcmd "test.db" ".\'foo OFF" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 201 | } {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 202 | do_test shell1-2.2.3 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 203 | catchcmd "test.db" ".explain \"OFF" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 204 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 205 | do_test shell1-2.2.4 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 206 | catchcmd "test.db" ".explain \'OFF" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 207 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 208 | do_test shell1-2.2.5 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 209 | catchcmd "test.db" ".mode \"insert FOO" |
mistachkin | 636bf9f | 2014-07-19 20:15:16 +0000 | [diff] [blame] | 210 | } {1 {Error: mode should be one of: ascii column csv html insert line list tabs tcl}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 211 | do_test shell1-2.2.6 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 212 | catchcmd "test.db" ".mode \'insert FOO" |
mistachkin | 636bf9f | 2014-07-19 20:15:16 +0000 | [diff] [blame] | 213 | } {1 {Error: mode should be one of: ascii column csv html insert line list tabs tcl}} |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 214 | |
| 215 | # check multiple tokens, and quoted tokens |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 216 | do_test shell1-2.3.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 217 | catchcmd "test.db" ".explain 1" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 218 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 219 | do_test shell1-2.3.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 220 | catchcmd "test.db" ".explain on" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 221 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 222 | do_test shell1-2.3.3 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 223 | catchcmd "test.db" ".explain \"1 2 3\"" |
drh | 173ba09 | 2013-01-28 18:18:26 +0000 | [diff] [blame] | 224 | } {1 {ERROR: Not a boolean value: "1 2 3". Assuming "no".}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 225 | do_test shell1-2.3.4 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 226 | catchcmd "test.db" ".explain \"OFF\"" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 227 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 228 | do_test shell1-2.3.5 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 229 | catchcmd "test.db" ".\'explain\' \'OFF\'" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 230 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 231 | do_test shell1-2.3.6 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 232 | catchcmd "test.db" ".explain \'OFF\'" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 233 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 234 | do_test shell1-2.3.7 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 235 | catchcmd "test.db" ".\'explain\' \'OFF\'" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 236 | } {0 {}} |
| 237 | |
| 238 | # check quoted args are unquoted |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 239 | do_test shell1-2.4.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 240 | catchcmd "test.db" ".mode FOO" |
mistachkin | 636bf9f | 2014-07-19 20:15:16 +0000 | [diff] [blame] | 241 | } {1 {Error: mode should be one of: ascii column csv html insert line list tabs tcl}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 242 | do_test shell1-2.4.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 243 | catchcmd "test.db" ".mode csv" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 244 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 245 | do_test shell1-2.4.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 246 | catchcmd "test.db" ".mode \"csv\"" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 247 | } {0 {}} |
| 248 | |
| 249 | |
| 250 | #---------------------------------------------------------------------------- |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 251 | # Test cases shell1-3.*: Basic test that "dot" command can be called. |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 252 | # |
| 253 | |
| 254 | # .backup ?DB? FILE Backup DB (default "main") to FILE |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 255 | do_test shell1-3.1.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 256 | catchcmd "test.db" ".backup" |
drh | bc46f02 | 2013-01-23 18:53:23 +0000 | [diff] [blame] | 257 | } {1 {missing FILENAME argument on .backup}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 258 | do_test shell1-3.1.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 259 | catchcmd "test.db" ".backup FOO" |
| 260 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 261 | do_test shell1-3.1.3 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 262 | catchcmd "test.db" ".backup FOO BAR" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 263 | } {1 {Error: unknown database FOO}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 264 | do_test shell1-3.1.4 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 265 | # too many arguments |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 266 | catchcmd "test.db" ".backup FOO BAR BAD" |
drh | bc46f02 | 2013-01-23 18:53:23 +0000 | [diff] [blame] | 267 | } {1 {too many arguments to .backup}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 268 | |
| 269 | # .bail ON|OFF Stop after hitting an error. Default OFF |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 270 | do_test shell1-3.2.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 271 | catchcmd "test.db" ".bail" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 272 | } {1 {Usage: .bail on|off}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 273 | do_test shell1-3.2.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 274 | catchcmd "test.db" ".bail ON" |
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.3 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 277 | catchcmd "test.db" ".bail OFF" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 278 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 279 | do_test shell1-3.2.4 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 280 | # too many arguments |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 281 | catchcmd "test.db" ".bail OFF BAD" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 282 | } {1 {Usage: .bail on|off}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 283 | |
| 284 | # .databases List names and files of attached databases |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 285 | do_test shell1-3.3.1 { |
drh | e4d3195 | 2012-05-12 01:14:27 +0000 | [diff] [blame] | 286 | catchcmd "-csv test.db" ".databases" |
mistachkin | 86ab48f | 2012-05-22 19:25:51 +0000 | [diff] [blame] | 287 | } "/0 +.*main +[string map {/ .} [string range [get_pwd] 0 10]].*/" |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 288 | do_test shell1-3.3.2 { |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 289 | # extra arguments ignored |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 290 | catchcmd "test.db" ".databases BAD" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 291 | } "/0 +.*main +[string map {/ .} [string range [get_pwd] 0 10]].*/" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 292 | |
| 293 | # .dump ?TABLE? ... Dump the database in an SQL text format |
| 294 | # If TABLE specified, only dump tables matching |
| 295 | # LIKE pattern TABLE. |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 296 | do_test shell1-3.4.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 297 | set res [catchcmd "test.db" ".dump"] |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 298 | list [regexp {BEGIN TRANSACTION;} $res] \ |
| 299 | [regexp {COMMIT;} $res] |
| 300 | } {1 1} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 301 | do_test shell1-3.4.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 302 | set res [catchcmd "test.db" ".dump FOO"] |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 303 | list [regexp {BEGIN TRANSACTION;} $res] \ |
| 304 | [regexp {COMMIT;} $res] |
| 305 | } {1 1} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 306 | do_test shell1-3.4.3 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 307 | # too many arguments |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 308 | catchcmd "test.db" ".dump FOO BAD" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 309 | } {1 {Usage: .dump ?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) |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 387 | set res [catchcmd "test.db" ".help BAD"] |
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 | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 397 | } {1 {Usage: .import FILE TABLE}} |
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 | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 400 | } {1 {Usage: .import FILE TABLE}} |
drh | db95f68 | 2013-06-26 22:46:00 +0000 | [diff] [blame] | 401 | #do_test shell1-3.11.2 { |
| 402 | # catchcmd "test.db" ".import FOO BAR" |
| 403 | #} {1 {Error: no such table: BAR}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 404 | do_test shell1-3.11.3 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 405 | # too many arguments |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 406 | catchcmd "test.db" ".import FOO BAR BAD" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 407 | } {1 {Usage: .import FILE TABLE}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 408 | |
drh | 0e55db1 | 2015-02-06 14:51:13 +0000 | [diff] [blame] | 409 | # .indexes ?TABLE? Show names of all indexes |
| 410 | # If TABLE specified, only show indexes for tables |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 411 | # matching LIKE pattern TABLE. |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 412 | do_test shell1-3.12.1 { |
drh | 0e55db1 | 2015-02-06 14:51:13 +0000 | [diff] [blame] | 413 | catchcmd "test.db" ".indexes" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 414 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 415 | do_test shell1-3.12.2 { |
drh | 0e55db1 | 2015-02-06 14:51:13 +0000 | [diff] [blame] | 416 | catchcmd "test.db" ".indexes FOO" |
| 417 | } {0 {}} |
| 418 | do_test shell1-3.12.2-legacy { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 419 | catchcmd "test.db" ".indices FOO" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 420 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 421 | do_test shell1-3.12.3 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 422 | # too many arguments |
drh | 0e55db1 | 2015-02-06 14:51:13 +0000 | [diff] [blame] | 423 | catchcmd "test.db" ".indexes FOO BAD" |
| 424 | } {1 {Usage: .indexes ?LIKE-PATTERN?}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 425 | |
| 426 | # .mode MODE ?TABLE? Set output mode where MODE is one of: |
mistachkin | e0d6885 | 2014-12-11 03:12:33 +0000 | [diff] [blame] | 427 | # ascii Columns/rows delimited by 0x1F and 0x1E |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 428 | # csv Comma-separated values |
| 429 | # column Left-aligned columns. (See .width) |
| 430 | # html HTML <table> code |
| 431 | # insert SQL insert statements for TABLE |
| 432 | # line One value per line |
mistachkin | e0d6885 | 2014-12-11 03:12:33 +0000 | [diff] [blame] | 433 | # list Values delimited by .separator strings |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 434 | # tabs Tab-separated values |
| 435 | # tcl TCL list elements |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 436 | do_test shell1-3.13.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 437 | catchcmd "test.db" ".mode" |
mistachkin | 636bf9f | 2014-07-19 20:15:16 +0000 | [diff] [blame] | 438 | } {1 {Error: mode should be one of: ascii column csv html insert line list tabs tcl}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 439 | do_test shell1-3.13.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 440 | catchcmd "test.db" ".mode FOO" |
mistachkin | 636bf9f | 2014-07-19 20:15:16 +0000 | [diff] [blame] | 441 | } {1 {Error: mode should be one of: ascii column csv html insert line list tabs tcl}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 442 | do_test shell1-3.13.3 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 443 | catchcmd "test.db" ".mode csv" |
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.4 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 446 | catchcmd "test.db" ".mode column" |
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.5 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 449 | catchcmd "test.db" ".mode html" |
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.6 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 452 | catchcmd "test.db" ".mode insert" |
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.7 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 455 | catchcmd "test.db" ".mode line" |
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.8 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 458 | catchcmd "test.db" ".mode list" |
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.9 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 461 | catchcmd "test.db" ".mode tabs" |
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.10 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 464 | catchcmd "test.db" ".mode tcl" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 465 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 466 | do_test shell1-3.13.11 { |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 467 | # extra arguments ignored |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 468 | catchcmd "test.db" ".mode tcl BAD" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 469 | } {0 {}} |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 470 | |
| 471 | # don't allow partial mode type matches |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 472 | do_test shell1-3.13.12 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 473 | catchcmd "test.db" ".mode l" |
mistachkin | 636bf9f | 2014-07-19 20:15:16 +0000 | [diff] [blame] | 474 | } {1 {Error: mode should be one of: ascii column csv html insert line list tabs tcl}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 475 | do_test shell1-3.13.13 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 476 | catchcmd "test.db" ".mode li" |
mistachkin | 636bf9f | 2014-07-19 20:15:16 +0000 | [diff] [blame] | 477 | } {1 {Error: mode should be one of: ascii column csv html insert line list tabs tcl}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 478 | do_test shell1-3.13.14 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 479 | catchcmd "test.db" ".mode lin" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 480 | } {0 {}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 481 | |
| 482 | # .nullvalue STRING Print STRING in place of NULL values |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 483 | do_test shell1-3.14.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 484 | catchcmd "test.db" ".nullvalue" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 485 | } {1 {Usage: .nullvalue STRING}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 486 | do_test shell1-3.14.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 487 | catchcmd "test.db" ".nullvalue FOO" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 488 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 489 | do_test shell1-3.14.3 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 490 | # too many arguments |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 491 | catchcmd "test.db" ".nullvalue FOO BAD" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 492 | } {1 {Usage: .nullvalue STRING}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 493 | |
| 494 | # .output FILENAME Send output to FILENAME |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 495 | do_test shell1-3.15.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 496 | catchcmd "test.db" ".output" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 497 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 498 | do_test shell1-3.15.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 499 | catchcmd "test.db" ".output FOO" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 500 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 501 | do_test shell1-3.15.3 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 502 | # too many arguments |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 503 | catchcmd "test.db" ".output FOO BAD" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 504 | } {1 {Usage: .output FILE}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 505 | |
| 506 | # .output stdout Send output to the screen |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 507 | do_test shell1-3.16.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 508 | catchcmd "test.db" ".output stdout" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 509 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 510 | do_test shell1-3.16.2 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 511 | # too many arguments |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 512 | catchcmd "test.db" ".output stdout BAD" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 513 | } {1 {Usage: .output FILE}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 514 | |
| 515 | # .prompt MAIN CONTINUE Replace the standard prompts |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 516 | do_test shell1-3.17.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 517 | catchcmd "test.db" ".prompt" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 518 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 519 | do_test shell1-3.17.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 520 | catchcmd "test.db" ".prompt FOO" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 521 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 522 | do_test shell1-3.17.3 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 523 | catchcmd "test.db" ".prompt FOO BAR" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 524 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 525 | do_test shell1-3.17.4 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 526 | # too many arguments |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 527 | catchcmd "test.db" ".prompt FOO BAR BAD" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 528 | } {0 {}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 529 | |
| 530 | # .quit Exit this program |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 531 | do_test shell1-3.18.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 532 | catchcmd "test.db" ".quit" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 533 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 534 | do_test shell1-3.18.2 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 535 | # too many arguments |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 536 | catchcmd "test.db" ".quit BAD" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 537 | } {0 {}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 538 | |
| 539 | # .read FILENAME Execute SQL in FILENAME |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 540 | do_test shell1-3.19.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 541 | catchcmd "test.db" ".read" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 542 | } {1 {Usage: .read FILE}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 543 | do_test shell1-3.19.2 { |
mistachkin | 9ac9931 | 2013-09-13 23:26:47 +0000 | [diff] [blame] | 544 | forcedelete FOO |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 545 | catchcmd "test.db" ".read FOO" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 546 | } {1 {Error: cannot open "FOO"}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 547 | do_test shell1-3.19.3 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 548 | # too many arguments |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 549 | catchcmd "test.db" ".read FOO BAD" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 550 | } {1 {Usage: .read FILE}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 551 | |
| 552 | # .restore ?DB? FILE Restore content of DB (default "main") from FILE |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 553 | do_test shell1-3.20.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 554 | catchcmd "test.db" ".restore" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 555 | } {1 {Usage: .restore ?DB? FILE}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 556 | do_test shell1-3.20.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 557 | catchcmd "test.db" ".restore FOO" |
| 558 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 559 | do_test shell1-3.20.3 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 560 | catchcmd "test.db" ".restore FOO BAR" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 561 | } {1 {Error: unknown database FOO}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 562 | do_test shell1-3.20.4 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 563 | # too many arguments |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 564 | catchcmd "test.db" ".restore FOO BAR BAD" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 565 | } {1 {Usage: .restore ?DB? FILE}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 566 | |
| 567 | # .schema ?TABLE? Show the CREATE statements |
| 568 | # If TABLE specified, only show tables matching |
| 569 | # LIKE pattern TABLE. |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 570 | do_test shell1-3.21.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 571 | catchcmd "test.db" ".schema" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 572 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 573 | do_test shell1-3.21.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 574 | catchcmd "test.db" ".schema FOO" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 575 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 576 | do_test shell1-3.21.3 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 577 | # too many arguments |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 578 | catchcmd "test.db" ".schema FOO BAD" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 579 | } {1 {Usage: .schema ?LIKE-PATTERN?}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 580 | |
drh | ac43e98 | 2012-05-21 03:15:06 +0000 | [diff] [blame] | 581 | do_test shell1-3.21.4 { |
| 582 | catchcmd "test.db" { |
| 583 | CREATE TABLE t1(x); |
| 584 | CREATE VIEW v2 AS SELECT x+1 AS y FROM t1; |
| 585 | CREATE VIEW v1 AS SELECT y+1 FROM v2; |
| 586 | } |
| 587 | catchcmd "test.db" ".schema" |
| 588 | } {0 {CREATE TABLE t1(x); |
| 589 | CREATE VIEW v2 AS SELECT x+1 AS y FROM t1; |
| 590 | CREATE VIEW v1 AS SELECT y+1 FROM v2;}} |
| 591 | db eval {DROP VIEW v1; DROP VIEW v2; DROP TABLE t1;} |
| 592 | |
mistachkin | 636bf9f | 2014-07-19 20:15:16 +0000 | [diff] [blame] | 593 | # .separator STRING Change column separator used by output and .import |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 594 | do_test shell1-3.22.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 595 | catchcmd "test.db" ".separator" |
mistachkin | e0d6885 | 2014-12-11 03:12:33 +0000 | [diff] [blame] | 596 | } {1 {Usage: .separator COL ?ROW?}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 597 | do_test shell1-3.22.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 598 | catchcmd "test.db" ".separator FOO" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 599 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 600 | do_test shell1-3.22.3 { |
drh | 6976c21 | 2014-07-24 12:09:47 +0000 | [diff] [blame] | 601 | catchcmd "test.db" ".separator ABC XYZ" |
| 602 | } {0 {}} |
| 603 | do_test shell1-3.22.4 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 604 | # too many arguments |
drh | 6976c21 | 2014-07-24 12:09:47 +0000 | [diff] [blame] | 605 | catchcmd "test.db" ".separator FOO BAD BAD2" |
mistachkin | e0d6885 | 2014-12-11 03:12:33 +0000 | [diff] [blame] | 606 | } {1 {Usage: .separator COL ?ROW?}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 607 | |
| 608 | # .show Show the current values for various settings |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 609 | do_test shell1-3.23.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 610 | set res [catchcmd "test.db" ".show"] |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 611 | list [regexp {echo:} $res] \ |
| 612 | [regexp {explain:} $res] \ |
| 613 | [regexp {headers:} $res] \ |
| 614 | [regexp {mode:} $res] \ |
| 615 | [regexp {nullvalue:} $res] \ |
| 616 | [regexp {output:} $res] \ |
mistachkin | 636bf9f | 2014-07-19 20:15:16 +0000 | [diff] [blame] | 617 | [regexp {colseparator:} $res] \ |
| 618 | [regexp {rowseparator:} $res] \ |
shaneh | 642d8b8 | 2010-07-28 16:05:34 +0000 | [diff] [blame] | 619 | [regexp {stats:} $res] \ |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 620 | [regexp {width:} $res] |
mistachkin | e0d6885 | 2014-12-11 03:12:33 +0000 | [diff] [blame] | 621 | } {1 1 1 1 1 1 1 1 1 1} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 622 | do_test shell1-3.23.2 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 623 | # too many arguments |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 624 | catchcmd "test.db" ".show BAD" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 625 | } {1 {Usage: .show}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 626 | |
shaneh | 642d8b8 | 2010-07-28 16:05:34 +0000 | [diff] [blame] | 627 | # .stats ON|OFF Turn stats on or off |
| 628 | do_test shell1-3.23b.1 { |
| 629 | catchcmd "test.db" ".stats" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 630 | } {1 {Usage: .stats on|off}} |
shaneh | 642d8b8 | 2010-07-28 16:05:34 +0000 | [diff] [blame] | 631 | do_test shell1-3.23b.2 { |
| 632 | catchcmd "test.db" ".stats ON" |
| 633 | } {0 {}} |
| 634 | do_test shell1-3.23b.3 { |
| 635 | catchcmd "test.db" ".stats OFF" |
| 636 | } {0 {}} |
| 637 | do_test shell1-3.23b.4 { |
| 638 | # too many arguments |
| 639 | catchcmd "test.db" ".stats OFF BAD" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 640 | } {1 {Usage: .stats on|off}} |
shaneh | 642d8b8 | 2010-07-28 16:05:34 +0000 | [diff] [blame] | 641 | |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 642 | # .tables ?TABLE? List names of tables |
| 643 | # If TABLE specified, only list tables matching |
| 644 | # LIKE pattern TABLE. |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 645 | do_test shell1-3.24.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 646 | catchcmd "test.db" ".tables" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 647 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 648 | do_test shell1-3.24.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 649 | catchcmd "test.db" ".tables FOO" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 650 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 651 | do_test shell1-3.24.3 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 652 | # too many arguments |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 653 | catchcmd "test.db" ".tables FOO BAD" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 654 | } {0 {}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 655 | |
| 656 | # .timeout MS Try opening locked tables for MS milliseconds |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 657 | do_test shell1-3.25.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 658 | catchcmd "test.db" ".timeout" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 659 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 660 | do_test shell1-3.25.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 661 | catchcmd "test.db" ".timeout zzz" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 662 | # this should be treated the same as a '0' timeout |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 663 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 664 | do_test shell1-3.25.3 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 665 | catchcmd "test.db" ".timeout 1" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 666 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 667 | do_test shell1-3.25.4 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 668 | # too many arguments |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 669 | catchcmd "test.db" ".timeout 1 BAD" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 670 | } {0 {}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 671 | |
| 672 | # .width NUM NUM ... Set column widths for "column" mode |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 673 | do_test shell1-3.26.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 674 | catchcmd "test.db" ".width" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 675 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 676 | do_test shell1-3.26.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 677 | catchcmd "test.db" ".width xxx" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 678 | # this should be treated the same as a '0' width for col 1 |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 679 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 680 | do_test shell1-3.26.3 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 681 | catchcmd "test.db" ".width xxx yyy" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 682 | # 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] | 683 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 684 | do_test shell1-3.26.4 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 685 | catchcmd "test.db" ".width 1 1" |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 686 | # 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] | 687 | } {0 {}} |
drh | 078b1fd | 2012-09-21 13:40:02 +0000 | [diff] [blame] | 688 | do_test shell1-3.26.5 { |
| 689 | catchcmd "test.db" ".mode column\n.width 10 -10\nSELECT 'abcdefg', 123456;" |
| 690 | # this should be treated the same as a '1' width for col 1 and 2 |
| 691 | } {0 {abcdefg 123456}} |
| 692 | do_test shell1-3.26.6 { |
| 693 | catchcmd "test.db" ".mode column\n.width -10 10\nSELECT 'abcdefg', 123456;" |
| 694 | # this should be treated the same as a '1' width for col 1 and 2 |
| 695 | } {0 { abcdefg 123456 }} |
| 696 | |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 697 | |
| 698 | # .timer ON|OFF Turn the CPU timer measurement on or off |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 699 | do_test shell1-3.27.1 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 700 | catchcmd "test.db" ".timer" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 701 | } {1 {Usage: .timer on|off}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 702 | do_test shell1-3.27.2 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 703 | catchcmd "test.db" ".timer ON" |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 704 | } {0 {}} |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 705 | do_test shell1-3.27.3 { |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 706 | catchcmd "test.db" ".timer OFF" |
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.27.4 { |
shaneh | e2aa9d7 | 2009-11-06 17:20:17 +0000 | [diff] [blame] | 709 | # too many arguments |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 710 | catchcmd "test.db" ".timer OFF BAD" |
drh | c2ce0be | 2014-05-29 12:36:14 +0000 | [diff] [blame] | 711 | } {1 {Usage: .timer on|off}} |
shaneh | a05e0c4 | 2009-11-06 03:22:54 +0000 | [diff] [blame] | 712 | |
drh | 53a9d15 | 2011-04-25 18:20:04 +0000 | [diff] [blame] | 713 | do_test shell1-3-28.1 { |
| 714 | catchcmd test.db \ |
| 715 | ".log stdout\nSELECT coalesce(sqlite_log(123,'hello'),'456');" |
| 716 | } "0 {(123) hello\n456}" |
| 717 | |
drh | 078b1fd | 2012-09-21 13:40:02 +0000 | [diff] [blame] | 718 | do_test shell1-3-29.1 { |
| 719 | catchcmd "test.db" ".print this is a test" |
| 720 | } {0 {this is a test}} |
| 721 | |
drh | 4c56b99 | 2013-06-27 13:26:55 +0000 | [diff] [blame] | 722 | # dot-command argument quoting |
| 723 | do_test shell1-3-30.1 { |
| 724 | catchcmd {test.db} {.print "this\"is'a\055test" 'this\"is\\a\055test'} |
| 725 | } {0 {this"is'a-test this\"is\\a\055test}} |
| 726 | do_test shell1-3-31.1 { |
| 727 | catchcmd {test.db} {.print "this\nis\ta\\test" 'this\nis\ta\\test'} |
| 728 | } [list 0 "this\nis\ta\\test this\\nis\\ta\\\\test"] |
| 729 | |
| 730 | |
drh | 5128e85 | 2012-04-24 13:14:49 +0000 | [diff] [blame] | 731 | # Test the output of the ".dump" command |
| 732 | # |
| 733 | do_test shell1-4.1 { |
drh | 55a1b30 | 2013-09-04 16:08:50 +0000 | [diff] [blame] | 734 | db close |
| 735 | forcedelete test.db |
| 736 | sqlite3 db test.db |
drh | 5128e85 | 2012-04-24 13:14:49 +0000 | [diff] [blame] | 737 | db eval { |
drh | 55a1b30 | 2013-09-04 16:08:50 +0000 | [diff] [blame] | 738 | PRAGMA encoding=UTF16; |
drh | 5128e85 | 2012-04-24 13:14:49 +0000 | [diff] [blame] | 739 | CREATE TABLE t1(x); |
mistachkin | 585dcb2 | 2012-12-04 00:23:43 +0000 | [diff] [blame] | 740 | INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f'); |
mistachkin | 151c75a | 2015-04-07 21:16:40 +0000 | [diff] [blame] | 741 | CREATE TABLE t3(x,y); |
| 742 | INSERT INTO t3 VALUES(1,null), (2,''), (3,1), |
| 743 | (4,2.25), (5,'hello'), (6,x'807f'); |
drh | 5128e85 | 2012-04-24 13:14:49 +0000 | [diff] [blame] | 744 | } |
| 745 | catchcmd test.db {.dump} |
| 746 | } {0 {PRAGMA foreign_keys=OFF; |
| 747 | BEGIN TRANSACTION; |
| 748 | CREATE TABLE t1(x); |
| 749 | INSERT INTO "t1" VALUES(NULL); |
mistachkin | 585dcb2 | 2012-12-04 00:23:43 +0000 | [diff] [blame] | 750 | INSERT INTO "t1" VALUES(''); |
drh | 5128e85 | 2012-04-24 13:14:49 +0000 | [diff] [blame] | 751 | INSERT INTO "t1" VALUES(1); |
| 752 | INSERT INTO "t1" VALUES(2.25); |
| 753 | INSERT INTO "t1" VALUES('hello'); |
| 754 | INSERT INTO "t1" VALUES(X'807F'); |
mistachkin | 151c75a | 2015-04-07 21:16:40 +0000 | [diff] [blame] | 755 | CREATE TABLE t3(x,y); |
| 756 | INSERT INTO "t3" VALUES(1,NULL); |
| 757 | INSERT INTO "t3" VALUES(2,''); |
| 758 | INSERT INTO "t3" VALUES(3,1); |
| 759 | INSERT INTO "t3" VALUES(4,2.25); |
| 760 | INSERT INTO "t3" VALUES(5,'hello'); |
| 761 | INSERT INTO "t3" VALUES(6,X'807F'); |
drh | 5128e85 | 2012-04-24 13:14:49 +0000 | [diff] [blame] | 762 | COMMIT;}} |
| 763 | |
| 764 | # Test the output of ".mode insert" |
| 765 | # |
mistachkin | 151c75a | 2015-04-07 21:16:40 +0000 | [diff] [blame] | 766 | do_test shell1-4.2.1 { |
drh | 5128e85 | 2012-04-24 13:14:49 +0000 | [diff] [blame] | 767 | catchcmd test.db ".mode insert t1\nselect * from t1;" |
| 768 | } {0 {INSERT INTO t1 VALUES(NULL); |
mistachkin | 585dcb2 | 2012-12-04 00:23:43 +0000 | [diff] [blame] | 769 | INSERT INTO t1 VALUES(''); |
drh | 5128e85 | 2012-04-24 13:14:49 +0000 | [diff] [blame] | 770 | INSERT INTO t1 VALUES(1); |
| 771 | INSERT INTO t1 VALUES(2.25); |
| 772 | INSERT INTO t1 VALUES('hello'); |
| 773 | INSERT INTO t1 VALUES(X'807f');}} |
| 774 | |
mistachkin | 151c75a | 2015-04-07 21:16:40 +0000 | [diff] [blame] | 775 | # Test the output of ".mode insert" with headers |
| 776 | # |
| 777 | do_test shell1-4.2.2 { |
| 778 | catchcmd test.db ".mode insert t1\n.headers on\nselect * from t1;" |
| 779 | } {0 {INSERT INTO t1(x) VALUES(NULL); |
| 780 | INSERT INTO t1(x) VALUES(''); |
| 781 | INSERT INTO t1(x) VALUES(1); |
| 782 | INSERT INTO t1(x) VALUES(2.25); |
| 783 | INSERT INTO t1(x) VALUES('hello'); |
| 784 | INSERT INTO t1(x) VALUES(X'807f');}} |
| 785 | |
| 786 | # Test the output of ".mode insert" |
| 787 | # |
| 788 | do_test shell1-4.2.3 { |
| 789 | catchcmd test.db ".mode insert t3\nselect * from t3;" |
| 790 | } {0 {INSERT INTO t3 VALUES(1,NULL); |
| 791 | INSERT INTO t3 VALUES(2,''); |
| 792 | INSERT INTO t3 VALUES(3,1); |
| 793 | INSERT INTO t3 VALUES(4,2.25); |
| 794 | INSERT INTO t3 VALUES(5,'hello'); |
| 795 | INSERT INTO t3 VALUES(6,X'807f');}} |
| 796 | |
| 797 | # Test the output of ".mode insert" with headers |
| 798 | # |
mistachkin | cc44540 | 2015-04-07 21:17:53 +0000 | [diff] [blame] | 799 | do_test shell1-4.2.4 { |
mistachkin | 151c75a | 2015-04-07 21:16:40 +0000 | [diff] [blame] | 800 | catchcmd test.db ".mode insert t3\n.headers on\nselect * from t3;" |
| 801 | } {0 {INSERT INTO t3(x,y) VALUES(1,NULL); |
| 802 | INSERT INTO t3(x,y) VALUES(2,''); |
| 803 | INSERT INTO t3(x,y) VALUES(3,1); |
| 804 | INSERT INTO t3(x,y) VALUES(4,2.25); |
| 805 | INSERT INTO t3(x,y) VALUES(5,'hello'); |
| 806 | INSERT INTO t3(x,y) VALUES(6,X'807f');}} |
| 807 | |
mistachkin | 585dcb2 | 2012-12-04 00:23:43 +0000 | [diff] [blame] | 808 | # Test the output of ".mode tcl" |
| 809 | # |
| 810 | do_test shell1-4.3 { |
drh | 55a1b30 | 2013-09-04 16:08:50 +0000 | [diff] [blame] | 811 | db close |
| 812 | forcedelete test.db |
| 813 | sqlite3 db test.db |
| 814 | db eval { |
| 815 | PRAGMA encoding=UTF8; |
| 816 | CREATE TABLE t1(x); |
| 817 | INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f'); |
| 818 | } |
mistachkin | 585dcb2 | 2012-12-04 00:23:43 +0000 | [diff] [blame] | 819 | catchcmd test.db ".mode tcl\nselect * from t1;" |
| 820 | } {0 {"" |
| 821 | "" |
| 822 | "1" |
| 823 | "2.25" |
| 824 | "hello" |
| 825 | "\200\177"}} |
| 826 | |
| 827 | # Test the output of ".mode tcl" with multiple columns |
| 828 | # |
| 829 | do_test shell1-4.4 { |
| 830 | db eval { |
| 831 | CREATE TABLE t2(x,y); |
| 832 | INSERT INTO t2 VALUES(null, ''), (1, 2.25), ('hello', x'807f'); |
| 833 | } |
| 834 | catchcmd test.db ".mode tcl\nselect * from t2;" |
| 835 | } {0 {"" "" |
| 836 | "1" "2.25" |
| 837 | "hello" "\200\177"}} |
| 838 | |
| 839 | # Test the output of ".mode tcl" with ".nullvalue" |
| 840 | # |
| 841 | do_test shell1-4.5 { |
| 842 | catchcmd test.db ".mode tcl\n.nullvalue NULL\nselect * from t2;" |
| 843 | } {0 {"NULL" "" |
| 844 | "1" "2.25" |
| 845 | "hello" "\200\177"}} |
| 846 | |
| 847 | # Test the output of ".mode tcl" with Tcl reserved characters |
| 848 | # |
| 849 | do_test shell1-4.6 { |
| 850 | db eval { |
| 851 | CREATE TABLE tcl1(x); |
| 852 | INSERT INTO tcl1 VALUES('"'), ('['), (']'), ('\{'), ('\}'), (';'), ('$'); |
| 853 | } |
| 854 | foreach {x y} [catchcmd test.db ".mode tcl\nselect * from tcl1;"] break |
| 855 | list $x $y [llength $y] |
| 856 | } {0 {"\"" |
| 857 | "[" |
| 858 | "]" |
| 859 | "\\{" |
| 860 | "\\}" |
| 861 | ";" |
| 862 | "$"} 7} |
drh | 5128e85 | 2012-04-24 13:14:49 +0000 | [diff] [blame] | 863 | |
mistachkin | f21979d | 2015-01-18 05:35:01 +0000 | [diff] [blame] | 864 | # Test using arbitrary byte data with the shell via standard input/output. |
| 865 | # |
| 866 | do_test shell1-5.0 { |
| 867 | # |
| 868 | # NOTE: Skip NUL byte because it appears to be incompatible with command |
| 869 | # shell argument parsing. |
| 870 | # |
| 871 | for {set i 1} {$i < 256} {incr i} { |
| 872 | # |
mistachkin | 46a6b99 | 2015-01-18 09:02:57 +0000 | [diff] [blame] | 873 | # NOTE: Due to how the Tcl [exec] command works (i.e. where it treats |
| 874 | # command channels opened for it as textual ones), the carriage |
| 875 | # return character (and on Windows, the end-of-file character) |
| 876 | # cannot be used here. |
mistachkin | f21979d | 2015-01-18 05:35:01 +0000 | [diff] [blame] | 877 | # |
mistachkin | 46a6b99 | 2015-01-18 09:02:57 +0000 | [diff] [blame] | 878 | if {$i==0x0D || ($tcl_platform(platform)=="windows" && $i==0x1A)} { |
mistachkin | f21979d | 2015-01-18 05:35:01 +0000 | [diff] [blame] | 879 | continue |
| 880 | } |
| 881 | set hex [format %02X $i] |
| 882 | set char [subst \\x$hex]; set oldChar $char |
mistachkin | 0acee51 | 2015-01-19 21:11:31 +0000 | [diff] [blame] | 883 | set escapes [list] |
| 884 | if {$tcl_platform(platform)=="windows"} { |
| 885 | # |
| 886 | # NOTE: On Windows, we need to escape all the whitespace characters, |
| 887 | # the alarm (\a) character, and those with special meaning to |
| 888 | # the SQLite shell itself. |
| 889 | # |
| 890 | set escapes [list \ |
| 891 | \a \\a \b \\b \t \\t \n \\n \v \\v \f \\f \r \\r \ |
| 892 | " " "\" \"" \" \\\" ' \"'\" \\ \\\\] |
| 893 | } else { |
| 894 | # |
| 895 | # NOTE: On Unix, we need to escape most of the whitespace characters |
| 896 | # and those with special meaning to the SQLite shell itself. |
| 897 | # The alarm (\a), backspace (\b), and carriage-return (\r) |
| 898 | # characters do not appear to require escaping on Unix. For |
| 899 | # the alarm and backspace characters, this is probably due to |
| 900 | # differences in the command shell. For the carriage-return, |
| 901 | # it is probably due to differences in how Tcl handles command |
| 902 | # channel end-of-line translations. |
| 903 | # |
| 904 | set escapes [list \ |
| 905 | \t \\t \n \\n \v \\v \f \\f \ |
| 906 | " " "\" \"" \" \\\" ' \"'\" \\ \\\\] |
| 907 | } |
| 908 | set char [string map $escapes $char] |
mistachkin | bfefa4c | 2015-01-19 21:27:46 +0000 | [diff] [blame] | 909 | set x [catchcmdex test.db ".print $char\n"] |
mistachkin | f21979d | 2015-01-18 05:35:01 +0000 | [diff] [blame] | 910 | set code [lindex $x 0] |
| 911 | set res [lindex $x 1] |
| 912 | if {$code ne "0"} { |
| 913 | error "failed with error: $res" |
| 914 | } |
| 915 | if {$res ne "$oldChar\n"} { |
| 916 | error "failed with byte $hex mismatch" |
| 917 | } |
| 918 | } |
| 919 | } {} |
| 920 | |
drh | 8df9185 | 2012-04-24 12:46:05 +0000 | [diff] [blame] | 921 | finish_test |