]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add the bWrapSnglCol flag to the QRF spec, though it is not yet documented
authordrh <>
Fri, 21 Nov 2025 20:10:12 +0000 (20:10 +0000)
committerdrh <>
Fri, 21 Nov 2025 20:10:12 +0000 (20:10 +0000)
and does not yet work.  Fix column output so that it omits trailing space.

FossilOrigin-Name: a858027fc92727c680b7e984303df7f9e0a2d90c860c547176f290b113a69390

ext/qrf/qrf.c
ext/qrf/qrf.h
manifest
manifest.uuid
test/qrf01.test
test/qrf03.test
test/shell1.test

index d9d0c75d0886e9f081f2d09bc028de3fddb43134..eb32424c3de4883d27261ec6cc55cd0a9dee4e4f 100644 (file)
@@ -1042,6 +1042,17 @@ static void qrfRenderValue(Qrf *p, sqlite3_str *pOut, int iCol){
 #endif
 }
 
+/* Trim spaces of the end if pOut
+*/
+static void qrfRTrim(sqlite3_str *pOut){
+#if SQLITE_VERSION_NUMBER>=3052000
+  int nByte = sqlite3_str_length(pOut);
+  const char *zOut = sqlite3_str_value(pOut);
+  while( nByte>0 && zOut[nByte-1]==' ' ){ nByte--; }
+  sqlite3_str_truncate(pOut, nByte);
+#endif
+}
+
 /*
 ** Store string zUtf to pOut as w characters.  If w is negative,
 ** then right-justify the text.  W is the width in display characters, not
@@ -1452,6 +1463,14 @@ static void qrfLoadAlignment(qrfColData *pData, Qrf *p){
   }
 }
 
+/*
+** The output is single-column and the bWrapSnglCol flag is set.
+** Check to see if the single-column output can be split into multiple
+** columns that appear side-by-side.  Adjust pData appropriately.
+*/
+static void qrfWrapSingleColumn(qrfColData *pData, Qrf *p){
+}
+
 /*
 ** Adjust the layout for the screen width restriction
 */
