diff options
author | drh <drh@noemail.net> | 2018-08-09 18:36:54 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2018-08-09 18:36:54 +0000 |
commit | d98f53249c363a48757500cf8918e160bc0ec8c1 (patch) | |
tree | f5c800537eb38fc1491a4744bccd6dbcaa7802dc /src/expr.c | |
parent | 6389a7b0aca9f311b2f337a5fb6395a098278124 (diff) | |
download | sqlite-d98f53249c363a48757500cf8918e160bc0ec8c1.tar.gz sqlite-d98f53249c363a48757500cf8918e160bc0ec8c1.zip |
When a column must be a constant due to WHERE clause and the value of that
column is being coded as a constant, make sure the affinity is correct.
FossilOrigin-Name: 7404ea83168e6c739ebe8fc5d65bbf0265432ccb35b3418bb0381d74362f7527
Diffstat (limited to 'src/expr.c')
-rw-r--r-- | src/expr.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/expr.c b/src/expr.c index a590bc6a9..769d198c2 100644 --- a/src/expr.c +++ b/src/expr.c @@ -3367,7 +3367,26 @@ expr_code_doover: case TK_COLUMN: { int iTab = pExpr->iTable; if( ExprHasProperty(pExpr, EP_FixedCol) ){ - return sqlite3ExprCodeTarget(pParse, pExpr->pLeft,target); + /* This COLUMN expression is really a constant due to WHERE clause + ** constraints, and that constant is coded by the pExpr->pLeft + ** expresssion. However, make sure the constant has the correct + ** datatype by applying the Affinity of the table column to the + ** constant. + */ + int iReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft,target); + int aff = sqlite3TableColumnAffinity(pExpr->pTab, pExpr->iColumn); + if( aff!=SQLITE_AFF_BLOB ){ + static const char zAff[] = "B\000C\000D\000E"; + assert( SQLITE_AFF_BLOB=='A' ); + assert( SQLITE_AFF_TEXT=='B' ); + if( iReg!=target ){ + sqlite3VdbeAddOp2(v, OP_SCopy, iReg, target); + iReg = target; + } + sqlite3VdbeAddOp4(v, OP_Affinity, iReg, 1, 0, + &zAff[(aff-'B')*2], P4_STATIC); + } + return iReg; } if( iTab<0 ){ if( pParse->iSelfTab<0 ){ |