]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add a new interface, sqlite3_context_db_handle(), that returns the database
authordrh <drh@noemail.net>
Wed, 19 Mar 2008 21:45:51 +0000 (21:45 +0000)
committerdrh <drh@noemail.net>
Wed, 19 Mar 2008 21:45:51 +0000 (21:45 +0000)
connection pointer for an application-defined function. (CVS 4889)

FossilOrigin-Name: 54c55cae556af5a16c0ce8be1a96d2932db80ad8

13 files changed:
manifest
manifest.uuid
sqlite3.def
src/alter.c
src/attach.c
src/date.c
src/func.c
src/loadext.c
src/sqlite.h.in
src/sqlite3ext.h
src/vdbe.c
src/vdbeapi.c
src/vdbemem.c

index faafb086e0c19f1300851c0933ce1cd469b061eb..b47325790dea303c0ddfb31dcea64b5b5cf2b2fe 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Undefine\sthe\s"isView"\smacro\swhen\scompiling\swith\sSQLITE_OMIT_VIEW\sso\sthat\nthe\smacro\sdoes\snot\sinterfer\swith\ssubsequent\smodules\sin\sthe\samalgamation.\s(CVS\s4888)
-D 2008-03-19T20:42:14
+C Add\sa\snew\sinterface,\ssqlite3_context_db_handle(),\sthat\sreturns\sthe\sdatabase\nconnection\spointer\sfor\san\sapplication-defined\sfunction.\s(CVS\s4889)
+D 2008-03-19T21:45:51
 F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
 F Makefile.in 31182aff7a39a0a0fc41e2e68562d20d57a8b16e
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -76,11 +76,11 @@ F publish_osx.sh 2ad2ee7d50632dff99949edc9c162dbb052f7534
 F spec.template b2f6c4e488cbc3b993a57deba22cbc36203c4da3
 F sqlite.pc.in 30552343140c53304c2a658c080fbe810cd09ca2
 F sqlite3.1 6be1ad09113570e1fc8dcaff84c9b0b337db5ffc
-F sqlite3.def a96c1d0d39362b763d2ddba220a32da41a15c4b4
+F sqlite3.def a1be7b9a4b8b51ac41c6ff6e8e44a14ef66b338b
 F sqlite3.pc.in abed4664817e1cd500f2276142c71958087c16bc
-F src/alter.c b494a50f239a760565ce6220ee316e96956ec054
+F src/alter.c b42d782906fc3b92c331efbe06e9389617b47ce7
 F src/analyze.c a78ac494668581fe7f54ee63700815bb0ea34261
-F src/attach.c e13d62597e8725075b27186817f7e745122af24e
+F src/attach.c e7cf4ae2a2c8ebd554dc6ca06859b587fa7197c2
 F src/auth.c c8b2ab5c8bad4bd90ed7c294694f48269162c627
 F src/bitvec.c fac68429a9916a50229c4ab88abb69c00c438f7f
 F src/btmutex.c 483ced3c52205b04b97df69161fadbf87f4f1ea2
@@ -92,19 +92,19 @@ F src/callback.c 77b302b0d41468dcda78c70e706e5b84577f0fa0
 F src/complete.c 4cf68fd75d60257524cbe74f87351b9848399131
 F src/config.h b60286b542f5284d529b659adcb9c9d25eecab20
 F src/config.h.in 343f19cacc74d4baf84a4af701b5bb44419642ff
-F src/date.c 4c026b335c529210aa17dc067b174655eda3559f
+F src/date.c 7b80383c47beafd9b49f2c1be65a72747593c4e1
 F src/delete.c 217cd5559e00bb135dc626d4ea4ac713604729e8
 F src/experimental.c 1b2d1a6cd62ecc39610e97670332ca073c50792b
 F src/expr.c 242f2f57a32f6909270e4a22ce1c810a150f5a17
 F src/fault.c 039abb45c9dbcbdf575ec2a23ae38db01bc2f7b2
