From: drh <> Date: Wed, 12 Nov 2025 20:50:08 +0000 (+0000) Subject: Implement the --titles option to the .mode command. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2a376849ca3f04f6720eb8b6a0c4343859a9b914;p=thirdparty%2Fsqlite.git Implement the --titles option to the .mode command. FossilOrigin-Name: cc25643ebc516db0799406797e9961a2af574875ae9639178b722dbc280c96ad --- diff --git a/manifest b/manifest index d40b2abfb8..3c3b66d99c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C More\sdetails\son\sthe\sformat\sof\sthe\sQRF_STYLE_Json\sand\sQRF_STYLE_JOBject. -D 2025-11-12T19:03:05.399 +C Implement\sthe\s--titles\soption\sto\sthe\s.mode\scommand. +D 2025-11-12T20:50:08.766 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea @@ -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 7fda2605823e01dbd3bde96d3189eb38bd3ed838070be73aeeb0ccfe89af8db8 +F src/shell.c.in 38d89f01de5bc91c7434f78fcf4b94d3e66e277ceffb142dc5b5d23711f629f7 F src/sqlite.h.in 7403a952a8f1239de7525b73c4e3a0f9540ec0607ed24fec887f5832642d44b8 F src/sqlite3.rc 015537e6ac1eec6c7050e17b616c2ffe6f70fca241835a84a4f0d5937383c479 F src/sqlite3ext.h 7f236ca1b175ffe03316d974ef57df79b3938466c28d2f95caef5e08c57f3a52 @@ -2175,8 +2175,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 e5a81711d0076b447e5bd3206bc04d755a6229b9f4926f42260fcd01ecf3e5a2 -R 76112737074ceb401df2b0b97e912a74 +P 2b22321df9c2f51e4b0ab9e4da859c58bb3f194ad69c22b9d32b35831740f9dd +R c068c55668f3795ef991708cb18d63fc U drh -Z b0c78e230dd1f490c7f00e70bce17b1a +Z 7b64d6843e01c08dbcd5d8f2aef211b0 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 53639e1b1f..7fb39ddb9c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2b22321df9c2f51e4b0ab9e4da859c58bb3f194ad69c22b9d32b35831740f9dd +cc25643ebc516db0799406797e9961a2af574875ae9639178b722dbc280c96ad diff --git a/src/shell.c.in b/src/shell.c.in index 0e9f0d8ead..9f13d03c9a 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -1433,33 +1433,34 @@ struct ModeInfo { unsigned char eTitle; /* Header incoding. */ unsigned char eStyle; /* Underlying QRF style */ unsigned char eCx; /* 0: other, 1: line, 2: columnar */ + unsigned char bTx; /* Column headers enabled by default */ }; static const char *aModeStr[] = /* 0 1 2 3 4 5 6 7 8 9 10 11 */ { 0, "\n", "|", " ", ",", "\r\n", "\036", "\037", "\t", "", "NULL", "null" }; static const ModeInfo aModeInfo[] = { -/* zName eCSep eRSep eNull eText eBlob bHdr eTitle eStyle eCx */ - { "ascii", 7, 6, 9, 1, 1, 1, 1, 12, 0 }, - { "box", 0, 0, 9, 1, 1, 2, 1, 1, 2 }, - { "c", 4, 1, 2, 5, 4, 1, 5, 12, 0 }, - { "column", 0, 0, 9, 1, 1, 2, 1, 2, 2 }, - { "count", 0, 0, 0, 0, 0, 0, 0, 3, 0 }, - { "csv", 4, 5, 9, 3, 1, 1, 3, 12, 0 }, - { "html", 0, 0, 9, 4, 1, 2, 4, 7, 0 }, - { "insert", 0, 0, 10, 2, 2, 1, 2, 8, 0 }, - { "jatom", 4, 1, 11, 6, 5, 1, 6, 12, 0 }, - { "jobject", 0, 1, 11, 6, 5, 0, 0, 10, 0 }, - { "json", 0, 0, 11, 6, 6, 0, 0, 9, 0 }, - { "line", 0, 1, 9, 1, 1, 0, 0, 11, 1 }, - { "list", 2, 1, 9, 1, 1, 1, 1, 12, 0 }, - { "markdown", 0, 0, 9, 1, 1, 2, 1, 13, 2 }, - { "off", 0, 0, 0, 0, 0, 0, 0, 14, 0 }, - { "qbox", 0, 0, 9, 2, 2, 2, 1, 1, 2 }, - { "quote", 4, 1, 10, 2, 2, 1, 2, 12, 0 }, - { "table", 0, 0, 9, 1, 1, 2, 1, 19, 2 }, - { "tabs", 8, 1, 9, 3, 1, 1, 3, 12, 0 }, - { "tcl", 3, 1, 9, 5, 4, 1, 5, 12, 0 }, - { "www", 0, 0, 9, 4, 1, 2, 4, 7, 0 }, +/* zName eCSep eRSep eNull eText eBlob bHdr eTitle eStyle eCx bTx */ + { "ascii", 7, 6, 9, 1, 1, 1, 1, 12, 0, 0 }, + { "box", 0, 0, 9, 1, 1, 2, 1, 1, 2, 1 }, + { "c", 4, 1, 2, 5, 4, 1, 5, 12, 0, 0 }, + { "column", 0, 0, 9, 1, 1, 2, 1, 2, 2, 1 }, + { "count", 0, 0, 0, 0, 0, 0, 0, 3, 0, 0 }, + { "csv", 4, 5, 9, 3, 1, 1, 3, 12, 0, 0 }, + { "html", 0, 0, 9, 4, 1, 2, 4, 7, 0, 0 }, + { "insert", 0, 0, 10, 2, 2, 1, 2, 8, 0, 0 }, + { "jatom", 4, 1, 11, 6, 5, 1, 6, 12, 0, 0 }, + { "jobject", 0, 1, 11, 6, 5, 0, 0, 10, 0, 0 }, + { "json", 0, 0, 11, 6, 6, 0, 0, 9, 0, 0 }, + { "line", 0, 1, 9, 1, 1, 0, 0, 11, 1, 0 }, + { "list", 2, 1, 9, 1, 1, 1, 1, 12, 0, 0 }, + { "markdown", 0, 0, 9, 1, 1, 2, 1, 13, 2, 1 }, + { "off", 0, 0, 0, 0, 0, 0, 0, 14, 0, 0 }, + { "qbox", 0, 0, 9, 2, 2, 2, 1, 1, 2, 1 }, + { "quote", 4, 1, 10, 2, 2, 1, 2, 12, 0, 0 }, + { "table", 0, 0, 9, 1, 1, 2, 1, 19, 2, 1 }, + { "tabs", 8, 1, 9, 3, 1, 1, 3, 12, 0, 0 }, + { "tcl", 3, 1, 9, 5, 4, 1, 5, 12, 0, 0 }, + { "www", 0, 0, 9, 4, 1, 2, 4, 7, 0, 1 }, }; /* | / / \ \ | / / ** | / / \ \ | / / ** First three columns These five column use integers that @@ -7237,6 +7238,10 @@ static int pickStr(const char *zArg, char **pzErr, ...){ ** ** --textjsonb BOOLEAN If enabled, JSONB text is displayed as text JSON. ** +** --title ARG Whether or not to show column headers, and if so +** how to encode them. ARG can be "off", "on", +** "sql", "csv", "html", "tcl", or "json". +** ** -v|--verbose Verbose output ** ** --widths LIST Set the columns widths for columnar modes. The @@ -7423,6 +7428,22 @@ static int dotCmdMode(ShellState *p){ } p->mode.spec.bTextJsonb = booleanValue(azArg[++i]) ? QRF_Yes : QRF_No; chng = 1; + }else if( optionMatch(z,"titles") ){ + char *zErr = 0; + if( i+1>=nArg ){ + dotCmdError(p, i, "missing argument", 0); + return 1; + } + k = pickStr(azArg[++i],&zErr, + "off","on","plain","sql","html","tcl","json",""); + /* 0 1 2 3 4 5 6 */ + if( k<0 ){ + dotCmdError(p, i, "bad --titles value","%z", zErr); + return 1; + } + p->mode.spec.bTitles = k>=1 ? QRF_Yes : QRF_No; + p->mode.spec.eTitle = k>1 ? k-1 : aModeInfo[p->mode.eMode].eTitle; + chng = 1; }else if( optionMatch(z,"widths") ){ int nWidth = 0; short int *aWidth; @@ -7497,6 +7518,8 @@ static int dotCmdMode(ShellState *p){ sqlite3_str *pDesc = sqlite3_str_new(p->db); char *zDesc; const char *zSetting; + int bSameTitle; + int bTitleOn; sqlite3_str_appendall(pDesc,pI->zName); if( bAll || (p->mode.spec.nAlign && pI->eCx==2) ){ int i; @@ -7554,6 +7577,20 @@ static int dotCmdMode(ShellState *p){ sqlite3_str_appendf(pDesc," --textjsonb %s", p->mode.spec.bTextJsonb==QRF_Yes ? "on" : "off"); } + bSameTitle = p->mode.spec.eTitle==pI->eTitle; + bTitleOn = (p->mode.spec.bTitles==QRF_Yes); + if( bAll || bTitleOn!=pI->bTx || (bTitleOn && !bSameTitle) ){ + static const char *azTitle[] = + { "off", "on", "plain", "sql", "csv", "html", "tcl", "json"}; + if( !bTitleOn ){ + k = 0; + }else if( bSameTitle ){ + k = 1; + }else{ + k = p->mode.spec.eTitle+1; + } + sqlite3_str_appendf(pDesc," --titles %s", azTitle[k]); + } if( p->mode.spec.nWidth>0 && (bAll || pI->eCx==2) ){ int i; const char *zSep = " --widths "; @@ -8721,6 +8758,7 @@ static int do_meta_command(const char *zLine, ShellState *p){ if( c=='h' && cli_strncmp(azArg[0], "headers", n)==0 ){ if( nArg==2 ){ p->mode.spec.bTitles = booleanValue(azArg[1]) ? QRF_Yes : QRF_No; + p->mode.spec.eTitle = aModeInfo[p->mode.eMode].eTitle; }else{ eputz("Usage: .headers on|off\n"); rc = 1;