column_expression progress
This commit is contained in:
@@ -25,7 +25,7 @@ const criteria_value& binary_criteria::value() const {
|
||||
return value_;
|
||||
}
|
||||
|
||||
binary_column_criteria::binary_column_criteria(const table_column& left_column, const binary_operator operand, const table_column& right_column)
|
||||
binary_column_criteria::binary_column_criteria(table_column left_column, const binary_operator operand, table_column right_column)
|
||||
: left_column_(std::move(left_column))
|
||||
, operator_(operand)
|
||||
, right_column_(std::move(right_column)){}
|
||||
|
||||
@@ -4,6 +4,10 @@ namespace matador::query {
|
||||
column_expression::column_expression(column_expression_ptr expr) noexcept
|
||||
: expression_(std::move(expr)) {}
|
||||
|
||||
column_expression::column_expression(utils::placeholder /*p*/)
|
||||
: expression_(std::make_unique<placeholder_expression>()){
|
||||
}
|
||||
|
||||
bool column_expression::empty() const noexcept {
|
||||
return !expression_;
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
#include "matador/query/expression/expression_visitor.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
table_column_expression::table_column_expression(const table_column& col)
|
||||
: column_(col){
|
||||
table_column_expression::table_column_expression(table_column col)
|
||||
: column_(std::move(col)){
|
||||
}
|
||||
|
||||
void table_column_expression::accept(expression_visitor &visitor) const {
|
||||
|
||||
@@ -54,4 +54,8 @@ void expression_evaluator::visit(const placeholder_expression& /*node*/) {
|
||||
query_.bind_vars.emplace_back(std::string("value_") + std::to_string(query_.bind_vars.size() + 1));
|
||||
expression_.append(dialect_.next_placeholder(query_.bind_vars));
|
||||
}
|
||||
|
||||
const std::string& expression_evaluator::result() const {
|
||||
return expression_;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,21 +9,20 @@ query_update_intermediate::query_update_intermediate(const table& tab) {
|
||||
context_->parts.push_back(std::make_unique<internal::query_update_part>(tab));
|
||||
}
|
||||
|
||||
// query_set_intermediate query_update_intermediate::set(const std::initializer_list<internal::column_value_pair> columns) {
|
||||
// return set(std::vector<internal::column_value_pair>{columns});
|
||||
// }
|
||||
|
||||
// query_set_intermediate query_update_intermediate::set(std::vector<internal::column_value_pair> &&columns) {
|
||||
// context_->parts.push_back(std::make_unique<internal::query_set_part>(std::move(columns)));
|
||||
// return {context_};
|
||||
// }
|
||||
query_update_intermediate& query_update_intermediate::set(const table_column &col, column_expression&& expression) {
|
||||
key_value_pairs_.emplace_back(col, std::move(expression));
|
||||
if (query_set_part_ == nullptr) {
|
||||
std::vector<internal::column_value_pair> key_value_pairs;
|
||||
key_value_pairs.emplace_back(col, std::move(expression));
|
||||
auto ptr = std::make_unique<internal::query_set_part>(std::move(key_value_pairs));
|
||||
query_set_part_ = ptr.get();
|
||||
context_->parts.push_back(std::move(ptr));
|
||||
} else {
|
||||
const_cast<std::vector<internal::column_value_pair>&>(query_set_part_->column_values()).emplace_back(col, std::move(expression));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
query_execute_where_intermediate query_update_intermediate::where(std::unique_ptr<abstract_criteria> cond) {
|
||||
context_->parts.push_back(std::make_unique<internal::query_set_part>(std::move(key_value_pairs_)));
|
||||
return where_clause(std::move(cond));
|
||||
}
|
||||
|
||||
@@ -31,4 +30,9 @@ query_execute_where_intermediate query_update_intermediate::where_clause(std::un
|
||||
context_->parts.push_back(std::make_unique<internal::query_where_part>(std::move(cond)));
|
||||
return {context_};
|
||||
}
|
||||
|
||||
query_set_intermediate query_update_intermediate::set(std::vector<internal::column_value_pair>&& key_value_pairs) {
|
||||
context_->parts.push_back(std::make_unique<internal::query_set_part>(std::move(key_value_pairs)));
|
||||
return {context_};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "matador/query/query_builder.hpp"
|
||||
|
||||
#include "matador/query/attribute_string_writer.hpp"
|
||||
#include "matador/query/expression_evaluator.hpp"
|
||||
#include "matador/query/query_data.hpp"
|
||||
#include "matador/query/criteria_evaluator.hpp"
|
||||
#include "matador/query/query_utils.hpp"
|
||||
@@ -218,6 +219,14 @@ struct value_visitor {
|
||||
internal::basic_type_to_string_visitor value_to_string_visitor;
|
||||
};
|
||||
|
||||
std::string query_builder::determine_value(const sql::dialect &d, sql::query_context& ctx, const abstract_column_expression &exp) {
|
||||
attribute_string_writer writer(d, {});
|
||||
expression_evaluator v(d, ctx);
|
||||
exp.accept(v);
|
||||
|
||||
return v.result();
|
||||
}
|
||||
|
||||
std::string query_builder::determine_value(value_visitor &visitor, const std::variant<utils::placeholder, utils::database_type> &val) {
|
||||
std::visit(visitor, val);
|
||||
return visitor.value_to_string_visitor.result;
|
||||
@@ -334,25 +343,36 @@ void query_builder::visit(internal::query_set_part &part) {
|
||||
query_.sql += " " + dialect_->set() + " ";
|
||||
|
||||
attribute_string_writer writer(*dialect_, connection_);
|
||||
std::string result;
|
||||
// std::string result;
|
||||
|
||||
value_visitor visitor(writer, query_); if (part.column_values().size() < 2) {
|
||||
for (const auto &column_value: part.column_values()) {
|
||||
result.append(dialect_->prepare_identifier_string(column_value.col().name()) + "=");
|
||||
result.append(determine_value(visitor, column_value.value()));
|
||||
}
|
||||
} else {
|
||||
auto it = part.column_values().begin();
|
||||
result.append(dialect_->prepare_identifier_string(it->col().name()) + "=");
|
||||
result.append(determine_value(visitor, (it++)->value()));
|
||||
for (; it != part.column_values().end(); ++it) {
|
||||
result.append(", ");
|
||||
result.append(dialect_->prepare_identifier_string(it->col().name()) + "=");
|
||||
result.append(determine_value(visitor, it->value()));
|
||||
value_visitor visitor(writer, query_);
|
||||
bool first = true;
|
||||
for (const auto& column_value : part.column_values()) {
|
||||
if (!first) {
|
||||
query_.sql.append(", ");
|
||||
}
|
||||
query_.sql.append(dialect_->prepare_identifier_string(column_value.col().name()) + "=");
|
||||
query_.sql.append(determine_value(*dialect_,query_, column_value.expression()));
|
||||
first = false;
|
||||
}
|
||||
|
||||
query_.sql += result;
|
||||
// if (part.column_values().size() < 2) {
|
||||
// for (const auto &column_value: part.column_values()) {
|
||||
// result.append(dialect_->prepare_identifier_string(column_value.col().name()) + "=");
|
||||
// result.append(determine_value(visitor, column_value.value()));
|
||||
// }
|
||||
// } else {
|
||||
// auto it = part.column_values().begin();
|
||||
// result.append(dialect_->prepare_identifier_string(it->col().name()) + "=");
|
||||
// result.append(determine_value(visitor, (it++)->value()));
|
||||
// for (; it != part.column_values().end(); ++it) {
|
||||
// result.append(", ");
|
||||
// result.append(dialect_->prepare_identifier_string(it->col().name()) + "=");
|
||||
// result.append(determine_value(visitor, it->value()));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// query_.sql += result;
|
||||
}
|
||||
|
||||
void query_builder::visit(internal::query_drop_sequence_part& part) {
|
||||
|
||||
Reference in New Issue
Block a user