@@ -1541,6 +1560,7 @@ static void qrfColumnar(Qrf *p){
   int bWW;                                /* True to do word-wrap */
   sqlite3_str *pStr;                      /* Temporary rendering */
   qrfColData data;                        /* Columnar layout data */
+  int bRTrim;                             /* Trim trailing space */
 
   rc = sqlite3_step(p->pStmt);
   if( rc!=SQLITE_ROW || nColumn==0 ){
@@ -1650,8 +1670,20 @@ static void qrfColumnar(Qrf *p){
     data.a[i].w = w;
   }
 
-  /* Adjust the column widths due to screen width restrictions */
-  qrfRestrictScreenWidth(&data, p);
+  if( nColumn==1
+   && p->spec.bWrapSnglCol
+   && p->spec.eStyle==QRF_STYLE_Column
+   && p->spec.bTitles==QRF_No
+   && p->spec.nScreenWidth>data.a[0].w+3
+  ){
+    /* Attempt to convert single-column tables into multi-column by
+    ** verticle wrapping, if the screen is wide enough and if the
+    ** bWrapSnglCol flag is set. */
+    qrfWrapSingleColumn(&data, p);
+  }else{
+    /* 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. */
@@ -1702,6 +1734,7 @@ static void qrfColumnar(Qrf *p){
   szColSep = (int)strlen(colSep);
 
   bWW = (p->spec.bWordWrap==QRF_Yes && data.bMultiRow);
+  bRTrim = (p->spec.eStyle==QRF_STYLE_Column);
   for(i=0; i<data.n; i+=nColumn){
     int bMore;
     int nRow = 0;
@@ -1727,6 +1760,7 @@ static void qrfColumnar(Qrf *p){
         if( j<nColumn-1 ){
           sqlite3_str_append(p->pOut, colSep, szColSep);
         }else{
+          if( bRTrim ) qrfRTrim(p->pOut);
           sqlite3_str_append(p->pOut, rowSep, szRowSep);
         }
       }
@@ -1745,6 +1779,7 @@ static void qrfColumnar(Qrf *p){
         if( j<nColumn-1 ){
           sqlite3_str_append(p->pOut, colSep, szColSep);
         }else{
+          if( bRTrim ) qrfRTrim(p->pOut);
           sqlite3_str_append(p->pOut, rowSep, szRowSep);
         }
       }
@@ -1785,10 +1820,12 @@ static void qrfColumnar(Qrf *p){
               if( j<nColumn-1 ){
                 sqlite3_str_append(p->pOut, colSep, szColSep);
               }else{
+                qrfRTrim(p->pOut);
                 sqlite3_str_append(p->pOut, rowSep, szRowSep);
               }
             }
           }else if( data.bMultiRow ){
+            qrfRTrim(p->pOut);
             sqlite3_str_append(p->pOut, "\n", 1);
           }
           break;
index ad9ff4ae4d473bbc0b7f2acecb125d412715de8c..5dc5f8f3af59cd85e876db05b77960e979502832 100644 (file)
@@ -37,6 +37,7 @@ struct sqlite3_qrf_spec {
   unsigned char bTextNull;    /* Apply eText encoding to zNull[] */
   unsigned char eDfltAlign;   /* Default alignment, no covered by aAlignment */
   unsigned char eTitleAlign;  /* Alignment for column headers */
+  unsigned char bWrapSnglCol; /* Wrap single-column output into many columns */
   short int nWrap;            /* Wrap columns wider than this */
   short int nScreenWidth;     /* Maximum overall table width */
   short int nLineLimit;       /* Maximum number of lines for any row */
index 88b2aca757081245ae0ff1d86a6cc39e07fca1b6..0f09f6e0ed43027c855148211946fdf87bf35483 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Need\sa\sdouble-underscore\sprefix\son\sthe\scplusplus\smacro
-D 2025-11-21T19:47:13.554
+C Add\sthe\sbWrapSnglCol\sflag\sto\sthe\sQRF\sspec,\sthough\sit\sis\snot\syet\sdocumented\nand\sdoes\snot\syet\swork.\s\sFix\scolumn\soutput\sso\sthat\sit\somits\strailing\sspace.
+D 2025-11-21T20:10:12.657
 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
@@ -417,8 +417,8 @@ F ext/misc/windirent.h 02211ce51f3034c675f2dbf4d228194d51b3ee05734678bad5106fff6
 F ext/misc/zipfile.c 09e6e3a3ff40a99677de3c0bc6569bd5f4709b1844ac3d1c1452a456c5a62f1c
 F ext/misc/zorder.c bddff2e1b9661a90c95c2a9a9c7ecd8908afab5763256294dd12d609d4664eee
 F ext/qrf/README.md dd565fd1ca0c46ea37dbf4d496e368b9ecade768c92669640bc106e039629016
-F ext/qrf/qrf.c 9c956eb63c34f9e1addfb658e61bc81c6e1783dd67d0656260223ab25b02ea37
-F ext/qrf/qrf.h bdd9eb90c08b07674cbe660da4a345a9535ee48bbbf8b45c87d9a71733fecdcb
+F ext/qrf/qrf.c 33379ad5044ba63729b204889fd6e59948ed5e80eb3037710d98f146907c4262
+F ext/qrf/qrf.h 116f9d7847c04f6377d40cd22dd2b1c6a1336a26201dfe6d69b1d58ec41d02e7
 F ext/rbu/rbu.c 801450b24eaf14440d8fd20385aacc751d5c9d6123398df41b1b5aa804bf4ce8
 F ext/rbu/rbu1.test 25870dd7db7eb5597e2b4d6e29e7a7e095abf332660f67d89959552ce8f8f255
 F ext/rbu/rbu10.test 7c22caa32c2ff26983ca8320779a31495a6555737684af7aba3daaf762ef3363
@@ -1509,9 +1509,9 @@ F test/printf2.test 3f55c1871a5a65507416076f6eb97e738d5210aeda7595a74ee895f2224c
 F test/progress.test ebab27f670bd0d4eb9d20d49cef96e68141d92fb
 F test/ptrchng.test ef1aa72d6cf35a2bbd0869a649b744e9d84977fc
 F test/pushdown.test 46a626ef1c0ca79b85296ff2e078b9da20a50e9b804b38f441590c3987580ddd
-F test/qrf01.test f1831a387233482b64a43d55f89a2d0f0da5d1e903e2473c7bd03deb88272234
+F test/qrf01.test e76be7da90e9c40010fd08336461c4fdc9825875167ee17170442c1e23631342
 F test/qrf02.test 39b4afdc000bedccdafc0aecf17638df67a67aaa2d2942865ae6abcc48ba0e92
-F test/qrf03.test 9d88aeb5cdd53f050b7ab9bd203281f7c9d063c33f22f8808e441b7ac0874ccf
+F test/qrf03.test 9de53aea459f5a127283db03cbb6011500757685646d21aa3c29c44c6ef23e86
 F test/queryonly.test 5f653159e0f552f0552d43259890c1089391dcca
 F test/quick.test 1681febc928d686362d50057c642f77a02c62e57
 F test/quickcheck.test a4b7e878cd97e46108291c409b0bf8214f29e18fddd68a42bc5c1375ad1fb80a
@@ -1605,7 +1605,7 @@ F test/sharedA.test 64bdd21216dda2c6a3bd3475348ccdc108160f34682c97f2f51c19fc0e21
 F test/sharedB.test 1a84863d7a2204e0d42f2e1606577c5e92e4473fa37ea0f5bdf829e4bf8ee707
 F test/shared_err.test 32634e404a3317eeb94abc7a099c556a346fdb8fb3858dbe222a4cbb8926a939
 F test/sharedlock.test 5ede3c37439067c43b0198f580fd374ebf15d304
-F test/shell1.test 8fbb73650b685766cdf4b5e8b5d12dee72664f44195eeb788d0f52fce08e04eb
+F test/shell1.test 9438957ab1c0d4c4622b98a11648999a86b6184c8317a87d3c5cb760d2f7bca9
 F test/shell2.test 103140814bdc7508aa41dd3462413cbc4aa84b4261112cb8d501d74275cb7d48
 F test/shell3.test 840192774cc4edf7653520c0434a311c7477b9bc324abbc7bd2887915792fa8c
 F test/shell4.test e25580a792b7b54560c3a76b6968bd8189261f38979fe28e6bc6312c5db280db
@@ -2178,8 +2178,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 1105b710934cf4a243c64d37dd147bc9378c0f7aa55a99891b7ac6e8f8f17f88
-R c69e89ececb8af516f46c72df26f3733
+P 04394387e626cd99ff98df978c4b7f2d32f65760e0c26e53f1ef4f59e4e91a4f
+R c2811c2ce4ec10183543473b397451a5
 U drh
-Z aa225474835adfbcef8fea17226c9505
+Z 7925dda900ed8e83a9a5d4713fd7d290
 # Remove this line to create a well-formed Fossil manifest.
index 97dcedd4ff313a3b8f606473878c599ee54c95d8..706bb90ab349ad74df035b0f0635bcc2b678c986 100644 (file)
@@ -1 +1 @@
-04394387e626cd99ff98df978c4b7f2d32f65760e0c26e53f1ef4f59e4e91a4f
+a858027fc92727c680b7e984303df7f9e0a2d90c860c547176f290b113a69390
index d251e35f7987d331552d954818f2b349c8de2176..4bba0fe9d44e87f3e6dbecfd2a74d511528a526b 100644 (file)
@@ -116,16 +116,16 @@ do_test 1.31 {
 do_test 1.40 {
   set result "\n[db format -style column {SELECT * FROM t1}]"
 } {
-a     b    c    
+a     b    c
 ----  ---  -----
 1     2.5  three
-BLOB       Ἀμήν 
+BLOB       Ἀμήν
 }
 do_test 1.41 {
   set result "\n[db format -style column -title off {SELECT * FROM t1}]"
 } {
 1     2.5  three
-BLOB       Ἀμήν 
+BLOB       Ἀμήν
 }
 
 do_test 1.50 {
@@ -683,15 +683,15 @@ do_test 5.3c {
                  -text plain -esc off -textjsonb no \
                    -wordwrap yes -linelimit 2 $sql]"
 } {
-    name        mtime        time         value     
+    name        mtime        time         value
 ------------  ----------  ----------  --------------
 sample-jsonb  1333101221  2012-03-30  x'cc7c57616c70
                             09:53:41  6861b535332e31
                                                  ...
 
-    one       1333206973  2012-03-31                
-    two                     15:16:13                
-    ...                                             
+    one       1333206973  2012-03-31
+    two                     15:16:13
+    ...
 
  entry-one    1708791504  2024-02-24  x'000000000000
                             16:18:24  00000000000000
index a8984c8554c2b7c88726bc6fa47a2fa00638b61f..5c0e52b55bf0b387081630b9cf821383538916f5 100644 (file)
@@ -151,11 +151,11 @@ do_test 1.40 {
 } {
  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.41 {
   set x "\n[db format -style column -screenwidth 52 \
@@ -164,11 +164,11 @@ do_test 1.41 {
 } {
  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
 }
 
 
index 2ff218f4d59ef96cca02dafd181b4fb744089e5a..539d8ef830dbaa09f4c7b95874af9adfc73ea24f 100644 (file)
@@ -731,7 +731,7 @@ do_test shell1-3.26.5 {
 do_test shell1-3.26.6 {
   catchcmd "test.db" ".mode column\n.header off\n.width -10 10\nSELECT 'abcdefg', 123456;"
   # this should be treated the same as a '1' width for col 1 and 2
-} {0 {   abcdefg  123456    }}
+} {0 {   abcdefg  123456}}
 
 
 # .timer ON|OFF          Turn the CPU timer measurement on or off