aboutsummaryrefslogtreecommitdiff
path: root/src/expr.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2019-09-02 00:58:44 +0000
committerdrh <drh@noemail.net>2019-09-02 00:58:44 +0000
commitbffdd636339b32c706253e8c791ccca8b3f88f19 (patch)
tree0c1aa485d441031c18d5f97078ec42db784223a3 /src/expr.c
parentcc80db69e9c52304b50209a4aca66b1ae908b602 (diff)
downloadsqlite-bffdd636339b32c706253e8c791ccca8b3f88f19.tar.gz
sqlite-bffdd636339b32c706253e8c791ccca8b3f88f19.zip
When computing an expression value for an index-on-expression or a CHECK
constraint and the expressions uses a REAL table column, but the value of that column is an integer (in other words, when it is using the store-real-as-integer optimization) be sure to promote the value to real before evaluating the expression. Ticket [57af00b6642ecd68]. FossilOrigin-Name: 0658c16e311393c8a347b1bd41fa5dbfd2e184aa75d84c011aa8dbac79b632e9
Diffstat (limited to 'src/expr.c')
-rw-r--r--src/expr.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/expr.c b/src/expr.c
index 61b45b992..622024eb2 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -3532,7 +3532,19 @@ expr_code_doover:
if( iTab<0 ){
if( pParse->iSelfTab<0 ){
/* Generating CHECK constraints or inserting into partial index */
- return pExpr->iColumn - pParse->iSelfTab;
+ assert( pExpr->y.pTab!=0 );
+ assert( pExpr->iColumn>=XN_ROWID );
+ assert( pExpr->iColumn<pExpr->y.pTab->nCol );
+ if( pExpr->iColumn>=0
+ && pExpr->y.pTab->aCol[pExpr->iColumn].affinity==SQLITE_AFF_REAL
+ ){
+ sqlite3VdbeAddOp2(v, OP_SCopy, pExpr->iColumn - pParse->iSelfTab,
+ target);
+ sqlite3VdbeAddOp1(v, OP_RealAffinity, target);
+ return target;
+ }else{
+ return pExpr->iColumn - pParse->iSelfTab;
+ }
}else{
/* Coding an expression that is part of an index where column names
** in the index refer to the table to which the index belongs */