Merge pull request #80 from javrucebo/operator-equals

Allow '==' for operator equals
This commit is contained in:
mrks 2018-01-24 14:53:22 +01:00 committed by GitHub
commit 36628dc005
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 2 deletions

View File

@ -814,6 +814,7 @@ exists_expr:
comp_expr: comp_expr:
operand '=' operand { $$ = Expr::makeOpBinary($1, kOpEquals, $3); } operand '=' operand { $$ = Expr::makeOpBinary($1, kOpEquals, $3); }
| operand EQUALS operand { $$ = Expr::makeOpBinary($1, kOpEquals, $3); }
| operand NOTEQUALS operand { $$ = Expr::makeOpBinary($1, kOpNotEquals, $3); } | operand NOTEQUALS operand { $$ = Expr::makeOpBinary($1, kOpNotEquals, $3); }
| operand '<' operand { $$ = Expr::makeOpBinary($1, kOpLess, $3); } | operand '<' operand { $$ = Expr::makeOpBinary($1, kOpLess, $3); }
| operand '>' operand { $$ = Expr::makeOpBinary($1, kOpGreater, $3); } | operand '>' operand { $$ = Expr::makeOpBinary($1, kOpGreater, $3); }

View File

@ -175,7 +175,9 @@ ON TOKEN(ON)
OR TOKEN(OR) OR TOKEN(OR)
TO TOKEN(TO) TO TOKEN(TO)
"!=" TOKEN(NOTEQUALS) /* Allow =/== see https://sqlite.org/lang_expr.html#collateop */
"==" TOKEN(EQUALS)
"!=" TOKEN(NOTEQUALS)
"<>" TOKEN(NOTEQUALS) "<>" TOKEN(NOTEQUALS)
"<=" TOKEN(LESSEQ) "<=" TOKEN(LESSEQ)
">=" TOKEN(GREATEREQ) ">=" TOKEN(GREATEREQ)

View File

@ -348,6 +348,43 @@ TEST(SelectColumnOrder) {
ASSERT_STREQ(stmt->fromTable->list->at(3)->alias, "d"); ASSERT_STREQ(stmt->fromTable->list->at(3)->alias, "d");
} }
TEST(Operators) {
SelectStatement* stmt;
SQLParserResult result;
SQLParser::parse("SELECT * FROM foo where a = 1; \
SELECT * FROM foo where a == 1; \
SELECT * FROM foo where a != 1; \
SELECT * FROM foo where a <> 1; \
SELECT * FROM foo where a > 1; \
SELECT * FROM foo where a < 1; \
SELECT * FROM foo where a >= 1; \
SELECT * FROM foo where a <= 1;", &result);
stmt = (SelectStatement*) result.getStatement(0);
ASSERT_EQ(stmt->whereClause->opType, kOpEquals);
stmt = (SelectStatement*) result.getStatement(1);
ASSERT_EQ(stmt->whereClause->opType, kOpEquals);
stmt = (SelectStatement*) result.getStatement(2);
ASSERT_EQ(stmt->whereClause->opType, kOpNotEquals);
stmt = (SelectStatement*) result.getStatement(3);
ASSERT_EQ(stmt->whereClause->opType, kOpNotEquals);
stmt = (SelectStatement*) result.getStatement(4);
ASSERT_EQ(stmt->whereClause->opType, kOpGreater);
stmt = (SelectStatement*) result.getStatement(5);
ASSERT_EQ(stmt->whereClause->opType, kOpLess);
stmt = (SelectStatement*) result.getStatement(6);
ASSERT_EQ(stmt->whereClause->opType, kOpGreaterEq);
stmt = (SelectStatement*) result.getStatement(7);
ASSERT_EQ(stmt->whereClause->opType, kOpLessEq);
}
TEST(JoinTypes) { TEST(JoinTypes) {
SelectStatement* stmt; SelectStatement* stmt;
@ -401,4 +438,4 @@ TEST(JoinTypes) {
stmt = (SelectStatement*) result.getStatement(11); stmt = (SelectStatement*) result.getStatement(11);
ASSERT_NULL(stmt->fromTable->join); ASSERT_NULL(stmt->fromTable->join);
} }