-F src/func.c 00a4f0a75faaf5f85c90710d099be2fc3aaf7914
+F src/func.c ffce8131bbc2117168beb32afce7fb75bd2c055f
 F src/hash.c 53655c312280211444bfe23af6490a460aec2980
 F src/hash.h 031cd9f915aff27e12262cb9eb570ac1b8326b53
 F src/insert.c 358c80592c20a61a8d5b4a127215b5e25de652f4
 F src/journal.c 807bed7a158979ac8d63953e1774e8d85bff65e2
 F src/legacy.c cb1939fdeb91ea88fb44fbd2768a10e14bc44650
 F src/limits.h 71ab25f17e35e0a9f3f6f234b8ed49cc56731d35
-F src/loadext.c cf7de78e1ee6c29697207eea291454c93ea2b892
+F src/loadext.c 4acd067b2e67608b42abeff50e39b6042eaae9f8
 F src/main.c bb31f65f7b1870825a4c9a31f19354d566b7633c
 F src/malloc.c 60e392a4c12c839517f9b0db7b995f825444fb35
 F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217
@@ -139,8 +139,8 @@ F src/random.c 8b6ab5418cf0f4dde551730825d67da1457c2b3c
 F src/select.c d0a1e01a2a6c05bd60324e843c7e4581d3605950
 F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96
 F src/shell.c 22297fffa6f00a6c6d44020fa13b1184a1bb372d
-F src/sqlite.h.in 7f1438fb2bef8eb1fdd4f09b4e709a39d53e6963
-F src/sqlite3ext.h 7a0def838426a4062fb619d789ead172f025f02e
+F src/sqlite.h.in d8acd2881bdd1def5dfcc280ebc86a60f248ba0b
+F src/sqlite3ext.h faacd0e6a81aabee0861c6d7883c9172e74ef5b3
 F src/sqliteInt.h e7596d5491f65aafe00c0f63f41aedf2a8e007a3
 F src/sqliteLimit.h ee4430f88f69bf63527967bb35ca52af7b0ccb1e
 F src/table.c 2c48c575dd59b3a6c5c306bc55f51a9402cf429a
@@ -175,14 +175,14 @@ F src/update.c d2c59643af98f966c2a04d392463089b715ca18f
 F src/utf.c 32b00d6e19010025e58f2ecb2f921d5e126771b4
 F src/util.c dba9e04121eb17ec4643d6ca231ff859452cf0e2
 F src/vacuum.c 3f34f278809bf3eb0b62ec46ff779e9c385b28f0
-F src/vdbe.c aaf93d6de79d2a2481a232e9a3a6b182632233d7
+F src/vdbe.c 86033e43d89892ea6a817e8bcd4e6273bc1ebdf5
 F src/vdbe.h 58a7d931ffb704e034b2a725981cfa5bd406fad9
 F src/vdbeInt.h 76c81d057a39813de0fda3cad1498655d53ec69d
-F src/vdbeapi.c cf9fc963efae3cdf5de08e2a9718b487059c7fc5
+F src/vdbeapi.c 6e6f2bd51a74b74a72e31f6db409f55a98bc8ea2
 F src/vdbeaux.c 82f3c8913e68b4928de28c3fa117464356d59df6
 F src/vdbeblob.c 63c750acc7b5012479f508c0e9627372a82cb65d
 F src/vdbefifo.c a30c237b2a3577e1415fb6e288cbb6b8ed1e5736
-F src/vdbemem.c 2aff1e7cf3755c332819ef1e573d66a7fefd9c9a
+F src/vdbemem.c 5de8de022bb93674cd6d48dd919242b517c27c60
 F src/vtab.c 00cd16317b29495c185ff40e4b227917d5a371b2
 F src/where.c 78d6689d7154d8d41c1a913e17bce9a320981653
 F tclinstaller.tcl 4356d9d94d2b5ed5e68f9f0c80c4df3048dd7617
@@ -624,7 +624,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
 F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
-P 73fbac7cf7b61b23831f62b996fbdd358695b473
-R ac3de7ed8140669efe87d57c5c298664
+P a42caa8f83ce19af1e569c4545ea8b2449152430
+R b8b61f236a175c9fc88a201d83ba74e4
 U drh
