usql/usql.h

52 lines
1.7 KiB
C++

#pragma once
#include "parser.h"
#include "table.h"
#include <string>
namespace usql {
class USql {
public:
USql() {};
std::unique_ptr<Table> execute(const std::string &command);
private:
std::unique_ptr<Table> execute(Node &node);
std::unique_ptr<Table> execute_create_table(CreateTableNode &node);
std::unique_ptr<Table> execute_create_table_as_table(CreateTableAsSelectNode &node);
std::unique_ptr<Table> execute_insert_into_table(InsertIntoTableNode &node);
std::unique_ptr<Table> execute_select(SelectFromTableNode &node);
std::unique_ptr<Table> execute_delete(DeleteFromTableNode &node);
std::unique_ptr<Table> execute_update(UpdateTableNode &node);
std::unique_ptr<Table> execute_load(LoadIntoTableNode &node);
private:
bool evalWhere(Node *where, Table *table, Row &row) const;
std::unique_ptr<ValueNode> evalValueNode(Table *table, Row &row, Node *node) const;
std::unique_ptr<ValueNode> evalDatabaseValueNode(Table *table, Row &row, Node *node) const;
std::unique_ptr<ValueNode> evalLiteralValueNode(Table *table, Row &row, Node *node) const;
std::unique_ptr<ValueNode> evalFunctionValueNode(Table *table, Row &row, Node *node) const;
bool evalRelationalOperator(const RelationalOperatorNode &filter, Table *table, Row &row) const;
bool evalLogicalOperator(LogicalOperatorNode &node, Table *pTable, Row &row) const;
std::unique_ptr<ValueNode> evalArithmeticOperator(ColumnType outType, ArithmeticalOperatorNode &node, Table *table, Row &row) const;
std::unique_ptr<Table> create_stmt_result_table(int code, std::string text);
Table *find_table(const std::string name);
private:
Parser m_parser;
std::vector<Table> m_tables;
};
} // namespace