1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-12 13:01:09 +03:00

Allow INDEXED BY and NOT INDEXED to be used in UPDATE and DELETE statements. (CVS 5772)

FossilOrigin-Name: 83a7e446b2d4846a6f92bd831a2adaa265f5a786
This commit is contained in:
danielk1977
2008-10-06 16:18:39 +00:00
parent 6ef7f85801
commit b1c685b0c8
8 changed files with 131 additions and 56 deletions

View File

@@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite.
**
** $Id: select.c,v 1.477 2008/10/06 05:32:19 danielk1977 Exp $
** $Id: select.c,v 1.478 2008/10/06 16:18:40 danielk1977 Exp $
*/
#include "sqliteInt.h"
@@ -2882,6 +2882,31 @@ static int minMaxQuery(Parse *pParse, Select *p){
return WHERE_ORDERBY_NORMAL;
}
/*
** If the source-list item passed as an argument was augmented with an
** INDEXED BY clause, then try to locate the specified index. If there
** was such a clause and the named index cannot be found, return
** SQLITE_ERROR and leave an error in pParse. Otherwise, populate
** pFrom->pIndex and return SQLITE_OK.
*/
int sqlite3IndexedByLookup(Parse *pParse, struct SrcList_item *pFrom){
if( pFrom->pTab && pFrom->zIndex ){
Table *pTab = pFrom->pTab;
char *zIndex = pFrom->zIndex;
Index *pIdx;
for(pIdx=pTab->pIndex;
pIdx && sqlite3StrICmp(pIdx->zName, zIndex);
pIdx=pIdx->pNext
);
if( !pIdx ){
sqlite3ErrorMsg(pParse, "no such index: %s", zIndex, 0);
return SQLITE_ERROR;
}
pFrom->pIndex = pIdx;
}
return SQLITE_OK;
}
/*
** This routine is a Walker callback for "expanding" a SELECT statement.
** "Expanding" means to do the following:
@@ -2984,18 +3009,8 @@ static int selectExpander(Walker *pWalker, Select *p){
}
/* Locate the index named by the INDEXED BY clause, if any. */
if( pFrom->zIndex ){
char *zIndex = pFrom->zIndex;
Index *pIdx;
for(pIdx=pTab->pIndex;
pIdx && sqlite3StrICmp(pIdx->zName, zIndex);
pIdx=pIdx->pNext
);
if( !pIdx ){
sqlite3ErrorMsg(pParse, "no such index: %s", zIndex, 0);
return WRC_Abort;
}
pFrom->pIndex = pIdx;
if( sqlite3IndexedByLookup(pParse, pFrom) ){
return WRC_Abort;
}
}