]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Initial implementation of the sqlite3_value_frombind() interface.
authordrh <drh@noemail.net>
Fri, 29 Mar 2019 11:13:37 +0000 (11:13 +0000)
committerdrh <drh@noemail.net>
Fri, 29 Mar 2019 11:13:37 +0000 (11:13 +0000)
FossilOrigin-Name: 98da62dfdacc6b3c490c387d1f8a74cc5daa978776967e264ad4800c380b0ddf

manifest
manifest.uuid
src/sqlite.h.in
src/test_func.c
src/vdbe.c
src/vdbeInt.h
src/vdbeapi.c
test/func.test

index 75f76fcf0143ea7695d187ac3a70e433bae83b13..ed7795770c6c2a1fbc10c58e53b7fefb12b2f50a 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Recover\sa\ssome\sof\sthe\sperformance\slost\sby\swindow\sfunction\salias\sfix\stwo\ncheck-ins\sback.
-D 2019-03-29T01:15:11.116
+C Initial\simplementation\sof\sthe\ssqlite3_value_frombind()\sinterface.
+D 2019-03-29T11:13:37.087
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -518,7 +518,7 @@ F src/resolve.c 567888ee3faec14dae06519b4306201771058364a37560186a3e0e755ebc4cb8
 F src/rowset.c d977b011993aaea002cab3e0bb2ce50cf346000dff94e944d547b989f4b1fe93
 F src/select.c 9263f5c30dd44c7ac2eb29f40a7ec64322a96885b71c00de6bc30b756c2e1c49
 F src/shell.c.in c1986496062f9dba4ed5b70db06b5e0f32e1954cdcfab0b30372c6c186796810
-F src/sqlite.h.in f765fce74038607388d3a96cd7fad892f363bdcde24911565edf610ecf69534c
+F src/sqlite.h.in e8a8dd45ae6849b3e40b243eca41181a740b4f4ac67d5b65fcea519d454db785
 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
 F src/sqlite3ext.h 960f1b86c3610fa23cb6a267572a97dcf286e77aa0dd3b9b23292ffaa1ea8683
 F src/sqliteInt.h 59b625f88bf96cad4cd1a6a6ded615c161f518fb56da3e49f2ff70429e49095f
@@ -546,7 +546,7 @@ F src/test_delete.c e2fe07646dff6300b48d49b2fee2fe192ed389e834dd635e3b3bac0ce0bf
 F src/test_demovfs.c a0c3bdd45ed044115c2c9f7779e56eafff18741e
 F src/test_devsym.c 1960abbb234b97e9b920f07e99503fc04b443f62bbc3c6ff2c2cea2133e3b8a2
 F src/test_fs.c c10706d63e64f1b1d0274e42c5443886c15ee9d6157b3bd330786aeb4057b151
-F src/test_func.c d12d805953bcb3bb19f71d29cdc93383b7b7a3369504d2b7e398a1bd77376294
+F src/test_func.c 181f992e5495644434c4f0e3cc72362a78c295eb2cf3ff4d02498b8bde7aa276
 F src/test_hexio.c 1d4469ca61ab202a1fcec6543f584d2407205e8d
 F src/test_init.c 4413c211a94b62157ca4c145b3f27c497f03c664
 F src/test_intarray.c 39b4181662a0f33a427748d87218e7578d913e683dc27eab7098bb41617cac71
@@ -587,10 +587,10 @@ F src/upsert.c 0dd81b40206841814d46942a7337786932475f085716042d0cb2fc7791bf8ca4
 F src/utf.c 810fbfebe12359f10bc2a011520a6e10879ab2a163bcb26c74768eab82ea62a5
 F src/util.c 82a2e3f691a3b654be872e305dab1f455e565dedf5e6a90c818c1ab307c00432
 F src/vacuum.c 532553ee1d47f69c1198858107b1f3af3d16af25f2ab4ce3b1263d9e333f26e2
-F src/vdbe.c 8f824b423460fbbd6a140f557b9d3cb26fa55404d03aee43584d11c7d1011b02
+F src/vdbe.c bc3632f4ed1b86c764415c0afea562ca8d8ef4a27432a30519b549613c5e4071
 F src/vdbe.h 712bca562eaed1c25506b9faf9680bdc75fc42e2f4a1cd518d883fa79c7a4237
