Merge pull request #3117 from sysown/v2.1.0-3115

Closes #3115: Fix removal of spaces before closing parenthesis for query digests
pull/3130/head
René Cannaò 6 years ago committed by GitHub
commit 4970ec9d62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -354,7 +354,7 @@ char *mysql_query_digest_and_first_comment(char *s, int _len, char **first_comme
continue;
}
// supress spaces before closing brakets
if (p >= r && (*s == ')')) {
if (p >= r && *p == '.' && is_space_char(prev_char) && (*s == ')')) {
prev_char = *s;
--p_r;
*p_r++ = *s;

@ -51,7 +51,15 @@ const std::vector<std::string> queries {
"SELECT * FROM tablename WHERE id IN (1,2,3,4,5,6,7,8,9,10)",
"SELECT * FROM tablename WHERE id IN (1,2,3,4)",
// invalid request grouping
"SELECT * tablename where id IN (1,2,3,4,5,6,7,8, AND j in (1,2,3,4,5,6 and k=1"
"SELECT * tablename where id IN (1,2,3,4,5,6,7,8, AND j in (1,2,3,4,5,6 and k=1",
// random insert queries
"INSERT INTO db.table(col1) VALUES ('val')",
"INSERT INTO db.table (col1) VALUES ('val')",
"INSERT INTO db.table( col1) VALUES ( 'val' )",
"INSERT INTO db.table( col1) VALUES ( 'val' )",
"INSERT INTO db.table ( col1 ) VALUES ( 'val' )",
"INSERT INTO db.table (col1, col2,col3,col4) VALUES ('val',2,3,'foo')",
"INSERT INTO db.table ( col1, col2,col3,col4 ) VALUES ('val',2,3,'foo')"
};
const std::vector<std::string> exp_results {
@ -86,7 +94,15 @@ const std::vector<std::string> exp_results {
"SELECT * FROM tablename WHERE id IN (?,?,?,...)",
"SELECT * FROM tablename WHERE id IN (?,?,?,...)",
// invalid request grouping
"SELECT * tablename where id IN (?,?,?,... AND j in (?,?,?,... and k=?"
"SELECT * tablename where id IN (?,?,?,... AND j in (?,?,?,... and k=?",
// random insert queries
"INSERT INTO db.table(col1) VALUES (?)",
"INSERT INTO db.table (col1) VALUES (?)",
"INSERT INTO db.table( col1) VALUES ( ? )",
"INSERT INTO db.table( col1) VALUES ( ? )",
"INSERT INTO db.table ( col1 ) VALUES ( ? )",
"INSERT INTO db.table (col1,col2,col3,col4) VALUES (?,?,?,?)",
"INSERT INTO db.table ( col1,col2,col3,col4 ) VALUES (?,?,?,?)"
};
const std::vector<std::string> queries_grouping {
@ -167,10 +183,10 @@ int main(int argc, char** argv) {
const auto& query = queries_grouping[i];
const auto& exp_res = increase_mark_num(exp_queries_grouping[i], j);
char* c_res = mysql_query_digest_and_first_comment(const_cast<char*>(query.c_str()), query.length(), NULL, buf);
std::string result(c_res);
ok(result == exp_res, "Grouping digest should be equal to exp result: '%s' == '%s'", result.c_str(), exp_res.c_str());
}
}

Loading…
Cancel
Save