From 9481abb42da5f2a0870520104b636daa87802e79 Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Tue, 15 Dec 2020 16:53:41 +0200 Subject: [PATCH 1/2] MXS-3318 Translate newlines in stmts given to compare A \n encounted in a string given to the query classifier test program compare, is not converted into a newline. Makes it easier to debug problems related to newlines. --- query_classifier/test/compare.cc | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/query_classifier/test/compare.cc b/query_classifier/test/compare.cc index 7090f7789..613f5b48b 100644 --- a/query_classifier/test/compare.cc +++ b/query_classifier/test/compare.cc @@ -1530,6 +1530,7 @@ int main(int argc, char* argv[]) string classifier2Args("log_unrecognized_statements=1"); version = 10 * 1000 * 2 * 100; #endif + string statement; const char* zStatement = NULL; qc_sql_mode_t sql_mode = QC_SQL_MODE_DEFAULT; bool solo = false; @@ -1581,7 +1582,34 @@ int main(int argc, char* argv[]) break; case 's': - zStatement = optarg; + { + const char* z = optarg; + + while (*z) + { + switch (*z) + { + case '\\': + if (*(z + 1) == 'n') + { + statement += '\n'; + ++z; + } + else + { + statement += *z; + } + break; + + default: + statement += *z; + } + + ++z; + } + + zStatement = statement.c_str(); + } break; case 'm': From 2b8d5076e2637c1d982276536e259aeb49adddd8 Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Tue, 15 Dec 2020 16:55:34 +0200 Subject: [PATCH 2/2] MXS-3318 Fix problem When the tokenizer encounters a keyword, it sniffs whether the last non-whitespace character before it happens to be a '.' and if it is, the keyword is assumed to be the second part of a qualified name. Thus, before this commit -- blah. UPDATE ... would not be parsed as KEYWORD (UPDATE) followed by stuff, but as an ID (blah.UPDATE) followed by stuff. With this change, newlines are no longer counted as whitespace. --- query_classifier/qc_sqlite/sqlite-src-3110100/src/tokenize.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/query_classifier/qc_sqlite/sqlite-src-3110100/src/tokenize.c b/query_classifier/qc_sqlite/sqlite-src-3110100/src/tokenize.c index fc958424b..ebaee5fcc 100644 --- a/query_classifier/qc_sqlite/sqlite-src-3110100/src/tokenize.c +++ b/query_classifier/qc_sqlite/sqlite-src-3110100/src/tokenize.c @@ -679,7 +679,7 @@ int sqlite3GetToken(const unsigned char *z, int *tokenType){ if (pParse) { if (z != (const unsigned char *)pParse->zTail) { const char *p = (const char*)z - 1; - while ((p != pParse->zTail) && sqlite3Isspace(*p)) { + while ((p != pParse->zTail) && sqlite3Isspace(*p) && *p != '\n') { --p; }