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# 15 16# Test plan: 17# 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. 21# 22set testdir [file dirname $argv0] 23source $testdir/tester.tcl 24if {$tcl_platform(platform)=="windows"} { 25 set CLI "sqlite3.exe" 26} else { 27 set CLI "./sqlite3" 28} 29if {![file executable $CLI]} { 30 finish_test 31 return 32} 33db close 34forcedelete test.db test.db-journal test.db-wal 35sqlite3 db test.db 36 37#---------------------------------------------------------------------------- 38# Test cases shell1-1.*: Basic command line option handling. 39# 40 41# invalid option 42do_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} 48# error on extra options 49do_test shell1-1.1.2 { 50 set res [catchcmd "-bad test.db \"select 3\" \"select 4\"" ""] 51 set rc [lindex $res 0] 52 list $rc \ 53 [regexp {Error: too many options: "select 4"} $res] 54} {1 1} 55# error on extra options 56do_test shell1-1.1.3 { 57 set res [catchcmd "-bad FOO test.db BAD" ".quit"] 58 set rc [lindex $res 0] 59 list $rc \ 60 [regexp {Error: too many options: "BAD"} $res] 61} {1 1} 62 63# -help 64do_test shell1-1.2.1 { 65 set res [catchcmd "-help test.db" ""] 66 set rc [lindex $res 0] 67 list $rc \ 68 [regexp {Usage} $res] \ 69 [regexp {\-init} $res] \ 70 [regexp {\-version} $res] 71} {1 1 1 1} 72 73# -init filename read/process named file 74do_test shell1-1.3.1 { 75 catchcmd "-init FOO test.db" "" 76} {0 {}} 77do_test shell1-1.3.2 { 78 set res [catchcmd "-init FOO test.db .quit BAD" ""] 79 set rc [lindex $res 0] 80 list $rc \ 81 [regexp {Error: too many options: "BAD"} $res] 82} {1 1} 83 84# -echo print commands before execution 85do_test shell1-1.4.1 { 86 catchcmd "-echo test.db" "" 87} {0 {}} 88 89# -[no]header turn headers on or off 90do_test shell1-1.5.1 { 91 catchcmd "-header test.db" "" 92} {0 {}} 93do_test shell1-1.5.2 { 94 catchcmd "-noheader test.db" "" 95} {0 {}} 96 97# -bail stop after hitting an error 98do_test shell1-1.6.1 { 99 catchcmd "-bail test.db" "" 100} {0 {}} 101 102# -interactive force interactive I/O 103do_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 112do_test shell1-1.8.1 { 113 catchcmd "-batch test.db" "" 114} {0 {}} 115 116# -column set output mode to 'column' 117do_test shell1-1.9.1 { 118 catchcmd "-column test.db" "" 119} {0 {}} 120 121# -csv set output mode to 'csv' 122do_test shell1-1.10.1 { 123 catchcmd "-csv test.db" "" 124} {0 {}} 125 126# -html set output mode to HTML 127do_test shell1-1.11.1 { 128 catchcmd "-html test.db" "" 129} {0 {}} 130 131# -line set output mode to 'line' 132do_test shell1-1.12.1 { 133 catchcmd "-line test.db" "" 134} {0 {}} 135 136# -list set output mode to 'list' 137do_test shell1-1.13.1 { 138 catchcmd "-list test.db" "" 139} {0 {}} 140 141# -separator 'x' set output field separator (|) 142do_test shell1-1.14.1 { 143 catchcmd "-separator 'x' test.db" "" 144} {0 {}} 145do_test shell1-1.14.2 { 146 catchcmd "-separator x test.db" "" 147} {0 {}} 148do_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 156do_test shell1-1.14b.1 { 157 catchcmd "-stats test.db" "" 158} {0 {}} 159 160# -nullvalue 'text' set text string for NULL values 161do_test shell1-1.15.1 { 162 catchcmd "-nullvalue 'x' test.db" "" 163} {0 {}} 164do_test shell1-1.15.2 { 165 catchcmd "-nullvalue x test.db" "" 166} {0 {}} 167do_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 175do_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#---------------------------------------------------------------------------- 180# Test cases shell1-2.*: Basic "dot" command token parsing. 181# 182 183# check first token handling 184do_test shell1-2.1.1 { 185 catchcmd "test.db" ".foo" 186} {1 {Error: unknown command or invalid arguments: "foo". Enter ".help" for help}} 187do_test shell1-2.1.2 { 188 catchcmd "test.db" ".\"foo OFF\"" 189} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}} 190do_test shell1-2.1.3 { 191 catchcmd "test.db" ".\'foo OFF\'" 192} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}} 193 194# unbalanced quotes 195do_test shell1-2.2.1 { 196 catchcmd "test.db" ".\"foo OFF" 197} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}} 198do_test shell1-2.2.2 { 199 catchcmd "test.db" ".\'foo OFF" 200} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}} 201do_test shell1-2.2.3 { 202 catchcmd "test.db" ".explain \"OFF" 203} {0 {}} 204do_test shell1-2.2.4 { 205 catchcmd "test.db" ".explain \'OFF" 206} {0 {}} 207do_test shell1-2.2.5 { 208 catchcmd "test.db" ".mode \"insert FOO" 209} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}} 210do_test shell1-2.2.6 { 211 catchcmd "test.db" ".mode \'insert FOO" 212} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}} 213 214# check multiple tokens, and quoted tokens 215do_test shell1-2.3.1 { 216 catchcmd "test.db" ".explain 1" 217} {0 {}} 218do_test shell1-2.3.2 { 219 catchcmd "test.db" ".explain on" 220} {0 {}} 221do_test shell1-2.3.3 { 222 catchcmd "test.db" ".explain \"1 2 3\"" 223} {1 {ERROR: Not a boolean value: "1 2 3". Assuming "no".}} 224do_test shell1-2.3.4 { 225 catchcmd "test.db" ".explain \"OFF\"" 226} {0 {}} 227do_test shell1-2.3.5 { 228 catchcmd "test.db" ".\'explain\' \'OFF\'" 229} {0 {}} 230do_test shell1-2.3.6 { 231 catchcmd "test.db" ".explain \'OFF\'" 232} {0 {}} 233do_test shell1-2.3.7 { 234 catchcmd "test.db" ".\'explain\' \'OFF\'" 235} {0 {}} 236 237# check quoted args are unquoted 238do_test shell1-2.4.1 { 239 catchcmd "test.db" ".mode FOO" 240} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}} 241do_test shell1-2.4.2 { 242 catchcmd "test.db" ".mode csv" 243} {0 {}} 244do_test shell1-2.4.2 { 245 catchcmd "test.db" ".mode \"csv\"" 246} {0 {}} 247 248 249#---------------------------------------------------------------------------- 250# Test cases shell1-3.*: Basic test that "dot" command can be called. 251# 252 253# .backup ?DB? FILE Backup DB (default "main") to FILE 254do_test shell1-3.1.1 { 255 catchcmd "test.db" ".backup" 256} {1 {missing FILENAME argument on .backup}} 257do_test shell1-3.1.2 { 258 catchcmd "test.db" ".backup FOO" 259} {0 {}} 260do_test shell1-3.1.3 { 261 catchcmd "test.db" ".backup FOO BAR" 262} {1 {Error: unknown database FOO}} 263do_test shell1-3.1.4 { 264 # too many arguments 265 catchcmd "test.db" ".backup FOO BAR BAD" 266} {1 {too many arguments to .backup}} 267 268# .bail ON|OFF Stop after hitting an error. Default OFF 269do_test shell1-3.2.1 { 270 catchcmd "test.db" ".bail" 271} {1 {Usage: .bail on|off}} 272do_test shell1-3.2.2 { 273 catchcmd "test.db" ".bail ON" 274} {0 {}} 275do_test shell1-3.2.3 { 276 catchcmd "test.db" ".bail OFF" 277} {0 {}} 278do_test shell1-3.2.4 { 279 # too many arguments 280 catchcmd "test.db" ".bail OFF BAD" 281} {1 {Usage: .bail on|off}} 282 283# .databases List names and files of attached databases 284do_test shell1-3.3.1 { 285 catchcmd "-csv test.db" ".databases" 286} "/0 +.*main +[string map {/ .} [string range [get_pwd] 0 10]].*/" 287do_test shell1-3.3.2 { 288 # extra arguments ignored 289 catchcmd "test.db" ".databases BAD" 290} "/0 +.*main +[string map {/ .} [string range [get_pwd] 0 10]].*/" 291 292# .dump ?TABLE? ... Dump the database in an SQL text format 293# If TABLE specified, only dump tables matching 294# LIKE pattern TABLE. 295do_test shell1-3.4.1 { 296 set res [catchcmd "test.db" ".dump"] 297 list [regexp {BEGIN TRANSACTION;} $res] \ 298 [regexp {COMMIT;} $res] 299} {1 1} 300do_test shell1-3.4.2 { 301 set res [catchcmd "test.db" ".dump FOO"] 302 list [regexp {BEGIN TRANSACTION;} $res] \ 303 [regexp {COMMIT;} $res] 304} {1 1} 305do_test shell1-3.4.3 { 306 # too many arguments 307 catchcmd "test.db" ".dump FOO BAD" 308} {1 {Usage: .dump ?LIKE-PATTERN?}} 309 310# .echo ON|OFF Turn command echo on or off 311do_test shell1-3.5.1 { 312 catchcmd "test.db" ".echo" 313} {1 {Usage: .echo on|off}} 314do_test shell1-3.5.2 { 315 catchcmd "test.db" ".echo ON" 316} {0 {}} 317do_test shell1-3.5.3 { 318 catchcmd "test.db" ".echo OFF" 319} {0 {}} 320do_test shell1-3.5.4 { 321 # too many arguments 322 catchcmd "test.db" ".echo OFF BAD" 323} {1 {Usage: .echo on|off}} 324 325# .exit Exit this program 326do_test shell1-3.6.1 { 327 catchcmd "test.db" ".exit" 328} {0 {}} 329 330# .explain ON|OFF Turn output mode suitable for EXPLAIN on or off. 331do_test shell1-3.7.1 { 332 catchcmd "test.db" ".explain" 333 # explain is the exception to the booleans. without an option, it turns it on. 334} {0 {}} 335do_test shell1-3.7.2 { 336 catchcmd "test.db" ".explain ON" 337} {0 {}} 338do_test shell1-3.7.3 { 339 catchcmd "test.db" ".explain OFF" 340} {0 {}} 341do_test shell1-3.7.4 { 342 # extra arguments ignored 343 catchcmd "test.db" ".explain OFF BAD" 344} {0 {}} 345 346 347# .header(s) ON|OFF Turn display of headers on or off 348do_test shell1-3.9.1 { 349 catchcmd "test.db" ".header" 350} {1 {Usage: .headers on|off}} 351do_test shell1-3.9.2 { 352 catchcmd "test.db" ".header ON" 353} {0 {}} 354do_test shell1-3.9.3 { 355 catchcmd "test.db" ".header OFF" 356} {0 {}} 357do_test shell1-3.9.4 { 358 # too many arguments 359 catchcmd "test.db" ".header OFF BAD" 360} {1 {Usage: .headers on|off}} 361 362do_test shell1-3.9.5 { 363 catchcmd "test.db" ".headers" 364} {1 {Usage: .headers on|off}} 365do_test shell1-3.9.6 { 366 catchcmd "test.db" ".headers ON" 367} {0 {}} 368do_test shell1-3.9.7 { 369 catchcmd "test.db" ".headers OFF" 370} {0 {}} 371do_test shell1-3.9.8 { 372 # too many arguments 373 catchcmd "test.db" ".headers OFF BAD" 374} {1 {Usage: .headers on|off}} 375 376# .help Show this message 377do_test shell1-3.10.1 { 378 set res [catchcmd "test.db" ".help"] 379 # look for a few of the possible help commands 380 list [regexp {.help} $res] \ 381 [regexp {.quit} $res] \ 382 [regexp {.show} $res] 383} {1 1 1} 384do_test shell1-3.10.2 { 385 # we allow .help to take extra args (it is help after all) 386 set res [catchcmd "test.db" ".help BAD"] 387 # look for a few of the possible help commands 388 list [regexp {.help} $res] \ 389 [regexp {.quit} $res] \ 390 [regexp {.show} $res] 391} {1 1 1} 392 393# .import FILE TABLE Import data from FILE into TABLE 394do_test shell1-3.11.1 { 395 catchcmd "test.db" ".import" 396} {1 {Usage: .import FILE TABLE}} 397do_test shell1-3.11.2 { 398 catchcmd "test.db" ".import FOO" 399} {1 {Usage: .import FILE TABLE}} 400#do_test shell1-3.11.2 { 401# catchcmd "test.db" ".import FOO BAR" 402#} {1 {Error: no such table: BAR}} 403do_test shell1-3.11.3 { 404 # too many arguments 405 catchcmd "test.db" ".import FOO BAR BAD" 406} {1 {Usage: .import FILE TABLE}} 407 408# .indices ?TABLE? Show names of all indices 409# If TABLE specified, only show indices for tables 410# matching LIKE pattern TABLE. 411do_test shell1-3.12.1 { 412 catchcmd "test.db" ".indices" 413} {0 {}} 414do_test shell1-3.12.2 { 415 catchcmd "test.db" ".indices FOO" 416} {0 {}} 417do_test shell1-3.12.3 { 418 # too many arguments 419 catchcmd "test.db" ".indices FOO BAD" 420} {1 {Usage: .indices ?LIKE-PATTERN?}} 421 422# .mode MODE ?TABLE? Set output mode where MODE is one of: 423# csv Comma-separated values 424# column Left-aligned columns. (See .width) 425# html HTML <table> code 426# insert SQL insert statements for TABLE 427# line One value per line 428# list Values delimited by .separator string 429# tabs Tab-separated values 430# tcl TCL list elements 431do_test shell1-3.13.1 { 432 catchcmd "test.db" ".mode" 433} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}} 434do_test shell1-3.13.2 { 435 catchcmd "test.db" ".mode FOO" 436} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}} 437do_test shell1-3.13.3 { 438 catchcmd "test.db" ".mode csv" 439} {0 {}} 440do_test shell1-3.13.4 { 441 catchcmd "test.db" ".mode column" 442} {0 {}} 443do_test shell1-3.13.5 { 444 catchcmd "test.db" ".mode html" 445} {0 {}} 446do_test shell1-3.13.6 { 447 catchcmd "test.db" ".mode insert" 448} {0 {}} 449do_test shell1-3.13.7 { 450 catchcmd "test.db" ".mode line" 451} {0 {}} 452do_test shell1-3.13.8 { 453 catchcmd "test.db" ".mode list" 454} {0 {}} 455do_test shell1-3.13.9 { 456 catchcmd "test.db" ".mode tabs" 457} {0 {}} 458do_test shell1-3.13.10 { 459 catchcmd "test.db" ".mode tcl" 460} {0 {}} 461do_test shell1-3.13.11 { 462 # extra arguments ignored 463 catchcmd "test.db" ".mode tcl BAD" 464} {0 {}} 465 466# don't allow partial mode type matches 467do_test shell1-3.13.12 { 468 catchcmd "test.db" ".mode l" 469} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}} 470do_test shell1-3.13.13 { 471 catchcmd "test.db" ".mode li" 472} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}} 473do_test shell1-3.13.14 { 474 catchcmd "test.db" ".mode lin" 475} {0 {}} 476 477# .nullvalue STRING Print STRING in place of NULL values 478do_test shell1-3.14.1 { 479 catchcmd "test.db" ".nullvalue" 480} {1 {Usage: .nullvalue STRING}} 481do_test shell1-3.14.2 { 482 catchcmd "test.db" ".nullvalue FOO" 483} {0 {}} 484do_test shell1-3.14.3 { 485 # too many arguments 486 catchcmd "test.db" ".nullvalue FOO BAD" 487} {1 {Usage: .nullvalue STRING}} 488 489# .output FILENAME Send output to FILENAME 490do_test shell1-3.15.1 { 491 catchcmd "test.db" ".output" 492} {0 {}} 493do_test shell1-3.15.2 { 494 catchcmd "test.db" ".output FOO" 495} {0 {}} 496do_test shell1-3.15.3 { 497 # too many arguments 498 catchcmd "test.db" ".output FOO BAD" 499} {1 {Usage: .output FILE}} 500 501# .output stdout Send output to the screen 502do_test shell1-3.16.1 { 503 catchcmd "test.db" ".output stdout" 504} {0 {}} 505do_test shell1-3.16.2 { 506 # too many arguments 507 catchcmd "test.db" ".output stdout BAD" 508} {1 {Usage: .output FILE}} 509 510# .prompt MAIN CONTINUE Replace the standard prompts 511do_test shell1-3.17.1 { 512 catchcmd "test.db" ".prompt" 513} {0 {}} 514do_test shell1-3.17.2 { 515 catchcmd "test.db" ".prompt FOO" 516} {0 {}} 517do_test shell1-3.17.3 { 518 catchcmd "test.db" ".prompt FOO BAR" 519} {0 {}} 520do_test shell1-3.17.4 { 521 # too many arguments 522 catchcmd "test.db" ".prompt FOO BAR BAD" 523} {0 {}} 524 525# .quit Exit this program 526do_test shell1-3.18.1 { 527 catchcmd "test.db" ".quit" 528} {0 {}} 529do_test shell1-3.18.2 { 530 # too many arguments 531 catchcmd "test.db" ".quit BAD" 532} {0 {}} 533 534# .read FILENAME Execute SQL in FILENAME 535do_test shell1-3.19.1 { 536 catchcmd "test.db" ".read" 537} {1 {Usage: .read FILE}} 538do_test shell1-3.19.2 { 539 forcedelete FOO 540 catchcmd "test.db" ".read FOO" 541} {1 {Error: cannot open "FOO"}} 542do_test shell1-3.19.3 { 543 # too many arguments 544 catchcmd "test.db" ".read FOO BAD" 545} {1 {Usage: .read FILE}} 546 547# .restore ?DB? FILE Restore content of DB (default "main") from FILE 548do_test shell1-3.20.1 { 549 catchcmd "test.db" ".restore" 550} {1 {Usage: .restore ?DB? FILE}} 551do_test shell1-3.20.2 { 552 catchcmd "test.db" ".restore FOO" 553} {0 {}} 554do_test shell1-3.20.3 { 555 catchcmd "test.db" ".restore FOO BAR" 556} {1 {Error: unknown database FOO}} 557do_test shell1-3.20.4 { 558 # too many arguments 559 catchcmd "test.db" ".restore FOO BAR BAD" 560} {1 {Usage: .restore ?DB? FILE}} 561 562# .schema ?TABLE? Show the CREATE statements 563# If TABLE specified, only show tables matching 564# LIKE pattern TABLE. 565do_test shell1-3.21.1 { 566 catchcmd "test.db" ".schema" 567} {0 {}} 568do_test shell1-3.21.2 { 569 catchcmd "test.db" ".schema FOO" 570} {0 {}} 571do_test shell1-3.21.3 { 572 # too many arguments 573 catchcmd "test.db" ".schema FOO BAD" 574} {1 {Usage: .schema ?LIKE-PATTERN?}} 575 576do_test shell1-3.21.4 { 577 catchcmd "test.db" { 578 CREATE TABLE t1(x); 579 CREATE VIEW v2 AS SELECT x+1 AS y FROM t1; 580 CREATE VIEW v1 AS SELECT y+1 FROM v2; 581 } 582 catchcmd "test.db" ".schema" 583} {0 {CREATE TABLE t1(x); 584CREATE VIEW v2 AS SELECT x+1 AS y FROM t1; 585CREATE VIEW v1 AS SELECT y+1 FROM v2;}} 586db eval {DROP VIEW v1; DROP VIEW v2; DROP TABLE t1;} 587 588# .separator STRING Change separator used by output mode and .import 589do_test shell1-3.22.1 { 590 catchcmd "test.db" ".separator" 591} {1 {Usage: .separator SEPARATOR ?NEWLINE?}} 592do_test shell1-3.22.2 { 593 catchcmd "test.db" ".separator FOO" 594} {0 {}} 595do_test shell1-3.22.3 { 596 catchcmd "test.db" ".separator ABC XYZ" 597} {0 {}} 598do_test shell1-3.22.4 { 599 # too many arguments 600 catchcmd "test.db" ".separator FOO BAD BAD2" 601} {1 {Usage: .separator SEPARATOR ?NEWLINE?}} 602 603# .show Show the current values for various settings 604do_test shell1-3.23.1 { 605 set res [catchcmd "test.db" ".show"] 606 list [regexp {echo:} $res] \ 607 [regexp {explain:} $res] \ 608 [regexp {headers:} $res] \ 609 [regexp {mode:} $res] \ 610 [regexp {nullvalue:} $res] \ 611 [regexp {output:} $res] \ 612 [regexp {separator:} $res] \ 613 [regexp {stats:} $res] \ 614 [regexp {width:} $res] 615} {1 1 1 1 1 1 1 1 1} 616do_test shell1-3.23.2 { 617 # too many arguments 618 catchcmd "test.db" ".show BAD" 619} {1 {Usage: .show}} 620 621# .stats ON|OFF Turn stats on or off 622do_test shell1-3.23b.1 { 623 catchcmd "test.db" ".stats" 624} {1 {Usage: .stats on|off}} 625do_test shell1-3.23b.2 { 626 catchcmd "test.db" ".stats ON" 627} {0 {}} 628do_test shell1-3.23b.3 { 629 catchcmd "test.db" ".stats OFF" 630} {0 {}} 631do_test shell1-3.23b.4 { 632 # too many arguments 633 catchcmd "test.db" ".stats OFF BAD" 634} {1 {Usage: .stats on|off}} 635 636# .tables ?TABLE? List names of tables 637# If TABLE specified, only list tables matching 638# LIKE pattern TABLE. 639do_test shell1-3.24.1 { 640 catchcmd "test.db" ".tables" 641} {0 {}} 642do_test shell1-3.24.2 { 643 catchcmd "test.db" ".tables FOO" 644} {0 {}} 645do_test shell1-3.24.3 { 646 # too many arguments 647 catchcmd "test.db" ".tables FOO BAD" 648} {0 {}} 649 650# .timeout MS Try opening locked tables for MS milliseconds 651do_test shell1-3.25.1 { 652 catchcmd "test.db" ".timeout" 653} {0 {}} 654do_test shell1-3.25.2 { 655 catchcmd "test.db" ".timeout zzz" 656 # this should be treated the same as a '0' timeout 657} {0 {}} 658do_test shell1-3.25.3 { 659 catchcmd "test.db" ".timeout 1" 660} {0 {}} 661do_test shell1-3.25.4 { 662 # too many arguments 663 catchcmd "test.db" ".timeout 1 BAD" 664} {0 {}} 665 666# .width NUM NUM ... Set column widths for "column" mode 667do_test shell1-3.26.1 { 668 catchcmd "test.db" ".width" 669} {0 {}} 670do_test shell1-3.26.2 { 671 catchcmd "test.db" ".width xxx" 672 # this should be treated the same as a '0' width for col 1 673} {0 {}} 674do_test shell1-3.26.3 { 675 catchcmd "test.db" ".width xxx yyy" 676 # this should be treated the same as a '0' width for col 1 and 2 677} {0 {}} 678do_test shell1-3.26.4 { 679 catchcmd "test.db" ".width 1 1" 680 # this should be treated the same as a '1' width for col 1 and 2 681} {0 {}} 682do_test shell1-3.26.5 { 683 catchcmd "test.db" ".mode column\n.width 10 -10\nSELECT 'abcdefg', 123456;" 684 # this should be treated the same as a '1' width for col 1 and 2 685} {0 {abcdefg 123456}} 686do_test shell1-3.26.6 { 687 catchcmd "test.db" ".mode column\n.width -10 10\nSELECT 'abcdefg', 123456;" 688 # this should be treated the same as a '1' width for col 1 and 2 689} {0 { abcdefg 123456 }} 690 691 692# .timer ON|OFF Turn the CPU timer measurement on or off 693do_test shell1-3.27.1 { 694 catchcmd "test.db" ".timer" 695} {1 {Usage: .timer on|off}} 696do_test shell1-3.27.2 { 697 catchcmd "test.db" ".timer ON" 698} {0 {}} 699do_test shell1-3.27.3 { 700 catchcmd "test.db" ".timer OFF" 701} {0 {}} 702do_test shell1-3.27.4 { 703 # too many arguments 704 catchcmd "test.db" ".timer OFF BAD" 705} {1 {Usage: .timer on|off}} 706 707do_test shell1-3-28.1 { 708 catchcmd test.db \ 709 ".log stdout\nSELECT coalesce(sqlite_log(123,'hello'),'456');" 710} "0 {(123) hello\n456}" 711 712do_test shell1-3-29.1 { 713 catchcmd "test.db" ".print this is a test" 714} {0 {this is a test}} 715 716# dot-command argument quoting 717do_test shell1-3-30.1 { 718 catchcmd {test.db} {.print "this\"is'a\055test" 'this\"is\\a\055test'} 719} {0 {this"is'a-test this\"is\\a\055test}} 720do_test shell1-3-31.1 { 721 catchcmd {test.db} {.print "this\nis\ta\\test" 'this\nis\ta\\test'} 722} [list 0 "this\nis\ta\\test this\\nis\\ta\\\\test"] 723 724 725# Test the output of the ".dump" command 726# 727do_test shell1-4.1 { 728 db close 729 forcedelete test.db 730 sqlite3 db test.db 731 db eval { 732 PRAGMA encoding=UTF16; 733 CREATE TABLE t1(x); 734 INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f'); 735 } 736 catchcmd test.db {.dump} 737} {0 {PRAGMA foreign_keys=OFF; 738BEGIN TRANSACTION; 739CREATE TABLE t1(x); 740INSERT INTO "t1" VALUES(NULL); 741INSERT INTO "t1" VALUES(''); 742INSERT INTO "t1" VALUES(1); 743INSERT INTO "t1" VALUES(2.25); 744INSERT INTO "t1" VALUES('hello'); 745INSERT INTO "t1" VALUES(X'807F'); 746COMMIT;}} 747 748# Test the output of ".mode insert" 749# 750do_test shell1-4.2 { 751 catchcmd test.db ".mode insert t1\nselect * from t1;" 752} {0 {INSERT INTO t1 VALUES(NULL); 753INSERT INTO t1 VALUES(''); 754INSERT INTO t1 VALUES(1); 755INSERT INTO t1 VALUES(2.25); 756INSERT INTO t1 VALUES('hello'); 757INSERT INTO t1 VALUES(X'807f');}} 758 759# Test the output of ".mode tcl" 760# 761do_test shell1-4.3 { 762 db close 763 forcedelete test.db 764 sqlite3 db test.db 765 db eval { 766 PRAGMA encoding=UTF8; 767 CREATE TABLE t1(x); 768 INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f'); 769 } 770 catchcmd test.db ".mode tcl\nselect * from t1;" 771} {0 {"" 772"" 773"1" 774"2.25" 775"hello" 776"\200\177"}} 777 778# Test the output of ".mode tcl" with multiple columns 779# 780do_test shell1-4.4 { 781 db eval { 782 CREATE TABLE t2(x,y); 783 INSERT INTO t2 VALUES(null, ''), (1, 2.25), ('hello', x'807f'); 784 } 785 catchcmd test.db ".mode tcl\nselect * from t2;" 786} {0 {"" "" 787"1" "2.25" 788"hello" "\200\177"}} 789 790# Test the output of ".mode tcl" with ".nullvalue" 791# 792do_test shell1-4.5 { 793 catchcmd test.db ".mode tcl\n.nullvalue NULL\nselect * from t2;" 794} {0 {"NULL" "" 795"1" "2.25" 796"hello" "\200\177"}} 797 798# Test the output of ".mode tcl" with Tcl reserved characters 799# 800do_test shell1-4.6 { 801 db eval { 802 CREATE TABLE tcl1(x); 803 INSERT INTO tcl1 VALUES('"'), ('['), (']'), ('\{'), ('\}'), (';'), ('$'); 804 } 805 foreach {x y} [catchcmd test.db ".mode tcl\nselect * from tcl1;"] break 806 list $x $y [llength $y] 807} {0 {"\"" 808"[" 809"]" 810"\\{" 811"\\}" 812";" 813"$"} 7} 814 815finish_test 816