added frame for join statements

This commit is contained in:
Pedro 2014-10-27 12:09:53 +01:00
parent bb1ec42022
commit e177b8cef7
4 changed files with 27 additions and 5 deletions

View File

@ -275,7 +275,7 @@ table_ref_atomic:
} }
| '(' select_statement ')' { | '(' select_statement ')' {
auto tbl = new TableRef(kTableSelect); auto tbl = new TableRef(kTableSelect);
tbl->stmt = $2; tbl->select = $2;
$$ = tbl; $$ = tbl;
} }
; ;

View File

@ -12,6 +12,7 @@
typedef enum { typedef enum {
kStmtSelect, kStmtSelect,
kStmtJoin,
kStmtDelete, kStmtDelete,
kStmtInsert, kStmtInsert,
kStmtCreate kStmtCreate
@ -34,6 +35,14 @@ struct OrderDescription {
}; };
typedef enum {
kJoinInner,
kJoinOuter,
kJoinLeft,
kJoinRight
} JoinType;
struct Statement { struct Statement {
Statement(StatementType type) : type(type) {}; Statement(StatementType type) : type(type) {};
StatementType type; StatementType type;
@ -56,6 +65,16 @@ struct SelectStatement : Statement {
}; };
struct JoinStatement : Statement {
JoinStatement() : Statement(kStmtJoin) {};
TableRef* table1;
TableRef* table2;
JoinType join_type;
Expr* join_condition;
};
struct DeleteStatement : Statement { struct DeleteStatement : Statement {
// TODO // TODO
}; };

View File

@ -1,7 +1,8 @@
#ifndef __TABLEREF_H_ #ifndef __TABLEREF_H__
#define __TABLEREF_H_ #define __TABLEREF_H__
class SelectStatement; class SelectStatement;
class JoinStatement;
/** /**
* TableRef * TableRef
@ -10,6 +11,7 @@ class SelectStatement;
typedef enum { typedef enum {
kTableName, kTableName,
kTableSelect, kTableSelect,
kTableJoin,
kTableCrossProduct kTableCrossProduct
} TableRefType; } TableRefType;
@ -21,7 +23,8 @@ struct TableRef {
TableRefType type; TableRefType type;
char* name; char* name;
SelectStatement* stmt; SelectStatement* select;
JoinStatement* join;
List<TableRef*>* list; List<TableRef*>* list;
}; };

View File

@ -18,7 +18,7 @@ void printTableRefInfo(TableRef* table, uint num_indent) {
inprint(table->name, num_indent); inprint(table->name, num_indent);
break; break;
case kTableSelect: case kTableSelect:
printSelectStatementInfo(table->stmt, num_indent); printSelectStatementInfo(table->select, num_indent);
break; break;
case kTableCrossProduct: case kTableCrossProduct:
for (TableRef* tbl : table->list->_vector) printTableRefInfo(tbl, num_indent); for (TableRef* tbl : table->list->_vector) printTableRefInfo(tbl, num_indent);