From: drh <> Date: Sat, 15 Nov 2025 12:09:13 +0000 (+0000) Subject: Columnar formats respond to --screenwidth restrictions by removing X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=18c7b4d65174a6718117312ca9be85ec5abaeff8;p=thirdparty%2Fsqlite.git Columnar formats respond to --screenwidth restrictions by removing cell padding. FossilOrigin-Name: cbe233ca131118692fd4a84d8fcf0dfca926fa935f66cfb718c235d54084de3d --- diff --git a/ext/qrf/qrf.c b/ext/qrf/qrf.c index 8aaf737537..ab882bff10 100644 --- a/ext/qrf/qrf.c +++ b/ext/qrf/qrf.c @@ -1419,6 +1419,34 @@ static void qrfLoadAlignment(qrfColData *pData, Qrf *p){ } } +/* +** Adjust the layout for the screen width restriction +*/ +static void qrfRestrictScreenWidth(qrfColData *pData, Qrf *p){ + int sepW; /* Width of all box separators and margins */ + int sumW; /* Total width of data area over all columns */ + int i; /* Loop counter */ + + pData->nMargin = 2; /* Default to normal margins */ + if( p->spec.nScreenWidth==0 ) return; + if( p->spec.eStyle==QRF_STYLE_Column ){ + sepW = pData->nCol*2 - 2; + }else{ + sepW = pData->nCol*3 + 1; + } + for(i=sumW=0; inCol; i++) sumW += pData->a[i].w; + if( p->spec.nScreenWidth >= sumW+sepW ) return; + + /* First thing to do is reduce the separation between columns */ + pData->nMargin = 0; + if( p->spec.eStyle==QRF_STYLE_Column ){ + sepW = pData->nCol - 1; + }else{ + sepW = pData->nCol + 1; + } + +} + /* ** Columnar modes require that the entire query be evaluated first, with ** results written into memory, so that we can compute appropriate column @@ -1548,33 +1576,51 @@ static void qrfColumnar(Qrf *p){ data.a[i].w = w; } - /* TBD: Narrow columns so that the total is less than p->spec.nScreenWidth */ + /* Adjust the column widths due to screen width restrictions */ + qrfRestrictScreenWidth(&data, p); /* Draw the line across the top of the table. Also initialize ** the row boundary and column separator texts. */ - data.nMargin = 2; switch( p->spec.eStyle ){ case QRF_STYLE_Box: - rowStart = BOX_13 " "; - colSep = " " BOX_13 " "; - rowSep = " " BOX_13 "\n"; + if( data.nMargin ){ + rowStart = BOX_13 " "; + colSep = " " BOX_13 " "; + rowSep = " " BOX_13 "\n"; + }else{ + rowStart = BOX_13; + colSep = BOX_13; + rowSep = BOX_13 "\n"; + } qrfBoxSeparator(p->pOut, &data, BOX_23, BOX_234, BOX_34); break; case QRF_STYLE_Table: - rowStart = "| "; - colSep = " | "; - rowSep = " |\n"; + if( data.nMargin ){ + rowStart = "| "; + colSep = " | "; + rowSep = " |\n"; + }else{ + rowStart = "|"; + colSep = "|"; + rowSep = "|\n"; + } qrfRowSeparator(p->pOut, &data, '+'); break; case QRF_STYLE_Column: rowStart = ""; - colSep = " "; + colSep = data.nMargin ? " " : " "; rowSep = "\n"; break; default: /*case QRF_STYLE_Markdown:*/ - rowStart = "| "; - colSep = " | "; - rowSep = " |\n"; + if( data.nMargin ){ + rowStart = "| "; + colSep = " | "; + rowSep = " |\n"; + }else{ + rowStart = "|"; + colSep = "|"; + rowSep = "|\n"; + } break; } szRowStart = (int)strlen(rowStart); diff --git a/manifest b/manifest index b0f19a4afa..20a81c9b37 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Data\sstructure\simprovements\son\scolumnar\slayout.\s\sPrep\swork\sfor\sgetting\ncolumnar\slayouts\sto\srespond\sto\snScreenWidth. -D 2025-11-15T11:28:23.387 +C Columnar\sformats\srespond\sto\s--screenwidth\srestrictions\sby\sremoving\ncell\spadding. +D 2025-11-15T12:09:13.368 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea @@ -417,7 +417,7 @@ F ext/misc/windirent.h 02211ce51f3034c675f2dbf4d228194d51b3ee05734678bad5106fff6 F ext/misc/zipfile.c 09e6e3a3ff40a99677de3c0bc6569bd5f4709b1844ac3d1c1452a456c5a62f1c F ext/misc/zorder.c bddff2e1b9661a90c95c2a9a9c7ecd8908afab5763256294dd12d609d4664eee F ext/qrf/README.md 09dd538966d8ee32598fc010e7fe6755bd7190494953a02960a9c81197d20cf3 -F ext/qrf/qrf.c 4b9a551c43631fee70561bec966484e1e6d0705e9390ad981bf90629ec50b43d +F ext/qrf/qrf.c fbb6de94990683f8dab198fd11f8d525814e238f239d8c2b5ba876f0547fc20d F ext/qrf/qrf.h b4b3489b3b3683523fd248d15cf5945830643b036943efacdb772a3e00367aa2 F ext/rbu/rbu.c 801450b24eaf14440d8fd20385aacc751d5c9d6123398df41b1b5aa804bf4ce8 F ext/rbu/rbu1.test 25870dd7db7eb5597e2b4d6e29e7a7e095abf332660f67d89959552ce8f8f255 @@ -1509,6 +1509,7 @@ F test/ptrchng.test ef1aa72d6cf35a2bbd0869a649b744e9d84977fc F test/pushdown.test 46a626ef1c0ca79b85296ff2e078b9da20a50e9b804b38f441590c3987580ddd F test/qrf01.test f46f498e447d988b52dfa1cd45c683b7212bb2056741a4eff306df185b9c00b1 F test/qrf02.test 39b4afdc000bedccdafc0aecf17638df67a67aaa2d2942865ae6abcc48ba0e92 +F test/qrf03.test 9d88aeb5cdd53f050b7ab9bd203281f7c9d063c33f22f8808e441b7ac0874ccf F test/queryonly.test 5f653159e0f552f0552d43259890c1089391dcca F test/quick.test 1681febc928d686362d50057c642f77a02c62e57 F test/quickcheck.test a4b7e878cd97e46108291c409b0bf8214f29e18fddd68a42bc5c1375ad1fb80a @@ -2175,8 +2176,8 @@ F tool/version-info.c 33d0390ef484b3b1cb685d59362be891ea162123cea181cb8e6d2cf6dd F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7 F tool/warnings.sh d924598cf2f55a4ecbc2aeb055c10bd5f48114793e7ba25f9585435da29e7e98 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 0650e2b83170b44c1ba944259a96d41e1a14a57004d4f1f80dc5640ae837a81e -R 68d6d980f828d21e49b27041ff53af43 +P 777eeb2ed2708faf42559387bd582b9345a794798a0327e4fcd75e37948eac60 +R 18da84638cbc549862fa04427f55af51 U drh -Z b607d4ec693b98f876c3e69df28145b2 +Z 09f09c667712ec4cacfa01d0509edacc # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 5cd4ed4176..92b0f0bbf5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -777eeb2ed2708faf42559387bd582b9345a794798a0327e4fcd75e37948eac60 +cbe233ca131118692fd4a84d8fcf0dfca926fa935f66cfb718c235d54084de3d diff --git a/test/qrf03.test b/test/qrf03.test new file mode 100644 index 0000000000..a8984c8554 --- /dev/null +++ b/test/qrf03.test @@ -0,0 +1,176 @@ +# 2025-11-15 +# +# 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 Query Result Formatter (QRF) +# +# Format narrowing due to nScreenWidth +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix qrf03 + +do_execsql_test 1.0 { + CREATE TABLE mlink( + mid INTEGER, + fid INTEGER, + pmid INTEGER, + pid INTEGER, + fnid INTEGER REFERENCES filename, + pfnid INTEGER, + mperm INTEGER, + isaux BOOLEAN DEFAULT 0 + ); + INSERT INTO mlink VALUES(28775,28774,28773,28706,1,0,0,0); + INSERT INTO mlink VALUES(28773,28706,28770,28685,1,0,0,0); + INSERT INTO mlink VALUES(28770,28736,28769,28695,2,0,0,0); + INSERT INTO mlink VALUES(28770,28697,28769,28698,3,0,0,0); + INSERT INTO mlink VALUES(28767,28768,28759,28746,4,0,0,0); + CREATE TABLE event( + type TEXT, + mtime DATETIME, + objid INTEGER PRIMARY KEY, + tagid INTEGER, + uid INTEGER REFERENCES user, + bgcolor TEXT, + euser TEXT, + user TEXT, + ecomment TEXT, + comment TEXT, + brief TEXT, + omtime DATETIME + ); + INSERT INTO event VALUES('ci',2460994.978048461023,126223,NULL,NULL,NULL,NULL,'drh',NULL,unistr('Data structure improvements on columnar layout. Prep work for getting\u000acolumnar layouts to respond to nScreenWidth.'),NULL,2460994.978048461023); + INSERT INTO event VALUES('ci',2460994.836955601816,126218,NULL,NULL,NULL,NULL,'stephan',NULL,'API doc typo fix.',NULL,2460994.836955601816); + INSERT INTO event VALUES('ci',2460994.88823369192,126212,NULL,NULL,NULL,NULL,'stephan',NULL,'Move sqlite3-api-cleanup.js into post-js-footer.js to remove the final direct Emscripten dependency from the intermediary build product sqlite3-api.js (the whole library, waiting to be bootstrapped). This is partly in response to [forum:4b7d45433731d2e0|forum post 4b7d45433731d2e0], which demonstrates a potential use case for a standalone sqlite3-api.js. This is a build/doc change, not a functional one.',NULL,2460994.88823369192); + INSERT INTO event VALUES('ci',2460994.516081551089,126211,NULL,NULL,NULL,NULL,'drh',NULL,unistr('Improve columnar layout in QRF so that it correctly deals with control\u000acharacters, and especially tabs.'),NULL,2460994.516081551089); + INSERT INTO event VALUES('ci',2460994.409343171865,126208,NULL,NULL,NULL,NULL,'drh',NULL,'Make use of the new sqlite3_str_free() interface in the CLI.',NULL,2460994.409343171865); +} + +do_test 1.10 { + set x "\n[db format -style box -screenwidth 68 \ + {SELECT * FROM mlink ORDER BY rowid}]" + +} { +┌───────┬───────┬───────┬───────┬──────┬───────┬───────┬───────┐ +│ mid │ fid │ pmid │ pid │ fnid │ pfnid │ mperm │ isaux │ +├───────┼───────┼───────┼───────┼──────┼───────┼───────┼───────┤ +│ 28775 │ 28774 │ 28773 │ 28706 │ 1 │ 0 │ 0 │ 0 │ +│ 28773 │ 28706 │ 28770 │ 28685 │ 1 │ 0 │ 0 │ 0 │ +│ 28770 │ 28736 │ 28769 │ 28695 │ 2 │ 0 │ 0 │ 0 │ +│ 28770 │ 28697 │ 28769 │ 28698 │ 3 │ 0 │ 0 │ 0 │ +│ 28767 │ 28768 │ 28759 │ 28746 │ 4 │ 0 │ 0 │ 0 │ +└───────┴───────┴───────┴───────┴──────┴───────┴───────┴───────┘ +} +do_test 1.11 { + set x "\n[db format -style box -screenwidth 52 \ + {SELECT * FROM mlink ORDER BY rowid}]" + +} { +┌─────┬─────┬─────┬─────┬────┬─────┬─────┬─────┐ +│ mid │ fid │pmid │ pid │fnid│pfnid│mperm│isaux│ +├─────┼─────┼─────┼─────┼────┼─────┼─────┼─────┤ +│28775│28774│28773│28706│1 │0 │0 │0 │ +│28773│28706│28770│28685│1 │0 │0 │0 │ +│28770│28736│28769│28695│2 │0 │0 │0 │ +│28770│28697│28769│28698│3 │0 │0 │0 │ +│28767│28768│28759│28746│4 │0 │0 │0 │ +└─────┴─────┴─────┴─────┴────┴─────┴─────┴─────┘ +} + +do_test 1.20 { + set x "\n[db format -style table -screenwidth 68 \ + {SELECT * FROM mlink ORDER BY rowid}]" + +} { ++-------+-------+-------+-------+------+-------+-------+-------+ +| mid | fid | pmid | pid | fnid | pfnid | mperm | isaux | ++-------+-------+-------+-------+------+-------+-------+-------+ +| 28775 | 28774 | 28773 | 28706 | 1 | 0 | 0 | 0 | +| 28773 | 28706 | 28770 | 28685 | 1 | 0 | 0 | 0 | +| 28770 | 28736 | 28769 | 28695 | 2 | 0 | 0 | 0 | +| 28770 | 28697 | 28769 | 28698 | 3 | 0 | 0 | 0 | +| 28767 | 28768 | 28759 | 28746 | 4 | 0 | 0 | 0 | ++-------+-------+-------+-------+------+-------+-------+-------+ +} +do_test 1.21 { + set x "\n[db format -style table -screenwidth 52 \ + {SELECT * FROM mlink ORDER BY rowid}]" + +} { ++-----+-----+-----+-----+----+-----+-----+-----+ +| mid | fid |pmid | pid |fnid|pfnid|mperm|isaux| ++-----+-----+-----+-----+----+-----+-----+-----+ +|28775|28774|28773|28706|1 |0 |0 |0 | +|28773|28706|28770|28685|1 |0 |0 |0 | +|28770|28736|28769|28695|2 |0 |0 |0 | +|28770|28697|28769|28698|3 |0 |0 |0 | +|28767|28768|28759|28746|4 |0 |0 |0 | ++-----+-----+-----+-----+----+-----+-----+-----+ +} + +do_test 1.30 { + set x "\n[db format -style markdown -screenwidth 68 \ + {SELECT * FROM mlink ORDER BY rowid}]" + +} { +| mid | fid | pmid | pid | fnid | pfnid | mperm | isaux | +|-------|-------|-------|-------|------|-------|-------|-------| +| 28775 | 28774 | 28773 | 28706 | 1 | 0 | 0 | 0 | +| 28773 | 28706 | 28770 | 28685 | 1 | 0 | 0 | 0 | +| 28770 | 28736 | 28769 | 28695 | 2 | 0 | 0 | 0 | +| 28770 | 28697 | 28769 | 28698 | 3 | 0 | 0 | 0 | +| 28767 | 28768 | 28759 | 28746 | 4 | 0 | 0 | 0 | +} +do_test 1.31 { + set x "\n[db format -style markdown -screenwidth 52 \ + {SELECT * FROM mlink ORDER BY rowid}]" + +} { +| mid | fid |pmid | pid |fnid|pfnid|mperm|isaux| +|-----|-----|-----|-----|----|-----|-----|-----| +|28775|28774|28773|28706|1 |0 |0 |0 | +|28773|28706|28770|28685|1 |0 |0 |0 | +|28770|28736|28769|28695|2 |0 |0 |0 | +|28770|28697|28769|28698|3 |0 |0 |0 | +|28767|28768|28759|28746|4 |0 |0 |0 | +} + +do_test 1.40 { + set x "\n[db format -style column -screenwidth 68 \ + {SELECT * FROM mlink ORDER BY rowid}]" + +} { + mid fid pmid pid fnid pfnid mperm isaux +----- ----- ----- ----- ---- ----- ----- ----- +28775 28774 28773 28706 1 0 0 0 +28773 28706 28770 28685 1 0 0 0 +28770 28736 28769 28695 2 0 0 0 +28770 28697 28769 28698 3 0 0 0 +28767 28768 28759 28746 4 0 0 0 +} +do_test 1.41 { + set x "\n[db format -style column -screenwidth 52 \ + {SELECT * FROM mlink ORDER BY rowid}]" + +} { + mid fid pmid pid fnid pfnid mperm isaux +----- ----- ----- ----- ---- ----- ----- ----- +28775 28774 28773 28706 1 0 0 0 +28773 28706 28770 28685 1 0 0 0 +28770 28736 28769 28695 2 0 0 0 +28770 28697 28769 28698 3 0 0 0 +28767 28768 28759 28746 4 0 0 0 +} + + + +finish_test