]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Move shell extension load functionality into its own .shxload command for usage and...
authorlarrybr <larrybr@noemail.net>
Sun, 17 Apr 2022 19:22:42 +0000 (19:22 +0000)
committerlarrybr <larrybr@noemail.net>
Sun, 17 Apr 2022 19:22:42 +0000 (19:22 +0000)
FossilOrigin-Name: e2c8c88b4b4f2c23c42fb1fdb86c0ade2992ce2e5d7f23b06af0e9ea3eb6a4f9

Makefile.in
manifest
manifest.uuid
src/shell.c.in
test/shell_x/shell10.test

index 77b019ff8dffa143a327c15e460f43672b6f38ab..8e095174a6e82f069f632b89bebfe71b4336c68d 100644 (file)
@@ -1381,8 +1381,12 @@ valgrindtest:    $(TESTPROGS) valgrindfuzz
 smoketest:     $(TESTPROGS) fuzzcheck$(TEXE)
        ./testfixture$(TEXE) $(TOP)/test/main.test $(TESTOPTS)
 
+TESTRUNS_SHX = \
+ $(TOP)/test/shell_x/shell9.test \
+ $(TOP)/test/shell_x/shell10.test
+
 shellxtest: $(TESTPROGS_SHX)
-       ./testfixture$(TEXE) $(TOP)/test/shell_x/shell*.test
+       ./testfixture$(TEXE) $(TESTRUNS_SHX)
 
 shelltest: $(TESTPROGS)
        ./testfixture$(TEXE) $(TOP)/test/permutations.test shell
index e2bdb37c0281488b378917cbc769c6f5e1b3fc53..e36cbbcc5e9162f4c64af55609ef1ff2bee2d1e0 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,9 +1,9 @@
-C For\ssqlite3x,\srudimentary\stesting\sin\splace\sas\smake\starget\sshellxtest\s.\sMore\sto\scome.
-D 2022-04-17T00:48:49.519
+C Move\sshell\sextension\sload\sfunctionality\sinto\sits\sown\s.shxload\scommand\sfor\susage\sand\scode\ssimplicity.
+D 2022-04-17T19:22:42.509
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
-F Makefile.in a39224b4ea1038f67c9ae5049c832e6ab8a6485ea1580dc5c54c13a37a8479d0
+F Makefile.in 3a2d4e3a13c497b24b92fa36e93f80dc49844f1ca62e5a7848b899afe7105a37
 F Makefile.linux-gcc f609543700659711fbd230eced1f01353117621dccae7b9fb70daa64236c5241
 F Makefile.msc 689726a2785027e0eb34ea9ce8e67ac94bc4aebbaa6def20ddb6fa9f7b0c43b5
 F README.md 2dd87a5c1d108b224921f3dd47dea567973f706e1f6959386282a626f459a70c
@@ -557,7 +557,7 @@ F src/random.c 097dc8b31b8fba5a9aca1697aeb9fd82078ec91be734c16bffda620ced7ab83c
 F src/resolve.c 18d99e7146852d6064559561769fcca0743eb32b14a97da6dbed373a30ee0e76
 F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92
 F src/select.c 7c106b3f36d483242b0a9c696614cd53d6f29e1ac81da6a3f0e9ea92f4211cc3
-F src/shell.c.in 47c84d1511e44ef28fb215c70a80065c6c103650579743ac60a129f541af17b2
+F src/shell.c.in 80745b0842e8becc6dc6934e7c2e4d31928108285ce4d1199466042509b5fd9f
 F src/shext_linkage.h 41e7e665fffd125b38b8211dc650233d4fe54941acd8177f23d3deb9d6f70154
 F src/sqlite.h.in 2a35f62185eb5e7ecc64a2f68442b538ce9be74f80f28a00abc24837edcf1c17
 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
@@ -1404,7 +1404,7 @@ F test/shell5.test 39d2cffb3c1c67456b2c42eb5e46bec1e3780c68a6d71bb156e012d3f5373
 F test/shell6.test 1ceb51b2678c472ba6cf1e5da96679ce8347889fe2c3bf93a0e0fa73f00b00d3
 F test/shell7.test 115132f66d0463417f408562cc2cf534f6bbc6d83a6d50f0072a9eb171bae97f
 F test/shell8.test 388471d16e4de767333107e30653983f186232c0e863f4490bb230419e830aae
