Fix order of table_ref

This commit is contained in:
Lawrence 2018-01-17 16:47:57 +01:00
parent 1425deb75d
commit a578842117
3 changed files with 461 additions and 452 deletions

File diff suppressed because it is too large Load Diff

View File

@ -793,7 +793,7 @@ in_expr:
| operand NOT IN '(' select_no_paren ')' { $$ = Expr::makeOpUnary(kOpNot, Expr::makeInOperator($1, $5)); } | operand NOT IN '(' select_no_paren ')' { $$ = Expr::makeOpUnary(kOpNot, Expr::makeInOperator($1, $5)); }
; ;
// CASE grammar based on: flex & bison by John Levine // CASE grammar based on: flex & bison by John Levine
// https://www.safaribooksonline.com/library/view/flex-bison/9780596805418/ch04.html#id352665 // https://www.safaribooksonline.com/library/view/flex-bison/9780596805418/ch04.html#id352665
case_expr: case_expr:
CASE expr case_list END { $$ = Expr::makeCase($2, $3, nullptr); } CASE expr case_list END { $$ = Expr::makeCase($2, $3, nullptr); }
@ -884,10 +884,10 @@ param_expr:
******************************/ ******************************/
table_ref: table_ref:
table_ref_atomic table_ref_atomic
| table_ref_atomic ',' table_ref_commalist { | table_ref_commalist ',' table_ref_atomic {
$3->push_back($1); $1->push_back($3);
auto tbl = new TableRef(kTableCrossProduct); auto tbl = new TableRef(kTableCrossProduct);
tbl->list = $3; tbl->list = $1;
$$ = tbl; $$ = tbl;
} }
; ;

View File

@ -325,3 +325,25 @@ TEST(SelectJoin) {
ASSERT_STREQ(inner_join->condition->expr2->table, "City"); ASSERT_STREQ(inner_join->condition->expr2->table, "City");
ASSERT_STREQ(inner_join->condition->expr2->name, "id"); ASSERT_STREQ(inner_join->condition->expr2->name, "id");
} }
TEST(SelectColumnOrder) {
TEST_PARSE_SINGLE_SQL(
"SELECT *\
FROM a,\
(SELECT a AS b FROM a) b,\
(SELECT a AS c FROM a) c,\
(SELECT a AS d FROM a) d;",
kStmtSelect,
SelectStatement,
result,
stmt);
ASSERT_EQ(stmt->fromTable->list->size(), 4);
// Make sure the order of the table list is corrects
ASSERT_STREQ(stmt->fromTable->list->at(0)->name, "a");
ASSERT_STREQ(stmt->fromTable->list->at(1)->alias, "b");
ASSERT_STREQ(stmt->fromTable->list->at(2)->alias, "c");
ASSERT_STREQ(stmt->fromTable->list->at(3)->alias, "d");
}