Merge pull request #78 from lawben/fix_ref_table_order

Fix order of table references in multi table FROM
This commit is contained in:
mrks 2018-01-18 10:37:57 +01:00 committed by GitHub
commit edaba87af7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 461 additions and 452 deletions

File diff suppressed because it is too large Load Diff

View File

@ -884,10 +884,10 @@ param_expr:
******************************/
table_ref:
table_ref_atomic
| table_ref_atomic ',' table_ref_commalist {
$3->push_back($1);
| table_ref_commalist ',' table_ref_atomic {
$1->push_back($3);
auto tbl = new TableRef(kTableCrossProduct);
tbl->list = $3;
tbl->list = $1;
$$ = tbl;
}
;

View File

@ -325,3 +325,25 @@ TEST(SelectJoin) {
ASSERT_STREQ(inner_join->condition->expr2->table, "City");
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");
}