diff options
author | drh <drh@noemail.net> | 2015-06-11 13:58:35 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2015-06-11 13:58:35 +0000 |
commit | 72bc8208f01a8e476996db7c6de09ad61ed62d6f (patch) | |
tree | 19038f1b0c8116c3b1d33c9b6b974e211ecd0bd8 /src | |
parent | 033eb6c8d3f4b9c3a0f9343bcb349fbad6ac0b66 (diff) | |
download | sqlite-72bc8208f01a8e476996db7c6de09ad61ed62d6f.tar.gz sqlite-72bc8208f01a8e476996db7c6de09ad61ed62d6f.zip |
When generating code for partial indexes, be sure not to modify the
index condition expression in the schema.
FossilOrigin-Name: e63d01c69c3e50f49ee3022a519c4f3e91f00520
Diffstat (limited to 'src')
-rw-r--r-- | src/delete.c | 4 | ||||
-rw-r--r-- | src/expr.c | 15 | ||||
-rw-r--r-- | src/insert.c | 4 | ||||
-rw-r--r-- | src/sqliteInt.h | 1 |
4 files changed, 20 insertions, 4 deletions
diff --git a/src/delete.c b/src/delete.c index ef6aace1c..369cdaf6f 100644 --- a/src/delete.c +++ b/src/delete.c @@ -798,8 +798,8 @@ int sqlite3GenerateIndexKey( *piPartIdxLabel = sqlite3VdbeMakeLabel(v); pParse->iPartIdxTab = iDataCur; sqlite3ExprCachePush(pParse); - sqlite3ExprIfFalse(pParse, pIdx->pPartIdxWhere, *piPartIdxLabel, - SQLITE_JUMPIFNULL); + sqlite3ExprIfFalseDup(pParse, pIdx->pPartIdxWhere, *piPartIdxLabel, + SQLITE_JUMPIFNULL); }else{ *piPartIdxLabel = 0; } diff --git a/src/expr.c b/src/expr.c index 89eee29ec..06993e737 100644 --- a/src/expr.c +++ b/src/expr.c @@ -3703,6 +3703,21 @@ void sqlite3ExprIfFalse(Parse *pParse, Expr *pExpr, int dest, int jumpIfNull){ } /* +** Like sqlite3ExprIfFalse() except that a copy is made of pExpr before +** code generation, and that copy is deleted after code generation. This +** ensures that the original pExpr is unchanged. +*/ +void sqlite3ExprIfFalseDup(Parse *pParse, Expr *pExpr, int dest,int jumpIfNull){ + sqlite3 *db = pParse->db; + Expr *pCopy = sqlite3ExprDup(db, pExpr, 0); + if( db->mallocFailed==0 ){ + sqlite3ExprIfFalse(pParse, pCopy, dest, jumpIfNull); + } + sqlite3ExprDelete(db, pCopy); +} + + +/* ** Do a deep comparison of two expression trees. Return 0 if the two ** expressions are completely identical. Return 1 if they differ only ** by a COLLATE operator at the top level. Return 2 if there are differences diff --git a/src/insert.c b/src/insert.c index 7e8741a9a..16bf07cdf 100644 --- a/src/insert.c +++ b/src/insert.c @@ -1381,8 +1381,8 @@ void sqlite3GenerateConstraintChecks( if( pIdx->pPartIdxWhere ){ sqlite3VdbeAddOp2(v, OP_Null, 0, aRegIdx[ix]); pParse->ckBase = regNewData+1; - sqlite3ExprIfFalse(pParse, pIdx->pPartIdxWhere, addrUniqueOk, - SQLITE_JUMPIFNULL); + sqlite3ExprIfFalseDup(pParse, pIdx->pPartIdxWhere, addrUniqueOk, + SQLITE_JUMPIFNULL); pParse->ckBase = 0; } diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 43e4b0be9..2378376c2 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -3326,6 +3326,7 @@ int sqlite3ExprCodeExprList(Parse*, ExprList*, int, u8); #define SQLITE_ECEL_FACTOR 0x02 /* Factor out constant terms */ void sqlite3ExprIfTrue(Parse*, Expr*, int, int); void sqlite3ExprIfFalse(Parse*, Expr*, int, int); +void sqlite3ExprIfFalseDup(Parse*, Expr*, int, int); Table *sqlite3FindTable(sqlite3*,const char*, const char*); Table *sqlite3LocateTable(Parse*,int isView,const char*, const char*); Table *sqlite3LocateTableItem(Parse*,int isView,struct SrcList_item *); |