1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

Add pzErr parameters to the xConnect and xCreate methods of virtual tables

in order to provide better error reporting.  This is an interface change
for virtual tables.  Prior virtual table implementations will need to be
modified and recompiled. (CVS 3402)

FossilOrigin-Name: f44b8bae97b6872524580009c96d07391578c388
This commit is contained in:
drh
2006-09-10 17:31:58 +00:00
parent fe1368ee08
commit 4ca8aac2b4
8 changed files with 45 additions and 44 deletions

View File

@@ -1109,14 +1109,14 @@ static void fulltext_vtab_destroy(fulltext_vtab *v){
** argv[4..] - passed to tokenizer (optional based on tokenizer) ** argv[4..] - passed to tokenizer (optional based on tokenizer)
**/ **/
static int fulltextConnect(sqlite3 *db, void *pAux, int argc, char **argv, static int fulltextConnect(sqlite3 *db, void *pAux, int argc, char **argv,
sqlite3_vtab **ppVTab){ sqlite3_vtab **ppVTab, char **pzErr){
int rc; int rc;
fulltext_vtab *v; fulltext_vtab *v;
const sqlite3_tokenizer_module *m = NULL; const sqlite3_tokenizer_module *m = NULL;
assert( argc>=3 ); assert( argc>=3 );
v = (fulltext_vtab *) malloc(sizeof(fulltext_vtab)); v = (fulltext_vtab *) malloc(sizeof(fulltext_vtab));
/* sqlite will initialize v->base */ memset(v, 0, sizeof(*v));
v->db = db; v->db = db;
v->zName = string_dup(argv[2]); v->zName = string_dup(argv[2]);
v->pTokenizer = NULL; v->pTokenizer = NULL;
@@ -1128,6 +1128,7 @@ static int fulltextConnect(sqlite3 *db, void *pAux, int argc, char **argv,
if( !strcmp(argv[3], "simple") ){ if( !strcmp(argv[3], "simple") ){
sqlite3Fts1SimpleTokenizerModule(&m); sqlite3Fts1SimpleTokenizerModule(&m);
} else { } else {
*pzErr = sqlite3_mprintf("unknown tokenizer: %s", argv[3]);
assert( "unrecognized tokenizer"==NULL ); assert( "unrecognized tokenizer"==NULL );
} }
} }
@@ -1156,7 +1157,7 @@ static int fulltextConnect(sqlite3 *db, void *pAux, int argc, char **argv,
} }
static int fulltextCreate(sqlite3 *db, void *pAux, int argc, char **argv, static int fulltextCreate(sqlite3 *db, void *pAux, int argc, char **argv,
sqlite3_vtab **ppVTab){ sqlite3_vtab **ppVTab, char **pzErr){
int rc; int rc;
assert( argc>=3 ); assert( argc>=3 );
TRACE(("FTS1 Create\n")); TRACE(("FTS1 Create\n"));
@@ -1202,7 +1203,7 @@ static int fulltextCreate(sqlite3 *db, void *pAux, int argc, char **argv,
"primary key(term, segment));"); "primary key(term, segment));");
if( rc!=SQLITE_OK ) return rc; if( rc!=SQLITE_OK ) return rc;
return fulltextConnect(db, pAux, argc, argv, ppVTab); return fulltextConnect(db, pAux, argc, argv, ppVTab, pzErr);
} }
/* Decide how to handle an SQL query. /* Decide how to handle an SQL query.

View File

@@ -1,5 +1,5 @@
C Add\sa\snew\szErrMsg\sfield\sto\sthe\ssqlite3_vtab\sstructure\sto\ssupport\sreturning\nerror\smessages\sfrom\svirtual\stable\sconstructors.\s\sThis\schange\smeans\sthat\nvirtual\stable\simplementations\scompiled\sas\sloadable\sextensions\sfor\sversion\n3.3.7\swill\sneed\sto\sbe\srecompile\sfor\sversion\s3.3.8\sand\swill\snot\sbe\susable\nby\sboth\sversions\sat\sone.\s\sThe\svirtual\stable\smechanism\sis\sstill\sconsidered\nexperimental\sso\swe\sfeel\sjustified\sin\sbreaking\sbackwards\scompatibility\nin\sthis\sway.\s\sAdditional\sinterface\schanges\smight\soccurs\sin\sthe\sfuture.\s(CVS\s3401) C Add\spzErr\sparameters\sto\sthe\sxConnect\sand\sxCreate\smethods\sof\svirtual\stables\nin\sorder\sto\sprovide\sbetter\serror\sreporting.\s\sThis\sis\san\sinterface\schange\nfor\svirtual\stables.\s\sPrior\svirtual\stable\simplementations\swill\sneed\sto\sbe\nmodified\sand\srecompiled.\s(CVS\s3402)
D 2006-09-10T17:08:30 D 2006-09-10T17:31:59
F Makefile.in cabd42d34340f49260bc2a7668c38eba8d4cfd99 F Makefile.in cabd42d34340f49260bc2a7668c38eba8d4cfd99
F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935 F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -21,7 +21,7 @@ F ext/README.txt 913a7bd3f4837ab14d7e063304181787658b14e1
F ext/fts1/README.txt 20ac73b006a70bcfd80069bdaf59214b6cf1db5e F ext/fts1/README.txt 20ac73b006a70bcfd80069bdaf59214b6cf1db5e
F ext/fts1/ft_hash.c 3927bd880e65329bdc6f506555b228b28924921b F ext/fts1/ft_hash.c 3927bd880e65329bdc6f506555b228b28924921b
F ext/fts1/ft_hash.h 1a35e654a235c2c662d3ca0dfc3138ad60b8b7d5 F ext/fts1/ft_hash.h 1a35e654a235c2c662d3ca0dfc3138ad60b8b7d5
F ext/fts1/fts1.c 36a33f0dae9b7106737d550e42a8e3974614dc5a F ext/fts1/fts1.c a0f9600c5d3fedaf0002247b554c0570c431bf9e
F ext/fts1/fts1.h fe8e8f38dd6d2d2645b9b0d6972e80985249575f F ext/fts1/fts1.h fe8e8f38dd6d2d2645b9b0d6972e80985249575f
F ext/fts1/fts1_hash.c 3196cee866edbebb1c0521e21672e6d599965114 F ext/fts1/fts1_hash.c 3196cee866edbebb1c0521e21672e6d599965114
F ext/fts1/fts1_hash.h 957d378355ed29f672cd5add012ce8b088a5e089 F ext/fts1/fts1_hash.h 957d378355ed29f672cd5add012ce8b088a5e089
@@ -86,7 +86,7 @@ F src/random.c d40f8d356cecbd351ccfab6eaedd7ec1b54f5261
F src/select.c 0d4724930a1f34c747105ed1802fa4af0d8eb519 F src/select.c 0d4724930a1f34c747105ed1802fa4af0d8eb519
F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96 F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96
F src/shell.c 233f7766e532a204bed465249ffc584424ed1757 F src/shell.c 233f7766e532a204bed465249ffc584424ed1757
F src/sqlite.h.in 364f2aac46a3f2435ff30ccae1f34b53d667b0af F src/sqlite.h.in c76f7a4609631606f657fbe976e3bc901d39c2d3
F src/sqlite3ext.h 11a046b3519c4b9b7709e6d6a95c3a36366f684a F src/sqlite3ext.h 11a046b3519c4b9b7709e6d6a95c3a36366f684a
F src/sqliteInt.h 259adce944cc3b28da1fa3df9beb9ba86017a45d F src/sqliteInt.h 259adce944cc3b28da1fa3df9beb9ba86017a45d
F src/table.c d8817f43a6c6bf139487db161760b9e1e02da3f1 F src/table.c d8817f43a6c6bf139487db161760b9e1e02da3f1
@@ -98,14 +98,14 @@ F src/test4.c 8b784cd82de158a2317cb4ac4bc86f91ad315e25
F src/test5.c 7162f8526affb771c4ed256826eee7bb9eca265f F src/test5.c 7162f8526affb771c4ed256826eee7bb9eca265f
F src/test6.c 60a02961ceb7b3edc25f5dc5c1ac2556622a76de F src/test6.c 60a02961ceb7b3edc25f5dc5c1ac2556622a76de
F src/test7.c 03fa8d787f6aebc6d1f72504d52f33013ad2c8e3 F src/test7.c 03fa8d787f6aebc6d1f72504d52f33013ad2c8e3
F src/test8.c 56d891ac9a37d1e1e941d9da7307e8d757a7b8e1 F src/test8.c f86da05e9611275a8ea8bbd679ebe89e9dddc4f1
F src/test_async.c e3deaedd4d86a56391b81808fde9e44fbd92f1d3 F src/test_async.c e3deaedd4d86a56391b81808fde9e44fbd92f1d3
F src/test_autoext.c bbb70bc1c83bd273cf59908ca9b486ae5df55a59 F src/test_autoext.c bbb70bc1c83bd273cf59908ca9b486ae5df55a59
F src/test_loadext.c 22065d601a18878e5542191001f0eaa5d77c0ed8 F src/test_loadext.c 22065d601a18878e5542191001f0eaa5d77c0ed8
F src/test_md5.c 6c42bc0a3c0b54be34623ff77a0eec32b2fa96e3 F src/test_md5.c 6c42bc0a3c0b54be34623ff77a0eec32b2fa96e3
F src/test_schema.c 8b2aaa9136edf3187a51166849c2de0aaaa27ce5 F src/test_schema.c 01a3bdd6005bffe6212468bf8e232fe31086d235
F src/test_server.c a6460daed0b92ecbc2531b6dc73717470e7a648c F src/test_server.c a6460daed0b92ecbc2531b6dc73717470e7a648c
F src/test_tclvar.c ea90da5ad6f25bbf908f309b9c3256bf3766d441 F src/test_tclvar.c be4e54ce56d612a90907e5190d8142875cdc778c
F src/tokenize.c dfdff21768fbedd40e8d3ca84fc5d0d7af2b46dd F src/tokenize.c dfdff21768fbedd40e8d3ca84fc5d0d7af2b46dd
F src/trigger.c 0fc40125820409a6274834a6e04ad804d96e2793 F src/trigger.c 0fc40125820409a6274834a6e04ad804d96e2793
F src/update.c 951f95ef044cf6d28557c48dc35cb0711a0b9129 F src/update.c 951f95ef044cf6d28557c48dc35cb0711a0b9129
@@ -119,7 +119,7 @@ F src/vdbeapi.c 81f531d7dc5c898131b02ef85f6c6144ab2892cf
F src/vdbeaux.c 9fab61427a0741c9c123e8ff16e349b1f90397be F src/vdbeaux.c 9fab61427a0741c9c123e8ff16e349b1f90397be
F src/vdbefifo.c 9efb94c8c3f4c979ebd0028219483f88e57584f5 F src/vdbefifo.c 9efb94c8c3f4c979ebd0028219483f88e57584f5
F src/vdbemem.c 26623176bf1c616aa478da958fac49502491a921 F src/vdbemem.c 26623176bf1c616aa478da958fac49502491a921
F src/vtab.c c68946eda1e9259582836d3fec39272fd3647b4d F src/vtab.c 430513b5e2b3cfe72f960be2d1dff41ce8ac0f9d
F src/where.c 75a89957fcb8c068bec55caa4e9d2ed5fa0b0724 F src/where.c 75a89957fcb8c068bec55caa4e9d2ed5fa0b0724
F tclinstaller.tcl 046e3624671962dc50f0481d7c25b38ef803eb42 F tclinstaller.tcl 046e3624671962dc50f0481d7c25b38ef803eb42
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
@@ -397,7 +397,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513 F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
P 70bcff024b44d1b40afac6eba959fa89fb993147 P 36693a5cb72b4363010f9ab0866e1f7865f65275
R 49ee6571b74bcd7a8b8e06a293fd1796 R bc62906dea603a74fb4a9c89628cc681
U drh U drh
Z e7e707b3d9d576052a0534936bdcea9b Z c46929b76e373fecb1fd2b6b3f4e1308

View File

@@ -1 +1 @@
36693a5cb72b4363010f9ab0866e1f7865f65275 f44b8bae97b6872524580009c96d07391578c388

View File

@@ -12,7 +12,7 @@
** This header file defines the interface that the SQLite library ** This header file defines the interface that the SQLite library
** presents to client programs. ** presents to client programs.
** **
** @(#) $Id: sqlite.h.in,v 1.190 2006/09/10 17:08:30 drh Exp $ ** @(#) $Id: sqlite.h.in,v 1.191 2006/09/10 17:31:59 drh Exp $
*/ */
#ifndef _SQLITE3_H_ #ifndef _SQLITE3_H_
#define _SQLITE3_H_ #define _SQLITE3_H_
@@ -1582,10 +1582,10 @@ struct sqlite3_module {
int iVersion; int iVersion;
int (*xCreate)(sqlite3*, void *pAux, int (*xCreate)(sqlite3*, void *pAux,
int argc, char **argv, int argc, char **argv,
sqlite3_vtab **ppVTab); sqlite3_vtab **ppVTab, char**);
int (*xConnect)(sqlite3*, void *pAux, int (*xConnect)(sqlite3*, void *pAux,
int argc, char **argv, int argc, char **argv,
sqlite3_vtab **ppVTab); sqlite3_vtab **ppVTab, char**);
int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*); int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*);
int (*xDisconnect)(sqlite3_vtab *pVTab); int (*xDisconnect)(sqlite3_vtab *pVTab);
int (*xDestroy)(sqlite3_vtab *pVTab); int (*xDestroy)(sqlite3_vtab *pVTab);
@@ -1719,7 +1719,7 @@ int sqlite3_create_module(
struct sqlite3_vtab { struct sqlite3_vtab {
const sqlite3_module *pModule; /* The module for this virtual table */ const sqlite3_module *pModule; /* The module for this virtual table */
int nRef; /* Used internally */ int nRef; /* Used internally */
char *zErrMsg; /* Error message text */ char *zErrMsg; /* Error message from sqlite3_mprintf() */
/* Virtual table implementations will typically add additional fields */ /* Virtual table implementations will typically add additional fields */
}; };

View File

@@ -13,7 +13,7 @@
** is not included in the SQLite library. It is used for automated ** is not included in the SQLite library. It is used for automated
** testing of the SQLite library. ** testing of the SQLite library.
** **
** $Id: test8.c,v 1.40 2006/07/08 18:09:15 drh Exp $ ** $Id: test8.c,v 1.41 2006/09/10 17:32:00 drh Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include "tcl.h" #include "tcl.h"
@@ -312,7 +312,8 @@ static int echoConstructor(
sqlite3 *db, sqlite3 *db,
void *pAux, void *pAux,
int argc, char **argv, int argc, char **argv,
sqlite3_vtab **ppVtab sqlite3_vtab **ppVtab,
char **pzErr
){ ){
int i; int i;
echo_vtab *pVtab; echo_vtab *pVtab;
@@ -358,11 +359,12 @@ static int echoCreate(
sqlite3 *db, sqlite3 *db,
void *pAux, void *pAux,
int argc, char **argv, int argc, char **argv,
sqlite3_vtab **ppVtab sqlite3_vtab **ppVtab,
char **pzErr
){ ){
int rc = SQLITE_OK; int rc = SQLITE_OK;
appendToEchoModule((Tcl_Interp *)(pAux), "xCreate"); appendToEchoModule((Tcl_Interp *)(pAux), "xCreate");
rc = echoConstructor(db, pAux, argc, argv, ppVtab); rc = echoConstructor(db, pAux, argc, argv, ppVtab, pzErr);
/* If there were two arguments passed to the module at the SQL level /* If there were two arguments passed to the module at the SQL level
** (i.e. "CREATE VIRTUAL TABLE tbl USING echo(arg1, arg2)"), then ** (i.e. "CREATE VIRTUAL TABLE tbl USING echo(arg1, arg2)"), then
@@ -393,10 +395,11 @@ static int echoConnect(
sqlite3 *db, sqlite3 *db,
void *pAux, void *pAux,
int argc, char **argv, int argc, char **argv,
sqlite3_vtab **ppVtab sqlite3_vtab **ppVtab,
char **pzErr
){ ){
appendToEchoModule((Tcl_Interp *)(pAux), "xConnect"); appendToEchoModule((Tcl_Interp *)(pAux), "xConnect");
return echoConstructor(db, pAux, argc, argv, ppVtab); return echoConstructor(db, pAux, argc, argv, ppVtab, pzErr);
} }
/* /*

View File

@@ -13,7 +13,7 @@
** is not included in the SQLite library. It is used for automated ** is not included in the SQLite library. It is used for automated
** testing of the SQLite library. ** testing of the SQLite library.
** **
** $Id: test_schema.c,v 1.9 2006/07/08 17:06:44 drh Exp $ ** $Id: test_schema.c,v 1.10 2006/09/10 17:32:00 drh Exp $
*/ */
/* The code in this file defines a sqlite3 virtual-table module that /* The code in this file defines a sqlite3 virtual-table module that
@@ -85,7 +85,8 @@ static int schemaCreate(
sqlite3 *db, sqlite3 *db,
void *pAux, void *pAux,
int argc, char **argv, int argc, char **argv,
sqlite3_vtab **ppVtab sqlite3_vtab **ppVtab,
char **pzErr
){ ){
int rc = SQLITE_NOMEM; int rc = SQLITE_NOMEM;
schema_vtab *pVtab = MALLOC(sizeof(schema_vtab)); schema_vtab *pVtab = MALLOC(sizeof(schema_vtab));

View File

@@ -16,7 +16,7 @@
** The emphasis of this file is a virtual table that provides ** The emphasis of this file is a virtual table that provides
** access to TCL variables. ** access to TCL variables.
** **
** $Id: test_tclvar.c,v 1.8 2006/08/15 14:21:16 drh Exp $ ** $Id: test_tclvar.c,v 1.9 2006/09/10 17:32:00 drh Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include "tcl.h" #include "tcl.h"
@@ -52,7 +52,8 @@ static int tclvarConnect(
sqlite3 *db, sqlite3 *db,
void *pAux, void *pAux,
int argc, char **argv, int argc, char **argv,
sqlite3_vtab **ppVtab sqlite3_vtab **ppVtab,
char **pzErr
){ ){
tclvar_vtab *pVtab; tclvar_vtab *pVtab;
static const char zSchema[] = static const char zSchema[] =

View File

@@ -11,7 +11,7 @@
************************************************************************* *************************************************************************
** This file contains code used to help implement virtual tables. ** This file contains code used to help implement virtual tables.
** **
** $Id: vtab.c,v 1.32 2006/09/10 17:08:30 drh Exp $ ** $Id: vtab.c,v 1.33 2006/09/10 17:32:00 drh Exp $
*/ */
#ifndef SQLITE_OMIT_VIRTUALTABLE #ifndef SQLITE_OMIT_VIRTUALTABLE
#include "sqliteInt.h" #include "sqliteInt.h"
@@ -59,8 +59,6 @@ void sqlite3VtabLock(sqlite3_vtab *pVtab){
void sqlite3VtabUnlock(sqlite3_vtab *pVtab){ void sqlite3VtabUnlock(sqlite3_vtab *pVtab){
pVtab->nRef--; pVtab->nRef--;
if( pVtab->nRef==0 ){ if( pVtab->nRef==0 ){
sqlite3_free(pVtab->zErrMsg);
pVtab->zErrMsg = 0;
pVtab->pModule->xDisconnect(pVtab); pVtab->pModule->xDisconnect(pVtab);
} }
} }
@@ -288,7 +286,7 @@ static int vtabCallConstructor(
sqlite3 *db, sqlite3 *db,
Table *pTab, Table *pTab,
Module *pMod, Module *pMod,
int (*xConstruct)(sqlite3*, void *, int, char **, sqlite3_vtab **), int (*xConstruct)(sqlite3*,void*,int,char**,sqlite3_vtab**,char**),
char **pzErr char **pzErr
){ ){
int rc; int rc;
@@ -296,7 +294,7 @@ static int vtabCallConstructor(
sqlite3_vtab *pVtab; sqlite3_vtab *pVtab;
char **azArg = pTab->azModuleArg; char **azArg = pTab->azModuleArg;
int nArg = pTab->nModuleArg; int nArg = pTab->nModuleArg;
char *zErr = sqlite3MPrintf("vtable constructor failed: %s", pTab->zName); char *zErr = 0;
assert( !db->pVTab ); assert( !db->pVTab );
assert( xConstruct ); assert( xConstruct );
@@ -304,7 +302,7 @@ static int vtabCallConstructor(
db->pVTab = pTab; db->pVTab = pTab;
rc = sqlite3SafetyOff(db); rc = sqlite3SafetyOff(db);
assert( rc==SQLITE_OK ); assert( rc==SQLITE_OK );
rc = xConstruct(db, pMod->pAux, nArg, azArg, &pTab->pVtab); rc = xConstruct(db, pMod->pAux, nArg, azArg, &pTab->pVtab, &zErr);
rc2 = sqlite3SafetyOn(db); rc2 = sqlite3SafetyOn(db);
pVtab = pTab->pVtab; pVtab = pTab->pVtab;
if( rc==SQLITE_OK && pVtab ){ if( rc==SQLITE_OK && pVtab ){
@@ -313,13 +311,11 @@ static int vtabCallConstructor(
} }
if( SQLITE_OK!=rc ){ if( SQLITE_OK!=rc ){
if( pVtab && pVtab->zErrMsg ){ if( zErr==0 ){
*pzErr = sqlite3MPrintf("%s", pVtab->zErrMsg); *pzErr = sqlite3MPrintf("vtable constructor failed: %s", pTab->zName);
sqlite3_free(pVtab->zErrMsg); }else {
pVtab->zErrMsg = 0; *pzErr = sqlite3_mprintf("%s", zErr);
}else{ sqlite3_free(zErr);
*pzErr = zErr;
zErr = 0;
} }
}else if( db->pVTab ){ }else if( db->pVTab ){
const char *zFormat = "vtable constructor did not declare schema: %s"; const char *zFormat = "vtable constructor did not declare schema: %s";
@@ -330,7 +326,6 @@ static int vtabCallConstructor(
rc = rc2; rc = rc2;
} }
db->pVTab = 0; db->pVTab = 0;
sqliteFree(zErr);
return rc; return rc;
} }