]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add the "www" output mode that include <table> in the HTML output.
authordrh <>
Wed, 25 Sep 2024 13:29:03 +0000 (13:29 +0000)
committerdrh <>
Wed, 25 Sep 2024 13:29:03 +0000 (13:29 +0000)
Add the ".www" command and the "-w" option to ".once".

FossilOrigin-Name: b06fd9e6bcce09f12c994dc34f329a8d267ea0601bb07c9b00903c5017d55d42

manifest
manifest.uuid
src/shell.c.in

index 1494e6c0218ac159fcd9f5452130cb897aea8af5..c421c9dd6a8465dd056cd293d4b1411d628c4a8a 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Always\sinclude\sa\sUTF-8\sBOM\sat\sthe\sbeginning\sof\sthe\soutput\sCSV\swhen\susing\nthe\s".excel"\scommand\son\sWindows,\sas\sthe\sactual\sExcel\sprogram\srequires\sthe\nBOM\sin\sorder\sto\swork\scorrectly.
-D 2024-09-25T12:56:44.564
+C Add\sthe\s"www"\soutput\smode\sthat\sinclude\s&lt;table&gt;\sin\sthe\sHTML\soutput.\nAdd\sthe\s".www"\scommand\sand\sthe\s"-w"\soption\sto\s".once".
+D 2024-09-25T13:29:03.338
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -770,7 +770,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c
 F src/resolve.c 9750a281f7ba073b4e6da2be1a6c4071f5d841a7746c5fb3f70d6d793b6675ea
 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97
 F src/select.c 4b14337a2742f0c0beeba490e9a05507e9b4b12184b9cd12773501d08d48e3fe
-F src/shell.c.in be499bb6bcd951a7fa9480588a824a03cef863c334f1843a2f4b76bcf31bd616
+F src/shell.c.in 9781ab726a108a10f8722d0d5e10c548d6f797ceef8d1a257a4e2cdc107bffc0
 F src/sqlite.h.in 77f55bd1978a04a14db211732f0a609077cf60ba4ccf9baf39988f508945419c
 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54
@@ -2215,8 +2215,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 1ee3fa0f0e87a61b5700abd56547c4acefe999317b0d53d66d890d9e09d8b7d9
-R aa31813957ce0d0538591043958b4e17
+P 04727fc00207325a76a5d5f20549c00232810ac727dedb70bc9e8112e60b3f56
+R a9ce986cea2b862753a371f08d91ab92
 U drh
-Z 487c96328e404c2d5a7c68c4fa573337
+Z cd53dd6e20071a9c7b2de3e7e318715b
 # Remove this line to create a well-formed Fossil manifest.
index 31a0367380f55ebd5836dfd5984bb881fd419a6b..2fedfa4050a2df5df7b12a138157315d8dcbd7cf 100644 (file)
@@ -1 +1 @@
-04727fc00207325a76a5d5f20549c00232810ac727dedb70bc9e8112e60b3f56
+b06fd9e6bcce09f12c994dc34f329a8d267ea0601bb07c9b00903c5017d55d42
index c6beeee0daaa91d45c7ec26a9af6b847b610aeb8..9581c5c3cbe8a0cc889a1eece014557fca54ce39 100644 (file)
@@ -1596,6 +1596,7 @@ static ShellState shellState;
 #define MODE_Count   17  /* Output only a count of the rows of output */
 #define MODE_Off     18  /* No query output shown */
 #define MODE_ScanExp 19  /* Like MODE_Explain, but for ".scanstats vm" */