-Z 9484b5fc96550c2dac020f0ae3861dc8
+Z 21fe871d94106aa8de33714f83ee397a
index 2f8380d0144f3d916907d3324cb1ec98608ce15e..cbc97ef43e1855cdf1f399ec2776e8a49a08a03e 100644 (file)
@@ -1 +1 @@
-a42caa8f83ce19af1e569c4545ea8b2449152430
\ No newline at end of file
+54c55cae556af5a16c0ce8be1a96d2932db80ad8
\ No newline at end of file
index 4947925e473074e9a5dbceca36a3e822a93b7c0a..8a826ca9d08bba134c93ef4222ac7c1c88b498ba 100644 (file)
@@ -1,6 +1,7 @@
 EXPORTS
 sqlite3_aggregate_context
 sqlite3_aggregate_count
+sqlite3_auto_extension
 sqlite3_bind_blob
 sqlite3_bind_double
 sqlite3_bind_int
@@ -11,9 +12,17 @@ sqlite3_bind_parameter_index
 sqlite3_bind_parameter_name
 sqlite3_bind_text
 sqlite3_bind_text16
+sqlite3_bind_value
+sqlite3_bind_zeroblob
+sqlite3_blob_bytes
+sqlite3_blob_close
+sqlite3_blob_open
+sqlite3_blob_read
+sqlite3_blob_write
 sqlite3_busy_handler
 sqlite3_busy_timeout
 sqlite3_changes
+sqlite3_clear_bindings
 sqlite3_close
 sqlite3_collation_needed
 sqlite3_collation_needed16
@@ -31,15 +40,20 @@ sqlite3_column_name16
 sqlite3_column_text
 sqlite3_column_text16
 sqlite3_column_type
+sqlite3_column_value
 sqlite3_commit_hook
 sqlite3_complete
 sqlite3_complete16
 sqlite3_create_collation
 sqlite3_create_collation16
+sqlite3_create_collation_v2
 sqlite3_create_function
 sqlite3_create_function16
+sqlite3_create_module
+sqlite3_create_module_v2
 sqlite3_data_count
 sqlite3_db_handle
+sqlite3_declare_vtab
 sqlite3_enable_load_extension
 sqlite3_enable_shared_cache
 sqlite3_errcode
@@ -47,6 +61,8 @@ sqlite3_errmsg
 sqlite3_errmsg16
 sqlite3_exec
 sqlite3_expired
+sqlite3_extended_result_codes
+sqlite3_file_control
 sqlite3_finalize
 sqlite3_free
 sqlite3_free_table
@@ -60,18 +76,37 @@ sqlite3_libversion
 sqlite3_libversion_number
 sqlite3_load_extension
 sqlite3_malloc
+sqlite3_memory_alarm
+sqlite3_memory_highwater
+sqlite3_memory_used
 sqlite3_mprintf
+sqlite3_mutex_alloc
+sqlite3_mutex_enter
+sqlite3_mutex_free
+sqlite3_mutex_leave
+sqlite3_mutex_try
 sqlite3_open
 sqlite3_open16
+sqlite3_open_v2
+sqlite3_overload_function
 sqlite3_prepare
 sqlite3_prepare16
+sqlite3_prepare16_v2
+sqlite3_prepare_v2
+sqlite3_profile
 sqlite3_progress_handler
+sqlite3_randomness
 sqlite3_realloc
+sqlite3_release_memory
 sqlite3_reset
+sqlite3_reset_auto_extension
 sqlite3_result_blob
 sqlite3_result_double
 sqlite3_result_error
 sqlite3_result_error16
+sqlite3_result_error_code
+sqlite3_result_error_nomem
+sqlite3_result_error_toobig
 sqlite3_result_int
 sqlite3_result_int64
 sqlite3_result_null
@@ -80,12 +115,18 @@ sqlite3_result_text16
 sqlite3_result_text16be
 sqlite3_result_text16le
 sqlite3_result_value
+sqlite3_result_zeroblob
 sqlite3_rollback_hook
 sqlite3_set_authorizer
 sqlite3_set_auxdata
+sqlite3_sleep
 sqlite3_snprintf
+sqlite3_soft_heap_limit
+sqlite3_sql
 sqlite3_step
+sqlite3_test_control
 sqlite3_thread_cleanup
+sqlite3_threadsafe
 sqlite3_total_changes
 sqlite3_trace
 sqlite3_transfer_bindings
@@ -97,9 +138,13 @@ sqlite3_value_bytes16
 sqlite3_value_double
 sqlite3_value_int
 sqlite3_value_int64
+sqlite3_value_numeric_type
 sqlite3_value_text
 sqlite3_value_text16
 sqlite3_value_text16be
 sqlite3_value_text16le
 sqlite3_value_type
