]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add void* argument to sqlite3_create_module to replace sqlite3_module.pAux. (CVS...
authordanielk1977 <danielk1977@noemail.net>
Thu, 15 Jun 2006 04:28:13 +0000 (04:28 +0000)
committerdanielk1977 <danielk1977@noemail.net>
Thu, 15 Jun 2006 04:28:13 +0000 (04:28 +0000)
FossilOrigin-Name: 470a3a0b20775be1226fb4d477c798d8da2d5708

manifest
manifest.uuid
src/delete.c
src/main.c
src/sqlite.h.in
src/sqliteInt.h
src/test8.c
src/test_tclvar.c
src/vtab.c

index 79db0f9184f3d66aeb72434ce1086c580adf1fa0..33cbbb08f07e0ebfc7b122f7037e2e667b881e86 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Changes\sto\stest8.c\sto\ssupport\sUPDATE\soperations\son\sxUpdate.\s(CVS\s3250)
-D 2006-06-14T23:43:31
+C Add\svoid*\sargument\sto\ssqlite3_create_module\sto\sreplace\ssqlite3_module.pAux.\s(CVS\s3251)
+D 2006-06-15T04:28:13
 F Makefile.in 200f6dc376ecfd9b01e5359c4e0c10c02f649b34
 F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935
 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -40,7 +40,7 @@ F src/build.c 076619b2a5cbdbdabf5201fc45dda488d7f3cbe6
 F src/callback.c fd9bb39f7ff6b52bad8365617abc61c720640429
 F src/complete.c 7d1a44be8f37de125fcafd3d3a018690b3799675
 F src/date.c cd2bd5d1ebc6fa12d6312f69789ae5b0a2766f2e
-F src/delete.c d529fe3e20d87af628c0078fc33a3e717bb511cf
+F src/delete.c f34599f681d291d5b5762ff162a4b10214809aef
 F src/experimental.c 1b2d1a6cd62ecc39610e97670332ca073c50792b
 F src/expr.c 78b521337d628b1fd9d87b12dbbe771247aab585
 F src/func.c 01e559893b5e43bea85135ad3e481d86c447942a
@@ -49,7 +49,7 @@ F src/hash.h 1b3f7e2609141fd571f62199fc38687d262e9564
 F src/insert.c bda00a0e4be8bf4e591186e710075662781293d0
 F src/legacy.c fa15d505dd4e45044177ee4d1c6aeaf8c836d390
 F src/loadext.c d8c7bd14e6ebc4e9f1ff269475bf63e131919449
-F src/main.c 4e48472d06ac3fc0250023e2eb406fc7d8d0a27c
+F src/main.c 7875e8835539d4f16e8b62fad1dee9bda2091272
 F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217
 F src/os.c 59f05de8c5777c34876607114a2fbe55ae578235
 F src/os.h ac2ccb4f48902c1611a7e1f171eb81d17e3b8eb2
@@ -72,9 +72,9 @@ F src/random.c d40f8d356cecbd351ccfab6eaedd7ec1b54f5261
 F src/select.c 38eda11d950ed5e631ea9054f84a4a8b9e9b39d8
 F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96
 F src/shell.c ad73192b30a338a58fe81183d4a5d5a1d4e51d36
-F src/sqlite.h.in b1ecebd3154cf49ba189193f7bdc10a78a9394a2
+F src/sqlite.h.in 1dc44da025da28a011d11ad1608c11a951047fab
 F src/sqlite3ext.h 127bd394c8eea481f2ac9b754bf399dbfc818b75
-F src/sqliteInt.h 5a806625f0e9400419d60f74dccef44569dd7871
+F src/sqliteInt.h 5eb64f1dd9a8b237d147962bc57637d87e044ff4
 F src/table.c f64ec4fbfe333f8df925bc6ba494f55e05b0e75e
 F src/tclsqlite.c 4ad22f354b6e4e137889000e9f585a0590ca39c5
 F src/test1.c 40f20775903bc76d3be3e7c026dddcbc221c1cb0
@@ -84,12 +84,12 @@ F src/test4.c 8b784cd82de158a2317cb4ac4bc86f91ad315e25
 F src/test5.c 7162f8526affb771c4ed256826eee7bb9eca265f
 F src/test6.c 60a02961ceb7b3edc25f5dc5c1ac2556622a76de
 F src/test7.c 03fa8d787f6aebc6d1f72504d52f33013ad2c8e3
-F src/test8.c 2f38a6c295f15dd9dbb3db954be21aa8ea3c284b
+F src/test8.c c8da12c237a507273dba8cb11a9f88d2252bd031
 F src/test_async.c e3deaedd4d86a56391b81808fde9e44fbd92f1d3
 F src/test_loadext.c 22065d601a18878e5542191001f0eaa5d77c0ed8
 F src/test_md5.c 6c42bc0a3c0b54be34623ff77a0eec32b2fa96e3
 F src/test_server.c a6460daed0b92ecbc2531b6dc73717470e7a648c
-F src/test_tclvar.c d434037c1730cfffbf007ac82f1c405d7155a92a
+F src/test_tclvar.c c52f67fbe06d32804af2ba9a2d7aadfc15f5910c
 F src/tokenize.c 6ebcafa6622839968dda4418a7b6945f277a128f
 F src/trigger.c 0fc40125820409a6274834a6e04ad804d96e2793
 F src/update.c 5e638a61102776c0f0333994e18361b40598b44f
@@ -103,7 +103,7 @@ F src/vdbeapi.c 6af0e7160af260052a7a4500464221a03dada75f
 F src/vdbeaux.c de49c1943146ad97538bc2bb0bce7f2c5e5db4f2
 F src/vdbefifo.c 9efb94c8c3f4c979ebd0028219483f88e57584f5
 F src/vdbemem.c 5f0afe3b92bb2c037f8d5d697f7c151fa50783a3
-F src/vtab.c 507cbb4e2101900339ce88e57144cc01dafa374e
+F src/vtab.c 3b58aa4a54288efe7b1b0cddcdeac239ffa3f071
 F src/where.c d7c3cc011834882b2d58ebb3a6a1a569ead7ebd7
 F tclinstaller.tcl 046e3624671962dc50f0481d7c25b38ef803eb42
 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
@@ -366,7 +366,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
 F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
-P c996185a9e0671e46bed06e5803b1ca3b42d61e2
-R ee3ad5273671026614072c99f84a0525
-U drh
-Z bbafadf19467cae14bf8a8d2edcf9481
+P 9e96511f83476e489fa62a05241393a851cbac5c
+R 3b2eab4f54e22efb7b510b16ba4f9657
+U danielk1977
+Z 15129ea2cdd7a9095da7badd4764cc47
index c7b1c9268c54a99697fdd7d0e0942c658d3d6ca4..1934aba7aa1bc67e38f1010c837159569851f3bc 100644 (file)
@@ -1 +1 @@
-9e96511f83476e489fa62a05241393a851cbac5c
\ No newline at end of file
+470a3a0b20775be1226fb4d477c798d8da2d5708
\ No newline at end of file
index 37b8577d8e8040a01ff0412220f772b0049cf0a7..f1cdcdb9a200650324e35a5034225693f3dd4f8b 100644 (file)
@@ -12,7 +12,7 @@
 ** This file contains C code routines that are called by the parser
 ** in order to generate code for DELETE FROM statements.
 **
-** $Id: delete.c,v 1.124 2006/06/14 19:00:21 drh Exp $
+** $Id: delete.c,v 1.125 2006/06/15 04:28:13 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 
@@ -45,7 +45,7 @@ int sqlite3IsReadOnly(Parse *pParse, Table *pTab, int viewOk){
   if( (pTab->readOnly && (pParse->db->flags & SQLITE_WriteSchema)==0
         && pParse->nested==0) 
 #ifndef SQLITE_OMIT_VIRTUALTABLE
-      || (pTab->pModule && pTab->pModule->xUpdate==0)
+      || (pTab->pMod && pTab->pMod->pModule->xUpdate==0)
 #endif
   ){
     sqlite3ErrorMsg(pParse, "table %s may not be modified", pTab->zName);
index 526eaed6a282198a78e4c34580e8be9a52c0aa09..463ba997a0660ec053a674fb8ac1a9b596682623 100644 (file)
@@ -14,7 +14,7 @@
 ** other files are for internal use by SQLite and should not be
 ** accessed by users of the library.
 **
-** $Id: main.c,v 1.343 2006/06/14 15:35:37 drh Exp $
+** $Id: main.c,v 1.344 2006/06/15 04:28:13 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -160,6 +160,10 @@ int sqlite3_close(sqlite3 *db){
   }
   sqlite3HashClear(&db->aCollSeq);
 #ifndef SQLITE_OMIT_VIRTUALTABLE
+  for(i=sqliteHashFirst(&db->aModule); i; i=sqliteHashNext(i)){
+    Module *pMod = (Module *)sqliteHashData(i);
+    sqliteFree(pMod);
+  }
   sqlite3HashClear(&db->aModule);
 #endif
 
index 2f8f1443cc3c832c88415d900d545501a26b2ccd..68f3a568bb84ffec074e80653d727149cc80dff6 100644 (file)
@@ -12,7 +12,7 @@
 ** This header file defines the interface that the SQLite library
 ** presents to client programs.
 **
-** @(#) $Id: sqlite.h.in,v 1.176 2006/06/14 13:03:23 danielk1977 Exp $
+** @(#) $Id: sqlite.h.in,v 1.177 2006/06/15 04:28:13 danielk1977 Exp $
 */
 #ifndef _SQLITE3_H_
 #define _SQLITE3_H_
@@ -1536,7 +1536,6 @@ typedef struct sqlite3_module sqlite3_module;
 struct sqlite3_module {
   int iVersion;
   const char *zName;
-  void *pAux;
   int (*xCreate)(sqlite3*, void *pAux,
                int argc, char **argv,
                sqlite3_vtab **ppVTab);
@@ -1649,7 +1648,8 @@ struct sqlite3_index_info {
 int sqlite3_create_module(
   sqlite3 *db,               /* SQLite connection to register module with */
   const char *zName,         /* Name of the module */
-  const sqlite3_module *     /* Methods for the module */
+  const sqlite3_module *,    /* Methods for the module */
+  void *                     /* Client data for xCreate/xConnect */
 );
 
 /*
index fcc147adfb9db50e9cd44703d779424ec15a4a75..f51ead31756962f5dc44cc88d08786dd61048781 100644 (file)
@@ -11,7 +11,7 @@
 *************************************************************************
 ** Internal interface definitions for SQLite.
 **
-** @(#) $Id: sqliteInt.h,v 1.505 2006/06/14 19:00:21 drh Exp $
+** @(#) $Id: sqliteInt.h,v 1.506 2006/06/15 04:28:13 danielk1977 Exp $
 */
 #ifndef _SQLITEINT_H_
 #define _SQLITEINT_H_
@@ -343,6 +343,7 @@ typedef struct IdList IdList;
 typedef struct Index Index;
 typedef struct KeyClass KeyClass;
 typedef struct KeyInfo KeyInfo;
+typedef struct Module Module;
 typedef struct NameContext NameContext;
 typedef struct Parse Parse;
 typedef struct Select Select;
@@ -566,6 +567,17 @@ struct FuncDef {
   char zName[1];       /* SQL name of the function.  MUST BE LAST */
 };
 
+/*
+** Each SQLite module (virtual table definition) is defined by an
+** instance of the following structure, stored in the sqlite3.aModule
+** hash table.
+*/
+struct Module {
+  const sqlite3_module *pModule;       /* Callback pointers */
+  const char *zName;                   /* Name passed to create_module() */
+  void *pAux;                          /* pAux passed to create_module() */
+};
+
 /*
 ** Possible values for FuncDef.flags
 */
@@ -705,7 +717,7 @@ struct Table {
   int addColOffset;  /* Offset in CREATE TABLE statement to add a new column */
 #endif
 #ifndef SQLITE_OMIT_VIRTUALTABLE
-  sqlite3_module *pModule;  /* Pointer to the implementation of the module */
+  Module *pMod;             /* Pointer to the implementation of the module */
   sqlite3_vtab *pVtab;      /* Pointer to the module instance */
   u8 isVirtual;             /* True if this is a virtual table */
   int nModuleArg;           /* Number of arguments to the module */
index 7742216350a647784aedd83ab12fe19075de72a3..ead66444f7eb3a8d93c692248958bcb7822e53aa 100644 (file)
@@ -13,7 +13,7 @@
 ** is not included in the SQLite library.  It is used for automated
 ** testing of the SQLite library.
 **
-** $Id: test8.c,v 1.19 2006/06/14 23:43:31 drh Exp $
+** $Id: test8.c,v 1.20 2006/06/15 04:28:13 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #include "tcl.h"
@@ -622,7 +622,6 @@ int echoUpdate(sqlite3_vtab *tab, int nData, sqlite3_value **apData){
 static sqlite3_module echoModule = {
   0,                         /* iVersion */
   "echo",                    /* zName */
-  0,                         /* pAux */
   echoCreate,
   echoConnect,
   echoBestIndex,
@@ -661,9 +660,8 @@ static int register_echo_module(
     return TCL_ERROR;
   }
   if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
-  echoModule.pAux = interp;
 #ifndef SQLITE_OMIT_VIRTUALTABLE
-  sqlite3_create_module(db, "echo", &echoModule);
+  sqlite3_create_module(db, "echo", &echoModule, (void *)interp);
 #endif
   return TCL_OK;
 }
index fc474bb70fc81ca619a6b2017b4e8da456a331b2..daa86e780776a1e9bf7cc9efcda7032b299ef85d 100644 (file)
@@ -16,7 +16,7 @@
 ** The emphasis of this file is a virtual table that provides
 ** access to TCL variables.
 **
-** $Id: test_tclvar.c,v 1.2 2006/06/14 06:58:16 danielk1977 Exp $
+** $Id: test_tclvar.c,v 1.3 2006/06/15 04:28:13 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #include "tcl.h"
@@ -65,6 +65,7 @@ static int tclvarConnect(
 ** methods are identical. */
 static int tclvarDisconnect(sqlite3_vtab *pVtab){
   free(pVtab);
+  return SQLITE_OK;
 }
 /* The xDisconnect and xDestroy methods are also the same */
 
@@ -126,7 +127,6 @@ static int tclvarBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
 static sqlite3_module tclvarModule = {
   0,                         /* iVersion */
   "tclvar",                  /* zName */
-  0,                         /* pAux */
   tclvarConnect,
   tclvarConnect,
   tclvarBestIndex,
@@ -164,9 +164,8 @@ static int register_tclvar_module(
     return TCL_ERROR;
   }
   if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
-  tclvarModule.pAux = interp;
 #ifndef SQLITE_OMIT_VIRTUALTABLE
-  sqlite3_create_module(db, "tclvar", &tclvarModule);
+  sqlite3_create_module(db, "tclvar", &tclvarModule, (void *)interp);
 #endif
   return TCL_OK;
 }
index a7fd6a88ec15693abb0c755858feb4b2a431ee92..727ee5117a09c02e01d46b3d169224924b79052d 100644 (file)
@@ -11,7 +11,7 @@
 *************************************************************************
 ** This file contains code used to help implement virtual tables.
 **
-** $Id: vtab.c,v 1.11 2006/06/14 13:03:24 danielk1977 Exp $
+** $Id: vtab.c,v 1.12 2006/06/15 04:28:13 danielk1977 Exp $
 */
 #ifndef SQLITE_OMIT_VIRTUALTABLE
 #include "sqliteInt.h"
 int sqlite3_create_module(
   sqlite3 *db,                    /* Database in which module is registered */
   const char *zName,              /* Name assigned to this module */
-  const sqlite3_module *pModule   /* The definition of the module */
+  const sqlite3_module *pModule,  /* The definition of the module */
+  void *pAux                      /* Context pointer for xCreate/xConnect */
 ){
-  sqlite3HashInsert(&db->aModule, zName, strlen(zName), (void*)pModule);
-  sqlite3ResetInternalSchema(db, 0);
-  return SQLITE_OK;
+  int nName = strlen(zName);
+  Module *pMod = (Module *)sqliteMallocRaw(sizeof(Module) + nName + 1);
+  if( pMod ){
+    char *zCopy = (char *)(&pMod[1]);
+    strcpy(zCopy, zName);
+    pMod->zName = zCopy;
+    pMod->pModule = pModule;
+    pMod->pAux = pAux;
+    pMod = (Module *)sqlite3HashInsert(&db->aModule, zCopy, nName, (void*)pMod);
+    sqliteFree(pMod);
+    sqlite3ResetInternalSchema(db, 0);
+  }
+  return sqlite3ApiExit(db, SQLITE_OK);
 }
 
 /*
@@ -36,8 +47,8 @@ int sqlite3_create_module(
 */
 void sqlite3VtabClear(Table *p){
   if( p->pVtab ){
-    assert( p->pModule!=0 );
-    p->pModule->xDisconnect(p->pVtab);
+    assert( p->pMod && p->pMod->pModule );
+    p->pMod->pModule->xDisconnect(p->pVtab);
   }
   if( p->azModuleArg ){
     int i;
@@ -116,6 +127,7 @@ void sqlite3VtabFinishParse(Parse *pParse, Token *pEnd){
   Table *pTab;        /* The table being constructed */
   sqlite3 *db;        /* The database connection */
   char *zModule;      /* The module name of the table: USING modulename */
+  Module *pMod = 0;
 
   addArgumentToVtab(pParse);
   sqliteFree(pParse->zArg);
@@ -128,8 +140,8 @@ void sqlite3VtabFinishParse(Parse *pParse, Token *pEnd){
   db = pParse->db;
   if( pTab->nModuleArg<1 ) return;
   zModule = pTab->azModuleArg[0];
-  pTab->pModule = (sqlite3_module*)sqlite3HashFind(&db->aModule, 
-                     zModule, strlen(zModule));
+  pMod = (Module *)sqlite3HashFind(&db->aModule, zModule, strlen(zModule));
+  pTab->pMod = pMod;
   
   /* If the CREATE VIRTUAL TABLE statement is being entered for the
   ** first time (in other words if the virtual table is actually being
@@ -142,7 +154,7 @@ void sqlite3VtabFinishParse(Parse *pParse, Token *pEnd){
     char *zWhere;
     int iDb;
     Vdbe *v;
-    if( pTab->pModule==0 ){
+    if( !pMod ){
       sqlite3ErrorMsg(pParse, "no such module: %s", zModule);
     }
 
@@ -241,7 +253,7 @@ void sqlite3VtabArgExtend(Parse *pParse, Token *p){
 static int vtabCallConstructor(
   sqlite3 *db, 
   Table *pTab,
-  sqlite3_module *pModule,
+  Module *pMod,
   int (*xConstruct)(sqlite3*, void *, int, char **, sqlite3_vtab **),
   char **pzErr
 ){
@@ -256,10 +268,10 @@ static int vtabCallConstructor(
   db->pVTab = pTab;
   rc = sqlite3SafetyOff(db);
   assert( rc==SQLITE_OK );
-  rc = xConstruct(db, pModule->pAux, nArg, azArg, &pTab->pVtab);
+  rc = xConstruct(db, pMod->pAux, nArg, azArg, &pTab->pVtab);
   rc2 = sqlite3SafetyOn(db);
   if( pTab->pVtab ){
-    pTab->pVtab->pModule = pModule;
+    pTab->pVtab->pModule = pMod->pModule;
   }
 
   if( SQLITE_OK!=rc ){
@@ -284,7 +296,7 @@ static int vtabCallConstructor(
 ** This call is a no-op if table pTab is not a virtual table.
 */
 int sqlite3VtabCallConnect(Parse *pParse, Table *pTab){
-  sqlite3_module *pModule;
+  Module *pMod;
   const char *zModule;
   int rc = SQLITE_OK;
 
@@ -292,15 +304,16 @@ int sqlite3VtabCallConnect(Parse *pParse, Table *pTab){
     return SQLITE_OK;
   }
 
-  pModule = pTab->pModule;
+  pMod = pTab->pMod;
   zModule = pTab->azModuleArg[0];
-  if( !pModule ){
+  if( !pMod ){
     const char *zModule = pTab->azModuleArg[0];
     sqlite3ErrorMsg(pParse, "no such module: %s", zModule);
     rc = SQLITE_ERROR;
   } else {
     char *zErr = 0;
-    rc = vtabCallConstructor(pParse->db,pTab,pModule,pModule->xConnect,&zErr);
+    sqlite3 *db = pParse->db;
+    rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xConnect, &zErr);
     if( rc!=SQLITE_OK ){
       sqlite3ErrorMsg(pParse, "%s", zErr);
     }
@@ -321,23 +334,23 @@ int sqlite3VtabCallConnect(Parse *pParse, Table *pTab){
 int sqlite3VtabCallCreate(sqlite3 *db, int iDb, const char *zTab, char **pzErr){
   int rc = SQLITE_OK;
   Table *pTab;
-  sqlite3_module *pModule;
+  Module *pMod;
   const char *zModule;
 
   pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName);
   assert(pTab && pTab->isVirtual && !pTab->pVtab);
-  pModule = pTab->pModule;
+  pMod = pTab->pMod;
   zModule = pTab->azModuleArg[0];
 
   /* If the module has been registered and includes a Create method, 
   ** invoke it now. If the module has not been registered, return an 
   ** error. Otherwise, do nothing.
   */
-  if( !pModule ){
+  if( !pMod ){
     *pzErr = sqlite3MPrintf("no such module: %s", zModule);
     rc = SQLITE_ERROR;
   }else{
-    rc = vtabCallConstructor(db, pTab, pModule, pModule->xCreate, pzErr);
+    rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xCreate, pzErr);
   }
 
   return rc;
@@ -401,15 +414,16 @@ int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab)
 {
   int rc = SQLITE_OK;
   Table *pTab;
-  sqlite3_module *pModule;
 
   pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName);
-  pModule = pTab->pModule;
   assert(pTab);
   if( pTab->pVtab ){
+    int (*xDestroy)(sqlite3_vtab *pVTab) = pTab->pMod->pModule->xDestroy;
     rc = sqlite3SafetyOff(db);
     assert( rc==SQLITE_OK );
-    rc = pModule->xDestroy(pTab->pVtab);
+    if( xDestroy ){
+      rc = xDestroy(pTab->pVtab);
+    }
     sqlite3SafetyOn(db);
     if( rc==SQLITE_OK ){
       pTab->pVtab = 0;