moved prepare_* methods from dialect to query_utils
This commit is contained in:
@@ -22,59 +22,11 @@ const std::string &dialect::to_string(const bool val) const {
|
||||
return bool_strings_[static_cast<int>(val)];
|
||||
}
|
||||
|
||||
std::string dialect::to_sql_string(const utils::value &val) const {
|
||||
if (val.is_null()) {
|
||||
return "NULL";
|
||||
}
|
||||
if (val.is_string()) {
|
||||
return token_at(dialect_token::BeginStringData) + val.str() + token_at(dialect_token::BeginStringData);
|
||||
}
|
||||
|
||||
return val.str();
|
||||
}
|
||||
|
||||
void dialect::bool_strings(const std::string &true_string, const std::string &false_string) {
|
||||
bool_strings_[0] = false_string;
|
||||
bool_strings_[1] = true_string;
|
||||
}
|
||||
|
||||
std::string dialect::prepare_identifier_string(const std::string &col) const {
|
||||
auto parts = utils::split(col, '.');
|
||||
|
||||
for (auto &part: parts) {
|
||||
escape_quotes_in_identifier(part);
|
||||
quote_identifier(part);
|
||||
}
|
||||
return utils::join(parts, ".");
|
||||
}
|
||||
|
||||
std::string dialect::prepare_literal(const std::string &str) const {
|
||||
std::string result(str);
|
||||
escape_quotes_in_literals(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void dialect::quote_identifier(std::string &str) const {
|
||||
str.insert(0, token_at(dialect_token::StartQuote));
|
||||
str += token_at(dialect_token::EndQuote);
|
||||
}
|
||||
|
||||
void dialect::escape_quotes_in_identifier(std::string &str) const {
|
||||
const std::string open_char(token_at(dialect_token::StartQuote));
|
||||
const std::string close_char(token_at(dialect_token::EndQuote));
|
||||
if (identifier_escape_type() == escape_identifier_t::ESCAPE_CLOSING_BRACKET) {
|
||||
utils::replace_all(str, close_char, close_char + close_char);
|
||||
} else {
|
||||
utils::replace_all(str, open_char, open_char + open_char);
|
||||
}
|
||||
}
|
||||
|
||||
void dialect::escape_quotes_in_literals(std::string &str) const {
|
||||
const std::string single_quote(token_at(dialect_token::StringQuote));
|
||||
const std::string double_quote(token_at(dialect_token::StringQuote) + token_at(dialect_token::StringQuote));
|
||||
utils::replace_all(str, single_quote, double_quote);
|
||||
}
|
||||
|
||||
dialect::escape_identifier_t dialect::identifier_escape_type() const {
|
||||
return identifier_escape_type_;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user