#pragma once #include "parser.h" #include "table.h" #include #include namespace usql { class USql { public: USql() = default; std::unique_ptr execute(const std::string &command); private: std::unique_ptr
execute(Node &node); std::unique_ptr
execute_create_table(CreateTableNode &node); std::unique_ptr
execute_create_table_as_table(CreateTableAsSelectNode &node); std::unique_ptr
execute_load(LoadIntoTableNode &node); std::unique_ptr
execute_save(SaveTableNode &node); std::unique_ptr
execute_drop(DropTableNode &node); static std::unique_ptr
execute_set(SetNode &node); static std::unique_ptr
execute_show(ShowNode &node); std::unique_ptr
execute_insert_into_table(InsertIntoTableNode &node); std::unique_ptr
execute_select(SelectFromTableNode &node); std::unique_ptr
execute_delete(DeleteFromTableNode &node); std::unique_ptr
execute_update(UpdateTableNode &node); private: static bool eval_where(Node *where, Table *table, Row &row) ; static std::unique_ptr eval_value_node(Table *table, Row &row, Node *node, ColDefNode *col_def_node, ColValue *agg_func_value); static std::unique_ptr eval_database_value_node(Table *table, Row &row, Node *node); static std::unique_ptr eval_literal_value_node(Table *table, Row &row, Node *node); static std::unique_ptr eval_function_value_node(Table *table, Row &row, Node *node, ColDefNode *col_def_node, ColValue *agg_func_value); static bool eval_relational_operator(const RelationalOperatorNode &filter, Table *table, Row &row); static bool eval_logical_operator(LogicalOperatorNode &node, Table *pTable, Row &row); static std::unique_ptr eval_arithmetic_operator(ColumnType outType, ArithmeticalOperatorNode &node, Table *table, Row &row); static std::unique_ptr
create_stmt_result_table(long code, const std::string &text, size_t affected_rows); static std::tuple get_column_definition(Table *table, SelectColNode *select_col_node, int col_order); static ColDefNode get_db_column_definition(Table *table, Node *node); static std::tuple get_node_definition(Table *table, Node *select_col_node, const std::string & col_name, int col_order); Table *find_table(const std::string &name); void check_table_not_exists(const std::string &name); private: Parser m_parser; std::list
m_tables; static void execute_distinct(SelectFromTableNode &node, Table *result) ; static void execute_order_by(SelectFromTableNode &node, Table *table, Table *result) ; static void execute_offset_limit(OffsetLimitNode &node, Table *result) ; void expand_asterix_char(SelectFromTableNode &node, Table *table) const; void setup_order_columns(std::vector &node, Table *table) const; bool check_for_aggregate_only_functions(SelectFromTableNode &node, int result_cols_cnt) const; static std::unique_ptr lower_function(const std::vector> &evaluatedPars); static std::unique_ptr upper_function(const std::vector> &evaluatedPars); static std::unique_ptr to_date_function(const std::vector> &evaluatedPars); static std::unique_ptr to_string_function(const std::vector> &evaluatedPars); static std::unique_ptr pp_function(const std::vector> &evaluatedPars); static std::unique_ptr max_function(const std::vector> &evaluatedPars, const ColDefNode *col_def_node, ColValue *agg_func_value); static std::unique_ptr min_function(const std::vector> &evaluatedPars, const ColDefNode *col_def_node, ColValue *agg_func_value); static std::unique_ptr count_function(ColValue *agg_func_value, const std::vector> &evaluatedPars); }; } // namespace