** parameters for SQLite. The key/value store is a singleton - there
** is exactly one per process. The store can be accessed and controlled
** from SQLite using an eponymous virtual table.
+**
+** This is used to do parameter binding in the command-line shell.
+**
+** The ".set key=value" command and the "-Dkey=value" command-line option
+** invoke shell_bindings_new_text() on the argument ("key=value") in order
+** to create entries in the store. The CLI then invokes
+** shell_bindings_apply() on each prepared statement just prior to
+** running it.
+**
+** All bindings are accessible through an eponymous-only virtual table
+** named shell_bindings. Ex:
+**
+** INSERT INTO shell_bindings(k,v) VALUES('p1',12345);
+** SELECT $p1, typeof($p1);
+**
+** The above results in an answer of 12345,'integer'. Bindings generated
+** using the virtual table can have any type other than NULL. But bindings
+** generated by the .set command and the -D command-line option are always
+** text.
+**
+** The CLI is single-threaded, so there is no attempt to make this code
+** threadsafe.
+**
+** The key/value store is kept in a global list, and uses malloc/free rather
+** than sqlite3_malloc64/sqlite3_free so that it can be completely independent
+** of SQLite, can exist both before sqlite3_initialize() and after
+** sqlite3_shutdown(), and so that it will persist across multiple
+** connections created using ".open".
+**
+** The number of parameters is expected to be small, so they are stored
+** on a simple linked list. If this proves to be too inefficient, some other
+** algorithm can be substituted in the future without changing the interface.
*/
#if !defined(SQLITEINT_H)
#include "sqlite3ext.h"
-C Add\sthe\sability\sto\suse\sbind\sparameters\sin\sthe\sCLI.\s\sThe\snew\s".set\sKEY=VALUE"\ndot-command\sworks\sto\sset\sbindings.\s\sOr\suse\sthe\s"-Dkey=value"\scommand-line\noption.\s\sOr\suse\sthe\sbuilt-in\sshell_bindings(k,v)\svirtual\stable\sto\sset,\ndelete,\sor\schanging\sbindings.
-D 2018-04-27T17:39:22.740
+C Better\scomments\son\sthe\sbindvtab.c\simplementation.\s\sAll\sthe\stwo-argument\nversion\sof\sthe\s.set\scommand.\s\sAll\sbindings\sfrom\s.set\sand\s-D\sare\sstill\nstring.
+D 2018-04-27T20:49:13.739
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F Makefile.in da02d4d3544992af522b4ece652debef3255a5d45377ebb1b5ab8a9a5cd16859
F ext/misc/amatch.c 6db4607cb17c54b853a2d7c7c36046d004853f65b9b733e6f019d543d5dfae87
F ext/misc/anycollseq.c 5ffdfde9829eeac52219136ad6aa7cd9a4edb3b15f4f2532de52f4a22525eddb
F ext/misc/appendvfs.c 3777f22ec1057dc4e5fd89f2fbddcc7a29fbeef1ad038c736c54411bb1967af7
-F ext/misc/bindvtab.c e21871461a0bb4646da111a7f32f709946f76a4013d523dc183192f0879c0cb3
+F ext/misc/bindvtab.c 70ca40ff9bec3cc6da53e09bf13e0af858dc210e68e41b7915d4ff71c363819c
F ext/misc/btreeinfo.c 78c8c57d325185ccc04b7679e5b020e34a4d9c87453e6b7ac943d0a26cee3256
F ext/misc/carray.c ed96c218ea940b85c9a274c4d9c59fe9491c299147a38a8bba537687bd6c6005
F ext/misc/closure.c 0d2a038df8fbae7f19de42e7c7d71f2e4dc88704
F src/resolve.c 6415381a0e9d22c0e7cba33ca4a53f81474190862f5d4838190f5eb5b0b47bc9
F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac
F src/select.c daf07d8defce3311f9e69f1280a874d78bc1d16c305f6aa689640f7afa02842f
-F src/shell.c.in 3bac9ab3c0ec1b8641b9ed25c0e2cf242b8bb186202d577b56fb16408dcacf24
+F src/shell.c.in d751c9e8aa9c73a700d4033d2bfcfccad90c476b1fcb0d406e3f6b140e0f02c0
F src/sqlite.h.in 8e70752a57597c08f64f3d49fc1fc46926b862d2e23b038b0d23b9cc748d88ea
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h 83a3c4ce93d650bedfd1aa558cb85a516bd6d094445ee989740827d0d944368d
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 05f6278a02e5cde89f76ced5af7d508e26576d7291dad7ee9e06b1a3be516cb0
-R 2fe85036f0f3b01feae669c6ee5a9387
-T *branch * shell-bindings
-T *sym-shell-bindings *
-T -sym-trunk *
+P 1f2944d1d64d36b729450685974c260295cf1e32c204b71e27d20ebc4d65f9e8
+R 8b8e4c122ecc932439216f69c14e3e66
U drh
-Z 275e393030ab15b790049a2a3b9245cb
+Z 42c91d81ee6385ae52b3a143c0c973f3
-1f2944d1d64d36b729450685974c260295cf1e32c204b71e27d20ebc4d65f9e8
\ No newline at end of file
+7b2a65a65475b80669af4ff5ac7adb6b310cd8275a36e672a3f5c88a259693c0
\ No newline at end of file
if( c=='s' && n==3 && strncmp(azArg[0],"set",3)==0 ){
int x;
- if( nArg<2 ){
- raw_printf(stderr, "Usage: .set KEY=VALUE\n");
+ char *zKey = 0;
+ char *zToFree = 0;
+ if( nArg==2 ){
+ zKey = azArg[1];
+ }else if( nArg==3 ){
+ zKey = zToFree = sqlite3_mprintf("%s=%s",azArg[1],azArg[2]);
+ }else{
+ raw_printf(stderr,
+ "Usage: .set KEY VALUE\n Or: .set KEY=VALUE\n"
+ "Use SQL on the \"shell_bindings\" table to query or delete keys.\n"
+ );
rc = 1;
goto meta_command_exit;
}
- x = shell_bindings_new_text(azArg[1]);
+ x = shell_bindings_new_text(zKey);
if( x ){
- utf8_printf(stderr, "Error: bad setting: %s\n", azArg[1]);
+ utf8_printf(stderr, "Error: bad setting: %s\n", zKey);
}
+ sqlite3_free(zToFree);
}else