From d0056d42345d6d0b2eecb0a27e0838c0f49f91e5 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sun, 23 Nov 2025 00:10:06 +0000 Subject: [PATCH] Use the new "split" mode to simplify and improve the implementation of 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 | 1 + manifest | 14 +++---- manifest.uuid | 2 +- src/shell.c.in | 101 +++++++++++++++---------------------------------- 4 files changed, 39 insertions(+), 79 deletions(-) diff --git a/ext/qrf/qrf.c b/ext/qrf/qrf.c index bd1f43c9ba..3b2405ed2e 100644 --- a/ext/qrf/qrf.c +++ b/ext/qrf/qrf.c @@ -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 diff --git a/manifest b/manifest index a7d4622136..7e1c82a507 100644 --- 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. diff --git a/manifest.uuid b/manifest.uuid index 10635e60bb..8e781dd5db 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2530f04d1bb02b800fda83544f5b5dcd42f52b3e56ad625cd03b40e42f24ac6b +b73df612b621699cd58de6ef327fefdeb8f52eb620f0d2df00d38ff6608a8dd5 diff --git a/src/shell.c.in b/src/shell.c.in index aab18624a5..1be0db50e3 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -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; imaxlen ) maxlen = len; - } - nPrintCol = shellScreenWidth()/(maxlen+2); - if( nPrintCol<1 ) nPrintCol = 1; - nPrintRow = (nRow + nPrintCol - 1)/nPrintCol; - for(i=0; iout, - "%s%-*s", zSp, maxlen, azResult[j] ? azResult[j]:""); - } - cli_puts("\n", p->out); - } - } - - for(ii=0; iidb); }else #ifndef SQLITE_SHELL_FIDDLE -- 2.47.3