diff --git a/lib/c_tokenizer.c b/lib/c_tokenizer.c index 55ff8172a..4f6085907 100644 --- a/lib/c_tokenizer.c +++ b/lib/c_tokenizer.c @@ -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; diff --git a/test/tap/tests/test_tokenizer-t.cpp b/test/tap/tests/test_tokenizer-t.cpp index 39b3bc40f..a1ef73f88 100644 --- a/test/tap/tests/test_tokenizer-t.cpp +++ b/test/tap/tests/test_tokenizer-t.cpp @@ -51,7 +51,15 @@ const std::vector 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 exp_results { @@ -86,7 +94,15 @@ const std::vector 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 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(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()); } }