progress on in conditions with queries and enums
This commit is contained in:
+20
-2
@@ -1,5 +1,7 @@
|
||||
#include "matador/sql/condition.hpp"
|
||||
|
||||
#include "matador/sql/query_intermediates.hpp"
|
||||
|
||||
namespace matador::sql {
|
||||
|
||||
condition<column, placeholder, std::enable_if<true>::type>::condition(const column &fld, basic_condition::operand_t op, const placeholder &val)
|
||||
@@ -12,17 +14,33 @@ std::string condition<column, placeholder, std::enable_if<true>::type>::evaluate
|
||||
return d.prepare_identifier(field_) + " " + operand + " " + d.next_placeholder(query.bind_vars);
|
||||
}
|
||||
|
||||
condition<column, query_context>::condition(column col, basic_condition::operand_t op, query_context &q)
|
||||
condition<column, query_context>::condition(column col, basic_condition::operand_t op, const query_context &q)
|
||||
: basic_column_condition(std::move(col), op), query_(q)
|
||||
{}
|
||||
|
||||
std::string condition<column, query_context>::evaluate(const dialect &d, query_context &query) const
|
||||
{
|
||||
std::string result(d.prepare_identifier(field_) + " " + operand + " (");
|
||||
result += (")");
|
||||
result += query_.sql + (")");
|
||||
return result;
|
||||
}
|
||||
|
||||
condition<column, query_context> in( const column& col, const query_context &q ) {
|
||||
return {col, basic_condition::operand_t::IN_LIST, q};
|
||||
}
|
||||
|
||||
condition<column, query_context> in( const column& col, const query_select& q ) {
|
||||
return in(col, q.build());
|
||||
}
|
||||
|
||||
condition<column, std::string> like( const column& col, const std::string& val ) {
|
||||
return {col, basic_condition::operand_t::LIKE, val};
|
||||
}
|
||||
|
||||
condition<column, query_context> equals( const column& col, query_context& q ) {
|
||||
return {col, basic_condition::operand_t::EQUAL, q};
|
||||
}
|
||||
|
||||
condition<column, column> operator==(const column &a, const column &b)
|
||||
{
|
||||
return {a, basic_condition::operand_t::EQUAL, b};
|
||||
|
||||
@@ -91,7 +91,7 @@ size_t connection::execute(const std::string &sql) const
|
||||
return connection_->execute(sql);
|
||||
}
|
||||
|
||||
sql::query connection::query(const sql::schema &schema) const
|
||||
sql::query connection::query(const schema &schema) const
|
||||
{
|
||||
return sql::query(*const_cast<connection*>(this), schema);
|
||||
}
|
||||
|
||||
+2
-2
@@ -51,8 +51,8 @@ std::string dialect::prepare_literal(const std::string &str) const
|
||||
|
||||
void dialect::quote_identifier(std::string &str) const
|
||||
{
|
||||
str.insert(0, token_at(token_t::START_QUOTE));
|
||||
str += token_at(token_t::END_QUOTE);
|
||||
// str.insert(0, token_at(token_t::START_QUOTE));
|
||||
// str += token_at(token_t::END_QUOTE);
|
||||
}
|
||||
|
||||
void dialect::escape_quotes_in_identifier(std::string &str) const
|
||||
|
||||
@@ -54,7 +54,7 @@ void query_compiler::visit(query_select_part &select_part)
|
||||
void query_compiler::visit(query_from_part &from_part)
|
||||
{
|
||||
query_.table = from_part.table();
|
||||
if (dialect_.default_schema_name().empty()) {
|
||||
if (!dialect_.default_schema_name().empty()) {
|
||||
query_.sql += " " + dialect_.token_at(dialect::token_t::FROM) +
|
||||
" " + dialect_.prepare_identifier(from_part.table().name) +
|
||||
(from_part.table().alias.empty() ? "" : " AS " +
|
||||
|
||||
@@ -8,6 +8,13 @@ namespace matador::sql {
|
||||
schema::schema(std::string name)
|
||||
: name_(std::move(name)) {}
|
||||
|
||||
void schema::create(connection &c) {
|
||||
for (const auto &ti : repository_) {
|
||||
// ti.second.prototype
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
std::string schema::name() const
|
||||
{
|
||||
return name_;
|
||||
|
||||
Reference in New Issue
Block a user