Refactored remove_quotes function

pull/5149/head
Rahim Kanji 7 months ago
parent 8f8a8c29e3
commit 83bec8d477

@ -36,6 +36,7 @@ class PgSQL_Set_Stmt_Parser {
std::map<std::string, std::vector<std::string>> parse1v2();
void generateRE_parse1v2();
std::string remove_comments(const std::string& q);
static void unquote_if_quoted(std::string& v);
};
#endif /* __CLASS_PGSQL_SET_STMT_PARSER_H */

@ -3936,19 +3936,6 @@ bool PgSQL_Session::is_multi_statement_command(const char* cmd) {
return false;
}
static void remove_quotes(string& v) {
if (v.length() > 2) {
char firstChar = v[0];
char lastChar = v[v.length() - 1];
if (firstChar == lastChar) {
if (firstChar == '\'' || firstChar == '"' || firstChar == '`') {
v.erase(v.length() - 1, 1);
v.erase(0, 1);
}
}
}
}
bool PgSQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___handle_SET_command(const char* dig, bool* lock_hostgroup) {
// this code is executed only if locked_on_hostgroup is not set yet
// if locked_on_hostgroup is set, we do not try to parse the SET statement
@ -4013,11 +4000,7 @@ bool PgSQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___handle_
if (idx != PGSQL_NAME_LAST_HIGH_WM) {
if (IS_PGTRACKED_VAR_OPTION_SET_NO_STRIP_VALUE(pgsql_tracked_variables[idx]) == 0) {
if (value1 == "''" || value1 == "\"\"") {
value1.clear();
} else {
remove_quotes(value1);
}
PgSQL_Set_Stmt_Parser::unquote_if_quoted(value1);
}
uint32_t current_hash = pgsql_variables.client_get_hash(this, idx);

@ -20,19 +20,6 @@
using namespace std;
static void remove_quotes(string& v) {
if (v.length() > 2) {
char firstChar = v[0];
char lastChar = v[v.length()-1];
if (firstChar == lastChar) {
if (firstChar == '\'' || firstChar == '"' || firstChar == '`') {
v.erase(v.length()-1, 1);
v.erase(0, 1);
}
}
}
}
#ifdef PARSERDEBUG
PgSQL_Set_Stmt_Parser::PgSQL_Set_Stmt_Parser(std::string nq, int verb) {
verbosity = verb;
@ -93,6 +80,18 @@ VALGRIND_DISABLE_ERROR_REPORTING;
parse1v2_init = true;
}
void PgSQL_Set_Stmt_Parser::unquote_if_quoted(std::string& v) {
if (v.length() >= 2) {
char firstChar = v[0];
char lastChar = v[v.length() - 1];
if (firstChar == lastChar) {
if (firstChar == '\'' || firstChar == '"' || firstChar == '`') {
v.erase(v.length() - 1, 1);
v.erase(0, 1);
}
}
}
}
std::map<std::string,std::vector<std::string>> PgSQL_Set_Stmt_Parser::parse1v2() {
@ -123,32 +122,24 @@ VALGRIND_ENABLE_ERROR_REPORTING;
else oper = "";
proxy_debug(PROXY_DEBUG_MYSQL_QUERY_PROCESSOR, 4, "SET parsing: scope='%s', parameter name='%s' , operator='%s' , parameter value='%s' , parameter_value_func='%s' , parameter_value_func_args='%s'\n", scope.c_str(), param_name.c_str(), oper.c_str(), param_val.c_str(), param_val_func.c_str(), param_val_func_args.c_str());
#endif // DEBUG
std::string key;
if (param_val_func.empty() == false) return {};
if (param_name.empty() || param_val.empty()) {
continue;
}
key = param_name;
remove_quotes(key);
unquote_if_quoted(param_name);
size_t pos = param_val.find_last_not_of(" \n\r\t,");
if (pos != param_val.npos) {
param_val.erase(pos+1);
param_val.erase(pos + 1);
}
/*
if (param_val == "''" || param_val == "\"\"") {
op.emplace_back("");
} else {
remove_quotes(param_val);
op.emplace_back(param_val);
}*/
if (param_name.empty() || param_val.empty()) {
continue;
}
op.emplace_back(param_val);
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
result[key] = op;
std::transform(param_name.begin(), param_name.end(), param_name.begin(), ::tolower);
result[param_name] = op;
}
if (input.size() != 0) {
#ifdef PARSERDEBUG

Loading…
Cancel
Save