basic skeletons of update and delete added

This commit is contained in:
2021-07-08 20:51:03 +02:00
parent e44b72ce53
commit ddb9441e23
9 changed files with 308 additions and 72 deletions

View File

@@ -21,9 +21,12 @@ enum class NodeType {
database_value,
logical_operator,
relational_operator,
arithmetical_operator,
create_table,
insert_into,
select_from,
delete_from,
update_table,
column_name,
column_value,
column_def,
@@ -101,6 +104,9 @@ struct LogicalOperatorNode : Node {
LogicalOperatorType op;
std::unique_ptr<Node> left;
std::unique_ptr<Node> right;
LogicalOperatorNode(LogicalOperatorType op, std::unique_ptr<Node> left, std::unique_ptr<Node> right) :
Node(NodeType::logical_operator), op(op), left(std::move(left)), right(std::move(right)) {};
};
enum class RelationalOperatorType {
@@ -123,6 +129,25 @@ struct RelationalOperatorNode : Node {
Node(NodeType::relational_operator), op(op), left(std::move(left)), right(std::move(right)) {};
};
enum class ArithmeticalOperatorType {
copy_value, // just copy lef value and do nothing with it
plus_operator,
minus_operator,
multiply_operator,
divide_operator
};
struct ArithmeticalOperatorNode : Node {
ArithmeticalOperatorType op;
std::unique_ptr<Node> left;
std::unique_ptr<Node> right;
ArithmeticalOperatorNode(ArithmeticalOperatorType op, std::unique_ptr<Node> left, std::unique_ptr<Node> right) :
Node(NodeType::arithmetical_operator), op(op), left(std::move(left)), right(std::move(right)) {};
};
struct CreateTableNode : Node {
std::string table_name;
std::vector<ColDefNode> cols_defs;
@@ -145,12 +170,29 @@ struct SelectFromTableNode : Node {
std::vector<ColNameNode> cols_names;
std::unique_ptr<Node> where;
SelectFromTableNode(const std::string name, std::vector<ColNameNode> names, std::unique_ptr<Node> where_clause) :
SelectFromTableNode(std::string name, std::vector<ColNameNode> names, std::unique_ptr<Node> where_clause) :
Node(NodeType::select_from), table_name(name), cols_names(names), where(std::move(where_clause)) {}
};
struct UpdateTableNode : Node { };
struct DeleteFromTableNode : Node { };
struct UpdateTableNode : Node {
std::string table_name;
std::vector<ColNameNode> cols_names;
std::vector<std::unique_ptr<Node>> values;
std::unique_ptr<Node> where;
UpdateTableNode(std::string name, std::vector<ColNameNode> names, std::vector<std::unique_ptr<Node>> vals,
std::unique_ptr<Node> where_clause) :
Node(NodeType::update_table), table_name(name), cols_names(names), values(std::move(vals)), where(std::move(where_clause)) {}
};
struct DeleteFromTableNode : Node {
std::string table_name;
std::unique_ptr<Node> where;
DeleteFromTableNode(const std::string name, std::unique_ptr<Node> where_clause) :
Node(NodeType::delete_from), table_name(name), where(std::move(where_clause)) {}
};
@@ -167,11 +209,18 @@ private:
std::unique_ptr<Node> parse_create_table();
std::unique_ptr<Node> parse_insert_into_table();
std::unique_ptr<Node> parse_select_from_table();
std::unique_ptr<Node> parse_delete_from_table();
std::unique_ptr<Node> parse_update_table();
std::unique_ptr<Node> parse_where_clause();
std::unique_ptr<Node> parse_operand_node();
RelationalOperatorType parse_operator();
RelationalOperatorType parse_relational_operator();
LogicalOperatorType parse_logical_operator();
ArithmeticalOperatorType parse_arithmetical_operator();
private:
Lexer lexer;
std::unique_ptr<Node> parse_relational_expression();
};