-F test/shell_x/shell10.test 9b396b83c3b150ffb4c3bca62600f28ed91d0e31a4f82d4de482e20f3b84570a
+F test/shell_x/shell10.test 80bf84e9d31ca4ec3db02dcecf9fb3febc4e76d717cd567141b2e2b64c816862
 F test/shell_x/shell9.test 22f15500ccdec5561cbedb3a4c28f0f2175a2b8eff1b837cc127de59c3bc0f73
 F test/shmlock.test 3dbf017d34ab0c60abe6a44e447d3552154bd0c87b41eaf5ceacd408dd13fda5
 F test/shortread1.test bb591ef20f0fd9ed26d0d12e80eee6d7ac8897a3
@@ -1954,9 +1954,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P d238fcf4beb0b121e4754e288df9906cb61d38a827f1fe38cf4aaa784520fc08
-Q +82366436ef74838dae1f379f3e5b8ad187225a30ec58fb49f047ab7c08a263cf
-R ef5b2dbf2d2afa126edf6b3816e08feb
+P b73928befb013622a369bf8f9904b5aeca626a5598884b4030229a33f684960f
+R 2c7fd3e4c92debe95d6c8ccc2dc84824
 U larrybr
-Z a3ff9fe808da85c8206c0da625259951
+Z bbb8449a12e35ee62f13674b7218bc2e
 # Remove this line to create a well-formed Fossil manifest.
index 9d45e0f0511c4cb20f9ba749e0fe7134d17d4a91..b2b2293f8f63a439cc5625639695554dc2d5e30a 100644 (file)
@@ -1 +1 @@
-b73928befb013622a369bf8f9904b5aeca626a5598884b4030229a33f684960f
\ No newline at end of file
+e2c8c88b4b4f2c23c42fb1fdb86c0ade2992ce2e5d7f23b06af0e9ea3eb6a4f9
\ No newline at end of file
index 5da38e325ef81a07cab2c9a94153079986b5943f..7ada78d6ad4f79c8a6a742e33aa683b19eb2a531 100644 (file)
@@ -1213,7 +1213,7 @@ struct EQPGraph {
 #define SHEXT_PARSING_BIT 0
 #define SHELL_EXTENDED_PARSING \
   NOT_IFDEF_BIT(SHELL_OMIT_EXTENSIONS, SHEXT_PARSING_BIT)
-/* Whether build will include runtime extension via .load -extension */
+/* Whether build will include runtime extension via .shxload */
 #define SHEXT_DYNEXT_BIT 1
 #define SHELL_DYNAMIC_EXTENSION ( !SHELL_OMIT_LOAD_EXTENSION \
   && NOT_IFDEF_BIT(SHELL_OMIT_EXTENSIONS, SHEXT_DYNEXT_BIT) )
@@ -9950,6 +9950,17 @@ DISPATCHABLE_COMMAND( iotrace ? 2 2 ){
   }
   return DCR_Ok;
 }
