diff options
author | danielk1977 <danielk1977@noemail.net> | 2006-06-14 06:58:15 +0000 |
---|---|---|
committer | danielk1977 <danielk1977@noemail.net> | 2006-06-14 06:58:15 +0000 |
commit | 9da9d471f5c7315cb97f536e1d4edbffb07fce38 (patch) | |
tree | d41c664bc0db369527817c8d536b71435065c309 /src | |
parent | a4e763671d9a9d29fc5f7cab047a930929628547 (diff) | |
download | sqlite-9da9d471f5c7315cb97f536e1d4edbffb07fce38.tar.gz sqlite-9da9d471f5c7315cb97f536e1d4edbffb07fce38.zip |
Change the pModule parameter of the xCreate and xConnect methods to a void*. (CVS 3236)
FossilOrigin-Name: 3ffa51b50a7831ef359bc40acf605decc922c498
Diffstat (limited to 'src')
-rw-r--r-- | src/sqlite.h.in | 6 | ||||
-rw-r--r-- | src/test8.c | 19 | ||||
-rw-r--r-- | src/test_tclvar.c | 7 | ||||
-rw-r--r-- | src/vtab.c | 153 |
4 files changed, 97 insertions, 88 deletions
diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 9d59515b9..0d3d25539 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 903ec3c7b..eeefaff8c 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; i<argc; i++){ @@ -251,21 +250,21 @@ static int echoConstructor( /* Methods for the echo module */ static int echoCreate( sqlite3 *db, - const sqlite3_module *pModule, + void *pAux, int argc, char **argv, sqlite3_vtab **ppVtab ){ - appendToEchoModule((Tcl_Interp *)(pModule->pAux), "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 00937c276..fc474bb70 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 6f94e2ce1..2f6062776 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" @@ -235,6 +235,49 @@ void sqlite3VtabArgExtend(Parse *pParse, Token *p){ } /* +** 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 ** and an error left in pParse. @@ -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 @@ -326,61 +392,6 @@ int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){ } /* -** 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 ** when a DROP TABLE is mentioned. |