creating join statement object

This commit is contained in:
Pedro 2014-11-04 00:34:32 +01:00
parent aab1684f5f
commit 33e04efcab
5 changed files with 20 additions and 5 deletions

View File

@ -77,8 +77,8 @@ struct SelectStatement : Statement {
struct JoinStatement : Statement {
JoinStatement() : Statement(kStmtJoin) {};
TableRef* table1;
TableRef* table2;
TableRef* left;
TableRef* right;
JoinType join_type;
Expr* join_condition;
};

View File

@ -80,8 +80,16 @@ void printSelectStatementInfo(SelectStatement* stmt, uint num_indent) {
inprint("Limit:", num_indent+1);
inprint(stmt->limit->limit, num_indent+2);
}
}
void printJoinStatementInfo(JoinStatement* stmt, uint num_indent) {
inprint("JoinStatement", num_indent);
inprint("Left Table", num_indent+1);
printTableRefInfo(stmt->left, num_indent+2);
inprint("Right Table", num_indent+1);
printTableRefInfo(stmt->right, num_indent+2);
inprint("Join Condition", num_indent+1);
printExpression(stmt->join_condition, num_indent+2);
}
} // namespace hsql

View File

@ -8,6 +8,7 @@
namespace hsql {
void printSelectStatementInfo(SelectStatement* stmt, uint num_indent);
void printJoinStatementInfo(JoinStatement* stmt, uint num_indent);
} // namespace hsql

View File

@ -111,7 +111,7 @@ typedef void* yyscan_t;
%type <table> from_clause table_ref table_ref_atomic table_ref_atomic_opt_paren
%type <expr> expr scalar_expr unary_expr binary_expr function_expr star_expr
%type <expr> column_name literal int_literal num_literal
%type <expr> comp_expr where_clause
%type <expr> comp_expr where_clause join_condition
%type <explist> expr_list group_clause select_list
%type <tbllist> table_ref_commalist
%type <order> order_by_clause
@ -171,6 +171,10 @@ join_statement:
table_ref_atomic_opt_paren JOIN table_ref_atomic_opt_paren ON join_condition
{
$$ = new JoinStatement();
$$->left = $1;
$$->right = $3;
$$->join_condition = $5;
$$->join_type = kJoinInner;
}
;

View File

@ -25,8 +25,10 @@ int main(int argc, char *argv[]) {
if (stmt->type == kStmtSelect) {
printSelectStatementInfo((SelectStatement*) stmt, 0);
} else if (stmt->type == kStmtJoin) {
printJoinStatementInfo((JoinStatement*) stmt, 0);
} else {
fprintf(stderr, "Only Supporting Select Statements!\n");
fprintf(stderr, "Unsupported Statement Type %u!\n", stmt->type);
}
}