aboutsummaryrefslogtreecommitdiff
path: root/src/expr.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2018-02-26 20:15:54 +0000
committerdrh <drh@noemail.net>2018-02-26 20:15:54 +0000
commit171d16bb2187b41636980b809d04d923e2811523 (patch)
tree9eb1793fa97cee4b0d2a439806859cd15e9ae060 /src/expr.c
parent3432821192f3c0ddcb5588f401daf661060ea124 (diff)
downloadsqlite-171d16bb2187b41636980b809d04d923e2811523.tar.gz
sqlite-171d16bb2187b41636980b809d04d923e2811523.zip
Get the "DEFAULT true" and "DEFAULT false" phrases working correctly in
CREATE TABLE. FossilOrigin-Name: 8002f87d96b3f885cd208e7d204907a33ba60c4057ce2338b71e2de41215b0e5
Diffstat (limited to 'src/expr.c')
-rw-r--r--src/expr.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/expr.c b/src/expr.c
index f32a03a6d..75d8db7e4 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -1123,7 +1123,7 @@ static int dupedExprStructSize(Expr *p, int flags){
assert( flags==EXPRDUP_REDUCE || flags==0 ); /* Only one flag value allowed */
assert( EXPR_FULLSIZE<=0xfff );
assert( (0xfff & (EP_Reduced|EP_TokenOnly))==0 );
- if( 0==flags || p->op==TK_SELECT_COLUMN ){
+ if( 0==flags || p->op==TK_SELECT_COLUMN || p->op==TK_TRUEFALSE ){
nSize = EXPR_FULLSIZE;
}else{
assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
@@ -1733,6 +1733,26 @@ int sqlite3SelectWalkFail(Walker *pWalker, Select *NotUsed){
}
/*
+** If the input expression is an ID with the name "true" or "false"
+** then convert it into an appropriate TK_TRUEFALSE term. Return true
+** if a conversion occurred, and false if the expression is unaltered.
+*/
+int sqlite3ExprIdToTrueFalse(Expr *pExpr){
+ assert( pExpr->op==TK_ID || pExpr->op==TK_STRING );
+ if( sqlite3StrICmp(pExpr->u.zToken, "true")==0
+ || sqlite3StrICmp(pExpr->u.zToken, "false")==0
+ ){
+ pExpr->op = TK_TRUEFALSE;
+ pExpr->iTable = pExpr->u.zToken[4]==0;
+ pExpr->pTab = 0;
+ ExprSetProperty(pExpr, EP_NoReduce);
+ return 1;
+ }
+ return 0;
+}
+
+
+/*
** These routines are Walker callbacks used to check expressions to
** see if they are "constant" for some definition of constant. The
** Walker.eCode value determines the type of "constant" we are looking
@@ -1779,6 +1799,12 @@ static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){
return WRC_Abort;
}
case TK_ID:
+ /* Convert "true" or "false" in a DEFAULT clause into the
+ ** appropriate TK_TRUEFALSE operator */
+ if( pWalker->eCode>=4 && sqlite3ExprIdToTrueFalse(pExpr) ){
+ return WRC_Prune;
+ }
+ /* Fall thru */
case TK_COLUMN:
case TK_AGG_FUNCTION:
case TK_AGG_COLUMN: