AryaWu/sqlite
0
1# 2025-11-122#3# The author disclaims copyright to this source code. In place of4# a legal notice, here is a blessing:5#6# May you do good and not evil.7# May you find forgiveness for yourself and forgive others.8# May you share freely, never taking more than you give.9#10#***********************************************************************11#12# Test cases for the ".mode" command of the CLI.13# To run these tests:14#15# ./sqlite3 <test/modeA.clitest16#17#18CREATE TABLE t1(a,b,c,d,e);19INSERT INTO t1 VALUES(1,2.5,'three',x'4444',NULL);20INSERT INTO t1 SELECT b,c,d,e,a FROM t1;21INSERT INTO t1 SELECT d,e,a,b,c FROM t1;22.mode box23 24.testcase 10025SELECT * FROM t1;26.check <<END27╭─────┬───────┬───────┬───────┬───────╮28│ a │ b │ c │ d │ e │29╞═════╪═══════╪═══════╪═══════╪═══════╡30│ 1 │ 2.5 │ three │ DD │ │31│ 2.5 │ three │ DD │ │ 1 │32│ DD │ │ 1 │ 2.5 │ three │33│ │ 1 │ 2.5 │ three │ DD │34╰─────┴───────┴───────┴───────┴───────╯35END36 37.testcase 11038.mode --null xyz39SELECT * FROM t1;40.check <<END41╭─────┬───────┬───────┬───────┬───────╮42│ a │ b │ c │ d │ e │43╞═════╪═══════╪═══════╪═══════╪═══════╡44│ 1 │ 2.5 │ three │ DD │ xyz │45│ 2.5 │ three │ DD │ xyz │ 1 │46│ DD │ xyz │ 1 │ 2.5 │ three │47│ xyz │ 1 │ 2.5 │ three │ DD │48╰─────┴───────┴───────┴───────┴───────╯49END50 51# Default output mode is qbox --quote relaxed52#53.mode tty --wrap 1054CREATE TABLE t2(a,b,c,d);55INSERT INTO t2 VALUES(1,2.5,'three',x'4444');56INSERT INTO t2 VALUES('The quick fox jumps over the lazy brown dog',2,3,4);57INSERT INTO t2 VALUES('10','', -1.25,NULL);58INSERT INTO t2 VALUES('a,b,c','"Double-Quoted"','-1.25','NULL');59.testcase 12060SELECT * FROM t2;61.check <<END62╭────────────┬────────────┬─────────┬─────────╮63│ a │ b │ c │ d │64╞════════════╪════════════╪═════════╪═════════╡65│ 1 │ 2.5 │ three │ x'4444' │66├────────────┼────────────┼─────────┼─────────┤67│ The quick │ 2 │ 3 │ 4 │68│ fox jumps │ │ │ │69│ over the │ │ │ │70│ lazy brown │ │ │ │71│ dog │ │ │ │72├────────────┼────────────┼─────────┼─────────┤73│ '10' │ │ -1.25 │ NULL │74├────────────┼────────────┼─────────┼─────────┤75│ a,b,c │ "Double- │ '-1.25' │ 'NULL' │76│ │ Quoted" │ │ │77╰────────────┴────────────┴─────────┴─────────╯78END79.testcase 13080.mode81.check <<END82.mode qbox --limits on --quote relaxed --sw auto --textjsonb on83END84.testcase 14085.mode -v86.check <<END87.mode qbox --align "" --border on --blob-quote auto --colsep "" --escape auto --limits on --null "NULL" --quote relaxed --rowsep "" --sw auto --tablename "" --textjsonb on --titles on --widths "" --wordwrap off --wrap 1088END89.testcase 150 --error-prefix "Error:"90.mode foo91.check <<END92Error: .mode foo93Error: ^--- unknown mode94Error: Use ".help .mode" for more info95END96 97.testcase 16098.mode --null xyzzy -v99.output -glob ' --null "xyzzy"'100.testcase 170101.mode -null abcde -v102.output -glob ' --null "abcde"'103 104# Test cases for the ".explain off" command105.mode box -reset106.testcase 180107EXPLAIN SELECT * FROM t1;108.output --notglob *────* --keep109.output --notglob "* id │ parent │ notused │ detail *" --keep110.output --glob "* Init *"111.testcase 190112EXPLAIN QUERY PLAN SELECT * FROM t1;113.output --glob "*`--SCAN *"114.explain off115.testcase 200116EXPLAIN SELECT * FROM t1;117.output --glob *────*118.testcase 210119EXPLAIN QUERY PLAN SELECT * FROM t1;120.output --glob "* id │ parent │ notused │ detail *"121.explain auto122 123# Test cases for limit settings in the .mode command.124.testcase 300125.mode box --reset126.mode127.check <<END128.mode box129END130.testcase 310131.mode --limits 5,300,20132.mode133.check <<END134.mode box --limits on135END136.testcase 320137.mode --limits 5,300,19138.mode139.check <<END140.mode box --limits 5,300,19141END142.testcase 330143.mode --limits 0,0,0144.mode -v145.check <<END146.mode box --align "" --border on --blob-quote auto --colsep "" --escape auto --limits off --null "" --quote off --rowsep "" --sw 0 --tablename "" --textjsonb off --titles on --widths "" --wordwrap off147END148 149.testcase 400150.mode --linelimit 123151.mode152.check <<END153.mode box --limits 123,0,0154END155 156.testcase 410157.mode --linelimit 0 -charlimit 123158.mode159.check <<END160.mode box --limits 0,123,0161END162 163.testcase 420164.mode --charlimit 0 -titlelimit 123165.mode166.check <<END167.mode box --limits 0,0,123168END169 170.testcase 430171.mode list172.mode173.check <<END174.mode list175END176 177.testcase 440178.mode -limits 0,123,0179.mode180.check <<END181.mode list --limits 0,123,0182END183 184.testcase 450185.mode -limits 123,0,0186.mode187.check <<END188.mode list189END190 191# --titlelimit functionality192#193.testcase 500194.mode line --limits off --titlelimit 20195SELECT a AS 'abcdefghijklmnopqrstuvwxyz', b FROM t2 WHERE c=3;196.check <<END197abcdefghijklmnopq...: The quick fox jumps over the lazy brown dog198 b: 2199END200.testcase 510201.mode line --titlelimit 10202SELECT a AS 'abcdefghijklmnopqrstuvwxyz', b FROM t2 WHERE c=3;203.check <<END204abcdefg...: The quick fox jumps over the lazy brown dog205 b: 2206END207.testcase 520208.mode line --titlelimit 2209SELECT a AS 'abcdefghijklmnopqrstuvwxyz', b FROM t2 WHERE c=3;210.check <<END211ab: The quick fox jumps over the lazy brown dog212 b: 2213END214.testcase 530215.mode line --titlelimit 4216SELECT a AS 'abcd', b FROM t2 WHERE c=3;217.check <<END218abcd: The quick fox jumps over the lazy brown dog219 b: 2220END221.testcase 540222.mode line --titlelimit 3223SELECT a AS 'abcd', b FROM t2 WHERE c=3;224.check <<END225...: The quick fox jumps over the lazy brown dog226 b: 2227END228 