| 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 |
# |
| 14 |
# TESTRUNNER: shell |
| 15 |
# |
| 16 |
|
| 17 |
# Test plan: |
| 18 |
# |
| 19 |
# shell1-1.*: Basic command line option handling. |
| 20 |
# shell1-2.*: Basic "dot" command token parsing. |
| 21 |
# shell1-3.*: Basic test that "dot" command can be called. |
| 22 |
# shell1-{4-8}.*: Test various "dot" commands's functionality. |
| 23 |
# shell1-9.*: Basic test that "dot" commands and SQL intermix ok. |
| 24 |
# |
| 25 |
set testdir [file dirname $argv0] |
| 26 |
source $testdir/tester.tcl |
| 27 |
set CLI [test_cli_invocation] |
| 28 |
db close |
| 29 |
forcedelete test.db test.db-journal test.db-wal |
| 30 |
sqlite3 db test.db |
| 31 |
|
| 32 |
#---------------------------------------------------------------------------- |
| 33 |
# Test cases shell1-1.*: Basic command line option handling. |
| 34 |
# |
| 35 |
|
| 36 |
# invalid option |
| 37 |
do_test shell1-1.1.1 { |
| 38 |
set res [catchcmd "-bad test.db" ""] |
| 39 |
set rc [lindex $res 0] |
| 40 |
list $rc \ |
| 41 |
[regexp {Error: unknown option: -bad} $res] |
| 42 |
} {1 1} |
| 43 |
do_test shell1-1.1.1b { |
| 44 |
set res [catchcmd "test.db -bad" ""] |
| 45 |
set rc [lindex $res 0] |
| 46 |
list $rc \ |
| 47 |
[regexp {Error: unknown option: -bad} $res] |
| 48 |
} {1 1} |
| 49 |
# error on extra options |
| 50 |
do_test shell1-1.1.2 { |
| 51 |
catchcmd "test.db \"select+3\" \"select+4\"" "" |
| 52 |
} {0 {3 |
| 53 |
4}} |
| 54 |
# error on extra options |
| 55 |
do_test shell1-1.1.3 { |
| 56 |
catchcmd "test.db FOO test.db BAD" ".quit" |
| 57 |
} {/1 .Parse error in 2nd command line argument: near "FOO": syntax error*/} |
| 58 |
|
| 59 |
# -help |
| 60 |
do_test shell1-1.2.1 { |
| 61 |
set res [catchcmd "-help test.db" ""] |
| 62 |
set rc [lindex $res 0] |
| 63 |
list $rc \ |
| 64 |
[regexp {Usage} $res] \ |
| 65 |
[regexp {\-init} $res] \ |
| 66 |
[regexp {\-version} $res] |
| 67 |
} {1 1 1 1} |
| 68 |
|
| 69 |
# -init filename read/process named file |
| 70 |
forcedelete FOO |
| 71 |
set out [open FOO w] |
| 72 |
puts $out "" |
| 73 |
close $out |
| 74 |
do_test shell1-1.3.1 { |
| 75 |
catchcmd "-init FOO test.db" "" |
| 76 |
} {0 {}} |
| 77 |
do_test shell1-1.3.2 { |
| 78 |
catchcmd "-init FOO test.db .quit BAD" "" |
| 79 |
} {0 {}} |
| 80 |
do_test shell1-1.3.3 { |
| 81 |
catchcmd "-init FOO test.db BAD .quit" "" |
| 82 |
} {/1 .Parse error in 4th command line argument: near "BAD": syntax error*/} |
| 83 |
|
| 84 |
# -echo print commands before execution |
| 85 |
do_test shell1-1.4.1 { |
| 86 |
catchcmd "-echo test.db" "" |
| 87 |
} {0 {}} |
| 88 |
|
| 89 |
# -[no]header turn headers on or off |
| 90 |
do_test shell1-1.5.1 { |
| 91 |
catchcmd "-header test.db" "" |
| 92 |
} {0 {}} |
| 93 |
do_test shell1-1.5.2 { |
| 94 |
catchcmd "-noheader test.db" "" |
| 95 |
} {0 {}} |
| 96 |
|
| 97 |
# -bail stop after hitting an error |
| 98 |
do_test shell1-1.6.1 { |
| 99 |
catchcmd "-bail test.db" "" |
| 100 |
} {0 {}} |
| 101 |
|
| 102 |
# -interactive force interactive I/O |
| 103 |
do_test shell1-1.7.1 { |
| 104 |
set res [catchcmd "-interactive test.db" ".quit"] |
| 105 |
set rc [lindex $res 0] |
| 106 |
list $rc \ |
| 107 |
[regexp {SQLite version} $res] \ |
| 108 |
[regexp {Enter ".help" for usage hints} $res] |
| 109 |
} {0 1 1} |
| 110 |
|
| 111 |
# -batch force batch I/O |
| 112 |
do_test shell1-1.8.1 { |
| 113 |
catchcmd "-batch test.db" "" |
| 114 |
} {0 {}} |
| 115 |
|
| 116 |
# -column set output mode to 'column' |
| 117 |
do_test shell1-1.9.1 { |
| 118 |
catchcmd "-column test.db" "" |
| 119 |
} {0 {}} |
| 120 |
|
| 121 |
# -csv set output mode to 'csv' |
| 122 |
do_test shell1-1.10.1 { |
| 123 |
catchcmd "-csv test.db" "" |
| 124 |
} {0 {}} |
| 125 |
|
| 126 |
# -html set output mode to HTML |
| 127 |
do_test shell1-1.11.1 { |
| 128 |
catchcmd "-html test.db" "" |
| 129 |
} {0 {}} |
| 130 |
|
| 131 |
# -line set output mode to 'line' |
| 132 |
do_test shell1-1.12.1 { |
| 133 |
catchcmd "-line test.db" "" |
| 134 |
} {0 {}} |
| 135 |
|
| 136 |
# -list set output mode to 'list' |
| 137 |
do_test shell1-1.13.1 { |
| 138 |
catchcmd "-list test.db" "" |
| 139 |
} {0 {}} |
| 140 |
|
| 141 |
# -separator 'x' set output field separator (|) |
| 142 |
do_test shell1-1.14.1 { |
| 143 |
catchcmd "-separator 'x' test.db" "" |
| 144 |
} {0 {}} |
| 145 |
do_test shell1-1.14.2 { |
| 146 |
catchcmd "-separator x test.db" "" |
| 147 |
} {0 {}} |
| 148 |
do_test shell1-1.14.3 { |
| 149 |
set res [catchcmd "-separator" ""] |
| 150 |
set rc [lindex $res 0] |
| 151 |
list $rc \ |
| 152 |
[regexp {Error: missing argument to -separator} $res] |
| 153 |
} {1 1} |
| 154 |
|
| 155 |
# -stats print memory stats before each finalize |
| 156 |
do_test shell1-1.14b.1 { |
| 157 |
catchcmd "-stats test.db" "" |
| 158 |
} {0 {}} |
| 159 |
|
| 160 |
# -nullvalue 'text' set text string for NULL values |
| 161 |
do_test shell1-1.15.1 { |
| 162 |
catchcmd "-nullvalue 'x' test.db" "" |
| 163 |
} {0 {}} |
| 164 |
do_test shell1-1.15.2 { |
| 165 |
catchcmd "-nullvalue x test.db" "" |
| 166 |
} {0 {}} |
| 167 |
do_test shell1-1.15.3 { |
| 168 |
set res [catchcmd "-nullvalue" ""] |
| 169 |
set rc [lindex $res 0] |
| 170 |
list $rc \ |
| 171 |
[regexp {Error: missing argument to -nullvalue} $res] |
| 172 |
} {1 1} |
| 173 |
|
| 174 |
# -version show SQLite version |
| 175 |
do_test shell1-1.16.1 { |
| 176 |
set x [catchcmd "-version test.db" ""] |
| 177 |
} {/3.[0-9.]+ 20\d\d-[01]\d-\d\d \d\d:\d\d:\d\d [0-9a-f]+/} |
| 178 |
|
| 179 |
# Handle no-more-options option |
| 180 |
forcedelete ./--db |
| 181 |
do_test shell1-1.17.1 { |
| 182 |
catchcmd {-- --db "CREATE TABLE T(c1);"} |
| 183 |
} {0 {}} |
| 184 |
do_test shell1-1.17.2 { |
| 185 |
catchcmd {-- --db "SELECT name from sqlite_schema;"} |
| 186 |
} {0 T} |
| 187 |
forcedelete ./--db |
| 188 |
|
| 189 |
#---------------------------------------------------------------------------- |
| 190 |
# Test cases shell1-2.*: Basic "dot" command token parsing. |
| 191 |
# |
| 192 |
|
| 193 |
# check first token handling |
| 194 |
do_test shell1-2.1.1 { |
| 195 |
catchcmd "test.db" ".foo" |
| 196 |
} {1 {Error: unknown command or invalid arguments: "foo". Enter ".help" for help}} |
| 197 |
do_test shell1-2.1.2 { |
| 198 |
catchcmd "test.db" ".\"foo OFF\"" |
| 199 |
} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}} |
| 200 |
do_test shell1-2.1.3 { |
| 201 |
catchcmd "test.db" ".\'foo OFF\'" |
| 202 |
} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}} |
| 203 |
|
| 204 |
# unbalanced quotes |
| 205 |
do_test shell1-2.2.1 { |
| 206 |
catchcmd "test.db" ".\"foo OFF" |
| 207 |
} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}} |
| 208 |
do_test shell1-2.2.2 { |
| 209 |
catchcmd "test.db" ".\'foo OFF" |
| 210 |
} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}} |
| 211 |
do_test shell1-2.2.3 { |
| 212 |
catchcmd "test.db" ".explain \"OFF" |
| 213 |
} {0 {}} |
| 214 |
do_test shell1-2.2.4 { |
| 215 |
catchcmd "test.db" ".explain \'OFF" |
| 216 |
} {0 {}} |
| 217 |
do_test shell1-2.2.5 { |
| 218 |
catchcmd "test.db" ".mode \"insert FOO" |
| 219 |
} {1 {line 1: .mode "insert FOO |
| 220 |
line 1: ^--- unknown mode |
| 221 |
line 1: Use ".help .mode" for more info}} |
| 222 |
do_test shell1-2.2.6 { |
| 223 |
catchcmd "test.db" ".mode \'insert FOO" |
| 224 |
} {1 {line 1: .mode 'insert FOO |
| 225 |
line 1: ^--- unknown mode |
| 226 |
line 1: Use ".help .mode" for more info}} |
| 227 |
|
| 228 |
# check multiple tokens, and quoted tokens |
| 229 |
do_test shell1-2.3.1 { |
| 230 |
catchcmd "test.db" ".explain 1" |
| 231 |
} {0 {}} |
| 232 |
do_test shell1-2.3.2 { |
| 233 |
catchcmd "test.db" ".explain on" |
| 234 |
} {0 {}} |
| 235 |
do_test shell1-2.3.3 { |
| 236 |
catchcmd "test.db" ".explain \"1 2 3\"" |
| 237 |
} {1 {ERROR: Not a boolean value: "1 2 3". Assuming "no".}} |
| 238 |
do_test shell1-2.3.4 { |
| 239 |
catchcmd "test.db" ".explain \"OFF\"" |
| 240 |
} {0 {}} |
| 241 |
do_test shell1-2.3.5 { |
| 242 |
catchcmd "test.db" ".\'explain\' \'OFF\'" |
| 243 |
} {0 {}} |
| 244 |
do_test shell1-2.3.6 { |
| 245 |
catchcmd "test.db" ".explain \'OFF\'" |
| 246 |
} {0 {}} |
| 247 |
do_test shell1-2.3.7 { |
| 248 |
catchcmd "test.db" ".\'explain\' \'OFF\'" |
| 249 |
} {0 {}} |
| 250 |
|
| 251 |
# check quoted args are unquoted |
| 252 |
do_test shell1-2.4.1 { |
| 253 |
catchcmd "test.db" ".mode FOO" |
| 254 |
} {1 {line 1: .mode FOO |
| 255 |
line 1: ^--- unknown mode |
| 256 |
line 1: Use ".help .mode" for more info}} |
| 257 |
do_test shell1-2.4.2 { |
| 258 |
catchcmd "test.db" ".mode csv" |
| 259 |
} {0 {}} |
| 260 |
do_test shell1-2.4.2 { |
| 261 |
catchcmd "test.db" ".mode \"csv\"" |
| 262 |
} {0 {}} |
| 263 |
|
| 264 |
# check that certain quoted arg escapes work |
| 265 |
do_test shell1-2.5.1 { |
| 266 |
catchcmd ":memory:" ".print \"\\060\\077 \\x3f\\x30 \\a\\t\"" |
| 267 |
} [list 0 "0? ?0 \a\t"] |
| 268 |
|
| 269 |
|
| 270 |
#---------------------------------------------------------------------------- |
| 271 |
# Test cases shell1-3.*: Basic test that "dot" command can be called. |
| 272 |
# |
| 273 |
|
| 274 |
# .backup ?DB? FILE Backup DB (default "main") to FILE |
| 275 |
do_test shell1-3.1.1 { |
| 276 |
catchcmd "test.db" ".backup" |
| 277 |
} {1 {missing FILENAME argument on .backup}} |
| 278 |
forcedelete FOO |
| 279 |
do_test shell1-3.1.2 { |
| 280 |
catchcmd "test.db" ".backup FOO" |
| 281 |
} {0 {}} |
| 282 |
do_test shell1-3.1.3 { |
| 283 |
catchcmd "test.db" ".backup FOO BAR" |
| 284 |
} {1 {Error: unknown database FOO}} |
| 285 |
do_test shell1-3.1.4 { |
| 286 |
# too many arguments |
| 287 |
catchcmd "test.db" ".backup FOO BAR BAD" |
| 288 |
} {1 {Usage: .backup ?DB? ?OPTIONS? FILENAME}} |
| 289 |
|
| 290 |
# .bail ON|OFF Stop after hitting an error. Default OFF |
| 291 |
do_test shell1-3.2.1 { |
| 292 |
catchcmd "test.db" ".bail" |
| 293 |
} {1 {Usage: .bail on|off}} |
| 294 |
do_test shell1-3.2.2 { |
| 295 |
catchcmd "test.db" ".bail ON" |
| 296 |
} {0 {}} |
| 297 |
do_test shell1-3.2.3 { |
| 298 |
catchcmd "test.db" ".bail OFF" |
| 299 |
} {0 {}} |
| 300 |
do_test shell1-3.2.4 { |
| 301 |
# too many arguments |
| 302 |
catchcmd "test.db" ".bail OFF BAD" |
| 303 |
} {1 {Usage: .bail on|off}} |
| 304 |
|
| 305 |
ifcapable vtab { |
| 306 |
# .databases List names and files of attached databases |
| 307 |
do_test shell1-3.3.1 { |
| 308 |
catchcmd "-csv test.db" ".databases" |
| 309 |
} "/0.+main.+[string map {/ ".{1,2}"} [string range [get_pwd] 0 10]].*/" |
| 310 |
do_test shell1-3.3.2 { |
| 311 |
# extra arguments ignored |
| 312 |
catchcmd "test.db" ".databases BAD" |
| 313 |
} "/0.+main.+[string map {/ ".{1,2}"} [string range [get_pwd] 0 10]].*/" |
| 314 |
} |
| 315 |
|
| 316 |
# .dump ?TABLE? ... Dump the database in an SQL text format |
| 317 |
# If TABLE specified, only dump tables matching |
| 318 |
# LIKE pattern TABLE. |
| 319 |
do_test shell1-3.4.1 { |
| 320 |
set res [catchcmd "test.db" ".dump"] |
| 321 |
list [regexp {BEGIN TRANSACTION;} $res] \ |
| 322 |
[regexp {COMMIT;} $res] |
| 323 |
} {1 1} |
| 324 |
do_test shell1-3.4.2 { |
| 325 |
set res [catchcmd "test.db" ".dump FOO"] |
| 326 |
list [regexp {BEGIN TRANSACTION;} $res] \ |
| 327 |
[regexp {COMMIT;} $res] |
| 328 |
} {1 1} |
| 329 |
# The .dump command now accepts multiple arguments |
| 330 |
#do_test shell1-3.4.3 { |
| 331 |
# # too many arguments |
| 332 |
# catchcmd "test.db" ".dump FOO BAD" |
| 333 |
#} {1 {Usage: .dump ?--preserve-rowids? ?--newlines? ?LIKE-PATTERN?}} |
| 334 |
|
| 335 |
# .echo ON|OFF Turn command echo on or off |
| 336 |
do_test shell1-3.5.1 { |
| 337 |
catchcmd "test.db" ".echo" |
| 338 |
} {1 {Usage: .echo on|off}} |
| 339 |
do_test shell1-3.5.2 { |
| 340 |
catchcmd "test.db" ".echo ON" |
| 341 |
} {0 {}} |
| 342 |
do_test shell1-3.5.3 { |
| 343 |
catchcmd "test.db" ".echo OFF" |
| 344 |
} {0 {}} |
| 345 |
do_test shell1-3.5.4 { |
| 346 |
# too many arguments |
| 347 |
catchcmd "test.db" ".echo OFF BAD" |
| 348 |
} {1 {Usage: .echo on|off}} |
| 349 |
|
| 350 |
# .exit Exit this program |
| 351 |
do_test shell1-3.6.1 { |
| 352 |
catchcmd "test.db" ".exit" |
| 353 |
} {0 {}} |
| 354 |
|
| 355 |
# .explain ON|OFF Turn output mode suitable for EXPLAIN on or off. |
| 356 |
do_test shell1-3.7.1 { |
| 357 |
catchcmd "test.db" ".explain" |
| 358 |
# explain is the exception to the booleans. without an option, it turns it on. |
| 359 |
} {0 {}} |
| 360 |
do_test shell1-3.7.2 { |
| 361 |
catchcmd "test.db" ".explain ON" |
| 362 |
} {0 {}} |
| 363 |
do_test shell1-3.7.3 { |
| 364 |
catchcmd "test.db" ".explain OFF" |
| 365 |
} {0 {}} |
| 366 |
do_test shell1-3.7.4 { |
| 367 |
# extra arguments ignored |
| 368 |
catchcmd "test.db" ".explain OFF BAD" |
| 369 |
} {0 {}} |
| 370 |
|
| 371 |
# .header(s) ON|OFF Turn display of headers on or off |
| 372 |
do_test shell1-3.9.1 { |
| 373 |
catchcmd "test.db" ".header" |
| 374 |
} {1 {Usage: .headers on|off}} |
| 375 |
do_test shell1-3.9.2 { |
| 376 |
catchcmd "test.db" ".header ON" |
| 377 |
} {0 {}} |
| 378 |
do_test shell1-3.9.3 { |
| 379 |
catchcmd "test.db" ".header OFF" |
| 380 |
} {0 {}} |
| 381 |
do_test shell1-3.9.4 { |
| 382 |
# too many arguments |
| 383 |
catchcmd "test.db" ".header OFF BAD" |
| 384 |
} {1 {Usage: .headers on|off}} |
| 385 |
|
| 386 |
do_test shell1-3.9.5 { |
| 387 |
catchcmd "test.db" ".headers" |
| 388 |
} {1 {Usage: .headers on|off}} |
| 389 |
do_test shell1-3.9.6 { |
| 390 |
catchcmd "test.db" ".headers ON" |
| 391 |
} {0 {}} |
| 392 |
do_test shell1-3.9.7 { |
| 393 |
catchcmd "test.db" ".headers OFF" |
| 394 |
} {0 {}} |
| 395 |
do_test shell1-3.9.8 { |
| 396 |
# too many arguments |
| 397 |
catchcmd "test.db" ".headers OFF BAD" |
| 398 |
} {1 {Usage: .headers on|off}} |
| 399 |
|
| 400 |
# .help Show this message |
| 401 |
do_test shell1-3.10.1 { |
| 402 |
set res [catchcmd "test.db" ".help"] |
| 403 |
# look for a few of the possible help commands |
| 404 |
list [regexp {.help} $res] \ |
| 405 |
[regexp {.quit} $res] \ |
| 406 |
[regexp {.mode} $res] |
| 407 |
} {1 1 1} |
| 408 |
do_test shell1-3.10.2 { |
| 409 |
# we allow .help to take extra args (it is help after all) |
| 410 |
set res [catchcmd "test.db" ".help *"] |
| 411 |
# look for a few of the possible help commands |
| 412 |
list [regexp {.help} $res] \ |
| 413 |
[regexp {.quit} $res] \ |
| 414 |
[regexp {.mode} $res] |
| 415 |
} {1 1 1} |
| 416 |
|
| 417 |
# .import FILE TABLE Import data from FILE into TABLE |
| 418 |
do_test shell1-3.11.1 { |
| 419 |
catchcmd "test.db" ".import" |
| 420 |
} {/1 .line 1: Missing FILE argument.*/} |
| 421 |
do_test shell1-3.11.2 { |
| 422 |
catchcmd "test.db" ".import FOO" |
| 423 |
} {/1 .line 1: Missing TABLE argument.*/} |
| 424 |
do_test shell1-3.11.3 { |
| 425 |
# too many arguments |
| 426 |
catchcmd "test.db" ".import FOO BAR BAD" |
| 427 |
} {1 {line 1: .import FOO BAR BAD |
| 428 |
line 1: ^--- unknown argument}} |
| 429 |
do_test shell1-3.11.4 { |
| 430 |
catchcmd "test.db" ".import <<END t1\na,b,c\n1,2,3" |
| 431 |
} {1 {line 1: Content terminator "END" not found.}} |
| 432 |
|
| 433 |
# .indexes ?TABLE? Show names of all indexes |
| 434 |
# If TABLE specified, only show indexes for tables |
| 435 |
# matching LIKE pattern TABLE. |
| 436 |
do_test shell1-3.12.1 { |
| 437 |
catchcmd "test.db" ".indexes" |
| 438 |
} {0 {}} |
| 439 |
do_test shell1-3.12.2 { |
| 440 |
catchcmd "test.db" ".indexes FOO" |
| 441 |
} {0 {}} |
| 442 |
do_test shell1-3.12.2-legacy { |
| 443 |
catchcmd "test.db" ".indices FOO" |
| 444 |
} {0 {}} |
| 445 |
do_test shell1-3.12.3 { |
| 446 |
# too many arguments |
| 447 |
catchcmd "test.db" ".indexes FOO BAD" |
| 448 |
} {1 {line 1: .indexes FOO BAD |
| 449 |
line 1: ^--- unknown argument}} |
| 450 |
|
| 451 |
# .mode MODE ?TABLE? Set output mode where MODE is one of: |
| 452 |
# ascii Columns/rows delimited by 0x1F and 0x1E |
| 453 |
# csv Comma-separated values |
| 454 |
# column Left-aligned columns. (See .width) |
| 455 |
# html HTML <table> code |
| 456 |
# insert SQL insert statements for TABLE |
| 457 |
# line One value per line |
| 458 |
# list Values delimited by .separator strings |
| 459 |
# tabs Tab-separated values |
| 460 |
# tcl TCL list elements |
| 461 |
do_test shell1-3.13.1 { |
| 462 |
catchcmd "test.db" ".mode batch\n.mode" |
| 463 |
} {0 {.mode list}} |
| 464 |
do_test shell1-3.13.2 { |
| 465 |
catchcmd "test.db" ".mode FOO" |
| 466 |
} {1 {line 1: .mode FOO |
| 467 |
line 1: ^--- unknown mode |
| 468 |
line 1: Use ".help .mode" for more info}} |
| 469 |
do_test shell1-3.13.3 { |
| 470 |
catchcmd "test.db" ".mode csv" |
| 471 |
} {0 {}} |
| 472 |
do_test shell1-3.13.4 { |
| 473 |
catchcmd "test.db" ".mode column" |
| 474 |
} {0 {}} |
| 475 |
do_test shell1-3.13.5 { |
| 476 |
catchcmd "test.db" ".mode html" |
| 477 |
} {0 {}} |
| 478 |
do_test shell1-3.13.6 { |
| 479 |
catchcmd "test.db" ".mode insert" |
| 480 |
} {0 {}} |
| 481 |
do_test shell1-3.13.7 { |
| 482 |
catchcmd "test.db" ".mode line" |
| 483 |
} {0 {}} |
| 484 |
do_test shell1-3.13.8 { |
| 485 |
catchcmd "test.db" ".mode list" |
| 486 |
} {0 {}} |
| 487 |
do_test shell1-3.13.9 { |
| 488 |
catchcmd "test.db" ".mode tabs" |
| 489 |
} {0 {}} |
| 490 |
do_test shell1-3.13.10 { |
| 491 |
catchcmd "test.db" ".mode tcl" |
| 492 |
} {0 {}} |
| 493 |
do_test shell1-3.13.11 { |
| 494 |
# extra arguments ignored |
| 495 |
catchcmd "test.db" ".mode tcl BAD" |
| 496 |
} {0 {}} |
| 497 |
|
| 498 |
# .nullvalue STRING Print STRING in place of NULL values |
| 499 |
do_test shell1-3.14.1 { |
| 500 |
catchcmd "test.db" ".nullvalue" |
| 501 |
} {1 {Usage: .nullvalue STRING}} |
| 502 |
do_test shell1-3.14.2 { |
| 503 |
catchcmd "test.db" ".nullvalue FOO" |
| 504 |
} {0 {}} |
| 505 |
do_test shell1-3.14.3 { |
| 506 |
# too many arguments |
| 507 |
catchcmd "test.db" ".nullvalue FOO BAD" |
| 508 |
} {1 {Usage: .nullvalue STRING}} |
| 509 |
|
| 510 |
# .output FILENAME Send output to FILENAME |
| 511 |
do_test shell1-3.15.1 { |
| 512 |
catchcmd "test.db" ".output |
| 513 |
.print x" |
| 514 |
} {0 x} |
| 515 |
do_test shell1-3.15.2 { |
| 516 |
catchcmd "test.db" ".mode batch\n.output FOO |
| 517 |
.print x |
| 518 |
.output |
| 519 |
SELECT readfile('FOO');" |
| 520 |
} {0 {x |
| 521 |
}} |
| 522 |
do_test shell1-3.15.3 { |
| 523 |
# too many arguments |
| 524 |
catchcmd "test.db" ".output FOO BAD" |
| 525 |
} {1 {line 1: .output FOO BAD |
| 526 |
line 1: ^--- surplus argument}} |
| 527 |
|
| 528 |
# .output stdout Send output to the screen |
| 529 |
do_test shell1-3.16.1 { |
| 530 |
catchcmd "test.db" ".output stdout" |
| 531 |
} {0 {}} |
| 532 |
do_test shell1-3.16.2 { |
| 533 |
# too many arguments |
| 534 |
catchcmd "test.db" ".output stdout BAD" |
| 535 |
} {1 {line 1: .output stdout BAD |
| 536 |
line 1: ^--- surplus argument}} |
| 537 |
|
| 538 |
# .prompt MAIN CONTINUE Replace the standard prompts |
| 539 |
do_test shell1-3.17.1 { |
| 540 |
catchcmd "test.db" ".prompt" |
| 541 |
} {0 {}} |
| 542 |
do_test shell1-3.17.2 { |
| 543 |
catchcmd "test.db" ".prompt FOO" |
| 544 |
} {0 {}} |
| 545 |
do_test shell1-3.17.3 { |
| 546 |
catchcmd "test.db" ".prompt FOO BAR" |
| 547 |
} {0 {}} |
| 548 |
do_test shell1-3.17.4 { |
| 549 |
# too many arguments |
| 550 |
catchcmd "test.db" ".prompt FOO BAR BAD" |
| 551 |
} {0 {}} |
| 552 |
|
| 553 |
# .quit Exit this program |
| 554 |
do_test shell1-3.18.1 { |
| 555 |
catchcmd "test.db" ".quit" |
| 556 |
} {0 {}} |
| 557 |
do_test shell1-3.18.2 { |
| 558 |
# too many arguments |
| 559 |
catchcmd "test.db" ".quit BAD" |
| 560 |
} {0 {}} |
| 561 |
|
| 562 |
# .read FILENAME Execute SQL in FILENAME |
| 563 |
do_test shell1-3.19.1 { |
| 564 |
catchcmd "test.db" ".read" |
| 565 |
} {1 {Usage: .read FILE}} |
| 566 |
do_test shell1-3.19.2 { |
| 567 |
forcedelete FOO |
| 568 |
catchcmd "test.db" ".read FOO" |
| 569 |
} {1 {Error: cannot open "FOO"}} |
| 570 |
do_test shell1-3.19.3 { |
| 571 |
# too many arguments |
| 572 |
catchcmd "test.db" ".read FOO BAD" |
| 573 |
} {1 {Usage: .read FILE}} |
| 574 |
|
| 575 |
# .restore ?DB? FILE Restore content of DB (default "main") from FILE |
| 576 |
do_test shell1-3.20.1 { |
| 577 |
catchcmd "test.db" ".restore" |
| 578 |
} {1 {Usage: .restore ?DB? FILE}} |
| 579 |
do_test shell1-3.20.2 { |
| 580 |
catchcmd "test.db" ".restore FOO" |
| 581 |
} {0 {}} |
| 582 |
do_test shell1-3.20.3 { |
| 583 |
catchcmd "test.db" ".restore FOO BAR" |
| 584 |
} {1 {Error: unknown database FOO}} |
| 585 |
do_test shell1-3.20.4 { |
| 586 |
# too many arguments |
| 587 |
catchcmd "test.db" ".restore FOO BAR BAD" |
| 588 |
} {1 {Usage: .restore ?DB? FILE}} |
| 589 |
|
| 590 |
ifcapable vtab { |
| 591 |
# .schema ?TABLE? Show the CREATE statements |
| 592 |
# If TABLE specified, only show tables matching |
| 593 |
# LIKE pattern TABLE. |
| 594 |
do_test shell1-3.21.1 { |
| 595 |
catchcmd "test.db" ".schema" |
| 596 |
} {0 {}} |
| 597 |
do_test shell1-3.21.2 { |
| 598 |
catchcmd "test.db" ".schema FOO" |
| 599 |
} {0 {}} |
| 600 |
do_test shell1-3.21.3 { |
| 601 |
# too many arguments |
| 602 |
catchcmd "test.db" ".schema FOO BAD" |
| 603 |
} {1 {Usage: .schema ?--indent? ?--nosys? ?LIKE-PATTERN?}} |
| 604 |
|
| 605 |
do_test shell1-3.21.4 { |
| 606 |
catchcmd "test.db" { |
| 607 |
CREATE TABLE t1(x); |
| 608 |
CREATE VIEW v2 AS SELECT x+1 AS y FROM t1; |
| 609 |
CREATE VIEW v1 AS SELECT y+1 FROM v2; |
| 610 |
} |
| 611 |
catchcmd "test.db" ".schema" |
| 612 |
} {0 {CREATE TABLE t1(x); |
| 613 |
CREATE VIEW v2 AS SELECT x+1 AS y FROM t1 |
| 614 |
/* v2(y) */; |
| 615 |
CREATE VIEW v1 AS SELECT y+1 FROM v2 |
| 616 |
/* v1("y+1") */;}} |
| 617 |
|
| 618 |
catch {db eval {DROP VIEW v1; DROP VIEW v2; DROP TABLE t1;}} |
| 619 |
} |
| 620 |
do_test shell1-3.21.5 { |
| 621 |
exec {*}$CLI -noinit test.db \ |
| 622 |
{CREATE TABLE t2(a INTEGER PRIMARY KEY, b BLOB DEFAULT(jsonb('[]')),c TEXT NOT NULL)STRICT;} \ |
| 623 |
{.schema -indent t2} |
| 624 |
} {CREATE TABLE t2( |
| 625 |
a INTEGER PRIMARY KEY, |
| 626 |
b BLOB DEFAULT(jsonb('[]')), |
| 627 |
c TEXT NOT NULL |
| 628 |
)STRICT;} |
| 629 |
do_test shell1-3.21.6 { |
| 630 |
exec {*}$CLI -noinit test.db \ |
| 631 |
{DROP TABLE t2;} \ |
| 632 |
{.schema -indent t2} |
| 633 |
} {} |
| 634 |
|
| 635 |
# .separator STRING Change column separator used by output and .import |
| 636 |
do_test shell1-3.22.1 { |
| 637 |
catchcmd "test.db" ".separator" |
| 638 |
} {1 {Usage: .separator COL ?ROW?}} |
| 639 |
do_test shell1-3.22.2 { |
| 640 |
catchcmd "test.db" ".separator FOO" |
| 641 |
} {0 {}} |
| 642 |
do_test shell1-3.22.3 { |
| 643 |
catchcmd "test.db" ".separator ABC XYZ" |
| 644 |
} {0 {}} |
| 645 |
do_test shell1-3.22.4 { |
| 646 |
# too many arguments |
| 647 |
catchcmd "test.db" ".separator FOO BAD BAD2" |
| 648 |
} {1 {Usage: .separator COL ?ROW?}} |
| 649 |
|
| 650 |
# .show Show the current values for various settings |
| 651 |
do_test shell1-3.23.1 { |
| 652 |
set res [catchcmd "test.db" ".mode batch\n.show"] |
| 653 |
list [regexp {echo:} $res] \ |
| 654 |
[regexp {explain:} $res] \ |
| 655 |
[regexp {headers:} $res] \ |
| 656 |
[regexp {mode:} $res] \ |
| 657 |
[regexp {nullvalue:} $res] \ |
| 658 |
[regexp {output:} $res] \ |
| 659 |
[regexp {colseparator:} $res] \ |
| 660 |
[regexp {rowseparator:} $res] \ |
| 661 |
[regexp {stats:} $res] \ |
| 662 |
[regexp {width:} $res] |
| 663 |
} {1 1 1 1 1 1 1 1 1 1} |
| 664 |
do_test shell1-3.23.2 { |
| 665 |
# too many arguments |
| 666 |
catchcmd "test.db" ".show BAD" |
| 667 |
} {1 {Usage: .show}} |
| 668 |
|
| 669 |
# .stats ON|OFF Turn stats on or off |
| 670 |
#do_test shell1-3.23b.1 { |
| 671 |
# catchcmd "test.db" ".stats" |
| 672 |
#} {1 {Usage: .stats on|off|stmt|vmstep}} |
| 673 |
do_test shell1-3.23b.2 { |
| 674 |
catchcmd "test.db" ".stats ON" |
| 675 |
} {0 {}} |
| 676 |
do_test shell1-3.23b.3 { |
| 677 |
catchcmd "test.db" ".stats OFF" |
| 678 |
} {0 {}} |
| 679 |
do_test shell1-3.23b.4 { |
| 680 |
# too many arguments |
| 681 |
catchcmd "test.db" ".stats OFF BAD" |
| 682 |
} {1 {Usage: .stats ?on|off|stmt|vmstep?}} |
| 683 |
|
| 684 |
# Ticket 7be932dfa60a8a6b3b26bcf7623ec46e0a403ddb 2018-06-07 |
| 685 |
# Adverse interaction between .stats and .eqp |
| 686 |
# |
| 687 |
do_test shell1-3.23b.5 { |
| 688 |
catchcmd "test.db" [string map {"\n " "\n"} {.mode batch |
| 689 |
CREATE TEMP TABLE t1(x); |
| 690 |
INSERT INTO t1 VALUES(1),(2); |
| 691 |
.stats on |
| 692 |
.eqp full |
| 693 |
SELECT * FROM t1; |
| 694 |
}] |
| 695 |
} {/1\n2\n/} |
| 696 |
|
| 697 |
# .tables ?TABLE? List names of tables |
| 698 |
# If TABLE specified, only list tables matching |
| 699 |
# LIKE pattern TABLE. |
| 700 |
do_test shell1-3.24.1 { |
| 701 |
catchcmd "test.db" ".tables" |
| 702 |
} {0 {}} |
| 703 |
do_test shell1-3.24.2 { |
| 704 |
catchcmd "test.db" ".tables FOO" |
| 705 |
} {0 {}} |
| 706 |
do_test shell1-3.24.3 { |
| 707 |
# too many arguments |
| 708 |
catchcmd "test.db" ".tables FOO BAD" |
| 709 |
} {0 {}} |
| 710 |
|
| 711 |
# .timeout MS Try opening locked tables for MS milliseconds |
| 712 |
do_test shell1-3.25.1 { |
| 713 |
catchcmd "test.db" ".timeout" |
| 714 |
} {0 {}} |
| 715 |
do_test shell1-3.25.2 { |
| 716 |
catchcmd "test.db" ".timeout zzz" |
| 717 |
# this should be treated the same as a '0' timeout |
| 718 |
} {0 {}} |
| 719 |
do_test shell1-3.25.3 { |
| 720 |
catchcmd "test.db" ".timeout 1" |
| 721 |
} {0 {}} |
| 722 |
do_test shell1-3.25.4 { |
| 723 |
# too many arguments |
| 724 |
catchcmd "test.db" ".timeout 1 BAD" |
| 725 |
} {0 {}} |
| 726 |
|
| 727 |
# .width NUM NUM ... Set column widths for "column" mode |
| 728 |
do_test shell1-3.26.1 { |
| 729 |
catchcmd "test.db" ".width" |
| 730 |
} {0 {}} |
| 731 |
do_test shell1-3.26.2 { |
| 732 |
catchcmd "test.db" ".width xxx" |
| 733 |
# this should be treated the same as a '0' width for col 1 |
| 734 |
} {0 {}} |
| 735 |
do_test shell1-3.26.3 { |
| 736 |
catchcmd "test.db" ".width xxx yyy" |
| 737 |
# this should be treated the same as a '0' width for col 1 and 2 |
| 738 |
} {0 {}} |
| 739 |
do_test shell1-3.26.4 { |
| 740 |
catchcmd "test.db" ".width 1 1" |
| 741 |
# this should be treated the same as a '1' width for col 1 and 2 |
| 742 |
} {0 {}} |
| 743 |
do_test shell1-3.26.5 { |
| 744 |
catchcmd "test.db" ".mode column\n.header off\n.width 10 -10\nSELECT 'abcdefg', 123456;" |
| 745 |
# this should be treated the same as a '1' width for col 1 and 2 |
| 746 |
} {0 {abcdefg 123456}} |
| 747 |
do_test shell1-3.26.6 { |
| 748 |
catchcmd "test.db" ".mode column\n.header off\n.width -10 10\nSELECT 'abcdefg', 123456;" |
| 749 |
# this should be treated the same as a '1' width for col 1 and 2 |
| 750 |
} {0 { abcdefg 123456}} |
| 751 |
|
| 752 |
|
| 753 |
# .timer ON|OFF Turn the CPU timer measurement on or off |
| 754 |
do_test shell1-3.27.1 { |
| 755 |
catchcmd "test.db" ".timer" |
| 756 |
} {1 {Usage: .timer on|off|once}} |
| 757 |
do_test shell1-3.27.2 { |
| 758 |
catchcmd "test.db" ".timer ON" |
| 759 |
} {0 {}} |
| 760 |
do_test shell1-3.27.3 { |
| 761 |
catchcmd "test.db" ".timer OFF" |
| 762 |
} {0 {}} |
| 763 |
do_test shell1-3.27.4 { |
| 764 |
# too many arguments |
| 765 |
catchcmd "test.db" ".timer OFF BAD" |
| 766 |
} {1 {Usage: .timer on|off|once}} |
| 767 |
|
| 768 |
do_test shell1-3.28.1 { |
| 769 |
catchcmd test.db \ |
| 770 |
".mode batch\n.log stdout\nSELECT coalesce(sqlite_log(123,'hello'),'456');" |
| 771 |
} "0 {(123) hello\n456}" |
| 772 |
|
| 773 |
do_test shell1-3-29.1 { |
| 774 |
catchcmd "test.db" ".print this is a test" |
| 775 |
} {0 {this is a test}} |
| 776 |
|
| 777 |
# dot-command argument quoting |
| 778 |
do_test shell1-3-30.1 { |
| 779 |
catchcmd {test.db} {.print "this\"is'a\055test" 'this\"is\\a\055test'} |
| 780 |
} {0 {this"is'a-test this\"is\\a\055test}} |
| 781 |
do_test shell1-3-31.1 { |
| 782 |
catchcmd {test.db} {.print "this\nis\ta\\test" 'this\nis\ta\\test'} |
| 783 |
} [list 0 "this\nis\ta\\test this\\nis\\ta\\\\test"] |
| 784 |
|
| 785 |
|
| 786 |
# Test the output of the ".dump" command |
| 787 |
# |
| 788 |
do_test shell1-4.1 { |
| 789 |
db close |
| 790 |
forcedelete test.db |
| 791 |
sqlite3 db test.db |
| 792 |
db eval { |
| 793 |
PRAGMA encoding=UTF16; |
| 794 |
CREATE TABLE t1(x); |
| 795 |
INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f'); |
| 796 |
CREATE TABLE t3(x,y); |
| 797 |
INSERT INTO t3 VALUES(1,null), (2,''), (3,1), |
| 798 |
(4,2.25), (5,'hello'), (6,x'807f'); |
| 799 |
} |
| 800 |
catchcmd test.db {.dump} |
| 801 |
} {0 {PRAGMA foreign_keys=OFF; |
| 802 |
BEGIN TRANSACTION; |
| 803 |
CREATE TABLE t1(x); |
| 804 |
INSERT INTO t1 VALUES(NULL); |
| 805 |
INSERT INTO t1 VALUES(''); |
| 806 |
INSERT INTO t1 VALUES(1); |
| 807 |
INSERT INTO t1 VALUES(2.25); |
| 808 |
INSERT INTO t1 VALUES('hello'); |
| 809 |
INSERT INTO t1 VALUES(x'807f'); |
| 810 |
CREATE TABLE t3(x,y); |
| 811 |
INSERT INTO t3 VALUES(1,NULL); |
| 812 |
INSERT INTO t3 VALUES(2,''); |
| 813 |
INSERT INTO t3 VALUES(3,1); |
| 814 |
INSERT INTO t3 VALUES(4,2.25); |
| 815 |
INSERT INTO t3 VALUES(5,'hello'); |
| 816 |
INSERT INTO t3 VALUES(6,x'807f'); |
| 817 |
COMMIT;}} |
| 818 |
|
| 819 |
|
| 820 |
ifcapable vtab { |
| 821 |
|
| 822 |
# The --preserve-rowids option to .dump |
| 823 |
# |
| 824 |
do_test shell1-4.1.1 { |
| 825 |
catchcmd test.db {.dump --preserve-rowids} |
| 826 |
} {0 {PRAGMA foreign_keys=OFF; |
| 827 |
BEGIN TRANSACTION; |
| 828 |
CREATE TABLE t1(x); |
| 829 |
INSERT INTO t1(rowid,x) VALUES(1,NULL); |
| 830 |
INSERT INTO t1(rowid,x) VALUES(2,''); |
| 831 |
INSERT INTO t1(rowid,x) VALUES(3,1); |
| 832 |
INSERT INTO t1(rowid,x) VALUES(4,2.25); |
| 833 |
INSERT INTO t1(rowid,x) VALUES(5,'hello'); |
| 834 |
INSERT INTO t1(rowid,x) VALUES(6,x'807f'); |
| 835 |
CREATE TABLE t3(x,y); |
| 836 |
INSERT INTO t3(rowid,x,y) VALUES(1,1,NULL); |
| 837 |
INSERT INTO t3(rowid,x,y) VALUES(2,2,''); |
| 838 |
INSERT INTO t3(rowid,x,y) VALUES(3,3,1); |
| 839 |
INSERT INTO t3(rowid,x,y) VALUES(4,4,2.25); |
| 840 |
INSERT INTO t3(rowid,x,y) VALUES(5,5,'hello'); |
| 841 |
INSERT INTO t3(rowid,x,y) VALUES(6,6,x'807f'); |
| 842 |
COMMIT;}} |
| 843 |
|
| 844 |
# If the table contains an INTEGER PRIMARY KEY, do not record a separate |
| 845 |
# rowid column in the output. |
| 846 |
# |
| 847 |
do_test shell1-4.1.2 { |
| 848 |
db close |
| 849 |
forcedelete test2.db |
| 850 |
sqlite3 db test2.db |
| 851 |
db eval { |
| 852 |
CREATE TABLE t1(x INTEGER PRIMARY KEY, y); |
| 853 |
INSERT INTO t1 VALUES(1,null), (2,''), (3,1), |
| 854 |
(4,2.25), (5,'hello'), (6,x'807f'); |
| 855 |
} |
| 856 |
catchcmd test2.db {.dump --preserve-rowids} |
| 857 |
} {0 {PRAGMA foreign_keys=OFF; |
| 858 |
BEGIN TRANSACTION; |
| 859 |
CREATE TABLE t1(x INTEGER PRIMARY KEY, y); |
| 860 |
INSERT INTO t1(x,y) VALUES(1,NULL); |
| 861 |
INSERT INTO t1(x,y) VALUES(2,''); |
| 862 |
INSERT INTO t1(x,y) VALUES(3,1); |
| 863 |
INSERT INTO t1(x,y) VALUES(4,2.25); |
| 864 |
INSERT INTO t1(x,y) VALUES(5,'hello'); |
| 865 |
INSERT INTO t1(x,y) VALUES(6,x'807f'); |
| 866 |
COMMIT;}} |
| 867 |
|
| 868 |
# Verify that the table named [table] is correctly quoted and that |
| 869 |
# an INTEGER PRIMARY KEY DESC is not an alias for the rowid. |
| 870 |
# |
| 871 |
do_test shell1-4.1.3 { |
| 872 |
db close |
| 873 |
forcedelete test2.db |
| 874 |
sqlite3 db test2.db |
| 875 |
db eval { |
| 876 |
CREATE TABLE [table](x INTEGER PRIMARY KEY DESC, y); |
| 877 |
INSERT INTO [table] VALUES(1,null), (12,''), (23,1), |
| 878 |
(34,2.25), (45,'hello'), (56,x'807f'); |
| 879 |
} |
| 880 |
catchcmd test2.db {.dump --preserve-rowids} |
| 881 |
} {0 {PRAGMA foreign_keys=OFF; |
| 882 |
BEGIN TRANSACTION; |
| 883 |
CREATE TABLE [table](x INTEGER PRIMARY KEY DESC, y); |
| 884 |
INSERT INTO "table"(rowid,x,y) VALUES(1,1,NULL); |
| 885 |
INSERT INTO "table"(rowid,x,y) VALUES(2,12,''); |
| 886 |
INSERT INTO "table"(rowid,x,y) VALUES(3,23,1); |
| 887 |
INSERT INTO "table"(rowid,x,y) VALUES(4,34,2.25); |
| 888 |
INSERT INTO "table"(rowid,x,y) VALUES(5,45,'hello'); |
| 889 |
INSERT INTO "table"(rowid,x,y) VALUES(6,56,x'807f'); |
| 890 |
COMMIT;}} |
| 891 |
|
| 892 |
# Do not record rowids for a WITHOUT ROWID table. Also check correct quoting |
| 893 |
# of table names that contain odd characters. |
| 894 |
# |
| 895 |
do_test shell1-4.1.4 { |
| 896 |
db close |
| 897 |
forcedelete test2.db |
| 898 |
sqlite3 db test2.db |
| 899 |
db eval { |
| 900 |
CREATE TABLE [ta<>ble](x INTEGER PRIMARY KEY, y) WITHOUT ROWID; |
| 901 |
INSERT INTO [ta<>ble] VALUES(1,null), (12,''), (23,1), |
| 902 |
(34,2.25), (45,'hello'), (56,x'807f'); |
| 903 |
} |
| 904 |
catchcmd test2.db {.dump --preserve-rowids} |
| 905 |
} {0 {PRAGMA foreign_keys=OFF; |
| 906 |
BEGIN TRANSACTION; |
| 907 |
CREATE TABLE [ta<>ble](x INTEGER PRIMARY KEY, y) WITHOUT ROWID; |
| 908 |
INSERT INTO "ta<>ble"(x,y) VALUES(1,NULL); |
| 909 |
INSERT INTO "ta<>ble"(x,y) VALUES(12,''); |
| 910 |
INSERT INTO "ta<>ble"(x,y) VALUES(23,1); |
| 911 |
INSERT INTO "ta<>ble"(x,y) VALUES(34,2.25); |
| 912 |
INSERT INTO "ta<>ble"(x,y) VALUES(45,'hello'); |
| 913 |
INSERT INTO "ta<>ble"(x,y) VALUES(56,x'807f'); |
| 914 |
COMMIT;}} |
| 915 |
|
| 916 |
# Do not record rowids if the rowid is inaccessible |
| 917 |
# |
| 918 |
do_test shell1-4.1.5 { |
| 919 |
db close |
| 920 |
forcedelete test2.db |
| 921 |
sqlite3 db test2.db |
| 922 |
db eval { |
| 923 |
CREATE TABLE t1(_ROWID_,rowid,oid); |
| 924 |
INSERT INTO t1 VALUES(1,null,'alpha'), (12,'',99), (23,1,x'b0b1b2'); |
| 925 |
} |
| 926 |
catchcmd test2.db {.dump --preserve-rowids} |
| 927 |
} {0 {PRAGMA foreign_keys=OFF; |
| 928 |
BEGIN TRANSACTION; |
| 929 |
CREATE TABLE t1(_ROWID_,rowid,oid); |
| 930 |
INSERT INTO t1(_ROWID_,rowid,oid) VALUES(1,NULL,'alpha'); |
| 931 |
INSERT INTO t1(_ROWID_,rowid,oid) VALUES(12,'',99); |
| 932 |
INSERT INTO t1(_ROWID_,rowid,oid) VALUES(23,1,x'b0b1b2'); |
| 933 |
COMMIT;}} |
| 934 |
|
| 935 |
} else { |
| 936 |
|
| 937 |
do_test shell1-4.1.6 { |
| 938 |
db close |
| 939 |
forcedelete test2.db |
| 940 |
sqlite3 db test2.db |
| 941 |
db eval { |
| 942 |
CREATE TABLE t1(x INTEGER PRIMARY KEY, y); |
| 943 |
INSERT INTO t1 VALUES(1,null), (2,''), (3,1), |
| 944 |
(4,2.25), (5,'hello'), (6,x'807f'); |
| 945 |
} |
| 946 |
catchcmd test2.db {.dump --preserve-rowids} |
| 947 |
} {/.* --preserve-rowids option is not compatible with SQLITE_OMIT_VIRTUALTABLE/} |
| 948 |
|
| 949 |
} |
| 950 |
|
| 951 |
# DELETE content of sqlite_sequence prior to repopulating, |
| 952 |
# but only if the sqlite_sequence table is non-empty. |
| 953 |
# Forum: 2024-10-13T17:10:01z and 2025-10-29T19:38:43z |
| 954 |
# |
| 955 |
do_test shell1-4.1.7 { |
| 956 |
db close |
| 957 |
forcedelete test2.db |
| 958 |
sqlite3 db test2.db |
| 959 |
db eval { |
| 960 |
CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b); |
| 961 |
INSERT INTO t1 VALUES(1,2),(20,21),(15,16); |
| 962 |
} |
| 963 |
catchcmd test2.db {.dump} |
| 964 |
} {0 {PRAGMA foreign_keys=OFF; |
| 965 |
BEGIN TRANSACTION; |
| 966 |
CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b); |
| 967 |
INSERT INTO t1 VALUES(1,2); |
| 968 |
INSERT INTO t1 VALUES(15,16); |
| 969 |
INSERT INTO t1 VALUES(20,21); |
| 970 |
PRAGMA writable_schema=ON; |
| 971 |
CREATE TABLE IF NOT EXISTS sqlite_sequence(name,seq); |
| 972 |
DELETE FROM sqlite_sequence; |
| 973 |
INSERT INTO sqlite_sequence VALUES('t1',20); |
| 974 |
PRAGMA writable_schema=OFF; |
| 975 |
COMMIT;}} |
| 976 |
do_test shell1-4.1.8 { |
| 977 |
db close |
| 978 |
forcedelete test2.db |
| 979 |
sqlite3 db test2.db |
| 980 |
db eval { |
| 981 |
CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b); |
| 982 |
INSERT INTO t1 VALUES(1,2),(20,21),(15,16); |
| 983 |
CREATE TABLE t2(x,y); |
| 984 |
INSERT INTO t2 VALUES(99,88); |
| 985 |
DROP TABLE t1; |
| 986 |
} |
| 987 |
catchcmd test2.db {.dump} |
| 988 |
} {0 {PRAGMA foreign_keys=OFF; |
| 989 |
BEGIN TRANSACTION; |
| 990 |
CREATE TABLE t2(x,y); |
| 991 |
INSERT INTO t2 VALUES(99,88); |
| 992 |
COMMIT;}} |
| 993 |
do_test shell1-4.1.9 { |
| 994 |
db close |
| 995 |
forcedelete test2.db |
| 996 |
sqlite3 db test2.db |
| 997 |
db eval { |
| 998 |
CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b); |
| 999 |
INSERT INTO t1 VALUES(1,2),(20,21),(15,16); |
| 1000 |
CREATE TABLE t2(x,y); |
| 1001 |
INSERT INTO t2 VALUES(99,88); |
| 1002 |
INSERT INTO sqlite_sequence VALUES('extra',999); |
| 1003 |
DROP TABLE t1; |
| 1004 |
} |
| 1005 |
catchcmd test2.db {.dump} |
| 1006 |
} {0 {PRAGMA foreign_keys=OFF; |
| 1007 |
BEGIN TRANSACTION; |
| 1008 |
CREATE TABLE t2(x,y); |
| 1009 |
INSERT INTO t2 VALUES(99,88); |
| 1010 |
PRAGMA writable_schema=ON; |
| 1011 |
CREATE TABLE IF NOT EXISTS sqlite_sequence(name,seq); |
| 1012 |
DELETE FROM sqlite_sequence; |
| 1013 |
INSERT INTO sqlite_sequence VALUES('extra',999); |
| 1014 |
PRAGMA writable_schema=OFF; |
| 1015 |
COMMIT;}} |
| 1016 |
|
| 1017 |
# Test the output of ".mode insert" |
| 1018 |
# |
| 1019 |
do_test shell1-4.2.1 { |
| 1020 |
catchcmd test.db ".mode insert t1\nselect * from t1;" |
| 1021 |
} {0 {INSERT INTO t1 VALUES(NULL); |
| 1022 |
INSERT INTO t1 VALUES(''); |
| 1023 |
INSERT INTO t1 VALUES(1); |
| 1024 |
INSERT INTO t1 VALUES(2.25); |
| 1025 |
INSERT INTO t1 VALUES('hello'); |
| 1026 |
INSERT INTO t1 VALUES(x'807f');}} |
| 1027 |
|
| 1028 |
# Test the output of ".mode insert" with headers |
| 1029 |
# |
| 1030 |
do_test shell1-4.2.2 { |
| 1031 |
catchcmd test.db ".mode insert t1\n.headers on\nselect * from t1;" |
| 1032 |
} {0 {INSERT INTO t1(x) VALUES(NULL); |
| 1033 |
INSERT INTO t1(x) VALUES(''); |
| 1034 |
INSERT INTO t1(x) VALUES(1); |
| 1035 |
INSERT INTO t1(x) VALUES(2.25); |
| 1036 |
INSERT INTO t1(x) VALUES('hello'); |
| 1037 |
INSERT INTO t1(x) VALUES(x'807f');}} |
| 1038 |
|
| 1039 |
# Test the output of ".mode insert" |
| 1040 |
# |
| 1041 |
do_test shell1-4.2.3 { |
| 1042 |
catchcmd test.db ".mode insert t3\nselect * from t3;" |
| 1043 |
} {0 {INSERT INTO t3 VALUES(1,NULL); |
| 1044 |
INSERT INTO t3 VALUES(2,''); |
| 1045 |
INSERT INTO t3 VALUES(3,1); |
| 1046 |
INSERT INTO t3 VALUES(4,2.25); |
| 1047 |
INSERT INTO t3 VALUES(5,'hello'); |
| 1048 |
INSERT INTO t3 VALUES(6,x'807f');}} |
| 1049 |
|
| 1050 |
# Test the output of ".mode insert" with headers |
| 1051 |
# |
| 1052 |
do_test shell1-4.2.4 { |
| 1053 |
catchcmd test.db ".mode insert t3\n.headers on\nselect * from t3;" |
| 1054 |
} {0 {INSERT INTO t3(x,y) VALUES(1,NULL); |
| 1055 |
INSERT INTO t3(x,y) VALUES(2,''); |
| 1056 |
INSERT INTO t3(x,y) VALUES(3,1); |
| 1057 |
INSERT INTO t3(x,y) VALUES(4,2.25); |
| 1058 |
INSERT INTO t3(x,y) VALUES(5,'hello'); |
| 1059 |
INSERT INTO t3(x,y) VALUES(6,x'807f');}} |
| 1060 |
|
| 1061 |
# Test the output of ".mode tcl" |
| 1062 |
# |
| 1063 |
do_test shell1-4.3 { |
| 1064 |
db close |
| 1065 |
forcedelete test.db |
| 1066 |
sqlite3 db test.db |
| 1067 |
db eval { |
| 1068 |
PRAGMA encoding=UTF8; |
| 1069 |
CREATE TABLE t1(x); |
| 1070 |
INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f'); |
| 1071 |
} |
| 1072 |
catchcmd test.db ".mode tcl\nselect * from t1;" |
| 1073 |
} {0 {"" |
| 1074 |
"" |
| 1075 |
1 |
| 1076 |
2.25 |
| 1077 |
"hello" |
| 1078 |
"\200\177"}} |
| 1079 |
|
| 1080 |
# Test the output of ".mode tcl" with multiple columns |
| 1081 |
# |
| 1082 |
do_test shell1-4.4 { |
| 1083 |
db eval { |
| 1084 |
CREATE TABLE t2(x,y); |
| 1085 |
INSERT INTO t2 VALUES(null, ''), (1, 2.25), ('hello', x'807f'); |
| 1086 |
} |
| 1087 |
catchcmd test.db ".mode tcl\nselect * from t2;" |
| 1088 |
} {0 {"" "" |
| 1089 |
1 2.25 |
| 1090 |
"hello" "\200\177"}} |
| 1091 |
|
| 1092 |
# Test the output of ".mode tcl" with ".nullvalue" |
| 1093 |
# |
| 1094 |
do_test shell1-4.5 { |
| 1095 |
catchcmd test.db ".mode tcl\n.nullvalue NULL\nselect * from t2;" |
| 1096 |
} {0 {NULL "" |
| 1097 |
1 2.25 |
| 1098 |
"hello" "\200\177"}} |
| 1099 |
|
| 1100 |
# Test the output of ".mode tcl" with Tcl reserved characters |
| 1101 |
# |
| 1102 |
do_test shell1-4.6 { |
| 1103 |
db eval { |
| 1104 |
CREATE TABLE tcl1(x); |
| 1105 |
INSERT INTO tcl1 VALUES('"'), ('['), (']'), ('\{'), ('\}'), (';'), ('$'); |
| 1106 |
} |
| 1107 |
foreach {x y} [catchcmd test.db ".mode tcl\nselect * from tcl1;"] break |
| 1108 |
list $x $y [llength $y] |
| 1109 |
} {0 {"\"" |
| 1110 |
"[" |
| 1111 |
"]" |
| 1112 |
"\\{" |
| 1113 |
"\\}" |
| 1114 |
";" |
| 1115 |
"$"} 7} |
| 1116 |
|
| 1117 |
# Test the output of ".mode quote" |
| 1118 |
# |
| 1119 |
do_test shell1-4.7 { |
| 1120 |
catchcmd test.db ".mode quote\nselect x'0123456789ABCDEF';" |
| 1121 |
} {0 x'0123456789abcdef'} |
| 1122 |
|
| 1123 |
# Test using arbitrary byte data with the shell via standard input/output. |
| 1124 |
# |
| 1125 |
if 0 { # Causes a valgrind error in TCL. Seems to be a TCL problem. |
| 1126 |
do_test shell1-5.0 { |
| 1127 |
# |
| 1128 |
# NOTE: Skip NUL byte because it appears to be incompatible with command |
| 1129 |
# shell argument parsing. |
| 1130 |
# |
| 1131 |
for {set i 1} {$i < 256} {incr i} { |
| 1132 |
# |
| 1133 |
# NOTE: Due to how the Tcl [exec] command works (i.e. where it treats |
| 1134 |
# command channels opened for it as textual ones), the carriage |
| 1135 |
# return character (and on Windows, the end-of-file character) |
| 1136 |
# cannot be used here. |
| 1137 |
# |
| 1138 |
if {$i==0x0D || ($tcl_platform(platform) eq "windows" && $i==0x1A)} { |
| 1139 |
continue |
| 1140 |
} |
| 1141 |
# Tcl 8.7 maps 0x80 through 0x9f into valid UTF8. So skip those tests. |
| 1142 |
if {$i>=0x80} { |
| 1143 |
if {$i<=0x9F || $tcl_version>=9.0} continue |
| 1144 |
if {$tcl_platform(platform) eq "windows"} continue |
| 1145 |
} |
| 1146 |
if {$i>=0xE0 && $tcl_platform(os) eq "OpenBSD"} continue |
| 1147 |
if {$i>=0xE0 && $i<=0xEF && $tcl_platform(os) eq "Linux"} continue |
| 1148 |
set hex [format %02X $i] |
| 1149 |
set char [subst \\x$hex]; set oldChar $char |
| 1150 |
set escapes [list] |
| 1151 |
if {$tcl_platform(platform) eq "windows"} { |
| 1152 |
# |
| 1153 |
# NOTE: On Windows, we need to escape all the whitespace characters, |
| 1154 |
# the alarm (\a) character, and those with special meaning to |
| 1155 |
# the SQLite shell itself. |
| 1156 |
# |
| 1157 |
set escapes [list \ |
| 1158 |
\a \\a \b \\b \t \\t \n \\n \v \\v \f \\f \r \\r \ |
| 1159 |
" " "\" \"" \" \\\" \\ \\\\] |
| 1160 |
} else { |
| 1161 |
# |
| 1162 |
# NOTE: On Unix, we need to escape most of the whitespace characters |
| 1163 |
# and those with special meaning to the SQLite shell itself. |
| 1164 |
# The alarm (\a), backspace (\b), and carriage-return (\r) |
| 1165 |
# characters do not appear to require escaping on Unix. For |
| 1166 |
# the alarm and backspace characters, this is probably due to |
| 1167 |
# differences in the command shell. For the carriage-return, |
| 1168 |
# it is probably due to differences in how Tcl handles command |
| 1169 |
# channel end-of-line translations. |
| 1170 |
# |
| 1171 |
set escapes [list \ |
| 1172 |
\t \\t \n \\n \v \\v \f \\f \ |
| 1173 |
" " "\" \"" \" \\\" \\ \\\\] |
| 1174 |
} |
| 1175 |
set char [string map $escapes $char] |
| 1176 |
set x [catchcmdex test.db ".print \"$char\"\n"] |
| 1177 |
set code [lindex $x 0] |
| 1178 |
set res [lindex $x 1] |
| 1179 |
if {$code ne "0"} { |
| 1180 |
error "failed with error: $res" |
| 1181 |
} |
| 1182 |
if {$res ne "$oldChar\n"} { |
| 1183 |
if {[llength $res] > 0} { |
| 1184 |
set got [format %02X [scan $res %c]] |
| 1185 |
} else { |
| 1186 |
set got <empty> |
| 1187 |
} |
| 1188 |
error "failed with byte $hex mismatch, got $got" |
| 1189 |
} |
| 1190 |
} |
| 1191 |
} {} |
| 1192 |
} |
| 1193 |
|
| 1194 |
# These test cases do not work on MinGW |
| 1195 |
if 0 { |
| 1196 |
|
| 1197 |
# The string used here is the word "test" in Chinese. |
| 1198 |
# In UTF-8, it is encoded as: \xE6\xB5\x8B\xE8\xAF\x95 |
| 1199 |
set test \u6D4B\u8BD5 |
| 1200 |
|
| 1201 |
do_test shell1-6.0 { |
| 1202 |
set fileName $test; append fileName .db |
| 1203 |
catch {forcedelete $fileName} |
| 1204 |
set x [catchcmdex $fileName "CREATE TABLE t1(x);\n.schema\n"] |
| 1205 |
set code [lindex $x 0] |
| 1206 |
set res [string trim [lindex $x 1]] |
| 1207 |
if {$code ne "0"} { |
| 1208 |
error "failed with error: $res" |
| 1209 |
} |
| 1210 |
if {$res ne "CREATE TABLE t1(x);"} { |
| 1211 |
error "failed with mismatch: $res" |
| 1212 |
} |
| 1213 |
if {![file exists $fileName]} { |
| 1214 |
error "file \"$fileName\" (Unicode) does not exist" |
| 1215 |
} |
| 1216 |
forcedelete $fileName |
| 1217 |
} {} |
| 1218 |
|
| 1219 |
do_test shell1-6.1 { |
| 1220 |
catch {forcedelete test3.db} |
| 1221 |
set x [catchcmdex test3.db \ |
| 1222 |
"CREATE TABLE [encoding convertto utf-8 $test](x);\n.schema\n"] |
| 1223 |
set code [lindex $x 0] |
| 1224 |
set res [string trim [lindex $x 1]] |
| 1225 |
if {$code ne "0"} { |
| 1226 |
error "failed with error: $res" |
| 1227 |
} |
| 1228 |
if {$res ne "CREATE TABLE ${test}(x);"} { |
| 1229 |
error "failed with mismatch: $res" |
| 1230 |
} |
| 1231 |
forcedelete test3.db |
| 1232 |
} {} |
| 1233 |
} |
| 1234 |
|
| 1235 |
db close |
| 1236 |
forcedelete test.db test.db-journal test.db-wal |
| 1237 |
sqlite3 db test.db |
| 1238 |
|
| 1239 |
# The shell tool ".schema" command uses virtual table "pragma_database_list" |
| 1240 |
# |
| 1241 |
ifcapable vtab { |
| 1242 |
|
| 1243 |
do_test shell1-7.1.1 { |
| 1244 |
db eval { |
| 1245 |
CREATE TABLE Z (x TEXT PRIMARY KEY); |
| 1246 |
CREATE TABLE _ (x TEXT PRIMARY KEY); |
| 1247 |
CREATE TABLE YY (x TEXT PRIMARY KEY); |
| 1248 |
CREATE TABLE __ (x TEXT PRIMARY KEY); |
| 1249 |
CREATE TABLE WWW (x TEXT PRIMARY KEY); |
| 1250 |
CREATE TABLE ___ (x TEXT PRIMARY KEY); |
| 1251 |
} |
| 1252 |
} {} |
| 1253 |
do_test shell1-7.1.2 { |
| 1254 |
catchcmd "test.db" ".schema _" |
| 1255 |
} {0 {CREATE TABLE Z (x TEXT PRIMARY KEY); |
| 1256 |
CREATE TABLE _ (x TEXT PRIMARY KEY);}} |
| 1257 |
do_test shell1-7.1.3 { |
| 1258 |
catchcmd "test.db" ".schema \"\\\\_\"" |
| 1259 |
} {0 {CREATE TABLE _ (x TEXT PRIMARY KEY);}} |
| 1260 |
do_test shell1-7.1.4 { |
| 1261 |
catchcmd "test.db" ".schema __" |
| 1262 |
} {0 {CREATE TABLE YY (x TEXT PRIMARY KEY); |
| 1263 |
CREATE TABLE __ (x TEXT PRIMARY KEY);}} |
| 1264 |
do_test shell1-7.1.5 { |
| 1265 |
catchcmd "test.db" ".schema \"\\\\_\\\\_\"" |
| 1266 |
} {0 {CREATE TABLE __ (x TEXT PRIMARY KEY);}} |
| 1267 |
do_test shell1-7.1.6 { |
| 1268 |
catchcmd "test.db" ".schema ___" |
| 1269 |
} {0 {CREATE TABLE WWW (x TEXT PRIMARY KEY); |
| 1270 |
CREATE TABLE ___ (x TEXT PRIMARY KEY);}} |
| 1271 |
do_test shell1-7.1.7 { |
| 1272 |
catchcmd "test.db" ".schema \"\\\\_\\\\_\\\\_\"" |
| 1273 |
} {0 {CREATE TABLE ___ (x TEXT PRIMARY KEY);}} |
| 1274 |
|
| 1275 |
} |
| 1276 |
|
| 1277 |
# Test case for the ieee754 and decimal extensions in the shell. |
| 1278 |
# See the "floatingpoint.html" file in the documentation for more |
| 1279 |
# information. |
| 1280 |
# |
| 1281 |
do_test shell1-8.1 { |
| 1282 |
catchcmd ":memory:" {.mode batch |
| 1283 |
-- The pow2 table will hold all the necessary powers of two. |
| 1284 |
CREATE TABLE pow2(x INTEGER PRIMARY KEY, v TEXT); |
| 1285 |
WITH RECURSIVE c(x,v) AS ( |
| 1286 |
VALUES(0,'1') |
| 1287 |
UNION ALL |
| 1288 |
SELECT x+1, decimal_mul(v,'2') FROM c WHERE x+1<=971 |
| 1289 |
) INSERT INTO pow2(x,v) SELECT x, v FROM c; |
| 1290 |
WITH RECURSIVE c(x,v) AS ( |
| 1291 |
VALUES(-1,'0.5') |
| 1292 |
UNION ALL |
| 1293 |
SELECT x-1, decimal_mul(v,'0.5') FROM c WHERE x-1>=-1075 |
| 1294 |
) INSERT INTO pow2(x,v) SELECT x, v FROM c; |
| 1295 |
|
| 1296 |
-- This query finds the decimal representation of each value in the "c" table. |
| 1297 |
WITH c(n) AS (VALUES(47.49)) |
| 1298 |
----XXXXX----------- Replace with whatever you want |
| 1299 |
SELECT decimal_mul(ieee754_mantissa(c.n),pow2.v) |
| 1300 |
FROM pow2, c WHERE pow2.x=ieee754_exponent(c.n); |
| 1301 |
} |
| 1302 |
} {0 47.49000000000000198951966012828052043914794921875} |
| 1303 |
do_test_with_ansi_output shell1-8.2 { |
| 1304 |
catchcmd :memory: { |
| 1305 |
.mode box |
| 1306 |
SELECT ieee754(47.49) AS x; |
| 1307 |
} |
| 1308 |
} {0 {╭───────────────────────────────╮ |
| 1309 |
│ x │ |
| 1310 |
╞═══════════════════════════════╡ |
| 1311 |
│ ieee754(6683623321994527,-47) │ |
| 1312 |
╰───────────────────────────────╯}} |
| 1313 |
do_test_with_ansi_output shell1-8.3 { |
| 1314 |
catchcmd ":memory: --box" { |
| 1315 |
select ieee754(6683623321994527,-47) as x; |
| 1316 |
} |
| 1317 |
} {0 {╭───────╮ |
| 1318 |
│ x │ |
| 1319 |
╞═══════╡ |
| 1320 |
│ 47.49 │ |
| 1321 |
╰───────╯}} |
| 1322 |
do_test shell1-8.4 { |
| 1323 |
catchcmd ":memory: --table" {SELECT ieee754_mantissa(47.49) AS M, ieee754_exponent(47.49) AS E;} |
| 1324 |
} {0 {+------------------+-----+ |
| 1325 |
| M | E | |
| 1326 |
+------------------+-----+ |
| 1327 |
| 6683623321994527 | -47 | |
| 1328 |
+------------------+-----+}} |
| 1329 |
do_test shell1-8.4b { |
| 1330 |
catchcmd ":memory: --psql" \ |
| 1331 |
{SELECT ieee754_mantissa(47.49) AS M, ieee754_exponent(47.49) AS E;} |
| 1332 |
} {0 { M | E |
| 1333 |
------------------+----- |
| 1334 |
6683623321994527 | -47}} |
| 1335 |
do_test_with_ansi_output shell1-8.5 { |
| 1336 |
catchcmd ":memory: --box" { |
| 1337 |
create table t(a text, b int); |
| 1338 |
insert into t values ('too long for one line', 1), ('shorter', NULL); |
| 1339 |
.header on |
| 1340 |
.mode box --wordwrap off |
| 1341 |
.width 10 10 |
| 1342 |
.nullvalue NADA |
| 1343 |
select * from t;} |
| 1344 |
} {0 {╭────────────┬────────────╮ |
| 1345 |
│ a │ b │ |
| 1346 |
╞════════════╪════════════╡ |
| 1347 |
│ too long f │ 1 │ |
| 1348 |
│ or one lin │ │ |
| 1349 |
│ e │ │ |
| 1350 |
├────────────┼────────────┤ |
| 1351 |
│ shorter │ NADA │ |
| 1352 |
╰────────────┴────────────╯}} |
| 1353 |
|
| 1354 |
#---------------------------------------------------------------------------- |
| 1355 |
# Test cases shell1-9.*: Basic test that "dot" commands and SQL intermix ok. |
| 1356 |
# |
| 1357 |
do_test shell1-9.1 { |
| 1358 |
catchcmd :memory: { |
| 1359 |
.mode csv --rowsep "\n" |
| 1360 |
/* |
| 1361 |
x */ select 1,2; --x |
| 1362 |
-- .nada |
| 1363 |
; |
| 1364 |
.mode csv --rowsep "\n" |
| 1365 |
--x |
| 1366 |
select 2,1; select 3,4; |
| 1367 |
} |
| 1368 |
} {0 {1,2 |
| 1369 |
2,1 |
| 1370 |
3,4}} |
| 1371 |
|
| 1372 |
#---------------------------------------------------------------------------- |
| 1373 |
# Test cases shell1-10.*: Test that certain static extensions are there. |
| 1374 |
# |
| 1375 |
do_test shell1-10.1 { |
| 1376 |
catchcmd :memory: { |
| 1377 |
.mode list |
| 1378 |
.header off |
| 1379 |
select base64(base64(cast('digity-doo' as blob))), |
| 1380 |
base85(base85(cast('digity-doo' as blob))); |
| 1381 |
} |
| 1382 |
} {0 digity-doo|digity-doo} |
| 1383 |
|
| 1384 |
#---------------------------------------------------------------------------- |
| 1385 |
# Test cases shell1-11.*: |
| 1386 |
# |
| 1387 |
do_test shell1-11.1 { |
| 1388 |
catchcmd :memory: { |
| 1389 |
.mode list |
| 1390 |
.header off |
| 1391 |
select base64(zeroblob(2000000000)); |
| 1392 |
} |
| 1393 |
} {/1.*too big.*/} |
| 1394 |
do_test shell1-11.2 { |
| 1395 |
catchcmd :memory: { |
| 1396 |
.mode list |
| 1397 |
.header off |
| 1398 |
select base85(zeroblob(2000000000)); |
| 1399 |
} |
| 1400 |
} {/1.*too big.*/} |
| 1401 |
|
| 1402 |
#---------------------------------------------------------------------------- |
| 1403 |
# As of 2025-11-17, the default mode is: |
| 1404 |
# |
| 1405 |
# qbox --screenwidth auto --linelimit 5 --charlimit 300 --textjsonb on |
| 1406 |
# |
| 1407 |
do_test shell1-12.1 { |
| 1408 |
catchcmd :memory: {.mode tty -quote sql |
| 1409 |
.print |
| 1410 |
SELECT jsonb(1234) AS x;} |
| 1411 |
} {0 { |
| 1412 |
╭───────────────╮ |
| 1413 |
│ x │ |
| 1414 |
╞═══════════════╡ |
| 1415 |
│ jsonb('1234') │ |
| 1416 |
╰───────────────╯}} |
| 1417 |
do_test shell1-12.2 { |
| 1418 |
catchcmd :memory: {.mode box --textjsonb on |
| 1419 |
.print |
| 1420 |
SELECT jsonb(1234) AS x;} |
| 1421 |
} {0 { |
| 1422 |
╭──────╮ |
| 1423 |
│ x │ |
| 1424 |
╞══════╡ |
| 1425 |
│ 1234 │ |
| 1426 |
╰──────╯}} |
| 1427 |
|
| 1428 |
finish_test |