query progress
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
#ifndef QUERY_ANY_TYPE_TO_STRING_VISITOR_HPP
|
||||
#define QUERY_ANY_TYPE_TO_STRING_VISITOR_HPP
|
||||
|
||||
#include "matador/utils/types.hpp"
|
||||
|
||||
#include "matador/sql/placeholder.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace matador::sql {
|
||||
|
||||
class dialect;
|
||||
class query_context;
|
||||
|
||||
struct any_type_to_string_visitor
|
||||
{
|
||||
explicit any_type_to_string_visitor(const dialect &d, query_context &query);
|
||||
|
||||
void operator()(char &x) { to_string(x); }
|
||||
void operator()(short &x) { to_string(x); }
|
||||
void operator()(int &x) { to_string(x); }
|
||||
void operator()(long &x) { to_string(x); }
|
||||
void operator()(long long &x) { to_string(x); }
|
||||
void operator()(unsigned char &x) { to_string(x); }
|
||||
void operator()(unsigned short &x) { to_string(x); }
|
||||
void operator()(unsigned int &x) { to_string(x); }
|
||||
void operator()(unsigned long &x) { to_string(x); }
|
||||
void operator()(unsigned long long &x) { to_string(x); }
|
||||
void operator()(bool &x) { to_string(x); }
|
||||
void operator()(float &x) { to_string(x); }
|
||||
void operator()(double &x) { to_string(x); }
|
||||
void operator()(const char *x) { to_string(x); }
|
||||
void operator()(std::string &x) { to_string(x); }
|
||||
void operator()(utils::blob &x) { to_string(x); }
|
||||
void operator()(placeholder &x) { to_string(x); }
|
||||
|
||||
template<typename Type>
|
||||
void to_string(Type &val)
|
||||
{
|
||||
result = std::to_string(val);
|
||||
}
|
||||
void to_string(const char *val);
|
||||
void to_string(std::string &val);
|
||||
void to_string(utils::blob &val);
|
||||
void to_string(placeholder &val);
|
||||
|
||||
const dialect &d;
|
||||
query_context &query;
|
||||
std::string result;
|
||||
};
|
||||
|
||||
}
|
||||
#endif //QUERY_ANY_TYPE_TO_STRING_VISITOR_HPP
|
||||
@@ -41,6 +41,7 @@ private:
|
||||
void visit(query_set_part &set_part) override;
|
||||
|
||||
void visit(query_delete_part &delete_part) override;
|
||||
void visit(query_delete_from_part &delete_from_part) override;
|
||||
|
||||
void visit(query_create_part &create_part) override;
|
||||
void visit(query_create_table_part &create_table_part) override;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define QUERY_QUERY_CONTEXT_HPP
|
||||
|
||||
#include "matador/sql/record.hpp"
|
||||
#include "matador/sql/table.hpp"
|
||||
|
||||
namespace matador::sql {
|
||||
|
||||
@@ -9,7 +10,7 @@ struct query_context
|
||||
{
|
||||
std::string sql;
|
||||
std::string command_name;
|
||||
std::string table_name;
|
||||
sql::table table{""};
|
||||
record prototype;
|
||||
std::vector<std::string> result_vars;
|
||||
std::vector<std::string> bind_vars;
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
#ifndef QUERY_QUERY_HELPER_HPP
|
||||
#define QUERY_QUERY_HELPER_HPP
|
||||
|
||||
#include "matador/utils/macro_map.hpp"
|
||||
|
||||
#include "matador/sql/table.hpp"
|
||||
#include "matador/sql/column.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <ostream>
|
||||
|
||||
#define FIELD(x) const sql::column x{this->name, #x, ""};
|
||||
|
||||
#define QUERY_HELPER(C, ...) \
|
||||
namespace matador::qh { \
|
||||
namespace internal { \
|
||||
struct C##_query : sql::table { \
|
||||
C##_query() : table(#C) {} \
|
||||
MAP(FIELD, __VA_ARGS__) \
|
||||
}; } \
|
||||
static const internal:: C##_query C; \
|
||||
}
|
||||
|
||||
#endif //QUERY_QUERY_HELPER_HPP
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
|
||||
size_t execute();
|
||||
statement prepare();
|
||||
[[nodiscard]] std::string str() const;
|
||||
[[nodiscard]] query_context build() const;
|
||||
};
|
||||
|
||||
class query_select_finish : public query_intermediate
|
||||
@@ -72,7 +72,7 @@ public:
|
||||
|
||||
statement prepare();
|
||||
|
||||
[[nodiscard]] std::string str() const;
|
||||
[[nodiscard]] query_context build() const;
|
||||
|
||||
private:
|
||||
std::unique_ptr<query_result_impl> fetch();
|
||||
@@ -275,7 +275,7 @@ class query_execute_where_intermediate : public query_execute_finish
|
||||
public:
|
||||
using query_execute_finish::query_execute_finish;
|
||||
|
||||
query_execute_finish limit(int limit);
|
||||
query_order_by_intermediate order_by(const column &col);
|
||||
};
|
||||
|
||||
class query_set_intermediate : public query_execute_finish
|
||||
|
||||
@@ -16,6 +16,8 @@ public:
|
||||
virtual ~query_part() = default;
|
||||
virtual void accept(query_part_visitor &visitor) = 0;
|
||||
|
||||
[[nodiscard]] dialect::token_t token() const;
|
||||
|
||||
protected:
|
||||
sql::dialect::token_t token_;
|
||||
};
|
||||
|
||||
@@ -20,6 +20,7 @@ class query_values_part;
|
||||
class query_update_part;
|
||||
class query_set_part;
|
||||
class query_delete_part;
|
||||
class query_delete_from_part;
|
||||
class query_create_part;
|
||||
class query_create_table_part;
|
||||
class query_drop_part;
|
||||
@@ -50,6 +51,7 @@ public:
|
||||
virtual void visit(query_set_part &set_part) = 0;
|
||||
|
||||
virtual void visit(query_delete_part &delete_part) = 0;
|
||||
virtual void visit(query_delete_from_part &delete_from_part) = 0;
|
||||
|
||||
virtual void visit(query_create_part &create_part) = 0;
|
||||
virtual void visit(query_create_table_part &create_table_part) = 0;
|
||||
|
||||
@@ -157,7 +157,7 @@ class query_offset_part : public query_part
|
||||
public:
|
||||
explicit query_offset_part(size_t offset);
|
||||
|
||||
size_t offset() const;
|
||||
[[nodiscard]] size_t offset() const;
|
||||
|
||||
private:
|
||||
void accept(query_part_visitor &visitor) override;
|
||||
@@ -171,7 +171,7 @@ class query_limit_part : public query_part
|
||||
public:
|
||||
explicit query_limit_part(size_t limit);
|
||||
|
||||
size_t limit() const;
|
||||
[[nodiscard]] size_t limit() const;
|
||||
|
||||
private:
|
||||
void accept(query_part_visitor &visitor) override;
|
||||
@@ -210,7 +210,7 @@ private:
|
||||
class query_values_part : public query_part
|
||||
{
|
||||
public:
|
||||
query_values_part(std::vector<any_type> &&values);
|
||||
explicit query_values_part(std::vector<any_type> &&values);
|
||||
|
||||
[[nodiscard]] const std::vector<any_type>& values() const;
|
||||
|
||||
@@ -258,6 +258,20 @@ private:
|
||||
void accept(query_part_visitor &visitor) override;
|
||||
};
|
||||
|
||||
class query_delete_from_part : public query_part
|
||||
{
|
||||
public:
|
||||
query_delete_from_part(sql::table table);
|
||||
|
||||
[[nodiscard]] const sql::table& table() const;
|
||||
|
||||
private:
|
||||
void accept(query_part_visitor &visitor) override;
|
||||
|
||||
private:
|
||||
sql::table table_;
|
||||
};
|
||||
|
||||
class query_create_part : public query_part
|
||||
{
|
||||
public:
|
||||
@@ -273,7 +287,7 @@ public:
|
||||
query_create_table_part(sql::table table, std::vector<sql::column_definition> columns);
|
||||
|
||||
[[nodiscard]] const sql::table& table() const;
|
||||
const std::vector<sql::column_definition>& columns() const;
|
||||
[[nodiscard]] const std::vector<sql::column_definition>& columns() const;
|
||||
|
||||
private:
|
||||
void accept(query_part_visitor &visitor) override;
|
||||
|
||||
@@ -17,8 +17,8 @@ struct table_info
|
||||
{
|
||||
std::string name;
|
||||
record prototype;
|
||||
void create(connection &conn) const;
|
||||
void drop(connection &conn) const;
|
||||
void create(connection &conn, schema &scm) const;
|
||||
void drop(connection &conn, schema &scm) const;
|
||||
};
|
||||
|
||||
class schema
|
||||
|
||||
Reference in New Issue
Block a user