diff --git a/src/parser/bison_parser.y b/src/parser/bison_parser.y index 4f8eff6..402c157 100755 --- a/src/parser/bison_parser.y +++ b/src/parser/bison_parser.y @@ -991,7 +991,7 @@ opt_alias: alias | /* empty */ { $$ = nullptr; } - + /****************************** * Join Statements ******************************/ diff --git a/test/queries/queries-good.sql b/test/queries/queries-good.sql index 9b45fd4..f77c639 100755 --- a/test/queries/queries-good.sql +++ b/test/queries/queries-good.sql @@ -16,6 +16,7 @@ SELECT a, MAX(b), MAX(c, d), CUSTOM(q, UP(r)) AS f FROM t1; SELECT * FROM t WHERE a BETWEEN 1 and c; SELECT * FROM t WHERE a = ? AND b = ?; SELECT City.name, Product.category, SUM(price) FROM fact INNER JOIN City ON fact.city_id = City.id INNER JOIN Product ON fact.product_id = Product.id GROUP BY City.name, Product.category; +SELECT SUBSTR(a, 3, 5) FROM t; # JOIN SELECT t1.a, t1.b, t2.c FROM "table" AS t1 JOIN (SELECT * FROM foo JOIN bar ON foo.id = bar.id) t2 ON t1.a = t2.b WHERE (t1.b OR NOT t1.a) AND t2.c = 12.5 SELECT * FROM t1 JOIN t2 ON c1 = c2; diff --git a/test/select_tests.cpp b/test/select_tests.cpp index 4291eb9..d1c266b 100644 --- a/test/select_tests.cpp +++ b/test/select_tests.cpp @@ -55,6 +55,35 @@ TEST(SelectExprTest) { ASSERT_STREQ(stmt->selectList->at(2)->exprList->at(1)->exprList->at(0)->getName(), "un"); } +TEST(SelectSubstrTest) { + TEST_PARSE_SINGLE_SQL( + "SELECT SUBSTR(a, 3, 5) FROM students;", + kStmtSelect, + SelectStatement, + result, + stmt); + + ASSERT_NULL(stmt->whereClause); + ASSERT_NULL(stmt->groupBy); + + ASSERT_EQ(stmt->selectList->size(), 1); + + ASSERT(stmt->selectList->at(0)->isType(kExprFunctionRef)); + ASSERT_STREQ(stmt->selectList->at(0)->getName(), "SUBSTR"); + + ASSERT_NOTNULL(stmt->selectList->at(0)->exprList); + ASSERT_EQ(stmt->selectList->at(0)->exprList->size(), 3); + + ASSERT(stmt->selectList->at(0)->exprList->at(0)->isType(kExprColumnRef)); + ASSERT_STREQ(stmt->selectList->at(0)->exprList->at(0)->getName(), "a"); + + ASSERT(stmt->selectList->at(0)->exprList->at(1)->isType(kExprLiteralInt)); + ASSERT_EQ(stmt->selectList->at(0)->exprList->at(1)->ival, 3); + + ASSERT(stmt->selectList->at(0)->exprList->at(2)->isType(kExprLiteralInt)); + ASSERT_EQ(stmt->selectList->at(0)->exprList->at(2)->ival, 5); +} + TEST(SelectHavingTest) { TEST_PARSE_SINGLE_SQL( @@ -472,7 +501,7 @@ TEST(JoinTypes) { stmt = (SelectStatement*) result.getStatement(7); ASSERT_EQ(stmt->fromTable->join->type, kJoinFull); - + stmt = (SelectStatement*) result.getStatement(8); ASSERT_EQ(stmt->fromTable->join->type, kJoinFull);