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. 21d797d6b6Slarrybr# shell1-{4-8}.*: Test various "dot" commands's functionality. 22d797d6b6Slarrybr# shell1-9.*: Basic test that "dot" commands and SQL intermix ok. 238df9185cSdrh# 248df9185cSdrhset testdir [file dirname $argv0] 258df9185cSdrhsource $testdir/tester.tcl 26089555c8Sdanset CLI [test_cli_invocation] 278df9185cSdrhdb close 288df9185cSdrhforcedelete test.db test.db-journal test.db-wal 298df9185cSdrhsqlite3 db test.db 308df9185cSdrh 318df9185cSdrh#---------------------------------------------------------------------------- 328df9185cSdrh# Test cases shell1-1.*: Basic command line option handling. 338df9185cSdrh# 348df9185cSdrh 358df9185cSdrh# invalid option 368df9185cSdrhdo_test shell1-1.1.1 { 378df9185cSdrh set res [catchcmd "-bad test.db" ""] 388df9185cSdrh set rc [lindex $res 0] 398df9185cSdrh list $rc \ 408df9185cSdrh [regexp {Error: unknown option: -bad} $res] 418df9185cSdrh} {1 1} 42ac5649a9Sdrhdo_test shell1-1.1.1b { 43ac5649a9Sdrh set res [catchcmd "test.db -bad" ""] 44ac5649a9Sdrh set rc [lindex $res 0] 45ac5649a9Sdrh list $rc \ 46ac5649a9Sdrh [regexp {Error: unknown option: -bad} $res] 47ac5649a9Sdrh} {1 1} 488df9185cSdrh# error on extra options 498df9185cSdrhdo_test shell1-1.1.2 { 5060c4249fSdrh catchcmd "test.db \"select+3\" \"select+4\"" "" 51ac5649a9Sdrh} {0 {3 52ac5649a9Sdrh4}} 538df9185cSdrh# error on extra options 548df9185cSdrhdo_test shell1-1.1.3 { 55ac5649a9Sdrh catchcmd "test.db FOO test.db BAD" ".quit" 56633c7982Sdrh} {/1 .Error: in prepare, near "FOO": syntax error*/} 578df9185cSdrh 588df9185cSdrh# -help 598df9185cSdrhdo_test shell1-1.2.1 { 608df9185cSdrh set res [catchcmd "-help test.db" ""] 618df9185cSdrh set rc [lindex $res 0] 628df9185cSdrh list $rc \ 638df9185cSdrh [regexp {Usage} $res] \ 648df9185cSdrh [regexp {\-init} $res] \ 658df9185cSdrh [regexp {\-version} $res] 668df9185cSdrh} {1 1 1 1} 678df9185cSdrh 688df9185cSdrh# -init filename read/process named file 69b7c46aa8Sdrhforcedelete FOO 70b7c46aa8Sdrhset out [open FOO w] 71b7c46aa8Sdrhputs $out "" 72b7c46aa8Sdrhclose $out 738df9185cSdrhdo_test shell1-1.3.1 { 748df9185cSdrh catchcmd "-init FOO test.db" "" 758df9185cSdrh} {0 {}} 768df9185cSdrhdo_test shell1-1.3.2 { 77ac5649a9Sdrh catchcmd "-init FOO test.db .quit BAD" "" 78ac5649a9Sdrh} {0 {}} 79ac5649a9Sdrhdo_test shell1-1.3.3 { 80ac5649a9Sdrh catchcmd "-init FOO test.db BAD .quit" "" 81633c7982Sdrh} {/1 .Error: in prepare, near "BAD": syntax error*/} 828df9185cSdrh 838df9185cSdrh# -echo print commands before execution 848df9185cSdrhdo_test shell1-1.4.1 { 858df9185cSdrh catchcmd "-echo test.db" "" 868df9185cSdrh} {0 {}} 878df9185cSdrh 888df9185cSdrh# -[no]header turn headers on or off 898df9185cSdrhdo_test shell1-1.5.1 { 908df9185cSdrh catchcmd "-header test.db" "" 918df9185cSdrh} {0 {}} 928df9185cSdrhdo_test shell1-1.5.2 { 938df9185cSdrh catchcmd "-noheader test.db" "" 948df9185cSdrh} {0 {}} 958df9185cSdrh 968df9185cSdrh# -bail stop after hitting an error 978df9185cSdrhdo_test shell1-1.6.1 { 988df9185cSdrh catchcmd "-bail test.db" "" 998df9185cSdrh} {0 {}} 1008df9185cSdrh 1018df9185cSdrh# -interactive force interactive I/O 1028df9185cSdrhdo_test shell1-1.7.1 { 1038df9185cSdrh set res [catchcmd "-interactive test.db" ".quit"] 1048df9185cSdrh set rc [lindex $res 0] 1058df9185cSdrh list $rc \ 1068df9185cSdrh [regexp {SQLite version} $res] \ 10739a3088dSdrh [regexp {Enter ".help" for usage hints} $res] 1088df9185cSdrh} {0 1 1} 1098df9185cSdrh 1108df9185cSdrh# -batch force batch I/O 1118df9185cSdrhdo_test shell1-1.8.1 { 1128df9185cSdrh catchcmd "-batch test.db" "" 1138df9185cSdrh} {0 {}} 1148df9185cSdrh 1158df9185cSdrh# -column set output mode to 'column' 1168df9185cSdrhdo_test shell1-1.9.1 { 1178df9185cSdrh catchcmd "-column test.db" "" 1188df9185cSdrh} {0 {}} 1198df9185cSdrh 1208df9185cSdrh# -csv set output mode to 'csv' 1218df9185cSdrhdo_test shell1-1.10.1 { 1228df9185cSdrh catchcmd "-csv test.db" "" 1238df9185cSdrh} {0 {}} 1248df9185cSdrh 1258df9185cSdrh# -html set output mode to HTML 1268df9185cSdrhdo_test shell1-1.11.1 { 1278df9185cSdrh catchcmd "-html test.db" "" 1288df9185cSdrh} {0 {}} 1298df9185cSdrh 1308df9185cSdrh# -line set output mode to 'line' 1318df9185cSdrhdo_test shell1-1.12.1 { 1328df9185cSdrh catchcmd "-line test.db" "" 1338df9185cSdrh} {0 {}} 1348df9185cSdrh 1358df9185cSdrh# -list set output mode to 'list' 1368df9185cSdrhdo_test shell1-1.13.1 { 1378df9185cSdrh catchcmd "-list test.db" "" 1388df9185cSdrh} {0 {}} 1398df9185cSdrh 1408df9185cSdrh# -separator 'x' set output field separator (|) 1418df9185cSdrhdo_test shell1-1.14.1 { 1428df9185cSdrh catchcmd "-separator 'x' test.db" "" 1438df9185cSdrh} {0 {}} 1448df9185cSdrhdo_test shell1-1.14.2 { 1458df9185cSdrh catchcmd "-separator x test.db" "" 1468df9185cSdrh} {0 {}} 1478df9185cSdrhdo_test shell1-1.14.3 { 1488df9185cSdrh set res [catchcmd "-separator" ""] 1498df9185cSdrh set rc [lindex $res 0] 1508df9185cSdrh list $rc \ 15198d312fcSdrh [regexp {Error: missing argument to -separator} $res] 1528df9185cSdrh} {1 1} 1538df9185cSdrh 1548df9185cSdrh# -stats print memory stats before each finalize 1558df9185cSdrhdo_test shell1-1.14b.1 { 1568df9185cSdrh catchcmd "-stats test.db" "" 1578df9185cSdrh} {0 {}} 1588df9185cSdrh 1598df9185cSdrh# -nullvalue 'text' set text string for NULL values 1608df9185cSdrhdo_test shell1-1.15.1 { 1618df9185cSdrh catchcmd "-nullvalue 'x' test.db" "" 1628df9185cSdrh} {0 {}} 1638df9185cSdrhdo_test shell1-1.15.2 { 1648df9185cSdrh catchcmd "-nullvalue x test.db" "" 1658df9185cSdrh} {0 {}} 1668df9185cSdrhdo_test shell1-1.15.3 { 1678df9185cSdrh set res [catchcmd "-nullvalue" ""] 1688df9185cSdrh set rc [lindex $res 0] 1698df9185cSdrh list $rc \ 17098d312fcSdrh [regexp {Error: missing argument to -nullvalue} $res] 1718df9185cSdrh} {1 1} 1728df9185cSdrh 1738df9185cSdrh# -version show SQLite version 1748df9185cSdrhdo_test shell1-1.16.1 { 1758df9185cSdrh set x [catchcmd "-version test.db" ""] 176b24c61a2Sdrh} {/3.[0-9.]+ 20\d\d-[01]\d-\d\d \d\d:\d\d:\d\d [0-9a-f]+/} 1778df9185cSdrh 1788df9185cSdrh#---------------------------------------------------------------------------- 1798df9185cSdrh# Test cases shell1-2.*: Basic "dot" command token parsing. 1808df9185cSdrh# 1818df9185cSdrh 1828df9185cSdrh# check first token handling 1838df9185cSdrhdo_test shell1-2.1.1 { 1848df9185cSdrh catchcmd "test.db" ".foo" 1858df9185cSdrh} {1 {Error: unknown command or invalid arguments: "foo". Enter ".help" for help}} 1868df9185cSdrhdo_test shell1-2.1.2 { 1878df9185cSdrh catchcmd "test.db" ".\"foo OFF\"" 1888df9185cSdrh} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}} 1898df9185cSdrhdo_test shell1-2.1.3 { 1908df9185cSdrh catchcmd "test.db" ".\'foo OFF\'" 1918df9185cSdrh} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}} 1928df9185cSdrh 1938df9185cSdrh# unbalanced quotes 1948df9185cSdrhdo_test shell1-2.2.1 { 1958df9185cSdrh catchcmd "test.db" ".\"foo OFF" 1968df9185cSdrh} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}} 1978df9185cSdrhdo_test shell1-2.2.2 { 1988df9185cSdrh catchcmd "test.db" ".\'foo OFF" 1998df9185cSdrh} {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}} 2008df9185cSdrhdo_test shell1-2.2.3 { 2018df9185cSdrh catchcmd "test.db" ".explain \"OFF" 2028df9185cSdrh} {0 {}} 2038df9185cSdrhdo_test shell1-2.2.4 { 2048df9185cSdrh catchcmd "test.db" ".explain \'OFF" 2058df9185cSdrh} {0 {}} 2068df9185cSdrhdo_test shell1-2.2.5 { 2078df9185cSdrh catchcmd "test.db" ".mode \"insert FOO" 208ca1776b5Sdrh} {1 {Error: mode should be one of: ascii box column csv html insert json line list markdown qbox quote table tabs tcl}} 2098df9185cSdrhdo_test shell1-2.2.6 { 2108df9185cSdrh catchcmd "test.db" ".mode \'insert FOO" 211ca1776b5Sdrh} {1 {Error: mode should be one of: ascii box column csv html insert json line list markdown qbox quote table tabs tcl}} 2128df9185cSdrh 2138df9185cSdrh# check multiple tokens, and quoted tokens 2148df9185cSdrhdo_test shell1-2.3.1 { 2158df9185cSdrh catchcmd "test.db" ".explain 1" 2168df9185cSdrh} {0 {}} 2178df9185cSdrhdo_test shell1-2.3.2 { 2188df9185cSdrh catchcmd "test.db" ".explain on" 2198df9185cSdrh} {0 {}} 2208df9185cSdrhdo_test shell1-2.3.3 { 2218df9185cSdrh catchcmd "test.db" ".explain \"1 2 3\"" 222173ba099Sdrh} {1 {ERROR: Not a boolean value: "1 2 3". Assuming "no".}} 2238df9185cSdrhdo_test shell1-2.3.4 { 2248df9185cSdrh catchcmd "test.db" ".explain \"OFF\"" 2258df9185cSdrh} {0 {}} 2268df9185cSdrhdo_test shell1-2.3.5 { 2278df9185cSdrh catchcmd "test.db" ".\'explain\' \'OFF\'" 2288df9185cSdrh} {0 {}} 2298df9185cSdrhdo_test shell1-2.3.6 { 2308df9185cSdrh catchcmd "test.db" ".explain \'OFF\'" 2318df9185cSdrh} {0 {}} 2328df9185cSdrhdo_test shell1-2.3.7 { 2338df9185cSdrh catchcmd "test.db" ".\'explain\' \'OFF\'" 2348df9185cSdrh} {0 {}} 2358df9185cSdrh 2368df9185cSdrh# check quoted args are unquoted 2378df9185cSdrhdo_test shell1-2.4.1 { 2388df9185cSdrh catchcmd "test.db" ".mode FOO" 239ca1776b5Sdrh} {1 {Error: mode should be one of: ascii box column csv html insert json line list markdown qbox quote table tabs tcl}} 2408df9185cSdrhdo_test shell1-2.4.2 { 2418df9185cSdrh catchcmd "test.db" ".mode csv" 2428df9185cSdrh} {0 {}} 2438df9185cSdrhdo_test shell1-2.4.2 { 2448df9185cSdrh catchcmd "test.db" ".mode \"csv\"" 2458df9185cSdrh} {0 {}} 2468df9185cSdrh 2478df9185cSdrh 2488df9185cSdrh#---------------------------------------------------------------------------- 2498df9185cSdrh# Test cases shell1-3.*: Basic test that "dot" command can be called. 2508df9185cSdrh# 2518df9185cSdrh 2528df9185cSdrh# .backup ?DB? FILE Backup DB (default "main") to FILE 2538df9185cSdrhdo_test shell1-3.1.1 { 2548df9185cSdrh catchcmd "test.db" ".backup" 255bc46f02cSdrh} {1 {missing FILENAME argument on .backup}} 256f82d78e9Sdrhforcedelete FOO 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" 2664d342827Sdrh} {1 {Usage: .backup ?DB? ?OPTIONS? FILENAME}} 2678df9185cSdrh 2688df9185cSdrh# .bail ON|OFF Stop after hitting an error. Default OFF 2698df9185cSdrhdo_test shell1-3.2.1 { 2708df9185cSdrh catchcmd "test.db" ".bail" 271c2ce0beaSdrh} {1 {Usage: .bail on|off}} 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" 281c2ce0beaSdrh} {1 {Usage: .bail on|off}} 2828df9185cSdrh 283c5954199Sdrhifcapable vtab { 2848df9185cSdrh# .databases List names and files of attached databases 2858df9185cSdrhdo_test shell1-3.3.1 { 286eaa544d4Sdrh catchcmd "-csv test.db" ".databases" 28715707ac9Sdrh} "/0.+main.+[string map {/ ".{1,2}"} [string range [get_pwd] 0 10]].*/" 2888df9185cSdrhdo_test shell1-3.3.2 { 289c2ce0beaSdrh # extra arguments ignored 290eaa544d4Sdrh catchcmd "test.db" ".databases BAD" 29115707ac9Sdrh} "/0.+main.+[string map {/ ".{1,2}"} [string range [get_pwd] 0 10]].*/" 292c5954199Sdrh} 2938df9185cSdrh 2948df9185cSdrh# .dump ?TABLE? ... Dump the database in an SQL text format 2958df9185cSdrh# If TABLE specified, only dump tables matching 2968df9185cSdrh# LIKE pattern TABLE. 2978df9185cSdrhdo_test shell1-3.4.1 { 2988df9185cSdrh set res [catchcmd "test.db" ".dump"] 2998df9185cSdrh list [regexp {BEGIN TRANSACTION;} $res] \ 3008df9185cSdrh [regexp {COMMIT;} $res] 3018df9185cSdrh} {1 1} 3028df9185cSdrhdo_test shell1-3.4.2 { 3038df9185cSdrh set res [catchcmd "test.db" ".dump FOO"] 3048df9185cSdrh list [regexp {BEGIN TRANSACTION;} $res] \ 3058df9185cSdrh [regexp {COMMIT;} $res] 3068df9185cSdrh} {1 1} 3078e9297fbSdrh# The .dump command now accepts multiple arguments 3088e9297fbSdrh#do_test shell1-3.4.3 { 3098e9297fbSdrh# # too many arguments 3108e9297fbSdrh# catchcmd "test.db" ".dump FOO BAD" 3118e9297fbSdrh#} {1 {Usage: .dump ?--preserve-rowids? ?--newlines? ?LIKE-PATTERN?}} 3128df9185cSdrh 3138df9185cSdrh# .echo ON|OFF Turn command echo on or off 3148df9185cSdrhdo_test shell1-3.5.1 { 3158df9185cSdrh catchcmd "test.db" ".echo" 316*527c39deSlarrybr} {1 {Usage: .echo on|off}} 3178df9185cSdrhdo_test shell1-3.5.2 { 3188df9185cSdrh catchcmd "test.db" ".echo ON" 3198df9185cSdrh} {0 {}} 3208df9185cSdrhdo_test shell1-3.5.3 { 3218df9185cSdrh catchcmd "test.db" ".echo OFF" 3228df9185cSdrh} {0 {}} 3238df9185cSdrhdo_test shell1-3.5.4 { 3248df9185cSdrh # too many arguments 3258df9185cSdrh catchcmd "test.db" ".echo OFF BAD" 326*527c39deSlarrybr} {1 {Usage: .echo on|off}} 3278df9185cSdrh 3288df9185cSdrh# .exit Exit this program 3298df9185cSdrhdo_test shell1-3.6.1 { 3308df9185cSdrh catchcmd "test.db" ".exit" 3318df9185cSdrh} {0 {}} 3328df9185cSdrh 3338df9185cSdrh# .explain ON|OFF Turn output mode suitable for EXPLAIN on or off. 3348df9185cSdrhdo_test shell1-3.7.1 { 3358df9185cSdrh catchcmd "test.db" ".explain" 3368df9185cSdrh # explain is the exception to the booleans. without an option, it turns it on. 3378df9185cSdrh} {0 {}} 3388df9185cSdrhdo_test shell1-3.7.2 { 3398df9185cSdrh catchcmd "test.db" ".explain ON" 3408df9185cSdrh} {0 {}} 3418df9185cSdrhdo_test shell1-3.7.3 { 3428df9185cSdrh catchcmd "test.db" ".explain OFF" 3438df9185cSdrh} {0 {}} 3448df9185cSdrhdo_test shell1-3.7.4 { 345c2ce0beaSdrh # extra arguments ignored 3468df9185cSdrh catchcmd "test.db" ".explain OFF BAD" 347c2ce0beaSdrh} {0 {}} 3488df9185cSdrh 3498df9185cSdrh 3508df9185cSdrh# .header(s) ON|OFF Turn display of headers on or off 3518df9185cSdrhdo_test shell1-3.9.1 { 3528df9185cSdrh catchcmd "test.db" ".header" 353c2ce0beaSdrh} {1 {Usage: .headers on|off}} 3548df9185cSdrhdo_test shell1-3.9.2 { 3558df9185cSdrh catchcmd "test.db" ".header ON" 3568df9185cSdrh} {0 {}} 3578df9185cSdrhdo_test shell1-3.9.3 { 3588df9185cSdrh catchcmd "test.db" ".header OFF" 3598df9185cSdrh} {0 {}} 3608df9185cSdrhdo_test shell1-3.9.4 { 3618df9185cSdrh # too many arguments 3628df9185cSdrh catchcmd "test.db" ".header OFF BAD" 363c2ce0beaSdrh} {1 {Usage: .headers on|off}} 3648df9185cSdrh 3658df9185cSdrhdo_test shell1-3.9.5 { 3668df9185cSdrh catchcmd "test.db" ".headers" 367c2ce0beaSdrh} {1 {Usage: .headers on|off}} 3688df9185cSdrhdo_test shell1-3.9.6 { 3698df9185cSdrh catchcmd "test.db" ".headers ON" 3708df9185cSdrh} {0 {}} 3718df9185cSdrhdo_test shell1-3.9.7 { 3728df9185cSdrh catchcmd "test.db" ".headers OFF" 3738df9185cSdrh} {0 {}} 3748df9185cSdrhdo_test shell1-3.9.8 { 3758df9185cSdrh # too many arguments 3768df9185cSdrh catchcmd "test.db" ".headers OFF BAD" 377c2ce0beaSdrh} {1 {Usage: .headers on|off}} 3788df9185cSdrh 3798df9185cSdrh# .help Show this message 3808df9185cSdrhdo_test shell1-3.10.1 { 3818df9185cSdrh set res [catchcmd "test.db" ".help"] 3828df9185cSdrh # look for a few of the possible help commands 3838df9185cSdrh list [regexp {.help} $res] \ 3848df9185cSdrh [regexp {.quit} $res] \ 3858df9185cSdrh [regexp {.show} $res] 3868df9185cSdrh} {1 1 1} 3878df9185cSdrhdo_test shell1-3.10.2 { 3888df9185cSdrh # we allow .help to take extra args (it is help after all) 38998aa2abcSdrh set res [catchcmd "test.db" ".help *"] 3908df9185cSdrh # look for a few of the possible help commands 3918df9185cSdrh list [regexp {.help} $res] \ 3928df9185cSdrh [regexp {.quit} $res] \ 3938df9185cSdrh [regexp {.show} $res] 3948df9185cSdrh} {1 1 1} 3958df9185cSdrh 3968df9185cSdrh# .import FILE TABLE Import data from FILE into TABLE 3978df9185cSdrhdo_test shell1-3.11.1 { 3988df9185cSdrh catchcmd "test.db" ".import" 399ccb37816Sdrh} {/1 .ERROR: missing FILE argument.*/} 4008df9185cSdrhdo_test shell1-3.11.2 { 4018df9185cSdrh catchcmd "test.db" ".import FOO" 402ccb37816Sdrh} {/1 .ERROR: missing TABLE argument.*/} 4038df9185cSdrhdo_test shell1-3.11.3 { 4048df9185cSdrh # too many arguments 4058df9185cSdrh catchcmd "test.db" ".import FOO BAR BAD" 406ccb37816Sdrh} {/1 .ERROR: extra argument: "BAD".*./} 4078df9185cSdrh 4080e55db1cSdrh# .indexes ?TABLE? Show names of all indexes 4090e55db1cSdrh# If TABLE specified, only show indexes for tables 4108df9185cSdrh# matching LIKE pattern TABLE. 4118df9185cSdrhdo_test shell1-3.12.1 { 4120e55db1cSdrh catchcmd "test.db" ".indexes" 4138df9185cSdrh} {0 {}} 4148df9185cSdrhdo_test shell1-3.12.2 { 4150e55db1cSdrh catchcmd "test.db" ".indexes FOO" 4160e55db1cSdrh} {0 {}} 4170e55db1cSdrhdo_test shell1-3.12.2-legacy { 4188df9185cSdrh catchcmd "test.db" ".indices FOO" 4198df9185cSdrh} {0 {}} 4208df9185cSdrhdo_test shell1-3.12.3 { 4218df9185cSdrh # too many arguments 4220e55db1cSdrh catchcmd "test.db" ".indexes FOO BAD" 4230e55db1cSdrh} {1 {Usage: .indexes ?LIKE-PATTERN?}} 4248df9185cSdrh 4258df9185cSdrh# .mode MODE ?TABLE? Set output mode where MODE is one of: 426e0d6885fSmistachkin# ascii Columns/rows delimited by 0x1F and 0x1E 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 432e0d6885fSmistachkin# list Values delimited by .separator strings 4338df9185cSdrh# tabs Tab-separated values 4348df9185cSdrh# tcl TCL list elements 4358df9185cSdrhdo_test shell1-3.13.1 { 4368df9185cSdrh catchcmd "test.db" ".mode" 437a501f7daSdrh} {0 {current output mode: list}} 4388df9185cSdrhdo_test shell1-3.13.2 { 4398df9185cSdrh catchcmd "test.db" ".mode FOO" 440ca1776b5Sdrh} {1 {Error: mode should be one of: ascii box column csv html insert json line list markdown qbox quote table 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 { 466c2ce0beaSdrh # extra arguments ignored 4678df9185cSdrh catchcmd "test.db" ".mode tcl BAD" 468c2ce0beaSdrh} {0 {}} 4698df9185cSdrh 4708df9185cSdrh# .nullvalue STRING Print STRING in place of NULL values 4718df9185cSdrhdo_test shell1-3.14.1 { 4728df9185cSdrh catchcmd "test.db" ".nullvalue" 473c2ce0beaSdrh} {1 {Usage: .nullvalue STRING}} 4748df9185cSdrhdo_test shell1-3.14.2 { 4758df9185cSdrh catchcmd "test.db" ".nullvalue FOO" 4768df9185cSdrh} {0 {}} 4778df9185cSdrhdo_test shell1-3.14.3 { 4788df9185cSdrh # too many arguments 4798df9185cSdrh catchcmd "test.db" ".nullvalue FOO BAD" 480c2ce0beaSdrh} {1 {Usage: .nullvalue STRING}} 4818df9185cSdrh 4828df9185cSdrh# .output FILENAME Send output to FILENAME 4838df9185cSdrhdo_test shell1-3.15.1 { 4848df9185cSdrh catchcmd "test.db" ".output" 485c2ce0beaSdrh} {0 {}} 4868df9185cSdrhdo_test shell1-3.15.2 { 4878df9185cSdrh catchcmd "test.db" ".output FOO" 4888df9185cSdrh} {0 {}} 4898df9185cSdrhdo_test shell1-3.15.3 { 4908df9185cSdrh # too many arguments 4918df9185cSdrh catchcmd "test.db" ".output FOO BAD" 492541ef2c3Sdrh} {1 {ERROR: extra parameter: "BAD". Usage: 493541ef2c3Sdrh.output ?FILE? Send output to FILE or stdout if FILE is omitted 494541ef2c3Sdrh If FILE begins with '|' then open it as a pipe. 495541ef2c3Sdrh Options: 496541ef2c3Sdrh --bom Prefix output with a UTF8 byte-order mark 497541ef2c3Sdrh -e Send output to the system text editor 498541ef2c3Sdrh -x Send output as CSV to a spreadsheet 499541ef2c3Sdrhchild process exited abnormally}} 5008df9185cSdrh 5018df9185cSdrh# .output stdout Send output to the screen 5028df9185cSdrhdo_test shell1-3.16.1 { 5038df9185cSdrh catchcmd "test.db" ".output stdout" 5048df9185cSdrh} {0 {}} 5058df9185cSdrhdo_test shell1-3.16.2 { 5068df9185cSdrh # too many arguments 5078df9185cSdrh catchcmd "test.db" ".output stdout BAD" 508541ef2c3Sdrh} {1 {ERROR: extra parameter: "BAD". Usage: 509541ef2c3Sdrh.output ?FILE? Send output to FILE or stdout if FILE is omitted 510541ef2c3Sdrh If FILE begins with '|' then open it as a pipe. 511541ef2c3Sdrh Options: 512541ef2c3Sdrh --bom Prefix output with a UTF8 byte-order mark 513541ef2c3Sdrh -e Send output to the system text editor 514541ef2c3Sdrh -x Send output as CSV to a spreadsheet 515541ef2c3Sdrhchild process exited abnormally}} 5168df9185cSdrh 5178df9185cSdrh# .prompt MAIN CONTINUE Replace the standard prompts 5188df9185cSdrhdo_test shell1-3.17.1 { 5198df9185cSdrh catchcmd "test.db" ".prompt" 520c2ce0beaSdrh} {0 {}} 5218df9185cSdrhdo_test shell1-3.17.2 { 5228df9185cSdrh catchcmd "test.db" ".prompt FOO" 5238df9185cSdrh} {0 {}} 5248df9185cSdrhdo_test shell1-3.17.3 { 5258df9185cSdrh catchcmd "test.db" ".prompt FOO BAR" 5268df9185cSdrh} {0 {}} 5278df9185cSdrhdo_test shell1-3.17.4 { 5288df9185cSdrh # too many arguments 5298df9185cSdrh catchcmd "test.db" ".prompt FOO BAR BAD" 530c2ce0beaSdrh} {0 {}} 5318df9185cSdrh 5328df9185cSdrh# .quit Exit this program 5338df9185cSdrhdo_test shell1-3.18.1 { 5348df9185cSdrh catchcmd "test.db" ".quit" 5358df9185cSdrh} {0 {}} 5368df9185cSdrhdo_test shell1-3.18.2 { 5378df9185cSdrh # too many arguments 5388df9185cSdrh catchcmd "test.db" ".quit BAD" 539c2ce0beaSdrh} {0 {}} 5408df9185cSdrh 5418df9185cSdrh# .read FILENAME Execute SQL in FILENAME 5428df9185cSdrhdo_test shell1-3.19.1 { 5438df9185cSdrh catchcmd "test.db" ".read" 544c2ce0beaSdrh} {1 {Usage: .read FILE}} 5458df9185cSdrhdo_test shell1-3.19.2 { 5469ac99313Smistachkin forcedelete FOO 5478df9185cSdrh catchcmd "test.db" ".read FOO" 5488df9185cSdrh} {1 {Error: cannot open "FOO"}} 5498df9185cSdrhdo_test shell1-3.19.3 { 5508df9185cSdrh # too many arguments 5518df9185cSdrh catchcmd "test.db" ".read FOO BAD" 552c2ce0beaSdrh} {1 {Usage: .read FILE}} 5538df9185cSdrh 5548df9185cSdrh# .restore ?DB? FILE Restore content of DB (default "main") from FILE 5558df9185cSdrhdo_test shell1-3.20.1 { 5568df9185cSdrh catchcmd "test.db" ".restore" 557c2ce0beaSdrh} {1 {Usage: .restore ?DB? FILE}} 5588df9185cSdrhdo_test shell1-3.20.2 { 5598df9185cSdrh catchcmd "test.db" ".restore FOO" 5608df9185cSdrh} {0 {}} 5618df9185cSdrhdo_test shell1-3.20.3 { 5628df9185cSdrh catchcmd "test.db" ".restore FOO BAR" 5638df9185cSdrh} {1 {Error: unknown database FOO}} 5648df9185cSdrhdo_test shell1-3.20.4 { 5658df9185cSdrh # too many arguments 5668df9185cSdrh catchcmd "test.db" ".restore FOO BAR BAD" 567c2ce0beaSdrh} {1 {Usage: .restore ?DB? FILE}} 5688df9185cSdrh 569a22dd386Sdrhifcapable vtab { 5708df9185cSdrh# .schema ?TABLE? Show the CREATE statements 5718df9185cSdrh# If TABLE specified, only show tables matching 5728df9185cSdrh# LIKE pattern TABLE. 5738df9185cSdrhdo_test shell1-3.21.1 { 5748df9185cSdrh catchcmd "test.db" ".schema" 5758df9185cSdrh} {0 {}} 5768df9185cSdrhdo_test shell1-3.21.2 { 5778df9185cSdrh catchcmd "test.db" ".schema FOO" 5788df9185cSdrh} {0 {}} 5798df9185cSdrhdo_test shell1-3.21.3 { 5808df9185cSdrh # too many arguments 5818df9185cSdrh catchcmd "test.db" ".schema FOO BAD" 582bbb29ecfSdrh} {1 {Usage: .schema ?--indent? ?--nosys? ?LIKE-PATTERN?}} 5838df9185cSdrh 584ac43e98dSdrhdo_test shell1-3.21.4 { 585ac43e98dSdrh catchcmd "test.db" { 586ac43e98dSdrh CREATE TABLE t1(x); 587ac43e98dSdrh CREATE VIEW v2 AS SELECT x+1 AS y FROM t1; 588ac43e98dSdrh CREATE VIEW v1 AS SELECT y+1 FROM v2; 589ac43e98dSdrh } 590ac43e98dSdrh catchcmd "test.db" ".schema" 591ac43e98dSdrh} {0 {CREATE TABLE t1(x); 592ceba792aSdrhCREATE VIEW v2 AS SELECT x+1 AS y FROM t1 5931d315cf7Sdrh/* v2(y) */; 594ceba792aSdrhCREATE VIEW v1 AS SELECT y+1 FROM v2 5951d315cf7Sdrh/* v1("y+1") */;}} 5964c5c6214Slarrybr 5974c5c6214Slarrybr catch {db eval {DROP VIEW v1; DROP VIEW v2; DROP TABLE t1;}} 598a22dd386Sdrh} 599ac43e98dSdrh 600636bf9f7Smistachkin# .separator STRING Change column separator used by output and .import 6018df9185cSdrhdo_test shell1-3.22.1 { 6028df9185cSdrh catchcmd "test.db" ".separator" 603e0d6885fSmistachkin} {1 {Usage: .separator COL ?ROW?}} 6048df9185cSdrhdo_test shell1-3.22.2 { 6058df9185cSdrh catchcmd "test.db" ".separator FOO" 6068df9185cSdrh} {0 {}} 6078df9185cSdrhdo_test shell1-3.22.3 { 6086976c212Sdrh catchcmd "test.db" ".separator ABC XYZ" 6096976c212Sdrh} {0 {}} 6106976c212Sdrhdo_test shell1-3.22.4 { 6118df9185cSdrh # too many arguments 6126976c212Sdrh catchcmd "test.db" ".separator FOO BAD BAD2" 613e0d6885fSmistachkin} {1 {Usage: .separator COL ?ROW?}} 6148df9185cSdrh 6158df9185cSdrh# .show Show the current values for various settings 6168df9185cSdrhdo_test shell1-3.23.1 { 6178df9185cSdrh set res [catchcmd "test.db" ".show"] 6188df9185cSdrh list [regexp {echo:} $res] \ 6198df9185cSdrh [regexp {explain:} $res] \ 6208df9185cSdrh [regexp {headers:} $res] \ 6218df9185cSdrh [regexp {mode:} $res] \ 6228df9185cSdrh [regexp {nullvalue:} $res] \ 6238df9185cSdrh [regexp {output:} $res] \ 624636bf9f7Smistachkin [regexp {colseparator:} $res] \ 625636bf9f7Smistachkin [regexp {rowseparator:} $res] \ 6268df9185cSdrh [regexp {stats:} $res] \ 6278df9185cSdrh [regexp {width:} $res] 628e0d6885fSmistachkin} {1 1 1 1 1 1 1 1 1 1} 6298df9185cSdrhdo_test shell1-3.23.2 { 6308df9185cSdrh # too many arguments 6318df9185cSdrh catchcmd "test.db" ".show BAD" 632c2ce0beaSdrh} {1 {Usage: .show}} 6338df9185cSdrh 6348df9185cSdrh# .stats ON|OFF Turn stats on or off 63534784903Sdrh#do_test shell1-3.23b.1 { 63634784903Sdrh# catchcmd "test.db" ".stats" 637a6e6cf2cSdrh#} {1 {Usage: .stats on|off|stmt|vmstep}} 6388df9185cSdrhdo_test shell1-3.23b.2 { 6398df9185cSdrh catchcmd "test.db" ".stats ON" 6408df9185cSdrh} {0 {}} 6418df9185cSdrhdo_test shell1-3.23b.3 { 6428df9185cSdrh catchcmd "test.db" ".stats OFF" 6438df9185cSdrh} {0 {}} 6448df9185cSdrhdo_test shell1-3.23b.4 { 6458df9185cSdrh # too many arguments 6468df9185cSdrh catchcmd "test.db" ".stats OFF BAD" 647a6e6cf2cSdrh} {1 {Usage: .stats ?on|off|stmt|vmstep?}} 6488df9185cSdrh 6493c49eaf4Sdrh# Ticket 7be932dfa60a8a6b3b26bcf7623ec46e0a403ddb 2018-06-07 6503c49eaf4Sdrh# Adverse interaction between .stats and .eqp 6513c49eaf4Sdrh# 6523c49eaf4Sdrhdo_test shell1-3.23b.5 { 6533c49eaf4Sdrh catchcmd "test.db" [string map {"\n " "\n"} { 6543c49eaf4Sdrh CREATE TEMP TABLE t1(x); 6553c49eaf4Sdrh INSERT INTO t1 VALUES(1),(2); 6563c49eaf4Sdrh .stats on 6573c49eaf4Sdrh .eqp full 6583c49eaf4Sdrh SELECT * FROM t1; 6593c49eaf4Sdrh }] 6603c49eaf4Sdrh} {/1\n2\n/} 6613c49eaf4Sdrh 6628df9185cSdrh# .tables ?TABLE? List names of tables 6638df9185cSdrh# If TABLE specified, only list tables matching 6648df9185cSdrh# LIKE pattern TABLE. 6658df9185cSdrhdo_test shell1-3.24.1 { 6668df9185cSdrh catchcmd "test.db" ".tables" 6678df9185cSdrh} {0 {}} 6688df9185cSdrhdo_test shell1-3.24.2 { 6698df9185cSdrh catchcmd "test.db" ".tables FOO" 6708df9185cSdrh} {0 {}} 6718df9185cSdrhdo_test shell1-3.24.3 { 6728df9185cSdrh # too many arguments 6738df9185cSdrh catchcmd "test.db" ".tables FOO BAD" 674c2ce0beaSdrh} {0 {}} 6758df9185cSdrh 6768df9185cSdrh# .timeout MS Try opening locked tables for MS milliseconds 6778df9185cSdrhdo_test shell1-3.25.1 { 6788df9185cSdrh catchcmd "test.db" ".timeout" 679c2ce0beaSdrh} {0 {}} 6808df9185cSdrhdo_test shell1-3.25.2 { 6818df9185cSdrh catchcmd "test.db" ".timeout zzz" 6828df9185cSdrh # this should be treated the same as a '0' timeout 6838df9185cSdrh} {0 {}} 6848df9185cSdrhdo_test shell1-3.25.3 { 6858df9185cSdrh catchcmd "test.db" ".timeout 1" 6868df9185cSdrh} {0 {}} 6878df9185cSdrhdo_test shell1-3.25.4 { 6888df9185cSdrh # too many arguments 6898df9185cSdrh catchcmd "test.db" ".timeout 1 BAD" 690c2ce0beaSdrh} {0 {}} 6918df9185cSdrh 6928df9185cSdrh# .width NUM NUM ... Set column widths for "column" mode 6938df9185cSdrhdo_test shell1-3.26.1 { 6948df9185cSdrh catchcmd "test.db" ".width" 695c2ce0beaSdrh} {0 {}} 6968df9185cSdrhdo_test shell1-3.26.2 { 6978df9185cSdrh catchcmd "test.db" ".width xxx" 6988df9185cSdrh # this should be treated the same as a '0' width for col 1 6998df9185cSdrh} {0 {}} 7008df9185cSdrhdo_test shell1-3.26.3 { 7018df9185cSdrh catchcmd "test.db" ".width xxx yyy" 7028df9185cSdrh # this should be treated the same as a '0' width for col 1 and 2 7038df9185cSdrh} {0 {}} 7048df9185cSdrhdo_test shell1-3.26.4 { 7058df9185cSdrh catchcmd "test.db" ".width 1 1" 7068df9185cSdrh # this should be treated the same as a '1' width for col 1 and 2 7078df9185cSdrh} {0 {}} 708078b1fdaSdrhdo_test shell1-3.26.5 { 709c0605084Sdrh catchcmd "test.db" ".mode column\n.header off\n.width 10 -10\nSELECT 'abcdefg', 123456;" 710078b1fdaSdrh # this should be treated the same as a '1' width for col 1 and 2 711078b1fdaSdrh} {0 {abcdefg 123456}} 712078b1fdaSdrhdo_test shell1-3.26.6 { 713c0605084Sdrh catchcmd "test.db" ".mode column\n.header off\n.width -10 10\nSELECT 'abcdefg', 123456;" 714078b1fdaSdrh # this should be treated the same as a '1' width for col 1 and 2 715078b1fdaSdrh} {0 { abcdefg 123456 }} 716078b1fdaSdrh 7178df9185cSdrh 7188df9185cSdrh# .timer ON|OFF Turn the CPU timer measurement on or off 7198df9185cSdrhdo_test shell1-3.27.1 { 7208df9185cSdrh catchcmd "test.db" ".timer" 721c2ce0beaSdrh} {1 {Usage: .timer on|off}} 7228df9185cSdrhdo_test shell1-3.27.2 { 7238df9185cSdrh catchcmd "test.db" ".timer ON" 7248df9185cSdrh} {0 {}} 7258df9185cSdrhdo_test shell1-3.27.3 { 7268df9185cSdrh catchcmd "test.db" ".timer OFF" 7278df9185cSdrh} {0 {}} 7288df9185cSdrhdo_test shell1-3.27.4 { 7298df9185cSdrh # too many arguments 7308df9185cSdrh catchcmd "test.db" ".timer OFF BAD" 731c2ce0beaSdrh} {1 {Usage: .timer on|off}} 7328df9185cSdrh 7338df9185cSdrhdo_test shell1-3-28.1 { 7348df9185cSdrh catchcmd test.db \ 7358df9185cSdrh ".log stdout\nSELECT coalesce(sqlite_log(123,'hello'),'456');" 7368df9185cSdrh} "0 {(123) hello\n456}" 7378df9185cSdrh 738078b1fdaSdrhdo_test shell1-3-29.1 { 739078b1fdaSdrh catchcmd "test.db" ".print this is a test" 740078b1fdaSdrh} {0 {this is a test}} 741078b1fdaSdrh 7424c56b99fSdrh# dot-command argument quoting 7434c56b99fSdrhdo_test shell1-3-30.1 { 7444c56b99fSdrh catchcmd {test.db} {.print "this\"is'a\055test" 'this\"is\\a\055test'} 7454c56b99fSdrh} {0 {this"is'a-test this\"is\\a\055test}} 7464c56b99fSdrhdo_test shell1-3-31.1 { 7474c56b99fSdrh catchcmd {test.db} {.print "this\nis\ta\\test" 'this\nis\ta\\test'} 7484c56b99fSdrh} [list 0 "this\nis\ta\\test this\\nis\\ta\\\\test"] 7494c56b99fSdrh 7504c56b99fSdrh 7515128e85cSdrh# Test the output of the ".dump" command 7525128e85cSdrh# 7535128e85cSdrhdo_test shell1-4.1 { 75455a1b308Sdrh db close 75555a1b308Sdrh forcedelete test.db 75655a1b308Sdrh sqlite3 db test.db 7575128e85cSdrh db eval { 75855a1b308Sdrh PRAGMA encoding=UTF16; 7595128e85cSdrh CREATE TABLE t1(x); 760585dcb25Smistachkin INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f'); 761151c75adSmistachkin CREATE TABLE t3(x,y); 762151c75adSmistachkin INSERT INTO t3 VALUES(1,null), (2,''), (3,1), 763151c75adSmistachkin (4,2.25), (5,'hello'), (6,x'807f'); 7645128e85cSdrh } 7655128e85cSdrh catchcmd test.db {.dump} 7665128e85cSdrh} {0 {PRAGMA foreign_keys=OFF; 7675128e85cSdrhBEGIN TRANSACTION; 7685128e85cSdrhCREATE TABLE t1(x); 769f42d3180SdrhINSERT INTO t1 VALUES(NULL); 770f42d3180SdrhINSERT INTO t1 VALUES(''); 771f42d3180SdrhINSERT INTO t1 VALUES(1); 772f42d3180SdrhINSERT INTO t1 VALUES(2.25); 773f42d3180SdrhINSERT INTO t1 VALUES('hello'); 774f42d3180SdrhINSERT INTO t1 VALUES(X'807f'); 775151c75adSmistachkinCREATE TABLE t3(x,y); 776f42d3180SdrhINSERT INTO t3 VALUES(1,NULL); 777f42d3180SdrhINSERT INTO t3 VALUES(2,''); 778f42d3180SdrhINSERT INTO t3 VALUES(3,1); 779f42d3180SdrhINSERT INTO t3 VALUES(4,2.25); 780f42d3180SdrhINSERT INTO t3 VALUES(5,'hello'); 781f42d3180SdrhINSERT INTO t3 VALUES(6,X'807f'); 7825128e85cSdrhCOMMIT;}} 7835128e85cSdrh 784b9cd86a0Sdan 785b9cd86a0Sdanifcapable vtab { 786b9cd86a0Sdan 787f42d3180Sdrh# The --preserve-rowids option to .dump 788f42d3180Sdrh# 789e611f144Sdrhdo_test shell1-4.1.1 { 790e611f144Sdrh catchcmd test.db {.dump --preserve-rowids} 791e611f144Sdrh} {0 {PRAGMA foreign_keys=OFF; 792e611f144SdrhBEGIN TRANSACTION; 793e611f144SdrhCREATE TABLE t1(x); 794f42d3180SdrhINSERT INTO t1(rowid,x) VALUES(1,NULL); 795f42d3180SdrhINSERT INTO t1(rowid,x) VALUES(2,''); 796f42d3180SdrhINSERT INTO t1(rowid,x) VALUES(3,1); 797f42d3180SdrhINSERT INTO t1(rowid,x) VALUES(4,2.25); 798f42d3180SdrhINSERT INTO t1(rowid,x) VALUES(5,'hello'); 799f42d3180SdrhINSERT INTO t1(rowid,x) VALUES(6,X'807f'); 800e611f144SdrhCREATE TABLE t3(x,y); 801f42d3180SdrhINSERT INTO t3(rowid,x,y) VALUES(1,1,NULL); 802f42d3180SdrhINSERT INTO t3(rowid,x,y) VALUES(2,2,''); 803f42d3180SdrhINSERT INTO t3(rowid,x,y) VALUES(3,3,1); 804f42d3180SdrhINSERT INTO t3(rowid,x,y) VALUES(4,4,2.25); 805f42d3180SdrhINSERT INTO t3(rowid,x,y) VALUES(5,5,'hello'); 806f42d3180SdrhINSERT INTO t3(rowid,x,y) VALUES(6,6,X'807f'); 807e611f144SdrhCOMMIT;}} 808e611f144Sdrh 809f42d3180Sdrh# If the table contains an INTEGER PRIMARY KEY, do not record a separate 810f42d3180Sdrh# rowid column in the output. 811f42d3180Sdrh# 812e611f144Sdrhdo_test shell1-4.1.2 { 813e611f144Sdrh db close 814e611f144Sdrh forcedelete test2.db 815e611f144Sdrh sqlite3 db test2.db 816e611f144Sdrh db eval { 817e611f144Sdrh CREATE TABLE t1(x INTEGER PRIMARY KEY, y); 818e611f144Sdrh INSERT INTO t1 VALUES(1,null), (2,''), (3,1), 819e611f144Sdrh (4,2.25), (5,'hello'), (6,x'807f'); 820e611f144Sdrh } 821e611f144Sdrh catchcmd test2.db {.dump --preserve-rowids} 822e611f144Sdrh} {0 {PRAGMA foreign_keys=OFF; 823e611f144SdrhBEGIN TRANSACTION; 824e611f144SdrhCREATE TABLE t1(x INTEGER PRIMARY KEY, y); 825f42d3180SdrhINSERT INTO t1 VALUES(1,NULL); 826f42d3180SdrhINSERT INTO t1 VALUES(2,''); 827f42d3180SdrhINSERT INTO t1 VALUES(3,1); 828f42d3180SdrhINSERT INTO t1 VALUES(4,2.25); 829f42d3180SdrhINSERT INTO t1 VALUES(5,'hello'); 830f42d3180SdrhINSERT INTO t1 VALUES(6,X'807f'); 831e611f144SdrhCOMMIT;}} 832e611f144Sdrh 833f42d3180Sdrh# Verify that the table named [table] is correctly quoted and that 834f42d3180Sdrh# an INTEGER PRIMARY KEY DESC is not an alias for the rowid. 835f42d3180Sdrh# 836f42d3180Sdrhdo_test shell1-4.1.3 { 837f42d3180Sdrh db close 838f42d3180Sdrh forcedelete test2.db 839f42d3180Sdrh sqlite3 db test2.db 840f42d3180Sdrh db eval { 841f42d3180Sdrh CREATE TABLE [table](x INTEGER PRIMARY KEY DESC, y); 842f42d3180Sdrh INSERT INTO [table] VALUES(1,null), (12,''), (23,1), 843f42d3180Sdrh (34,2.25), (45,'hello'), (56,x'807f'); 844f42d3180Sdrh } 845f42d3180Sdrh catchcmd test2.db {.dump --preserve-rowids} 846f42d3180Sdrh} {0 {PRAGMA foreign_keys=OFF; 847f42d3180SdrhBEGIN TRANSACTION; 848f42d3180SdrhCREATE TABLE [table](x INTEGER PRIMARY KEY DESC, y); 849f42d3180SdrhINSERT INTO "table"(rowid,x,y) VALUES(1,1,NULL); 850f42d3180SdrhINSERT INTO "table"(rowid,x,y) VALUES(2,12,''); 851f42d3180SdrhINSERT INTO "table"(rowid,x,y) VALUES(3,23,1); 852f42d3180SdrhINSERT INTO "table"(rowid,x,y) VALUES(4,34,2.25); 853f42d3180SdrhINSERT INTO "table"(rowid,x,y) VALUES(5,45,'hello'); 854f42d3180SdrhINSERT INTO "table"(rowid,x,y) VALUES(6,56,X'807f'); 855f42d3180SdrhCOMMIT;}} 856f42d3180Sdrh 857f42d3180Sdrh# Do not record rowids for a WITHOUT ROWID table. Also check correct quoting 858f42d3180Sdrh# of table names that contain odd characters. 859f42d3180Sdrh# 860f42d3180Sdrhdo_test shell1-4.1.4 { 861f42d3180Sdrh db close 862f42d3180Sdrh forcedelete test2.db 863f42d3180Sdrh sqlite3 db test2.db 864f42d3180Sdrh db eval { 865f42d3180Sdrh CREATE TABLE [ta<>ble](x INTEGER PRIMARY KEY, y) WITHOUT ROWID; 866f42d3180Sdrh INSERT INTO [ta<>ble] VALUES(1,null), (12,''), (23,1), 867f42d3180Sdrh (34,2.25), (45,'hello'), (56,x'807f'); 868f42d3180Sdrh } 869f42d3180Sdrh catchcmd test2.db {.dump --preserve-rowids} 870f42d3180Sdrh} {0 {PRAGMA foreign_keys=OFF; 871f42d3180SdrhBEGIN TRANSACTION; 872f42d3180SdrhCREATE TABLE [ta<>ble](x INTEGER PRIMARY KEY, y) WITHOUT ROWID; 873f42d3180SdrhINSERT INTO "ta<>ble" VALUES(1,NULL); 874f42d3180SdrhINSERT INTO "ta<>ble" VALUES(12,''); 875f42d3180SdrhINSERT INTO "ta<>ble" VALUES(23,1); 876f42d3180SdrhINSERT INTO "ta<>ble" VALUES(34,2.25); 877f42d3180SdrhINSERT INTO "ta<>ble" VALUES(45,'hello'); 878f42d3180SdrhINSERT INTO "ta<>ble" VALUES(56,X'807f'); 879f42d3180SdrhCOMMIT;}} 880f42d3180Sdrh 881f42d3180Sdrh# Do not record rowids if the rowid is inaccessible 882f42d3180Sdrh# 883f42d3180Sdrhdo_test shell1-4.1.5 { 884f42d3180Sdrh db close 885f42d3180Sdrh forcedelete test2.db 886f42d3180Sdrh sqlite3 db test2.db 887f42d3180Sdrh db eval { 888f42d3180Sdrh CREATE TABLE t1(_ROWID_,rowid,oid); 889f42d3180Sdrh INSERT INTO t1 VALUES(1,null,'alpha'), (12,'',99), (23,1,x'b0b1b2'); 890f42d3180Sdrh } 891f42d3180Sdrh catchcmd test2.db {.dump --preserve-rowids} 892f42d3180Sdrh} {0 {PRAGMA foreign_keys=OFF; 893f42d3180SdrhBEGIN TRANSACTION; 894f42d3180SdrhCREATE TABLE t1(_ROWID_,rowid,oid); 895f42d3180SdrhINSERT INTO t1 VALUES(1,NULL,'alpha'); 896f42d3180SdrhINSERT INTO t1 VALUES(12,'',99); 897f42d3180SdrhINSERT INTO t1 VALUES(23,1,X'b0b1b2'); 898f42d3180SdrhCOMMIT;}} 899e611f144Sdrh 900b9cd86a0Sdan} else { 901b9cd86a0Sdan 902b9cd86a0Sdando_test shell1-4.1.6 { 903b9cd86a0Sdan db close 904b9cd86a0Sdan forcedelete test2.db 905b9cd86a0Sdan sqlite3 db test2.db 906b9cd86a0Sdan db eval { 907b9cd86a0Sdan CREATE TABLE t1(x INTEGER PRIMARY KEY, y); 908b9cd86a0Sdan INSERT INTO t1 VALUES(1,null), (2,''), (3,1), 909b9cd86a0Sdan (4,2.25), (5,'hello'), (6,x'807f'); 910b9cd86a0Sdan } 911b9cd86a0Sdan catchcmd test2.db {.dump --preserve-rowids} 912b9cd86a0Sdan} {1 {The --preserve-rowids option is not compatible with SQLITE_OMIT_VIRTUALTABLE}} 913b9cd86a0Sdan 914b9cd86a0Sdan} 915b9cd86a0Sdan 916b9cd86a0Sdan 9175128e85cSdrh# Test the output of ".mode insert" 9185128e85cSdrh# 919151c75adSmistachkindo_test shell1-4.2.1 { 9205128e85cSdrh catchcmd test.db ".mode insert t1\nselect * from t1;" 9215128e85cSdrh} {0 {INSERT INTO t1 VALUES(NULL); 922585dcb25SmistachkinINSERT INTO t1 VALUES(''); 9235128e85cSdrhINSERT INTO t1 VALUES(1); 9245128e85cSdrhINSERT INTO t1 VALUES(2.25); 9255128e85cSdrhINSERT INTO t1 VALUES('hello'); 9265128e85cSdrhINSERT INTO t1 VALUES(X'807f');}} 9275128e85cSdrh 928151c75adSmistachkin# Test the output of ".mode insert" with headers 929151c75adSmistachkin# 930151c75adSmistachkindo_test shell1-4.2.2 { 931151c75adSmistachkin catchcmd test.db ".mode insert t1\n.headers on\nselect * from t1;" 932151c75adSmistachkin} {0 {INSERT INTO t1(x) VALUES(NULL); 933151c75adSmistachkinINSERT INTO t1(x) VALUES(''); 934151c75adSmistachkinINSERT INTO t1(x) VALUES(1); 935151c75adSmistachkinINSERT INTO t1(x) VALUES(2.25); 936151c75adSmistachkinINSERT INTO t1(x) VALUES('hello'); 937151c75adSmistachkinINSERT INTO t1(x) VALUES(X'807f');}} 938151c75adSmistachkin 939151c75adSmistachkin# Test the output of ".mode insert" 940151c75adSmistachkin# 941151c75adSmistachkindo_test shell1-4.2.3 { 942151c75adSmistachkin catchcmd test.db ".mode insert t3\nselect * from t3;" 943151c75adSmistachkin} {0 {INSERT INTO t3 VALUES(1,NULL); 944151c75adSmistachkinINSERT INTO t3 VALUES(2,''); 945151c75adSmistachkinINSERT INTO t3 VALUES(3,1); 946151c75adSmistachkinINSERT INTO t3 VALUES(4,2.25); 947151c75adSmistachkinINSERT INTO t3 VALUES(5,'hello'); 948151c75adSmistachkinINSERT INTO t3 VALUES(6,X'807f');}} 949151c75adSmistachkin 950151c75adSmistachkin# Test the output of ".mode insert" with headers 951151c75adSmistachkin# 952cc445402Smistachkindo_test shell1-4.2.4 { 953151c75adSmistachkin catchcmd test.db ".mode insert t3\n.headers on\nselect * from t3;" 954151c75adSmistachkin} {0 {INSERT INTO t3(x,y) VALUES(1,NULL); 955151c75adSmistachkinINSERT INTO t3(x,y) VALUES(2,''); 956151c75adSmistachkinINSERT INTO t3(x,y) VALUES(3,1); 957151c75adSmistachkinINSERT INTO t3(x,y) VALUES(4,2.25); 958151c75adSmistachkinINSERT INTO t3(x,y) VALUES(5,'hello'); 959151c75adSmistachkinINSERT INTO t3(x,y) VALUES(6,X'807f');}} 960151c75adSmistachkin 961585dcb25Smistachkin# Test the output of ".mode tcl" 962585dcb25Smistachkin# 963585dcb25Smistachkindo_test shell1-4.3 { 96455a1b308Sdrh db close 96555a1b308Sdrh forcedelete test.db 96655a1b308Sdrh sqlite3 db test.db 96755a1b308Sdrh db eval { 96855a1b308Sdrh PRAGMA encoding=UTF8; 96955a1b308Sdrh CREATE TABLE t1(x); 97055a1b308Sdrh INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f'); 97155a1b308Sdrh } 972585dcb25Smistachkin catchcmd test.db ".mode tcl\nselect * from t1;" 973585dcb25Smistachkin} {0 {"" 974585dcb25Smistachkin"" 975585dcb25Smistachkin"1" 976585dcb25Smistachkin"2.25" 977585dcb25Smistachkin"hello" 978585dcb25Smistachkin"\200\177"}} 979585dcb25Smistachkin 980585dcb25Smistachkin# Test the output of ".mode tcl" with multiple columns 981585dcb25Smistachkin# 982585dcb25Smistachkindo_test shell1-4.4 { 983585dcb25Smistachkin db eval { 984585dcb25Smistachkin CREATE TABLE t2(x,y); 985585dcb25Smistachkin INSERT INTO t2 VALUES(null, ''), (1, 2.25), ('hello', x'807f'); 986585dcb25Smistachkin } 987585dcb25Smistachkin catchcmd test.db ".mode tcl\nselect * from t2;" 988585dcb25Smistachkin} {0 {"" "" 989585dcb25Smistachkin"1" "2.25" 990585dcb25Smistachkin"hello" "\200\177"}} 991585dcb25Smistachkin 992585dcb25Smistachkin# Test the output of ".mode tcl" with ".nullvalue" 993585dcb25Smistachkin# 994585dcb25Smistachkindo_test shell1-4.5 { 995585dcb25Smistachkin catchcmd test.db ".mode tcl\n.nullvalue NULL\nselect * from t2;" 996585dcb25Smistachkin} {0 {"NULL" "" 997585dcb25Smistachkin"1" "2.25" 998585dcb25Smistachkin"hello" "\200\177"}} 999585dcb25Smistachkin 1000585dcb25Smistachkin# Test the output of ".mode tcl" with Tcl reserved characters 1001585dcb25Smistachkin# 1002585dcb25Smistachkindo_test shell1-4.6 { 1003585dcb25Smistachkin db eval { 1004585dcb25Smistachkin CREATE TABLE tcl1(x); 1005585dcb25Smistachkin INSERT INTO tcl1 VALUES('"'), ('['), (']'), ('\{'), ('\}'), (';'), ('$'); 1006585dcb25Smistachkin } 1007585dcb25Smistachkin foreach {x y} [catchcmd test.db ".mode tcl\nselect * from tcl1;"] break 1008585dcb25Smistachkin list $x $y [llength $y] 1009585dcb25Smistachkin} {0 {"\"" 1010585dcb25Smistachkin"[" 1011585dcb25Smistachkin"]" 1012585dcb25Smistachkin"\\{" 1013585dcb25Smistachkin"\\}" 1014585dcb25Smistachkin";" 1015585dcb25Smistachkin"$"} 7} 10165128e85cSdrh 1017d0a9a462Slarrybr# Test the output of ".mode quote" 1018d0a9a462Slarrybr# 1019d0a9a462Slarrybrdo_test shell1-4.7 { 1020d0a9a462Slarrybr catchcmd test.db ".mode quote\nselect x'0123456789ABCDEF';" 1021d0a9a462Slarrybr} {0 X'0123456789abcdef'} 1022d0a9a462Slarrybr 1023f21979dfSmistachkin# Test using arbitrary byte data with the shell via standard input/output. 1024f21979dfSmistachkin# 1025f21979dfSmistachkindo_test shell1-5.0 { 1026f21979dfSmistachkin # 1027f21979dfSmistachkin # NOTE: Skip NUL byte because it appears to be incompatible with command 1028f21979dfSmistachkin # shell argument parsing. 1029f21979dfSmistachkin # 1030f21979dfSmistachkin for {set i 1} {$i < 256} {incr i} { 1031f21979dfSmistachkin # 103246a6b994Smistachkin # NOTE: Due to how the Tcl [exec] command works (i.e. where it treats 103346a6b994Smistachkin # command channels opened for it as textual ones), the carriage 103446a6b994Smistachkin # return character (and on Windows, the end-of-file character) 103546a6b994Smistachkin # cannot be used here. 1036f21979dfSmistachkin # 103746a6b994Smistachkin if {$i==0x0D || ($tcl_platform(platform)=="windows" && $i==0x1A)} { 1038f21979dfSmistachkin continue 1039f21979dfSmistachkin } 1040158931abSdrh # Tcl 8.7 maps 0x80 through 0x9f into valid UTF8. So skip those tests. 1041158931abSdrh if {$i>=0x80 && $i<=0x9f} continue 104201725680Sdrh if {$i>=0xE0 && $tcl_platform(os)=="OpenBSD"} continue 1043be56ad31Smistachkin if {$i>=0xE0 && $i<=0xEF && $tcl_platform(os)=="Linux"} continue 1044f21979dfSmistachkin set hex [format %02X $i] 1045f21979dfSmistachkin set char [subst \\x$hex]; set oldChar $char 10460acee513Smistachkin set escapes [list] 10470acee513Smistachkin if {$tcl_platform(platform)=="windows"} { 10480acee513Smistachkin # 10490acee513Smistachkin # NOTE: On Windows, we need to escape all the whitespace characters, 10500acee513Smistachkin # the alarm (\a) character, and those with special meaning to 10510acee513Smistachkin # the SQLite shell itself. 10520acee513Smistachkin # 10530acee513Smistachkin set escapes [list \ 1054f21979dfSmistachkin \a \\a \b \\b \t \\t \n \\n \v \\v \f \\f \r \\r \ 10550acee513Smistachkin " " "\" \"" \" \\\" ' \"'\" \\ \\\\] 10560acee513Smistachkin } else { 10570acee513Smistachkin # 10580acee513Smistachkin # NOTE: On Unix, we need to escape most of the whitespace characters 10590acee513Smistachkin # and those with special meaning to the SQLite shell itself. 10600acee513Smistachkin # The alarm (\a), backspace (\b), and carriage-return (\r) 10610acee513Smistachkin # characters do not appear to require escaping on Unix. For 10620acee513Smistachkin # the alarm and backspace characters, this is probably due to 10630acee513Smistachkin # differences in the command shell. For the carriage-return, 10640acee513Smistachkin # it is probably due to differences in how Tcl handles command 10650acee513Smistachkin # channel end-of-line translations. 10660acee513Smistachkin # 10670acee513Smistachkin set escapes [list \ 10680acee513Smistachkin \t \\t \n \\n \v \\v \f \\f \ 10690acee513Smistachkin " " "\" \"" \" \\\" ' \"'\" \\ \\\\] 10700acee513Smistachkin } 10710acee513Smistachkin set char [string map $escapes $char] 1072bfefa4c2Smistachkin set x [catchcmdex test.db ".print $char\n"] 1073f21979dfSmistachkin set code [lindex $x 0] 1074f21979dfSmistachkin set res [lindex $x 1] 1075f21979dfSmistachkin if {$code ne "0"} { 1076f21979dfSmistachkin error "failed with error: $res" 1077f21979dfSmistachkin } 1078f21979dfSmistachkin if {$res ne "$oldChar\n"} { 107948dcf2b6Smistachkin if {[llength $res] > 0} { 108048dcf2b6Smistachkin set got [format %02X [scan $res %c]] 108148dcf2b6Smistachkin } else { 108248dcf2b6Smistachkin set got <empty> 108348dcf2b6Smistachkin } 108448dcf2b6Smistachkin error "failed with byte $hex mismatch, got $got" 1085f21979dfSmistachkin } 1086f21979dfSmistachkin } 10871fe36bb8Smistachkin} {} 10881fe36bb8Smistachkin 1089697c9eaaSdrh# These test cases do not work on MinGW 1090697c9eaaSdrhif 0 { 1091697c9eaaSdrh 109249e1125bSmistachkin# The string used here is the word "test" in Chinese. 10931fe36bb8Smistachkin# In UTF-8, it is encoded as: \xE6\xB5\x8B\xE8\xAF\x95 109449e1125bSmistachkinset test \u6D4B\u8BD5 109549e1125bSmistachkin 109649e1125bSmistachkindo_test shell1-6.0 { 109749e1125bSmistachkin set fileName $test; append fileName .db 109849e1125bSmistachkin catch {forcedelete $fileName} 10991fe36bb8Smistachkin set x [catchcmdex $fileName "CREATE TABLE t1(x);\n.schema\n"] 11001fe36bb8Smistachkin set code [lindex $x 0] 11011fe36bb8Smistachkin set res [string trim [lindex $x 1]] 11021fe36bb8Smistachkin if {$code ne "0"} { 11031fe36bb8Smistachkin error "failed with error: $res" 11041fe36bb8Smistachkin } 11051fe36bb8Smistachkin if {$res ne "CREATE TABLE t1(x);"} { 11061fe36bb8Smistachkin error "failed with mismatch: $res" 11071fe36bb8Smistachkin } 11081fe36bb8Smistachkin if {![file exists $fileName]} { 11091810f228Smistachkin error "file \"$fileName\" (Unicode) does not exist" 11101fe36bb8Smistachkin } 11111fe36bb8Smistachkin forcedelete $fileName 1112f21979dfSmistachkin} {} 1113f21979dfSmistachkin 111449e1125bSmistachkindo_test shell1-6.1 { 111549e1125bSmistachkin catch {forcedelete test3.db} 111649e1125bSmistachkin set x [catchcmdex test3.db \ 111749e1125bSmistachkin "CREATE TABLE [encoding convertto utf-8 $test](x);\n.schema\n"] 111849e1125bSmistachkin set code [lindex $x 0] 111949e1125bSmistachkin set res [string trim [lindex $x 1]] 112049e1125bSmistachkin if {$code ne "0"} { 112149e1125bSmistachkin error "failed with error: $res" 112249e1125bSmistachkin } 112349e1125bSmistachkin if {$res ne "CREATE TABLE ${test}(x);"} { 112449e1125bSmistachkin error "failed with mismatch: $res" 112549e1125bSmistachkin } 112649e1125bSmistachkin forcedelete test3.db 112749e1125bSmistachkin} {} 1128697c9eaaSdrh} 112949e1125bSmistachkin 11309d107262Smistachkindb close 11319d107262Smistachkinforcedelete test.db test.db-journal test.db-wal 11329d107262Smistachkinsqlite3 db test.db 11339d107262Smistachkin 113407f119e4Sdan# The shell tool ".schema" command uses virtual table "pragma_database_list" 113507f119e4Sdan# 113607f119e4Sdanifcapable vtab { 113707f119e4Sdan 11389d107262Smistachkindo_test shell1-7.1.1 { 11399d107262Smistachkin db eval { 11409d107262Smistachkin CREATE TABLE Z (x TEXT PRIMARY KEY); 11419d107262Smistachkin CREATE TABLE _ (x TEXT PRIMARY KEY); 11429d107262Smistachkin CREATE TABLE YY (x TEXT PRIMARY KEY); 11439d107262Smistachkin CREATE TABLE __ (x TEXT PRIMARY KEY); 11449d107262Smistachkin CREATE TABLE WWW (x TEXT PRIMARY KEY); 11459d107262Smistachkin CREATE TABLE ___ (x TEXT PRIMARY KEY); 11469d107262Smistachkin } 11479d107262Smistachkin} {} 11489d107262Smistachkindo_test shell1-7.1.2 { 11499d107262Smistachkin catchcmd "test.db" ".schema _" 11509d107262Smistachkin} {0 {CREATE TABLE Z (x TEXT PRIMARY KEY); 11519d107262SmistachkinCREATE TABLE _ (x TEXT PRIMARY KEY);}} 11529d107262Smistachkindo_test shell1-7.1.3 { 11539d107262Smistachkin catchcmd "test.db" ".schema \\\\_" 11549d107262Smistachkin} {0 {CREATE TABLE _ (x TEXT PRIMARY KEY);}} 11559d107262Smistachkindo_test shell1-7.1.4 { 11569d107262Smistachkin catchcmd "test.db" ".schema __" 11579d107262Smistachkin} {0 {CREATE TABLE YY (x TEXT PRIMARY KEY); 11589d107262SmistachkinCREATE TABLE __ (x TEXT PRIMARY KEY);}} 11599d107262Smistachkindo_test shell1-7.1.5 { 11609d107262Smistachkin catchcmd "test.db" ".schema \\\\_\\\\_" 11619d107262Smistachkin} {0 {CREATE TABLE __ (x TEXT PRIMARY KEY);}} 11629d107262Smistachkindo_test shell1-7.1.6 { 11639d107262Smistachkin catchcmd "test.db" ".schema ___" 11649d107262Smistachkin} {0 {CREATE TABLE WWW (x TEXT PRIMARY KEY); 11659d107262SmistachkinCREATE TABLE ___ (x TEXT PRIMARY KEY);}} 11669d107262Smistachkindo_test shell1-7.1.7 { 11679d107262Smistachkin catchcmd "test.db" ".schema \\\\_\\\\_\\\\_" 11689d107262Smistachkin} {0 {CREATE TABLE ___ (x TEXT PRIMARY KEY);}} 11699d107262Smistachkin 117007f119e4Sdan} 117107f119e4Sdan 11724dfdb86cSdrh# Test case for the ieee754 and decimal extensions in the shell. 11734dfdb86cSdrh# See the "floatingpoint.html" file in the documentation for more 11744dfdb86cSdrh# information. 11754dfdb86cSdrh# 11764dfdb86cSdrhdo_test shell1-8.1 { 11774dfdb86cSdrh catchcmd ":memory:" { 11784dfdb86cSdrh -- The pow2 table will hold all the necessary powers of two. 11794dfdb86cSdrh CREATE TABLE pow2(x INTEGER PRIMARY KEY, v TEXT); 11804dfdb86cSdrh WITH RECURSIVE c(x,v) AS ( 11814dfdb86cSdrh VALUES(0,'1') 11824dfdb86cSdrh UNION ALL 11834dfdb86cSdrh SELECT x+1, decimal_mul(v,'2') FROM c WHERE x+1<=971 11844dfdb86cSdrh ) INSERT INTO pow2(x,v) SELECT x, v FROM c; 11854dfdb86cSdrh WITH RECURSIVE c(x,v) AS ( 11864dfdb86cSdrh VALUES(-1,'0.5') 11874dfdb86cSdrh UNION ALL 11884dfdb86cSdrh SELECT x-1, decimal_mul(v,'0.5') FROM c WHERE x-1>=-1075 11894dfdb86cSdrh ) INSERT INTO pow2(x,v) SELECT x, v FROM c; 11904dfdb86cSdrh 11914dfdb86cSdrh -- This query finds the decimal representation of each value in the "c" table. 11924dfdb86cSdrh WITH c(n) AS (VALUES(47.49)) 11934dfdb86cSdrh ----XXXXX----------- Replace with whatever you want 11944dfdb86cSdrh SELECT decimal_mul(ieee754_mantissa(c.n),pow2.v) 11954dfdb86cSdrh FROM pow2, c WHERE pow2.x=ieee754_exponent(c.n); 11964dfdb86cSdrh } 11974dfdb86cSdrh} {0 47.49000000000000198951966012828052043914794921875} 11984dfdb86cSdrhdo_test shell1-8.2 { 11994dfdb86cSdrh catchcmd :memory: { 12004dfdb86cSdrh.mode box 12014dfdb86cSdrhSELECT ieee754(47.49) AS x; 12024dfdb86cSdrh } 12034dfdb86cSdrh} {0 {┌───────────────────────────────┐ 12044dfdb86cSdrh│ x │ 12054dfdb86cSdrh├───────────────────────────────┤ 12064dfdb86cSdrh│ ieee754(6683623321994527,-47) │ 12074dfdb86cSdrh└───────────────────────────────┘}} 12084dfdb86cSdrhdo_test shell1-8.3 { 12094dfdb86cSdrh catchcmd ":memory: --box" { 12104dfdb86cSdrh select ieee754(6683623321994527,-47) as x; 12114dfdb86cSdrh } 12124dfdb86cSdrh} {0 {┌───────┐ 12134dfdb86cSdrh│ x │ 12144dfdb86cSdrh├───────┤ 12154dfdb86cSdrh│ 47.49 │ 12164dfdb86cSdrh└───────┘}} 12174dfdb86cSdrhdo_test shell1-8.4 { 12184dfdb86cSdrh catchcmd ":memory: --table" {SELECT ieee754_mantissa(47.49) AS M, ieee754_exponent(47.49) AS E;} 12194dfdb86cSdrh} {0 {+------------------+-----+ 12204dfdb86cSdrh| M | E | 12214dfdb86cSdrh+------------------+-----+ 12224dfdb86cSdrh| 6683623321994527 | -47 | 12234dfdb86cSdrh+------------------+-----+}} 12246403e77dSlarrybrdo_test shell1-8.5 { 12256403e77dSlarrybr catchcmd ":memory: --box" { 12266403e77dSlarrybrcreate table t(a text, b int); 12276403e77dSlarrybrinsert into t values ('too long for one line', 1), ('shorter', NULL); 12286403e77dSlarrybr.header on 12296403e77dSlarrybr.width 10 10 12306403e77dSlarrybr.nullvalue NADA 12316403e77dSlarrybrselect * from t;} 12326403e77dSlarrybr} {0 {┌────────────┬────────────┐ 12336403e77dSlarrybr│ a │ b │ 12346403e77dSlarrybr├────────────┼────────────┤ 12356403e77dSlarrybr│ too long f │ 1 │ 12366403e77dSlarrybr│ or one lin │ │ 12376403e77dSlarrybr│ e │ │ 12386403e77dSlarrybr├────────────┼────────────┤ 12396403e77dSlarrybr│ shorter │ NADA │ 12406403e77dSlarrybr└────────────┴────────────┘}} 12414dfdb86cSdrh 1242d797d6b6Slarrybr#---------------------------------------------------------------------------- 1243d797d6b6Slarrybr# Test cases shell1-9.*: Basic test that "dot" commands and SQL intermix ok. 1244d797d6b6Slarrybr# 1245d797d6b6Slarrybrdo_test shell1-9.1 { 1246d797d6b6Slarrybr catchcmd :memory: { 1247d797d6b6Slarrybr.mode csv 1248d797d6b6Slarrybr/* 1249d797d6b6Slarrybrx */ select 1,2; --x 1250d797d6b6Slarrybr -- .nada 1251d797d6b6Slarrybr; 1252d797d6b6Slarrybr.mode csv 1253d797d6b6Slarrybr--x 1254d797d6b6Slarrybrselect 2,1; select 3,4; 1255d797d6b6Slarrybr} 1256d797d6b6Slarrybr} {0 {1,2 1257d797d6b6Slarrybr2,1 1258d797d6b6Slarrybr3,4}} 1259d797d6b6Slarrybr 12608df9185cSdrhfinish_test 1261