implemented prepared statement for postgres and sqlite
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "matador/sql/types.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
@@ -12,7 +13,7 @@ namespace matador::sql {
|
||||
|
||||
class column;
|
||||
|
||||
class dialect
|
||||
class dialect final
|
||||
{
|
||||
public:
|
||||
enum class token_t : uint8_t
|
||||
@@ -65,14 +66,11 @@ public:
|
||||
using data_type_to_string_map = std::unordered_map<data_type_t, std::string>;
|
||||
using sql_func_to_string_map = std::unordered_map<sql_function_t, std::string>;
|
||||
|
||||
public:
|
||||
dialect() = default;
|
||||
dialect(const token_to_string_map &token_replace_map, const data_type_to_string_map &data_type_replace_map);
|
||||
explicit dialect(const data_type_to_string_map &data_type_replace_map);
|
||||
explicit dialect(const token_to_string_map &token_replace_map);
|
||||
using next_placeholder_func = std::function<std::string(size_t)>;
|
||||
|
||||
const std::string& token_at(token_t token) const;
|
||||
const std::string& data_type_at(data_type_t type) const;
|
||||
public:
|
||||
[[nodiscard]] const std::string& token_at(token_t token) const;
|
||||
[[nodiscard]] const std::string& data_type_at(data_type_t type) const;
|
||||
|
||||
/**
|
||||
* Prepare sql dialect identifier for execution
|
||||
@@ -82,14 +80,14 @@ public:
|
||||
* @param str The identifier string to be prepared
|
||||
* @return The prepared string
|
||||
*/
|
||||
std::string prepare_identifier(const column &col) const;
|
||||
[[nodiscard]] std::string prepare_identifier(const column &col) const;
|
||||
|
||||
/**
|
||||
* Prepare string literal
|
||||
*
|
||||
* @param str String literal to be prepared
|
||||
*/
|
||||
std::string prepare_literal(const std::string &str) const;
|
||||
[[nodiscard]] std::string prepare_literal(const std::string &str) const;
|
||||
|
||||
/**
|
||||
* Wrap identifier quotes around a sql identifier keyword
|
||||
@@ -118,7 +116,7 @@ public:
|
||||
*
|
||||
* @return How the identifier quotes should be escaped
|
||||
*/
|
||||
virtual escape_identifier_t identifier_escape_type() const;
|
||||
[[nodiscard]] virtual escape_identifier_t identifier_escape_type() const;
|
||||
|
||||
/**
|
||||
* Generates a next placeholder string. default is
|
||||
@@ -126,17 +124,24 @@ public:
|
||||
*
|
||||
* @return Placeholder string
|
||||
*/
|
||||
virtual std::string next_placeholder() const;
|
||||
[[nodiscard]] std::string next_placeholder(const std::vector<std::string> &bind_vars) const;
|
||||
|
||||
void add_host_var(const std::string &host_var);
|
||||
void add_column(const std::string &column);
|
||||
|
||||
const std::vector<std::string>& host_vars() const;
|
||||
const std::vector<std::string>& columns() const;
|
||||
/**
|
||||
* Returns the default schema name.
|
||||
*
|
||||
* @return The default schema name.
|
||||
*/
|
||||
[[nodiscard]] std::string default_schema_name() const;
|
||||
|
||||
private:
|
||||
std::vector<std::string> host_vars_;
|
||||
std::vector<std::string> columns_;
|
||||
dialect() = default;
|
||||
|
||||
private:
|
||||
friend class dialect_builder;
|
||||
|
||||
next_placeholder_func placeholder_func_ = [](size_t) { return "?"; };
|
||||
|
||||
std::string default_schema_name_;
|
||||
|
||||
token_to_string_map tokens_ {
|
||||
{token_t::CREATE, "CREATE"},
|
||||
|
||||
Reference in New Issue
Block a user