column, placeholder and column_value generator progress
This commit is contained in:
@@ -74,7 +74,7 @@ void session_query_builder::append_join(const sql::column &left, const sql::colu
|
||||
using namespace matador::query;
|
||||
entity_query_data_.joins.push_back({
|
||||
{right.table_},
|
||||
left == right
|
||||
std::make_unique<binary_column_criteria>(left, binary_operator::EQUALS, right)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,31 @@
|
||||
#include "matador/query/generator.hpp"
|
||||
|
||||
namespace matador::query::generator {
|
||||
column_generator2::column_generator2( const std::string& table_name, const column_generator_options options)
|
||||
: options_(options) {
|
||||
table_stack_.push(table_name.empty() ? std::make_shared<sql::table>() : std::make_shared<sql::table>(table_name));
|
||||
}
|
||||
|
||||
column_generator2::column_generator2(const object::repository& repo, const std::string& table_name, const column_generator_options options)
|
||||
: repo_(std::cref(repo))
|
||||
, options_(options) {
|
||||
table_stack_.push(table_name.empty() ? std::make_shared<sql::table>() : std::make_shared<sql::table>(table_name));
|
||||
}
|
||||
|
||||
void column_generator2::on_revision( const char* id, uint64_t& ) {
|
||||
push(id);
|
||||
}
|
||||
|
||||
void column_generator2::push( const std::string& column_name ) {
|
||||
if (is_column_generator_option_set(options_, column_generator_options::GenerateAlias)) {
|
||||
char str[4];
|
||||
snprintf(str, 4, "c%02d", ++column_index);
|
||||
result_.emplace_back(table_stack_.top(), column_name, str);
|
||||
} else {
|
||||
result_.emplace_back(table_stack_.top(), column_name);
|
||||
}
|
||||
}
|
||||
|
||||
void placeholder_generator::on_revision(const char* /*id*/, uint64_t&) {
|
||||
result_.emplace_back(utils::_);
|
||||
}
|
||||
|
||||
@@ -5,29 +5,37 @@
|
||||
namespace matador::query::internal {
|
||||
|
||||
column_value_pair::column_value_pair(std::string name, utils::database_type value)
|
||||
: name_(std::move(name))
|
||||
: column_(std::move(name))
|
||||
, value_(std::move(value)) {
|
||||
}
|
||||
|
||||
column_value_pair::column_value_pair(const sql::column &col, utils::database_type value)
|
||||
: name_(col.name)
|
||||
: column_(col)
|
||||
, value_(std::move(value)) {
|
||||
}
|
||||
|
||||
column_value_pair::column_value_pair(const char *name, utils::database_type value)
|
||||
: name_(name)
|
||||
: column_(name)
|
||||
, value_(std::move(value)) {
|
||||
}
|
||||
|
||||
column_value_pair::column_value_pair( const char* name, utils::placeholder p )
|
||||
: name_(name)
|
||||
: column_(name)
|
||||
, value_(p) {}
|
||||
|
||||
const std::string &column_value_pair::name() const {
|
||||
return name_;
|
||||
const sql::column &column_value_pair::col() const {
|
||||
return column_;
|
||||
}
|
||||
|
||||
const std::variant<utils::placeholder, utils::database_type>& column_value_pair::value() const {
|
||||
return value_;
|
||||
}
|
||||
|
||||
bool operator==( const column_value_pair& lhs, const column_value_pair& rhs ) {
|
||||
return lhs.column_.equals(rhs.column_) && lhs.value_ == rhs.value_;
|
||||
}
|
||||
|
||||
bool operator!=( const column_value_pair& lhs, const column_value_pair& rhs ) {
|
||||
return !( lhs == rhs );
|
||||
}
|
||||
}
|
||||
@@ -304,7 +304,7 @@ query_set_part::query_set_part(const std::vector<column_value_pair>& key_value_p
|
||||
: query_part(sql::dialect_token::Set)
|
||||
, key_value_pairs_(key_value_pairs) {}
|
||||
|
||||
const std::vector<column_value_pair> &query_set_part::key_values() const
|
||||
const std::vector<column_value_pair> &query_set_part::column_values() const
|
||||
{
|
||||
return key_value_pairs_;
|
||||
}
|
||||
|
||||
@@ -363,18 +363,18 @@ void query_compiler::visit(internal::query_set_part &part) {
|
||||
attribute_string_writer writer(*dialect_, connection_);
|
||||
std::string result;
|
||||
|
||||
value_visitor visitor(writer, query_); if (part.key_values().size() < 2) {
|
||||
for (const auto &col: part.key_values()) {
|
||||
result.append(dialect_->prepare_identifier_string(col.name()) + "=");
|
||||
result.append(determine_value(visitor, col.value()));
|
||||
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.key_values().begin();
|
||||
result.append(dialect_->prepare_identifier_string(it->name()) + "=");
|
||||
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.key_values().end(); ++it) {
|
||||
for (; it != part.column_values().end(); ++it) {
|
||||
result.append(", ");
|
||||
result.append(dialect_->prepare_identifier_string(it->name()) + "=");
|
||||
result.append(dialect_->prepare_identifier_string(it->col().name) + "=");
|
||||
result.append(determine_value(visitor, it->value()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user