]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Miscellaneous fixes to the new alignment configurations.
authordrh <>
Sat, 8 Nov 2025 15:25:07 +0000 (15:25 +0000)
committerdrh <>
Sat, 8 Nov 2025 15:25:07 +0000 (15:25 +0000)
FossilOrigin-Name: 787fb4c2ac80db6552bc7a740c3c3c63c0c8414cb4e7db80d367b4b5512519d0

ext/qrf/qrf.c
manifest
manifest.uuid
src/tclsqlite.c
test/qrf01.test

index c964dcf4c2dbc4e87c59e5ba1de57299c697be51..eee1b80e26d9bf1b8872bd558e4c2ae92d941947 100644 (file)
@@ -1215,23 +1215,37 @@ static void qrfBoxSeparator(
   sqlite3_str_append(pOut, "\n", 1);
 }
 
+/*
+** Load into pData the default alignment for the body of a table.
+*/
+static void qrfLoadAlignment(qrfColData *pData, Qrf *p){
+  sqlite3_int64 i;
+  memset(pData->aAlign, p->spec.eDfltAlign, pData->nCol);
+  for(i=0; i<pData->nCol && i<p->spec.nAlign; i++){
+    unsigned char ax = p->spec.aAlign[i];
+    if( (ax & QRF_ALIGN_HMASK)!=0 ){
+      pData->aAlign[i] = (ax & QRF_ALIGN_HMASK) |
+                          (pData->aAlign[i] & QRF_ALIGN_VMASK);
+    }
+  }
+}
+
 /*
 ** Columnar modes require that the entire query be evaluated first, with
 ** results written into memory, so that we can compute appropriate column
 ** widths.
 */
 static void qrfColumnar(Qrf *p){
-  sqlite3_int64 i, j;
-  const char *colSep = 0;
-  const char *rowSep = 0;
-  const char *rowStart = 0;
-  int szColSep, szRowSep, szRowStart;
-  int rc;
-  int nColumn = p->nCol;
-  int bWW;
-  int bCenter;
-  sqlite3_str *pStr;
-  qrfColData data;
+  sqlite3_int64 i, j;                     /* Loop counters */
+  const char *colSep = 0;                 /* Column separator text */
+  const char *rowSep = 0;                 /* Row terminator text */
+  const char *rowStart = 0;               /* Row start text */
+  int szColSep, szRowSep, szRowStart;     /* Size in bytes of previous 3 */
+  int rc;                                 /* Result code */
+  int nColumn = p->nCol;                  /* Number of columns */
+  int bWW;                                /* True to do word-wrap */
+  sqlite3_str *pStr;                      /* Temporary rendering */
+  qrfColData data;                        /* Columnar layout data */
 
   rc = sqlite3_step(p->pStmt);
   if( rc!=SQLITE_ROW || nColumn==0 ){
@@ -1272,9 +1286,6 @@ static void qrfColumnar(Qrf *p){
     }
     p->spec.eText = saved_eText;
     p->nRow++;
-    bCenter = 1;
-  }else{
-    bCenter = 0;
   }
   do{
     if( data.n+nColumn > data.nAlloc ){
@@ -1301,10 +1312,12 @@ static void qrfColumnar(Qrf *p){
   }
 
   /* Compute the width and alignment of every column */
-  memset(data.aAlign, p->spec.eDfltAlign, nColumn);
-  for(i=0; i<nColumn && i<p->spec.nAlign; i++){
-    data.aAlign[i] = p->spec.aAlign[i];
+  if( p->spec.bColumnNames==QRF_Yes ){
+    memset(data.aAlign, p->spec.eTitleAlign, nColumn);
+  }else{
+    qrfLoadAlignment(&data, p);
   }
+
   for(i=0; i<nColumn; i++){
     int w = 0;
     if( i<p->spec.nWidth ){
@@ -1343,9 +1356,10 @@ static void qrfColumnar(Qrf *p){
     data.aiCol[i] = w;
   }
 
-  /* TBD: Narrow columns so that the total is less the p->spec.mxTotalWidth */
+  /* TBD: Narrow columns so that the total is less than p->spec.mxTotalWidth */
 
-  /* Draw the line across the top of the table */
+  /* Draw the line across the top of the table.  Also initialize
+  ** the row boundary and column separator texts. */
   switch( p->spec.eStyle ){
     case QRF_STYLE_Box:
       rowStart = BOX_13 " ";
@@ -1377,6 +1391,11 @@ static void qrfColumnar(Qrf *p){
   bWW = (p->spec.bWordWrap==QRF_Yes && data.bMultiRow);
   for(i=0; i<data.n; i+=nColumn){
     int bMore;
+
+    /* Draw a single row of the table.  This might be the title line
+    ** (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; j<nColumn; j++){ data.azThis[j] = data.az[i+j]; }
     do{
       sqlite3_str_append(p->pOut, rowStart, szRowStart);
@@ -1388,7 +1407,7 @@ static void qrfColumnar(Qrf *p){
         int nWS;
         qrfWrapLine(data.azThis[j], data.aiCol[j], bWW, &nThis, &nWide, &iNext);
         nWS = data.aiCol[j] - nWide;
-        if( bCenter || (data.aAlign[j] & QRF_ALIGN_HMASK)==QRF_ALIGN_Center ){
+        if( (data.aAlign[j] & QRF_ALIGN_HMASK)==QRF_ALIGN_Center ){
           /* Center the text */
           sqlite3_str_appendchar(p->pOut, nWS/2, ' ');
           sqlite3_str_append(p->pOut, data.azThis[j], nThis);
@@ -1411,29 +1430,37 @@ static void qrfColumnar(Qrf *p){
         }
       }
     }while( bMore );
-    bCenter = 0;
+
+    /* Draw either (1) the separator between the title line and the body
+    ** of the table, or (2) separators between individual rows of the table
+    ** body.  isTitleDataSeparator will be true if we are doing (1).
+    */
     if( (i==0 || data.bMultiRow) && i+nColumn<data.n ){
+      int isTitleDataSeparator = (i==0 && p->spec.bColumnNames==QRF_Yes);
+      if( isTitleDataSeparator ){
+        qrfLoadAlignment(&data, p);
+      }
       switch( p->spec.eStyle ){
         case QRF_STYLE_Table: {
-          if( (i==0 && p->spec.bColumnNames==QRF_Yes) || data.bMultiRow ){
+          if( isTitleDataSeparator || data.bMultiRow ){
             qrfRowSeparator(p->pOut, &data, '+');
           }
           break;
         }
         case QRF_STYLE_Box: {
-          if( (i==0 && p->spec.bColumnNames==QRF_Yes) || data.bMultiRow ){
+          if( isTitleDataSeparator || data.bMultiRow ){
             qrfBoxSeparator(p->pOut, &data, BOX_123, BOX_1234, BOX_134);
           }
           break;
         }
         case QRF_STYLE_Markdown: {
-          if( i==0 && p->spec.bColumnNames==QRF_Yes ){
+          if( isTitleDataSeparator ){
             qrfRowSeparator(p->pOut, &data, '|');
           }
           break;
         }
         case QRF_STYLE_Column: {
-          if( i==0 && p->spec.bColumnNames==QRF_Yes ){
+          if( isTitleDataSeparator ){
             for(j=0; j<nColumn; j++){
               sqlite3_str_appendchar(p->pOut, data.aiCol[j], '-');
               if( j<nColumn-1 ){
index 5fc156e9267b178b85a34c377e8d44aa98a93dda..76ebd4f83b120cd048c166a4eb18005f4736bc20 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Separate\scolumn\swidth\sspecification\sfrom\scell\salignment.
-D 2025-11-08T14:04:29.620
+C Miscellaneous\sfixes\sto\sthe\snew\salignment\sconfigurations.
+D 2025-11-08T15:25:07.110
 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 7c32e08e1cc5bb704f243a641ddfaf2f00152bbeb62c3a621efcf9371e6b156b
-F ext/qrf/qrf.c 2aed044a15f9776f5e142021a0cced555c510b84ff99cc148ea058bbd927960f
+F ext/qrf/qrf.c 0592756f5b4d072790c3ff052a56b40dd4fbcd3c1420f4c60cfd4f457a329f1b
 F ext/qrf/qrf.h 3917767fdd7547bded156327f2b6bf3e1dbf6c7ea787f67f31453815986fe780
 F ext/rbu/rbu.c 801450b24eaf14440d8fd20385aacc751d5c9d6123398df41b1b5aa804bf4ce8
 F ext/rbu/rbu1.test 25870dd7db7eb5597e2b4d6e29e7a7e095abf332660f67d89959552ce8f8f255
@@ -743,7 +743,7 @@ F src/sqliteInt.h 88f7fc9ce1630d9a5f7e0a8e1f3287cdc63882fba985c18e7eee1b9f457f59
 F src/sqliteLimit.h fe70bd8983e5d317a264f2ea97473b359faf3ebb0827877a76813f5cf0cdc364
 F src/status.c 7565d63a79aa2f326339a24a0461a60096d0bd2bce711fefb50b5c89335f3592
 F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1
-F src/tclsqlite.c be06a88784bea622f3ceacdfadc69ca5bf62dee350f8b0ceea111d2944217364
+F src/tclsqlite.c fb6c9e86386f9401b2858e0ec91b06a56e6c06c1ac131fba0419fd82d72aaa1a
 F src/tclsqlite.h 614b3780a62522bc9f8f2b9fb22689e8009958e7aa77e572d0f3149050af348a
 F src/test1.c f880ab766eeedf2c063662bd9538b923fd42c4341b7bfc2150a6d93ab8b9341c
 F src/test2.c 62f0830958f9075692c29c6de51b495ae8969e1bef85f239ffcd9ba5fb44a5ff
@@ -1506,7 +1506,7 @@ F test/printf2.test 3f55c1871a5a65507416076f6eb97e738d5210aeda7595a74ee895f2224c
 F test/progress.test ebab27f670bd0d4eb9d20d49cef96e68141d92fb
 F test/ptrchng.test ef1aa72d6cf35a2bbd0869a649b744e9d84977fc
 F test/pushdown.test 46a626ef1c0ca79b85296ff2e078b9da20a50e9b804b38f441590c3987580ddd
-F test/qrf01.test d0f655dbd4071d475d878e47a7c17693784bc4653df198df431b1dd3b30d8ea0
+F test/qrf01.test 6053b4680c9d939dd210d2536fa77d3e54ede9f44c2884db261a79612fa28399
 F test/qrf02.test 39b4afdc000bedccdafc0aecf17638df67a67aaa2d2942865ae6abcc48ba0e92
 F test/queryonly.test 5f653159e0f552f0552d43259890c1089391dcca
 F test/quick.test 1681febc928d686362d50057c642f77a02c62e57
@@ -2173,8 +2173,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 b429e7882fd630a490350efa38bfce8686d6727f324a60191337a59d5436828b
-R 1329d55649e069457afc085261020c3a
+P 5dadfd7f41764ddfed39bb49bbde3a54d8f282bb494c9c2abbba37d0995a7f8e
+R b5ca6911301d259c44cb06229f6e8f82
 U drh
-Z cebf3ea2c0f08016d910b76b9d9d0544
+Z 62a882cb37c25b41ad74b0d2277aeced
 # Remove this line to create a well-formed Fossil manifest.
index 473b80e939ced78d8c372db17773437a689bfb5b..23bc4676b8ae02f09c24e9601d2873f2cd099320 100644 (file)
@@ -1 +1 @@
-5dadfd7f41764ddfed39bb49bbde3a54d8f282bb494c9c2abbba37d0995a7f8e
+787fb4c2ac80db6552bc7a740c3c3c63c0c8414cb4e7db80d367b4b5512519d0
index aa6e80deb83b638177f027ad92fa04435a30011c..c6008f5a689d09fc06db0e9e6cb5c1e3531ce08d 100644 (file)
@@ -2246,7 +2246,7 @@ static int dbQrf(SqliteDb *pDb, int objc, Tcl_Obj *const*objv){
     }else if( strcmp(zArg,"-defaultalign")==0 || strcmp(zArg,"-titlealign")==0){
       int ax = 0;
       rc = Tcl_GetIndexFromObj(pDb->interp, objv[i+1], azAlign,
-                    zArg[1]=='d' ?  "default alignment (-dfltalign)" :
+                    zArg[1]=='d' ?  "default alignment (-defaultalign)" :
                                     "title alignment (-titlealign)",
                     0, &ax);
       if( rc ) goto format_failed;
@@ -2298,9 +2298,9 @@ static int dbQrf(SqliteDb *pDb, int objc, Tcl_Obj *const*objv){
         rc = Tcl_ListObjIndex(pDb->interp, objv[i+1], jj, &pTerm);
         if( rc ) goto format_failed;
         rc = Tcl_GetIndexFromObj(pDb->interp, pTerm, azAlign,
-                          "column alignement (-align)", 0, &x);
+                          "column alignment (-align)", 0, &x);
         if( rc ) goto format_failed;
-        qrf.aAlign[jj] = x;
+        qrf.aAlign[jj] = aAlignMap[x];
       }
       i++;
     }else if( strcmp(zArg,"-widths")==0 ){
index 44fa2e37da88efed08e04d177fece9e944a28c3d..86ec135e821e2271e9218ba4096c48a651dcba55 100644 (file)
@@ -390,11 +390,53 @@ do_test 2.6 {
 │       │       │ own dog.           │
 └───────┴───────┴────────────────────┘
 }
+do_test 2.7 {
+  set result "\n[db format -widths {5 5 18} -wordwrap yes \
+                 -align {left center right} -titlealign right \
+                 {SELECT * FROM t1}]"
+} {
+┌───────┬───────┬────────────────────┐
+│     a │     b │                  c │
+├───────┼───────┼────────────────────┤
+│ 1     │   2   │      The quick fox │
+│       │       │     jumps over the │
+│       │       │    lazy brown dog. │
+└───────┴───────┴────────────────────┘
+}
+do_test 2.8 {
+  set result "\n[db format -widths {5 8 11} -wordwrap yes \
+                 -align {auto auto center} -titlealign left \
+                 -defaultalign right \
+                 {SELECT * FROM t1}]"
+} {
+┌───────┬──────────┬─────────────┐
+│ a     │ b        │ c           │
+├───────┼──────────┼─────────────┤
+│     1 │        2 │  The quick  │
+│       │          │  fox jumps  │
+│       │          │  over the   │
+│       │          │ lazy brown  │
+│       │          │    dog.     │
+└───────┴──────────┴─────────────┘
+}
+do_test 2.9 {
+  catch {db format -align {auto xyz 123} {SELECT * FROM t1}} res
+  set res
+} {bad column alignment (-align) "xyz": must be auto, bottom, c, center, e, left, middle, n, ne, nw, right, s, se, sw, top, or w}
+do_test 2.10 {
+  catch {db format -defaultalign xyz {SELECT * FROM t1}} res
+  set res
+} {bad default alignment (-defaultalign) "xyz": must be auto, bottom, c, center, e, left, middle, n, ne, nw, right, s, se, sw, top, or w}
+do_test 2.11 {
+  catch {db format -titlealign xyz {SELECT * FROM t1}} res
+  set res
+} {bad title alignment (-titlealign) "xyz": must be auto, bottom, c, center, e, left, middle, n, ne, nw, right, s, se, sw, top, or w}
 
-do_execsql_test 2.10 {
+
+do_execsql_test 2.30 {
   UPDATE t1 SET c='Η γρήγορη αλεπού πηδάει πάνω από το τεμπέλικο καφέ σκυλί';
 }
-do_test 2.11 {
+do_test 2.31 {
   set result "\n[db format -widths {5 -5 18} -wordwrap on \
                  {SELECT * FROM t1}]"
 } {
@@ -407,7 +449,7 @@ do_test 2.11 {
 │       │       │ σκυλί              │
 └───────┴───────┴────────────────────┘
 }
-do_test 2.12 {
+do_test 2.32 {
   set result "\n[db format -widths {5 5 18} -align {left center center} -wordwrap on \
                  {SELECT * FROM t1}]"
 } {