xref: /sqlite-3.40.0/test/shell1.test (revision 86ab48fc)
18df9185cSdrh# 2009 Nov 11
28df9185cSdrh#
38df9185cSdrh# The author disclaims copyright to this source code.  In place of
48df9185cSdrh# a legal notice, here is a blessing:
58df9185cSdrh#
68df9185cSdrh#    May you do good and not evil.
78df9185cSdrh#    May you find forgiveness for yourself and forgive others.
88df9185cSdrh#    May you share freely, never taking more than you give.
98df9185cSdrh#
108df9185cSdrh#***********************************************************************
118df9185cSdrh#
128df9185cSdrh# The focus of this file is testing the CLI shell tool.
138df9185cSdrh#
148df9185cSdrh#
158df9185cSdrh
168df9185cSdrh# Test plan:
178df9185cSdrh#
188df9185cSdrh#   shell1-1.*: Basic command line option handling.
198df9185cSdrh#   shell1-2.*: Basic "dot" command token parsing.
208df9185cSdrh#   shell1-3.*: Basic test that "dot" command can be called.
218df9185cSdrh#
228df9185cSdrhset testdir [file dirname $argv0]
238df9185cSdrhsource $testdir/tester.tcl
248df9185cSdrhif {$tcl_platform(platform)=="windows"} {
258df9185cSdrh  set CLI "sqlite3.exe"
268df9185cSdrh} else {
278df9185cSdrh  set CLI "./sqlite3"
288df9185cSdrh}
298df9185cSdrhif {![file executable $CLI]} {
308df9185cSdrh  finish_test
318df9185cSdrh  return
328df9185cSdrh}
338df9185cSdrhdb close
348df9185cSdrhforcedelete test.db test.db-journal test.db-wal
358df9185cSdrhsqlite3 db test.db
368df9185cSdrh
378df9185cSdrh#----------------------------------------------------------------------------
388df9185cSdrh# Test cases shell1-1.*: Basic command line option handling.
398df9185cSdrh#
408df9185cSdrh
418df9185cSdrh# invalid option
428df9185cSdrhdo_test shell1-1.1.1 {
438df9185cSdrh  set res [catchcmd "-bad test.db" ""]
448df9185cSdrh  set rc [lindex $res 0]
458df9185cSdrh  list $rc \
468df9185cSdrh       [regexp {Error: unknown option: -bad} $res]
478df9185cSdrh} {1 1}
488df9185cSdrh# error on extra options
498df9185cSdrhdo_test shell1-1.1.2 {
508df9185cSdrh  set res [catchcmd "-bad test.db \"select 3\" \"select 4\"" ""]
518df9185cSdrh  set rc [lindex $res 0]
528df9185cSdrh  list $rc \
538df9185cSdrh       [regexp {Error: too many options: "select 4"} $res]
548df9185cSdrh} {1 1}
558df9185cSdrh# error on extra options
568df9185cSdrhdo_test shell1-1.1.3 {
578df9185cSdrh  set res [catchcmd "-bad FOO test.db BAD" ".quit"]
588df9185cSdrh  set rc [lindex $res 0]
598df9185cSdrh  list $rc \
608df9185cSdrh       [regexp {Error: too many options: "BAD"} $res]
618df9185cSdrh} {1 1}
628df9185cSdrh
638df9185cSdrh# -help
648df9185cSdrhdo_test shell1-1.2.1 {
658df9185cSdrh  set res [catchcmd "-help test.db" ""]
668df9185cSdrh  set rc [lindex $res 0]
678df9185cSdrh  list $rc \
688df9185cSdrh       [regexp {Usage} $res] \
698df9185cSdrh       [regexp {\-init} $res] \
708df9185cSdrh       [regexp {\-version} $res]
718df9185cSdrh} {1 1 1 1}
728df9185cSdrh
738df9185cSdrh# -init filename       read/process named file
748df9185cSdrhdo_test shell1-1.3.1 {
758df9185cSdrh  catchcmd "-init FOO test.db" ""
768df9185cSdrh} {0 {}}
778df9185cSdrhdo_test shell1-1.3.2 {
788df9185cSdrh  set res [catchcmd "-init FOO test.db .quit BAD" ""]
798df9185cSdrh  set rc [lindex $res 0]
808df9185cSdrh  list $rc \
818df9185cSdrh       [regexp {Error: too many options: "BAD"} $res]
828df9185cSdrh} {1 1}
838df9185cSdrh
848df9185cSdrh# -echo                print commands before execution
858df9185cSdrhdo_test shell1-1.4.1 {
868df9185cSdrh  catchcmd "-echo test.db" ""
878df9185cSdrh} {0 {}}
888df9185cSdrh
898df9185cSdrh# -[no]header          turn headers on or off
908df9185cSdrhdo_test shell1-1.5.1 {
918df9185cSdrh  catchcmd "-header test.db" ""
928df9185cSdrh} {0 {}}
938df9185cSdrhdo_test shell1-1.5.2 {
948df9185cSdrh  catchcmd "-noheader test.db" ""
958df9185cSdrh} {0 {}}
968df9185cSdrh
978df9185cSdrh# -bail                stop after hitting an error
988df9185cSdrhdo_test shell1-1.6.1 {
998df9185cSdrh  catchcmd "-bail test.db" ""
1008df9185cSdrh} {0 {}}
1018df9185cSdrh
1028df9185cSdrh# -interactive         force interactive I/O
1038df9185cSdrhdo_test shell1-1.7.1 {
1048df9185cSdrh  set res [catchcmd "-interactive test.db" ".quit"]
1058df9185cSdrh  set rc [lindex $res 0]
1068df9185cSdrh  list $rc \
1078df9185cSdrh       [regexp {SQLite version} $res] \
1088df9185cSdrh       [regexp {Enter SQL statements} $res]
1098df9185cSdrh} {0 1 1}
1108df9185cSdrh
1118df9185cSdrh# -batch               force batch I/O
1128df9185cSdrhdo_test shell1-1.8.1 {
1138df9185cSdrh  catchcmd "-batch test.db" ""
1148df9185cSdrh} {0 {}}
1158df9185cSdrh
1168df9185cSdrh# -column              set output mode to 'column'
1178df9185cSdrhdo_test shell1-1.9.1 {
1188df9185cSdrh  catchcmd "-column test.db" ""
1198df9185cSdrh} {0 {}}
1208df9185cSdrh
1218df9185cSdrh# -csv                 set output mode to 'csv'
1228df9185cSdrhdo_test shell1-1.10.1 {
1238df9185cSdrh  catchcmd "-csv test.db" ""
1248df9185cSdrh} {0 {}}
1258df9185cSdrh
1268df9185cSdrh# -html                set output mode to HTML
1278df9185cSdrhdo_test shell1-1.11.1 {
1288df9185cSdrh  catchcmd "-html test.db" ""
1298df9185cSdrh} {0 {}}
1308df9185cSdrh
1318df9185cSdrh# -line                set output mode to 'line'
1328df9185cSdrhdo_test shell1-1.12.1 {
1338df9185cSdrh  catchcmd "-line test.db" ""
1348df9185cSdrh} {0 {}}
1358df9185cSdrh
1368df9185cSdrh# -list                set output mode to 'list'
1378df9185cSdrhdo_test shell1-1.13.1 {
1388df9185cSdrh  catchcmd "-list test.db" ""
1398df9185cSdrh} {0 {}}
1408df9185cSdrh
1418df9185cSdrh# -separator 'x'       set output field separator (|)
1428df9185cSdrhdo_test shell1-1.14.1 {
1438df9185cSdrh  catchcmd "-separator 'x' test.db" ""
1448df9185cSdrh} {0 {}}
1458df9185cSdrhdo_test shell1-1.14.2 {
1468df9185cSdrh  catchcmd "-separator x test.db" ""
1478df9185cSdrh} {0 {}}
1488df9185cSdrhdo_test shell1-1.14.3 {
1498df9185cSdrh  set res [catchcmd "-separator" ""]
1508df9185cSdrh  set rc [lindex $res 0]
1518df9185cSdrh  list $rc \
1528df9185cSdrh       [regexp {Error: missing argument for option: -separator} $res]
1538df9185cSdrh} {1 1}
1548df9185cSdrh
1558df9185cSdrh# -stats               print memory stats before each finalize
1568df9185cSdrhdo_test shell1-1.14b.1 {
1578df9185cSdrh  catchcmd "-stats test.db" ""
1588df9185cSdrh} {0 {}}
1598df9185cSdrh
1608df9185cSdrh# -nullvalue 'text'    set text string for NULL values
1618df9185cSdrhdo_test shell1-1.15.1 {
1628df9185cSdrh  catchcmd "-nullvalue 'x' test.db" ""
1638df9185cSdrh} {0 {}}
1648df9185cSdrhdo_test shell1-1.15.2 {
1658df9185cSdrh  catchcmd "-nullvalue x test.db" ""
1668df9185cSdrh} {0 {}}
1678df9185cSdrhdo_test shell1-1.15.3 {
1688df9185cSdrh  set res [catchcmd "-nullvalue" ""]
1698df9185cSdrh  set rc [lindex $res 0]
1708df9185cSdrh  list $rc \
1718df9185cSdrh       [regexp {Error: missing argument for option: -nullvalue} $res]
1728df9185cSdrh} {1 1}
1738df9185cSdrh
1748df9185cSdrh# -version             show SQLite version
1758df9185cSdrhdo_test shell1-1.16.1 {
1768df9185cSdrh  set x [catchcmd "-version test.db" ""]
177b24c61a2Sdrh} {/3.[0-9.]+ 20\d\d-[01]\d-\d\d \d\d:\d\d:\d\d [0-9a-f]+/}
1788df9185cSdrh
1798df9185cSdrh#----------------------------------------------------------------------------
1808df9185cSdrh# Test cases shell1-2.*: Basic "dot" command token parsing.
1818df9185cSdrh#
1828df9185cSdrh
1838df9185cSdrh# check first token handling
1848df9185cSdrhdo_test shell1-2.1.1 {
1858df9185cSdrh  catchcmd "test.db" ".foo"
1868df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "foo". Enter ".help" for help}}
1878df9185cSdrhdo_test shell1-2.1.2 {
1888df9185cSdrh  catchcmd "test.db" ".\"foo OFF\""
1898df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "foo OFF". Enter ".help" for help}}
1908df9185cSdrhdo_test shell1-2.1.3 {
1918df9185cSdrh  catchcmd "test.db" ".\'foo OFF\'"
1928df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "foo OFF". Enter ".help" for help}}
1938df9185cSdrh
1948df9185cSdrh# unbalanced quotes
1958df9185cSdrhdo_test shell1-2.2.1 {
1968df9185cSdrh  catchcmd "test.db" ".\"foo OFF"
1978df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "foo OFF". Enter ".help" for help}}
1988df9185cSdrhdo_test shell1-2.2.2 {
1998df9185cSdrh  catchcmd "test.db" ".\'foo OFF"
2008df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "foo OFF". Enter ".help" for help}}
2018df9185cSdrhdo_test shell1-2.2.3 {
2028df9185cSdrh  catchcmd "test.db" ".explain \"OFF"
2038df9185cSdrh} {0 {}}
2048df9185cSdrhdo_test shell1-2.2.4 {
2058df9185cSdrh  catchcmd "test.db" ".explain \'OFF"
2068df9185cSdrh} {0 {}}
2078df9185cSdrhdo_test shell1-2.2.5 {
2088df9185cSdrh  catchcmd "test.db" ".mode \"insert FOO"
2098df9185cSdrh} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
2108df9185cSdrhdo_test shell1-2.2.6 {
2118df9185cSdrh  catchcmd "test.db" ".mode \'insert FOO"
2128df9185cSdrh} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
2138df9185cSdrh
2148df9185cSdrh# check multiple tokens, and quoted tokens
2158df9185cSdrhdo_test shell1-2.3.1 {
2168df9185cSdrh  catchcmd "test.db" ".explain 1"
2178df9185cSdrh} {0 {}}
2188df9185cSdrhdo_test shell1-2.3.2 {
2198df9185cSdrh  catchcmd "test.db" ".explain on"
2208df9185cSdrh} {0 {}}
2218df9185cSdrhdo_test shell1-2.3.3 {
2228df9185cSdrh  catchcmd "test.db" ".explain \"1 2 3\""
2238df9185cSdrh} {0 {}}
2248df9185cSdrhdo_test shell1-2.3.4 {
2258df9185cSdrh  catchcmd "test.db" ".explain \"OFF\""
2268df9185cSdrh} {0 {}}
2278df9185cSdrhdo_test shell1-2.3.5 {
2288df9185cSdrh  catchcmd "test.db" ".\'explain\' \'OFF\'"
2298df9185cSdrh} {0 {}}
2308df9185cSdrhdo_test shell1-2.3.6 {
2318df9185cSdrh  catchcmd "test.db" ".explain \'OFF\'"
2328df9185cSdrh} {0 {}}
2338df9185cSdrhdo_test shell1-2.3.7 {
2348df9185cSdrh  catchcmd "test.db" ".\'explain\' \'OFF\'"
2358df9185cSdrh} {0 {}}
2368df9185cSdrh
2378df9185cSdrh# check quoted args are unquoted
2388df9185cSdrhdo_test shell1-2.4.1 {
2398df9185cSdrh  catchcmd "test.db" ".mode FOO"
2408df9185cSdrh} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
2418df9185cSdrhdo_test shell1-2.4.2 {
2428df9185cSdrh  catchcmd "test.db" ".mode csv"
2438df9185cSdrh} {0 {}}
2448df9185cSdrhdo_test shell1-2.4.2 {
2458df9185cSdrh  catchcmd "test.db" ".mode \"csv\""
2468df9185cSdrh} {0 {}}
2478df9185cSdrh
2488df9185cSdrh
2498df9185cSdrh#----------------------------------------------------------------------------
2508df9185cSdrh# Test cases shell1-3.*: Basic test that "dot" command can be called.
2518df9185cSdrh#
2528df9185cSdrh
2538df9185cSdrh# .backup ?DB? FILE      Backup DB (default "main") to FILE
2548df9185cSdrhdo_test shell1-3.1.1 {
2558df9185cSdrh  catchcmd "test.db" ".backup"
2568df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "backup". Enter ".help" for help}}
2578df9185cSdrhdo_test shell1-3.1.2 {
2588df9185cSdrh  catchcmd "test.db" ".backup FOO"
2598df9185cSdrh} {0 {}}
2608df9185cSdrhdo_test shell1-3.1.3 {
2618df9185cSdrh  catchcmd "test.db" ".backup FOO BAR"
2628df9185cSdrh} {1 {Error: unknown database FOO}}
2638df9185cSdrhdo_test shell1-3.1.4 {
2648df9185cSdrh  # too many arguments
2658df9185cSdrh  catchcmd "test.db" ".backup FOO BAR BAD"
2668df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "backup". Enter ".help" for help}}
2678df9185cSdrh
2688df9185cSdrh# .bail ON|OFF           Stop after hitting an error.  Default OFF
2698df9185cSdrhdo_test shell1-3.2.1 {
2708df9185cSdrh  catchcmd "test.db" ".bail"
2718df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "bail". Enter ".help" for help}}
2728df9185cSdrhdo_test shell1-3.2.2 {
2738df9185cSdrh  catchcmd "test.db" ".bail ON"
2748df9185cSdrh} {0 {}}
2758df9185cSdrhdo_test shell1-3.2.3 {
2768df9185cSdrh  catchcmd "test.db" ".bail OFF"
2778df9185cSdrh} {0 {}}
2788df9185cSdrhdo_test shell1-3.2.4 {
2798df9185cSdrh  # too many arguments
2808df9185cSdrh  catchcmd "test.db" ".bail OFF BAD"
2818df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "bail". Enter ".help" for help}}
2828df9185cSdrh
2838df9185cSdrh# .databases             List names and files of attached databases
2848df9185cSdrhdo_test shell1-3.3.1 {
285e4d31957Sdrh  catchcmd "-csv test.db" ".databases"
286*86ab48fcSmistachkin} "/0 +.*main +[string map {/ .} [string range [get_pwd] 0 10]].*/"
2878df9185cSdrhdo_test shell1-3.3.2 {
2888df9185cSdrh  # too many arguments
2898df9185cSdrh  catchcmd "test.db" ".databases BAD"
2908df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "databases". Enter ".help" for help}}
2918df9185cSdrh
2928df9185cSdrh# .dump ?TABLE? ...      Dump the database in an SQL text format
2938df9185cSdrh#                          If TABLE specified, only dump tables matching
2948df9185cSdrh#                          LIKE pattern TABLE.
2958df9185cSdrhdo_test shell1-3.4.1 {
2968df9185cSdrh  set res [catchcmd "test.db" ".dump"]
2978df9185cSdrh  list [regexp {BEGIN TRANSACTION;} $res] \
2988df9185cSdrh       [regexp {COMMIT;} $res]
2998df9185cSdrh} {1 1}
3008df9185cSdrhdo_test shell1-3.4.2 {
3018df9185cSdrh  set res [catchcmd "test.db" ".dump FOO"]
3028df9185cSdrh  list [regexp {BEGIN TRANSACTION;} $res] \
3038df9185cSdrh       [regexp {COMMIT;} $res]
3048df9185cSdrh} {1 1}
3058df9185cSdrhdo_test shell1-3.4.3 {
3068df9185cSdrh  # too many arguments
3078df9185cSdrh  catchcmd "test.db" ".dump FOO BAD"
3088df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "dump". Enter ".help" for help}}
3098df9185cSdrh
3108df9185cSdrh# .echo ON|OFF           Turn command echo on or off
3118df9185cSdrhdo_test shell1-3.5.1 {
3128df9185cSdrh  catchcmd "test.db" ".echo"
3138df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "echo". Enter ".help" for help}}
3148df9185cSdrhdo_test shell1-3.5.2 {
3158df9185cSdrh  catchcmd "test.db" ".echo ON"
3168df9185cSdrh} {0 {}}
3178df9185cSdrhdo_test shell1-3.5.3 {
3188df9185cSdrh  catchcmd "test.db" ".echo OFF"
3198df9185cSdrh} {0 {}}
3208df9185cSdrhdo_test shell1-3.5.4 {
3218df9185cSdrh  # too many arguments
3228df9185cSdrh  catchcmd "test.db" ".echo OFF BAD"
3238df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "echo". Enter ".help" for help}}
3248df9185cSdrh
3258df9185cSdrh# .exit                  Exit this program
3268df9185cSdrhdo_test shell1-3.6.1 {
3278df9185cSdrh  catchcmd "test.db" ".exit"
3288df9185cSdrh} {0 {}}
3298df9185cSdrhdo_test shell1-3.6.2 {
3308df9185cSdrh  # too many arguments
3318df9185cSdrh  catchcmd "test.db" ".exit BAD"
3328df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "exit". Enter ".help" for help}}
3338df9185cSdrh
3348df9185cSdrh# .explain ON|OFF        Turn output mode suitable for EXPLAIN on or off.
3358df9185cSdrhdo_test shell1-3.7.1 {
3368df9185cSdrh  catchcmd "test.db" ".explain"
3378df9185cSdrh  # explain is the exception to the booleans.  without an option, it turns it on.
3388df9185cSdrh} {0 {}}
3398df9185cSdrhdo_test shell1-3.7.2 {
3408df9185cSdrh  catchcmd "test.db" ".explain ON"
3418df9185cSdrh} {0 {}}
3428df9185cSdrhdo_test shell1-3.7.3 {
3438df9185cSdrh  catchcmd "test.db" ".explain OFF"
3448df9185cSdrh} {0 {}}
3458df9185cSdrhdo_test shell1-3.7.4 {
3468df9185cSdrh  # too many arguments
3478df9185cSdrh  catchcmd "test.db" ".explain OFF BAD"
3488df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "explain". Enter ".help" for help}}
3498df9185cSdrh
3508df9185cSdrh
3518df9185cSdrh# .header(s) ON|OFF      Turn display of headers on or off
3528df9185cSdrhdo_test shell1-3.9.1 {
3538df9185cSdrh  catchcmd "test.db" ".header"
3548df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "header". Enter ".help" for help}}
3558df9185cSdrhdo_test shell1-3.9.2 {
3568df9185cSdrh  catchcmd "test.db" ".header ON"
3578df9185cSdrh} {0 {}}
3588df9185cSdrhdo_test shell1-3.9.3 {
3598df9185cSdrh  catchcmd "test.db" ".header OFF"
3608df9185cSdrh} {0 {}}
3618df9185cSdrhdo_test shell1-3.9.4 {
3628df9185cSdrh  # too many arguments
3638df9185cSdrh  catchcmd "test.db" ".header OFF BAD"
3648df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "header". Enter ".help" for help}}
3658df9185cSdrh
3668df9185cSdrhdo_test shell1-3.9.5 {
3678df9185cSdrh  catchcmd "test.db" ".headers"
3688df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "headers". Enter ".help" for help}}
3698df9185cSdrhdo_test shell1-3.9.6 {
3708df9185cSdrh  catchcmd "test.db" ".headers ON"
3718df9185cSdrh} {0 {}}
3728df9185cSdrhdo_test shell1-3.9.7 {
3738df9185cSdrh  catchcmd "test.db" ".headers OFF"
3748df9185cSdrh} {0 {}}
3758df9185cSdrhdo_test shell1-3.9.8 {
3768df9185cSdrh  # too many arguments
3778df9185cSdrh  catchcmd "test.db" ".headers OFF BAD"
3788df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "headers". Enter ".help" for help}}
3798df9185cSdrh
3808df9185cSdrh# .help                  Show this message
3818df9185cSdrhdo_test shell1-3.10.1 {
3828df9185cSdrh  set res [catchcmd "test.db" ".help"]
3838df9185cSdrh  # look for a few of the possible help commands
3848df9185cSdrh  list [regexp {.help} $res] \
3858df9185cSdrh       [regexp {.quit} $res] \
3868df9185cSdrh       [regexp {.show} $res]
3878df9185cSdrh} {1 1 1}
3888df9185cSdrhdo_test shell1-3.10.2 {
3898df9185cSdrh  # we allow .help to take extra args (it is help after all)
3908df9185cSdrh  set res [catchcmd "test.db" ".help BAD"]
3918df9185cSdrh  # look for a few of the possible help commands
3928df9185cSdrh  list [regexp {.help} $res] \
3938df9185cSdrh       [regexp {.quit} $res] \
3948df9185cSdrh       [regexp {.show} $res]
3958df9185cSdrh} {1 1 1}
3968df9185cSdrh
3978df9185cSdrh# .import FILE TABLE     Import data from FILE into TABLE
3988df9185cSdrhdo_test shell1-3.11.1 {
3998df9185cSdrh  catchcmd "test.db" ".import"
4008df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "import". Enter ".help" for help}}
4018df9185cSdrhdo_test shell1-3.11.2 {
4028df9185cSdrh  catchcmd "test.db" ".import FOO"
4038df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "import". Enter ".help" for help}}
4048df9185cSdrhdo_test shell1-3.11.2 {
4058df9185cSdrh  catchcmd "test.db" ".import FOO BAR"
4068df9185cSdrh} {1 {Error: no such table: BAR}}
4078df9185cSdrhdo_test shell1-3.11.3 {
4088df9185cSdrh  # too many arguments
4098df9185cSdrh  catchcmd "test.db" ".import FOO BAR BAD"
4108df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "import". Enter ".help" for help}}
4118df9185cSdrh
4128df9185cSdrh# .indices ?TABLE?       Show names of all indices
4138df9185cSdrh#                          If TABLE specified, only show indices for tables
4148df9185cSdrh#                          matching LIKE pattern TABLE.
4158df9185cSdrhdo_test shell1-3.12.1 {
4168df9185cSdrh  catchcmd "test.db" ".indices"
4178df9185cSdrh} {0 {}}
4188df9185cSdrhdo_test shell1-3.12.2 {
4198df9185cSdrh  catchcmd "test.db" ".indices FOO"
4208df9185cSdrh} {0 {}}
4218df9185cSdrhdo_test shell1-3.12.3 {
4228df9185cSdrh  # too many arguments
4238df9185cSdrh  catchcmd "test.db" ".indices FOO BAD"
4248df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "indices". Enter ".help" for help}}
4258df9185cSdrh
4268df9185cSdrh# .mode MODE ?TABLE?     Set output mode where MODE is one of:
4278df9185cSdrh#                          csv      Comma-separated values
4288df9185cSdrh#                          column   Left-aligned columns.  (See .width)
4298df9185cSdrh#                          html     HTML <table> code
4308df9185cSdrh#                          insert   SQL insert statements for TABLE
4318df9185cSdrh#                          line     One value per line
4328df9185cSdrh#                          list     Values delimited by .separator string
4338df9185cSdrh#                          tabs     Tab-separated values
4348df9185cSdrh#                          tcl      TCL list elements
4358df9185cSdrhdo_test shell1-3.13.1 {
4368df9185cSdrh  catchcmd "test.db" ".mode"
4378df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "mode". Enter ".help" for help}}
4388df9185cSdrhdo_test shell1-3.13.2 {
4398df9185cSdrh  catchcmd "test.db" ".mode FOO"
4408df9185cSdrh} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
4418df9185cSdrhdo_test shell1-3.13.3 {
4428df9185cSdrh  catchcmd "test.db" ".mode csv"
4438df9185cSdrh} {0 {}}
4448df9185cSdrhdo_test shell1-3.13.4 {
4458df9185cSdrh  catchcmd "test.db" ".mode column"
4468df9185cSdrh} {0 {}}
4478df9185cSdrhdo_test shell1-3.13.5 {
4488df9185cSdrh  catchcmd "test.db" ".mode html"
4498df9185cSdrh} {0 {}}
4508df9185cSdrhdo_test shell1-3.13.6 {
4518df9185cSdrh  catchcmd "test.db" ".mode insert"
4528df9185cSdrh} {0 {}}
4538df9185cSdrhdo_test shell1-3.13.7 {
4548df9185cSdrh  catchcmd "test.db" ".mode line"
4558df9185cSdrh} {0 {}}
4568df9185cSdrhdo_test shell1-3.13.8 {
4578df9185cSdrh  catchcmd "test.db" ".mode list"
4588df9185cSdrh} {0 {}}
4598df9185cSdrhdo_test shell1-3.13.9 {
4608df9185cSdrh  catchcmd "test.db" ".mode tabs"
4618df9185cSdrh} {0 {}}
4628df9185cSdrhdo_test shell1-3.13.10 {
4638df9185cSdrh  catchcmd "test.db" ".mode tcl"
4648df9185cSdrh} {0 {}}
4658df9185cSdrhdo_test shell1-3.13.11 {
4668df9185cSdrh  # too many arguments
4678df9185cSdrh  catchcmd "test.db" ".mode tcl BAD"
4688df9185cSdrh} {1 {Error: invalid arguments:  "BAD". Enter ".help" for help}}
4698df9185cSdrh
4708df9185cSdrh# don't allow partial mode type matches
4718df9185cSdrhdo_test shell1-3.13.12 {
4728df9185cSdrh  catchcmd "test.db" ".mode l"
4738df9185cSdrh} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
4748df9185cSdrhdo_test shell1-3.13.13 {
4758df9185cSdrh  catchcmd "test.db" ".mode li"
4768df9185cSdrh} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
4778df9185cSdrhdo_test shell1-3.13.14 {
4788df9185cSdrh  catchcmd "test.db" ".mode lin"
4798df9185cSdrh} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
4808df9185cSdrh
4818df9185cSdrh# .nullvalue STRING      Print STRING in place of NULL values
4828df9185cSdrhdo_test shell1-3.14.1 {
4838df9185cSdrh  catchcmd "test.db" ".nullvalue"
4848df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "nullvalue". Enter ".help" for help}}
4858df9185cSdrhdo_test shell1-3.14.2 {
4868df9185cSdrh  catchcmd "test.db" ".nullvalue FOO"
4878df9185cSdrh} {0 {}}
4888df9185cSdrhdo_test shell1-3.14.3 {
4898df9185cSdrh  # too many arguments
4908df9185cSdrh  catchcmd "test.db" ".nullvalue FOO BAD"
4918df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "nullvalue". Enter ".help" for help}}
4928df9185cSdrh
4938df9185cSdrh# .output FILENAME       Send output to FILENAME
4948df9185cSdrhdo_test shell1-3.15.1 {
4958df9185cSdrh  catchcmd "test.db" ".output"
4968df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "output". Enter ".help" for help}}
4978df9185cSdrhdo_test shell1-3.15.2 {
4988df9185cSdrh  catchcmd "test.db" ".output FOO"
4998df9185cSdrh} {0 {}}
5008df9185cSdrhdo_test shell1-3.15.3 {
5018df9185cSdrh  # too many arguments
5028df9185cSdrh  catchcmd "test.db" ".output FOO BAD"
5038df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "output". Enter ".help" for help}}
5048df9185cSdrh
5058df9185cSdrh# .output stdout         Send output to the screen
5068df9185cSdrhdo_test shell1-3.16.1 {
5078df9185cSdrh  catchcmd "test.db" ".output stdout"
5088df9185cSdrh} {0 {}}
5098df9185cSdrhdo_test shell1-3.16.2 {
5108df9185cSdrh  # too many arguments
5118df9185cSdrh  catchcmd "test.db" ".output stdout BAD"
5128df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "output". Enter ".help" for help}}
5138df9185cSdrh
5148df9185cSdrh# .prompt MAIN CONTINUE  Replace the standard prompts
5158df9185cSdrhdo_test shell1-3.17.1 {
5168df9185cSdrh  catchcmd "test.db" ".prompt"
5178df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "prompt". Enter ".help" for help}}
5188df9185cSdrhdo_test shell1-3.17.2 {
5198df9185cSdrh  catchcmd "test.db" ".prompt FOO"
5208df9185cSdrh} {0 {}}
5218df9185cSdrhdo_test shell1-3.17.3 {
5228df9185cSdrh  catchcmd "test.db" ".prompt FOO BAR"
5238df9185cSdrh} {0 {}}
5248df9185cSdrhdo_test shell1-3.17.4 {
5258df9185cSdrh  # too many arguments
5268df9185cSdrh  catchcmd "test.db" ".prompt FOO BAR BAD"
5278df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "prompt". Enter ".help" for help}}
5288df9185cSdrh
5298df9185cSdrh# .quit                  Exit this program
5308df9185cSdrhdo_test shell1-3.18.1 {
5318df9185cSdrh  catchcmd "test.db" ".quit"
5328df9185cSdrh} {0 {}}
5338df9185cSdrhdo_test shell1-3.18.2 {
5348df9185cSdrh  # too many arguments
5358df9185cSdrh  catchcmd "test.db" ".quit BAD"
5368df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "quit". Enter ".help" for help}}
5378df9185cSdrh
5388df9185cSdrh# .read FILENAME         Execute SQL in FILENAME
5398df9185cSdrhdo_test shell1-3.19.1 {
5408df9185cSdrh  catchcmd "test.db" ".read"
5418df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "read". Enter ".help" for help}}
5428df9185cSdrhdo_test shell1-3.19.2 {
5438df9185cSdrh  file delete -force FOO
5448df9185cSdrh  catchcmd "test.db" ".read FOO"
5458df9185cSdrh} {1 {Error: cannot open "FOO"}}
5468df9185cSdrhdo_test shell1-3.19.3 {
5478df9185cSdrh  # too many arguments
5488df9185cSdrh  catchcmd "test.db" ".read FOO BAD"
5498df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "read". Enter ".help" for help}}
5508df9185cSdrh
5518df9185cSdrh# .restore ?DB? FILE     Restore content of DB (default "main") from FILE
5528df9185cSdrhdo_test shell1-3.20.1 {
5538df9185cSdrh  catchcmd "test.db" ".restore"
5548df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "restore". Enter ".help" for help}}
5558df9185cSdrhdo_test shell1-3.20.2 {
5568df9185cSdrh  catchcmd "test.db" ".restore FOO"
5578df9185cSdrh} {0 {}}
5588df9185cSdrhdo_test shell1-3.20.3 {
5598df9185cSdrh  catchcmd "test.db" ".restore FOO BAR"
5608df9185cSdrh} {1 {Error: unknown database FOO}}
5618df9185cSdrhdo_test shell1-3.20.4 {
5628df9185cSdrh  # too many arguments
5638df9185cSdrh  catchcmd "test.db" ".restore FOO BAR BAD"
5648df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "restore". Enter ".help" for help}}
5658df9185cSdrh
5668df9185cSdrh# .schema ?TABLE?        Show the CREATE statements
5678df9185cSdrh#                          If TABLE specified, only show tables matching
5688df9185cSdrh#                          LIKE pattern TABLE.
5698df9185cSdrhdo_test shell1-3.21.1 {
5708df9185cSdrh  catchcmd "test.db" ".schema"
5718df9185cSdrh} {0 {}}
5728df9185cSdrhdo_test shell1-3.21.2 {
5738df9185cSdrh  catchcmd "test.db" ".schema FOO"
5748df9185cSdrh} {0 {}}
5758df9185cSdrhdo_test shell1-3.21.3 {
5768df9185cSdrh  # too many arguments
5778df9185cSdrh  catchcmd "test.db" ".schema FOO BAD"
5788df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "schema". Enter ".help" for help}}
5798df9185cSdrh
580ac43e98dSdrhdo_test shell1-3.21.4 {
581ac43e98dSdrh  catchcmd "test.db" {
582ac43e98dSdrh     CREATE TABLE t1(x);
583ac43e98dSdrh     CREATE VIEW v2 AS SELECT x+1 AS y FROM t1;
584ac43e98dSdrh     CREATE VIEW v1 AS SELECT y+1 FROM v2;
585ac43e98dSdrh  }
586ac43e98dSdrh  catchcmd "test.db" ".schema"
587ac43e98dSdrh} {0 {CREATE TABLE t1(x);
588ac43e98dSdrhCREATE VIEW v2 AS SELECT x+1 AS y FROM t1;
589ac43e98dSdrhCREATE VIEW v1 AS SELECT y+1 FROM v2;}}
590ac43e98dSdrhdb eval {DROP VIEW v1; DROP VIEW v2; DROP TABLE t1;}
591ac43e98dSdrh
5928df9185cSdrh# .separator STRING      Change separator used by output mode and .import
5938df9185cSdrhdo_test shell1-3.22.1 {
5948df9185cSdrh  catchcmd "test.db" ".separator"
5958df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "separator". Enter ".help" for help}}
5968df9185cSdrhdo_test shell1-3.22.2 {
5978df9185cSdrh  catchcmd "test.db" ".separator FOO"
5988df9185cSdrh} {0 {}}
5998df9185cSdrhdo_test shell1-3.22.3 {
6008df9185cSdrh  # too many arguments
6018df9185cSdrh  catchcmd "test.db" ".separator FOO BAD"
6028df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "separator". Enter ".help" for help}}
6038df9185cSdrh
6048df9185cSdrh# .show                  Show the current values for various settings
6058df9185cSdrhdo_test shell1-3.23.1 {
6068df9185cSdrh  set res [catchcmd "test.db" ".show"]
6078df9185cSdrh  list [regexp {echo:} $res] \
6088df9185cSdrh       [regexp {explain:} $res] \
6098df9185cSdrh       [regexp {headers:} $res] \
6108df9185cSdrh       [regexp {mode:} $res] \
6118df9185cSdrh       [regexp {nullvalue:} $res] \
6128df9185cSdrh       [regexp {output:} $res] \
6138df9185cSdrh       [regexp {separator:} $res] \
6148df9185cSdrh       [regexp {stats:} $res] \
6158df9185cSdrh       [regexp {width:} $res]
6168df9185cSdrh} {1 1 1 1 1 1 1 1 1}
6178df9185cSdrhdo_test shell1-3.23.2 {
6188df9185cSdrh  # too many arguments
6198df9185cSdrh  catchcmd "test.db" ".show BAD"
6208df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "show". Enter ".help" for help}}
6218df9185cSdrh
6228df9185cSdrh# .stats ON|OFF          Turn stats on or off
6238df9185cSdrhdo_test shell1-3.23b.1 {
6248df9185cSdrh  catchcmd "test.db" ".stats"
6258df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "stats". Enter ".help" for help}}
6268df9185cSdrhdo_test shell1-3.23b.2 {
6278df9185cSdrh  catchcmd "test.db" ".stats ON"
6288df9185cSdrh} {0 {}}
6298df9185cSdrhdo_test shell1-3.23b.3 {
6308df9185cSdrh  catchcmd "test.db" ".stats OFF"
6318df9185cSdrh} {0 {}}
6328df9185cSdrhdo_test shell1-3.23b.4 {
6338df9185cSdrh  # too many arguments
6348df9185cSdrh  catchcmd "test.db" ".stats OFF BAD"
6358df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "stats". Enter ".help" for help}}
6368df9185cSdrh
6378df9185cSdrh# .tables ?TABLE?        List names of tables
6388df9185cSdrh#                          If TABLE specified, only list tables matching
6398df9185cSdrh#                          LIKE pattern TABLE.
6408df9185cSdrhdo_test shell1-3.24.1 {
6418df9185cSdrh  catchcmd "test.db" ".tables"
6428df9185cSdrh} {0 {}}
6438df9185cSdrhdo_test shell1-3.24.2 {
6448df9185cSdrh  catchcmd "test.db" ".tables FOO"
6458df9185cSdrh} {0 {}}
6468df9185cSdrhdo_test shell1-3.24.3 {
6478df9185cSdrh  # too many arguments
6488df9185cSdrh  catchcmd "test.db" ".tables FOO BAD"
6498df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "tables". Enter ".help" for help}}
6508df9185cSdrh
6518df9185cSdrh# .timeout MS            Try opening locked tables for MS milliseconds
6528df9185cSdrhdo_test shell1-3.25.1 {
6538df9185cSdrh  catchcmd "test.db" ".timeout"
6548df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "timeout". Enter ".help" for help}}
6558df9185cSdrhdo_test shell1-3.25.2 {
6568df9185cSdrh  catchcmd "test.db" ".timeout zzz"
6578df9185cSdrh  # this should be treated the same as a '0' timeout
6588df9185cSdrh} {0 {}}
6598df9185cSdrhdo_test shell1-3.25.3 {
6608df9185cSdrh  catchcmd "test.db" ".timeout 1"
6618df9185cSdrh} {0 {}}
6628df9185cSdrhdo_test shell1-3.25.4 {
6638df9185cSdrh  # too many arguments
6648df9185cSdrh  catchcmd "test.db" ".timeout 1 BAD"
6658df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "timeout". Enter ".help" for help}}
6668df9185cSdrh
6678df9185cSdrh# .width NUM NUM ...     Set column widths for "column" mode
6688df9185cSdrhdo_test shell1-3.26.1 {
6698df9185cSdrh  catchcmd "test.db" ".width"
6708df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "width". Enter ".help" for help}}
6718df9185cSdrhdo_test shell1-3.26.2 {
6728df9185cSdrh  catchcmd "test.db" ".width xxx"
6738df9185cSdrh  # this should be treated the same as a '0' width for col 1
6748df9185cSdrh} {0 {}}
6758df9185cSdrhdo_test shell1-3.26.3 {
6768df9185cSdrh  catchcmd "test.db" ".width xxx yyy"
6778df9185cSdrh  # this should be treated the same as a '0' width for col 1 and 2
6788df9185cSdrh} {0 {}}
6798df9185cSdrhdo_test shell1-3.26.4 {
6808df9185cSdrh  catchcmd "test.db" ".width 1 1"
6818df9185cSdrh  # this should be treated the same as a '1' width for col 1 and 2
6828df9185cSdrh} {0 {}}
6838df9185cSdrh
6848df9185cSdrh# .timer ON|OFF          Turn the CPU timer measurement on or off
6858df9185cSdrhdo_test shell1-3.27.1 {
6868df9185cSdrh  catchcmd "test.db" ".timer"
6878df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "timer". Enter ".help" for help}}
6888df9185cSdrhdo_test shell1-3.27.2 {
6898df9185cSdrh  catchcmd "test.db" ".timer ON"
6908df9185cSdrh} {0 {}}
6918df9185cSdrhdo_test shell1-3.27.3 {
6928df9185cSdrh  catchcmd "test.db" ".timer OFF"
6938df9185cSdrh} {0 {}}
6948df9185cSdrhdo_test shell1-3.27.4 {
6958df9185cSdrh  # too many arguments
6968df9185cSdrh  catchcmd "test.db" ".timer OFF BAD"
6978df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "timer". Enter ".help" for help}}
6988df9185cSdrh
6998df9185cSdrhdo_test shell1-3-28.1 {
7008df9185cSdrh  catchcmd test.db \
7018df9185cSdrh     ".log stdout\nSELECT coalesce(sqlite_log(123,'hello'),'456');"
7028df9185cSdrh} "0 {(123) hello\n456}"
7038df9185cSdrh
7045128e85cSdrh# Test the output of the ".dump" command
7055128e85cSdrh#
7065128e85cSdrhdo_test shell1-4.1 {
7075128e85cSdrh  db eval {
7085128e85cSdrh    CREATE TABLE t1(x);
7095128e85cSdrh    INSERT INTO t1 VALUES(null), (1), (2.25), ('hello'), (x'807f');
7105128e85cSdrh  }
7115128e85cSdrh  catchcmd test.db {.dump}
7125128e85cSdrh} {0 {PRAGMA foreign_keys=OFF;
7135128e85cSdrhBEGIN TRANSACTION;
7145128e85cSdrhCREATE TABLE t1(x);
7155128e85cSdrhINSERT INTO "t1" VALUES(NULL);
7165128e85cSdrhINSERT INTO "t1" VALUES(1);
7175128e85cSdrhINSERT INTO "t1" VALUES(2.25);
7185128e85cSdrhINSERT INTO "t1" VALUES('hello');
7195128e85cSdrhINSERT INTO "t1" VALUES(X'807F');
7205128e85cSdrhCOMMIT;}}
7215128e85cSdrh
7225128e85cSdrh# Test the output of ".mode insert"
7235128e85cSdrh#
7245128e85cSdrhdo_test shell1-4.2 {
7255128e85cSdrh  catchcmd test.db ".mode insert t1\nselect * from t1;"
7265128e85cSdrh} {0 {INSERT INTO t1 VALUES(NULL);
7275128e85cSdrhINSERT INTO t1 VALUES(1);
7285128e85cSdrhINSERT INTO t1 VALUES(2.25);
7295128e85cSdrhINSERT INTO t1 VALUES('hello');
7305128e85cSdrhINSERT INTO t1 VALUES(X'807f');}}
7315128e85cSdrh
7325128e85cSdrh
7338df9185cSdrhfinish_test
734