-F src/vdbeInt.h a76d5eed62c76bcd8de7afd3147fac1bc40c5a870582664bcd7d071ef437c37f
-F src/vdbeapi.c 7a052df80d7e2e55382076174633e888f21fe200feb5d49b1b441b4c38ab851a
+F src/vdbeInt.h 5ea6f6548a14b20a9210ca055a989478a37d16f84740cc123834f13e4527bce7
+F src/vdbeapi.c a6e462bd7853e272cf614d6fbda7f3f20c89a2d255805855b32895a5983ddcec
 F src/vdbeaux.c 7aa412e7e56eb53649d87766f3064994a31991ee2b2716bf8c3129fa15cc7653
 F src/vdbeblob.c f5c70f973ea3a9e915d1693278a5f890dc78594300cf4d54e64f2b0917c94191
 F src/vdbemem.c 3e89e087df928eba80e520824078dc563c579a0848b1557ac36845ec14392923
@@ -973,7 +973,7 @@ F test/fts4opt.test 0fd0cc84000743ff2a883b9b84b4a5be07249f0ba790c8848a757164cdd4
 F test/fts4umlaut.test fcaca4471de7e78c9d1f7e8976e3e8704d7d8ad979d57a739d00f3f757380429
 F test/fts4unicode.test ceca76422abc251818cb25dabe33d3c3970da5f7c90e1540f190824e6b3a7c95
 F test/full.test 6b3c8fb43c6beab6b95438c1675374b95fab245d
-F test/func.test 09dda479bcfc568f99f3070413e9672a8eeedc1be9c5d819bf55d4788c2583b7
+F test/func.test 150270b6e2e0281697c116e5ca0e46b41ace8d34b1c92461d88fdd9968c9b03c
 F test/func2.test 772d66227e4e6684b86053302e2d74a2500e1e0f
 F test/func3.test d202a7606d23f90988a664e88e268aed1087c11c
 F test/func4.test 6beacdfcb0e18c358e6c2dcacf1b65d1fa80955f
@@ -1813,7 +1813,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P f908cd40b275a5753d5167ebb25871300381687adcb3a7fcb1f14b57a20ee3d0
-R d09d343d4a65e6083144623bc2793fd6
+P 965cbcea117835d2c6d2ec58c8025b227f491c35805e282cb31228436bc6bec1
+R a5f91d5ae4a62cededad3857c6b176e7
+T *branch * value_frombind
+T *sym-value_frombind *
+T -sym-trunk *
 U drh
-Z 9d5464d6e79c7b4f0d1819c4eb226890
+Z 4dc0402dbd3994ae8b5cae8ff0562029
index 6c92ef79c83cdb1354e0e74450a63b3f3ab885a0..ab7c63b4d62b8d988561e3c8fe0113af791cd43b 100644 (file)
@@ -1 +1 @@
-965cbcea117835d2c6d2ec58c8025b227f491c35805e282cb31228436bc6bec1
\ No newline at end of file
+98da62dfdacc6b3c490c387d1f8a74cc5daa978776967e264ad4800c380b0ddf
\ No newline at end of file
index d6b9d38ccd504357b5986eba1038015412069382..fb9bda8896bd2667354970c8afa7a026341b420c 100644 (file)
@@ -4979,6 +4979,8 @@ SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),
 ** <tr><td><b>sqlite3_value_nochange&nbsp;&nbsp;</b>
 ** <td>&rarr;&nbsp;&nbsp;<td>True if the column is unchanged in an UPDATE
 ** against a virtual table.
+** <tr><td><b>sqlite3_value_frombind&nbsp;&nbsp;</b>
+** <td>&rarr;&nbsp;&nbsp;<td>True if value originated a bound parameter
 ** </table></blockquote>
 **
 ** <b>Details:</b>
@@ -5040,6 +5042,11 @@ SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),
 ** than within an [xUpdate] method call for an UPDATE statement, then
 ** the return value is arbitrary and meaningless.
 **
+** ^The sqlite3_value_frombind(X) interface returns non-zero if the
+** value X originated from one of the [sqlite3_bind_int|sqlite3_bind()]
+** interfaces.  ^If X comes from an SQL literal value, or a table column,
+** and expression, then sqlite3_value_frombind(X) returns zero.
+**
 ** Please pay particular attention to the fact that the pointer returned
 ** from [sqlite3_value_blob()], [sqlite3_value_text()], or
 ** [sqlite3_value_text16()] can be invalidated by a subsequent call to
@@ -5085,6 +5092,7 @@ int sqlite3_value_bytes16(sqlite3_value*);
 int sqlite3_value_type(sqlite3_value*);
 int sqlite3_value_numeric_type(sqlite3_value*);
 int sqlite3_value_nochange(sqlite3_value*);
