From: drh <> Date: Wed, 26 Nov 2025 17:23:11 +0000 (+0000) Subject: In QRF, if the horizontal alignment is QRF_ALIGN_Auto, then use right X-Git-Tag: artiphishell~168 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9286439c4ab19aa5d48051da1d96806d5b4fac18;p=thirdparty%2Fsqlite.git In QRF, if the horizontal alignment is QRF_ALIGN_Auto, then use right alignment for numeric values and left alignment for everything else. FossilOrigin-Name: 5fdedc69b1ac05bcdc40ee30c1473be75d3afe89e031d750c8fc3dcfa9846d5b --- diff --git a/ext/qrf/README.md b/ext/qrf/README.md index d7fd0e4742..34b0409def 100644 --- a/ext/qrf/README.md +++ b/ext/qrf/README.md @@ -465,8 +465,9 @@ entry for that column takes precedence. If either the horizontal or vertical alignment has an "auto" value for that column or if a column is beyond the first nAlign entries, then eDfltAlign is used as a backup. If neither aAlign\[\] nor eDfltAlign -specify a horizontal alignment, then values are left-aligned -(QRF_ALIGN_Left). If neither aAlign\[\] nor eDfltAlign +specify a horizontal alignment, then values are right-aligned +(QRF_ALIGN_Right) if they are numeric and left-aligned +(QRF_ALIGN_Left) otherwise. If neither aAlign\[\] nor eDfltAlign specify a vertical alignment, then values are top-aligned (QRF_ALIGN_Top). diff --git a/ext/qrf/qrf.c b/ext/qrf/qrf.c index cc73a5f039..892cedaf3f 100644 --- a/ext/qrf/qrf.c +++ b/ext/qrf/qrf.c @@ -1265,36 +1265,6 @@ static void qrfAppendWithTabs( sqlite3_str_append(pOut, (const char*)z, i); } -/* -** Output horizontally justified text into pOut. The text is the -** first nVal bytes of zVal. Include nWS bytes of whitespace, either -** split between both sides, or on the left, or on the right, depending -** on eAlign. -*/ -static void qrfPrintAligned( - sqlite3_str *pOut, /* Append text here */ - const char *zVal, /* Text to append */ - int nVal, /* Use only the first nVal bytes of zVal[] */ - int nWS, /* Whitespace for horizonal alignment */ - unsigned char eAlign /* Alignment type */ -){ - eAlign &= QRF_ALIGN_HMASK; - if( eAlign==QRF_ALIGN_Center ){ - /* Center the text */ - sqlite3_str_appendchar(pOut, nWS/2, ' '); - qrfAppendWithTabs(pOut, zVal, nVal); - sqlite3_str_appendchar(pOut, nWS - nWS/2, ' '); - }else if( eAlign==QRF_ALIGN_Right){ - /* Right justify the text */ - sqlite3_str_appendchar(pOut, nWS, ' '); - qrfAppendWithTabs(pOut, zVal, nVal); - }else{ - /* Left justify the next */ - qrfAppendWithTabs(pOut, zVal, nVal); - sqlite3_str_appendchar(pOut, nWS, ' '); - } -} - /* ** GCC does not define the offsetof() macro so we'll have to do it ** ourselves. @@ -1318,15 +1288,47 @@ struct qrfColData { sqlite3_int64 n; /* Number of cells. nCol*nRow */ char **az; /* Content of all cells */ int *aiWth; /* Width of each cell */ + unsigned char *abNum; /* True for each numeric cell */ struct qrfPerCol { /* Per-column data */ char *z; /* Cache of text for current row */ int w; /* Computed width of this column */ int mxW; /* Maximum natural (unwrapped) width */ unsigned char e; /* Alignment */ unsigned char fx; /* Width is fixed */ + unsigned char bNum; /* True if is numeric */ } *a; /* One per column */ }; +/* +** Output horizontally justified text into pOut. The text is the +** first nVal bytes of zVal. Include nWS bytes of whitespace, either +** split between both sides, or on the left, or on the right, depending +** on eAlign. +*/ +static void qrfPrintAligned( + sqlite3_str *pOut, /* Append text here */ + struct qrfPerCol *pCol, /* Information about the text to print */ + int nVal, /* Use only the first nVal bytes of zVal[] */ + int nWS /* Whitespace for horizonal alignment */ +){ + unsigned char eAlign = pCol->e & QRF_ALIGN_HMASK; + if( eAlign==QRF_Auto && pCol->bNum ) eAlign = QRF_ALIGN_Right; + if( eAlign==QRF_ALIGN_Center ){ + /* Center the text */ + sqlite3_str_appendchar(pOut, nWS/2, ' '); + qrfAppendWithTabs(pOut, pCol->z, nVal); + sqlite3_str_appendchar(pOut, nWS - nWS/2, ' '); + }else if( eAlign==QRF_ALIGN_Right ){ + /* Right justify the text */ + sqlite3_str_appendchar(pOut, nWS, ' '); + qrfAppendWithTabs(pOut, pCol->z, nVal); + }else{ + /* Left justify the text */ + qrfAppendWithTabs(pOut, pCol->z, nVal); + sqlite3_str_appendchar(pOut, nWS, ' '); + } +} + /* ** Free all the memory allocates in the qrfColData object */ @@ -1335,6 +1337,7 @@ static void qrfColDataFree(qrfColData *p){ for(i=0; in; i++) sqlite3_free(p->az[i]); sqlite3_free(p->az); sqlite3_free(p->aiWth); + sqlite3_free(p->abNum); sqlite3_free(p->a); memset(p, 0, sizeof(*p)); } @@ -1346,6 +1349,7 @@ static void qrfColDataFree(qrfColData *p){ static int qrfColDataEnlarge(qrfColData *p){ char **azData; int *aiWth; + unsigned char *abNum; p->nAlloc = 2*p->nAlloc + 10*p->nCol; azData = sqlite3_realloc64(p->az, p->nAlloc*sizeof(char*)); if( azData==0 ){ @@ -1361,6 +1365,13 @@ static int qrfColDataEnlarge(qrfColData *p){ return 1; } p->aiWth = aiWth; + abNum = sqlite3_realloc64(p->abNum, p->nAlloc); + if( abNum==0 ){ + qrfOom(p->p); + qrfColDataFree(p); + return 1; + } + p->abNum = abNum; return 0; } @@ -1729,6 +1740,7 @@ static void qrfColumnar(Qrf *p){ if( p->spec.bTitles==QRF_Yes ){ unsigned char saved_eText = p->spec.eText; p->spec.eText = p->spec.eTitle; + memset(data.abNum, 0, nColumn); for(i=0; ipStmt,i); int nNL = 0; @@ -1753,10 +1765,12 @@ static void qrfColumnar(Qrf *p){ char *z; int nNL = 0; int n, w; + int eType = sqlite3_column_type(p->pStmt,i); pStr = sqlite3_str_new(p->db); qrfRenderValue(p, pStr, i); n = sqlite3_str_length(pStr); z = data.az[data.n] = sqlite3_str_finish(pStr); + data.abNum[data.n] = eType==SQLITE_INTEGER || eType==SQLITE_FLOAT; data.aiWth[data.n] = w = qrfDisplayWidth(z, n, &nNL); data.n++; if( w>data.a[i].mxW ) data.a[i].mxW = w; @@ -1917,7 +1931,10 @@ static void qrfColumnar(Qrf *p){ ** (if there is a title line) or a row in the body of the table. ** The column number will be j. The row number is i/nColumn. */ - for(j=0; jpOut, rowStart, szRowStart); bMore = 0; @@ -1928,7 +1945,7 @@ static void qrfColumnar(Qrf *p){ int nWS; qrfWrapLine(data.a[j].z, data.a[j].w, bWW, &nThis, &nWide, &iNext); nWS = data.a[j].w - nWide; - qrfPrintAligned(p->pOut, data.a[j].z, nThis, nWS, data.a[j].e); + qrfPrintAligned(p->pOut, &data.a[j], nThis, nWS); data.a[j].z += iNext; if( data.a[j].z[0]!=0 ){ bMore = 1; @@ -1950,7 +1967,8 @@ static void qrfColumnar(Qrf *p){ }else{ int nE = 3; if( nE>data.a[j].w ) nE = data.a[j].w; - qrfPrintAligned(p->pOut, "...", nE, data.a[j].w-nE, data.a[j].e); + data.a[j].z = "..."; + qrfPrintAligned(p->pOut, &data.a[j], nE, data.a[j].w-nE); } if( jpOut, colSep, szColSep); diff --git a/manifest b/manifest index 0dd1cc4ff2..b67b89d519 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\sbBorder\soption\sto\sthe\sQRF\sspec.\s\sReflect\sthis\sin\sthe\s-border\noption\son\sthe\sTCL\sformat\smethod,\sand\sthe\s--border\soption\sto\s".mode"\nin\sthe\sCLI.\s\sAlso\sadd\sthe\s"psql"\smode\sto\sthe\sCLI. -D 2025-11-26T16:21:56.554 +C In\sQRF,\sif\sthe\shorizontal\salignment\sis\sQRF_ALIGN_Auto,\sthen\suse\sright\nalignment\sfor\snumeric\svalues\sand\sleft\salignment\sfor\severything\selse. +D 2025-11-26T17:23:11.968 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea @@ -416,8 +416,8 @@ F ext/misc/wholenumber.c 0fa0c082676b7868bf2fa918e911133f2b349bcdceabd1198bba5f6 F ext/misc/windirent.h 02211ce51f3034c675f2dbf4d228194d51b3ee05734678bad5106fff6292e60c F ext/misc/zipfile.c 09e6e3a3ff40a99677de3c0bc6569bd5f4709b1844ac3d1c1452a456c5a62f1c F ext/misc/zorder.c bddff2e1b9661a90c95c2a9a9c7ecd8908afab5763256294dd12d609d4664eee -F ext/qrf/README.md c63030fbaf2f5ceedc574749a0630da14bdac4f4ffe70415ddb0e64fc9876aa2 -F ext/qrf/qrf.c b134a3d07cea77d27301dca44bcd8d3cd1551cbed7e51c21854bb6fe570995fa +F ext/qrf/README.md 07dcefad86c259c161d0ec2ee5f8430a88d1645ff9b23f535b7cf27a1c527d32 +F ext/qrf/qrf.c af751995194a62f5cc631a6f19b5c5a2c44211098a983ca5a9e26c6ea2eef311 F ext/qrf/qrf.h 322d48537a5aa39c206c2ec0764a7938ea7662a8c25be1c4e9d742789609ba1e F ext/rbu/rbu.c 801450b24eaf14440d8fd20385aacc751d5c9d6123398df41b1b5aa804bf4ce8 F ext/rbu/rbu1.test 25870dd7db7eb5597e2b4d6e29e7a7e095abf332660f67d89959552ce8f8f255 @@ -1440,7 +1440,7 @@ F test/mmap4.test 2e2b4e32555b58da15176e6fe750f17c9dcf7f93 F test/mmapcorrupt.test 470fb44fe92e99c1d23701d156f8c17865f5b027063c9119dcfdb842791f4465 F test/mmapfault.test d4c9eff9cd8c2dc14bc43e71e042f175b0a26fe3 F test/mmapwarm.test 2272005969cd17a910077bd5082f70bc1fefad9a875afec7fc9af483898ecaf3 -F test/modeA.clitest 43098858465029ebe9229009fbd59528adf89f265fb82af87fc5c58f7901b2bc +F test/modeA.clitest e0c63c28e2651dd322e21de683fec7d247028b80f7a753663244ba0087215dc8 F test/multiplex.test d74c034e52805f6de8cc5432cef8c9eb774bb64ec29b83a22effc8ca4dac1f08 F test/multiplex2.test 580ca5817c7edbe4cc68fa150609c9473393003a F test/multiplex3.test fac575e0b1b852025575a6a8357701d80933e98b5d2fe6d35ddaa68f92f6a1f7 @@ -1512,7 +1512,7 @@ F test/ptrchng.test ef1aa72d6cf35a2bbd0869a649b744e9d84977fc F test/pushdown.test 46a626ef1c0ca79b85296ff2e078b9da20a50e9b804b38f441590c3987580ddd F test/qrf01.test 6cef9377ad7defbb9dce75e022304807b75b5f1a7e17d1cafdea05bf076cc7f9 F test/qrf02.test 39b4afdc000bedccdafc0aecf17638df67a67aaa2d2942865ae6abcc48ba0e92 -F test/qrf03.test 9de53aea459f5a127283db03cbb6011500757685646d21aa3c29c44c6ef23e86 +F test/qrf03.test ad7fa339fb46b26b08625f3a77a4827bdee9f0dad402d8ddc1fcb8f05aa64a54 F test/qrf04.test 0894692c998d2401dcc33449c02051b503ecce0c94217be54fb007c82d2d1379 F test/queryonly.test 5f653159e0f552f0552d43259890c1089391dcca F test/quick.test 1681febc928d686362d50057c642f77a02c62e57 @@ -2180,8 +2180,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 8b0cbc18be3c6f2501b102757af6be98c48044a296104cca7bce822ac2304515 -R 8945f4ddcddcd63749e20ffed7b156be +P 02cbeb69884cd884d9b1b5f59c4168a3dc24b1a5aecc6967586c0be350b10574 +R 1d443466fd57e9ddd9d39780d34ef6e2 U drh -Z 40eaa1e5fedbd407b6fc2b7e3ad849db +Z a9a3510b1739287ae392b4f4d704735c # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 8990fd26e9..2936c32fd7 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -02cbeb69884cd884d9b1b5f59c4168a3dc24b1a5aecc6967586c0be350b10574 +5fdedc69b1ac05bcdc40ee30c1473be75d3afe89e031d750c8fc3dcfa9846d5b diff --git a/test/modeA.clitest b/test/modeA.clitest index c444c80664..e1aa26f89b 100644 --- a/test/modeA.clitest +++ b/test/modeA.clitest @@ -27,10 +27,10 @@ SELECT * FROM t1; ┌─────┬───────┬───────┬───────┬───────┐ │ 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 │ +│ 1 │ 2.5 │ three │ DD │ │ +│ 2.5 │ three │ DD │ │ 1 │ +│ DD │ │ 1 │ 2.5 │ three │ +│ │ 1 │ 2.5 │ three │ DD │ └─────┴───────┴───────┴───────┴───────┘ END @@ -41,10 +41,10 @@ SELECT * FROM t1; ┌─────┬───────┬───────┬───────┬───────┐ │ 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 │ +│ 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 diff --git a/test/qrf03.test b/test/qrf03.test index 5c0e52b55b..de52307196 100644 --- a/test/qrf03.test +++ b/test/qrf03.test @@ -63,11 +63,11 @@ do_test 1.10 { ┌───────┬───────┬───────┬───────┬──────┬───────┬───────┬───────┐ │ 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 │ +│ 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 { @@ -78,11 +78,11 @@ do_test 1.11 { ┌─────┬─────┬─────┬─────┬────┬─────┬─────┬─────┐ │ 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 │ +│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│ └─────┴─────┴─────┴─────┴────┴─────┴─────┴─────┘ } @@ -94,11 +94,11 @@ do_test 1.20 { +-------+-------+-------+-------+------+-------+-------+-------+ | 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 | +| 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 { @@ -109,11 +109,11 @@ do_test 1.21 { +-----+-----+-----+-----+----+-----+-----+-----+ | 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 | +|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| +-----+-----+-----+-----+----+-----+-----+-----+ } @@ -124,11 +124,11 @@ do_test 1.30 { } { | 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 | +| 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 \ @@ -137,11 +137,11 @@ do_test 1.31 { } { | 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 | +|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 {