+#define MODE_Www     20  /* Full web-page output */
 
 static const char *modeDescr[] = {
   "line",
@@ -1616,7 +1617,9 @@ static const char *modeDescr[] = {
   "table",
   "box",
   "count",
-  "off"
+  "off",
+  "scanexp",
+  "www",
 };
 
 /*
@@ -2728,8 +2731,13 @@ static int shell_callback(
       }
       break;
     }
+    case MODE_Www:
     case MODE_Html: {
-      if( p->cnt++==0 && p->showHeader ){
+      if( p->cnt==0 && p->cMode==MODE_Www ){
+        sqlite3_fputs(
+          "<TABLE border='1' cellspacing='0' cellpadding='2'>\n",p->out);
+      }
+      if( p->cnt==0 && p->showHeader ){
         sqlite3_fputs("<TR>", p->out);
         for(i=0; i<nArg; i++){
           sqlite3_fputs("<TH>", p->out);
@@ -2738,6 +2746,7 @@ static int shell_callback(
         }
         sqlite3_fputs("</TR>\n", p->out);
       }
+      p->cnt++;
       if( azArg==0 ) break;
       sqlite3_fputs("<TR>", p->out);
       for(i=0; i<nArg; i++){
@@ -4275,6 +4284,8 @@ static void exec_prepared_stmt(
       sqlite3_free(pData);
       if( pArg->cMode==MODE_Json ){
         sqlite3_fputs("]\n", pArg->out);
+      }else if( pArg->cMode==MODE_Www ){
+        sqlite3_fputs("</TABLE>\n", pArg->out);
       }else if( pArg->cMode==MODE_Count ){
         char zBuf[200];
         sqlite3_snprintf(sizeof(zBuf), zBuf, "%llu row%s\n",
@@ -5029,6 +5040,7 @@ static const char *(azHelp[]) = {
   "     If FILE begins with '|' then open as a pipe",
   "       --bom  Put a UTF8 byte-order mark at the beginning",
   "       -e     Send output to the system text editor",
+  "       -w     Send output as HTML to a web browser (same as \".www\")",
   "       -x     Send output as CSV to a spreadsheet (same as \".excel\")",
   /* Note that .open is (partially) available in WASM builds but is
   ** currently only intended to be used by the fiddle tool, not
@@ -5165,6 +5177,9 @@ static const char *(azHelp[]) = {
   ".vfsname ?AUX?           Print the name of the VFS stack",
   ".width NUM1 NUM2 ...     Set minimum column widths for columnar output",
   "     Negative values right-justify",
+#ifndef SQLITE_SHELL_FIDDLE
+  ".www                     Display output of the next command in web browser",
+#endif
 };
 
 /*
@@ -9702,6 +9717,8 @@ static int do_meta_command(char *zLine, ShellState *p){
       sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
     }else if( cli_strncmp(zMode,"html",n2)==0 ){
       p->mode = MODE_Html;
+    }else if( cli_strncmp(zMode,"www",n2)==0 ){
+      p->mode = MODE_Www;
     }else if( cli_strncmp(zMode,"tcl",n2)==0 ){
       p->mode = MODE_Tcl;
       sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Space);
@@ -9873,12 +9890,13 @@ static int do_meta_command(char *zLine, ShellState *p){
         && (cli_strncmp(azArg[0], "output", n)==0
             || cli_strncmp(azArg[0], "once", n)==0))
    || (c=='e' && n==5 && cli_strcmp(azArg[0],"excel")==0)
+   || (c=='w' && n==3 && cli_strcmp(azArg[0],"www")==0)
   ){
     char *zFile = 0;
     int bTxtMode = 0;
     int i;
     int eMode = 0;
-    int bOnce = 0;            /* 0: .output, 1: .once, 2: .excel */
+    int bOnce = 0;            /* 0: .output, 1: .once, 2: .excel/.www */
     static const char *zBomUtf8 = "\xef\xbb\xbf";
     const char *zBom = 0;
 
@@ -9886,6 +9904,9 @@ static int do_meta_command(char *zLine, ShellState *p){
     if( c=='e' ){
       eMode = 'x';
       bOnce = 2;
+    }else if( c=='w' ){
+      eMode = 'w';
+      bOnce = 2;
     }else if( cli_strncmp(azArg[0],"once",n)==0 ){
       bOnce = 1;
     }
@@ -9895,10 +9916,12 @@ static int do_meta_command(char *zLine, ShellState *p){
         if( z[1]=='-' ) z++;
         if( cli_strcmp(z,"-bom")==0 ){
           zBom = zBomUtf8;
-        }else if( c!='e' && cli_strcmp(z,"-x")==0 ){
+        }else if( c=='o' && cli_strcmp(z,"-x")==0 ){
           eMode = 'x';  /* spreadsheet */
-        }else if( c!='e' && cli_strcmp(z,"-e")==0 ){
+        }else if( c=='o' && cli_strcmp(z,"-e")==0 ){
           eMode = 'e';  /* text editor */
+        }else if( c=='o' && cli_strcmp(z,"-w")==0 ){
+          eMode = 'w';  /* Web browser */
         }else{
           sqlite3_fprintf(p->out, 
                           "ERROR: unknown option: \"%s\". Usage:\n", azArg[i]);
@@ -9906,7 +9929,7 @@ static int do_meta_command(char *zLine, ShellState *p){
           rc = 1;
           goto meta_command_exit;
         }
-      }else if( zFile==0 && eMode!='e' && eMode!='x' ){
+      }else if( zFile==0 && eMode==0 ){
         zFile = sqlite3_mprintf("%s", z);
         if( zFile && zFile[0]=='|' ){
           while( i+1<nArg ) zFile = sqlite3_mprintf("%z %s", zFile, azArg[++i]);
@@ -9931,7 +9954,7 @@ static int do_meta_command(char *zLine, ShellState *p){
     }
     output_reset(p);
 #ifndef SQLITE_NOHAVE_SYSTEM
-    if( eMode=='e' || eMode=='x' ){
+    if( eMode=='e' || eMode=='x' || eMode=='w' ){
       p->doXdgOpen = 1;
       outputModePush(p);
       if( eMode=='x' ){
@@ -9945,6 +9968,11 @@ static int do_meta_command(char *zLine, ShellState *p){
         zBom = zBomUtf8;  /* Always include the BOM on Windows, as Excel does
                           ** not work without it. */
 #endif
+      }else if( eMode=='w' ){
+        /* web-browser mode. */
+        newTempFile(p, "html");
+        p->mode = MODE_Www;
+        bTxtMode = 1;
       }else{
         /* text editor mode */
         newTempFile(p, "txt");
@@ -12979,6 +13007,8 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
       i++;
     }else if( cli_strcmp(z,"-html")==0 ){
       data.mode = MODE_Html;
+    }else if( cli_strcmp(z,"-www")==0 ){
+      data.mode = MODE_Www;
     }else if( cli_strcmp(z,"-list")==0 ){
       data.mode = MODE_List;
     }else if( cli_strcmp(z,"-quote")==0 ){