|
|
|
|
@ -12,7 +12,7 @@ SetParser::SetParser(std::string nq) {
|
|
|
|
|
memcpy(query_no_space,nq.c_str(),query_no_space_length);
|
|
|
|
|
query_no_space[query_no_space_length]='\0';
|
|
|
|
|
query_no_space_length=remove_spaces(query_no_space);
|
|
|
|
|
query = string(query_no_space);
|
|
|
|
|
query = std::string(query_no_space);
|
|
|
|
|
free(query_no_space);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -21,7 +21,7 @@ SetParser::SetParser(std::string nq) {
|
|
|
|
|
#define NAMES "(NAMES)"
|
|
|
|
|
#define NAME_VALUE "((?:\\w|\\d)+)"
|
|
|
|
|
|
|
|
|
|
std::map<std::string,std::vector<string>> SetParser::parse1() {
|
|
|
|
|
std::map<std::string,std::vector<std::string>> SetParser::parse1() {
|
|
|
|
|
|
|
|
|
|
proxy_debug(PROXY_DEBUG_MYSQL_QUERY_PROCESSOR, 4, "Parsing query %s\n", query.c_str());
|
|
|
|
|
re2::RE2::Options *opt2=new re2::RE2::Options(RE2::Quiet);
|
|
|
|
|
@ -31,7 +31,7 @@ std::map<std::string,std::vector<string>> SetParser::parse1() {
|
|
|
|
|
re2::RE2 re0("^\\s*SET\\s+", *opt2);
|
|
|
|
|
re2::RE2::Replace(&query, re0, "");
|
|
|
|
|
|
|
|
|
|
std::map<std::string,std::vector<string>> result;
|
|
|
|
|
std::map<std::string,std::vector<std::string>> result;
|
|
|
|
|
|
|
|
|
|
#define SESSION_P1 "(?:|SESSION +|@@|@@session.)"
|
|
|
|
|
#define VAR_P1 "(\\w+)"
|
|
|
|
|
@ -39,19 +39,19 @@ std::map<std::string,std::vector<string>> SetParser::parse1() {
|
|
|
|
|
//#define VAR_VALUE "((?:CONCAT\\((?:(REPLACE|CONCAT)\\()+@@sql_mode,(?:(?:'|\\w|,| |\"|\\))+(?:\\)))|(?:[@\\w/\\d:\\+\\-]|,)+|(?:)))"
|
|
|
|
|
#define VAR_VALUE_P1 "(((?:CONCAT\\()*(?:((?: )*REPLACE|IFNULL|CONCAT)\\()+(?: )*(?:NULL|@OLD_SQL_MODE|@@sql_mode),(?:(?:'|\\w|,| |\"|\\))+(?:\\))*)|(?:[@\\w/\\d:\\+\\-]|,)+|(?:)))"
|
|
|
|
|
|
|
|
|
|
const string pattern="(?:" NAMES SPACES QUOTES NAME_VALUE QUOTES "(?: +COLLATE +" QUOTES NAME_VALUE QUOTES "|)" "|" SESSION_P1 VAR_P1 SPACES "(?:|:)=" SPACES QUOTES VAR_VALUE_P1 QUOTES ") *,? *";
|
|
|
|
|
const std::string pattern="(?:" NAMES SPACES QUOTES NAME_VALUE QUOTES "(?: +COLLATE +" QUOTES NAME_VALUE QUOTES "|)" "|" SESSION_P1 VAR_P1 SPACES "(?:|:)=" SPACES QUOTES VAR_VALUE_P1 QUOTES ") *,? *";
|
|
|
|
|
VALGRIND_DISABLE_ERROR_REPORTING;
|
|
|
|
|
re2::RE2 re(pattern, *opt2);
|
|
|
|
|
VALGRIND_ENABLE_ERROR_REPORTING;
|
|
|
|
|
string var;
|
|
|
|
|
string value1, value2, value3, value4, value5;
|
|
|
|
|
std::string var;
|
|
|
|
|
std::string value1, value2, value3, value4, value5;
|
|
|
|
|
re2::StringPiece input(query);
|
|
|
|
|
while (re2::RE2::Consume(&input, re, &value1, &value2, &value3, &value4, &value5)) {
|
|
|
|
|
std::vector<std::string> op;
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
proxy_debug(PROXY_DEBUG_MYSQL_QUERY_PROCESSOR, 4, "SET parsing: v1='%s' , v2='%s' , v3='%s' , v4='%s' , v5='%s'\n", value1.c_str(), value2.c_str(), value3.c_str(), value4.c_str(), value5.c_str());
|
|
|
|
|
#endif // DEBUG
|
|
|
|
|
string key;
|
|
|
|
|
std::string key;
|
|
|
|
|
if (value1 != "") {
|
|
|
|
|
// NAMES
|
|
|
|
|
key = value1;
|
|
|
|
|
@ -74,7 +74,7 @@ VALGRIND_ENABLE_ERROR_REPORTING;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::map<std::string,std::vector<string>> SetParser::parse2() {
|
|
|
|
|
std::map<std::string,std::vector<std::string>> SetParser::parse2() {
|
|
|
|
|
|
|
|
|
|
proxy_debug(PROXY_DEBUG_MYSQL_QUERY_PROCESSOR, 4, "Parsing query %s\n", query.c_str());
|
|
|
|
|
re2::RE2::Options *opt2=new re2::RE2::Options(RE2::Quiet);
|
|
|
|
|
@ -84,7 +84,7 @@ std::map<std::string,std::vector<string>> SetParser::parse2() {
|
|
|
|
|
re2::RE2 re0("^\\s*SET\\s+", *opt2);
|
|
|
|
|
re2::RE2::Replace(&query, re0, "");
|
|
|
|
|
|
|
|
|
|
std::map<std::string,std::vector<string>> result;
|
|
|
|
|
std::map<std::string,std::vector<std::string>> result;
|
|
|
|
|
|
|
|
|
|
// regex used:
|
|
|
|
|
// SET(?: +)(|SESSION +)TRANSACTION(?: +)(?:(?:(ISOLATION(?: +)LEVEL)(?: +)(REPEATABLE(?: +)READ|READ(?: +)COMMITTED|READ(?: +)UNCOMMITTED|SERIALIZABLE))|(?:(READ)(?: +)(WRITE|ONLY)))
|
|
|
|
|
@ -95,18 +95,18 @@ std::map<std::string,std::vector<string>> SetParser::parse2() {
|
|
|
|
|
//#define VAR_VALUE "((?:CONCAT\\((?:(REPLACE|CONCAT)\\()+@@sql_mode,(?:(?:'|\\w|,| |\"|\\))+(?:\\)))|(?:[@\\w/\\d:\\+\\-]|,)+|(?:)))"
|
|
|
|
|
#define VAR_VALUE_P2 "(((?:CONCAT\\()*(?:((?: )*REPLACE|IFNULL|CONCAT)\\()+(?: )*(?:NULL|@OLD_SQL_MODE|@@sql_mode),(?:(?:'|\\w|,| |\"|\\))+(?:\\))*)|(?:[@\\w/\\d:\\+\\-]|,)+|(?:)))"
|
|
|
|
|
*/
|
|
|
|
|
//const string pattern="(?:" NAMES SPACES QUOTES NAME_VALUE QUOTES "(?: +COLLATE +" QUOTES NAME_VALUE QUOTES "|)" "|" SESSION_P1 VAR_P1 SPACES "(?:|:)=" SPACES QUOTES VAR_VALUE_P1 QUOTES ") *,? *";
|
|
|
|
|
const string pattern="(|SESSION) *TRANSACTION(?: +)(?:(?:(ISOLATION(?: +)LEVEL)(?: +)(REPEATABLE(?: +)READ|READ(?: +)COMMITTED|READ(?: +)UNCOMMITTED|SERIALIZABLE))|(?:(READ)(?: +)(WRITE|ONLY)))";
|
|
|
|
|
//const std::string pattern="(?:" NAMES SPACES QUOTES NAME_VALUE QUOTES "(?: +COLLATE +" QUOTES NAME_VALUE QUOTES "|)" "|" SESSION_P1 VAR_P1 SPACES "(?:|:)=" SPACES QUOTES VAR_VALUE_P1 QUOTES ") *,? *";
|
|
|
|
|
const std::string pattern="(|SESSION) *TRANSACTION(?: +)(?:(?:(ISOLATION(?: +)LEVEL)(?: +)(REPEATABLE(?: +)READ|READ(?: +)COMMITTED|READ(?: +)UNCOMMITTED|SERIALIZABLE))|(?:(READ)(?: +)(WRITE|ONLY)))";
|
|
|
|
|
re2::RE2 re(pattern, *opt2);
|
|
|
|
|
string var;
|
|
|
|
|
string value1, value2, value3, value4, value5;
|
|
|
|
|
std::string var;
|
|
|
|
|
std::string value1, value2, value3, value4, value5;
|
|
|
|
|
re2::StringPiece input(query);
|
|
|
|
|
while (re2::RE2::Consume(&input, re, &value1, &value2, &value3, &value4, &value5)) {
|
|
|
|
|
std::vector<std::string> op;
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
proxy_debug(PROXY_DEBUG_MYSQL_QUERY_PROCESSOR, 4, "SET parsing: v1='%s' , v2='%s' , v3='%s' , v4='%s' , v5='%s'\n", value1.c_str(), value2.c_str(), value3.c_str(), value4.c_str(), value5.c_str());
|
|
|
|
|
#endif // DEBUG
|
|
|
|
|
string key;
|
|
|
|
|
std::string key;
|
|
|
|
|
if (value1 != "") { // session is specified
|
|
|
|
|
if (value2 != "") { // isolation level
|
|
|
|
|
key = value2;
|
|
|
|
|
@ -135,12 +135,12 @@ std::string SetParser::parse_character_set() {
|
|
|
|
|
re2::RE2 re0("^\\s*SET\\s+", *opt2);
|
|
|
|
|
re2::RE2::Replace(&query, re0, "");
|
|
|
|
|
|
|
|
|
|
std::map<std::string,std::vector<string>> result;
|
|
|
|
|
std::map<std::string,std::vector<std::string>> result;
|
|
|
|
|
|
|
|
|
|
const string pattern="((charset)|(character +set))(?: )(?:'?)([^'|\\s]*)(?:'?)";
|
|
|
|
|
const std::string pattern="((charset)|(character +set))(?: )(?:'?)([^'|\\s]*)(?:'?)";
|
|
|
|
|
re2::RE2 re(pattern, *opt2);
|
|
|
|
|
string var;
|
|
|
|
|
string value1, value2, value3, value4;
|
|
|
|
|
std::string var;
|
|
|
|
|
std::string value1, value2, value3, value4;
|
|
|
|
|
re2::StringPiece input(query);
|
|
|
|
|
re2::RE2::Consume(&input, re, &value1, &value2, &value3, &value4);
|
|
|
|
|
|
|
|
|
|
|