aboutsummaryrefslogtreecommitdiff
path: root/src/expr.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2020-01-03 02:20:37 +0000
committerdrh <drh@noemail.net>2020-01-03 02:20:37 +0000
commit0cbec59c8bbaa2e2ddf13928441d68b28a9aa3d0 (patch)
tree3d75061431bac9fbbb2f9cf60866fcfe05ce97e4 /src/expr.c
parente1f49b88501363222a3f13c25c1ec4e08150811b (diff)
downloadsqlite-0cbec59c8bbaa2e2ddf13928441d68b28a9aa3d0.tar.gz
sqlite-0cbec59c8bbaa2e2ddf13928441d68b28a9aa3d0.zip
When generating the name of a view (or common table expression) because the
SQL does not specify a name, avoid the names "true" and "false" which might be confused for the boolean literals of the same name, leading to an inconsistent abstract syntax tree. FossilOrigin-Name: ff9492d3ff733c222ea67f23d478df1547641b5e2e6dd870b0b29e25c13f3739
Diffstat (limited to 'src/expr.c')
-rw-r--r--src/expr.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/expr.c b/src/expr.c
index 2d9854c89..cc795c09f 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -1849,18 +1849,33 @@ int sqlite3SelectWalkFail(Walker *pWalker, Select *NotUsed){
}
/*
+** Check the input string to see if it is "true" or "false" (in any case).
+**
+** If the string is.... Return
+** "true" EP_IsTrue
+** "false" EP_IsFalse
+** anything else 0
+*/
+u32 sqlite3IsTrueOrFalse(const char *zIn){
+ if( sqlite3StrICmp(zIn, "true")==0 ) return EP_IsTrue;
+ if( sqlite3StrICmp(zIn, "false")==0 ) return EP_IsFalse;
+ return 0;
+}
+
+
+/*
** If the input expression is an ID with the name "true" or "false"
** then convert it into an TK_TRUEFALSE term. Return non-zero if
** the conversion happened, and zero if the expression is unaltered.
*/
int sqlite3ExprIdToTrueFalse(Expr *pExpr){
+ u32 v;
assert( pExpr->op==TK_ID || pExpr->op==TK_STRING );
if( !ExprHasProperty(pExpr, EP_Quoted)
- && (sqlite3StrICmp(pExpr->u.zToken, "true")==0
- || sqlite3StrICmp(pExpr->u.zToken, "false")==0)
+ && (v = sqlite3IsTrueOrFalse(pExpr->u.zToken))!=0
){
pExpr->op = TK_TRUEFALSE;
- ExprSetProperty(pExpr, pExpr->u.zToken[4]==0 ? EP_IsTrue : EP_IsFalse);
+ ExprSetProperty(pExpr, v);
return 1;
}
return 0;