commit
ea694ad2b3
|
@ -993,11 +993,13 @@ join_clause:
|
||||||
|
|
||||||
opt_join_type:
|
opt_join_type:
|
||||||
INNER { $$ = kJoinInner; }
|
INNER { $$ = kJoinInner; }
|
||||||
| OUTER { $$ = kJoinOuter; }
|
| LEFT OUTER { $$ = kJoinLeft; }
|
||||||
| LEFT OUTER { $$ = kJoinLeftOuter; }
|
|
||||||
| RIGHT OUTER { $$ = kJoinRightOuter; }
|
|
||||||
| LEFT { $$ = kJoinLeft; }
|
| LEFT { $$ = kJoinLeft; }
|
||||||
|
| RIGHT OUTER { $$ = kJoinRight; }
|
||||||
| RIGHT { $$ = kJoinRight; }
|
| RIGHT { $$ = kJoinRight; }
|
||||||
|
| FULL OUTER { $$ = kJoinFull; }
|
||||||
|
| OUTER { $$ = kJoinFull; }
|
||||||
|
| FULL { $$ = kJoinFull; }
|
||||||
| CROSS { $$ = kJoinCross; }
|
| CROSS { $$ = kJoinCross; }
|
||||||
| /* empty, default */ { $$ = kJoinInner; }
|
| /* empty, default */ { $$ = kJoinInner; }
|
||||||
;
|
;
|
||||||
|
|
|
@ -49,11 +49,9 @@ namespace hsql {
|
||||||
// Possible types of joins.
|
// Possible types of joins.
|
||||||
enum JoinType {
|
enum JoinType {
|
||||||
kJoinInner,
|
kJoinInner,
|
||||||
kJoinOuter,
|
kJoinFull,
|
||||||
kJoinLeft,
|
kJoinLeft,
|
||||||
kJoinRight,
|
kJoinRight,
|
||||||
kJoinLeftOuter,
|
|
||||||
kJoinRightOuter,
|
|
||||||
kJoinCross,
|
kJoinCross,
|
||||||
kJoinNatural
|
kJoinNatural
|
||||||
};
|
};
|
||||||
|
|
|
@ -298,7 +298,7 @@ TEST(SelectJoin) {
|
||||||
const TableRef* table = stmt->fromTable;
|
const TableRef* table = stmt->fromTable;
|
||||||
const JoinDefinition* outer_join = table->join;
|
const JoinDefinition* outer_join = table->join;
|
||||||
ASSERT_EQ(table->type, kTableJoin);
|
ASSERT_EQ(table->type, kTableJoin);
|
||||||
ASSERT_EQ(outer_join->type, kJoinOuter);
|
ASSERT_EQ(outer_join->type, kJoinFull);
|
||||||
|
|
||||||
ASSERT_EQ(outer_join->right->type, kTableName);
|
ASSERT_EQ(outer_join->right->type, kTableName);
|
||||||
ASSERT_STREQ(outer_join->right->name, "Product");
|
ASSERT_STREQ(outer_join->right->name, "Product");
|
||||||
|
@ -347,3 +347,58 @@ TEST(SelectColumnOrder) {
|
||||||
ASSERT_STREQ(stmt->fromTable->list->at(2)->alias, "c");
|
ASSERT_STREQ(stmt->fromTable->list->at(2)->alias, "c");
|
||||||
ASSERT_STREQ(stmt->fromTable->list->at(3)->alias, "d");
|
ASSERT_STREQ(stmt->fromTable->list->at(3)->alias, "d");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST(JoinTypes) {
|
||||||
|
SelectStatement* stmt;
|
||||||
|
SQLParserResult result;
|
||||||
|
|
||||||
|
SQLParser::parse("SELECT * FROM x join y on a=b; \
|
||||||
|
SELECT * FROM x inner join y on a=b; \
|
||||||
|
SELECT * FROM x left join y on a=b; \
|
||||||
|
SELECT * FROM x left outer join y on a=b; \
|
||||||
|
SELECT * FROM x right join y on a=b; \
|
||||||
|
SELECT * FROM x right outer join y on a=b; \
|
||||||
|
SELECT * FROM x full join y on a=b; \
|
||||||
|
SELECT * FROM x outer join y on a=b; \
|
||||||
|
SELECT * FROM x full outer join y on a=b; \
|
||||||
|
SELECT * FROM x natural join y; \
|
||||||
|
SELECT * FROM x cross join y on a=b; \
|
||||||
|
SELECT * FROM x, y where a = b;", &result);
|
||||||
|
|
||||||
|
stmt = (SelectStatement*) result.getStatement(0);
|
||||||
|
ASSERT_EQ(stmt->fromTable->join->type, kJoinInner);
|
||||||
|
|
||||||
|
stmt = (SelectStatement*) result.getStatement(1);
|
||||||
|
ASSERT_EQ(stmt->fromTable->join->type, kJoinInner);
|
||||||
|
|
||||||
|
stmt = (SelectStatement*) result.getStatement(2);
|
||||||
|
ASSERT_EQ(stmt->fromTable->join->type, kJoinLeft);
|
||||||
|
|
||||||
|
stmt = (SelectStatement*) result.getStatement(3);
|
||||||
|
ASSERT_EQ(stmt->fromTable->join->type, kJoinLeft);
|
||||||
|
|
||||||
|
stmt = (SelectStatement*) result.getStatement(4);
|
||||||
|
ASSERT_EQ(stmt->fromTable->join->type, kJoinRight);
|
||||||
|
|
||||||
|
stmt = (SelectStatement*) result.getStatement(5);
|
||||||
|
ASSERT_EQ(stmt->fromTable->join->type, kJoinRight);
|
||||||
|
|
||||||
|
stmt = (SelectStatement*) result.getStatement(6);
|
||||||
|
ASSERT_EQ(stmt->fromTable->join->type, kJoinFull);
|
||||||
|
|
||||||
|
stmt = (SelectStatement*) result.getStatement(7);
|
||||||
|
ASSERT_EQ(stmt->fromTable->join->type, kJoinFull);
|
||||||
|
|
||||||
|
stmt = (SelectStatement*) result.getStatement(8);
|
||||||
|
ASSERT_EQ(stmt->fromTable->join->type, kJoinFull);
|
||||||
|
|
||||||
|
stmt = (SelectStatement*) result.getStatement(9);
|
||||||
|
ASSERT_EQ(stmt->fromTable->join->type, kJoinNatural);
|
||||||
|
|
||||||
|
stmt = (SelectStatement*) result.getStatement(10);
|
||||||
|
ASSERT_EQ(stmt->fromTable->join->type, kJoinCross);
|
||||||
|
|
||||||
|
stmt = (SelectStatement*) result.getStatement(11);
|
||||||
|
ASSERT_NULL(stmt->fromTable->join);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue