xref: /sqlite-3.40.0/test/shell1.test (revision bbb29ecf)
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
24089555c8Sdanset CLI [test_find_cli]
258df9185cSdrhdb close
268df9185cSdrhforcedelete test.db test.db-journal test.db-wal
278df9185cSdrhsqlite3 db test.db
288df9185cSdrh
298df9185cSdrh#----------------------------------------------------------------------------
308df9185cSdrh# Test cases shell1-1.*: Basic command line option handling.
318df9185cSdrh#
328df9185cSdrh
338df9185cSdrh# invalid option
348df9185cSdrhdo_test shell1-1.1.1 {
358df9185cSdrh  set res [catchcmd "-bad test.db" ""]
368df9185cSdrh  set rc [lindex $res 0]
378df9185cSdrh  list $rc \
388df9185cSdrh       [regexp {Error: unknown option: -bad} $res]
398df9185cSdrh} {1 1}
40ac5649a9Sdrhdo_test shell1-1.1.1b {
41ac5649a9Sdrh  set res [catchcmd "test.db -bad" ""]
42ac5649a9Sdrh  set rc [lindex $res 0]
43ac5649a9Sdrh  list $rc \
44ac5649a9Sdrh       [regexp {Error: unknown option: -bad} $res]
45ac5649a9Sdrh} {1 1}
468df9185cSdrh# error on extra options
478df9185cSdrhdo_test shell1-1.1.2 {
4860c4249fSdrh  catchcmd "test.db \"select+3\" \"select+4\"" ""
49ac5649a9Sdrh} {0 {3
50ac5649a9Sdrh4}}
518df9185cSdrh# error on extra options
528df9185cSdrhdo_test shell1-1.1.3 {
53ac5649a9Sdrh  catchcmd "test.db FOO test.db BAD" ".quit"
54ac5649a9Sdrh} {1 {Error: near "FOO": syntax error}}
558df9185cSdrh
568df9185cSdrh# -help
578df9185cSdrhdo_test shell1-1.2.1 {
588df9185cSdrh  set res [catchcmd "-help test.db" ""]
598df9185cSdrh  set rc [lindex $res 0]
608df9185cSdrh  list $rc \
618df9185cSdrh       [regexp {Usage} $res] \
628df9185cSdrh       [regexp {\-init} $res] \
638df9185cSdrh       [regexp {\-version} $res]
648df9185cSdrh} {1 1 1 1}
658df9185cSdrh
668df9185cSdrh# -init filename       read/process named file
678df9185cSdrhdo_test shell1-1.3.1 {
688df9185cSdrh  catchcmd "-init FOO test.db" ""
698df9185cSdrh} {0 {}}
708df9185cSdrhdo_test shell1-1.3.2 {
71ac5649a9Sdrh  catchcmd "-init FOO test.db .quit BAD" ""
72ac5649a9Sdrh} {0 {}}
73ac5649a9Sdrhdo_test shell1-1.3.3 {
74ac5649a9Sdrh  catchcmd "-init FOO test.db BAD .quit" ""
75ac5649a9Sdrh} {1 {Error: near "BAD": syntax error}}
768df9185cSdrh
778df9185cSdrh# -echo                print commands before execution
788df9185cSdrhdo_test shell1-1.4.1 {
798df9185cSdrh  catchcmd "-echo test.db" ""
808df9185cSdrh} {0 {}}
818df9185cSdrh
828df9185cSdrh# -[no]header          turn headers on or off
838df9185cSdrhdo_test shell1-1.5.1 {
848df9185cSdrh  catchcmd "-header test.db" ""
858df9185cSdrh} {0 {}}
868df9185cSdrhdo_test shell1-1.5.2 {
878df9185cSdrh  catchcmd "-noheader test.db" ""
888df9185cSdrh} {0 {}}
898df9185cSdrh
908df9185cSdrh# -bail                stop after hitting an error
918df9185cSdrhdo_test shell1-1.6.1 {
928df9185cSdrh  catchcmd "-bail test.db" ""
938df9185cSdrh} {0 {}}
948df9185cSdrh
958df9185cSdrh# -interactive         force interactive I/O
968df9185cSdrhdo_test shell1-1.7.1 {
978df9185cSdrh  set res [catchcmd "-interactive test.db" ".quit"]
988df9185cSdrh  set rc [lindex $res 0]
998df9185cSdrh  list $rc \
1008df9185cSdrh       [regexp {SQLite version} $res] \
10139a3088dSdrh       [regexp {Enter ".help" for usage hints} $res]
1028df9185cSdrh} {0 1 1}
1038df9185cSdrh
1048df9185cSdrh# -batch               force batch I/O
1058df9185cSdrhdo_test shell1-1.8.1 {
1068df9185cSdrh  catchcmd "-batch test.db" ""
1078df9185cSdrh} {0 {}}
1088df9185cSdrh
1098df9185cSdrh# -column              set output mode to 'column'
1108df9185cSdrhdo_test shell1-1.9.1 {
1118df9185cSdrh  catchcmd "-column test.db" ""
1128df9185cSdrh} {0 {}}
1138df9185cSdrh
1148df9185cSdrh# -csv                 set output mode to 'csv'
1158df9185cSdrhdo_test shell1-1.10.1 {
1168df9185cSdrh  catchcmd "-csv test.db" ""
1178df9185cSdrh} {0 {}}
1188df9185cSdrh
1198df9185cSdrh# -html                set output mode to HTML
1208df9185cSdrhdo_test shell1-1.11.1 {
1218df9185cSdrh  catchcmd "-html test.db" ""
1228df9185cSdrh} {0 {}}
1238df9185cSdrh
1248df9185cSdrh# -line                set output mode to 'line'
1258df9185cSdrhdo_test shell1-1.12.1 {
1268df9185cSdrh  catchcmd "-line test.db" ""
1278df9185cSdrh} {0 {}}
1288df9185cSdrh
1298df9185cSdrh# -list                set output mode to 'list'
1308df9185cSdrhdo_test shell1-1.13.1 {
1318df9185cSdrh  catchcmd "-list test.db" ""
1328df9185cSdrh} {0 {}}
1338df9185cSdrh
1348df9185cSdrh# -separator 'x'       set output field separator (|)
1358df9185cSdrhdo_test shell1-1.14.1 {
1368df9185cSdrh  catchcmd "-separator 'x' test.db" ""
1378df9185cSdrh} {0 {}}
1388df9185cSdrhdo_test shell1-1.14.2 {
1398df9185cSdrh  catchcmd "-separator x test.db" ""
1408df9185cSdrh} {0 {}}
1418df9185cSdrhdo_test shell1-1.14.3 {
1428df9185cSdrh  set res [catchcmd "-separator" ""]
1438df9185cSdrh  set rc [lindex $res 0]
1448df9185cSdrh  list $rc \
14598d312fcSdrh       [regexp {Error: missing argument to -separator} $res]
1468df9185cSdrh} {1 1}
1478df9185cSdrh
1488df9185cSdrh# -stats               print memory stats before each finalize
1498df9185cSdrhdo_test shell1-1.14b.1 {
1508df9185cSdrh  catchcmd "-stats test.db" ""
1518df9185cSdrh} {0 {}}
1528df9185cSdrh
1538df9185cSdrh# -nullvalue 'text'    set text string for NULL values
1548df9185cSdrhdo_test shell1-1.15.1 {
1558df9185cSdrh  catchcmd "-nullvalue 'x' test.db" ""
1568df9185cSdrh} {0 {}}
1578df9185cSdrhdo_test shell1-1.15.2 {
1588df9185cSdrh  catchcmd "-nullvalue x test.db" ""
1598df9185cSdrh} {0 {}}
1608df9185cSdrhdo_test shell1-1.15.3 {
1618df9185cSdrh  set res [catchcmd "-nullvalue" ""]
1628df9185cSdrh  set rc [lindex $res 0]
1638df9185cSdrh  list $rc \
16498d312fcSdrh       [regexp {Error: missing argument to -nullvalue} $res]
1658df9185cSdrh} {1 1}
1668df9185cSdrh
1678df9185cSdrh# -version             show SQLite version
1688df9185cSdrhdo_test shell1-1.16.1 {
1698df9185cSdrh  set x [catchcmd "-version test.db" ""]
170b24c61a2Sdrh} {/3.[0-9.]+ 20\d\d-[01]\d-\d\d \d\d:\d\d:\d\d [0-9a-f]+/}
1718df9185cSdrh
1728df9185cSdrh#----------------------------------------------------------------------------
1738df9185cSdrh# Test cases shell1-2.*: Basic "dot" command token parsing.
1748df9185cSdrh#
1758df9185cSdrh
1768df9185cSdrh# check first token handling
1778df9185cSdrhdo_test shell1-2.1.1 {
1788df9185cSdrh  catchcmd "test.db" ".foo"
1798df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "foo". Enter ".help" for help}}
1808df9185cSdrhdo_test shell1-2.1.2 {
1818df9185cSdrh  catchcmd "test.db" ".\"foo OFF\""
1828df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "foo OFF". Enter ".help" for help}}
1838df9185cSdrhdo_test shell1-2.1.3 {
1848df9185cSdrh  catchcmd "test.db" ".\'foo OFF\'"
1858df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "foo OFF". Enter ".help" for help}}
1868df9185cSdrh
1878df9185cSdrh# unbalanced quotes
1888df9185cSdrhdo_test shell1-2.2.1 {
1898df9185cSdrh  catchcmd "test.db" ".\"foo OFF"
1908df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "foo OFF". Enter ".help" for help}}
1918df9185cSdrhdo_test shell1-2.2.2 {
1928df9185cSdrh  catchcmd "test.db" ".\'foo OFF"
1938df9185cSdrh} {1 {Error: unknown command or invalid arguments:  "foo OFF". Enter ".help" for help}}
1948df9185cSdrhdo_test shell1-2.2.3 {
1958df9185cSdrh  catchcmd "test.db" ".explain \"OFF"
1968df9185cSdrh} {0 {}}
1978df9185cSdrhdo_test shell1-2.2.4 {
1988df9185cSdrh  catchcmd "test.db" ".explain \'OFF"
1998df9185cSdrh} {0 {}}
2008df9185cSdrhdo_test shell1-2.2.5 {
2018df9185cSdrh  catchcmd "test.db" ".mode \"insert FOO"
2020908e385Sdrh} {1 {Error: mode should be one of: ascii box column csv html insert json line list markdown quote table tabs tcl}}
2038df9185cSdrhdo_test shell1-2.2.6 {
2048df9185cSdrh  catchcmd "test.db" ".mode \'insert FOO"
2050908e385Sdrh} {1 {Error: mode should be one of: ascii box column csv html insert json line list markdown quote table tabs tcl}}
2068df9185cSdrh
2078df9185cSdrh# check multiple tokens, and quoted tokens
2088df9185cSdrhdo_test shell1-2.3.1 {
2098df9185cSdrh  catchcmd "test.db" ".explain 1"
2108df9185cSdrh} {0 {}}
2118df9185cSdrhdo_test shell1-2.3.2 {
2128df9185cSdrh  catchcmd "test.db" ".explain on"
2138df9185cSdrh} {0 {}}
2148df9185cSdrhdo_test shell1-2.3.3 {
2158df9185cSdrh  catchcmd "test.db" ".explain \"1 2 3\""
216173ba099Sdrh} {1 {ERROR: Not a boolean value: "1 2 3". Assuming "no".}}
2178df9185cSdrhdo_test shell1-2.3.4 {
2188df9185cSdrh  catchcmd "test.db" ".explain \"OFF\""
2198df9185cSdrh} {0 {}}
2208df9185cSdrhdo_test shell1-2.3.5 {
2218df9185cSdrh  catchcmd "test.db" ".\'explain\' \'OFF\'"
2228df9185cSdrh} {0 {}}
2238df9185cSdrhdo_test shell1-2.3.6 {
2248df9185cSdrh  catchcmd "test.db" ".explain \'OFF\'"
2258df9185cSdrh} {0 {}}
2268df9185cSdrhdo_test shell1-2.3.7 {
2278df9185cSdrh  catchcmd "test.db" ".\'explain\' \'OFF\'"
2288df9185cSdrh} {0 {}}
2298df9185cSdrh
2308df9185cSdrh# check quoted args are unquoted
2318df9185cSdrhdo_test shell1-2.4.1 {
2328df9185cSdrh  catchcmd "test.db" ".mode FOO"
2330908e385Sdrh} {1 {Error: mode should be one of: ascii box column csv html insert json line list markdown quote table tabs tcl}}
2348df9185cSdrhdo_test shell1-2.4.2 {
2358df9185cSdrh  catchcmd "test.db" ".mode csv"
2368df9185cSdrh} {0 {}}
2378df9185cSdrhdo_test shell1-2.4.2 {
2388df9185cSdrh  catchcmd "test.db" ".mode \"csv\""
2398df9185cSdrh} {0 {}}
2408df9185cSdrh
2418df9185cSdrh
2428df9185cSdrh#----------------------------------------------------------------------------
2438df9185cSdrh# Test cases shell1-3.*: Basic test that "dot" command can be called.
2448df9185cSdrh#
2458df9185cSdrh
2468df9185cSdrh# .backup ?DB? FILE      Backup DB (default "main") to FILE
2478df9185cSdrhdo_test shell1-3.1.1 {
2488df9185cSdrh  catchcmd "test.db" ".backup"
249bc46f02cSdrh} {1 {missing FILENAME argument on .backup}}
2508df9185cSdrhdo_test shell1-3.1.2 {
2518df9185cSdrh  catchcmd "test.db" ".backup FOO"
2528df9185cSdrh} {0 {}}
2538df9185cSdrhdo_test shell1-3.1.3 {
2548df9185cSdrh  catchcmd "test.db" ".backup FOO BAR"
2558df9185cSdrh} {1 {Error: unknown database FOO}}
2568df9185cSdrhdo_test shell1-3.1.4 {
2578df9185cSdrh  # too many arguments
2588df9185cSdrh  catchcmd "test.db" ".backup FOO BAR BAD"
2594d342827Sdrh} {1 {Usage: .backup ?DB? ?OPTIONS? FILENAME}}
2608df9185cSdrh
2618df9185cSdrh# .bail ON|OFF           Stop after hitting an error.  Default OFF
2628df9185cSdrhdo_test shell1-3.2.1 {
2638df9185cSdrh  catchcmd "test.db" ".bail"
264c2ce0beaSdrh} {1 {Usage: .bail on|off}}
2658df9185cSdrhdo_test shell1-3.2.2 {
2668df9185cSdrh  catchcmd "test.db" ".bail ON"
2678df9185cSdrh} {0 {}}
2688df9185cSdrhdo_test shell1-3.2.3 {
2698df9185cSdrh  catchcmd "test.db" ".bail OFF"
2708df9185cSdrh} {0 {}}
2718df9185cSdrhdo_test shell1-3.2.4 {
2728df9185cSdrh  # too many arguments
2738df9185cSdrh  catchcmd "test.db" ".bail OFF BAD"
274c2ce0beaSdrh} {1 {Usage: .bail on|off}}
2758df9185cSdrh
276c5954199Sdrhifcapable vtab {
2778df9185cSdrh# .databases             List names and files of attached databases
2788df9185cSdrhdo_test shell1-3.3.1 {
279eaa544d4Sdrh  catchcmd "-csv test.db" ".databases"
28015707ac9Sdrh} "/0.+main.+[string map {/ ".{1,2}"} [string range [get_pwd] 0 10]].*/"
2818df9185cSdrhdo_test shell1-3.3.2 {
282c2ce0beaSdrh  # extra arguments ignored
283eaa544d4Sdrh  catchcmd "test.db" ".databases BAD"
28415707ac9Sdrh} "/0.+main.+[string map {/ ".{1,2}"} [string range [get_pwd] 0 10]].*/"
285c5954199Sdrh}
2868df9185cSdrh
2878df9185cSdrh# .dump ?TABLE? ...      Dump the database in an SQL text format
2888df9185cSdrh#                          If TABLE specified, only dump tables matching
2898df9185cSdrh#                          LIKE pattern TABLE.
2908df9185cSdrhdo_test shell1-3.4.1 {
2918df9185cSdrh  set res [catchcmd "test.db" ".dump"]
2928df9185cSdrh  list [regexp {BEGIN TRANSACTION;} $res] \
2938df9185cSdrh       [regexp {COMMIT;} $res]
2948df9185cSdrh} {1 1}
2958df9185cSdrhdo_test shell1-3.4.2 {
2968df9185cSdrh  set res [catchcmd "test.db" ".dump FOO"]
2978df9185cSdrh  list [regexp {BEGIN TRANSACTION;} $res] \
2988df9185cSdrh       [regexp {COMMIT;} $res]
2998df9185cSdrh} {1 1}
3008e9297fbSdrh# The .dump command now accepts multiple arguments
3018e9297fbSdrh#do_test shell1-3.4.3 {
3028e9297fbSdrh#  # too many arguments
3038e9297fbSdrh#  catchcmd "test.db" ".dump FOO BAD"
3048e9297fbSdrh#} {1 {Usage: .dump ?--preserve-rowids? ?--newlines? ?LIKE-PATTERN?}}
3058df9185cSdrh
3068df9185cSdrh# .echo ON|OFF           Turn command echo on or off
3078df9185cSdrhdo_test shell1-3.5.1 {
3088df9185cSdrh  catchcmd "test.db" ".echo"
309c2ce0beaSdrh} {1 {Usage: .echo on|off}}
3108df9185cSdrhdo_test shell1-3.5.2 {
3118df9185cSdrh  catchcmd "test.db" ".echo ON"
3128df9185cSdrh} {0 {}}
3138df9185cSdrhdo_test shell1-3.5.3 {
3148df9185cSdrh  catchcmd "test.db" ".echo OFF"
3158df9185cSdrh} {0 {}}
3168df9185cSdrhdo_test shell1-3.5.4 {
3178df9185cSdrh  # too many arguments
3188df9185cSdrh  catchcmd "test.db" ".echo OFF BAD"
319c2ce0beaSdrh} {1 {Usage: .echo on|off}}
3208df9185cSdrh
3218df9185cSdrh# .exit                  Exit this program
3228df9185cSdrhdo_test shell1-3.6.1 {
3238df9185cSdrh  catchcmd "test.db" ".exit"
3248df9185cSdrh} {0 {}}
3258df9185cSdrh
3268df9185cSdrh# .explain ON|OFF        Turn output mode suitable for EXPLAIN on or off.
3278df9185cSdrhdo_test shell1-3.7.1 {
3288df9185cSdrh  catchcmd "test.db" ".explain"
3298df9185cSdrh  # explain is the exception to the booleans.  without an option, it turns it on.
3308df9185cSdrh} {0 {}}
3318df9185cSdrhdo_test shell1-3.7.2 {
3328df9185cSdrh  catchcmd "test.db" ".explain ON"
3338df9185cSdrh} {0 {}}
3348df9185cSdrhdo_test shell1-3.7.3 {
3358df9185cSdrh  catchcmd "test.db" ".explain OFF"
3368df9185cSdrh} {0 {}}
3378df9185cSdrhdo_test shell1-3.7.4 {
338c2ce0beaSdrh  # extra arguments ignored
3398df9185cSdrh  catchcmd "test.db" ".explain OFF BAD"
340c2ce0beaSdrh} {0 {}}
3418df9185cSdrh
3428df9185cSdrh
3438df9185cSdrh# .header(s) ON|OFF      Turn display of headers on or off
3448df9185cSdrhdo_test shell1-3.9.1 {
3458df9185cSdrh  catchcmd "test.db" ".header"
346c2ce0beaSdrh} {1 {Usage: .headers on|off}}
3478df9185cSdrhdo_test shell1-3.9.2 {
3488df9185cSdrh  catchcmd "test.db" ".header ON"
3498df9185cSdrh} {0 {}}
3508df9185cSdrhdo_test shell1-3.9.3 {
3518df9185cSdrh  catchcmd "test.db" ".header OFF"
3528df9185cSdrh} {0 {}}
3538df9185cSdrhdo_test shell1-3.9.4 {
3548df9185cSdrh  # too many arguments
3558df9185cSdrh  catchcmd "test.db" ".header OFF BAD"
356c2ce0beaSdrh} {1 {Usage: .headers on|off}}
3578df9185cSdrh
3588df9185cSdrhdo_test shell1-3.9.5 {
3598df9185cSdrh  catchcmd "test.db" ".headers"
360c2ce0beaSdrh} {1 {Usage: .headers on|off}}
3618df9185cSdrhdo_test shell1-3.9.6 {
3628df9185cSdrh  catchcmd "test.db" ".headers ON"
3638df9185cSdrh} {0 {}}
3648df9185cSdrhdo_test shell1-3.9.7 {
3658df9185cSdrh  catchcmd "test.db" ".headers OFF"
3668df9185cSdrh} {0 {}}
3678df9185cSdrhdo_test shell1-3.9.8 {
3688df9185cSdrh  # too many arguments
3698df9185cSdrh  catchcmd "test.db" ".headers OFF BAD"
370c2ce0beaSdrh} {1 {Usage: .headers on|off}}
3718df9185cSdrh
3728df9185cSdrh# .help                  Show this message
3738df9185cSdrhdo_test shell1-3.10.1 {
3748df9185cSdrh  set res [catchcmd "test.db" ".help"]
3758df9185cSdrh  # look for a few of the possible help commands
3768df9185cSdrh  list [regexp {.help} $res] \
3778df9185cSdrh       [regexp {.quit} $res] \
3788df9185cSdrh       [regexp {.show} $res]
3798df9185cSdrh} {1 1 1}
3808df9185cSdrhdo_test shell1-3.10.2 {
3818df9185cSdrh  # we allow .help to take extra args (it is help after all)
38298aa2abcSdrh  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}
3888df9185cSdrh
3898df9185cSdrh# .import FILE TABLE     Import data from FILE into TABLE
3908df9185cSdrhdo_test shell1-3.11.1 {
3918df9185cSdrh  catchcmd "test.db" ".import"
392ccb37816Sdrh} {/1 .ERROR: missing FILE argument.*/}
3938df9185cSdrhdo_test shell1-3.11.2 {
3948df9185cSdrh  catchcmd "test.db" ".import FOO"
395ccb37816Sdrh} {/1 .ERROR: missing TABLE argument.*/}
3968df9185cSdrhdo_test shell1-3.11.3 {
3978df9185cSdrh  # too many arguments
3988df9185cSdrh  catchcmd "test.db" ".import FOO BAR BAD"
399ccb37816Sdrh} {/1 .ERROR: extra argument: "BAD".*./}
4008df9185cSdrh
4010e55db1cSdrh# .indexes ?TABLE?       Show names of all indexes
4020e55db1cSdrh#                          If TABLE specified, only show indexes for tables
4038df9185cSdrh#                          matching LIKE pattern TABLE.
4048df9185cSdrhdo_test shell1-3.12.1 {
4050e55db1cSdrh  catchcmd "test.db" ".indexes"
4068df9185cSdrh} {0 {}}
4078df9185cSdrhdo_test shell1-3.12.2 {
4080e55db1cSdrh  catchcmd "test.db" ".indexes FOO"
4090e55db1cSdrh} {0 {}}
4100e55db1cSdrhdo_test shell1-3.12.2-legacy {
4118df9185cSdrh  catchcmd "test.db" ".indices FOO"
4128df9185cSdrh} {0 {}}
4138df9185cSdrhdo_test shell1-3.12.3 {
4148df9185cSdrh  # too many arguments
4150e55db1cSdrh  catchcmd "test.db" ".indexes FOO BAD"
4160e55db1cSdrh} {1 {Usage: .indexes ?LIKE-PATTERN?}}
4178df9185cSdrh
4188df9185cSdrh# .mode MODE ?TABLE?     Set output mode where MODE is one of:
419e0d6885fSmistachkin#                          ascii    Columns/rows delimited by 0x1F and 0x1E
4208df9185cSdrh#                          csv      Comma-separated values
4218df9185cSdrh#                          column   Left-aligned columns.  (See .width)
4228df9185cSdrh#                          html     HTML <table> code
4238df9185cSdrh#                          insert   SQL insert statements for TABLE
4248df9185cSdrh#                          line     One value per line
425e0d6885fSmistachkin#                          list     Values delimited by .separator strings
4268df9185cSdrh#                          tabs     Tab-separated values
4278df9185cSdrh#                          tcl      TCL list elements
4288df9185cSdrhdo_test shell1-3.13.1 {
4298df9185cSdrh  catchcmd "test.db" ".mode"
430a501f7daSdrh} {0 {current output mode: list}}
4318df9185cSdrhdo_test shell1-3.13.2 {
4328df9185cSdrh  catchcmd "test.db" ".mode FOO"
4330908e385Sdrh} {1 {Error: mode should be one of: ascii box column csv html insert json line list markdown quote table tabs tcl}}
4348df9185cSdrhdo_test shell1-3.13.3 {
4358df9185cSdrh  catchcmd "test.db" ".mode csv"
4368df9185cSdrh} {0 {}}
4378df9185cSdrhdo_test shell1-3.13.4 {
4388df9185cSdrh  catchcmd "test.db" ".mode column"
4398df9185cSdrh} {0 {}}
4408df9185cSdrhdo_test shell1-3.13.5 {
4418df9185cSdrh  catchcmd "test.db" ".mode html"
4428df9185cSdrh} {0 {}}
4438df9185cSdrhdo_test shell1-3.13.6 {
4448df9185cSdrh  catchcmd "test.db" ".mode insert"
4458df9185cSdrh} {0 {}}
4468df9185cSdrhdo_test shell1-3.13.7 {
4478df9185cSdrh  catchcmd "test.db" ".mode line"
4488df9185cSdrh} {0 {}}
4498df9185cSdrhdo_test shell1-3.13.8 {
4508df9185cSdrh  catchcmd "test.db" ".mode list"
4518df9185cSdrh} {0 {}}
4528df9185cSdrhdo_test shell1-3.13.9 {
4538df9185cSdrh  catchcmd "test.db" ".mode tabs"
4548df9185cSdrh} {0 {}}
4558df9185cSdrhdo_test shell1-3.13.10 {
4568df9185cSdrh  catchcmd "test.db" ".mode tcl"
4578df9185cSdrh} {0 {}}
4588df9185cSdrhdo_test shell1-3.13.11 {
459c2ce0beaSdrh  # extra arguments ignored
4608df9185cSdrh  catchcmd "test.db" ".mode tcl BAD"
461c2ce0beaSdrh} {0 {}}
4628df9185cSdrh
4638df9185cSdrh# don't allow partial mode type matches
4648df9185cSdrhdo_test shell1-3.13.12 {
4658df9185cSdrh  catchcmd "test.db" ".mode l"
4660908e385Sdrh} {1 {Error: mode should be one of: ascii box column csv html insert json line list markdown quote table tabs tcl}}
4678df9185cSdrhdo_test shell1-3.13.13 {
4688df9185cSdrh  catchcmd "test.db" ".mode li"
4690908e385Sdrh} {1 {Error: mode should be one of: ascii box column csv html insert json line list markdown quote table tabs tcl}}
4708df9185cSdrhdo_test shell1-3.13.14 {
4718df9185cSdrh  catchcmd "test.db" ".mode lin"
472c2ce0beaSdrh} {0 {}}
4738df9185cSdrh
4748df9185cSdrh# .nullvalue STRING      Print STRING in place of NULL values
4758df9185cSdrhdo_test shell1-3.14.1 {
4768df9185cSdrh  catchcmd "test.db" ".nullvalue"
477c2ce0beaSdrh} {1 {Usage: .nullvalue STRING}}
4788df9185cSdrhdo_test shell1-3.14.2 {
4798df9185cSdrh  catchcmd "test.db" ".nullvalue FOO"
4808df9185cSdrh} {0 {}}
4818df9185cSdrhdo_test shell1-3.14.3 {
4828df9185cSdrh  # too many arguments
4838df9185cSdrh  catchcmd "test.db" ".nullvalue FOO BAD"
484c2ce0beaSdrh} {1 {Usage: .nullvalue STRING}}
4858df9185cSdrh
4868df9185cSdrh# .output FILENAME       Send output to FILENAME
4878df9185cSdrhdo_test shell1-3.15.1 {
4888df9185cSdrh  catchcmd "test.db" ".output"
489c2ce0beaSdrh} {0 {}}
4908df9185cSdrhdo_test shell1-3.15.2 {
4918df9185cSdrh  catchcmd "test.db" ".output FOO"
4928df9185cSdrh} {0 {}}
4938df9185cSdrhdo_test shell1-3.15.3 {
4948df9185cSdrh  # too many arguments
4958df9185cSdrh  catchcmd "test.db" ".output FOO BAD"
496541ef2c3Sdrh} {1 {ERROR: extra parameter: "BAD".  Usage:
497541ef2c3Sdrh.output ?FILE?           Send output to FILE or stdout if FILE is omitted
498541ef2c3Sdrh   If FILE begins with '|' then open it as a pipe.
499541ef2c3Sdrh   Options:
500541ef2c3Sdrh     --bom                 Prefix output with a UTF8 byte-order mark
501541ef2c3Sdrh     -e                    Send output to the system text editor
502541ef2c3Sdrh     -x                    Send output as CSV to a spreadsheet
503541ef2c3Sdrhchild process exited abnormally}}
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"
512541ef2c3Sdrh} {1 {ERROR: extra parameter: "BAD".  Usage:
513541ef2c3Sdrh.output ?FILE?           Send output to FILE or stdout if FILE is omitted
514541ef2c3Sdrh   If FILE begins with '|' then open it as a pipe.
515541ef2c3Sdrh   Options:
516541ef2c3Sdrh     --bom                 Prefix output with a UTF8 byte-order mark
517541ef2c3Sdrh     -e                    Send output to the system text editor
518541ef2c3Sdrh     -x                    Send output as CSV to a spreadsheet
519541ef2c3Sdrhchild process exited abnormally}}
5208df9185cSdrh
5218df9185cSdrh# .prompt MAIN CONTINUE  Replace the standard prompts
5228df9185cSdrhdo_test shell1-3.17.1 {
5238df9185cSdrh  catchcmd "test.db" ".prompt"
524c2ce0beaSdrh} {0 {}}
5258df9185cSdrhdo_test shell1-3.17.2 {
5268df9185cSdrh  catchcmd "test.db" ".prompt FOO"
5278df9185cSdrh} {0 {}}
5288df9185cSdrhdo_test shell1-3.17.3 {
5298df9185cSdrh  catchcmd "test.db" ".prompt FOO BAR"
5308df9185cSdrh} {0 {}}
5318df9185cSdrhdo_test shell1-3.17.4 {
5328df9185cSdrh  # too many arguments
5338df9185cSdrh  catchcmd "test.db" ".prompt FOO BAR BAD"
534c2ce0beaSdrh} {0 {}}
5358df9185cSdrh
5368df9185cSdrh# .quit                  Exit this program
5378df9185cSdrhdo_test shell1-3.18.1 {
5388df9185cSdrh  catchcmd "test.db" ".quit"
5398df9185cSdrh} {0 {}}
5408df9185cSdrhdo_test shell1-3.18.2 {
5418df9185cSdrh  # too many arguments
5428df9185cSdrh  catchcmd "test.db" ".quit BAD"
543c2ce0beaSdrh} {0 {}}
5448df9185cSdrh
5458df9185cSdrh# .read FILENAME         Execute SQL in FILENAME
5468df9185cSdrhdo_test shell1-3.19.1 {
5478df9185cSdrh  catchcmd "test.db" ".read"
548c2ce0beaSdrh} {1 {Usage: .read FILE}}
5498df9185cSdrhdo_test shell1-3.19.2 {
5509ac99313Smistachkin  forcedelete FOO
5518df9185cSdrh  catchcmd "test.db" ".read FOO"
5528df9185cSdrh} {1 {Error: cannot open "FOO"}}
5538df9185cSdrhdo_test shell1-3.19.3 {
5548df9185cSdrh  # too many arguments
5558df9185cSdrh  catchcmd "test.db" ".read FOO BAD"
556c2ce0beaSdrh} {1 {Usage: .read FILE}}
5578df9185cSdrh
5588df9185cSdrh# .restore ?DB? FILE     Restore content of DB (default "main") from FILE
5598df9185cSdrhdo_test shell1-3.20.1 {
5608df9185cSdrh  catchcmd "test.db" ".restore"
561c2ce0beaSdrh} {1 {Usage: .restore ?DB? FILE}}
5628df9185cSdrhdo_test shell1-3.20.2 {
5638df9185cSdrh  catchcmd "test.db" ".restore FOO"
5648df9185cSdrh} {0 {}}
5658df9185cSdrhdo_test shell1-3.20.3 {
5668df9185cSdrh  catchcmd "test.db" ".restore FOO BAR"
5678df9185cSdrh} {1 {Error: unknown database FOO}}
5688df9185cSdrhdo_test shell1-3.20.4 {
5698df9185cSdrh  # too many arguments
5708df9185cSdrh  catchcmd "test.db" ".restore FOO BAR BAD"
571c2ce0beaSdrh} {1 {Usage: .restore ?DB? FILE}}
5728df9185cSdrh
573a22dd386Sdrhifcapable vtab {
5748df9185cSdrh# .schema ?TABLE?        Show the CREATE statements
5758df9185cSdrh#                          If TABLE specified, only show tables matching
5768df9185cSdrh#                          LIKE pattern TABLE.
5778df9185cSdrhdo_test shell1-3.21.1 {
5788df9185cSdrh  catchcmd "test.db" ".schema"
5798df9185cSdrh} {0 {}}
5808df9185cSdrhdo_test shell1-3.21.2 {
5818df9185cSdrh  catchcmd "test.db" ".schema FOO"
5828df9185cSdrh} {0 {}}
5838df9185cSdrhdo_test shell1-3.21.3 {
5848df9185cSdrh  # too many arguments
5858df9185cSdrh  catchcmd "test.db" ".schema FOO BAD"
586*bbb29ecfSdrh} {1 {Usage: .schema ?--indent? ?--nosys? ?LIKE-PATTERN?}}
5878df9185cSdrh
588ac43e98dSdrhdo_test shell1-3.21.4 {
589ac43e98dSdrh  catchcmd "test.db" {
590ac43e98dSdrh     CREATE TABLE t1(x);
591ac43e98dSdrh     CREATE VIEW v2 AS SELECT x+1 AS y FROM t1;
592ac43e98dSdrh     CREATE VIEW v1 AS SELECT y+1 FROM v2;
593ac43e98dSdrh  }
594ac43e98dSdrh  catchcmd "test.db" ".schema"
595ac43e98dSdrh} {0 {CREATE TABLE t1(x);
596ceba792aSdrhCREATE VIEW v2 AS SELECT x+1 AS y FROM t1
5971d315cf7Sdrh/* v2(y) */;
598ceba792aSdrhCREATE VIEW v1 AS SELECT y+1 FROM v2
5991d315cf7Sdrh/* v1("y+1") */;}}
600ac43e98dSdrhdb eval {DROP VIEW v1; DROP VIEW v2; DROP TABLE t1;}
601a22dd386Sdrh}
602ac43e98dSdrh
603636bf9f7Smistachkin# .separator STRING  Change column separator used by output and .import
6048df9185cSdrhdo_test shell1-3.22.1 {
6058df9185cSdrh  catchcmd "test.db" ".separator"
606e0d6885fSmistachkin} {1 {Usage: .separator COL ?ROW?}}
6078df9185cSdrhdo_test shell1-3.22.2 {
6088df9185cSdrh  catchcmd "test.db" ".separator FOO"
6098df9185cSdrh} {0 {}}
6108df9185cSdrhdo_test shell1-3.22.3 {
6116976c212Sdrh  catchcmd "test.db" ".separator ABC XYZ"
6126976c212Sdrh} {0 {}}
6136976c212Sdrhdo_test shell1-3.22.4 {
6148df9185cSdrh  # too many arguments
6156976c212Sdrh  catchcmd "test.db" ".separator FOO BAD BAD2"
616e0d6885fSmistachkin} {1 {Usage: .separator COL ?ROW?}}
6178df9185cSdrh
6188df9185cSdrh# .show                  Show the current values for various settings
6198df9185cSdrhdo_test shell1-3.23.1 {
6208df9185cSdrh  set res [catchcmd "test.db" ".show"]
6218df9185cSdrh  list [regexp {echo:} $res] \
6228df9185cSdrh       [regexp {explain:} $res] \
6238df9185cSdrh       [regexp {headers:} $res] \
6248df9185cSdrh       [regexp {mode:} $res] \
6258df9185cSdrh       [regexp {nullvalue:} $res] \
6268df9185cSdrh       [regexp {output:} $res] \
627636bf9f7Smistachkin       [regexp {colseparator:} $res] \
628636bf9f7Smistachkin       [regexp {rowseparator:} $res] \
6298df9185cSdrh       [regexp {stats:} $res] \
6308df9185cSdrh       [regexp {width:} $res]
631e0d6885fSmistachkin} {1 1 1 1 1 1 1 1 1 1}
6328df9185cSdrhdo_test shell1-3.23.2 {
6338df9185cSdrh  # too many arguments
6348df9185cSdrh  catchcmd "test.db" ".show BAD"
635c2ce0beaSdrh} {1 {Usage: .show}}
6368df9185cSdrh
6378df9185cSdrh# .stats ON|OFF          Turn stats on or off
63834784903Sdrh#do_test shell1-3.23b.1 {
63934784903Sdrh#  catchcmd "test.db" ".stats"
64034784903Sdrh#} {1 {Usage: .stats on|off}}
6418df9185cSdrhdo_test shell1-3.23b.2 {
6428df9185cSdrh  catchcmd "test.db" ".stats ON"
6438df9185cSdrh} {0 {}}
6448df9185cSdrhdo_test shell1-3.23b.3 {
6458df9185cSdrh  catchcmd "test.db" ".stats OFF"
6468df9185cSdrh} {0 {}}
6478df9185cSdrhdo_test shell1-3.23b.4 {
6488df9185cSdrh  # too many arguments
6498df9185cSdrh  catchcmd "test.db" ".stats OFF BAD"
65034784903Sdrh} {1 {Usage: .stats ?on|off?}}
6518df9185cSdrh
6523c49eaf4Sdrh# Ticket 7be932dfa60a8a6b3b26bcf7623ec46e0a403ddb 2018-06-07
6533c49eaf4Sdrh# Adverse interaction between .stats and .eqp
6543c49eaf4Sdrh#
6553c49eaf4Sdrhdo_test shell1-3.23b.5 {
6563c49eaf4Sdrh  catchcmd "test.db" [string map {"\n    " "\n"} {
6573c49eaf4Sdrh    CREATE TEMP TABLE t1(x);
6583c49eaf4Sdrh    INSERT INTO t1 VALUES(1),(2);
6593c49eaf4Sdrh    .stats on
6603c49eaf4Sdrh    .eqp full
6613c49eaf4Sdrh    SELECT * FROM t1;
6623c49eaf4Sdrh  }]
6633c49eaf4Sdrh} {/1\n2\n/}
6643c49eaf4Sdrh
6658df9185cSdrh# .tables ?TABLE?        List names of tables
6668df9185cSdrh#                          If TABLE specified, only list tables matching
6678df9185cSdrh#                          LIKE pattern TABLE.
6688df9185cSdrhdo_test shell1-3.24.1 {
6698df9185cSdrh  catchcmd "test.db" ".tables"
6708df9185cSdrh} {0 {}}
6718df9185cSdrhdo_test shell1-3.24.2 {
6728df9185cSdrh  catchcmd "test.db" ".tables FOO"
6738df9185cSdrh} {0 {}}
6748df9185cSdrhdo_test shell1-3.24.3 {
6758df9185cSdrh  # too many arguments
6768df9185cSdrh  catchcmd "test.db" ".tables FOO BAD"
677c2ce0beaSdrh} {0 {}}
6788df9185cSdrh
6798df9185cSdrh# .timeout MS            Try opening locked tables for MS milliseconds
6808df9185cSdrhdo_test shell1-3.25.1 {
6818df9185cSdrh  catchcmd "test.db" ".timeout"
682c2ce0beaSdrh} {0 {}}
6838df9185cSdrhdo_test shell1-3.25.2 {
6848df9185cSdrh  catchcmd "test.db" ".timeout zzz"
6858df9185cSdrh  # this should be treated the same as a '0' timeout
6868df9185cSdrh} {0 {}}
6878df9185cSdrhdo_test shell1-3.25.3 {
6888df9185cSdrh  catchcmd "test.db" ".timeout 1"
6898df9185cSdrh} {0 {}}
6908df9185cSdrhdo_test shell1-3.25.4 {
6918df9185cSdrh  # too many arguments
6928df9185cSdrh  catchcmd "test.db" ".timeout 1 BAD"
693c2ce0beaSdrh} {0 {}}
6948df9185cSdrh
6958df9185cSdrh# .width NUM NUM ...     Set column widths for "column" mode
6968df9185cSdrhdo_test shell1-3.26.1 {
6978df9185cSdrh  catchcmd "test.db" ".width"
698c2ce0beaSdrh} {0 {}}
6998df9185cSdrhdo_test shell1-3.26.2 {
7008df9185cSdrh  catchcmd "test.db" ".width xxx"
7018df9185cSdrh  # this should be treated the same as a '0' width for col 1
7028df9185cSdrh} {0 {}}
7038df9185cSdrhdo_test shell1-3.26.3 {
7048df9185cSdrh  catchcmd "test.db" ".width xxx yyy"
7058df9185cSdrh  # this should be treated the same as a '0' width for col 1 and 2
7068df9185cSdrh} {0 {}}
7078df9185cSdrhdo_test shell1-3.26.4 {
7088df9185cSdrh  catchcmd "test.db" ".width 1 1"
7098df9185cSdrh  # this should be treated the same as a '1' width for col 1 and 2
7108df9185cSdrh} {0 {}}
711078b1fdaSdrhdo_test shell1-3.26.5 {
712c0605084Sdrh  catchcmd "test.db" ".mode column\n.header off\n.width 10 -10\nSELECT 'abcdefg', 123456;"
713078b1fdaSdrh  # this should be treated the same as a '1' width for col 1 and 2
714078b1fdaSdrh} {0 {abcdefg         123456}}
715078b1fdaSdrhdo_test shell1-3.26.6 {
716c0605084Sdrh  catchcmd "test.db" ".mode column\n.header off\n.width -10 10\nSELECT 'abcdefg', 123456;"
717078b1fdaSdrh  # this should be treated the same as a '1' width for col 1 and 2
718078b1fdaSdrh} {0 {   abcdefg  123456    }}
719078b1fdaSdrh
7208df9185cSdrh
7218df9185cSdrh# .timer ON|OFF          Turn the CPU timer measurement on or off
7228df9185cSdrhdo_test shell1-3.27.1 {
7238df9185cSdrh  catchcmd "test.db" ".timer"
724c2ce0beaSdrh} {1 {Usage: .timer on|off}}
7258df9185cSdrhdo_test shell1-3.27.2 {
7268df9185cSdrh  catchcmd "test.db" ".timer ON"
7278df9185cSdrh} {0 {}}
7288df9185cSdrhdo_test shell1-3.27.3 {
7298df9185cSdrh  catchcmd "test.db" ".timer OFF"
7308df9185cSdrh} {0 {}}
7318df9185cSdrhdo_test shell1-3.27.4 {
7328df9185cSdrh  # too many arguments
7338df9185cSdrh  catchcmd "test.db" ".timer OFF BAD"
734c2ce0beaSdrh} {1 {Usage: .timer on|off}}
7358df9185cSdrh
7368df9185cSdrhdo_test shell1-3-28.1 {
7378df9185cSdrh  catchcmd test.db \
7388df9185cSdrh     ".log stdout\nSELECT coalesce(sqlite_log(123,'hello'),'456');"
7398df9185cSdrh} "0 {(123) hello\n456}"
7408df9185cSdrh
741078b1fdaSdrhdo_test shell1-3-29.1 {
742078b1fdaSdrh  catchcmd "test.db" ".print this is a test"
743078b1fdaSdrh} {0 {this is a test}}
744078b1fdaSdrh
7454c56b99fSdrh# dot-command argument quoting
7464c56b99fSdrhdo_test shell1-3-30.1 {
7474c56b99fSdrh  catchcmd {test.db} {.print "this\"is'a\055test" 'this\"is\\a\055test'}
7484c56b99fSdrh} {0 {this"is'a-test this\"is\\a\055test}}
7494c56b99fSdrhdo_test shell1-3-31.1 {
7504c56b99fSdrh  catchcmd {test.db} {.print "this\nis\ta\\test" 'this\nis\ta\\test'}
7514c56b99fSdrh} [list 0 "this\nis\ta\\test this\\nis\\ta\\\\test"]
7524c56b99fSdrh
7534c56b99fSdrh
7545128e85cSdrh# Test the output of the ".dump" command
7555128e85cSdrh#
7565128e85cSdrhdo_test shell1-4.1 {
75755a1b308Sdrh  db close
75855a1b308Sdrh  forcedelete test.db
75955a1b308Sdrh  sqlite3 db test.db
7605128e85cSdrh  db eval {
76155a1b308Sdrh    PRAGMA encoding=UTF16;
7625128e85cSdrh    CREATE TABLE t1(x);
763585dcb25Smistachkin    INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f');
764151c75adSmistachkin    CREATE TABLE t3(x,y);
765151c75adSmistachkin    INSERT INTO t3 VALUES(1,null), (2,''), (3,1),
766151c75adSmistachkin                         (4,2.25), (5,'hello'), (6,x'807f');
7675128e85cSdrh  }
7685128e85cSdrh  catchcmd test.db {.dump}
7695128e85cSdrh} {0 {PRAGMA foreign_keys=OFF;
7705128e85cSdrhBEGIN TRANSACTION;
7715128e85cSdrhCREATE TABLE t1(x);
772f42d3180SdrhINSERT INTO t1 VALUES(NULL);
773f42d3180SdrhINSERT INTO t1 VALUES('');
774f42d3180SdrhINSERT INTO t1 VALUES(1);
775f42d3180SdrhINSERT INTO t1 VALUES(2.25);
776f42d3180SdrhINSERT INTO t1 VALUES('hello');
777f42d3180SdrhINSERT INTO t1 VALUES(X'807f');
778151c75adSmistachkinCREATE TABLE t3(x,y);
779f42d3180SdrhINSERT INTO t3 VALUES(1,NULL);
780f42d3180SdrhINSERT INTO t3 VALUES(2,'');
781f42d3180SdrhINSERT INTO t3 VALUES(3,1);
782f42d3180SdrhINSERT INTO t3 VALUES(4,2.25);
783f42d3180SdrhINSERT INTO t3 VALUES(5,'hello');
784f42d3180SdrhINSERT INTO t3 VALUES(6,X'807f');
7855128e85cSdrhCOMMIT;}}
7865128e85cSdrh
787b9cd86a0Sdan
788b9cd86a0Sdanifcapable vtab {
789b9cd86a0Sdan
790f42d3180Sdrh# The --preserve-rowids option to .dump
791f42d3180Sdrh#
792e611f144Sdrhdo_test shell1-4.1.1 {
793e611f144Sdrh  catchcmd test.db {.dump --preserve-rowids}
794e611f144Sdrh} {0 {PRAGMA foreign_keys=OFF;
795e611f144SdrhBEGIN TRANSACTION;
796e611f144SdrhCREATE TABLE t1(x);
797f42d3180SdrhINSERT INTO t1(rowid,x) VALUES(1,NULL);
798f42d3180SdrhINSERT INTO t1(rowid,x) VALUES(2,'');
799f42d3180SdrhINSERT INTO t1(rowid,x) VALUES(3,1);
800f42d3180SdrhINSERT INTO t1(rowid,x) VALUES(4,2.25);
801f42d3180SdrhINSERT INTO t1(rowid,x) VALUES(5,'hello');
802f42d3180SdrhINSERT INTO t1(rowid,x) VALUES(6,X'807f');
803e611f144SdrhCREATE TABLE t3(x,y);
804f42d3180SdrhINSERT INTO t3(rowid,x,y) VALUES(1,1,NULL);
805f42d3180SdrhINSERT INTO t3(rowid,x,y) VALUES(2,2,'');
806f42d3180SdrhINSERT INTO t3(rowid,x,y) VALUES(3,3,1);
807f42d3180SdrhINSERT INTO t3(rowid,x,y) VALUES(4,4,2.25);
808f42d3180SdrhINSERT INTO t3(rowid,x,y) VALUES(5,5,'hello');
809f42d3180SdrhINSERT INTO t3(rowid,x,y) VALUES(6,6,X'807f');
810e611f144SdrhCOMMIT;}}
811e611f144Sdrh
812f42d3180Sdrh# If the table contains an INTEGER PRIMARY KEY, do not record a separate
813f42d3180Sdrh# rowid column in the output.
814f42d3180Sdrh#
815e611f144Sdrhdo_test shell1-4.1.2 {
816e611f144Sdrh  db close
817e611f144Sdrh  forcedelete test2.db
818e611f144Sdrh  sqlite3 db test2.db
819e611f144Sdrh  db eval {
820e611f144Sdrh    CREATE TABLE t1(x INTEGER PRIMARY KEY, y);
821e611f144Sdrh    INSERT INTO t1 VALUES(1,null), (2,''), (3,1),
822e611f144Sdrh                         (4,2.25), (5,'hello'), (6,x'807f');
823e611f144Sdrh  }
824e611f144Sdrh  catchcmd test2.db {.dump --preserve-rowids}
825e611f144Sdrh} {0 {PRAGMA foreign_keys=OFF;
826e611f144SdrhBEGIN TRANSACTION;
827e611f144SdrhCREATE TABLE t1(x INTEGER PRIMARY KEY, y);
828f42d3180SdrhINSERT INTO t1 VALUES(1,NULL);
829f42d3180SdrhINSERT INTO t1 VALUES(2,'');
830f42d3180SdrhINSERT INTO t1 VALUES(3,1);
831f42d3180SdrhINSERT INTO t1 VALUES(4,2.25);
832f42d3180SdrhINSERT INTO t1 VALUES(5,'hello');
833f42d3180SdrhINSERT INTO t1 VALUES(6,X'807f');
834e611f144SdrhCOMMIT;}}
835e611f144Sdrh
836f42d3180Sdrh# Verify that the table named [table] is correctly quoted and that
837f42d3180Sdrh# an INTEGER PRIMARY KEY DESC is not an alias for the rowid.
838f42d3180Sdrh#
839f42d3180Sdrhdo_test shell1-4.1.3 {
840f42d3180Sdrh  db close
841f42d3180Sdrh  forcedelete test2.db
842f42d3180Sdrh  sqlite3 db test2.db
843f42d3180Sdrh  db eval {
844f42d3180Sdrh    CREATE TABLE [table](x INTEGER PRIMARY KEY DESC, y);
845f42d3180Sdrh    INSERT INTO [table] VALUES(1,null), (12,''), (23,1),
846f42d3180Sdrh                         (34,2.25), (45,'hello'), (56,x'807f');
847f42d3180Sdrh  }
848f42d3180Sdrh  catchcmd test2.db {.dump --preserve-rowids}
849f42d3180Sdrh} {0 {PRAGMA foreign_keys=OFF;
850f42d3180SdrhBEGIN TRANSACTION;
851f42d3180SdrhCREATE TABLE [table](x INTEGER PRIMARY KEY DESC, y);
852f42d3180SdrhINSERT INTO "table"(rowid,x,y) VALUES(1,1,NULL);
853f42d3180SdrhINSERT INTO "table"(rowid,x,y) VALUES(2,12,'');
854f42d3180SdrhINSERT INTO "table"(rowid,x,y) VALUES(3,23,1);
855f42d3180SdrhINSERT INTO "table"(rowid,x,y) VALUES(4,34,2.25);
856f42d3180SdrhINSERT INTO "table"(rowid,x,y) VALUES(5,45,'hello');
857f42d3180SdrhINSERT INTO "table"(rowid,x,y) VALUES(6,56,X'807f');
858f42d3180SdrhCOMMIT;}}
859f42d3180Sdrh
860f42d3180Sdrh# Do not record rowids for a WITHOUT ROWID table.  Also check correct quoting
861f42d3180Sdrh# of table names that contain odd characters.
862f42d3180Sdrh#
863f42d3180Sdrhdo_test shell1-4.1.4 {
864f42d3180Sdrh  db close
865f42d3180Sdrh  forcedelete test2.db
866f42d3180Sdrh  sqlite3 db test2.db
867f42d3180Sdrh  db eval {
868f42d3180Sdrh    CREATE TABLE [ta<>ble](x INTEGER PRIMARY KEY, y) WITHOUT ROWID;
869f42d3180Sdrh    INSERT INTO [ta<>ble] VALUES(1,null), (12,''), (23,1),
870f42d3180Sdrh                         (34,2.25), (45,'hello'), (56,x'807f');
871f42d3180Sdrh  }
872f42d3180Sdrh  catchcmd test2.db {.dump --preserve-rowids}
873f42d3180Sdrh} {0 {PRAGMA foreign_keys=OFF;
874f42d3180SdrhBEGIN TRANSACTION;
875f42d3180SdrhCREATE TABLE [ta<>ble](x INTEGER PRIMARY KEY, y) WITHOUT ROWID;
876f42d3180SdrhINSERT INTO "ta<>ble" VALUES(1,NULL);
877f42d3180SdrhINSERT INTO "ta<>ble" VALUES(12,'');
878f42d3180SdrhINSERT INTO "ta<>ble" VALUES(23,1);
879f42d3180SdrhINSERT INTO "ta<>ble" VALUES(34,2.25);
880f42d3180SdrhINSERT INTO "ta<>ble" VALUES(45,'hello');
881f42d3180SdrhINSERT INTO "ta<>ble" VALUES(56,X'807f');
882f42d3180SdrhCOMMIT;}}
883f42d3180Sdrh
884f42d3180Sdrh# Do not record rowids if the rowid is inaccessible
885f42d3180Sdrh#
886f42d3180Sdrhdo_test shell1-4.1.5 {
887f42d3180Sdrh  db close
888f42d3180Sdrh  forcedelete test2.db
889f42d3180Sdrh  sqlite3 db test2.db
890f42d3180Sdrh  db eval {
891f42d3180Sdrh    CREATE TABLE t1(_ROWID_,rowid,oid);
892f42d3180Sdrh    INSERT INTO t1 VALUES(1,null,'alpha'), (12,'',99), (23,1,x'b0b1b2');
893f42d3180Sdrh  }
894f42d3180Sdrh  catchcmd test2.db {.dump --preserve-rowids}
895f42d3180Sdrh} {0 {PRAGMA foreign_keys=OFF;
896f42d3180SdrhBEGIN TRANSACTION;
897f42d3180SdrhCREATE TABLE t1(_ROWID_,rowid,oid);
898f42d3180SdrhINSERT INTO t1 VALUES(1,NULL,'alpha');
899f42d3180SdrhINSERT INTO t1 VALUES(12,'',99);
900f42d3180SdrhINSERT INTO t1 VALUES(23,1,X'b0b1b2');
901f42d3180SdrhCOMMIT;}}
902e611f144Sdrh
903b9cd86a0Sdan} else {
904b9cd86a0Sdan
905b9cd86a0Sdando_test shell1-4.1.6 {
906b9cd86a0Sdan  db close
907b9cd86a0Sdan  forcedelete test2.db
908b9cd86a0Sdan  sqlite3 db test2.db
909b9cd86a0Sdan  db eval {
910b9cd86a0Sdan    CREATE TABLE t1(x INTEGER PRIMARY KEY, y);
911b9cd86a0Sdan    INSERT INTO t1 VALUES(1,null), (2,''), (3,1),
912b9cd86a0Sdan                         (4,2.25), (5,'hello'), (6,x'807f');
913b9cd86a0Sdan  }
914b9cd86a0Sdan  catchcmd test2.db {.dump --preserve-rowids}
915b9cd86a0Sdan} {1 {The --preserve-rowids option is not compatible with SQLITE_OMIT_VIRTUALTABLE}}
916b9cd86a0Sdan
917b9cd86a0Sdan}
918b9cd86a0Sdan
919b9cd86a0Sdan
9205128e85cSdrh# Test the output of ".mode insert"
9215128e85cSdrh#
922151c75adSmistachkindo_test shell1-4.2.1 {
9235128e85cSdrh  catchcmd test.db ".mode insert t1\nselect * from t1;"
9245128e85cSdrh} {0 {INSERT INTO t1 VALUES(NULL);
925585dcb25SmistachkinINSERT INTO t1 VALUES('');
9265128e85cSdrhINSERT INTO t1 VALUES(1);
9275128e85cSdrhINSERT INTO t1 VALUES(2.25);
9285128e85cSdrhINSERT INTO t1 VALUES('hello');
9295128e85cSdrhINSERT INTO t1 VALUES(X'807f');}}
9305128e85cSdrh
931151c75adSmistachkin# Test the output of ".mode insert" with headers
932151c75adSmistachkin#
933151c75adSmistachkindo_test shell1-4.2.2 {
934151c75adSmistachkin  catchcmd test.db ".mode insert t1\n.headers on\nselect * from t1;"
935151c75adSmistachkin} {0 {INSERT INTO t1(x) VALUES(NULL);
936151c75adSmistachkinINSERT INTO t1(x) VALUES('');
937151c75adSmistachkinINSERT INTO t1(x) VALUES(1);
938151c75adSmistachkinINSERT INTO t1(x) VALUES(2.25);
939151c75adSmistachkinINSERT INTO t1(x) VALUES('hello');
940151c75adSmistachkinINSERT INTO t1(x) VALUES(X'807f');}}
941151c75adSmistachkin
942151c75adSmistachkin# Test the output of ".mode insert"
943151c75adSmistachkin#
944151c75adSmistachkindo_test shell1-4.2.3 {
945151c75adSmistachkin  catchcmd test.db ".mode insert t3\nselect * from t3;"
946151c75adSmistachkin} {0 {INSERT INTO t3 VALUES(1,NULL);
947151c75adSmistachkinINSERT INTO t3 VALUES(2,'');
948151c75adSmistachkinINSERT INTO t3 VALUES(3,1);
949151c75adSmistachkinINSERT INTO t3 VALUES(4,2.25);
950151c75adSmistachkinINSERT INTO t3 VALUES(5,'hello');
951151c75adSmistachkinINSERT INTO t3 VALUES(6,X'807f');}}
952151c75adSmistachkin
953151c75adSmistachkin# Test the output of ".mode insert" with headers
954151c75adSmistachkin#
955cc445402Smistachkindo_test shell1-4.2.4 {
956151c75adSmistachkin  catchcmd test.db ".mode insert t3\n.headers on\nselect * from t3;"
957151c75adSmistachkin} {0 {INSERT INTO t3(x,y) VALUES(1,NULL);
958151c75adSmistachkinINSERT INTO t3(x,y) VALUES(2,'');
959151c75adSmistachkinINSERT INTO t3(x,y) VALUES(3,1);
960151c75adSmistachkinINSERT INTO t3(x,y) VALUES(4,2.25);
961151c75adSmistachkinINSERT INTO t3(x,y) VALUES(5,'hello');
962151c75adSmistachkinINSERT INTO t3(x,y) VALUES(6,X'807f');}}
963151c75adSmistachkin
964585dcb25Smistachkin# Test the output of ".mode tcl"
965585dcb25Smistachkin#
966585dcb25Smistachkindo_test shell1-4.3 {
96755a1b308Sdrh  db close
96855a1b308Sdrh  forcedelete test.db
96955a1b308Sdrh  sqlite3 db test.db
97055a1b308Sdrh  db eval {
97155a1b308Sdrh    PRAGMA encoding=UTF8;
97255a1b308Sdrh    CREATE TABLE t1(x);
97355a1b308Sdrh    INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f');
97455a1b308Sdrh  }
975585dcb25Smistachkin  catchcmd test.db ".mode tcl\nselect * from t1;"
976585dcb25Smistachkin} {0 {""
977585dcb25Smistachkin""
978585dcb25Smistachkin"1"
979585dcb25Smistachkin"2.25"
980585dcb25Smistachkin"hello"
981585dcb25Smistachkin"\200\177"}}
982585dcb25Smistachkin
983585dcb25Smistachkin# Test the output of ".mode tcl" with multiple columns
984585dcb25Smistachkin#
985585dcb25Smistachkindo_test shell1-4.4 {
986585dcb25Smistachkin  db eval {
987585dcb25Smistachkin    CREATE TABLE t2(x,y);
988585dcb25Smistachkin    INSERT INTO t2 VALUES(null, ''), (1, 2.25), ('hello', x'807f');
989585dcb25Smistachkin  }
990585dcb25Smistachkin  catchcmd test.db ".mode tcl\nselect * from t2;"
991585dcb25Smistachkin} {0 {"" ""
992585dcb25Smistachkin"1" "2.25"
993585dcb25Smistachkin"hello" "\200\177"}}
994585dcb25Smistachkin
995585dcb25Smistachkin# Test the output of ".mode tcl" with ".nullvalue"
996585dcb25Smistachkin#
997585dcb25Smistachkindo_test shell1-4.5 {
998585dcb25Smistachkin  catchcmd test.db ".mode tcl\n.nullvalue NULL\nselect * from t2;"
999585dcb25Smistachkin} {0 {"NULL" ""
1000585dcb25Smistachkin"1" "2.25"
1001585dcb25Smistachkin"hello" "\200\177"}}
1002585dcb25Smistachkin
1003585dcb25Smistachkin# Test the output of ".mode tcl" with Tcl reserved characters
1004585dcb25Smistachkin#
1005585dcb25Smistachkindo_test shell1-4.6 {
1006585dcb25Smistachkin  db eval {
1007585dcb25Smistachkin    CREATE TABLE tcl1(x);
1008585dcb25Smistachkin    INSERT INTO tcl1 VALUES('"'), ('['), (']'), ('\{'), ('\}'), (';'), ('$');
1009585dcb25Smistachkin  }
1010585dcb25Smistachkin  foreach {x y} [catchcmd test.db ".mode tcl\nselect * from tcl1;"] break
1011585dcb25Smistachkin  list $x $y [llength $y]
1012585dcb25Smistachkin} {0 {"\""
1013585dcb25Smistachkin"["
1014585dcb25Smistachkin"]"
1015585dcb25Smistachkin"\\{"
1016585dcb25Smistachkin"\\}"
1017585dcb25Smistachkin";"
1018585dcb25Smistachkin"$"} 7}
10195128e85cSdrh
1020f21979dfSmistachkin# Test using arbitrary byte data with the shell via standard input/output.
1021f21979dfSmistachkin#
1022f21979dfSmistachkindo_test shell1-5.0 {
1023f21979dfSmistachkin  #
1024f21979dfSmistachkin  # NOTE: Skip NUL byte because it appears to be incompatible with command
1025f21979dfSmistachkin  #       shell argument parsing.
1026f21979dfSmistachkin  #
1027f21979dfSmistachkin  for {set i 1} {$i < 256} {incr i} {
1028f21979dfSmistachkin    #
102946a6b994Smistachkin    # NOTE: Due to how the Tcl [exec] command works (i.e. where it treats
103046a6b994Smistachkin    #       command channels opened for it as textual ones), the carriage
103146a6b994Smistachkin    #       return character (and on Windows, the end-of-file character)
103246a6b994Smistachkin    #       cannot be used here.
1033f21979dfSmistachkin    #
103446a6b994Smistachkin    if {$i==0x0D || ($tcl_platform(platform)=="windows" && $i==0x1A)} {
1035f21979dfSmistachkin      continue
1036f21979dfSmistachkin    }
1037158931abSdrh    # Tcl 8.7 maps 0x80 through 0x9f into valid UTF8.  So skip those tests.
1038158931abSdrh    if {$i>=0x80 && $i<=0x9f} continue
103901725680Sdrh    if {$i>=0xE0 && $tcl_platform(os)=="OpenBSD"}  continue
1040be56ad31Smistachkin    if {$i>=0xE0 && $i<=0xEF && $tcl_platform(os)=="Linux"}  continue
1041f21979dfSmistachkin    set hex [format %02X $i]
1042f21979dfSmistachkin    set char [subst \\x$hex]; set oldChar $char
10430acee513Smistachkin    set escapes [list]
10440acee513Smistachkin    if {$tcl_platform(platform)=="windows"} {
10450acee513Smistachkin      #
10460acee513Smistachkin      # NOTE: On Windows, we need to escape all the whitespace characters,
10470acee513Smistachkin      #       the alarm (\a) character, and those with special meaning to
10480acee513Smistachkin      #       the SQLite shell itself.
10490acee513Smistachkin      #
10500acee513Smistachkin      set escapes [list \
1051f21979dfSmistachkin          \a \\a \b \\b \t \\t \n \\n \v \\v \f \\f \r \\r \
10520acee513Smistachkin          " " "\" \"" \" \\\" ' \"'\" \\ \\\\]
10530acee513Smistachkin    } else {
10540acee513Smistachkin      #
10550acee513Smistachkin      # NOTE: On Unix, we need to escape most of the whitespace characters
10560acee513Smistachkin      #       and those with special meaning to the SQLite shell itself.
10570acee513Smistachkin      #       The alarm (\a), backspace (\b), and carriage-return (\r)
10580acee513Smistachkin      #       characters do not appear to require escaping on Unix.  For
10590acee513Smistachkin      #       the alarm and backspace characters, this is probably due to
10600acee513Smistachkin      #       differences in the command shell.  For the carriage-return,
10610acee513Smistachkin      #       it is probably due to differences in how Tcl handles command
10620acee513Smistachkin      #       channel end-of-line translations.
10630acee513Smistachkin      #
10640acee513Smistachkin      set escapes [list \
10650acee513Smistachkin          \t \\t \n \\n \v \\v \f \\f \
10660acee513Smistachkin          " " "\" \"" \" \\\" ' \"'\" \\ \\\\]
10670acee513Smistachkin    }
10680acee513Smistachkin    set char [string map $escapes $char]
1069bfefa4c2Smistachkin    set x [catchcmdex test.db ".print $char\n"]
1070f21979dfSmistachkin    set code [lindex $x 0]
1071f21979dfSmistachkin    set res [lindex $x 1]
1072f21979dfSmistachkin    if {$code ne "0"} {
1073f21979dfSmistachkin      error "failed with error: $res"
1074f21979dfSmistachkin    }
1075f21979dfSmistachkin    if {$res ne "$oldChar\n"} {
107648dcf2b6Smistachkin      if {[llength $res] > 0} {
107748dcf2b6Smistachkin        set got [format %02X [scan $res %c]]
107848dcf2b6Smistachkin      } else {
107948dcf2b6Smistachkin        set got <empty>
108048dcf2b6Smistachkin      }
108148dcf2b6Smistachkin      error "failed with byte $hex mismatch, got $got"
1082f21979dfSmistachkin    }
1083f21979dfSmistachkin  }
10841fe36bb8Smistachkin} {}
10851fe36bb8Smistachkin
1086697c9eaaSdrh# These test cases do not work on MinGW
1087697c9eaaSdrhif 0 {
1088697c9eaaSdrh
108949e1125bSmistachkin# The string used here is the word "test" in Chinese.
10901fe36bb8Smistachkin# In UTF-8, it is encoded as: \xE6\xB5\x8B\xE8\xAF\x95
109149e1125bSmistachkinset test \u6D4B\u8BD5
109249e1125bSmistachkin
109349e1125bSmistachkindo_test shell1-6.0 {
109449e1125bSmistachkin  set fileName $test; append fileName .db
109549e1125bSmistachkin  catch {forcedelete $fileName}
10961fe36bb8Smistachkin  set x [catchcmdex $fileName "CREATE TABLE t1(x);\n.schema\n"]
10971fe36bb8Smistachkin  set code [lindex $x 0]
10981fe36bb8Smistachkin  set res [string trim [lindex $x 1]]
10991fe36bb8Smistachkin  if {$code ne "0"} {
11001fe36bb8Smistachkin    error "failed with error: $res"
11011fe36bb8Smistachkin  }
11021fe36bb8Smistachkin  if {$res ne "CREATE TABLE t1(x);"} {
11031fe36bb8Smistachkin    error "failed with mismatch: $res"
11041fe36bb8Smistachkin  }
11051fe36bb8Smistachkin  if {![file exists $fileName]} {
11061810f228Smistachkin    error "file \"$fileName\" (Unicode) does not exist"
11071fe36bb8Smistachkin  }
11081fe36bb8Smistachkin  forcedelete $fileName
1109f21979dfSmistachkin} {}
1110f21979dfSmistachkin
111149e1125bSmistachkindo_test shell1-6.1 {
111249e1125bSmistachkin  catch {forcedelete test3.db}
111349e1125bSmistachkin  set x [catchcmdex test3.db \
111449e1125bSmistachkin      "CREATE TABLE [encoding convertto utf-8 $test](x);\n.schema\n"]
111549e1125bSmistachkin  set code [lindex $x 0]
111649e1125bSmistachkin  set res [string trim [lindex $x 1]]
111749e1125bSmistachkin  if {$code ne "0"} {
111849e1125bSmistachkin    error "failed with error: $res"
111949e1125bSmistachkin  }
112049e1125bSmistachkin  if {$res ne "CREATE TABLE ${test}(x);"} {
112149e1125bSmistachkin    error "failed with mismatch: $res"
112249e1125bSmistachkin  }
112349e1125bSmistachkin  forcedelete test3.db
112449e1125bSmistachkin} {}
1125697c9eaaSdrh}
112649e1125bSmistachkin
11279d107262Smistachkindb close
11289d107262Smistachkinforcedelete test.db test.db-journal test.db-wal
11299d107262Smistachkinsqlite3 db test.db
11309d107262Smistachkin
113107f119e4Sdan# The shell tool ".schema" command uses virtual table "pragma_database_list"
113207f119e4Sdan#
113307f119e4Sdanifcapable vtab {
113407f119e4Sdan
11359d107262Smistachkindo_test shell1-7.1.1 {
11369d107262Smistachkin  db eval {
11379d107262Smistachkin    CREATE TABLE Z (x TEXT PRIMARY KEY);
11389d107262Smistachkin    CREATE TABLE _ (x TEXT PRIMARY KEY);
11399d107262Smistachkin    CREATE TABLE YY (x TEXT PRIMARY KEY);
11409d107262Smistachkin    CREATE TABLE __ (x TEXT PRIMARY KEY);
11419d107262Smistachkin    CREATE TABLE WWW (x TEXT PRIMARY KEY);
11429d107262Smistachkin    CREATE TABLE ___ (x TEXT PRIMARY KEY);
11439d107262Smistachkin  }
11449d107262Smistachkin} {}
11459d107262Smistachkindo_test shell1-7.1.2 {
11469d107262Smistachkin  catchcmd "test.db" ".schema _"
11479d107262Smistachkin} {0 {CREATE TABLE Z (x TEXT PRIMARY KEY);
11489d107262SmistachkinCREATE TABLE _ (x TEXT PRIMARY KEY);}}
11499d107262Smistachkindo_test shell1-7.1.3 {
11509d107262Smistachkin  catchcmd "test.db" ".schema \\\\_"
11519d107262Smistachkin} {0 {CREATE TABLE _ (x TEXT PRIMARY KEY);}}
11529d107262Smistachkindo_test shell1-7.1.4 {
11539d107262Smistachkin  catchcmd "test.db" ".schema __"
11549d107262Smistachkin} {0 {CREATE TABLE YY (x TEXT PRIMARY KEY);
11559d107262SmistachkinCREATE TABLE __ (x TEXT PRIMARY KEY);}}
11569d107262Smistachkindo_test shell1-7.1.5 {
11579d107262Smistachkin  catchcmd "test.db" ".schema \\\\_\\\\_"
11589d107262Smistachkin} {0 {CREATE TABLE __ (x TEXT PRIMARY KEY);}}
11599d107262Smistachkindo_test shell1-7.1.6 {
11609d107262Smistachkin  catchcmd "test.db" ".schema ___"
11619d107262Smistachkin} {0 {CREATE TABLE WWW (x TEXT PRIMARY KEY);
11629d107262SmistachkinCREATE TABLE ___ (x TEXT PRIMARY KEY);}}
11639d107262Smistachkindo_test shell1-7.1.7 {
11649d107262Smistachkin  catchcmd "test.db" ".schema \\\\_\\\\_\\\\_"
11659d107262Smistachkin} {0 {CREATE TABLE ___ (x TEXT PRIMARY KEY);}}
11669d107262Smistachkin
116707f119e4Sdan}
116807f119e4Sdan
11694dfdb86cSdrh# Test case for the ieee754 and decimal extensions in the shell.
11704dfdb86cSdrh# See the "floatingpoint.html" file in the documentation for more
11714dfdb86cSdrh# information.
11724dfdb86cSdrh#
11734dfdb86cSdrhdo_test shell1-8.1 {
11744dfdb86cSdrh  catchcmd ":memory:" {
11754dfdb86cSdrh    -- The pow2 table will hold all the necessary powers of two.
11764dfdb86cSdrh    CREATE TABLE pow2(x INTEGER PRIMARY KEY, v TEXT);
11774dfdb86cSdrh    WITH RECURSIVE c(x,v) AS (
11784dfdb86cSdrh      VALUES(0,'1')
11794dfdb86cSdrh      UNION ALL
11804dfdb86cSdrh      SELECT x+1, decimal_mul(v,'2') FROM c WHERE x+1<=971
11814dfdb86cSdrh    ) INSERT INTO pow2(x,v) SELECT x, v FROM c;
11824dfdb86cSdrh    WITH RECURSIVE c(x,v) AS (
11834dfdb86cSdrh      VALUES(-1,'0.5')
11844dfdb86cSdrh      UNION ALL
11854dfdb86cSdrh      SELECT x-1, decimal_mul(v,'0.5') FROM c WHERE x-1>=-1075
11864dfdb86cSdrh    ) INSERT INTO pow2(x,v) SELECT x, v FROM c;
11874dfdb86cSdrh
11884dfdb86cSdrh    -- This query finds the decimal representation of each value in the "c" table.
11894dfdb86cSdrh    WITH c(n) AS (VALUES(47.49))
11904dfdb86cSdrh                     ----XXXXX----------- Replace with whatever you want
11914dfdb86cSdrh    SELECT decimal_mul(ieee754_mantissa(c.n),pow2.v)
11924dfdb86cSdrh      FROM pow2, c WHERE pow2.x=ieee754_exponent(c.n);
11934dfdb86cSdrh  }
11944dfdb86cSdrh} {0 47.49000000000000198951966012828052043914794921875}
11954dfdb86cSdrhdo_test shell1-8.2 {
11964dfdb86cSdrh  catchcmd :memory: {
11974dfdb86cSdrh.mode box
11984dfdb86cSdrhSELECT ieee754(47.49) AS x;
11994dfdb86cSdrh  }
12004dfdb86cSdrh} {0 {┌───────────────────────────────┐
12014dfdb86cSdrh│               x               │
12024dfdb86cSdrh├───────────────────────────────┤
12034dfdb86cSdrh│ ieee754(6683623321994527,-47) │
12044dfdb86cSdrh└───────────────────────────────┘}}
12054dfdb86cSdrhdo_test shell1-8.3 {
12064dfdb86cSdrh  catchcmd ":memory: --box" {
12074dfdb86cSdrh    select ieee754(6683623321994527,-47) as x;
12084dfdb86cSdrh  }
12094dfdb86cSdrh} {0 {┌───────┐
12104dfdb86cSdrh│   x   │
12114dfdb86cSdrh├───────┤
12124dfdb86cSdrh│ 47.49 │
12134dfdb86cSdrh└───────┘}}
12144dfdb86cSdrhdo_test shell1-8.4 {
12154dfdb86cSdrh  catchcmd ":memory: --table" {SELECT ieee754_mantissa(47.49) AS M, ieee754_exponent(47.49) AS E;}
12164dfdb86cSdrh} {0 {+------------------+-----+
12174dfdb86cSdrh|        M         |  E  |
12184dfdb86cSdrh+------------------+-----+
12194dfdb86cSdrh| 6683623321994527 | -47 |
12204dfdb86cSdrh+------------------+-----+}}
12214dfdb86cSdrh
12228df9185cSdrhfinish_test
1223