sqlite
[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.
Brought by drakestapleton
| 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: |
| 21 | CREATE TABLE t1(a,b,c,d,e); |
| 22 | INSERT INTO t1 VALUES(1,2.5,'three',x'4444',NULL); |
| 23 | INSERT INTO t1 SELECT b,c,d,e,a FROM t1; |
| 24 | INSERT INTO t1 SELECT d,e,a,b,c FROM t1; |
| 25 | .mode box |
| 26 | |
| 27 | .testcase 100 |
| 28 | SELECT * 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 | ╰─────┴───────┴───────┴───────┴───────╯ |
| 38 | END |
| 39 | |
| 40 | .testcase 110 |
| 41 | .mode --null xyz |
| 42 | SELECT * 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 | ╰─────┴───────┴───────┴───────┴───────╯ |
| 52 | END |
| 53 | |
| 54 | # Default output mode is qbox --quote relaxed |
| 55 | # |
| 56 | .mode tty --wrap 10 |
| 57 | CREATE TABLE t2(a,b,c,d); |
| 58 | INSERT INTO t2 VALUES(1,2.5,'three',x'4444'); |
| 59 | INSERT INTO t2 VALUES('The quick fox jumps over the lazy brown dog',2,3,4); |
| 60 | INSERT INTO t2 VALUES('10','', -1.25,NULL); |
| 61 | INSERT INTO t2 VALUES('a,b,c','"Double-Quoted"','-1.25','NULL'); |
| 62 | .testcase 120 |
| 63 | SELECT * 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 | ╰────────────┴────────────┴─────────┴─────────╯ |
| 81 | END |
| 82 | .testcase 121 |
| 83 | .mode tty --wrap 1 --limits off |
| 84 | SELECT '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 | ╰───┴───╯ |
| 96 | END |
| 97 | .testcase 130 |
| 98 | .mode tty -wrap 10 |
| 99 | .mode |
| 100 | .check <<END |
| 101 | .mode qbox --limits on --quote relaxed --sw auto --textjsonb on |
| 102 | END |
| 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 |
| 107 | END |
| 108 | .testcase 150 --error-prefix "Error:" |
| 109 | .mode foo |
| 110 | .check <<END |
| 111 | Error: .mode foo |
| 112 | Error: ^--- unknown mode |
| 113 | Error: Use ".help .mode" for more info |
| 114 | END |
| 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 |
| 126 | EXPLAIN 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 |
| 132 | EXPLAIN QUERY PLAN SELECT * FROM t1; |
| 133 | .check --glob "*`--SCAN *" |
| 134 | .explain off |
| 135 | .testcase 200 |
| 136 | EXPLAIN SELECT * FROM t1; |
| 137 | .check --regexp ──── |
| 138 | .testcase 210 |
| 139 | EXPLAIN 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 |
| 149 | END |
| 150 | .testcase 310 |
| 151 | .mode --limits 5,300,20 |
| 152 | .mode |
| 153 | .check <<END |
| 154 | .mode box --limits on |
| 155 | END |
| 156 | .testcase 320 |
| 157 | .mode --limits 5,300,19 |
| 158 | .mode |
| 159 | .check <<END |
| 160 | .mode box --limits 5,300,19 |
| 161 | END |
| 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 |
| 167 | END |
| 168 | |
| 169 | .testcase 400 |
| 170 | .mode --linelimit 123 |
| 171 | .mode |
| 172 | .check <<END |
| 173 | .mode box --limits 123,0,0 |
| 174 | END |
| 175 | |
| 176 | .testcase 410 |
| 177 | .mode --linelimit 0 -charlimit 123 |
| 178 | .mode |
| 179 | .check <<END |
| 180 | .mode box --limits 0,123,0 |
| 181 | END |
| 182 | |
| 183 | .testcase 420 |
| 184 | .mode --charlimit 0 -titlelimit 123 |
| 185 | .mode |
| 186 | .check <<END |
| 187 | .mode box --limits 0,0,123 |
| 188 | END |
| 189 | |
| 190 | .testcase 430 |
| 191 | .mode list |
| 192 | .mode |
| 193 | .check <<END |
| 194 | .mode list |
| 195 | END |
| 196 | |
| 197 | .testcase 440 |
| 198 | .mode -limits 0,123,0 |
| 199 | .mode |
| 200 | .check <<END |
| 201 | .mode list --limits 0,123,0 |
| 202 | END |
| 203 | |
| 204 | .testcase 450 |
| 205 | .mode -limits 123,0,0 |
| 206 | .mode |
| 207 | .check <<END |
| 208 | .mode list |
| 209 | END |
| 210 | |
| 211 | # --titlelimit functionality |
| 212 | # |
| 213 | .testcase 500 |
| 214 | .mode line --limits off --titlelimit 20 |
| 215 | SELECT a AS 'abcdefghijklmnopqrstuvwxyz', b FROM t2 WHERE c=3; |
| 216 | .check <<END |
| 217 | abcdefghijklmnopq...: The quick fox jumps over the lazy brown dog |
| 218 | b: 2 |
| 219 | END |
| 220 | .testcase 501 |
| 221 | SELECT a AS 'a bc', b AS 'b |
| 222 | c |
| 223 | d' FROM t2 WHERE c=3; |
| 224 | .check <<END |
| 225 | a bc: The quick fox jumps over the lazy brown dog |
| 226 | b c d: 2 |
| 227 | END |
| 228 | .testcase 510 |
| 229 | .mode line --titlelimit 10 |
| 230 | SELECT a AS 'abcdefghijklmnopqrstuvwxyz', b FROM t2 WHERE c=3; |
| 231 | .check <<END |
| 232 | abcdefg...: The quick fox jumps over the lazy brown dog |
| 233 | b: 2 |
| 234 | END |
| 235 | .testcase 520 |
| 236 | .mode line --titlelimit 2 |
| 237 | SELECT a AS 'abcdefghijklmnopqrstuvwxyz', b FROM t2 WHERE c=3; |
| 238 | .check <<END |
| 239 | ab: The quick fox jumps over the lazy brown dog |
| 240 | b: 2 |
| 241 | END |
| 242 | .testcase 530 |
| 243 | .mode line --titlelimit 4 |
| 244 | SELECT a AS 'abcd', b FROM t2 WHERE c=3; |
| 245 | .check <<END |
| 246 | abcd: The quick fox jumps over the lazy brown dog |
| 247 | b: 2 |
| 248 | END |
| 249 | .testcase 540 |
| 250 | .mode line --titlelimit 3 |
| 251 | SELECT 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 |
| 255 | END |
| 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 |
| 262 | SELECT 1 AS 'abcdefghij', 2 AS 'éééééééééé'; |
| 263 | .check <<END |
| 264 | ╭────────────┬────────────╮ |
| 265 | │ abcdefghij │ éééééééééé │ |
| 266 | ╞════════════╪════════════╡ |
| 267 | │ 1 │ 2 │ |
| 268 | ╰────────────┴────────────╯ |
| 269 | END |
| 270 | # nine characters fit |
| 271 | .testcase 542 |
| 272 | .mode box --titlelimit 10 |
| 273 | SELECT 1 AS 'abcdefghi', 2 AS 'ééééééééé'; |
| 274 | .check <<END |
| 275 | ╭───────────┬───────────╮ |
| 276 | │ abcdefghi │ ééééééééé │ |
| 277 | ╞═══════════╪═══════════╡ |
| 278 | │ 1 │ 2 │ |
| 279 | ╰───────────┴───────────╯ |
| 280 | END |
| 281 | # eleven characters are truncated to seven plus an ellipsis |
| 282 | .testcase 543 |
| 283 | .mode box --titlelimit 10 |
| 284 | SELECT 1 AS 'abcdefghijk', 2 AS 'ééééééééééé'; |
| 285 | .check <<END |
| 286 | ╭────────────┬────────────╮ |
| 287 | │ abcdefg... │ ééééééé... │ |
| 288 | ╞════════════╪════════════╡ |
| 289 | │ 1 │ 2 │ |
| 290 | ╰────────────┴────────────╯ |
| 291 | END |
| 292 | # multi-byte characters at the end of the title |
| 293 | .testcase 544 |
| 294 | .mode box --titlelimit 10 |
| 295 | SELECT 1 AS 'éééééééééz', 2 AS 'zééééééééé'; |
| 296 | .check <<END |
| 297 | ╭────────────┬────────────╮ |
| 298 | │ éééééééééz │ zééééééééé │ |
| 299 | ╞════════════╪════════════╡ |
| 300 | │ 1 │ 2 │ |
| 301 | ╰────────────┴────────────╯ |
| 302 | END |
| 303 | # three-byte characters |
| 304 | .testcase 545 |
| 305 | .mode box --titlelimit 10 |
| 306 | SELECT 1 AS '€€€€€€€€€', 2 AS '€€€€€€€€€€'; |
| 307 | .check <<END |
| 308 | ╭───────────┬────────────╮ |
| 309 | │ €€€€€€€€€ │ €€€€€€€€€€ │ |
| 310 | ╞═══════════╪════════════╡ |
| 311 | │ 1 │ 2 │ |
| 312 | ╰───────────┴────────────╯ |
| 313 | END |
| 314 | # double-width characters; truncation must account for their width |
| 315 | .testcase 546 |
| 316 | .mode box --titlelimit 10 |
| 317 | SELECT 1 AS '安安安安安安', 2 AS 'a安安安安安安'; |
| 318 | .check <<END |
| 319 | ╭───────────┬────────────╮ |
| 320 | │ 安安安... │ a安安安... │ |
| 321 | ╞═══════════╪════════════╡ |
| 322 | │ 1 │ 2 │ |
| 323 | ╰───────────┴────────────╯ |
| 324 | END |
| 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 |
| 332 | SELECT NULL AS n; |
| 333 | .check <<END |
| 334 | <tr> |
| 335 | <th>n |
| 336 | </tr> |
| 337 | <tr> |
| 338 | <td>null |
| 339 | </tr> |
| 340 | END |
| 341 | |
| 342 | .testcase 551 |
| 343 | .mode html --null XX |
| 344 | SELECT NULL AS n; |
| 345 | .check <<END |
| 346 | <tr> |
| 347 | <th>n |
| 348 | </tr> |
| 349 | <tr> |
| 350 | <td>XX |
| 351 | </tr> |
| 352 | END |
| 353 | |
| 354 | .testcase 552 |
| 355 | .nullvalue YY |
| 356 | SELECT NULL AS n; |
| 357 | .check <<END |
| 358 | <tr> |
| 359 | <th>n |
| 360 | </tr> |
| 361 | <tr> |
| 362 | <td>YY |
| 363 | </tr> |
| 364 | END |
| 365 | |
| 366 | .testcase 553 |
| 367 | .nullvalue |
| 368 | SELECT 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> |
| 375 | SELECT NULL AS n, 'null' AS m; |
| 376 | .check <<END |
| 377 | <tr> |
| 378 | <th>n |
| 379 | <th>m |
| 380 | </tr> |
| 381 | <tr> |
| 382 | <td><nil> |
| 383 | <td>null |
| 384 | </tr> |
| 385 | END |
| 386 | |
| 387 | # Switching to another mode and back restores the default for html. |
| 388 | .testcase 555 |
| 389 | .mode list --null XX |
| 390 | .mode html |
| 391 | SELECT NULL AS n; |
| 392 | .check <<END |
| 393 | <tr> |
| 394 | <th>n |
| 395 | </tr> |
| 396 | <tr> |
| 397 | <td>null |
| 398 | </tr> |
| 399 | END |
| 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 |
| 410 | SELECT 'a'||char(7)||'b' AS x; |
| 411 | .check <<END |
| 412 | ╭─────╮ |
| 413 | │ x │ |
| 414 | ╞═════╡ |
| 415 | │ a␇b │ |
| 416 | ╰─────╯ |
| 417 | END |
| 418 | |
| 419 | .testcase 561 |
| 420 | .mode box --escape symbol |
| 421 | SELECT 'a'||char(7)||'b' AS x; |
| 422 | .check <<END |
| 423 | ╭─────╮ |
| 424 | │ x │ |
| 425 | ╞═════╡ |
| 426 | │ a␇b │ |
| 427 | ╰─────╯ |
| 428 | END |
| 429 | |
| 430 | .testcase 562 |
| 431 | .mode box --escape ascii |
| 432 | SELECT 'a'||char(7)||'b' AS x; |
| 433 | .check <<END |
| 434 | ╭──────╮ |
| 435 | │ x │ |
| 436 | ╞══════╡ |
| 437 | │ a^Gb │ |
| 438 | ╰──────╯ |
| 439 | END |
| 440 | |
| 441 | .testcase 563 |
| 442 | .mode table --escape off |
| 443 | SELECT '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 | +-----+------+ |
| 450 | END |
| 451 | |
| 452 | .testcase 564 |
| 453 | .mode column --escape off |
| 454 | SELECT 'a'||char(7)||'b' AS x, 'xyz'||char(8) AS y; |
| 455 | .check <<END |
| 456 | x y |
| 457 | --- ---- |
| 458 | a␇b xyz␈ |
| 459 | END |
| 460 | |
| 461 | # A title wider than the value never wrapped, and still does not. |
| 462 | .testcase 565 |
| 463 | .mode box --escape off --titlelimit 20 |
| 464 | SELECT 'a'||char(7)||'b' AS 'a long title'; |
| 465 | .check <<END |
| 466 | ╭──────────────╮ |
| 467 | │ a long title │ |
| 468 | ╞══════════════╡ |
| 469 | │ a␇b │ |
| 470 | ╰──────────────╯ |
| 471 | END |
| 472 | |
| 473 | # Control characters combined with a width limit. |
| 474 | .testcase 566 |
| 475 | .mode box --escape off --wrap 4 |
| 476 | SELECT 'ab'||char(7)||'cd'||char(8)||'ef' AS x; |
| 477 | .check <<END |
| 478 | ╭──────╮ |
| 479 | │ x │ |
| 480 | ╞══════╡ |
| 481 | │ ab␇ │ |
| 482 | │ cd␈ │ |
| 483 | │ ef │ |
| 484 | ╰──────╯ |
| 485 | END |
| 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 |
| 494 | SELECT 1 AS abcdefghij; |
| 495 | .check <<END |
| 496 | ╭────────────╮ |
| 497 | │ abcdefghij │ |
| 498 | ╞════════════╡ |
| 499 | │ 1 │ |
| 500 | ╰────────────╯ |
| 501 | END |
| 502 | |
| 503 | .testcase 571 |
| 504 | .mode box --titlelimit 65540 |
| 505 | SELECT 1 AS abcdefghij; |
| 506 | .check <<END |
| 507 | ╭────────────╮ |
| 508 | │ abcdefghij │ |
| 509 | ╞════════════╡ |
| 510 | │ 1 │ |
| 511 | ╰────────────╯ |
| 512 | END |
| 513 | |
| 514 | .testcase 572 |
| 515 | .mode box --linelimit 20 |
| 516 | SELECT 'abc'||char(10)||'def'||char(10)||'ghi' AS x; |
| 517 | .check <<END |
| 518 | ╭─────╮ |
| 519 | │ x │ |
| 520 | ╞═════╡ |
| 521 | │ abc │ |
| 522 | │ def │ |
| 523 | │ ghi │ |
| 524 | ╰─────╯ |
| 525 | END |
| 526 | |
| 527 | .testcase 573 |
| 528 | .mode box --linelimit 65537 |
| 529 | SELECT 'abc'||char(10)||'def'||char(10)||'ghi' AS x; |
| 530 | .check <<END |
| 531 | ╭─────╮ |
| 532 | │ x │ |
| 533 | ╞═════╡ |
| 534 | │ abc │ |
| 535 | │ def │ |
| 536 | │ ghi │ |
| 537 | ╰─────╯ |
| 538 | END |
| 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 |
| 544 | SELECT 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 | ╰────────────┴─────╯ |
| 553 | END |
| 554 | |
| 555 | .testcase 575 |
| 556 | .mode box --titlelimit 32769 --linelimit 32769 |
| 557 | SELECT 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 | ╰────────────┴─────╯ |
| 566 | END |
| 567 | |
| 568 | # The --limits option has the same problem. |
| 569 | .testcase 576 |
| 570 | .mode box --limits 65537,0,65540 |
| 571 | SELECT 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 | ╰────────────┴─────╯ |
| 580 | END |
| 581 | |
| 582 | # Small values are unaffected. |
| 583 | .testcase 577 |
| 584 | .mode box --titlelimit 4 --linelimit 1 |
| 585 | SELECT 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 | ╰──────┴─────╯ |
| 593 | END |
| 594 | .mode line --titlelimit 3 --linelimit 5 |
| 595 | |
| 596 | # line --screenwidth and --colsep |
| 597 | # |
| 598 | .testcase 550 |
| 599 | .mode line --sw 40 --colsep ":-hi-:" |
| 600 | SELECT a AS 'abc', b FROM t2 WHERE c=3; |
| 601 | .check <<END |
| 602 | abc:-hi-:The quick fox jumps over the |
| 603 | lazy brown dog |
| 604 | b:-hi-:2 |
| 605 | END |
| 606 | .testcase 551 |
| 607 | .mode line --sw 40 --colsep ":-hi-:" --wordwrap off |
| 608 | SELECT a AS 'abc', b FROM t2 WHERE c=3; |
| 609 | .check <<END |
| 610 | abc:-hi-:The quick fox jumps over the la |
| 611 | zy brown dog |
| 612 | b:-hi-:2 |
| 613 | END |
| 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 |
| 622 | SELECT 'abc' AS averyveryverylongcolumnname; |
| 623 | .check <<END |
| 624 | averyveryverylongcolumnname: ab |
| 625 | c |
| 626 | END |
| 627 | .testcase 561 |
| 628 | .mode line --sw 10 --linelimit 4 --titlelimit 0 |
| 629 | SELECT 'abc' AS averyveryverylongcolumnname; |
| 630 | .check <<END |
| 631 | averyveryverylongcolumnname: ab |
| 632 | c |
| 633 | END |
| 634 | # A double-width character with a screen width too narrow to hold it. |
| 635 | .testcase 562 |
| 636 | .mode line --sw 4 |
| 637 | SELECT unistr('中文') AS a; |
| 638 | .check <<END |
| 639 | a: 中 |
| 640 | 文 |
| 641 | END |
| 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 |
| 649 | DROP TABLE IF EXISTS t1; |
| 650 | CREATE TABLE t1(a,b,c); |
| 651 | INSERT INTO t1 VALUES(1,2,3); |
| 652 | .header on |
| 653 | .mode csv |
| 654 | SELECT * FROM t1; |
| 655 | .check --glob *a,b,c* |
| 656 | |
| 657 | .testcase 601 |
| 658 | SELECT 'abc',char(0x05,0x18,0x33),'xyz'; |
| 659 | .check --glob *abc,"??3",xyz* |
| 660 | |
| 661 | .testcase 610 |
| 662 | .mode csv -reset |
| 663 | SELECT * FROM t1; |
| 664 | .check 1,2,3 |
| 665 | |
| 666 | .testcase 620 |
| 667 | .mode tty |
| 668 | .mode csv |
| 669 | .header on |
| 670 | SELECT * FROM t1; |
| 671 | .check --glob a,b,c* |
| 672 | |
| 673 | .testcase 630 |
| 674 | .mode tty |
| 675 | .mode csv --title on |
| 676 | SELECT * FROM t1; |
| 677 | .check --glob a,b,c* |
| 678 | .testcase 631 |
| 679 | .mode tty |
| 680 | .mode csv --title off |
| 681 | SELECT * FROM t1; |
| 682 | .check 1,2,3 |
| 683 | |
| 684 | .testcase 640 |
| 685 | .mode csv --reset --colsep "^" --rowsep "::" |
| 686 | SELECT 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 |
| 692 | CREATE TABLE tbl1(one,two); |
| 693 | INSERT INTO tbl1 VALUES('hello!',10),('goodbye',20); |
| 694 | .mode insert new_table --multiinsert 0 |
| 695 | SELECT * FROM tbl1; |
| 696 | .check <<END |
| 697 | INSERT INTO new_table VALUES('hello!',10); |
| 698 | INSERT INTO new_table VALUES('goodbye',20); |
| 699 | END |
| 700 | .testcase 710 |
| 701 | .mode insert new_table --titles on |
| 702 | SELECT * FROM tbl1; |
| 703 | .check <<END |
| 704 | INSERT INTO new_table(one,two) VALUES('hello!',10); |
| 705 | INSERT INTO new_table(one,two) VALUES('goodbye',20); |
| 706 | END |
| 707 | .testcase 720 |
| 708 | .mode insert new_table --titles off |
| 709 | SELECT * FROM tbl1; |
| 710 | .check <<END |
| 711 | INSERT INTO new_table VALUES('hello!',10); |
| 712 | INSERT INTO new_table VALUES('goodbye',20); |
| 713 | END |
| 714 | .testcase 730 |
| 715 | .mode insert new_table --titles always --rowcount on |
| 716 | SELECT * FROM tbl1; |
| 717 | .check <<END |
| 718 | INSERT INTO new_table(one,two) VALUES('hello!',10); |
| 719 | INSERT INTO new_table(one,two) VALUES('goodbye',20); |
| 720 | /* 2 rows inserted */ |
| 721 | END |
| 722 | .testcase 740 |
| 723 | .mode insert new_table --titles always --rowcount on |
| 724 | SELECT * FROM tbl1 WHERE two<0; |
| 725 | .check <<END |
| 726 | /* 0 rows inserted */ |
| 727 | END |
| 728 | .testcase 750 |
| 729 | .mode insert new_table --titles always --rowcount on |
| 730 | SELECT * FROM tbl1 WHERE two<15; |
| 731 | .check <<END |
| 732 | INSERT INTO new_table(one,two) VALUES('hello!',10); |
| 733 | /* 1 row inserted */ |
| 734 | END |
| 735 | |
| 736 | # QRF reports an error if the string is too big. |
| 737 | # |
| 738 | .testcase 800 |
| 739 | .mode box |
| 740 | .limit length 1000 |
| 741 | WITH c(n) AS (VALUES(1) UNION ALL SELECT n+1 FROM c WHERE n<100) |
| 742 | SELECT 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 |
| 752 | END |
| 753 | .testcase 901 |
| 754 | .mode |
| 755 | .check <<END |
| 756 | .mode psql |
| 757 | END |
| 758 | .testcase 902 |
| 759 | .mode --rowcount off |
| 760 | .mode |
| 761 | .check <<END |
| 762 | .mode psql --rowcount off |
| 763 | END |
| 764 | .testcase 910 |
| 765 | .mode psql --reset |
| 766 | DROP TABLE IF EXISTS t1; |
| 767 | CREATE TABLE t1(ab INT, text_column TEXT, int_col INT); |
| 768 | SELECT * FROM t1; |
| 769 | .check <<END |
| 770 | ab | text_column | int_col |
| 771 | ----+-------------+--------- |
| 772 | (0 rows) |
| 773 | END |
| 774 | .testcase 911 |
| 775 | INSERT INTO t1 VALUES(31415926,'Hello',99); |
| 776 | SELECT * FROM t1; |
| 777 | .check <<END |
| 778 | ab | text_column | int_col |
| 779 | ----------+-------------+--------- |
| 780 | 31415926 | Hello | 99 |
| 781 | (1 row) |
| 782 | END |
| 783 | .testcase 912 |
| 784 | INSERT INTO t1 VALUES(2,NULL,2); |
| 785 | SELECT * FROM t1; |
| 786 | .check <<END |
| 787 | ab | text_column | int_col |
| 788 | ----------+-------------+--------- |
| 789 | 31415926 | Hello | 99 |
| 790 | 2 | | 2 |
| 791 | (2 rows) |
| 792 | END |
| 793 | |
| 794 | # Variations on ".mode -title" |
| 795 | # |
| 796 | DROP TABLE IF EXISTS t1; |
| 797 | CREATE TABLE t1("a b", "c'""<""'d", "xyz", "123"); |
| 798 | .testcase 1000 |
| 799 | .mode box -reset -title off -title plain |
| 800 | SELECT * FROM t1; |
| 801 | .check <<END |
| 802 | ╭─────┬─────────┬─────┬─────╮ |
| 803 | │ a b │ c'"<"'d │ xyz │ 123 │ |
| 804 | ╘═════╧═════════╧═════╧═════╛ |
| 805 | END |
| 806 | .testcase 1001 |
| 807 | .mode -title off -title sql |
| 808 | SELECT * FROM t1; |
| 809 | .check <<END |
| 810 | ╭───────┬─────────────┬───────┬───────╮ |
| 811 | │ 'a b' │ 'c''"<"''d' │ 'xyz' │ '123' │ |
| 812 | ╘═══════╧═════════════╧═══════╧═══════╛ |
| 813 | END |
| 814 | .testcase 1002 |
| 815 | .mode -title off -title csv |
| 816 | SELECT * FROM t1; |
| 817 | .check <<END |
| 818 | ╭───────┬─────────────┬─────┬─────╮ |
| 819 | │ "a b" │ "c'""<""'d" │ xyz │ 123 │ |
| 820 | ╘═══════╧═════════════╧═════╧═════╛ |
| 821 | END |
| 822 | .testcase 1003 |
| 823 | .mode -title off -title html |
| 824 | SELECT * FROM t1; |
| 825 | .check <<END |
| 826 | ╭─────┬──────────────────────────────┬─────┬─────╮ |
| 827 | │ a b │ c'"<"'d │ xyz │ 123 │ |
| 828 | ╘═════╧══════════════════════════════╧═════╧═════╛ |
| 829 | END |
| 830 | .testcase 1003b |
| 831 | .mode -title off -title html -title off --title always |
| 832 | SELECT * FROM t1; |
| 833 | .check <<END |
| 834 | ╭─────┬──────────────────────────────┬─────┬─────╮ |
| 835 | │ a b │ c'"<"'d │ xyz │ 123 │ |
| 836 | ╘═════╧══════════════════════════════╧═════╧═════╛ |
| 837 | END |
| 838 | .testcase 1003c |
| 839 | .show |
| 840 | .check --glob "*headers: always*" |
| 841 | .testcase 1004 |
| 842 | .mode -title off -title tcl |
| 843 | SELECT * FROM t1; |
| 844 | .check <<END |
| 845 | ╭───────┬─────────────┬───────┬───────╮ |
| 846 | │ "a b" │ "c'\"<\"'d" │ "xyz" │ "123" │ |
| 847 | ╘═══════╧═════════════╧═══════╧═══════╛ |
| 848 | END |
| 849 | .testcase 1005 |
| 850 | .mode -title off -title json |
| 851 | SELECT * FROM t1; |
| 852 | .check <<END |
| 853 | ╭───────┬─────────────┬───────┬───────╮ |
| 854 | │ "a b" │ "c'\"<\"'d" │ "xyz" │ "123" │ |
| 855 | ╘═══════╧═════════════╧═══════╧═══════╛ |
| 856 | END |
| 857 | .testcase 1006 |
| 858 | .mode -title on -title json |
| 859 | SELECT * FROM t1; |
| 860 | .check "" |
| 861 | .testcase 1007 |
| 862 | .mode -title on -title json -title auto |
| 863 | SELECT * FROM t1; |
| 864 | .check <<END |
| 865 | ╭─────┬─────────┬─────┬─────╮ |
| 866 | │ a b │ c'"<"'d │ xyz │ 123 │ |
| 867 | ╘═════╧═════════╧═════╧═════╛ |
| 868 | END |
| 869 | .testcase 1008 |
| 870 | .mode -title off -title json |
| 871 | .headers always |
| 872 | SELECT * FROM t1; |
| 873 | .check <<END |
| 874 | ╭─────┬─────────┬─────┬─────╮ |
| 875 | │ a b │ c'"<"'d │ xyz │ 123 │ |
| 876 | ╘═════╧═════════╧═════╧═════╛ |
| 877 | END |
| 878 | .testcase 1100 |
| 879 | .mode -reset -fpfmt %.2f -ifmt %,d |
| 880 | WITH RECURSIVE c(n) AS (VALUES(0.01) UNION ALL SELECT n*10 FROM c WHERE n<1e8) |
| 881 | SELECT 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 | ╰──────────────┴─────────────────────╯ |
| 898 | END |
| 899 | .testcase 1101 |
| 900 | .mode -fpfmt %+,0.2f -ifmt %04x |
| 901 | WITH RECURSIVE c(n) AS (VALUES(0.01) UNION ALL SELECT n*10 FROM c WHERE n<1e8) |
| 902 | SELECT 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 | ╰─────────────────┴─────────────────────╯ |
| 919 | END |
| 920 | .testcase 1102 |
| 921 | .mode -fpfmt %.6e -ifmt %#+o |
| 922 | WITH RECURSIVE c(n) AS (VALUES(0.01) UNION ALL SELECT n*10 FROM c WHERE n<1e8) |
| 923 | SELECT 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 | ╰──────────────┴─────────────────────╯ |
| 940 | END |
| 941 | .testcase 1103 |
| 942 | .mode -fpfmt auto -ifmt auto |
| 943 | WITH RECURSIVE c(n) AS (VALUES(1) UNION ALL SELECT n*10 FROM c WHERE n<1e4) |
| 944 | SELECT 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 | ╰────────────────────┴─────────────────────╯ |
| 955 | END |
| 956 | .testcase 1104 |
| 957 | .mode -fpfmt %d |
| 958 | .check <<END |
| 959 | Error: .mode -fpfmt %d |
| 960 | Error: ^--- not a valid floating-point format |
| 961 | END |
| 962 | .testcase 1105 |
| 963 | .mode -fpfmt xyz |
| 964 | .check <<END |
| 965 | Error: .mode -fpfmt xyz |
| 966 | Error: ^--- not a valid floating-point format |
| 967 | END |
| 968 | .testcase 1106 |
| 969 | .mode -fpfmt %1234f |
| 970 | .check <<END |
| 971 | Error: .mode -fpfmt %1234f |
| 972 | Error: ^--- not a valid floating-point format |
| 973 | END |
| 974 | .testcase 1107 |
| 975 | .mode -fpfmt %.1234f |
| 976 | .check <<END |
| 977 | Error: .mode -fpfmt %.1234f |
| 978 | Error: ^--- not a valid floating-point format |
| 979 | END |
| 980 | .testcase 1108 |
| 981 | .mode -fpfmt %?.2f |
| 982 | .check <<END |
| 983 | Error: .mode -fpfmt %?.2f |
| 984 | Error: ^--- not a valid floating-point format |
| 985 | END |
| 986 | .testcase 1109 |
| 987 | .mode -ifmt %.2f |
| 988 | .check <<END |
| 989 | Error: .mode -ifmt %.2f |
| 990 | Error: ^--- not a valid integer format |
| 991 | END |
| 992 | .testcase 1110 |
| 993 | .mode list -ifmt %x |
| 994 | SELECT 123; |
| 995 | .check 7b |
| 996 | .testcase 1111 |
| 997 | .mode list -ifmt %X |
| 998 | SELECT 123; |
| 999 | .check 7B |
| 1000 | .testcase 1112 |
| 1001 | .mode list -fpfmt %g |
| 1002 | SELECT 1.23456789e+12; |
| 1003 | .check 1.23457e+12 |
| 1004 | .testcase 1113 |
| 1005 | .mode list -fpfmt %G |
| 1006 | SELECT 1.23456789e+12; |
| 1007 | .check 1.23457E+12 |
| 1008 | .testcase 1114 |
| 1009 | .mode list -fpfmt "" -ifmt "" |
| 1010 | SELECT 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 |
| 1017 | SELECT 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 |
| 1021 | CREATE TABLE t1(a); |
| 1022 | INSERT INTO t1 VALUES(123),(9e999),('hello'),(-9e999),(x'313233'); |
| 1023 | .dump |
| 1024 | .check <<END |
| 1025 | PRAGMA foreign_keys=OFF; |
| 1026 | BEGIN TRANSACTION; |
| 1027 | CREATE TABLE t1(a); |
| 1028 | INSERT INTO t1 VALUES(123); |
| 1029 | INSERT INTO t1 VALUES(9.0e+999); |
| 1030 | INSERT INTO t1 VALUES('hello'); |
| 1031 | INSERT INTO t1 VALUES(-9.0e+999); |
| 1032 | INSERT INTO t1 VALUES(x'313233'); |
| 1033 | COMMIT; |
| 1034 | END |
| 1035 | |
| 1036 | # Bug 2026-10-17T09:26:21Z |
| 1037 | # |
| 1038 | .testcase 1300 |
| 1039 | .mode box --title html --limits on |
| 1040 | SELECT '' AS ''; |
| 1041 | .check <<END |
| 1042 | ╭──╮ |
| 1043 | │ │ |
| 1044 | ╞══╡ |
| 1045 | │ │ |
| 1046 | ╰──╯ |
| 1047 | END |
| 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 |
| 1056 | CREATE TABLE t1(a,b,c); |
| 1057 | INSERT INTO t1 VALUES(1234.5678, 16, jsonb('{"a":1}')); |
| 1058 | INSERT INTO t1 VALUES(0.5, 1234567, x'0102'); |
| 1059 | .mode list --fpfmt %.2f --ifmt %x --textjsonb on |
| 1060 | .dump |
| 1061 | .check <<END |
| 1062 | PRAGMA foreign_keys=OFF; |
| 1063 | BEGIN TRANSACTION; |
| 1064 | CREATE TABLE t1(a,b,c); |
| 1065 | INSERT INTO t1 VALUES(1234.5678,16,x'4c17611331'); |
| 1066 | INSERT INTO t1 VALUES(0.5,1234567,x'0102'); |
| 1067 | COMMIT; |
| 1068 | END |
| 1069 | .testcase 1410 |
| 1070 | .mode list --ifmt %,d |
| 1071 | .dump |
| 1072 | .check <<END |
| 1073 | PRAGMA foreign_keys=OFF; |
| 1074 | BEGIN TRANSACTION; |
| 1075 | CREATE TABLE t1(a,b,c); |
| 1076 | INSERT INTO t1 VALUES(1234.5678,16,x'4c17611331'); |
| 1077 | INSERT INTO t1 VALUES(0.5,1234567,x'0102'); |
| 1078 | COMMIT; |
| 1079 | END |
| 1080 | .testcase 1420 |
| 1081 | SELECT a, b FROM t1; |
| 1082 | .check <<END |
| 1083 | 1234.57|16 |
| 1084 | 0.50|1,234,567 |
| 1085 | END |
| 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 |
| 1096 | CREATE TABLE t(x REAL); |
| 1097 | INSERT INTO t VALUES(1.7976931348623157e308),(0.1+0.2),(123456789.123456789); |
| 1098 | .dump |
| 1099 | .check <<END |
| 1100 | PRAGMA foreign_keys=OFF; |
| 1101 | BEGIN TRANSACTION; |
| 1102 | CREATE TABLE t(x REAL); |
| 1103 | INSERT INTO t VALUES(1.7976931348623157e+308); |
| 1104 | INSERT INTO t VALUES(0.30000000000000004); |
| 1105 | INSERT INTO t VALUES(123456789.12345679); |
| 1106 | COMMIT; |
| 1107 | END |
| 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 |
| 1118 | SELECT '.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 | ╰──────┴───────┴─────┴───────┴────────┴────╯ |
| 1125 | END |
| 1126 | .testcase 1610 |
| 1127 | CREATE TABLE t2(a,b); |
| 1128 | INSERT 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'); |
| 1150 | SELECT 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 | ╰─────────┴─────────────╯ |
| 1177 | END |