-C Test\scases\sfor\ssqlite3_db_config()\sand\ssqlite3_db_status().\s(CVS\s5518)
-D 2008-08-01T16:31:14
+C Test\sthat\svirtual\stable\smethods\sxBestIndex,\sxOpen,\sxFilter,\sxNext,\sxColumn,\sxRowid,\sxUpdate,\sxSync\sand\sxBegin\scan\sall\sreturn\serror\smessages\susing\sthe\ssqlite3_vtab.zErrMsg\svariable.\s(CVS\s5519)
+D 2008-08-01T17:37:41
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in bbb62eecc851379aef5a48a1bf8787eb13e6ec06
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
F src/shell.c 4b835fe734304ac22a3385868cd3790c1e4f7aa1
F src/sqlite.h.in 30af3a002a0b672aaae8f4a5deb0a2e9a4b699af
F src/sqlite3ext.h 1e3887c9bd3ae66cb599e922824b04cd0d0f2c3e
-F src/sqliteInt.h 99a49b2d85b7648fbb2f7933b145dfb5b11d8941
+F src/sqliteInt.h 80fa4a46024dee8cb6c66a6f04a716c253d98165
F src/sqliteLimit.h f435e728c6b620ef7312814d660a81f9356eb5c8
F src/status.c 8ad1f215934c5f5afb91df86e44dccff7ef3c1d0
F src/table.c 22744786199c9195720c15a7a42cb97b2e2728d8
F src/test5.c 847eb5cfe89c197b6b494858ccf60be981235bdf
F src/test6.c 0a0304a69cfa4962a429d084c6d451ff9e4fb572
F src/test7.c 475b1fa7e3275408b40a3cbdc9508cbdc41ffa02
-F src/test8.c ae09a70c009097561d0d21e0291d383ad059d3f8
+F src/test8.c f869497d3f6e8a7566e9b7116dce7ada49ee1183
F src/test9.c 904ebe0ed1472d6bad17a81e2ecbfc20017dc237
F src/test_async.c da9f58f49faccd3a26ba89f58de125862351b6e2
F src/test_autoext.c f53b0cdf7bf5f08100009572a5d65cdb540bd0ad
F src/utf.c a7004436a6ef2aee012ace93de274dd0f3c7624e
F src/util.c afe659ccc05d1f8af9e8631dabfec3ee3a7144af
F src/vacuum.c ef342828002debc97514617af3424aea8ef8522c
-F src/vdbe.c caa169475973e56a87eb90477928d84f3daa14b8
+F src/vdbe.c 90296a45d28939fd631c05c235dab7e123f94f57
F src/vdbe.h c46155c221418bea29ee3a749d5950fcf85a70e2
F src/vdbeInt.h ab27f964458fd070c6660f80694ab85d56d5f4c5
F src/vdbeapi.c 25dd01c8b12978c14ec30e9a50666b23da767b27
-F src/vdbeaux.c dbd2756c203d8c45281dd2f33a9f4741b5f81047
+F src/vdbeaux.c 78c9d6413b8720edfe5b2a40a14850d21b0079b7
F src/vdbeblob.c f93110888ddc246215e9ba1f831d3d375bfd8355
F src/vdbefifo.c 20fda2a7c4c0bcee1b90eb7e545fefcdbf2e1de7
F src/vdbemem.c bdf92746583b0187655d736c4a20a2622eb9ab69
-F src/vtab.c 691813795f1bba5df57389c1cec62f9e73eebd9d
-F src/where.c ee4878e42ac97e2b3389b44cee34b35458321488
+F src/vtab.c 914db4c9435c61a522e3cdaf103dac163d38aa30
+F src/where.c a800184a2d023b15d6f2758b7a6c7ab011258fee
F tclinstaller.tcl 4356d9d94d2b5ed5e68f9f0c80c4df3048dd7617
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
F test/all.test 89e09ed0074083ac6f208dc3243429e8f89efb69
F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102
F test/veryquick.test e265401afefa994cdf2fe4b6f286b1e87c2f9b9d
F test/view.test 5799906511d6c77cfe3516d3d1189224350ef732
-F test/vtab1.test 905a1aedad6e7307aea29f00d87b255b04994777
+F test/vtab1.test 2108cfb3ff72cb0f46363589d3c4746c04723368
F test/vtab2.test 1da49b015582965a8fc386aa23d051a5a622b08e
F test/vtab3.test baad99fd27217f5d6db10660522e0b7192446de1
F test/vtab4.test 942f8b8280b3ea8a41dae20e7822d065ca1cb275
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
-P 3f70e03ae83d374f5f69770bd7a4b279584f7090
-R 21a8914e4d9d6622f109fe97eb26a591
-U drh
-Z 0e954aa8108084642ae7fe8343f84356
+P 6a6b94302acdfe6404b04bff1cc8d16c1ef69df9
+R 5672f7054494561346fae0939e873dda
+U danielk1977
+Z bf74e8d5f26a63b2617162677c14612e
-6a6b94302acdfe6404b04bff1cc8d16c1ef69df9
\ No newline at end of file
+007359b770f225877880b11f4c5d97bb548e38ca
\ No newline at end of file
*************************************************************************
** Internal interface definitions for SQLite.
**
-** @(#) $Id: sqliteInt.h,v 1.748 2008/07/31 17:35:45 drh Exp $
+** @(#) $Id: sqliteInt.h,v 1.749 2008/08/01 17:37:41 danielk1977 Exp $
*/
#ifndef _SQLITEINT_H_
#define _SQLITEINT_H_
# define sqlite3VtabTransferError(A,B,C)
#else
void sqlite3VtabClear(Table*);
- int sqlite3VtabSync(sqlite3 *db, int rc);
+ int sqlite3VtabSync(sqlite3 *db, char **);
int sqlite3VtabRollback(sqlite3 *db);
int sqlite3VtabCommit(sqlite3 *db);
void sqlite3VtabTransferError(sqlite3 *db, int, sqlite3_vtab*);
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
-** $Id: test8.c,v 1.69 2008/07/28 19:34:54 drh Exp $
+** $Id: test8.c,v 1.70 2008/08/01 17:37:41 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
** use the named table as a backing store will fail.
*/
+/*
+** Errors can be provoked within the following echo virtual table methods:
+**
+** xBestIndex xOpen xFilter xNext
+** xColumn xRowid xUpdate xSync
+** xBegin
+**
+** This is done by setting the global tcl variable:
+**
+** echo_module_fail($method,$tbl)
+**
+** where $method is set to the name of the virtual table method to fail
+** (i.e. "xBestIndex") and $tbl is the name of the table being echoed (not
+** the name of the virtual table, the name of the underlying real table).
+*/
+
/*
** An echo virtual-table object.
**
sqlite3_stmt *pStmt;
};
+static int simulateVtabError(echo_vtab *p, const char *zMethod){
+ const char *zErr;
+ char zVarname[128];
+ zVarname[127] = '\0';
+ snprintf(zVarname, 127, "echo_module_fail(%s,%s)", zMethod, p->zTableName);
+ zErr = Tcl_GetVar(p->interp, zVarname, TCL_GLOBAL_ONLY);
+ if( zErr ){
+ p->base.zErrMsg = sqlite3_mprintf("echo-vtab-error: %s", zErr);
+ }
+ return (zErr!=0);
+}
+
/*
** Convert an SQL-style quoted string into a normal string by removing
** the quote characters. The conversion is done in-place. If the
*/
static int echoOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
echo_cursor *pCur;
+ if( simulateVtabError((echo_vtab *)pVTab, "xOpen") ){
+ return SQLITE_ERROR;
+ }
pCur = sqlite3MallocZero(sizeof(echo_cursor));
*ppCursor = (sqlite3_vtab_cursor *)pCur;
return (pCur ? SQLITE_OK : SQLITE_NOMEM);
int rc = SQLITE_OK;
echo_cursor *pCur = (echo_cursor *)cur;
+ if( simulateVtabError((echo_vtab *)(cur->pVtab), "xNext") ){
+ return SQLITE_ERROR;
+ }
+
if( pCur->pStmt ){
rc = sqlite3_step(pCur->pStmt);
if( rc==SQLITE_ROW ){
static int echoColumn(sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int i){
int iCol = i + 1;
sqlite3_stmt *pStmt = ((echo_cursor *)cur)->pStmt;
+
+ if( simulateVtabError((echo_vtab *)(cur->pVtab), "xColumn") ){
+ return SQLITE_ERROR;
+ }
+
if( !pStmt ){
sqlite3_result_null(ctx);
}else{
*/
static int echoRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
sqlite3_stmt *pStmt = ((echo_cursor *)cur)->pStmt;
+
+ if( simulateVtabError((echo_vtab *)(cur->pVtab), "xRowid") ){
+ return SQLITE_ERROR;
+ }
+
*pRowid = sqlite3_column_int64(pStmt, 0);
return SQLITE_OK;
}
echo_vtab *pVtab = (echo_vtab *)pVtabCursor->pVtab;
sqlite3 *db = pVtab->db;
+ if( simulateVtabError(pVtab, "xFilter") ){
+ return SQLITE_ERROR;
+ }
+
/* Check that idxNum matches idxStr */
assert( idxNum==hashString(idxStr) );
int rc = SQLITE_OK;
int useCost = 0;
double cost;
-
int isIgnoreUsable = 0;
if( Tcl_GetVar(interp, "echo_module_ignore_usable", TCL_GLOBAL_ONLY) ){
isIgnoreUsable = 1;
}
+ if( simulateVtabError(pVtab, "xBestIndex") ){
+ return SQLITE_ERROR;
+ }
+
/* Determine the number of rows in the table and store this value in local
** variable nRow. The 'estimated-cost' of the scan will be the number of
** rows in the table for a linear scan, or the log (base 2) of the
** making any changes to a virtual table */
assert( pVtab->inTransaction );
+ if( simulateVtabError(pVtab, "xUpdate") ){
+ return SQLITE_ERROR;
+ }
+
/* If apData[0] is an integer and nData>1 then do an UPDATE */
if( nData>1 && sqlite3_value_type(apData[0])==SQLITE_INTEGER ){
char *zSep = " SET";
** a transaction */
assert( !pVtab->inTransaction );
+ if( simulateVtabError(pVtab, "xBegin") ){
+ return SQLITE_ERROR;
+ }
+
rc = echoTransactionCall(tab, "xBegin");
if( rc==SQLITE_OK ){
** transaction */
assert( pVtab->inTransaction );
+ if( simulateVtabError(pVtab, "xSync") ){
+ return SQLITE_ERROR;
+ }
+
rc = echoTransactionCall(tab, "xSync");
if( rc==SQLITE_OK ){
** a transaction */
assert( pVtab->inTransaction );
+ if( simulateVtabError(pVtab, "xCommit") ){
+ return SQLITE_ERROR;
+ }
+
sqlite3BeginBenignMalloc();
rc = echoTransactionCall(tab, "xCommit");
sqlite3EndBenignMalloc();
** in this file for details. If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code.
**
-** $Id: vdbe.c,v 1.769 2008/07/30 13:27:11 drh Exp $
+** $Id: vdbe.c,v 1.770 2008/08/01 17:37:41 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
#ifndef SQLITE_OMIT_VIRTUALTABLE
/* Opcode: VBegin * * * P4 *
**
-** P4 a pointer to an sqlite3_vtab structure. Call the xBegin method
-** for that table.
+** P4 may be a pointer to an sqlite3_vtab structure. If so, call the
+** xBegin method for that table.
+**
+** Also, whether or not P4 is set, check that this is not being called from
+** within a callback to a virtual table xSync() method. If it is, set the
+** error code to SQLITE_LOCKED.
*/
case OP_VBegin: {
- rc = sqlite3VtabBegin(db, pOp->p4.pVtab);
+ sqlite3_vtab *pVtab = pOp->p4.pVtab;
+ rc = sqlite3VtabBegin(db, pVtab);
+ if( pVtab ){
+ sqlite3DbFree(db, p->zErrMsg);
+ p->zErrMsg = pVtab->zErrMsg;
+ pVtab->zErrMsg = 0;
+ }
break;
}
#endif /* SQLITE_OMIT_VIRTUALTABLE */
p->inVtabMethod = 1;
rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg);
p->inVtabMethod = 0;
+ sqlite3DbFree(db, p->zErrMsg);
+ p->zErrMsg = pVtab->zErrMsg;
+ pVtab->zErrMsg = 0;
if( rc==SQLITE_OK ){
res = pModule->xEof(pVtabCursor);
}
** the virtual-table that the P1 cursor is pointing to.
*/
case OP_VRowid: { /* out2-prerelease */
+ sqlite3_vtab *pVtab;
const sqlite3_module *pModule;
sqlite_int64 iRow;
Cursor *pCur = p->apCsr[pOp->p1];
if( pCur->nullRow ){
break;
}
- pModule = pCur->pVtabCursor->pVtab->pModule;
+ pVtab = pCur->pVtabCursor->pVtab;
+ pModule = pVtab->pModule;
assert( pModule->xRowid );
if( sqlite3SafetyOff(db) ) goto abort_due_to_misuse;
rc = pModule->xRowid(pCur->pVtabCursor, &iRow);
+ sqlite3DbFree(db, p->zErrMsg);
+ p->zErrMsg = pVtab->zErrMsg;
+ pVtab->zErrMsg = 0;
if( sqlite3SafetyOn(db) ) goto abort_due_to_misuse;
MemSetTypeFlag(pOut, MEM_Int);
pOut->u.i = iRow;
** P1 cursor is pointing to into register P3.
*/
case OP_VColumn: {
+ sqlite3_vtab *pVtab;
const sqlite3_module *pModule;
Mem *pDest;
sqlite3_context sContext;
sqlite3VdbeMemSetNull(pDest);
break;
}
- pModule = pCur->pVtabCursor->pVtab->pModule;
+ pVtab = pCur->pVtabCursor->pVtab;
+ pModule = pVtab->pModule;
assert( pModule->xColumn );
memset(&sContext, 0, sizeof(sContext));
if( sqlite3SafetyOff(db) ) goto abort_due_to_misuse;
rc = pModule->xColumn(pCur->pVtabCursor, &sContext, pOp->p2);
+ sqlite3DbFree(db, p->zErrMsg);
+ p->zErrMsg = pVtab->zErrMsg;
+ pVtab->zErrMsg = 0;
/* Copy the result of the function to the P3 register. We
** do this regardless of whether or not an error occured to ensure any
** the end of its result set, then fall through to the next instruction.
*/
case OP_VNext: { /* jump */
+ sqlite3_vtab *pVtab;
const sqlite3_module *pModule;
int res = 0;
if( pCur->nullRow ){
break;
}
- pModule = pCur->pVtabCursor->pVtab->pModule;
+ pVtab = pCur->pVtabCursor->pVtab;
+ pModule = pVtab->pModule;
assert( pModule->xNext );
/* Invoke the xNext() method of the module. There is no way for the
p->inVtabMethod = 1;
rc = pModule->xNext(pCur->pVtabCursor);
p->inVtabMethod = 0;
+ sqlite3DbFree(db, p->zErrMsg);
+ p->zErrMsg = pVtab->zErrMsg;
+ pVtab->zErrMsg = 0;
if( rc==SQLITE_OK ){
res = pModule->xEof(pCur->pVtabCursor);
}
** to version 2.8.7, all this code was combined into the vdbe.c source file.
** But that file was getting too big so this subroutines were split out.
**
-** $Id: vdbeaux.c,v 1.402 2008/07/31 01:43:14 shane Exp $
+** $Id: vdbeaux.c,v 1.403 2008/08/01 17:37:41 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
** write-transaction spanning more than one database file, this routine
** takes care of the master journal trickery.
*/
-static int vdbeCommit(sqlite3 *db){
+static int vdbeCommit(sqlite3 *db, Vdbe *p){
int i;
int nTrans = 0; /* Number of databases with an active write-transaction */
int rc = SQLITE_OK;
** required, as an xSync() callback may add an attached database
** to the transaction.
*/
- rc = sqlite3VtabSync(db, rc);
+ rc = sqlite3VtabSync(db, &p->zErrMsg);
if( rc!=SQLITE_OK ){
return rc;
}
** successful or hit an 'OR FAIL' constraint. This means a commit
** is required.
*/
- int rc = vdbeCommit(db);
+ int rc = vdbeCommit(db, p);
if( rc==SQLITE_BUSY ){
sqlite3BtreeMutexArrayLeave(&p->aMutex);
return SQLITE_BUSY;
*************************************************************************
** This file contains code used to help implement virtual tables.
**
-** $Id: vtab.c,v 1.72 2008/07/28 19:34:54 drh Exp $
+** $Id: vtab.c,v 1.73 2008/08/01 17:37:41 danielk1977 Exp $
*/
#ifndef SQLITE_OMIT_VIRTUALTABLE
#include "sqliteInt.h"
}
/*
-** If argument rc2 is not SQLITE_OK, then return it and do nothing.
-** Otherwise, invoke the xSync method of all virtual tables in the
-** sqlite3.aVTrans array. Return the error code for the first error
-** that occurs, or SQLITE_OK if all xSync operations are successful.
+** Invoke the xSync method of all virtual tables in the sqlite3.aVTrans
+** array. Return the error code for the first error that occurs, or
+** SQLITE_OK if all xSync operations are successful.
+**
+** Set *pzErrmsg to point to a buffer that should be released using
+** sqlite3DbFree() containing an error message, if one is available.
*/
-int sqlite3VtabSync(sqlite3 *db, int rc2){
+int sqlite3VtabSync(sqlite3 *db, char **pzErrmsg){
int i;
int rc = SQLITE_OK;
int rcsafety;
sqlite3_vtab **aVTrans = db->aVTrans;
- if( rc2!=SQLITE_OK ) return rc2;
rc = sqlite3SafetyOff(db);
db->aVTrans = 0;
x = pVtab->pModule->xSync;
if( x ){
rc = x(pVtab);
+ sqlite3DbFree(db, *pzErrmsg);
+ *pzErrmsg = pVtab->zErrMsg;
+ pVtab->zErrMsg = 0;
}
}
db->aVTrans = aVTrans;
/* Invoke the xBegin method */
rc = pModule->xBegin(pVtab);
- sqlite3VtabTransferError(db, rc, pVtab);
- if( rc!=SQLITE_OK ){
- return rc;
+ if( rc==SQLITE_OK ){
+ rc = addToVTrans(db, pVtab);
}
-
- rc = addToVTrans(db, pVtab);
}
return rc;
}
** so is applicable. Because this module is responsible for selecting
** indices, you might also think of this module as the "query optimizer".
**
-** $Id: where.c,v 1.318 2008/07/28 19:34:54 drh Exp $
+** $Id: where.c,v 1.319 2008/08/01 17:37:41 danielk1977 Exp $
*/
#include "sqliteInt.h"
sqlite3_index_info **ppIdxInfo /* Index information passed to xBestIndex */
){
Table *pTab = pSrc->pTab;
+ sqlite3_vtab *pVtab = pTab->pVtab;
sqlite3_index_info *pIdxInfo;
struct sqlite3_index_constraint *pIdxCons;
struct sqlite3_index_orderby *pIdxOrderBy;
** sqlite3ViewGetColumnNames() would have picked up the error.
*/
assert( pTab->azModuleArg && pTab->azModuleArg[0] );
- assert( pTab->pVtab );
+ assert( pVtab );
#if 0
if( pTab->pVtab==0 ){
sqlite3ErrorMsg(pParse, "undefined module %s for table %s",
(void)sqlite3SafetyOff(pParse->db);
WHERETRACE(("xBestIndex for %s\n", pTab->zName));
TRACE_IDX_INPUTS(pIdxInfo);
- rc = pTab->pVtab->pModule->xBestIndex(pTab->pVtab, pIdxInfo);
+ rc = pVtab->pModule->xBestIndex(pVtab, pIdxInfo);
TRACE_IDX_OUTPUTS(pIdxInfo);
(void)sqlite3SafetyOn(pParse->db);
+ if( rc!=SQLITE_OK ){
+ if( rc==SQLITE_NOMEM ){
+ pParse->db->mallocFailed = 1;
+ }else if( !pVtab->zErrMsg ){
+ sqlite3ErrorMsg(pParse, "%s", sqlite3ErrStr(rc));
+ }else{
+ sqlite3ErrorMsg(pParse, "%s", pVtab->zErrMsg);
+ }
+ }
+ sqlite3DbFree(pParse->db, pVtab->zErrMsg);
+ pVtab->zErrMsg = 0;
+
for(i=0; i<pIdxInfo->nConstraint; i++){
if( !pIdxInfo->aConstraint[i].usable && pUsage[i].argvIndex>0 ){
sqlite3ErrorMsg(pParse,
}
}
- if( rc!=SQLITE_OK ){
- if( rc==SQLITE_NOMEM ){
- pParse->db->mallocFailed = 1;
- }else {
- sqlite3ErrorMsg(pParse, "%s", sqlite3ErrStr(rc));
- }
- }
*(int*)&pIdxInfo->nOrderBy = nOrderBy;
-
return pIdxInfo->estimatedCost;
}
#endif /* SQLITE_OMIT_VIRTUALTABLE */
# This file implements regression tests for SQLite library. The
# focus of this file is creating and dropping virtual tables.
#
-# $Id: vtab1.test,v 1.55 2008/07/23 21:07:25 drh Exp $
+# $Id: vtab1.test,v 1.56 2008/08/01 17:37:41 danielk1977 Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# We cannot create a virtual table if the module has not been registered.
#
do_test vtab1-1.1 {
+ explain {
+ CREATE VIRTUAL TABLE t1 USING echo;
+ }
catchsql {
CREATE VIRTUAL TABLE t1 USING echo;
}
}
} {1 {datatype mismatch}}
+# The following tests - vtab1-16.* - are designed to test that setting
+# sqlite3_vtab.zErrMsg variable can be used by the vtab interface to
+# return an error message to the user.
+#
+do_test vtab1-16.1 {
+ execsql {
+ CREATE TABLE t2(a PRIMARY KEY, b, c);
+ INSERT INTO t2 VALUES(1, 2, 3);
+ INSERT INTO t2 VALUES(4, 5, 6);
+ CREATE VIRTUAL TABLE echo_t2 USING echo(t2);
+ }
+} {}
+
+set tn 2
+foreach method [list \
+ xBestIndex \
+ xOpen \
+ xFilter \
+ xNext \
+ xColumn \
+ xRowid \
+] {
+ do_test vtab1-16.$tn {
+ set echo_module_fail($method,t2) "the $method method has failed"
+ catchsql { SELECT rowid, * FROM echo_t2 WHERE a >= 1 }
+ } "1 {echo-vtab-error: the $method method has failed}"
+ unset echo_module_fail($method,t2)
+ incr tn
+}
+
+foreach method [list \
+ xUpdate \
+ xBegin \
+ xSync \
+] {
+ do_test vtab1-16.$tn {
+ set echo_module_fail($method,t2) "the $method method has failed"
+ catchsql { INSERT INTO echo_t2 VALUES(7, 8, 9) }
+ } "1 {echo-vtab-error: the $method method has failed}"
+ unset echo_module_fail($method,t2)
+ incr tn
+}
unset -nocomplain echo_module_begin_fail
finish_test