]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Enhance the command-line shell to accept bound parameters, using the
authordrh <drh@noemail.net>
Mon, 25 Feb 2019 18:43:54 +0000 (18:43 +0000)
committerdrh <drh@noemail.net>
Mon, 25 Feb 2019 18:43:54 +0000 (18:43 +0000)
TEMP table named "$Parameters" to look up the values for bound parameters.

FossilOrigin-Name: 7c941ce5bcc872ec92cbe0e409fd773f44a5ab1f814e689ad57f756b911e2b96

manifest
manifest.uuid
src/shell.c.in

index a725656c76879cd38465d17676ed3aef32dd5f27..bc7ae72323e214a76e2fdf341ba62276136a5b15 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Update\scomments\son\sthe\sfossildelta\sextension.\s\sNo\schanges\sto\scode.
-D 2019-02-25T14:52:43.832
+C Enhance\sthe\scommand-line\sshell\sto\saccept\sbound\sparameters,\susing\sthe\nTEMP\stable\snamed\s"$Parameters"\sto\slook\sup\sthe\svalues\sfor\sbound\sparameters.
+D 2019-02-25T18:43:54.244
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F Makefile.in 178d8eb6840771149cee40b322d1b3be30d330198c522c903c1b66fb5a1bfca4
@@ -516,7 +516,7 @@ F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384
 F src/resolve.c 09419ad5c432190b69be7c0c326e03abb548a97c2c50675b81b459e1b382d1d2
 F src/rowset.c d977b011993aaea002cab3e0bb2ce50cf346000dff94e944d547b989f4b1fe93
 F src/select.c c998f694759e37799929e28df8a2649747f8774d4fc233529ab6bda689388e15
-F src/shell.c.in f2c1adbee3f6f36686b4a38d2168ebfc25298b4ad1e6d95199fc4e95b539251d
+F src/shell.c.in a238f3f80f7085d31056c69930ec13a87872da0d0d08fd561f5aff78cc618f5d
 F src/sqlite.h.in 8859e0b45b48d4186fbc466885e508f8272420a349099acdebcdb8d410d54824
 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
 F src/sqlite3ext.h 960f1b86c3610fa23cb6a267572a97dcf286e77aa0dd3b9b23292ffaa1ea8683
@@ -1805,7 +1805,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 8474c1560e0c3a28c6a7ed360202a8e7caae3c8259f60bbfa6d2948ab7876f51
-R b6b94692df1ff68d1775b0307c4b76d3
+P 9da4fb59b28686630d63a79988b458726332cf06cc0e6e84d7c0a7600f5fcab0
+R 6ea2c77700991e615d8d2faccc53ab72
 U drh
-Z 398771f938c8db2543123478ba7fdec9
+Z 82b4b57ac959f29e2a6d5db5cac484ef
index 3326c630fad6bf97df571bf8e9d53f1e74308483..40b6b070f63a9f8074df0622216d8ac327b6e201 100644 (file)
@@ -1 +1 @@
-9da4fb59b28686630d63a79988b458726332cf06cc0e6e84d7c0a7600f5fcab0
\ No newline at end of file
+7c941ce5bcc872ec92cbe0e409fd773f44a5ab1f814e689ad57f756b911e2b96
\ No newline at end of file
index c7d94dbee810d3644aaf220f7e773ed891c9291c..3474c10ca8adffceca34fa8f555216567ceb04aa 100644 (file)
@@ -2747,6 +2747,55 @@ static void restore_debug_trace_modes(void){
 #endif
 }
 
+/* Name of the TEMP table that holds bind parameter values */
+#define BIND_PARAM_TABLE "$Parameters"
+
+/*
+** Bind parameters on a prepared statement.
+**
+** Parameter bindings are taken from a TEMP table of the form:
+**
+**    CREATE TEMP TABLE "$Parameters"(key TEXT PRIMARY KEY, value)
+**    WITHOUT ROWID;
+**
+** No bindings occur if this table does not exist.  The special character '$'
+** is included in the table name to help prevent collisions with actual tables.
+** The table must be in the TEMP schema.
+*/
+static void bind_prepared_stmt(ShellState *pArg, sqlite3_stmt *pStmt){
+  int nVar;
+  int i;
+  int rc;
+  sqlite3_stmt *pQ = 0;
+
+  nVar = sqlite3_bind_parameter_count(pStmt);
+  if( nVar==0 ) return;  /* Nothing to do */
+  if( sqlite3_table_column_metadata(pArg->db, "TEMP", BIND_PARAM_TABLE,
+                                    "key", 0, 0, 0, 0, 0)!=SQLITE_OK ){
+    return; /* Parameter table does not exist */
+  }
+  rc = sqlite3_prepare_v2(pArg->db,
+          "SELECT value FROM temp.\"" BIND_PARAM_TABLE "\""
+          " WHERE key=?1", -1, &pQ, 0);
+  if( rc || pQ==0 ) return;
+  for(i=1; i<=nVar; i++){
+    char zNum[30];
+    const char *zVar = sqlite3_bind_parameter_name(pStmt, i);
+    if( zVar==0 ){
+      sqlite3_snprintf(sizeof(zNum),zNum,"?%d",i);
+      zVar = zNum;
+    }
+    sqlite3_bind_text(pQ, 1, zVar, -1, SQLITE_STATIC);
+    if( sqlite3_step(pQ)==SQLITE_ROW ){
+      sqlite3_bind_value(pStmt, i, sqlite3_column_value(pQ, 0));
+    }else{
+      sqlite3_bind_null(pStmt, i);
+    }
+    sqlite3_reset(pQ);
+  }
+  sqlite3_finalize(pQ);
+}
+
 /*
 ** Run a prepared statement
 */
@@ -3066,6 +3115,7 @@ static int shell_exec(
         }
       }
 
+      bind_prepared_stmt(pArg, pStmt);
       exec_prepared_stmt(pArg, pStmt);
       explain_data_delete(pArg);
       eqp_render(pArg);