diff --git a/query_classifier/qc_sqlite/qc_sqlite.c b/query_classifier/qc_sqlite/qc_sqlite.c index 7d5d8b44b..22c9cfca4 100644 --- a/query_classifier/qc_sqlite/qc_sqlite.c +++ b/query_classifier/qc_sqlite/qc_sqlite.c @@ -1536,15 +1536,18 @@ void mxs_sqlite3Analyze(Parse* pParse, SrcList* pSrcList) exposed_sqlite3SrcListDelete(pParse->db, pSrcList); } -void mxs_sqlite3BeginTransaction(Parse* pParse, int type) +void mxs_sqlite3BeginTransaction(Parse* pParse, int token, int type) { QC_TRACE(); QC_SQLITE_INFO* info = this_thread.info; ss_dassert(info); - info->status = QC_QUERY_PARSED; - info->type_mask = QUERY_TYPE_BEGIN_TRX | type; + if ((this_unit.sql_mode != QC_SQL_MODE_ORACLE) || (token == TK_START)) + { + info->status = QC_QUERY_PARSED; + info->type_mask = QUERY_TYPE_BEGIN_TRX | type; + } } void mxs_sqlite3BeginTrigger(Parse *pParse, /* The parse context of the CREATE TRIGGER statement */ @@ -2465,10 +2468,19 @@ void maxscaleLock(Parse* pParse, mxs_lock_t type, SrcList* pTables) } } -void maxscaleKeyword(int token) +/** + * Register the tokenization of a keyword. + * + * @param token A keyword code (check generated parse.h) + * + * @return Non-zero if all input should be consumed, 0 otherwise. + */ +int maxscaleKeyword(int token) { QC_TRACE(); + int rv = 0; + QC_SQLITE_INFO* info = this_thread.info; ss_dassert(info); @@ -2493,6 +2505,18 @@ void maxscaleKeyword(int token) info->operation = QUERY_OP_ALTER; break; + case TK_BEGIN: + if (this_unit.sql_mode == QC_SQL_MODE_ORACLE) + { + // The beginning of a BLOCK. We'll assume it is in a single + // COM_QUERY packet and hence one GWBUF. + info->status = QC_QUERY_TOKENIZED; + info->type_mask = QUERY_TYPE_WRITE; + // Return non-0 to cause the entire input to be consumed. + rv = 1; + } + break; + case TK_CALL: info->status = QC_QUERY_TOKENIZED; info->type_mask = QUERY_TYPE_WRITE; @@ -2683,6 +2707,8 @@ void maxscaleKeyword(int token) } } } + + return rv; } void maxscaleRenameTable(Parse* pParse, SrcList* pTables) diff --git a/query_classifier/qc_sqlite/sqlite-src-3110100/src/parse.y b/query_classifier/qc_sqlite/sqlite-src-3110100/src/parse.y index 2555ab7bd..79b819be4 100644 --- a/query_classifier/qc_sqlite/sqlite-src-3110100/src/parse.y +++ b/query_classifier/qc_sqlite/sqlite-src-3110100/src/parse.y @@ -86,7 +86,7 @@ typedef enum qc_field_usage extern void mxs_sqlite3AlterFinishAddColumn(Parse *, Token *); extern void mxs_sqlite3AlterBeginAddColumn(Parse *, SrcList *); extern void mxs_sqlite3Analyze(Parse *, SrcList *); -extern void mxs_sqlite3BeginTransaction(Parse*, int); +extern void mxs_sqlite3BeginTransaction(Parse*, int token, int type); extern void mxs_sqlite3CommitTransaction(Parse*); extern void mxs_sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*, Expr*, int, int); @@ -308,7 +308,7 @@ cmdx ::= cmd. { sqlite3FinishCoding(pParse); } %ifdef MAXSCALE work_opt ::= WORK. work_opt ::= . -cmd ::= BEGIN work_opt. {mxs_sqlite3BeginTransaction(pParse, 0);} // BEGIN [WORK] +cmd ::= BEGIN work_opt. {mxs_sqlite3BeginTransaction(pParse, TK_BEGIN, 0);} // BEGIN [WORK] %endif %ifndef MAXSCALE cmd ::= BEGIN transtype(Y) trans_opt. {sqlite3BeginTransaction(pParse, Y);} @@ -3256,7 +3256,7 @@ start_transaction_characteristics(A) ::= } cmd ::= START TRANSACTION start_transaction_characteristics(X). { - mxs_sqlite3BeginTransaction(pParse, X); + mxs_sqlite3BeginTransaction(pParse, TK_START, X); } //////////////////////// The TRUNCATE statement //////////////////////////////////// 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 b358ae234..e0b171a5f 100644 --- a/query_classifier/qc_sqlite/sqlite-src-3110100/src/tokenize.c +++ b/query_classifier/qc_sqlite/sqlite-src-3110100/src/tokenize.c @@ -568,8 +568,14 @@ int sqlite3GetToken(const unsigned char *z, int *tokenType){ } if (*tokenType != TK_ID) { - extern void maxscaleKeyword(int); - maxscaleKeyword(*tokenType); + extern int maxscaleKeyword(int); + if (maxscaleKeyword(*tokenType) != 0) + { + /* Consume the entire string. */ + while ( z[i] ) { + ++i; + } + } } } return i;