From 9da9d471f5c7315cb97f536e1d4edbffb07fce38 Mon Sep 17 00:00:00 2001 From: danielk1977 Date: Wed, 14 Jun 2006 06:58:15 +0000 Subject: [PATCH] Change the pModule parameter of the xCreate and xConnect methods to a void*. (CVS 3236) FossilOrigin-Name: 3ffa51b50a7831ef359bc40acf605decc922c498 --- manifest | 18 +++--- manifest.uuid | 2 +- src/sqlite.h.in | 6 +- src/test8.c | 19 +++--- src/test_tclvar.c | 7 +-- src/vtab.c | 153 +++++++++++++++++++++++++--------------------- 6 files changed, 107 insertions(+), 98 deletions(-) diff --git a/manifest b/manifest index 630170c89b..326e7b5c7a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\stests\sfor\serror\sconditions\ssurrounding\sthe\screation/connection\sof\svirtual\stables.\s(CVS\s3235) -D 2006-06-14T06:31:28 +C Change\sthe\spModule\sparameter\sof\sthe\sxCreate\sand\sxConnect\smethods\sto\sa\svoid*.\s(CVS\s3236) +D 2006-06-14T06:58:16 F Makefile.in 200f6dc376ecfd9b01e5359c4e0c10c02f649b34 F Makefile.linux-gcc 74ba0eadf88748a9ce3fd03d2a3ede2e6715baec F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -72,7 +72,7 @@ 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 84522f48a0a044987267a82d680121194d31fb7a +F src/sqlite.h.in 45975614ab23be1be971a1624a2c5f6801c99c2d F src/sqlite3ext.h 127bd394c8eea481f2ac9b754bf399dbfc818b75 F src/sqliteInt.h e8710fd5c10c03ca4a2fb49802b8aae6689f27a0 F src/table.c f64ec4fbfe333f8df925bc6ba494f55e05b0e75e @@ -84,11 +84,11 @@ F src/test4.c 8b784cd82de158a2317cb4ac4bc86f91ad315e25 F src/test5.c 7162f8526affb771c4ed256826eee7bb9eca265f F src/test6.c 60a02961ceb7b3edc25f5dc5c1ac2556622a76de F src/test7.c 03fa8d787f6aebc6d1f72504d52f33013ad2c8e3 -F src/test8.c f91c78d8ad3aecf3e670e66c087a79ff806b21b2 +F src/test8.c 06c0a7b6057b8733f8ef94e9eae815b32141c143 F src/test_async.c e3deaedd4d86a56391b81808fde9e44fbd92f1d3 F src/test_md5.c 6c42bc0a3c0b54be34623ff77a0eec32b2fa96e3 F src/test_server.c a6460daed0b92ecbc2531b6dc73717470e7a648c -F src/test_tclvar.c 3157e17194caa73434041d310b66ec93803aa1be +F src/test_tclvar.c d434037c1730cfffbf007ac82f1c405d7155a92a F src/tokenize.c 6ebcafa6622839968dda4418a7b6945f277a128f F src/trigger.c 48bbb94c11954c8e132efcc04478efe8304c4196 F src/update.c 0186f09414a6578156d40666becc964f85c2a616 @@ -102,7 +102,7 @@ F src/vdbeapi.c af663689ef57e5506f190bbd1068d28936b0fb34 F src/vdbeaux.c c9474fd27f1735170feb4f6a46885d282cf22d52 F src/vdbefifo.c 9efb94c8c3f4c979ebd0028219483f88e57584f5 F src/vdbemem.c 5f0afe3b92bb2c037f8d5d697f7c151fa50783a3 -F src/vtab.c 6af0aa0ef2ebca743a4647eb22fd5d5d3813d83e +F src/vtab.c b198496e428e1d1c1fef96afeac36828f0171628 F src/where.c 299c385e32a7b98d42864c7c83cdc6a778fae562 F tclinstaller.tcl 046e3624671962dc50f0481d7c25b38ef803eb42 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -364,7 +364,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513 -P 29199eeea4c46168ccaa7535d4941bd740479dee -R dc5e6094d3fe7373d35dfb54c78f916b +P 5e592c422b86deb5802c6536e91661717ee9bbe1 +R 4fa19ffe7cfb0134822441de8330a6ea U danielk1977 -Z 267156075d7b55f7a94e810698d71dbc +Z 368680ae09650a1bb3f150de6a1748ad diff --git a/manifest.uuid b/manifest.uuid index 2a5b436431..78871a9a1d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5e592c422b86deb5802c6536e91661717ee9bbe1 \ No newline at end of file +3ffa51b50a7831ef359bc40acf605decc922c498 \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 9d59515b91..0d3d255398 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -12,7 +12,7 @@ ** This header file defines the interface that the SQLite library ** presents to client programs. ** -** @(#) $Id: sqlite.h.in,v 1.174 2006/06/13 23:51:34 drh Exp $ +** @(#) $Id: sqlite.h.in,v 1.175 2006/06/14 06:58:16 danielk1977 Exp $ */ #ifndef _SQLITE3_H_ #define _SQLITE3_H_ @@ -1537,10 +1537,10 @@ struct sqlite3_module { int iVersion; const char *zName; void *pAux; - int (*xCreate)(sqlite3*, const sqlite3_module *pModule, + int (*xCreate)(sqlite3*, void *pAux, int argc, char **argv, sqlite3_vtab **ppVTab); - int (*xConnect)(sqlite3*, const sqlite3_module *pModule, + int (*xConnect)(sqlite3*, void *pAux, int argc, char **argv, sqlite3_vtab **ppVTab); int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*); diff --git a/src/test8.c b/src/test8.c index 903ec3c7b4..eeefaff8c4 100644 --- a/src/test8.c +++ b/src/test8.c @@ -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.12 2006/06/14 06:31:28 danielk1977 Exp $ +** $Id: test8.c,v 1.13 2006/06/14 06:58:16 danielk1977 Exp $ */ #include "sqliteInt.h" #include "tcl.h" @@ -223,7 +223,7 @@ static int echoDestructor(sqlite3_vtab *pVtab){ static int echoConstructor( sqlite3 *db, - const sqlite3_module *pModule, + void *pAux, int argc, char **argv, sqlite3_vtab **ppVtab ){ @@ -231,8 +231,7 @@ static int echoConstructor( echo_vtab *pVtab; pVtab = sqliteMalloc( sizeof(*pVtab) ); - pVtab->base.pModule = pModule; - pVtab->interp = pModule->pAux; + pVtab->interp = (Tcl_Interp *)pAux; pVtab->db = db; pVtab->zTableName = sqlite3MPrintf("%s", argv[1]); for(i=0; ipAux), "xCreate"); - return echoConstructor(db, pModule, argc, argv, ppVtab); + appendToEchoModule((Tcl_Interp *)(pAux), "xCreate"); + return echoConstructor(db, pAux, argc, argv, ppVtab); } static int echoConnect( sqlite3 *db, - const sqlite3_module *pModule, + void *pAux, int argc, char **argv, sqlite3_vtab **ppVtab ){ - appendToEchoModule((Tcl_Interp *)(pModule->pAux), "xConnect"); - return echoConstructor(db, pModule, argc, argv, ppVtab); + appendToEchoModule((Tcl_Interp *)(pAux), "xConnect"); + return echoConstructor(db, pAux, argc, argv, ppVtab); } static int echoDisconnect(sqlite3_vtab *pVtab){ diff --git a/src/test_tclvar.c b/src/test_tclvar.c index 00937c2769..fc474bb70f 100644 --- a/src/test_tclvar.c +++ b/src/test_tclvar.c @@ -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.1 2006/06/13 23:51:35 drh Exp $ +** $Id: test_tclvar.c,v 1.2 2006/06/14 06:58:16 danielk1977 Exp $ */ #include "sqliteInt.h" #include "tcl.h" @@ -45,7 +45,7 @@ struct tclvar_cursor { /* Methods for the tclvar module */ static int tclvarConnect( sqlite3 *db, - const sqlite3_module *pModule, + void *pAux, int argc, char **argv, sqlite3_vtab **ppVtab ){ @@ -55,8 +55,7 @@ static int tclvarConnect( pVtab = sqliteMalloc( sizeof(*pVtab) ); if( pVtab==0 ) return SQLITE_NOMEM; *ppVtab = &pVtab->base; - pVtab->base.pModule = pModule; - pVtab->interp = pModule->pAux; + pVtab->interp = (Tcl_Interp *)pAux; #ifndef SQLITE_OMIT_VIRTUALTABLE sqlite3_declare_vtab(db, zSchema); #endif diff --git a/src/vtab.c b/src/vtab.c index 6f94e2ce1e..2f60627762 100644 --- a/src/vtab.c +++ b/src/vtab.c @@ -11,7 +11,7 @@ ************************************************************************* ** This file contains code used to help implement virtual tables. ** -** $Id: vtab.c,v 1.9 2006/06/14 06:31:28 danielk1977 Exp $ +** $Id: vtab.c,v 1.10 2006/06/14 06:58:16 danielk1977 Exp $ */ #ifndef SQLITE_OMIT_VIRTUALTABLE #include "sqliteInt.h" @@ -234,6 +234,49 @@ void sqlite3VtabArgExtend(Parse *pParse, Token *p){ pParse->zArg[pParse->nArgUsed] = 0; } +/* +** Invoke a virtual table constructor (either xCreate or xConnect). The +** pointer to the function to invoke is passed as the fourth parameter +** to this procedure. +*/ +static int vtabCallConstructor( + sqlite3 *db, + Table *pTab, + sqlite3_module *pModule, + int (*xConstruct)(sqlite3*, void *, int, char **, sqlite3_vtab **), + char **pzErr +){ + int rc; + int rc2; + char **azArg = pTab->azModuleArg; + int nArg = pTab->nModuleArg; + + assert( !db->pVTab ); + assert( xConstruct ); + + db->pVTab = pTab; + rc = sqlite3SafetyOff(db); + assert( rc==SQLITE_OK ); + rc = xConstruct(db, pModule->pAux, nArg, azArg, &pTab->pVtab); + rc2 = sqlite3SafetyOn(db); + if( pTab->pVtab ){ + pTab->pVtab->pModule = pModule; + } + + if( SQLITE_OK!=rc ){ + *pzErr = sqlite3MPrintf("vtable constructor failed: %s", pTab->zName); + } else if( db->pVTab ){ + const char *zFormat = "vtable constructor did not declare schema: %s"; + *pzErr = sqlite3MPrintf(zFormat, pTab->zName); + rc = SQLITE_ERROR; + } + if( rc==SQLITE_OK ){ + rc = rc2; + } + db->pVTab = 0; + return rc; +} + /* ** This function is invoked by the parser to call the xConnect() method ** of the virtual table pTab. If an error occurs, an error code is returned @@ -252,31 +295,54 @@ int sqlite3VtabCallConnect(Parse *pParse, Table *pTab){ pModule = pTab->pModule; zModule = pTab->azModuleArg[0]; - if( !pModule || !pModule->xConnect ){ + if( !pModule ){ const char *zModule = pTab->azModuleArg[0]; sqlite3ErrorMsg(pParse, "no such module: %s", zModule); rc = SQLITE_ERROR; } else { - char **azArg = pTab->azModuleArg; - int nArg = pTab->nModuleArg; - sqlite3 *db = pParse->db; - assert( !db->pVTab ); - db->pVTab = pTab; - rc = sqlite3SafetyOff(db); - assert( rc==SQLITE_OK ); - rc = pModule->xConnect(db, pModule, nArg, azArg, &pTab->pVtab); - db->pVTab = 0; - if( rc ){ - sqlite3ErrorMsg(pParse, "module connect failed: %s", zModule); - sqlite3SafetyOn(db); - } else { - rc = sqlite3SafetyOn(db); + char *zErr = 0; + rc = vtabCallConstructor(pParse->db,pTab,pModule,pModule->xConnect,&zErr); + if( rc!=SQLITE_OK ){ + sqlite3ErrorMsg(pParse, "%s", zErr); } + sqliteFree(zErr); } return rc; } +/* +** This function is invoked by the vdbe to call the xCreate method +** of the virtual table named zTab in database iDb. +** +** If an error occurs, *pzErr is set to point an an English language +** description of the error and an SQLITE_XXX error code is returned. +** In this case the caller must call sqliteFree() on *pzErr. +*/ +int sqlite3VtabCallCreate(sqlite3 *db, int iDb, const char *zTab, char **pzErr){ + int rc = SQLITE_OK; + Table *pTab; + sqlite3_module *pModule; + const char *zModule; + + pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName); + assert(pTab && pTab->isVirtual && !pTab->pVtab); + pModule = pTab->pModule; + 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 ){ + *pzErr = sqlite3MPrintf("no such module: %s", zModule); + rc = SQLITE_ERROR; + }else{ + rc = vtabCallConstructor(db, pTab, pModule, pModule->xCreate, pzErr); + } + + return rc; +} /* ** This function is used to set the schema of a virtual table. It is only @@ -325,61 +391,6 @@ int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){ return rc; } -/* -** This function is invoked by the vdbe to call the xCreate method -** of the virtual table named zTab in database iDb. -** -** If an error occurs, *pzErr is set to point an an English language -** description of the error and an SQLITE_XXX error code is returned. -** In this case the caller must call sqliteFree() on *pzErr. -*/ -int sqlite3VtabCallCreate(sqlite3 *db, int iDb, const char *zTab, char **pzErr){ - int rc = SQLITE_OK; - Table *pTab; - sqlite3_module *pModule; - const char *zModule; - - pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName); - assert(pTab && pTab->isVirtual && !pTab->pVtab); - pModule = pTab->pModule; - 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 ){ - *pzErr = sqlite3MPrintf("no such module: %s", zModule); - rc = SQLITE_ERROR; - }else{ - int rc2; - char **azArg = pTab->azModuleArg; - int nArg = pTab->nModuleArg; - - assert( !db->pVTab ); - assert( pModule->xCreate ); - db->pVTab = pTab; - rc = sqlite3SafetyOff(db); - assert( rc==SQLITE_OK ); - rc = pModule->xCreate(db, pModule, nArg, azArg, &pTab->pVtab); - rc2 = sqlite3SafetyOn(db); - - if( SQLITE_OK!=rc ){ - *pzErr = sqlite3MPrintf("vtable constructor failed: %s", zTab); - } else if( db->pVTab ){ - const char *zFormat = "vtable constructor did not declare schema: %s"; - *pzErr = sqlite3MPrintf(zFormat, zTab); - rc = SQLITE_ERROR; - } - db->pVTab = 0; - if( rc==SQLITE_OK ){ - rc = rc2; - } - } - - return rc; -} - /* ** This function is invoked by the vdbe to call the xDestroy method ** of the virtual table named zTab in database iDb. This occurs