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