+sqlite3_vfs_find
+sqlite3_vfs_register
+sqlite3_vfs_unregister
 sqlite3_vmprintf
index 1a43370d567f125206ea50c2851afe3c65553317..2acefe2b8237b9628bfdc5130a6a2042d0fe96b6 100644 (file)
@@ -12,7 +12,7 @@
 ** This file contains C code routines that used to generate VDBE code
 ** that implements the ALTER TABLE command.
 **
-** $Id: alter.c,v 1.42 2008/02/09 14:30:30 drh Exp $
+** $Id: alter.c,v 1.43 2008/03/19 21:45:51 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -51,7 +51,7 @@ static void renameTableFunc(
   int len = 0;
   char *zRet;
 
-  sqlite3 *db = sqlite3_user_data(context);
+  sqlite3 *db = sqlite3_context_db_handle(context);
 
   /* The principle used to locate the table name in the CREATE TABLE 
   ** statement is that the table name is the first token that is immediatedly
@@ -107,7 +107,7 @@ static void renameTriggerFunc(
   int len = 0;
   char *zRet;
 
-  sqlite3 *db = sqlite3_user_data(context);
+  sqlite3 *db = sqlite3_context_db_handle(context);
 
   /* The principle used to locate the table name in the CREATE TRIGGER 
   ** statement is that the table name is the first token that is immediatedly
@@ -178,7 +178,7 @@ void sqlite3AlterFunctions(sqlite3 *db){
 
   for(i=0; i<sizeof(aFuncs)/sizeof(aFuncs[0]); i++){
     sqlite3CreateFunc(db, aFuncs[i].zName, aFuncs[i].nArg,
-        SQLITE_UTF8, (void *)db, aFuncs[i].xFunc, 0, 0);
+        SQLITE_UTF8, 0, aFuncs[i].xFunc, 0, 0);
   }
 }
 
index 905b1b052d180343d22e3ffd583c37a4088ed04a..57ef9d36455d9e69a0d4aca568fcb4d25853b3e0 100644 (file)
@@ -11,7 +11,7 @@
 *************************************************************************
 ** This file contains code used to implement the ATTACH and DETACH commands.
 **
-** $Id: attach.c,v 1.72 2008/02/13 18:25:27 danielk1977 Exp $
+** $Id: attach.c,v 1.73 2008/03/19 21:45:51 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -69,7 +69,7 @@ static void attachFunc(
 ){
   int i;
   int rc = 0;
-  sqlite3 *db = sqlite3_user_data(context);
+  sqlite3 *db = sqlite3_context_db_handle(context);
   const char *zName;
   const char *zFile;
   Db *aNew;
@@ -239,7 +239,7 @@ static void detachFunc(
   sqlite3_value **argv
 ){
   const char *zName = (const char *)sqlite3_value_text(argv[0]);
-  sqlite3 *db = sqlite3_user_data(context);
+  sqlite3 *db = sqlite3_context_db_handle(context);
   int i;
   Db *pDb = 0;
   char zErr[128];
@@ -378,8 +378,8 @@ void sqlite3Attach(Parse *pParse, Expr *p, Expr *pDbname, Expr *pKey){
 void sqlite3AttachFunctions(sqlite3 *db){
 #ifndef SQLITE_OMIT_ATTACH
   static const int enc = SQLITE_UTF8;
-  sqlite3CreateFunc(db, "sqlite_attach", 3, enc, db, attachFunc, 0, 0);
-  sqlite3CreateFunc(db, "sqlite_detach", 1, enc, db, detachFunc, 0, 0);
+  sqlite3CreateFunc(db, "sqlite_attach", 3, enc, 0, attachFunc, 0, 0);
+  sqlite3CreateFunc(db, "sqlite_detach", 1, enc, 0, detachFunc, 0, 0);
 #endif
 }
 
index 0a21bf3c5ec18b8ee3af51f4f8ed82cd5ab0c485..c1138f8fdfb75d303d14906901c0e2422fa39df5 100644 (file)
@@ -16,7 +16,7 @@
 ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
 ** All other code has file scope.
 **
-** $Id: date.c,v 1.77 2008/03/19 20:18:28 drh Exp $
+** $Id: date.c,v 1.78 2008/03/19 21:45:51 drh Exp $
 **
 ** SQLite processes all times and dates as Julian Day numbers.  The
 ** dates and times are stored as the number of days since noon
@@ -324,7 +324,8 @@ static int parseDateOrTime(
     return 0;
   }else if( sqlite3StrICmp(zDate,"now")==0){
     double r;
-    sqlite3OsCurrentTime((sqlite3_vfs *)sqlite3_user_data(context), &r);
+    sqlite3 *db = sqlite3_context_db_handle(context);
+    sqlite3OsCurrentTime(db->pVfs, &r);
     p->rJD = r;
     p->validJD = 1;
     return 0;
@@ -970,12 +971,12 @@ static void currentTimeFunc(
 ){
   time_t t;
   char *zFormat = (char *)sqlite3_user_data(context);
-  sqlite3_vfs *pVfs;
+  sqlite3 *db;
   double rT;
   char zBuf[20];
 
-  pVfs = sqlite3_vfs_find(0);
-  sqlite3OsCurrentTime(pVfs, &rT);
+  db = sqlite3_context_db_handle(context);
+  sqlite3OsCurrentTime(db->pVfs, &rT);
   t = 86400.0*(rT - 2440587.5) + 0.5;
 #ifdef HAVE_GMTIME_R
   {
@@ -1022,7 +1023,7 @@ void sqlite3RegisterDateTimeFunctions(sqlite3 *db){
 
   for(i=0; i<sizeof(aFuncs)/sizeof(aFuncs[0]); i++){
     sqlite3CreateFunc(db, aFuncs[i].zName, aFuncs[i].nArg,
-        SQLITE_UTF8, (void *)(db->pVfs), aFuncs[i].xFunc, 0, 0);
+        SQLITE_UTF8, 0, aFuncs[i].xFunc, 0, 0);
   }
 #else
   static const struct {
index d91b36a3ae1284d82e563f14d11c690c8412305d..f380bcfa3e60aea5d4b8e18f8c2d63f54864cda2 100644 (file)
@@ -16,7 +16,7 @@
 ** sqliteRegisterBuildinFunctions() found at the bottom of the file.
 ** All other code has file scope.
 **
-** $Id: func.c,v 1.188 2008/03/19 16:08:54 drh Exp $
+** $Id: func.c,v 1.189 2008/03/19 21:45:51 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -365,7 +365,7 @@ static void last_insert_rowid(
   int arg, 
   sqlite3_value **argv
 ){
-  sqlite3 *db = sqlite3_user_data(context);
+  sqlite3 *db = sqlite3_context_db_handle(context);
   sqlite3_result_int64(context, sqlite3_last_insert_rowid(db));
 }
 
@@ -378,7 +378,7 @@ static void changes(
   int arg,
   sqlite3_value **argv
 ){
-  sqlite3 *db = sqlite3_user_data(context);
+  sqlite3 *db = sqlite3_context_db_handle(context);
   sqlite3_result_int(context, sqlite3_changes(db));
 }
 
@@ -391,7 +391,7 @@ static void total_changes(
   int arg,
   sqlite3_value **argv
 ){
-  sqlite3 *db = sqlite3_user_data(context);
+  sqlite3 *db = sqlite3_context_db_handle(context);
   sqlite3_result_int(context, sqlite3_total_changes(db));
 }
 
@@ -1005,7 +1005,7 @@ static void soundexFunc(
 static void loadExt(sqlite3_context *context, int argc, sqlite3_value **argv){
   const char *zFile = (const char *)sqlite3_value_text(argv[0]);
   const char *zProc;
-  sqlite3 *db = sqlite3_user_data(context);
+  sqlite3 *db = sqlite3_context_db_handle(context);
   char *zErrMsg = 0;
 
   if( argc==2 ){
@@ -1219,7 +1219,7 @@ void sqlite3RegisterBuiltinFunctions(sqlite3 *db){
   static const struct {
      char *zName;
      signed char nArg;
-     u8 argType;           /* ff: db   1: 0, 2: 1, 3: 2,...  N:  N-1. */
+     u8 argType;           /* 1: 0, 2: 1, 3: 2,...  N:  N-1. */
      u8 eTextRep;          /* 1: UTF-16.  0: UTF-8 */
      u8 needCollSeq;
      void (*xFunc)(sqlite3_context*,int,sqlite3_value **);
@@ -1247,9 +1247,9 @@ void sqlite3RegisterBuiltinFunctions(sqlite3 *db){
     { "nullif",             2, 0, SQLITE_UTF8,    1, nullifFunc },
     { "sqlite_version",     0, 0, SQLITE_UTF8,    0, versionFunc},
     { "quote",              1, 0, SQLITE_UTF8,    0, quoteFunc  },
-    { "last_insert_rowid",  0, 0xff, SQLITE_UTF8, 0, last_insert_rowid },
-    { "changes",            0, 0xff, SQLITE_UTF8, 0, changes           },
-    { "total_changes",      0, 0xff, SQLITE_UTF8, 0, total_changes     },
+    { "last_insert_rowid",  0, 0, SQLITE_UTF8, 0, last_insert_rowid },
+    { "changes",            0, 0, SQLITE_UTF8, 0, changes           },
+    { "total_changes",      0, 0, SQLITE_UTF8, 0, total_changes     },
     { "replace",            3, 0, SQLITE_UTF8,    0, replaceFunc       },
     { "ltrim",              1, 1, SQLITE_UTF8,    0, trimFunc          },
     { "ltrim",              2, 1, SQLITE_UTF8,    0, trimFunc          },
@@ -1262,8 +1262,8 @@ void sqlite3RegisterBuiltinFunctions(sqlite3 *db){
     { "soundex",            1, 0, SQLITE_UTF8,    0, soundexFunc},
 #endif
 #ifndef SQLITE_OMIT_LOAD_EXTENSION
-    { "load_extension",     1, 0xff, SQLITE_UTF8, 0, loadExt },
-    { "load_extension",     2, 0xff, SQLITE_UTF8, 0, loadExt },
+    { "load_extension",     1, 0, SQLITE_UTF8, 0, loadExt },
+    { "load_extension",     2, 0, SQLITE_UTF8, 0, loadExt },
 #endif
   };
   static const struct {
@@ -1289,11 +1289,7 @@ void sqlite3RegisterBuiltinFunctions(sqlite3 *db){
   for(i=0; i<sizeof(aFuncs)/sizeof(aFuncs[0]); i++){
     void *pArg;
     u8 argType = aFuncs[i].argType;
-    if( argType==0xff ){
-      pArg = db;
-    }else{
-      pArg = (void*)(sqlite3_intptr_t)argType;
-    }
+    pArg = (void*)(sqlite3_intptr_t)argType;
     sqlite3CreateFunc(db, aFuncs[i].zName, aFuncs[i].nArg,
         aFuncs[i].eTextRep, pArg, aFuncs[i].xFunc, 0, 0);
     if( aFuncs[i].needCollSeq ){
index f23b38ee236e432b4a1bb6e66694c519c2ac1533..55289a6aa7b6f108c569bd3532c01a640be554f9 100644 (file)
@@ -301,6 +301,7 @@ const sqlite3_api_routines sqlite3Apis = {
   sqlite3_result_error_code,
   sqlite3_test_control,
   sqlite3_randomness,
+  sqlite3_context_db_handle,
 };
 
 /*
index dd3d8a026126b7d332a76c9fbd7b88257d7c7814..bc8643f2cc34bdbaadd9516f198912e7b9106f40 100644 (file)
@@ -30,7 +30,7 @@
 ** the version number) and changes its name to "sqlite3.h" as
 ** part of the build process.
 **
-** @(#) $Id: sqlite.h.in,v 1.293 2008/03/19 14:15:35 drh Exp $
+** @(#) $Id: sqlite.h.in,v 1.294 2008/03/19 21:45:51 drh Exp $
 */
 #ifndef _SQLITE3_H_
 #define _SQLITE3_H_
@@ -3663,6 +3663,25 @@ void *sqlite3_aggregate_context(sqlite3_context*, int nBytes);
 */
 void *sqlite3_user_data(sqlite3_context*);
 
+/*
+** CAPI3REF: Database Connection For Functions {F16250}
+**
+** The sqlite3_context_db_handle() interface returns a copy of
+** the pointer to the [database connection] (the 1st parameter)
+** of the the [sqlite3_create_function()]
+** and [sqlite3_create_function16()] routines that originally
+** registered the application defined function.
+**
+** INVARIANTS:
+**
+** {F16253} The [sqlite3_context_db_handle(C)] interface returns a copy of the
+**          D pointer from the [sqlite3_create_function(D,X,N,E,P,F,S,L)]
+**          or [sqlite3_create_function16(D,X,N,E,P,F,S,L)] call that
+**          registered the SQL function associated with 
+**          [sqlite3_context] C.
+*/
+sqlite3 *sqlite3_context_db_handle(sqlite3_context*);
+
 /*
 ** CAPI3REF: Function Auxiliary Data {F16270}
 **
index 67eab3ae88c57281c5ada7fc0ad94b4ff133fcaf..6c538ffe0ef7f81b6257cee78f77751e8fad0052 100644 (file)
@@ -15,7 +15,7 @@
 ** as extensions by SQLite should #include this file instead of 
 ** sqlite3.h.
 **
-** @(#) $Id: sqlite3ext.h,v 1.20 2008/03/19 19:55:55 drh Exp $
+** @(#) $Id: sqlite3ext.h,v 1.21 2008/03/19 21:45:51 drh Exp $
 */
 #ifndef _SQLITE3EXT_H_
 #define _SQLITE3EXT_H_
@@ -187,6 +187,7 @@ struct sqlite3_api_routines {
   void (*result_error_code)(sqlite3_context*,int);
   int (*test_control)(int, ...);
   void (*randomness)(int,void*);
+  sqlite3 *(*context_db_handle)(sqlite3_context*);
 };
 
 /*
@@ -352,6 +353,7 @@ struct sqlite3_api_routines {
 #define sqlite3_result_error_code      sqlite3_api->result_error_code
 #define sqlite3_test_control           sqlite3_api->test_control
 #define sqlite3_randomness             sqlite3_api->randomness
+#define sqlite3_context_db_handle      sqlite3_api->context_db_handle
 #endif /* SQLITE_CORE */
 
 #define SQLITE_EXTENSION_INIT1     const sqlite3_api_routines *sqlite3_api;
index 77f319cd43c7916f73a91bd4f0e426ca286d5ea0..6f4b144e736b7d2e3c219c26f326b8cb9a9bdd29 100644 (file)
@@ -43,7 +43,7 @@
 ** in this file for details.  If in doubt, do not deviate from existing
 ** commenting and indentation practices when changing or adding code.
 **
-** $Id: vdbe.c,v 1.712 2008/03/19 14:15:35 drh Exp $
+** $Id: vdbe.c,v 1.713 2008/03/19 21:45:51 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -1212,7 +1212,7 @@ case OP_Function: {
   assert( pOp->p3>0 && pOp->p3<=p->nMem );
   pOut = &p->aMem[pOp->p3];
   ctx.s.flags = MEM_Null;
-  ctx.s.db = 0;
+  ctx.s.db = db;
 
   /* The output cell may already have a buffer allocated. Move
   ** the pointer to ctx.s so in case the user-function can use
index 8b4283d944479b0f168f4a1b9c03fc71c261eb1f..db6054ae88f95befd7eb9cdfaf96da019a5e83e2 100644 (file)
@@ -413,6 +413,15 @@ void *sqlite3_user_data(sqlite3_context *p){
   return p->pFunc->pUserData;
 }
 
+/*
+** Extract the user data from a sqlite3_context structure and return a
+** pointer to it.
+*/
+sqlite3 *sqlite3_context_db_handle(sqlite3_context *p){
+  assert( p && p->pFunc );
+  return p->s.db;
+}
+
 /*
 ** The following is the implementation of an SQL function that always
 ** fails with an error message stating that the function is used in the
index 7b5a4655ed079b7efc2f5a200b8b386b4940e54b..32628c59d33fd7a386fcf7a575664b9f6372c4b9 100644 (file)
@@ -503,6 +503,7 @@ void sqlite3VdbeMemSetDouble(Mem *pMem, double val){
 ** too large - whose size exceeds SQLITE_MAX_LENGTH.
 */
 int sqlite3VdbeMemTooBig(Mem *p){
+  assert( p->db!=0 );
   if( p->flags & (MEM_Str|MEM_Blob) ){
     int n = p->n;
     if( p->flags & MEM_Zero ){