From 776f199d016f5282373cdb416c95bb1c5a55922f Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Fri, 8 Jun 2018 11:44:40 +0300 Subject: [PATCH] MXS-1719 Treat # comments the same way as -- comments sqlite does not treat # as the start of a to-end-of-line comment. It cannot trivially be treated as such because at startup sqlite parses statements containing the #-character. Thus, only after sqlite has been initialized can it be treated the same way as --. --- query_classifier/qc_sqlite/qc_sqlite.cc | 20 ++++++++++++++----- .../sqlite-src-3110100/src/tokenize.c | 11 ++++++++-- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/query_classifier/qc_sqlite/qc_sqlite.cc b/query_classifier/qc_sqlite/qc_sqlite.cc index 30b6c0195..4ec882119 100644 --- a/query_classifier/qc_sqlite/qc_sqlite.cc +++ b/query_classifier/qc_sqlite/qc_sqlite.cc @@ -2110,15 +2110,25 @@ public: update_names(zDatabase, table, NULL, NULL); } - void maxscaleComment() + int maxscaleComment() { - ss_dassert(this_thread.initialized); + // We are regularily parsing if the thread has been initialized. + // In that case # should be interpreted as the start of a comment, + // otherwise it should not. + int regular_parsing = false; - if (m_status == QC_QUERY_INVALID) + if (this_thread.initialized) { - m_status = QC_QUERY_PARSED; - m_type_mask = QUERY_TYPE_READ; + regular_parsing = true; + + if (m_status == QC_QUERY_INVALID) + { + m_status = QC_QUERY_PARSED; + m_type_mask = QUERY_TYPE_READ; + } } + + return regular_parsing; } void maxscaleDeclare(Parse* pParse) 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 fd875b64e..3284a2e2e 100644 --- a/query_classifier/qc_sqlite/sqlite-src-3110100/src/tokenize.c +++ b/query_classifier/qc_sqlite/sqlite-src-3110100/src/tokenize.c @@ -198,6 +198,7 @@ int sqlite3IsIdChar(u8 c){ return IdChar(c); } ** Store the token type in *tokenType before returning. */ #ifdef MAXSCALE +extern int maxscaleComment(); int sqlite3GetToken(Parse* pParse, const unsigned char *z, int *tokenType){ #else int sqlite3GetToken(const unsigned char *z, int *tokenType){ @@ -219,8 +220,7 @@ int sqlite3GetToken(const unsigned char *z, int *tokenType){ case CC_MINUS: { if( z[1]=='-' ){ #ifdef MAXSCALE - extern void maxscaleComment(); - maxscaleComment(); + maxscaleComment(); #endif for(i=2; (c=z[i])!=0 && c!='\n'; i++){} *tokenType = TK_SPACE; /* IMP: R-22934-25134 */ @@ -466,6 +466,13 @@ int sqlite3GetToken(const unsigned char *z, int *tokenType){ testcase( z[0]=='$' ); testcase( z[0]=='@' ); testcase( z[0]==':' ); testcase( z[0]=='#' ); #ifdef MAXSCALE + if (z[0]=='#') { + if (maxscaleComment()) { + for(i=1; (c=z[i])!=0 && c!='\n'; i++){} + *tokenType = TK_SPACE; + return i; + } + } if (z[0]==':' && z[1]=='=') { *tokenType = TK_EQ; return 2;