interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / test / modeA.sql

1177 lines · 34218 bytes Raw Blame History
1#!sqlite3
2#
3# 2025-11-12
4#
5# The author disclaims copyright to this source code. In place of
6# a legal notice, here is a blessing:
7#
8# May you do good and not evil.
9# May you find forgiveness for yourself and forgive others.
10# May you share freely, never taking more than you give.
11#
12#***********************************************************************
13#
14# Test cases for the ".mode" command of the CLI.
15# To run these tests:
16#
17# ./sqlite3 test/modeA.sql
18#
19#
20.open :memory:
21CREATE TABLE t1(a,b,c,d,e);
22INSERT INTO t1 VALUES(1,2.5,'three',x'4444',NULL);
23INSERT INTO t1 SELECT b,c,d,e,a FROM t1;
24INSERT INTO t1 SELECT d,e,a,b,c FROM t1;
25.mode box
26
27.testcase 100
28SELECT * FROM t1;
29.check <<END
30╭─────┬───────┬───────┬───────┬───────╮
31│ a │ b │ c │ d │ e │
32╞═════╪═══════╪═══════╪═══════╪═══════╡
33│ 1 │ 2.5 │ three │ DD │ │
34│ 2.5 │ three │ DD │ │ 1 │
35│ DD │ │ 1 │ 2.5 │ three │
36│ │ 1 │ 2.5 │ three │ DD │
37╰─────┴───────┴───────┴───────┴───────╯
38END
39
40.testcase 110
41.mode --null xyz
42SELECT * FROM t1;
43.check <<END
44╭─────┬───────┬───────┬───────┬───────╮
45│ a │ b │ c │ d │ e │
46╞═════╪═══════╪═══════╪═══════╪═══════╡
47│ 1 │ 2.5 │ three │ DD │ xyz │
48│ 2.5 │ three │ DD │ xyz │ 1 │
49│ DD │ xyz │ 1 │ 2.5 │ three │
50│ xyz │ 1 │ 2.5 │ three │ DD │
51╰─────┴───────┴───────┴───────┴───────╯
52END
53
54# Default output mode is qbox --quote relaxed
55#
56.mode tty --wrap 10
57CREATE TABLE t2(a,b,c,d);
58INSERT INTO t2 VALUES(1,2.5,'three',x'4444');
59INSERT INTO t2 VALUES('The quick fox jumps over the lazy brown dog',2,3,4);
60INSERT INTO t2 VALUES('10','', -1.25,NULL);
61INSERT INTO t2 VALUES('a,b,c','"Double-Quoted"','-1.25','NULL');
62.testcase 120
63SELECT * FROM t2;
64.check <<END
65╭────────────┬────────────┬─────────┬─────────╮
66│ a │ b │ c │ d │
67╞════════════╪════════════╪═════════╪═════════╡
68│ 1 │ 2.5 │ three │ x'4444' │
69├────────────┼────────────┼─────────┼─────────┤
70│ The quick │ 2 │ 3 │ 4 │
71│ fox jumps │ │ │ │
72│ over the │ │ │ │
73│ lazy brown │ │ │ │
74│ dog │ │ │ │
75├────────────┼────────────┼─────────┼─────────┤
76│ '10' │ │ -1.25 │ NULL │
77├────────────┼────────────┼─────────┼─────────┤
78│ a,b,c │ "Double- │ '-1.25' │ 'NULL' │
79│ │ Quoted" │ │ │
80╰────────────┴────────────┴─────────┴─────────╯
81END
82.testcase 121
83.mode tty --wrap 1 --limits off
84SELECT 'xyz123' AS a, 2 AS b;
85.check <<END
86╭───┬───╮
87│ a │ b │
88╞═══╪═══╡
89│ x │ 2 │
90│ y │ │
91│ z │ │
92│ 1 │ │
93│ 2 │ │
94│ 3 │ │
95╰───┴───╯
96END
97.testcase 130
98.mode tty -wrap 10
99.mode
100.check <<END
101.mode qbox --limits on --quote relaxed --sw auto --textjsonb on
102END
103.testcase 140
104.mode -v
105.check <<END
106.mode qbox --align "" --border on --blob-quote auto --colsep "" --escape auto --fpfmt auto --ifmt auto --limits on --multiinsert 3000 --null "NULL" --quote relaxed --rowcount off --rowsep "" --sw auto --tablename "" --textjsonb on --titles always --widths "" --wordwrap off --wrap 10
107END
108.testcase 150 --error-prefix "Error:"
109.mode foo
110.check <<END
111Error: .mode foo
112Error: ^--- unknown mode
113Error: Use ".help .mode" for more info
114END
115
116.testcase 160
117.mode --null xyzzy -v
118.check -any ' --null "xyzzy"'
119.testcase 170
120.mode -null abcde -v
121.check -any ' --null "abcde"'
122
123# Test cases for the ".explain off" command
124.mode box -reset
125.testcase 180
126EXPLAIN SELECT * FROM t1;
127.check --nowhere ──── --keep
128.check --nowhere " id │ parent │ notused │ detail " --keep
129.check --regexp '\bInit\b' --keep
130.check --any ' Init '
131.testcase 190
132EXPLAIN QUERY PLAN SELECT * FROM t1;
133.check --glob "*`--SCAN *"
134.explain off
135.testcase 200
136EXPLAIN SELECT * FROM t1;
137.check --regexp ────
138.testcase 210
139EXPLAIN QUERY PLAN SELECT * FROM t1;
140.check --glob "* id │ parent │ notused │ detail *"
141.explain auto
142
143# Test cases for limit settings in the .mode command.
144.testcase 300
145.mode box --reset
146.mode
147.check <<END
148.mode box
149END
150.testcase 310
151.mode --limits 5,300,20
152.mode
153.check <<END
154.mode box --limits on
155END
156.testcase 320
157.mode --limits 5,300,19
158.mode
159.check <<END
160.mode box --limits 5,300,19
161END
162.testcase 330
163.mode --limits 0,0,0
164.mode -v
165.check <<END
166.mode box --align "" --border on --blob-quote auto --colsep "" --escape auto --fpfmt auto --ifmt auto --limits off --multiinsert 0 --null "" --quote off --rowcount off --rowsep "" --sw 0 --tablename "" --textjsonb off --titles always --widths "" --wordwrap off
167END
168
169.testcase 400
170.mode --linelimit 123
171.mode
172.check <<END
173.mode box --limits 123,0,0
174END
175
176.testcase 410
177.mode --linelimit 0 -charlimit 123
178.mode
179.check <<END
180.mode box --limits 0,123,0
181END
182
183.testcase 420
184.mode --charlimit 0 -titlelimit 123
185.mode
186.check <<END
187.mode box --limits 0,0,123
188END
189
190.testcase 430
191.mode list
192.mode
193.check <<END
194.mode list
195END
196
197.testcase 440
198.mode -limits 0,123,0
199.mode
200.check <<END
201.mode list --limits 0,123,0
202END
203
204.testcase 450
205.mode -limits 123,0,0
206.mode
207.check <<END
208.mode list
209END
210
211# --titlelimit functionality
212#
213.testcase 500
214.mode line --limits off --titlelimit 20
215SELECT a AS 'abcdefghijklmnopqrstuvwxyz', b FROM t2 WHERE c=3;
216.check <<END
217abcdefghijklmnopq...: The quick fox jumps over the lazy brown dog
218 b: 2
219END
220.testcase 501
221SELECT a AS 'a bc', b AS 'b
222c
223d' FROM t2 WHERE c=3;
224.check <<END
225a bc: The quick fox jumps over the lazy brown dog
226b c d: 2
227END
228.testcase 510
229.mode line --titlelimit 10
230SELECT a AS 'abcdefghijklmnopqrstuvwxyz', b FROM t2 WHERE c=3;
231.check <<END
232abcdefg...: The quick fox jumps over the lazy brown dog
233 b: 2
234END
235.testcase 520
236.mode line --titlelimit 2
237SELECT a AS 'abcdefghijklmnopqrstuvwxyz', b FROM t2 WHERE c=3;
238.check <<END
239ab: The quick fox jumps over the lazy brown dog
240 b: 2
241END
242.testcase 530
243.mode line --titlelimit 4
244SELECT a AS 'abcd', b FROM t2 WHERE c=3;
245.check <<END
246abcd: The quick fox jumps over the lazy brown dog
247 b: 2
248END
249.testcase 540
250.mode line --titlelimit 3
251SELECT a AS 'abcd', b FROM t2 WHERE c=3;
252.check <<END
253...: The quick fox jumps over the lazy brown dog
254 b: 2
255END
256
257# --titlelimit counts display width, not bytes
258#
259# ten two-byte characters fit within --titlelimit 10
260.testcase 541
261.mode box --titlelimit 10
262SELECT 1 AS 'abcdefghij', 2 AS 'éééééééééé';
263.check <<END
264╭────────────┬────────────╮
265│ abcdefghij │ éééééééééé │
266╞════════════╪════════════╡
267│ 1 │ 2 │
268╰────────────┴────────────╯
269END
270# nine characters fit
271.testcase 542
272.mode box --titlelimit 10
273SELECT 1 AS 'abcdefghi', 2 AS 'ééééééééé';
274.check <<END
275╭───────────┬───────────╮
276│ abcdefghi │ ééééééééé │
277╞═══════════╪═══════════╡
278│ 1 │ 2 │
279╰───────────┴───────────╯
280END
281# eleven characters are truncated to seven plus an ellipsis
282.testcase 543
283.mode box --titlelimit 10
284SELECT 1 AS 'abcdefghijk', 2 AS 'ééééééééééé';
285.check <<END
286╭────────────┬────────────╮
287│ abcdefg... │ ééééééé... │
288╞════════════╪════════════╡
289│ 1 │ 2 │
290╰────────────┴────────────╯
291END
292# multi-byte characters at the end of the title
293.testcase 544
294.mode box --titlelimit 10
295SELECT 1 AS 'éééééééééz', 2 AS 'zééééééééé';
296.check <<END
297╭────────────┬────────────╮
298│ éééééééééz │ zééééééééé │
299╞════════════╪════════════╡
300│ 1 │ 2 │
301╰────────────┴────────────╯
302END
303# three-byte characters
304.testcase 545
305.mode box --titlelimit 10
306SELECT 1 AS '€€€€€€€€€', 2 AS '€€€€€€€€€€';
307.check <<END
308╭───────────┬────────────╮
309│ €€€€€€€€€ │ €€€€€€€€€€ │
310╞═══════════╪════════════╡
311│ 1 │ 2 │
312╰───────────┴────────────╯
313END
314# double-width characters; truncation must account for their width
315.testcase 546
316.mode box --titlelimit 10
317SELECT 1 AS '安安安安安安', 2 AS 'a安安安安安安';
318.check <<END
319╭───────────┬────────────╮
320│ 安安安... │ a安安安... │
321╞═══════════╪════════════╡
322│ 1 │ 2 │
323╰───────────┴────────────╯
324END
325.mode line --titlelimit 3
326
327# The --null option and the .nullvalue command must be honored by
328# ".mode html". Bug 2026-11-05T22:27:46Z.
329#
330.testcase 550
331.mode html
332SELECT NULL AS n;
333.check <<END
334<tr>
335<th>n
336</tr>
337<tr>
338<td>null
339</tr>
340END
341
342.testcase 551
343.mode html --null XX
344SELECT NULL AS n;
345.check <<END
346<tr>
347<th>n
348</tr>
349<tr>
350<td>XX
351</tr>
352END
353
354.testcase 552
355.nullvalue YY
356SELECT NULL AS n;
357.check <<END
358<tr>
359<th>n
360</tr>
361<tr>
362<td>YY
363</tr>
364END
365
366.testcase 553
367.nullvalue
368SELECT NULL AS n;
369.check -glob "*sage: .nullvalue STRING*"
370
371# NULL text is HTML-escaped, and does not change how a string that
372# happens to look like the NULL text is rendered.
373.testcase 554
374.mode html --null <nil>
375SELECT NULL AS n, 'null' AS m;
376.check <<END
377<tr>
378<th>n
379<th>m
380</tr>
381<tr>
382<td>&lt;nil&gt;
383<td>null
384</tr>
385END
386
387# Switching to another mode and back restores the default for html.
388.testcase 555
389.mode list --null XX
390.mode html
391SELECT NULL AS n;
392.check <<END
393<tr>
394<th>n
395</tr>
396<tr>
397<td>null
398</tr>
399END
400.mode line --titlelimit 3
401.nullvalue ""
402
403# With "--escape off" a control character in a value is shown by the
404# columnar modes as a one-column Control Picture symbol. Column widths
405# must count it as one column, so that the value is not wrapped.
406# Bug 2026-11-05T22:27:00Z.
407#
408.testcase 560
409.mode box --escape off
410SELECT 'a'||char(7)||'b' AS x;
411.check <<END
412╭─────╮
413│ x │
414╞═════╡
415│ a␇b │
416╰─────╯
417END
418
419.testcase 561
420.mode box --escape symbol
421SELECT 'a'||char(7)||'b' AS x;
422.check <<END
423╭─────╮
424│ x │
425╞═════╡
426│ a␇b │
427╰─────╯
428END
429
430.testcase 562
431.mode box --escape ascii
432SELECT 'a'||char(7)||'b' AS x;
433.check <<END
434╭──────╮
435│ x │
436╞══════╡
437│ a^Gb │
438╰──────╯
439END
440
441.testcase 563
442.mode table --escape off
443SELECT 'a'||char(7)||'b' AS x, char(1)||'q'||char(2)||char(31) AS y;
444.check <<END
445+-----+------+
446| x | y |
447+-----+------+
448| a␇b | ␁q␂␟ |
449+-----+------+
450END
451
452.testcase 564
453.mode column --escape off
454SELECT 'a'||char(7)||'b' AS x, 'xyz'||char(8) AS y;
455.check <<END
456 x y
457--- ----
458a␇b xyz␈
459END
460
461# A title wider than the value never wrapped, and still does not.
462.testcase 565
463.mode box --escape off --titlelimit 20
464SELECT 'a'||char(7)||'b' AS 'a long title';
465.check <<END
466╭──────────────╮
467│ a long title │
468╞══════════════╡
469│ a␇b │
470╰──────────────╯
471END
472
473# Control characters combined with a width limit.
474.testcase 566
475.mode box --escape off --wrap 4
476SELECT 'ab'||char(7)||'cd'||char(8)||'ef' AS x;
477.check <<END
478╭──────╮
479│ x │
480╞══════╡
481│ ab␇ │
482│ cd␈ │
483│ ef │
484╰──────╯
485END
486.mode line --titlelimit 3 --wrap 0 --escape auto
487
488# The nLineLimit and nTitleLimit fields of sqlite3_qrf_spec are 16-bit.
489# A large value for --linelimit or --titlelimit must not wrap around into
490# a small one. Bug 2026-11-05T22:26:14Z.
491#
492.testcase 570
493.mode box --titlelimit 20
494SELECT 1 AS abcdefghij;
495.check <<END
496╭────────────╮
497│ abcdefghij │
498╞════════════╡
499│ 1 │
500╰────────────╯
501END
502
503.testcase 571
504.mode box --titlelimit 65540
505SELECT 1 AS abcdefghij;
506.check <<END
507╭────────────╮
508│ abcdefghij │
509╞════════════╡
510│ 1 │
511╰────────────╯
512END
513
514.testcase 572
515.mode box --linelimit 20
516SELECT 'abc'||char(10)||'def'||char(10)||'ghi' AS x;
517.check <<END
518╭─────╮
519│ x │
520╞═════╡
521│ abc │
522│ def │
523│ ghi │
524╰─────╯
525END
526
527.testcase 573
528.mode box --linelimit 65537
529SELECT 'abc'||char(10)||'def'||char(10)||'ghi' AS x;
530.check <<END
531╭─────╮
532│ x │
533╞═════╡
534│ abc │
535│ def │
536│ ghi │
537╰─────╯
538END
539
540# Values that do not fit in 32 bits, and values that wrap to a negative
541# 16-bit number.
542.testcase 574
543.mode box --titlelimit 4294967297 --linelimit 4294967297
544SELECT 1 AS abcdefghij, 'abc'||char(10)||'def'||char(10)||'ghi' AS x;
545.check <<END
546╭────────────┬─────╮
547│ abcdefghij │ x │
548╞════════════╪═════╡
549│ 1 │ abc │
550│ │ def │
551│ │ ghi │
552╰────────────┴─────╯
553END
554
555.testcase 575
556.mode box --titlelimit 32769 --linelimit 32769
557SELECT 1 AS abcdefghij, 'abc'||char(10)||'def'||char(10)||'ghi' AS x;
558.check <<END
559╭────────────┬─────╮
560│ abcdefghij │ x │
561╞════════════╪═════╡
562│ 1 │ abc │
563│ │ def │
564│ │ ghi │
565╰────────────┴─────╯
566END
567
568# The --limits option has the same problem.
569.testcase 576
570.mode box --limits 65537,0,65540
571SELECT 1 AS abcdefghij, 'abc'||char(10)||'def'||char(10)||'ghi' AS x;
572.check <<END
573╭────────────┬─────╮
574│ abcdefghij │ x │
575╞════════════╪═════╡
576│ 1 │ abc │
577│ │ def │
578│ │ ghi │
579╰────────────┴─────╯
580END
581
582# Small values are unaffected.
583.testcase 577
584.mode box --titlelimit 4 --linelimit 1
585SELECT 1 AS abcdefghij, 'abc'||char(10)||'def'||char(10)||'ghi' AS x;
586.check <<END
587╭──────┬─────╮
588│ a... │ x │
589╞══════╪═════╡
590│ 1 │ abc │
591│ │ ... │
592╰──────┴─────╯
593END
594.mode line --titlelimit 3 --linelimit 5
595
596# line --screenwidth and --colsep
597#
598.testcase 550
599.mode line --sw 40 --colsep ":-hi-:"
600SELECT a AS 'abc', b FROM t2 WHERE c=3;
601.check <<END
602abc:-hi-:The quick fox jumps over the
603 lazy brown dog
604 b:-hi-:2
605END
606.testcase 551
607.mode line --sw 40 --colsep ":-hi-:" --wordwrap off
608SELECT a AS 'abc', b FROM t2 WHERE c=3;
609.check <<END
610abc:-hi-:The quick fox jumps over the la
611 zy brown dog
612 b:-hi-:2
613END
614# 23456789 123456789 123456789 123456789
615
616# line mode when a column name is wider than the screen width. The value
617# must still be shown, two characters per line, rather than looping.
618# https://sqlite.org/bugs/info/f8dda85c2edf5565
619#
620.testcase 560
621.mode line --sw 10 --titlelimit 0
622SELECT 'abc' AS averyveryverylongcolumnname;
623.check <<END
624averyveryverylongcolumnname: ab
625 c
626END
627.testcase 561
628.mode line --sw 10 --linelimit 4 --titlelimit 0
629SELECT 'abc' AS averyveryverylongcolumnname;
630.check <<END
631averyveryverylongcolumnname: ab
632 c
633END
634# A double-width character with a screen width too narrow to hold it.
635.testcase 562
636.mode line --sw 4
637SELECT unistr('中文') AS a;
638.check <<END
639a: 中
640 文
641END
642
643# https://sqlite.org/forum/forumpost/2025-12-31T19:14:24z
644#
645# For legacy compatibility, ".header" settings are not changed
646# by ".mode" unless the --title or --reset option is used on .mode.
647#
648.testcase 600
649DROP TABLE IF EXISTS t1;
650CREATE TABLE t1(a,b,c);
651INSERT INTO t1 VALUES(1,2,3);
652.header on
653.mode csv
654SELECT * FROM t1;
655.check --glob *a,b,c*
656
657.testcase 601
658SELECT 'abc',char(0x05,0x18,0x33),'xyz';
659.check --glob *abc,"??3",xyz*
660
661.testcase 610
662.mode csv -reset
663SELECT * FROM t1;
664.check 1,2,3
665
666.testcase 620
667.mode tty
668.mode csv
669.header on
670SELECT * FROM t1;
671.check --glob a,b,c*
672
673.testcase 630
674.mode tty
675.mode csv --title on
676SELECT * FROM t1;
677.check --glob a,b,c*
678.testcase 631
679.mode tty
680.mode csv --title off
681SELECT * FROM t1;
682.check 1,2,3
683
684.testcase 640
685.mode csv --reset --colsep "^" --rowsep "::"
686SELECT 1, 2, 3 UNION ALL SELECT 'a','b','c';
687.check 1^2^3::a^b^c::
688
689# Verification of claims about .insert mode in the climode.html
690# documentation.
691.testcase 700
692CREATE TABLE tbl1(one,two);
693INSERT INTO tbl1 VALUES('hello!',10),('goodbye',20);
694.mode insert new_table --multiinsert 0
695SELECT * FROM tbl1;
696.check <<END
697INSERT INTO new_table VALUES('hello!',10);
698INSERT INTO new_table VALUES('goodbye',20);
699END
700.testcase 710
701.mode insert new_table --titles on
702SELECT * FROM tbl1;
703.check <<END
704INSERT INTO new_table(one,two) VALUES('hello!',10);
705INSERT INTO new_table(one,two) VALUES('goodbye',20);
706END
707.testcase 720
708.mode insert new_table --titles off
709SELECT * FROM tbl1;
710.check <<END
711INSERT INTO new_table VALUES('hello!',10);
712INSERT INTO new_table VALUES('goodbye',20);
713END
714.testcase 730
715.mode insert new_table --titles always --rowcount on
716SELECT * FROM tbl1;
717.check <<END
718INSERT INTO new_table(one,two) VALUES('hello!',10);
719INSERT INTO new_table(one,two) VALUES('goodbye',20);
720/* 2 rows inserted */
721END
722.testcase 740
723.mode insert new_table --titles always --rowcount on
724SELECT * FROM tbl1 WHERE two<0;
725.check <<END
726/* 0 rows inserted */
727END
728.testcase 750
729.mode insert new_table --titles always --rowcount on
730SELECT * FROM tbl1 WHERE two<15;
731.check <<END
732INSERT INTO new_table(one,two) VALUES('hello!',10);
733/* 1 row inserted */
734END
735
736# QRF reports an error if the string is too big.
737#
738.testcase 800
739.mode box
740.limit length 1000
741WITH c(n) AS (VALUES(1) UNION ALL SELECT n+1 FROM c WHERE n<100)
742SELECT hex(randomblob(100)) c;
743.check -glob "*: string or blob too big"
744.limit length 10000000
745
746# "psql" mode.
747#
748.testcase 900
749.mode --reset psql -v
750.check <<END
751.mode psql --align "" --border off --blob-quote auto --colsep "" --escape auto --fpfmt auto --ifmt auto --limits off --multiinsert 0 --null "" --quote off --rowcount on --rowsep "" --sw 0 --tablename "" --textjsonb off --titles always --widths "" --wordwrap off
752END
753.testcase 901
754.mode
755.check <<END
756.mode psql
757END
758.testcase 902
759.mode --rowcount off
760.mode
761.check <<END
762.mode psql --rowcount off
763END
764.testcase 910
765.mode psql --reset
766DROP TABLE IF EXISTS t1;
767CREATE TABLE t1(ab INT, text_column TEXT, int_col INT);
768SELECT * FROM t1;
769.check <<END
770 ab | text_column | int_col
771----+-------------+---------
772(0 rows)
773END
774.testcase 911
775INSERT INTO t1 VALUES(31415926,'Hello',99);
776SELECT * FROM t1;
777.check <<END
778 ab | text_column | int_col
779----------+-------------+---------
780 31415926 | Hello | 99
781(1 row)
782END
783.testcase 912
784INSERT INTO t1 VALUES(2,NULL,2);
785SELECT * FROM t1;
786.check <<END
787 ab | text_column | int_col
788----------+-------------+---------
789 31415926 | Hello | 99
790 2 | | 2
791(2 rows)
792END
793
794# Variations on ".mode -title"
795#
796DROP TABLE IF EXISTS t1;
797CREATE TABLE t1("a b", "c'""<""'d", "xyz", "123");
798.testcase 1000
799.mode box -reset -title off -title plain
800SELECT * FROM t1;
801.check <<END
802╭─────┬─────────┬─────┬─────╮
803│ a b │ c'"<"'d │ xyz │ 123 │
804╘═════╧═════════╧═════╧═════╛
805END
806.testcase 1001
807.mode -title off -title sql
808SELECT * FROM t1;
809.check <<END
810╭───────┬─────────────┬───────┬───────╮
811│ 'a b' │ 'c''"<"''d' │ 'xyz' │ '123' │
812╘═══════╧═════════════╧═══════╧═══════╛
813END
814.testcase 1002
815.mode -title off -title csv
816SELECT * FROM t1;
817.check <<END
818╭───────┬─────────────┬─────┬─────╮
819│ "a b" │ "c'""<""'d" │ xyz │ 123 │
820╘═══════╧═════════════╧═════╧═════╛
821END
822.testcase 1003
823.mode -title off -title html
824SELECT * FROM t1;
825.check <<END
826╭─────┬──────────────────────────────┬─────┬─────╮
827│ a b │ c&#39;&quot;&lt;&quot;&#39;d │ xyz │ 123 │
828╘═════╧══════════════════════════════╧═════╧═════╛
829END
830.testcase 1003b
831.mode -title off -title html -title off --title always
832SELECT * FROM t1;
833.check <<END
834╭─────┬──────────────────────────────┬─────┬─────╮
835│ a b │ c&#39;&quot;&lt;&quot;&#39;d │ xyz │ 123 │
836╘═════╧══════════════════════════════╧═════╧═════╛
837END
838.testcase 1003c
839.show
840.check --glob "*headers: always*"
841.testcase 1004
842.mode -title off -title tcl
843SELECT * FROM t1;
844.check <<END
845╭───────┬─────────────┬───────┬───────╮
846│ "a b" │ "c'\"<\"'d" │ "xyz" │ "123" │
847╘═══════╧═════════════╧═══════╧═══════╛
848END
849.testcase 1005
850.mode -title off -title json
851SELECT * FROM t1;
852.check <<END
853╭───────┬─────────────┬───────┬───────╮
854│ "a b" │ "c'\"<\"'d" │ "xyz" │ "123" │
855╘═══════╧═════════════╧═══════╧═══════╛
856END
857.testcase 1006
858.mode -title on -title json
859SELECT * FROM t1;
860.check ""
861.testcase 1007
862.mode -title on -title json -title auto
863SELECT * FROM t1;
864.check <<END
865╭─────┬─────────┬─────┬─────╮
866│ a b │ c'"<"'d │ xyz │ 123 │
867╘═════╧═════════╧═════╧═════╛
868END
869.testcase 1008
870.mode -title off -title json
871.headers always
872SELECT * FROM t1;
873.check <<END
874╭─────┬─────────┬─────┬─────╮
875│ a b │ c'"<"'d │ xyz │ 123 │
876╘═════╧═════════╧═════╧═════╛
877END
878.testcase 1100
879.mode -reset -fpfmt %.2f -ifmt %,d
880WITH RECURSIVE c(n) AS (VALUES(0.01) UNION ALL SELECT n*10 FROM c WHERE n<1e8)
881SELECT pi()*n, CAST(pi()*n AS INT) FROM c;
882.check <<END
883╭──────────────┬─────────────────────╮
884│ pi()*n │ CAST(pi()*n AS INT) │
885╞══════════════╪═════════════════════╡
886│ 0.03 │ 0 │
887│ 0.31 │ 0 │
888│ 3.14 │ 3 │
889│ 31.42 │ 31 │
890│ 314.16 │ 314 │
891│ 3141.59 │ 3,141 │
892│ 31415.93 │ 31,415 │
893│ 314159.27 │ 314,159 │
894│ 3141592.65 │ 3,141,592 │
895│ 31415926.54 │ 31,415,926 │
896│ 314159265.36 │ 314,159,265 │
897╰──────────────┴─────────────────────╯
898END
899.testcase 1101
900.mode -fpfmt %+,0.2f -ifmt %04x
901WITH RECURSIVE c(n) AS (VALUES(0.01) UNION ALL SELECT n*10 FROM c WHERE n<1e8)
902SELECT pi()*n, CAST(pi()*n AS INT) FROM c;
903.check <<END
904╭─────────────────┬─────────────────────╮
905│ pi()*n │ CAST(pi()*n AS INT) │
906╞═════════════════╪═════════════════════╡
907│ +0.03 │ 0000 │
908│ +0.31 │ 0000 │
909│ +3.14 │ 0003 │
910│ +31.42 │ 001f │
911│ +314.16 │ 013a │
912│ +3,141.59 │ 0c45 │
913│ +31,415.93 │ 7ab7 │
914│ +314,159.27 │ 4cb2f │
915│ +3,141,592.65 │ 2fefd8 │
916│ +31,415,926.54 │ 1df5e76 │
917│ +314,159,265.36 │ 12b9b0a1 │
918╰─────────────────┴─────────────────────╯
919END
920.testcase 1102
921.mode -fpfmt %.6e -ifmt %#+o
922WITH RECURSIVE c(n) AS (VALUES(0.01) UNION ALL SELECT n*10 FROM c WHERE n<1e8)
923SELECT pi()*n, CAST(pi()*n AS INT) FROM c;
924.check <<END
925╭──────────────┬─────────────────────╮
926│ pi()*n │ CAST(pi()*n AS INT) │
927╞══════════════╪═════════════════════╡
928│ 3.141593e-02 │ 0 │
929│ 3.141593e-01 │ 0 │
930│ 3.141593e+00 │ 03 │
931│ 3.141593e+01 │ 037 │
932│ 3.141593e+02 │ 0472 │
933│ 3.141593e+03 │ 06105 │
934│ 3.141593e+04 │ 075267 │
935│ 3.141593e+05 │ 01145457 │
936│ 3.141593e+06 │ 013767730 │
937│ 3.141593e+07 │ 0167657166 │
938│ 3.141593e+08 │ 02256330241 │
939╰──────────────┴─────────────────────╯
940END
941.testcase 1103
942.mode -fpfmt auto -ifmt auto
943WITH RECURSIVE c(n) AS (VALUES(1) UNION ALL SELECT n*10 FROM c WHERE n<1e4)
944SELECT pi()*n, CAST(pi()*n AS INT) FROM c;
945.check <<END
946╭────────────────────┬─────────────────────╮
947│ pi()*n │ CAST(pi()*n AS INT) │
948╞════════════════════╪═════════════════════╡
949│ 3.1415926535897931 │ 3 │
950│ 31.415926535897931 │ 31 │
951│ 314.15926535897933 │ 314 │
952│ 3141.5926535897929 │ 3141 │
953│ 31415.926535897932 │ 31415 │
954╰────────────────────┴─────────────────────╯
955END
956.testcase 1104
957.mode -fpfmt %d
958.check <<END
959Error: .mode -fpfmt %d
960Error: ^--- not a valid floating-point format
961END
962.testcase 1105
963.mode -fpfmt xyz
964.check <<END
965Error: .mode -fpfmt xyz
966Error: ^--- not a valid floating-point format
967END
968.testcase 1106
969.mode -fpfmt %1234f
970.check <<END
971Error: .mode -fpfmt %1234f
972Error: ^--- not a valid floating-point format
973END
974.testcase 1107
975.mode -fpfmt %.1234f
976.check <<END
977Error: .mode -fpfmt %.1234f
978Error: ^--- not a valid floating-point format
979END
980.testcase 1108
981.mode -fpfmt %?.2f
982.check <<END
983Error: .mode -fpfmt %?.2f
984Error: ^--- not a valid floating-point format
985END
986.testcase 1109
987.mode -ifmt %.2f
988.check <<END
989Error: .mode -ifmt %.2f
990Error: ^--- not a valid integer format
991END
992.testcase 1110
993.mode list -ifmt %x
994SELECT 123;
995.check 7b
996.testcase 1111
997.mode list -ifmt %X
998SELECT 123;
999.check 7B
1000.testcase 1112
1001.mode list -fpfmt %g
1002SELECT 1.23456789e+12;
1003.check 1.23457e+12
1004.testcase 1113
1005.mode list -fpfmt %G
1006SELECT 1.23456789e+12;
1007.check 1.23457E+12
1008.testcase 1114
1009.mode list -fpfmt "" -ifmt ""
1010SELECT 1.25e+12, 0x1234;
1011.check 1250000000000.0|4660
1012
1013# Bug 2026-10-04T05:35:43Z
1014#
1015.testcase 1200
1016.mode jobject --fpfmt auto
1017SELECT 1 AS a, +9.0e+999 AS b, -9.0e+999 AS c, 0.0 AS d;
1018.check {"a":1,"b":9.0e+999,"c":-9.0e+999,"d":0.0}
1019.open :memory:
1020.testcase 1210
1021CREATE TABLE t1(a);
1022INSERT INTO t1 VALUES(123),(9e999),('hello'),(-9e999),(x'313233');
1023.dump
1024.check <<END
1025PRAGMA foreign_keys=OFF;
1026BEGIN TRANSACTION;
1027CREATE TABLE t1(a);
1028INSERT INTO t1 VALUES(123);
1029INSERT INTO t1 VALUES(9.0e+999);
1030INSERT INTO t1 VALUES('hello');
1031INSERT INTO t1 VALUES(-9.0e+999);
1032INSERT INTO t1 VALUES(x'313233');
1033COMMIT;
1034END
1035
1036# Bug 2026-10-17T09:26:21Z
1037#
1038.testcase 1300
1039.mode box --title html --limits on
1040SELECT '' AS '';
1041.check <<END
1042╭──╮
1043│ │
1044╞══╡
1045│ │
1046╰──╯
1047END
1048
1049# Bug 2026-10-18T20:39:22Z
1050#
1051# .dump should not be affected by the --fpfmt, --ifmt, and --textjsonb
1052# settings of .mode
1053#
1054.open :memory:
1055.testcase 1400
1056CREATE TABLE t1(a,b,c);
1057INSERT INTO t1 VALUES(1234.5678, 16, jsonb('{"a":1}'));
1058INSERT INTO t1 VALUES(0.5, 1234567, x'0102');
1059.mode list --fpfmt %.2f --ifmt %x --textjsonb on
1060.dump
1061.check <<END
1062PRAGMA foreign_keys=OFF;
1063BEGIN TRANSACTION;
1064CREATE TABLE t1(a,b,c);
1065INSERT INTO t1 VALUES(1234.5678,16,x'4c17611331');
1066INSERT INTO t1 VALUES(0.5,1234567,x'0102');
1067COMMIT;
1068END
1069.testcase 1410
1070.mode list --ifmt %,d
1071.dump
1072.check <<END
1073PRAGMA foreign_keys=OFF;
1074BEGIN TRANSACTION;
1075CREATE TABLE t1(a,b,c);
1076INSERT INTO t1 VALUES(1234.5678,16,x'4c17611331');
1077INSERT INTO t1 VALUES(0.5,1234567,x'0102');
1078COMMIT;
1079END
1080.testcase 1420
1081SELECT a, b FROM t1;
1082.check <<END
10831234.57|16
10840.50|1,234,567
1085END
1086.testcase 1430
1087.mode
1088.check ".mode list --fpfmt %.2f --ifmt %,d --limits on --textjsonb on"
1089
1090# Bug 2026-10-18T20:37:23Z
1091#
1092# Preserve full double precision for .dump and .mode insert.
1093#
1094.open :memory:
1095.testcase 1500
1096CREATE TABLE t(x REAL);
1097INSERT INTO t VALUES(1.7976931348623157e308),(0.1+0.2),(123456789.123456789);
1098.dump
1099.check <<END
1100PRAGMA foreign_keys=OFF;
1101BEGIN TRANSACTION;
1102CREATE TABLE t(x REAL);
1103INSERT INTO t VALUES(1.7976931348623157e+308);
1104INSERT INTO t VALUES(0.30000000000000004);
1105INSERT INTO t VALUES(123456789.12345679);
1106COMMIT;
1107END
1108
1109# Bug 2026-10-24T04:41:27Z
1110#
1111# Relaxed quoting must quote text values that look like real literals
1112# with no digits before the "." and text values that look like
1113# hexadecimal integer literals.
1114#
1115.open :memory:
1116.mode tty
1117.testcase 1600
1118SELECT '.5' AS a, '0.5' AS b, 0.5 AS c, '-.5' AS d, '0x10' AS e, 0x10 AS f;
1119.check <<END
1120╭──────┬───────┬─────┬───────┬────────┬────╮
1121│ a │ b │ c │ d │ e │ f │
1122╞══════╪═══════╪═════╪═══════╪════════╪════╡
1123│ '.5' │ '0.5' │ 0.5 │ '-.5' │ '0x10' │ 16 │
1124╰──────┴───────┴─────┴───────┴────────┴────╯
1125END
1126.testcase 1610
1127CREATE TABLE t2(a,b);
1128INSERT INTO t2(a,b) VALUES
1129 (1,'.5'),
1130 (1,'-.5'),
1131 (1,'+.5'),
1132 (1,'.5e3'),
1133 (1,'.5E-3'),
1134 (1,'5.'),
1135 (0,'.'),
1136 (0,'-.'),
1137 (0,'.e5'),
1138 (0,'.5.5'),
1139 (0,'.5x'),
1140 (0,'.5e'),
1141 (1,'0x1F'),
1142 (1,'0X1f'),
1143 (1,'-0x10'),
1144 (1,'+0xabcdef'),
1145 (0,'0x'),
1146 (0,'0x1G'),
1147 (0,'0x1.5'),
1148 (0,'x10'),
1149 (0,'1x10');
1150SELECT if(a,'yes','') AS 'quoted?', b AS string FROM t2 ORDER BY rowid;
1151.check <<END
1152╭─────────┬─────────────╮
1153│ quoted? │ string │
1154╞═════════╪═════════════╡
1155│ yes │ '.5' │
1156│ yes │ '-.5' │
1157│ yes │ '+.5' │
1158│ yes │ '.5e3' │
1159│ yes │ '.5E-3' │
1160│ yes │ '5.' │
1161│ │ . │
1162│ │ -. │
1163│ │ .e5 │
1164│ │ .5.5 │
1165│ │ .5x │
1166│ │ .5e │
1167│ yes │ '0x1F' │
1168│ yes │ '0X1f' │
1169│ yes │ '-0x10' │
1170│ yes │ '+0xabcdef' │
1171│ │ 0x │
1172│ │ 0x1G │
1173│ │ 0x1.5 │
1174│ │ x10 │
1175│ │ 1x10 │
1176╰─────────┴─────────────╯
1177END