1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-16 23:02:26 +03:00

Fix for ticket #105: Fix the UPDATE command so that it works properly with

indexed tables when there is a subquery in the WHERE clause.  Add tests
to verify correct operation. (CVS 680)

FossilOrigin-Name: bbca16f88d00cd33ac7229edf3ee4623eff6e62f
This commit is contained in:
drh
2002-07-16 17:22:50 +00:00
parent 0c36cbe0c2
commit 53e3fc70bf
4 changed files with 36 additions and 13 deletions

View File

@@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser
** to handle UPDATE statements.
**
** $Id: update.c,v 1.47 2002/07/05 21:42:37 drh Exp $
** $Id: update.c,v 1.48 2002/07/16 17:22:51 drh Exp $
*/
#include "sqliteInt.h"
@@ -98,11 +98,20 @@ void sqliteUpdate(
oldIdx = pParse->nTab++;
}
/* Allocate a cursors for the main database table and for all indices.
** The index cursors might not be used, but if they are used they
** need to occur right after the database cursor. So go ahead and
** allocate enough space, just in case.
*/
base = pParse->nTab++;
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
pParse->nTab++;
}
/* Resolve the column names in all the expressions in both the
** WHERE clause and in the new values. Also find the column index
** for each column to be updated in the pChanges array.
*/
base = pParse->nTab++;
if( pWhere ){
if( sqliteExprResolveIds(pParse, base, pTabList, 0, pWhere) ){
goto update_cleanup;
@@ -270,9 +279,8 @@ void sqliteUpdate(
for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
if( openAll || aIdxUsed[i] ){
sqliteVdbeAddOp(v, openOp, base+i+1, pIdx->tnum);
assert( pParse->nTab==base+i+1 );
assert( pParse->nTab>base+i+1 );
}
pParse->nTab++;
}
/* Loop over every record that needs updating. We have to load