]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Use the new "split" mode to simplify and improve the implementation of
authordrh <>
Sun, 23 Nov 2025 00:10:06 +0000 (00:10 +0000)
committerdrh <>
Sun, 23 Nov 2025 00:10:06 +0000 (00:10 +0000)
the ".tables" and ".indexes" commands in the CLI.  Fix a bug in QRF
that this new implementation found.

FossilOrigin-Name: b73df612b621699cd58de6ef327fefdeb8f52eb620f0d2df00d38ff6608a8dd5

ext/qrf/qrf.c
manifest
manifest.uuid
src/shell.c.in

index bd1f43c9bacafaa6e4a9760b0506ab5ba27c306d..3b2405ed2e35c259e2f704b3e5e02972230b8e81 100644 (file)
@@ -1785,6 +1785,7 @@ static void qrfColumnar(Qrf *p){
   }
 
   if( nColumn==1
+   && data.n>1
    && p->spec.bSplitColumn==QRF_Yes
    && p->spec.eStyle==QRF_STYLE_Column
    && p->spec.bTitles==QRF_No
index a7d46221360b34f85c306d9e5ffda91327f7d1d2..7e1c82a507763193e4cfd98cba72c30dd0648f62 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Add\s"split"\smode\sin\sthe\sCLI.\s\sFix\sCLI\scommands\sgiven\son\sthe\scommand\sline\nso\sthat\sthey\shonor\s--once\sin\sprior\scommands.
-D 2025-11-22T23:34:53.769
+C Use\sthe\snew\s"split"\smode\sto\ssimplify\sand\simprove\sthe\simplementation\sof\nthe\s".tables"\sand\s".indexes"\scommands\sin\sthe\sCLI.\s\sFix\sa\sbug\sin\sQRF\nthat\sthis\snew\simplementation\sfound.
+D 2025-11-23T00:10:06.101
 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 dd565fd1ca0c46ea37dbf4d496e368b9ecade768c92669640bc106e039629016
-F ext/qrf/qrf.c 032b61e09ace375674d27789688a957ee38518850b0fa588b6cf828850f62345
+F ext/qrf/qrf.c 1dea934e7af5718ce64c8101182250cdfcf2954ec6263496ed2847ca39e336e2
 F ext/qrf/qrf.h bccc9d1c1b6a05fa0da56332bba29d85782318926f022c849114a63da916393f
 F ext/rbu/rbu.c 801450b24eaf14440d8fd20385aacc751d5c9d6123398df41b1b5aa804bf4ce8
 F ext/rbu/rbu1.test 25870dd7db7eb5597e2b4d6e29e7a7e095abf332660f67d89959552ce8f8f255
@@ -735,7 +735,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c
 F src/resolve.c 5616fbcf3b833c7c705b24371828215ad0925d0c0073216c4f153348d5753f0a
 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97
 F src/select.c ba9cd07ffa3277883c1986085f6ddc4320f4d35d5f212ab58df79a7ecc1a576a
-F src/shell.c.in 977f8b9b108f37cdcce4c1a0f17e7809666aaa6c504f0752eb8c4ec7122999c4
+F src/shell.c.in 7f4a56ac62b5030755e72c5a9598b45782a0deccba350605b13d6d7b48e58b2d
 F src/sqlite.h.in f1363321ca55cc2feaa289e9fe6dfb08102a28c54edf005564711a2348b06eef
 F src/sqlite3.rc 015537e6ac1eec6c7050e17b616c2ffe6f70fca241835a84a4f0d5937383c479
 F src/sqlite3ext.h 5d5330f5f8461f5ce74960436ddcfa53ecd09c2b8b23901e22ae38aec3243998
@@ -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 3cee168e8801481f6d909fb5d20a773b9c6ca0b8daedfc301c9d762a17f9d839
-R 53605c07fff250aecf8e1982cc6fddce
+P 2530f04d1bb02b800fda83544f5b5dcd42f52b3e56ad625cd03b40e42f24ac6b
+R 51d2374ea006c46fbfbd23ef805a7a3f
 U drh
-Z 5d5dcf7a665f0cd59987ab755e809ab9
+Z 753707664ad527223b8edfa6977e8080
 # Remove this line to create a well-formed Fossil manifest.
index 10635e60bb77acc8bfa9e3caee98358fe00af8f9..8e781dd5db436db0c5d2026374d126edfac891a7 100644 (file)
@@ -1 +1 @@
-2530f04d1bb02b800fda83544f5b5dcd42f52b3e56ad625cd03b40e42f24ac6b
+b73df612b621699cd58de6ef327fefdeb8f52eb620f0d2df00d38ff6608a8dd5
index aab18624a5d15e73fd7a5232fc743a4f6e9816fb..1be0db50e36193a0877461b26c02b420ab11079a 100644 (file)
@@ -10784,12 +10784,11 @@ static int do_meta_command(const char *zLine, ShellState *p){
    || (c=='i' && (cli_strncmp(azArg[0], "indices", n)==0
                  || cli_strncmp(azArg[0], "indexes", n)==0) )
   ){
-    sqlite3_stmt *pStmt;
-    char **azResult;
-    int nRow, nAlloc;
     int ii;
-    ShellText s;
-    initText(&s);
+    sqlite3_stmt *pStmt;
+    sqlite3_str *pSql;
+    const char *zPattern = nArg>1 ? azArg[1] : 0;
+
     open_db(p, 0);
     rc = sqlite3_prepare_v2(p->db, "PRAGMA database_list", -1, &pStmt, 0);
     if( rc ){
@@ -10806,86 +10805,46 @@ static int do_meta_command(const char *zLine, ShellState *p){
       sqlite3_finalize(pStmt);
       goto meta_command_exit;
     }
+    pSql = sqlite3_str_new(p->db);
     for(ii=0; sqlite3_step(pStmt)==SQLITE_ROW; ii++){
       const char *zDbName = (const char*)sqlite3_column_text(pStmt, 1);
       if( zDbName==0 ) continue;
-      if( s.zTxt && s.zTxt[0] ) appendText(&s, " UNION ALL ", 0);
+      if( sqlite3_str_length(pSql) ){
+        sqlite3_str_appendall(pSql, " UNION ALL ");
+      }
       if( sqlite3_stricmp(zDbName, "main")==0 ){
-        appendText(&s, "SELECT name FROM ", 0);
+        sqlite3_str_appendall(pSql, "SELECT name FROM ");
       }else{
-        appendText(&s, "SELECT ", 0);
-        appendText(&s, zDbName, '\'');
-        appendText(&s, "||'.'||name FROM ", 0);
+        sqlite3_str_appendf(pSql, "SELECT %Q||'.'||name FROM ", zDbName);
       }
-      appendText(&s, zDbName, '"');
-      appendText(&s, ".sqlite_schema ", 0);
+      sqlite3_str_appendf(pSql, "\"%w\".sqlite_schema", zDbName);
       if( c=='t' ){
-        appendText(&s," WHERE type IN ('table','view')"
-                      "   AND name NOT LIKE 'sqlite__%' ESCAPE '_'"
-                      "   AND name LIKE ?1", 0);
+        sqlite3_str_appendf(pSql,
+            " WHERE type IN ('table','view')"
+            "   AND name NOT LIKE 'sqlite__%%' ESCAPE '_'"
+        );
+        if( zPattern ){
+          sqlite3_str_appendf(pSql," AND name LIKE %Q", zPattern);
+        }
       }else{
-        appendText(&s," WHERE type='index'"
-                      "   AND tbl_name LIKE ?1", 0);
+        sqlite3_str_appendf(pSql, " WHERE type='index'");
+        if( zPattern ){
+          sqlite3_str_appendf(pSql," AND tbl_name LIKE %Q", zPattern);
+        }
       }
     }
     rc = sqlite3_finalize(pStmt);
     if( rc==SQLITE_OK ){
-      appendText(&s, " ORDER BY 1", 0);
-      rc = sqlite3_prepare_v2(p->db, s.zTxt, -1, &pStmt, 0);
+      sqlite3_str_appendall(pSql, " ORDER BY 1");
     }
-    freeText(&s);
-    if( rc ) return shellDatabaseError(p->db);
 
-    /* Run the SQL statement prepared by the above block. Store the results
-    ** as an array of nul-terminated strings in azResult[].  */
-    nRow = nAlloc = 0;
-    azResult = 0;
-    if( nArg>1 ){
-      sqlite3_bind_text(pStmt, 1, azArg[1], -1, SQLITE_TRANSIENT);
-    }else{
-      sqlite3_bind_text(pStmt, 1, "%", -1, SQLITE_STATIC);
-    }
-    while( sqlite3_step(pStmt)==SQLITE_ROW ){
-      if( nRow>=nAlloc ){
-        char **azNew;
-        sqlite3_int64 n2 = 2*(sqlite3_int64)nAlloc + 10;
-        azNew = sqlite3_realloc64(azResult, sizeof(azResult[0])*n2);
-        shell_check_oom(azNew);
-        nAlloc = (int)n2;
-        azResult = azNew;
-      }
-      azResult[nRow] = sqlite3_mprintf("%s", sqlite3_column_text(pStmt, 0));
-      shell_check_oom(azResult[nRow]);
-      nRow++;
-    }
-    if( sqlite3_finalize(pStmt)!=SQLITE_OK ){
-      rc = shellDatabaseError(p->db);
-    }
-
-    /* Pretty-print the contents of array azResult[] to the output */
-    if( rc==0 && nRow>0 ){
-      int len, maxlen = 0;
-      int i, j;
-      int nPrintCol, nPrintRow;
-      for(i=0; i<nRow; i++){
-        len = strlen30(azResult[i]);
-        if( len>maxlen ) maxlen = len;
-      }
-      nPrintCol = shellScreenWidth()/(maxlen+2);
-      if( nPrintCol<1 ) nPrintCol = 1;
-      nPrintRow = (nRow + nPrintCol - 1)/nPrintCol;
-      for(i=0; i<nPrintRow; i++){
-        for(j=i; j<nRow; j+=nPrintRow){
-          char *zSp = j<nPrintRow ? "" : "  ";
-          cli_printf(p->out,
-               "%s%-*s", zSp, maxlen, azResult[j] ? azResult[j]:"");
-        }
-        cli_puts("\n", p->out);
-      }
-    }
-
-    for(ii=0; ii<nRow; ii++) sqlite3_free(azResult[ii]);
-    sqlite3_free(azResult);
+    /* Run the SQL statement in "split" mode. */
+    modePush(p);
+    modeChange(p, MODE_Split);
+    shell_exec(p, sqlite3_str_value(pSql), 0);
+    sqlite3_str_free(pSql);
+    modePop(p);
+    if( rc ) return shellDatabaseError(p->db);
   }else
 
 #ifndef SQLITE_SHELL_FIDDLE