ColNameNode removed, a bit more powerfull inserts etc

BEWARE insert into t (i) values(1+1) WILL FAIL - it is not "1" "+" "1" but "1" "+1"
This commit is contained in:
2021-08-13 16:34:51 +02:00
parent ee0cbf64ff
commit 6921421a65
5 changed files with 44440 additions and 74 deletions

View File

@@ -148,7 +148,7 @@ std::unique_ptr<Table> USql::execute_insert_into_table(InsertIntoTableNode &node
// copy values
for (size_t i = 0; i < node.cols_names.size(); i++) {
ColDefNode col_def = table_def->get_column_def(node.cols_names[i].name);
ColDefNode col_def = table_def->get_column_def(node.cols_names[i].col_name);
auto col_value = eval_value_node(table_def, new_row, node.cols_values[i].get());
new_row.setColumnValue(&col_def, col_value.get());
@@ -169,7 +169,7 @@ std::unique_ptr<Table> USql::execute_select(SelectFromTableNode &node) {
if (node.cols_names->size()==1 && node.cols_names->operator[](0).name == "*") {
node.cols_names->clear();
for(auto col : table->m_col_defs) {
node.cols_names->push_back(SelectColNode{std::move(std::make_unique<ColNameNode>(col.name)), col.name});
node.cols_names->push_back(SelectColNode{std::move(std::make_unique<DatabaseValueNode>(col.name)), col.name});
}
}
@@ -263,7 +263,7 @@ void USql::execute_offset_limit(OffsetLimitNode &node, Table *result) {
std::tuple<int, ColDefNode> USql::get_column_definition(Table *table, SelectColNode *select_col_node, int col_order ) {
std::string new_col_name = select_col_node->name;
if (select_col_node->value->node_type == NodeType::column_name) {
if (select_col_node->value->node_type == NodeType::database_value) {
ColDefNode src_cdef = table->get_column_def(new_col_name);
ColDefNode cdef = ColDefNode{new_col_name, src_cdef.type, col_order, src_cdef.length, src_cdef.null};
return std::make_tuple(src_cdef.order, cdef);
@@ -279,6 +279,11 @@ std::tuple<int, ColDefNode> USql::get_column_definition(Table *table, SelectColN
return std::make_tuple(-1, cdef);
}
throw Exception("Unsupported function");
} else if (select_col_node->value->node_type == NodeType::arithmetical_operator) {
// TODO return correct type
ColDefNode cdef = ColDefNode{new_col_name, ColumnType::float_type, col_order, 1, true};
return std::make_tuple(-1, cdef);
}
throw Exception("Unsupported node type");
}
@@ -313,7 +318,7 @@ std::unique_ptr<Table> USql::execute_update(UpdateTableNode &node) {
if (eval_where(node.where.get(), table, *row)) {
int i = 0;
for (const auto& col : node.cols_names) {
ColDefNode col_def = table->get_column_def(col.name); // TODO cache it like in select
ColDefNode col_def = table->get_column_def(col.col_name); // TODO cache it like in select
std::unique_ptr<ValueNode> new_val = eval_arithmetic_operator(col_def.type,
static_cast<ArithmeticalOperatorNode &>(*node.values[i]),
table, *row);
@@ -390,7 +395,7 @@ bool USql::eval_relational_operator(const RelationalOperatorNode &filter, Table
std::unique_ptr<ValueNode> USql::eval_value_node(Table *table, Row &row, Node *node) {
if (node->node_type == NodeType::database_value || node->node_type == NodeType::column_name) { // TODO sjednotit
if (node->node_type == NodeType::database_value) {
return eval_database_value_node(table, row, node);
} else if (node->node_type == NodeType::int_value || node->node_type == NodeType::float_value || node->node_type == NodeType::string_value || node->node_type == NodeType::bool_value) {
return eval_literal_value_node(table, row, node);
@@ -398,6 +403,9 @@ std::unique_ptr<ValueNode> USql::eval_value_node(Table *table, Row &row, Node *n
return eval_function_value_node(table, row, node);
} else if (node->node_type == NodeType::null_value) {
return std::make_unique<NullValueNode>();
} else if (node->node_type == NodeType::arithmetical_operator) {
// TODO correct type here
return eval_arithmetic_operator(ColumnType::float_type, static_cast<ArithmeticalOperatorNode &>(*node), table, row);
}
throw Exception("unsupported node type");
}