Index: src/select.c ================================================================== --- src/select.c +++ src/select.c @@ -711,12 +711,17 @@ } }else if( eDest!=SRT_Exists ){ /* If the destination is an EXISTS(...) expression, the actual ** values returned by the SELECT are not required. */ - sqlite3ExprCodeExprList(pParse, pEList, regResult, - (eDest==SRT_Output||eDest==SRT_Coroutine)?SQLITE_ECEL_DUP:0); + u8 ecelFlags; + if( eDest==SRT_Mem || eDest==SRT_Output || eDest==SRT_Coroutine ){ + ecelFlags = SQLITE_ECEL_DUP; + }else{ + ecelFlags = 0; + } + sqlite3ExprCodeExprList(pParse, pEList, regResult, ecelFlags); } /* If the DISTINCT keyword was present on the SELECT statement ** and this row has been seen before, then do not make this row ** part of the result. Index: test/misc4.test ================================================================== --- test/misc4.test +++ test/misc4.test @@ -216,7 +216,17 @@ CREATE TABLE t7(x); PRAGMA writable_schema=ON; UPDATE sqlite_master SET sql='CREATE TABLE [M%s%s%s%s%s%s%s%s%s%s%s%s%s'; VACUUM; } {1 {unrecognized token: "[M%s%s%s%s%s%s%s%s%s%s%s%s%s"}} + +# 2015-05-18. Use of ephermeral Mem content after the cursor that holds +# the canonical content has moved on. +# +do_execsql_test misc4-7.2 { + CREATE TABLE t0(a,b); + INSERT INTO t0 VALUES(1,0),(2,0); + UPDATE t0 SET b=9 WHERE a AND (SELECT a FROM t0 WHERE a); + SELECT * FROM t0 ORDER BY +a; +} {1 9 2 9} finish_test