+
+/*****************
+ * The .limits and .load commands
+ */
+COLLECT_HELP_TEXT[
+  ",limits ?LIMIT_NAME?     Display limit selected by its name, or all limits",
+  ".load FILE ?ENTRY?       Load a SQLite extension library",
+  "   If ENTRY is provided, the entry point \"sqlite_ENTRY_init\" is called.",
+  "   Otherwise, the entry point name is derived from the FILE's name.",
+];
+
 DISPATCHABLE_COMMAND( limits 5 1 3 ){
   static const struct {
     const char *zLimitName;   /* Name of a limit */
@@ -10183,6 +10194,21 @@ DISPATCHABLE_COMMAND( lint 3 1 0 ){
   return DCR_Ok|(rc!=0);
 }
 
+DISPATCHABLE_COMMAND( load ? 2 3 ){
+  const char *zFile = 0, *zProc = 0;
+  int ai = 1, rc;
+  if( ISS(p)->bSafeMode ) return DCR_AbortError;
+  while( ai<nArg ){
+    const char *zA = azArg[ai++];
+    if( zFile==0 ) zFile = zA;
+    else if( zProc==0 ) zProc = zA;
+    else return DCR_TooMany|ai;
+  }
+  open_db(p, 0);
+  rc = sqlite3_load_extension(DBX(p), zFile, zProc, pzErr);
+  return DCR_Ok|(rc!=SQLITE_OK);
+}
+
 DISPATCHABLE_COMMAND( log ? 2 2 ){
   const char *zFile = azArg[1];
   if( ISS(p)->bSafeMode ) return DCR_AbortError;
@@ -10257,66 +10283,6 @@ static void effectMode(ShellInState *psi, u8 modeRequest, u8 modeNominal){
   psi->mode = modeNominal;
 }
 
-/*****************
- * The .load command
- * This is out of order to alleviate code clarity concerns.
- */
-#if SHELL_DYNAMIC_EXTENSION  /* Avoid confusing users or mkshellc.tcl here. */
-# define LDEXT_OPTS "?ENTRY? ?..?"
-# define LDEXT_MAXARGS 0
-#else
-# define LDEXT_OPTS "?ENTRY?     "
-# define LDEXT_MAXARGS 3
-#endif
-COLLECT_HELP_TEXT[
-  ".load FILE "LDEXT_OPTS"  Load an extension library",
-#if SHELL_DYNAMIC_EXTENSION
-  "   If option -shext follows the first 1 or 2 arguments, then the library",
-  "   will be loaded as a shell extension, and any subsequent arguments will",
-  "   be passed to the extension's init function. That function is named per",
-  "   the docs for sqlite3_load_extension(), with ENTRY taking zProc's role.",
-#else
-  "   If ENTRY is provided, the entry point \"sqlite_ENTRY_init\" is called.",
-  "   Otherwise, the entry point name is derived from the FILE's name.",
-#endif
-];
-DISPATCHABLE_COMMAND( load ? 2 LDEXT_MAXARGS ){
-  const char *zFile = 0, *zProc = 0;
-  char *zErrMsg = 0;
-  int ai = 1, rc;
-#if SHELL_DYNAMIC_EXTENSION
-  char **pzShext = 0;
-#else
-  if( nArg>3 ) return DCR_TooMany|3;
-#endif
-  if( ISS(p)->bSafeMode ) return DCR_AbortError;
-  while( ai<nArg ){
-    const char *zA = azArg[ai++];
-#if SHELL_DYNAMIC_EXTENSION
-    if( optionMatch(zA, "shext") ){
-      if( zFile==0 ) return DCR_Missing;
-      pzShext = azArg + ai;
-      break;
-    }else if( zFile==0 ) zFile = zA;
-    else if( zProc==0 ) zProc = zA;
-#else
-    if( zFile==0 ) zFile = zA;
-    else if( zProc==0 ) zProc = zA;
-    else return DCR_TooMany|ai;
-#endif
-  }
-  open_db(p, 0);
-#if SHELL_DYNAMIC_EXTENSION
-  if( pzShext ){
-    rc = load_shell_extension(p, zFile, zProc, pzErr, nArg-ai, pzShext);
-  }else
-#endif
-    {
-      rc = sqlite3_load_extension(DBX(p), zFile, zProc, pzErr);
-    }
-  return DCR_Ok|(rc!=SQLITE_OK);
-}
-
 /*****************
  * The .mode command
  */
@@ -12222,13 +12188,10 @@ DISPATCHABLE_COMMAND( sha3sum 4 1 1 ){
 }
 
 /*****************
- * The .selftest*, .shell, .show, .shxopts, .stats and .system commands
+ * The .selftest*, .shell, and .show commands
  */
 CONDITION_COMMAND( selftest_bool defined(SQLITE_DEBUG) );
 CONDITION_COMMAND( selftest_int defined(SQLITE_DEBUG) );
-CONDITION_COMMAND( shell !defined(SQLITE_NOHAVE_SYSTEM) );
-CONDITION_COMMAND( shxopts (SHELL_EXTENSIONS)!=0 );
-CONDITION_COMMAND( system !defined(SQLITE_NOHAVE_SYSTEM) );
 COLLECT_HELP_TEXT[
   ",selftest ?OPTIONS?      Run tests defined in the SELFTEST table",
   "    Options:",
@@ -12236,16 +12199,7 @@ COLLECT_HELP_TEXT[
   "       -v                   Verbose output",
   ",selftest_bool ?ARGS?    Show boolean values of ARGS as flag tokens",
   ",selftest_int ?ARGS?     Show integer values of ARGS as integer tokens",
-  ".shell CMD ARGS...       Run CMD ARGS... in a system shell",
   ".show                    Show the current values for various settings",
-  ".shxopts ?SIGNED_OPTS?   Show or alter shell extension options",
-  "   Run without arguments to see their self-descriptive names",
-  ".stats ?ARG?             Show stats or turn stats on or off",
-  "   off                      Turn off automatic stat display",
-  "   on                       Turn on automatic stat display",
-  "   stmt                     Show statement stats",
-  "   vmstep                   Show the virtual machine step count only",
-  ".system CMD ARGS...      Run CMD ARGS... in a system shell",
 ];
 
 DISPATCHABLE_COMMAND( selftest_bool 10 0 0 ){
@@ -12372,22 +12326,82 @@ DISPATCHABLE_COMMAND( selftest 4 0 0 ){
   return rc > 0;
 }
 
-DISPATCHABLE_COMMAND( shell ? 2 0 ){
+/*****************
+ * The .shell, .stats and .system commands
+ */
+CONDITION_COMMAND( shell !defined(SQLITE_NOHAVE_SYSTEM) );
+CONDITION_COMMAND( system !defined(SQLITE_NOHAVE_SYSTEM) );
+COLLECT_HELP_TEXT[
+  ".shell CMD ARGS...       Run CMD ARGS... in a system shell",
+  ".stats ?ARG?             Show stats or turn stats on or off",
+  "   off                      Turn off automatic stat display",
+  "   on                       Turn on automatic stat display",
+  "   stmt                     Show statement stats",
+  "   vmstep                   Show the virtual machine step count only",
+  ".system CMD ARGS...      Run CMD ARGS... in a system shell",
+];
+
+#ifndef SQLITE_NOHAVE_SYSTEM
+static DotCmdRC shellOut(char *azArg[], int nArg,
+                         ShellExState *psx, char **pzErr){
   char *zCmd;
   int i, x;
-  if( ISS(p)->bSafeMode ) return DCR_AbortError;
+  if( ISS(psx)->bSafeMode ) return DCR_AbortError;
   zCmd = smprintf(strchr(azArg[1],' ')==0?"%s":"\"%s\"", azArg[1]);
-  shell_check_oom(zCmd);
   for(i=2; i<nArg; i++){
     zCmd = smprintf(strchr(azArg[i],' ')==0?"%z %s":"%z \"%s\"",
                     zCmd, azArg[i]);
-    shell_check_oom(zCmd);
   }
+  shell_check_oom(zCmd);
   x = system(zCmd);
   sqlite3_free(zCmd);
   if( x ) raw_printf(STD_ERR, "%s command returns %d\n", azArg[0], x);
   return DCR_Ok;
 }
+#endif
+DISPATCHABLE_COMMAND( shell ? 2 0 ){
+  return shellOut(azArg, nArg, p, pzErr);
+}
+
+DISPATCHABLE_COMMAND( system ? 2 0 ){
+  return shellOut(azArg, nArg, p, pzErr);
+}
+
+/*****************
+ * The .shxload and .shxopts commands
+ */
+CONDITION_COMMAND( shxload (SHELL_DYNAMIC_EXTENSION)!=0 );
+CONDITION_COMMAND( shxopts (SHELL_EXTENSIONS)!=0 );
+COLLECT_HELP_TEXT[
+  ".shxload FILE ?OPTIONS?  Load a CLI shell extension library",
+  "   The first option may name the init function to be called upon load.",
+  "   Otherwise, its name is derived from FILE. Either way, the entry point"
+  "   \"sqlite_NAME_init\" is called. All options after \"--\" are passed to",
+  "   the extension's init function in the ShellExtensionLink struct.",
+  ".shxopts ?SIGNED_OPTS?   Show or alter shell extension options",
+  "   Run without arguments to see their self-descriptive names",
+];
+
+DISPATCHABLE_COMMAND( shxload 4 2 0 ){
+  const char *zFile = 0, *zProc = 0;
+  int ai = 1, rc;
+  char **pzExtArgs = 0;
+  if( ISS(p)->bSafeMode ) return DCR_AbortError;
+  while( ai<nArg ){
+    const char *zA = azArg[ai++];
+    if( strcmp(zA, "--")==0 ){
+      pzExtArgs = azArg + ai;
+      break;
+    }
+    if( zFile==0 ) zFile = zA;
+    else if( zProc==0 ) zProc = zA;
+  }
+  if( zFile==0 ) return DCR_Missing;
+  if( pzExtArgs==0 ) pzExtArgs = azArg + ai;
+  rc = load_shell_extension(p, zFile, zProc, pzErr, nArg-ai, pzExtArgs);
+  return DCR_Ok|(rc!=SQLITE_OK);
+}
+
 DISPATCHABLE_COMMAND( shxopts 3 0 0 ){
   static struct { const char *name; u8 mask; } shopts[] = {
 #if SHELL_DYNAMIC_COMMANDS
@@ -12442,9 +12456,6 @@ DISPATCHABLE_COMMAND( shxopts 3 0 0 ){
   raw_printf(STD_ERR, "Error: %s %s\n", zAbout, zMoan);
   return DCR_CmdErred;
 }
-DISPATCHABLE_COMMAND( system ? 2 0 ){
-  return shellCommand(azArg, nArg, p, pzErr);
-}
 DISPATCHABLE_COMMAND( show ? 1 1 ){
   static const char *azBool[] = { "off", "on", "trigger", "full"};
   const char *zOut;
@@ -14015,8 +14026,8 @@ static int showHelp(FILE *out, const char *zPattern, ShellExState *psx){
   if( hoKind==HO_Undoc ){
     int ixct = 0;
     utf8_printf(out, "%s\n%s\n",
-                "The following commands are used for internal SQLite testing.",
-                "They are undocumented and subject to change without notice.");
+      "The following commands are for SQLite diagnosis and internal testing.",
+      "They are undocumented and subject to change without notice.");
     /* Bypass command lookup/resolution. This is just for internal commands. */
     while( ixct<numCommands ){
       struct CommandInfo *pci = &command_table[ixct];
index d9047215208ea2907578f894db9c1c603568e20d..348971b0d52d700972a65711289d4f918f1c39cc 100644 (file)
@@ -42,12 +42,15 @@ proc catch_mdb_cmd {args} {
 #----------------------------------------------------------------------------
 # Test cases shell10-1.*: loading/running the {C,C++}-written test extensions
 set cmds ".
- .load $blddir/test_shellext_cpp -shext C++
+ .shxload $blddir/test_shellext_cpp -- C++
+ .tables
+ .quit
 "
 do_test shell10-1.1 {
   catch_mdb_cmd $cmds
 } {0 {BatBeing lives.
 Load arguments: C++
+dbUser appeared
 dbUser closing
 dbShell closing
 BatBeing incommunicado.
@@ -55,10 +58,11 @@ BatBeing unbecoming.
 BatBeing RIP.}}
 
 set cmds ".
- .load $blddir/test_shellext_c -shext C
+ .shxload $blddir/test_shellext_c -- C
  .bat 10 20 30
- .load $blddir/test_shellext_cpp -shext C++
+ .shxload $blddir/test_shellext_cpp -- C++
  .bat 10 20 30
+ .tables
 "
 do_test shell10-1.2 {
   catch_mdb_cmd $cmds
@@ -69,6 +73,8 @@ BatBeing lives.
 Load arguments: C++
 Column widths: 20 30 10
 This execute has been called 2 times.
+dbUser appeared
+dbUser appeared
 dbUser closing
 dbUser closing
 dbShell closing
@@ -83,7 +89,7 @@ BatBeing RIP.}}
 #----------------------------------------------------------------------------
 # Test cases shell10-2.*: Tcl extension load and execution environment switching
 
-set ldtce ".load $blddir/tclshext -shext"
+set ldtce ".shxload $blddir/tclshext"
 
 set cmds {
  ..