Index: src/update.c ================================================================== --- src/update.c +++ src/update.c @@ -10,11 +10,11 @@ ** ************************************************************************* ** This file contains C code routines that are called by the parser ** to handle UPDATE statements. ** -** $Id: update.c,v 1.134 2007/02/07 01:06:53 drh Exp $ +** $Id: update.c,v 1.135 2007/02/21 16:52:12 danielk1977 Exp $ */ #include "sqliteInt.h" #ifndef SQLITE_OMIT_VIRTUALTABLE /* Forward declaration */ @@ -566,10 +566,11 @@ Select *pSelect = 0; /* The SELECT statement */ Expr *pExpr; /* Temporary expression */ int ephemTab; /* Table holding the result of the SELECT */ int i; /* Loop counter */ int addr; /* Address of top of loop */ + int iLabel; /* Vdbe label used by the OP_Rewind op */ /* Construct the SELECT statement that will find the new values for ** all updated rows. */ pEList = sqlite3ExprListAppend(0, sqlite3CreateIdExpr("_rowid_"), 0); @@ -600,11 +601,12 @@ /* ** Generate code to scan the ephemeral table and call VDelete and ** VInsert */ - sqlite3VdbeAddOp(v, OP_Rewind, ephemTab, 0); + iLabel = sqlite3VdbeMakeLabel(v); + sqlite3VdbeAddOp(v, OP_Rewind, ephemTab, iLabel); addr = sqlite3VdbeCurrentAddr(v); sqlite3VdbeAddOp(v, OP_Column, ephemTab, 0); if( pRowid ){ sqlite3VdbeAddOp(v, OP_Column, ephemTab, 1); }else{ @@ -615,11 +617,12 @@ } pParse->pVirtualLock = pTab; sqlite3VdbeOp3(v, OP_VUpdate, 0, pTab->nCol+2, (const char*)pTab->pVtab, P3_VTAB); sqlite3VdbeAddOp(v, OP_Next, ephemTab, addr); + sqlite3VdbeResolveLabel(v, iLabel); sqlite3VdbeAddOp(v, OP_Close, ephemTab, 0); /* Cleanup */ sqlite3SelectDelete(pSelect); } #endif /* SQLITE_OMIT_VIRTUALTABLE */ Index: test/vtab1.test ================================================================== --- test/vtab1.test +++ test/vtab1.test @@ -9,11 +9,11 @@ # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this file is creating and dropping virtual tables. # -# $Id: vtab1.test,v 1.39 2007/01/09 14:01:14 drh Exp $ +# $Id: vtab1.test,v 1.40 2007/02/21 16:52:12 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl ifcapable !vtab||!schema_pragmas { @@ -887,8 +887,31 @@ do_test vtab1.11-5 { execsql { SELECT glob(a,'2') FROM e } } {{2 1} {2 2}} + +# See ticket #2244 +# +do_test vtab1.2244-1 { + execsql { + CREATE TABLE t2244(a, b); + CREATE VIRTUAL TABLE t2244e USING echo(t2244); + INSERT INTO t2244 VALUES('AA', 'BB'); + INSERT INTO t2244 VALUES('CC', 'DD'); + SELECT rowid, * FROM t2244e; + } +} {1 AA BB 2 CC DD} +do_test vtab1.2244-2 { + execsql { + SELECT * FROM t2244e WHERE rowid = 10; + } +} {} +do_test vtab1.2244-3 { + execsql { + UPDATE t2244e SET a = 'hello world' WHERE 0; + SELECT rowid, * FROM t2244e; + } +} {1 AA BB 2 CC DD} unset -nocomplain echo_module_begin_fail finish_test