+int sqlite3_value_frombind(sqlite3_value*);
 
 /*
 ** CAPI3REF: Finding The Subtype Of SQL Values
index 2a7103f88ef2ca50390220ad2fd9e0f18b7bf3b5..b7c9e08ceb38091b2b8a93b50c6ef727fd8fd851 100644 (file)
@@ -630,6 +630,24 @@ static void test_getsubtype(
   sqlite3_result_int(context, (int)sqlite3_value_subtype(argv[0]));
 }
 
+/*         test_frombind(A,B,C,...)
+**
+** Return an integer bitmask that has a bit set for every argument
+** (up to the first 63 arguments) that originates from a bind a parameter.
+*/
+static void test_frombind(
+  sqlite3_context *context,
+  int argc,
+  sqlite3_value **argv
+){
+  sqlite3_uint64 m = 0;
+  int i;
+  for(i=0; i<argc && i<63; i++){
+    if( sqlite3_value_frombind(argv[i]) ) m |= ((sqlite3_uint64)1)<<i;
+  }
+  sqlite3_result_int64(context, (sqlite3_int64)m);
+}
+
 /*         test_setsubtype(V, T)
 **
 ** Return the value V with its subtype changed to T
@@ -675,6 +693,7 @@ static int registerTestFunctions(
     { "test_zeroblob",  1, SQLITE_UTF8|SQLITE_DETERMINISTIC, test_zeroblob},
     { "test_getsubtype",       1, SQLITE_UTF8, test_getsubtype},
     { "test_setsubtype",       2, SQLITE_UTF8, test_setsubtype},
+    { "test_frombind",        -1, SQLITE_UTF8, test_frombind},
   };
   int i;
 
index 50ec9edd14a7a3c9584ba9f48e86a3cae9aa30bf..ed5434be2b9f08f07d8b52f079690010a0696010 100644 (file)
@@ -1237,6 +1237,7 @@ case OP_Variable: {            /* out2 */
   }
   pOut = &aMem[pOp->p2];
   sqlite3VdbeMemShallowCopy(pOut, pVar, MEM_Static);
+  pOut->flags |= MEM_FromBind;
   UPDATE_MAX_BLOBSIZE(pOut);
   break;
 }
index acc7f5a6a0bf78af3bf41b963f3f2d1227c9470c..875d2cf7f053bc4d38011b599986dc344540a67e 100644 (file)
@@ -246,7 +246,7 @@ struct sqlite3_value {
 #define MEM_Real      0x0008   /* Value is a real number */
 #define MEM_Blob      0x0010   /* Value is a BLOB */
 #define MEM_AffMask   0x001f   /* Mask of affinity bits */
-/* Available          0x0020   */
+#define MEM_FromBind  0x0020   /* Value originates from sqlite3_bind() */
 /* Available          0x0040   */
 #define MEM_Undefined 0x0080   /* Value is undefined */
 #define MEM_Cleared   0x0100   /* NULL set by OP_Null, not from data */
index 82138258a9e35461c083fb6ed294e600c36d1ef6..c3cf4cd221749cde0e1601fa093bd5c41d01b864 100644 (file)
@@ -275,6 +275,11 @@ int sqlite3_value_nochange(sqlite3_value *pVal){
   return (pVal->flags&(MEM_Null|MEM_Zero))==(MEM_Null|MEM_Zero);
 }
 
+/* Return true if a parameter value originated from an sqlite3_bind() */
+int sqlite3_value_frombind(sqlite3_value *pVal){
+  return (pVal->flags&MEM_FromBind)!=0;
+}
+
 /* Make a copy of an sqlite3_value object
 */
 sqlite3_value *sqlite3_value_dup(const sqlite3_value *pOrig){
index 23a3ae4392fe5721c0c7ae5ccd97b56c7502b46b..ab719388af8617d8536eccc709a75c27a8948bce 100644 (file)
@@ -1391,4 +1391,32 @@ for {set i 65536} {$i<=0x10ffff} {incr i 139} {
 do_execsql_test func-31.1 { 
   SELECT char(), length(char()), typeof(char()) 
 } {{} 0 text}
+
+# sqlite3_value_frombind()
+#
+do_execsql_test func-32.100 {
+  SELECT test_frombind(1,2,3,4);
+} {0}
+do_execsql_test func-32.110 {
+  SELECT test_frombind(1,2,?,4);
+} {4}
+do_execsql_test func-32.120 {
+  SELECT test_frombind(1,(?),4,?+7);
+} {2}
+do_execsql_test func-32.130 {
+  DROP TABLE IF EXISTS t1;
+  CREATE TABLE t1(a,b,c,e,f);
+  INSERT INTO t1 VALUES(1,2.5,'xyz',x'e0c1b2a3',null);
+  SELECT test_frombind(a,b,c,e,f,$xyz) FROM t1;
+} {32}
+do_execsql_test func-32.140 {
+  SELECT test_frombind(a,b,c,e,f,$xyz+f) FROM t1;
+} {0}
+do_execsql_test func-32.150 {
+  SELECT test_frombind(x.a,y.b,x.c,:123,y.e,x.f,$xyz+y.f) FROM t1 x, t1 y;
+} {8}
+
+
+
+
 finish_test