usql update
This commit is contained in:
441
usql/parser.h
441
usql/parser.h
@@ -6,21 +6,22 @@
|
||||
#include "settings.h"
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
static const int FUNCTION_CALL = -1;
|
||||
|
||||
namespace usql {
|
||||
|
||||
enum class ColumnType {
|
||||
enum class ColumnType {
|
||||
integer_type,
|
||||
float_type,
|
||||
varchar_type,
|
||||
date_type,
|
||||
bool_type
|
||||
};
|
||||
};
|
||||
|
||||
enum class NodeType {
|
||||
enum class NodeType {
|
||||
true_node,
|
||||
null_value,
|
||||
int_value,
|
||||
@@ -39,173 +40,232 @@ namespace usql {
|
||||
load_table,
|
||||
save_table,
|
||||
drop_table,
|
||||
create_index,
|
||||
set,
|
||||
show,
|
||||
database_value,
|
||||
offset_limit,
|
||||
column_order,
|
||||
column_value,
|
||||
function,
|
||||
column_def,
|
||||
error
|
||||
};
|
||||
};
|
||||
|
||||
struct Node {
|
||||
struct Node {
|
||||
NodeType node_type;
|
||||
|
||||
explicit Node(const NodeType type) : node_type(type) {}
|
||||
virtual ~Node() = default;
|
||||
};
|
||||
|
||||
virtual void dump() const {
|
||||
std::cout << "type: Node" << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct ColOrderNode : Node {
|
||||
struct ColOrderNode : Node {
|
||||
std::string col_name;
|
||||
int col_index;
|
||||
bool ascending;
|
||||
|
||||
ColOrderNode(const std::string& name, bool asc) : Node(NodeType::column_order), col_name(name), col_index(-1), ascending(asc) {}
|
||||
ColOrderNode(int index, bool asc) : Node(NodeType::database_value), col_name(""), col_index(index), ascending(asc) {}
|
||||
};
|
||||
ColOrderNode(std::string name, bool asc) : Node(NodeType::column_order), col_name(std::move(name)), col_index(-1), ascending(asc) {}
|
||||
ColOrderNode(int index, bool asc) : Node(NodeType::database_value), col_index(index), ascending(asc) {}
|
||||
|
||||
void dump() const override {
|
||||
std::cout << "type: ColOrderNode, col_name: " << col_name << ", col_index: " << col_index << ", asc: " << ascending << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct OffsetLimitNode : Node {
|
||||
|
||||
struct OffsetLimitNode : Node {
|
||||
int offset;
|
||||
int limit;
|
||||
|
||||
OffsetLimitNode(int off, int lim) : Node(NodeType::offset_limit), offset(off), limit(lim) {}
|
||||
};
|
||||
|
||||
void dump() const override {
|
||||
std::cout << "type: OffsetLimitNode, offset: " << offset << ", limit: " << limit << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct SelectColNode : Node {
|
||||
std::unique_ptr<Node> value;
|
||||
std::string name;
|
||||
struct SelectColNode : Node {
|
||||
std::unique_ptr<Node> value;
|
||||
std::string name;
|
||||
|
||||
SelectColNode(std::unique_ptr<Node> column, const std::string &alias) :
|
||||
Node(NodeType::database_value), value(std::move(column)), name(alias) {}
|
||||
};
|
||||
SelectColNode(std::unique_ptr<Node> column, std::string alias) :
|
||||
Node(NodeType::database_value), value(std::move(column)), name(std::move(alias)) {}
|
||||
|
||||
struct ColDefNode : Node {
|
||||
void dump() const override {
|
||||
std::cout << "type: SelectColNode, name:" << name << "value:" << std::endl;
|
||||
value->dump();
|
||||
}
|
||||
};
|
||||
|
||||
struct ColDefNode : Node {
|
||||
std::string name;
|
||||
ColumnType type;
|
||||
int order;
|
||||
int length;
|
||||
bool null;
|
||||
|
||||
ColDefNode(const std::string& col_name, ColumnType col_type, int col_order, int col_len, bool nullable) :
|
||||
Node(NodeType::column_def), name(col_name), type(col_type), order(col_order), length(col_len),
|
||||
null(nullable) {}
|
||||
};
|
||||
ColDefNode(std::string col_name, ColumnType col_type, int col_order, int col_len, bool nullable) :
|
||||
Node(NodeType::column_def), name(std::move(col_name)), type(col_type), order(col_order), length(col_len),
|
||||
null(nullable) {}
|
||||
|
||||
struct FunctionNode : Node {
|
||||
std::string function; // TODO use enum
|
||||
std::vector<std::unique_ptr<Node>> params;
|
||||
void dump() const override {
|
||||
std::cout << "type: ColDefNode, name: " << name << ", type: " << (int)type << " TODO add more" << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
FunctionNode(const std::string& func_name, std::vector<std::unique_ptr<Node>> pars) :
|
||||
Node(NodeType::function), function(func_name), params(std::move(pars)) {}
|
||||
};
|
||||
struct FunctionNode : Node {
|
||||
std::string function; // TODO use enum
|
||||
std::vector<std::unique_ptr<Node>> params;
|
||||
|
||||
struct TrueNode : Node {
|
||||
FunctionNode(std::string func_name, std::vector<std::unique_ptr<Node>> pars) :
|
||||
Node(NodeType::function), function(std::move(func_name)), params(std::move(pars)) {}
|
||||
|
||||
void dump() const override {
|
||||
std::cout << "type: FunctionNode, function: " << function << " TODO add more" << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
struct TrueNode : Node {
|
||||
TrueNode() : Node(NodeType::true_node) {}
|
||||
};
|
||||
|
||||
struct ValueNode : Node {
|
||||
void dump() const override {
|
||||
std::cout << "type: TrueNode," << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
struct ValueNode : Node {
|
||||
explicit ValueNode(NodeType type) : Node(type) {}
|
||||
|
||||
virtual bool isNull() { return false; }
|
||||
virtual long getIntegerValue() = 0;
|
||||
virtual double getDoubleValue() = 0;
|
||||
virtual std::string getStringValue() = 0;
|
||||
virtual long getDateValue() = 0;
|
||||
virtual bool getBooleanValue() = 0;
|
||||
virtual bool isNull() const { return false; }
|
||||
virtual long getIntegerValue() const = 0;
|
||||
virtual double getDoubleValue() const = 0;
|
||||
virtual std::string getStringValue() const = 0;
|
||||
virtual long getDateValue() const = 0;
|
||||
virtual bool getBooleanValue() const = 0;
|
||||
|
||||
virtual ~ValueNode() = default;
|
||||
};
|
||||
~ValueNode() override = default;
|
||||
};
|
||||
|
||||
struct NullValueNode : ValueNode {
|
||||
struct NullValueNode : ValueNode {
|
||||
|
||||
NullValueNode() : ValueNode(NodeType::null_value) {}
|
||||
NullValueNode() : ValueNode(NodeType::null_value) {}
|
||||
|
||||
bool isNull() override { return true; }
|
||||
bool isNull() const override { return true; }
|
||||
|
||||
long getIntegerValue() override { throw Exception("getIntegerValue not supported on NullValueNode"); };
|
||||
double getDoubleValue() override { throw Exception("getDoubleValue not supported on NullValueNode"); };
|
||||
std::string getStringValue() override { throw Exception("getStringValue not supported on NullValueNode"); };
|
||||
long getDateValue() override { throw Exception("getDateValue not supported on NullValueNode"); };
|
||||
bool getBooleanValue() override { throw Exception("getBooleanValue not supported on NullValueNode"); };
|
||||
};
|
||||
long getIntegerValue() const override { throw Exception("getIntegerValue not supported on NullValueNode"); };
|
||||
double getDoubleValue() const override { throw Exception("getDoubleValue not supported on NullValueNode"); };
|
||||
std::string getStringValue() const override { throw Exception("getStringValue not supported on NullValueNode"); };
|
||||
long getDateValue() const override { throw Exception("getDateValue not supported on NullValueNode"); };
|
||||
bool getBooleanValue() const override { throw Exception("getBooleanValue not supported on NullValueNode"); };
|
||||
|
||||
struct IntValueNode : ValueNode {
|
||||
void dump() const override {
|
||||
std::cout << "type: NullValueNode," << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
struct IntValueNode : ValueNode {
|
||||
long value;
|
||||
|
||||
explicit IntValueNode(long value) : ValueNode(NodeType::int_value), value(value) {}
|
||||
|
||||
long getIntegerValue() override { return value; };
|
||||
double getDoubleValue() override { return (double) value; };
|
||||
std::string getStringValue() override { return Settings::int_to_string(value); }
|
||||
long getDateValue() override { return value; };
|
||||
bool getBooleanValue() override { return value != 0; };
|
||||
};
|
||||
long getIntegerValue() const override { return value; };
|
||||
double getDoubleValue() const override { return (double) value; };
|
||||
std::string getStringValue() const override { return Settings::long_to_string(value); }
|
||||
long getDateValue() const override { return value; };
|
||||
bool getBooleanValue() const override { return value != 0; };
|
||||
|
||||
struct DoubleValueNode : ValueNode {
|
||||
void dump() const override {
|
||||
std::cout << "type: IntValueNode, value: " << value << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
struct DoubleValueNode : ValueNode {
|
||||
double value;
|
||||
|
||||
explicit DoubleValueNode(double value) : ValueNode(NodeType::float_value), value(value) {}
|
||||
|
||||
long getIntegerValue() override { return (long) value; };
|
||||
double getDoubleValue() override { return value; };
|
||||
std::string getStringValue() override { return Settings::double_to_string(value); }
|
||||
long getDateValue() override { return (long) value; };
|
||||
bool getBooleanValue() override { return value != 0.0; };
|
||||
};
|
||||
long getIntegerValue() const override { return (long) value; };
|
||||
double getDoubleValue() const override { return value; };
|
||||
std::string getStringValue() const override { return Settings::double_to_string(value); }
|
||||
long getDateValue() const override { return (long) value; };
|
||||
bool getBooleanValue() const override { return value != 0.0; };
|
||||
|
||||
struct StringValueNode : ValueNode {
|
||||
void dump() const override {
|
||||
std::cout << "type: DoubleValueNode, value: " << value << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
struct StringValueNode : ValueNode {
|
||||
std::string value;
|
||||
|
||||
explicit StringValueNode(const std::string &value) : ValueNode(NodeType::string_value), value(value) {}
|
||||
explicit StringValueNode(std::string value) : ValueNode(NodeType::string_value), value(std::move(value)) {}
|
||||
|
||||
long getIntegerValue() override { return Settings::string_to_int(value); };
|
||||
double getDoubleValue() override { return Settings::string_to_double(value); };
|
||||
std::string getStringValue() override { return value; };
|
||||
long getDateValue() override { return Settings::string_to_date(value); };
|
||||
bool getBooleanValue() override { return Settings::string_to_bool(value); };
|
||||
};
|
||||
long getIntegerValue() const override { return Settings::string_to_long(value); };
|
||||
double getDoubleValue() const override { return Settings::string_to_double(value); };
|
||||
std::string getStringValue() const override { return value; };
|
||||
long getDateValue() const override { return Settings::string_to_date(value); };
|
||||
bool getBooleanValue() const override { return Settings::string_to_bool(value); };
|
||||
|
||||
struct BooleanValueNode : ValueNode {
|
||||
bool value;
|
||||
void dump() const override {
|
||||
std::cout << "type: StringValueNode, value: " << value << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
explicit BooleanValueNode(bool value) : ValueNode(NodeType::bool_value), value(value) {}
|
||||
struct BooleanValueNode : ValueNode {
|
||||
bool value;
|
||||
|
||||
long getIntegerValue() override { return (long) value; };
|
||||
double getDoubleValue() override { return (double) value; };
|
||||
std::string getStringValue() override { return Settings::bool_to_string(value); }
|
||||
long getDateValue() override { return (long) value; };
|
||||
bool getBooleanValue() override { return value; };
|
||||
};
|
||||
explicit BooleanValueNode(bool value) : ValueNode(NodeType::bool_value), value(value) {}
|
||||
|
||||
long getIntegerValue() const override { return (long) value; };
|
||||
double getDoubleValue() const override { return (double) value; };
|
||||
std::string getStringValue() const override { return Settings::bool_to_string(value); }
|
||||
long getDateValue() const override { return (long) value; };
|
||||
bool getBooleanValue() const override { return value; };
|
||||
|
||||
void dump() const override {
|
||||
std::cout << "type: BooleanValueNode, value: " << value << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct DatabaseValueNode : Node {
|
||||
struct DatabaseValueNode : Node {
|
||||
std::string col_name;
|
||||
|
||||
explicit DatabaseValueNode(const std::string &name) : Node(NodeType::database_value), col_name(name) {}
|
||||
};
|
||||
explicit DatabaseValueNode(std::string name) : Node(NodeType::database_value), col_name(std::move(name)) {}
|
||||
|
||||
enum class LogicalOperatorType {
|
||||
void dump() const override {
|
||||
std::cout << "type: DatabaseValueNode, col_name: " << col_name << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
enum class LogicalOperatorType {
|
||||
and_operator,
|
||||
or_operator,
|
||||
not_operator
|
||||
};
|
||||
or_operator
|
||||
// not_operator
|
||||
};
|
||||
|
||||
struct LogicalOperatorNode : Node {
|
||||
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)) {};
|
||||
};
|
||||
Node(NodeType::logical_operator), op(op), left(std::move(left)), right(std::move(right)) {};
|
||||
|
||||
enum class RelationalOperatorType {
|
||||
void dump() const override {
|
||||
std::cout << "type: LogicalOperatorNode, op: " << (int)op << std::endl;
|
||||
left->dump();
|
||||
right->dump();
|
||||
}
|
||||
};
|
||||
|
||||
enum class RelationalOperatorType {
|
||||
equal,
|
||||
greater,
|
||||
greater_equal,
|
||||
@@ -215,54 +275,74 @@ namespace usql {
|
||||
is,
|
||||
is_not
|
||||
// like
|
||||
};
|
||||
};
|
||||
|
||||
struct RelationalOperatorNode : Node {
|
||||
struct RelationalOperatorNode : Node {
|
||||
RelationalOperatorType op;
|
||||
|
||||
std::unique_ptr<Node> left;
|
||||
std::unique_ptr<Node> right;
|
||||
|
||||
RelationalOperatorNode(RelationalOperatorType op, std::unique_ptr<Node> left, std::unique_ptr<Node> right) :
|
||||
Node(NodeType::relational_operator), op(op), left(std::move(left)), right(std::move(right)) {};
|
||||
};
|
||||
Node(NodeType::relational_operator), op(op), left(std::move(left)), right(std::move(right)) {};
|
||||
|
||||
enum class ArithmeticalOperatorType {
|
||||
void dump() const override {
|
||||
std::cout << "type: RelationalOperatorNode, op: " << (int)op << std::endl;
|
||||
left->dump();
|
||||
right->dump();
|
||||
}
|
||||
};
|
||||
|
||||
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 {
|
||||
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)) {};
|
||||
};
|
||||
Node(NodeType::arithmetical_operator), op(op), left(std::move(left)), right(std::move(right)) {};
|
||||
|
||||
struct CreateTableNode : Node {
|
||||
void dump() const override {
|
||||
std::cout << "type: ArithmeticalOperatorNode, op: " << (int)op << std::endl;
|
||||
left->dump();
|
||||
right->dump();
|
||||
}
|
||||
};
|
||||
|
||||
struct CreateTableNode : Node {
|
||||
std::string table_name;
|
||||
std::vector<ColDefNode> cols_defs;
|
||||
|
||||
CreateTableNode(const std::string& name, std::vector<ColDefNode> defs) :
|
||||
Node(NodeType::create_table), table_name(name), cols_defs(std::move(defs)) {}
|
||||
};
|
||||
CreateTableNode(std::string name, std::vector<ColDefNode> defs) :
|
||||
Node(NodeType::create_table), table_name(std::move(name)), cols_defs(std::move(defs)) {}
|
||||
|
||||
struct InsertIntoTableNode : Node {
|
||||
void dump() const override {
|
||||
std::cout << "type: CreateTableNode, table_name: " << table_name << "TODO complete me" << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
struct InsertIntoTableNode : Node {
|
||||
std::string table_name;
|
||||
std::vector<DatabaseValueNode> cols_names;
|
||||
std::vector<std::unique_ptr<Node>> cols_values;
|
||||
|
||||
InsertIntoTableNode(const std::string& name, std::vector<DatabaseValueNode> names, std::vector<std::unique_ptr<Node>> values) :
|
||||
Node(NodeType::insert_into), table_name(name), cols_names(std::move(names)), cols_values(std::move(values)) {}
|
||||
};
|
||||
InsertIntoTableNode(std::string name, std::vector<DatabaseValueNode> names, std::vector<std::unique_ptr<Node>> values) :
|
||||
Node(NodeType::insert_into), table_name(std::move(name)), cols_names(std::move(names)), cols_values(std::move(values)) {}
|
||||
|
||||
struct SelectFromTableNode : Node {
|
||||
void dump() const override {
|
||||
std::cout << "type: InsertIntoTableNode, table_name: " << table_name << "TODO complete me" << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
struct SelectFromTableNode : Node {
|
||||
std::string table_name;
|
||||
std::unique_ptr<std::vector<SelectColNode>> cols_names;
|
||||
std::unique_ptr<Node> where;
|
||||
@@ -271,84 +351,134 @@ namespace usql {
|
||||
bool distinct;
|
||||
|
||||
SelectFromTableNode(std::string name, std::unique_ptr<std::vector<SelectColNode>> names, std::unique_ptr<Node> where_clause, std::vector<ColOrderNode> orderby, OffsetLimitNode offlim, bool distinct_):
|
||||
Node(NodeType::select_from), table_name(std::move(name)), cols_names(std::move(names)), where(std::move(where_clause)), order_by(std::move(orderby)), offset_limit(offlim), distinct(distinct_) {}
|
||||
};
|
||||
Node(NodeType::select_from), table_name(std::move(name)), cols_names(std::move(names)), where(std::move(where_clause)), order_by(std::move(orderby)), offset_limit(std::move(offlim)), distinct(distinct_) {}
|
||||
|
||||
struct CreateTableAsSelectNode : Node {
|
||||
std::string table_name;
|
||||
std::unique_ptr<Node> select_table;
|
||||
void dump() const override {
|
||||
std::cout << "type: SelectFromTableNode, table_name: " << table_name << "TODO complete me" << std::endl;
|
||||
where->dump();
|
||||
}
|
||||
};
|
||||
|
||||
CreateTableAsSelectNode(const std::string& name, std::unique_ptr<Node> table) :
|
||||
Node(NodeType::create_table_as_select), table_name(name), select_table(std::move(table)) {}
|
||||
};
|
||||
struct CreateTableAsSelectNode : Node {
|
||||
std::string table_name;
|
||||
std::unique_ptr<Node> select_table;
|
||||
|
||||
struct UpdateTableNode : Node {
|
||||
CreateTableAsSelectNode(std::string name, std::unique_ptr<Node> table) :
|
||||
Node(NodeType::create_table_as_select), table_name(std::move(name)), select_table(std::move(table)) {}
|
||||
|
||||
void dump() const override {
|
||||
std::cout << "type: CreateTableAsSelectNode, table_name: " << table_name << std::endl;
|
||||
select_table->dump();
|
||||
}
|
||||
};
|
||||
|
||||
struct UpdateTableNode : Node {
|
||||
std::string table_name;
|
||||
std::vector<DatabaseValueNode> cols_names;
|
||||
std::vector<std::unique_ptr<Node>> values;
|
||||
std::unique_ptr<Node> where;
|
||||
|
||||
UpdateTableNode(const std::string &name, std::vector<DatabaseValueNode> names, std::vector<std::unique_ptr<Node>> vals,
|
||||
UpdateTableNode(std::string name, std::vector<DatabaseValueNode> 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)) {}
|
||||
};
|
||||
Node(NodeType::update_table), table_name(std::move(name)), cols_names(std::move(names)), values(std::move(vals)),
|
||||
where(std::move(where_clause)) {}
|
||||
|
||||
struct LoadIntoTableNode : Node {
|
||||
void dump() const override {
|
||||
std::cout << "type: UpdateTableNode, table_name: " << table_name << "TODO complete me" << std::endl;
|
||||
where->dump();
|
||||
}
|
||||
};
|
||||
|
||||
struct LoadIntoTableNode : Node {
|
||||
std::string table_name;
|
||||
std::string filename;
|
||||
|
||||
LoadIntoTableNode(const std::string& name, const std::string &file) :
|
||||
Node(NodeType::load_table), table_name(name), filename(file) {}
|
||||
};
|
||||
LoadIntoTableNode(std::string name, std::string file) :
|
||||
Node(NodeType::load_table), table_name(std::move(name)), filename(std::move(file)) {}
|
||||
|
||||
struct SaveTableNode : Node {
|
||||
std::string table_name;
|
||||
std::string filename;
|
||||
void dump() const override {
|
||||
std::cout << "type: LoadIntoTableNode, table_name: " << table_name << ", filename" << filename << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
SaveTableNode(const std::string& name, const std::string &file) :
|
||||
Node(NodeType::save_table), table_name(name), filename(file) {}
|
||||
};
|
||||
struct SaveTableNode : Node {
|
||||
std::string table_name;
|
||||
std::string filename;
|
||||
|
||||
struct DropTableNode : Node {
|
||||
std::string table_name;
|
||||
SaveTableNode(std::string name, std::string file) :
|
||||
Node(NodeType::save_table), table_name(std::move(name)), filename(std::move(file)) {}
|
||||
|
||||
explicit DropTableNode(const std::string& name) : Node(NodeType::drop_table), table_name(name) {}
|
||||
};
|
||||
void dump() const override {
|
||||
std::cout << "type: SaveTableNode, table_name: " << table_name << ", filename" << filename << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
struct DeleteFromTableNode : Node {
|
||||
struct DropTableNode : Node {
|
||||
std::string table_name;
|
||||
|
||||
explicit DropTableNode(std::string name) : Node(NodeType::drop_table), table_name(std::move(name)) {}
|
||||
|
||||
void dump() const override {
|
||||
std::cout << "type: SelectFromTableNode, table_name: " << table_name << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
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)) {}
|
||||
};
|
||||
DeleteFromTableNode(std::string name, std::unique_ptr<Node> where_clause) :
|
||||
Node(NodeType::delete_from), table_name(std::move(name)), where(std::move(where_clause)) {}
|
||||
|
||||
struct SetNode : Node {
|
||||
void dump() const override {
|
||||
std::cout << "type: DeleteFromTableNode, table_name: " << table_name << std::endl;
|
||||
where->dump();
|
||||
}
|
||||
};
|
||||
|
||||
struct SetNode : Node {
|
||||
std::string name;
|
||||
std::string value;
|
||||
|
||||
SetNode(const std::string& name_, const std::string& value_) :
|
||||
Node(NodeType::set), name(name_), value(value_) {}
|
||||
};
|
||||
SetNode(std::string node_name, std::string node_value) :
|
||||
Node(NodeType::set), name(std::move(node_name)), value(std::move(node_value)) {}
|
||||
|
||||
struct ShowNode : Node {
|
||||
void dump() const override {
|
||||
std::cout << "type: SetNode, name: " << name << ", value: " << value << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
struct ShowNode : Node {
|
||||
std::string name;
|
||||
|
||||
explicit ShowNode(const std::string& name_) : Node(NodeType::show), name(name_) {}
|
||||
};
|
||||
explicit ShowNode(std::string node_name) : Node(NodeType::show), name(std::move(node_name)) {}
|
||||
|
||||
void dump() const override {
|
||||
std::cout << "type: ShowNode, name: " << name << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
struct CreateIndexNode : Node {
|
||||
std::string index_name;
|
||||
std::string table_name;
|
||||
std::string column_name;
|
||||
|
||||
class Parser {
|
||||
private:
|
||||
CreateIndexNode(std::string idx_name, std::string tbl_name, std::string col_name) :
|
||||
Node(NodeType::create_index), index_name(std::move(idx_name)), table_name(std::move(tbl_name)), column_name(std::move(col_name)) {}
|
||||
|
||||
public:
|
||||
void dump() const override {
|
||||
std::cout << "type: CreateIndexNode, table_name: " << table_name << ", index_name: " << index_name << ", column_name: " << column_name << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
class Parser {
|
||||
private:
|
||||
public:
|
||||
Parser();
|
||||
|
||||
std::unique_ptr<Node> parse(const std::string &code);
|
||||
|
||||
private:
|
||||
private:
|
||||
std::unique_ptr<Node> parse_create_table();
|
||||
std::unique_ptr<Node> parse_drop_table();
|
||||
std::unique_ptr<Node> parse_load_table();
|
||||
@@ -360,6 +490,7 @@ namespace usql {
|
||||
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_create_index();
|
||||
|
||||
std::vector<ColOrderNode> parse_order_by_clause();
|
||||
OffsetLimitNode parse_offset_limit_clause();
|
||||
@@ -373,8 +504,8 @@ namespace usql {
|
||||
LogicalOperatorType parse_logical_operator();
|
||||
ArithmeticalOperatorType parse_arithmetical_operator();
|
||||
|
||||
private:
|
||||
private:
|
||||
Lexer m_lexer;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user