]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add pzErr parameters to the xConnect and xCreate methods of virtual tables
authordrh <drh@noemail.net>
Sun, 10 Sep 2006 17:31:58 +0000 (17:31 +0000)
committerdrh <drh@noemail.net>
Sun, 10 Sep 2006 17:31:58 +0000 (17:31 +0000)
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

ext/fts1/fts1.c
manifest
manifest.uuid
src/sqlite.h.in
src/test8.c
src/test_schema.c
src/test_tclvar.c
src/vtab.c

index 0c973a6dd1191b6f7fcd473555a06dedd115f4ee..108070532d29f6ee5b892a21ab85ae07e47c5f7a 100644 (file)
@@ -1109,14 +1109,14 @@ static void fulltext_vtab_destroy(fulltext_vtab *v){
 ** argv[4..] - passed to tokenizer (optional based on tokenizer)
 **/
 static int fulltextConnect(sqlite3 *db, void *pAux, int argc, char **argv,
-                           sqlite3_vtab **ppVTab){
+                           sqlite3_vtab **ppVTab, char **pzErr){
   int rc;
   fulltext_vtab *v;
   const sqlite3_tokenizer_module *m = NULL;
 
   assert( argc>=3 );
   v = (fulltext_vtab *) malloc(sizeof(fulltext_vtab));
-  /* sqlite will initialize v->base */
+  memset(v, 0, sizeof(*v));
   v->db = db;
   v->zName = string_dup(argv[2]);
   v->pTokenizer = NULL;
@@ -1128,6 +1128,7 @@ static int fulltextConnect(sqlite3 *db, void *pAux, int argc, char **argv,
     if( !strcmp(argv[3], "simple") ){
       sqlite3Fts1SimpleTokenizerModule(&m);
     } else {
+      *pzErr = sqlite3_mprintf("unknown tokenizer: %s", argv[3]);
       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,
-                          sqlite3_vtab **ppVTab){
+                          sqlite3_vtab **ppVTab, char **pzErr){
   int rc;
   assert( argc>=3 );
   TRACE(("FTS1 Create\n"));
@@ -1202,7 +1203,7 @@ static int fulltextCreate(sqlite3 *db, void *pAux, int argc, char **argv,
                         "primary key(term, segment));");
   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.
index c241e31be5c7f2a605c593f59bb6781f627e35fe..27789bd88e161d2ae81a457625a9243d31d58619 100644 (file)
--- a/manifest
+++ b/manifest
@@ -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)
-D 2006-09-10T17:08:30
+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:31:59
 F Makefile.in cabd42d34340f49260bc2a7668c38eba8d4cfd99
 F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935
 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -21,7 +21,7 @@ F ext/README.txt 913a7bd3f4837ab14d7e063304181787658b14e1
 F ext/fts1/README.txt 20ac73b006a70bcfd80069bdaf59214b6cf1db5e
 F ext/fts1/ft_hash.c 3927bd880e65329bdc6f506555b228b28924921b
 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_hash.c 3196cee866edbebb1c0521e21672e6d599965114
 F ext/fts1/fts1_hash.h 957d378355ed29f672cd5add012ce8b088a5e089
@@ -86,7 +86,7 @@ F src/random.c d40f8d356cecbd351ccfab6eaedd7ec1b54f5261
 F src/select.c 0d4724930a1f34c747105ed1802fa4af0d8eb519
 F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96
 F src/shell.c 233f7766e532a204bed465249ffc584424ed1757
-F src/sqlite.h.in 364f2aac46a3f2435ff30ccae1f34b53d667b0af
+F src/sqlite.h.in c76f7a4609631606f657fbe976e3bc901d39c2d3
 F src/sqlite3ext.h 11a046b3519c4b9b7709e6d6a95c3a36366f684a
 F src/sqliteInt.h 259adce944cc3b28da1fa3df9beb9ba86017a45d
 F src/table.c d8817f43a6c6bf139487db161760b9e1e02da3f1
@@ -98,14 +98,14 @@ F src/test4.c 8b784cd82de158a2317cb4ac4bc86f91ad315e25
 F src/test5.c 7162f8526affb771c4ed256826eee7bb9eca265f
 F src/test6.c 60a02961ceb7b3edc25f5dc5c1ac2556622a76de
 F src/test7.c 03fa8d787f6aebc6d1f72504d52f33013ad2c8e3
-F src/test8.c 56d891ac9a37d1e1e941d9da7307e8d757a7b8e1
+F src/test8.c f86da05e9611275a8ea8bbd679ebe89e9dddc4f1
 F src/test_async.c e3deaedd4d86a56391b81808fde9e44fbd92f1d3
 F src/test_autoext.c bbb70bc1c83bd273cf59908ca9b486ae5df55a59
 F src/test_loadext.c 22065d601a18878e5542191001f0eaa5d77c0ed8
 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_tclvar.c ea90da5ad6f25bbf908f309b9c3256bf3766d441
+F src/test_tclvar.c be4e54ce56d612a90907e5190d8142875cdc778c
 F src/tokenize.c dfdff21768fbedd40e8d3ca84fc5d0d7af2b46dd
 F src/trigger.c 0fc40125820409a6274834a6e04ad804d96e2793
 F src/update.c 951f95ef044cf6d28557c48dc35cb0711a0b9129
@@ -119,7 +119,7 @@ F src/vdbeapi.c 81f531d7dc5c898131b02ef85f6c6144ab2892cf
 F src/vdbeaux.c 9fab61427a0741c9c123e8ff16e349b1f90397be
 F src/vdbefifo.c 9efb94c8c3f4c979ebd0028219483f88e57584f5
 F src/vdbemem.c 26623176bf1c616aa478da958fac49502491a921
-F src/vtab.c c68946eda1e9259582836d3fec39272fd3647b4d
+F src/vtab.c 430513b5e2b3cfe72f960be2d1dff41ce8ac0f9d
 F src/where.c 75a89957fcb8c068bec55caa4e9d2ed5fa0b0724
 F tclinstaller.tcl 046e3624671962dc50f0481d7c25b38ef803eb42
 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
@@ -397,7 +397,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
 F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
-P 70bcff024b44d1b40afac6eba959fa89fb993147
-R 49ee6571b74bcd7a8b8e06a293fd1796
+P 36693a5cb72b4363010f9ab0866e1f7865f65275
+R bc62906dea603a74fb4a9c89628cc681
 U drh
-Z e7e707b3d9d576052a0534936bdcea9b
+Z c46929b76e373fecb1fd2b6b3f4e1308
index 948d54bf706f054bd99b65c6a8dfb887781599f9..4e6139234621186e3bb1d657ea52559379d81751 100644 (file)
@@ -1 +1 @@
-36693a5cb72b4363010f9ab0866e1f7865f65275
\ No newline at end of file
+f44b8bae97b6872524580009c96d07391578c388
\ No newline at end of file
index 1d559db5ac2e5bfc8025e1177274a41e67e4556c..4b53818d7568ee99747f88b970d3640f52cb8d96 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.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_
 #define _SQLITE3_H_
@@ -1582,10 +1582,10 @@ struct sqlite3_module {
   int iVersion;
   int (*xCreate)(sqlite3*, void *pAux,
                int argc, char **argv,
-               sqlite3_vtab **ppVTab);
+               sqlite3_vtab **ppVTab, char**);
   int (*xConnect)(sqlite3*, void *pAux,
                int argc, char **argv,
-               sqlite3_vtab **ppVTab);
+               sqlite3_vtab **ppVTab, char**);
   int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*);
   int (*xDisconnect)(sqlite3_vtab *pVTab);
   int (*xDestroy)(sqlite3_vtab *pVTab);
@@ -1719,7 +1719,7 @@ int sqlite3_create_module(
 struct sqlite3_vtab {
   const sqlite3_module *pModule;  /* The module for this virtual table */
   int nRef;                       /* Used internally */
-  char *zErrMsg;                  /* Error message text */
+  char *zErrMsg;                  /* Error message from sqlite3_mprintf() */
   /* Virtual table implementations will typically add additional fields */
 };
 
index 3a639d9e351c9185cfb06bc022ecaecab543b499..176e9efd277f52d798a91d33316f2dd7c0324b2b 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.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 "tcl.h"
@@ -312,7 +312,8 @@ static int echoConstructor(
   sqlite3 *db,
   void *pAux,
   int argc, char **argv,
-  sqlite3_vtab **ppVtab
+  sqlite3_vtab **ppVtab,
+  char **pzErr
 ){
   int i;
   echo_vtab *pVtab;
@@ -358,11 +359,12 @@ static int echoCreate(
   sqlite3 *db,
   void *pAux,
   int argc, char **argv,
-  sqlite3_vtab **ppVtab
+  sqlite3_vtab **ppVtab,
+  char **pzErr
 ){
   int rc = SQLITE_OK;
   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 
   ** (i.e. "CREATE VIRTUAL TABLE tbl USING echo(arg1, arg2)"), then 
@@ -393,10 +395,11 @@ static int echoConnect(
   sqlite3 *db,
   void *pAux,
   int argc, char **argv,
-  sqlite3_vtab **ppVtab
+  sqlite3_vtab **ppVtab,
+  char **pzErr
 ){
   appendToEchoModule((Tcl_Interp *)(pAux), "xConnect");
-  return echoConstructor(db, pAux, argc, argv, ppVtab);
+  return echoConstructor(db, pAux, argc, argv, ppVtab, pzErr);
 }
 
 /* 
index bd9083987a2f6820e736c8ada0b4ac4d826de409..a4df801cc81833f6148876bd7dea868052c8b9fa 100644 (file)
@@ -13,7 +13,7 @@
 ** is not included in the SQLite library.  It is used for automated
 ** 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
@@ -85,7 +85,8 @@ static int schemaCreate(
   sqlite3 *db,
   void *pAux,
   int argc, char **argv,
-  sqlite3_vtab **ppVtab
+  sqlite3_vtab **ppVtab,
+  char **pzErr
 ){
   int rc = SQLITE_NOMEM;
   schema_vtab *pVtab = MALLOC(sizeof(schema_vtab));
index 9d3024862516598c2c74851643999fc56561b8f8..5ccb12d4bcc765afea53a3c95d32940cc7b9b79d 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.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 "tcl.h"
@@ -52,7 +52,8 @@ static int tclvarConnect(
   sqlite3 *db,
   void *pAux,
   int argc, char **argv,
-  sqlite3_vtab **ppVtab
+  sqlite3_vtab **ppVtab,
+  char **pzErr
 ){
   tclvar_vtab *pVtab;
   static const char zSchema[] = 
index bb4634a46a2ce70e2047f652cd965a27ed053371..9ac8e599a782f855fece1585cda4e23915b030ae 100644 (file)
@@ -11,7 +11,7 @@
 *************************************************************************
 ** 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
 #include "sqliteInt.h"
@@ -59,8 +59,6 @@ void sqlite3VtabLock(sqlite3_vtab *pVtab){
 void sqlite3VtabUnlock(sqlite3_vtab *pVtab){
   pVtab->nRef--;
   if( pVtab->nRef==0 ){
-    sqlite3_free(pVtab->zErrMsg);
-    pVtab->zErrMsg = 0;
     pVtab->pModule->xDisconnect(pVtab);
   }
 }
@@ -288,7 +286,7 @@ static int vtabCallConstructor(
   sqlite3 *db, 
   Table *pTab,
   Module *pMod,
-  int (*xConstruct)(sqlite3*, void *, int, char **, sqlite3_vtab **),
+  int (*xConstruct)(sqlite3*,void*,int,char**,sqlite3_vtab**,char**),
   char **pzErr
 ){
   int rc;
@@ -296,7 +294,7 @@ static int vtabCallConstructor(
   sqlite3_vtab *pVtab;
   char **azArg = pTab->azModuleArg;
   int nArg = pTab->nModuleArg;
-  char *zErr = sqlite3MPrintf("vtable constructor failed: %s", pTab->zName);
+  char *zErr = 0;
 
   assert( !db->pVTab );
   assert( xConstruct );
@@ -304,7 +302,7 @@ static int vtabCallConstructor(
   db->pVTab = pTab;
   rc = sqlite3SafetyOff(db);
   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);
   pVtab = pTab->pVtab;
   if( rc==SQLITE_OK && pVtab ){
@@ -313,13 +311,11 @@ static int vtabCallConstructor(
   }
 
   if( SQLITE_OK!=rc ){
-    if( pVtab && pVtab->zErrMsg ){
-      *pzErr = sqlite3MPrintf("%s", pVtab->zErrMsg);
-      sqlite3_free(pVtab->zErrMsg);
-      pVtab->zErrMsg = 0;
-    }else{
-      *pzErr = zErr;
-      zErr = 0;
+    if( zErr==0 ){
+      *pzErr = sqlite3MPrintf("vtable constructor failed: %s", pTab->zName);
+    }else {
+      *pzErr = sqlite3_mprintf("%s", zErr);
+      sqlite3_free(zErr);
     }
   }else if( db->pVTab ){
     const char *zFormat = "vtable constructor did not declare schema: %s";
@@ -330,7 +326,6 @@ static int vtabCallConstructor(
     rc = rc2;
   }
   db->pVTab = 0;
-  sqliteFree(zErr);
   return rc;
 }