From 61b265467bec431e5b80c4197a3e913a8357177a Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Mon, 22 May 2017 15:26:50 +0300 Subject: [PATCH] MXS-1196: Add support for DROP SEQUENCE --- .../qc_mysqlembedded/qc_mysqlembedded.cc | 3 +++ query_classifier/qc_sqlite/qc_sqlite.c | 22 +++++++++++++++- .../qc_sqlite/sqlite-src-3110100/src/parse.y | 26 ++++++++++++++----- .../sqlite-src-3110100/src/sqliteInt.h | 7 +---- 4 files changed, 45 insertions(+), 13 deletions(-) diff --git a/query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc b/query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc index 75e23506b..e3ccd4389 100644 --- a/query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc +++ b/query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc @@ -1861,6 +1861,9 @@ int32_t qc_mysql_get_operation(GWBUF* querybuf, int32_t* operation) case SQLCOM_DROP_FUNCTION: case SQLCOM_DROP_INDEX: case SQLCOM_DROP_PROCEDURE: +#if MYSQL_VERSION_MAJOR >= 10 && MYSQL_VERSION_MINOR >= 3 + case SQLCOM_DROP_SEQUENCE: +#endif case SQLCOM_DROP_SERVER: case SQLCOM_DROP_TABLE: case SQLCOM_DROP_TRIGGER: diff --git a/query_classifier/qc_sqlite/qc_sqlite.c b/query_classifier/qc_sqlite/qc_sqlite.c index 71c4407f7..67613f315 100644 --- a/query_classifier/qc_sqlite/qc_sqlite.c +++ b/query_classifier/qc_sqlite/qc_sqlite.c @@ -2140,7 +2140,7 @@ void maxscaleDo(Parse* pParse, ExprList* pEList) exposed_sqlite3ExprListDelete(pParse->db, pEList); } -void maxscaleDrop(Parse* pParse, MxsDrop* pDrop) +void maxscaleDrop(Parse* pParse, int what, Token* pDatabase, Token* pName) { QC_TRACE(); @@ -2150,6 +2150,26 @@ void maxscaleDrop(Parse* pParse, MxsDrop* pDrop) info->status = QC_QUERY_PARSED; info->type_mask = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); info->operation = QUERY_OP_DROP; + + if (what == MXS_DROP_SEQUENCE) + { + const char* zDatabase = NULL; + char database[pDatabase ? pDatabase->n + 1 : 1]; + + if (pDatabase) + { + strncpy(database, pDatabase->z, pDatabase->n); + database[pDatabase->n] = 0; + + zDatabase = database; + } + + char table[pName->n + 1]; + strncpy(table, pName->z, pName->n); + table[pName->n] = 0; + + update_names(info, zDatabase, table); + } } void maxscaleExecute(Parse* pParse, Token* pName, int type_mask) 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 a119fc126..76813045d 100644 --- a/query_classifier/qc_sqlite/sqlite-src-3110100/src/parse.y +++ b/query_classifier/qc_sqlite/sqlite-src-3110100/src/parse.y @@ -113,7 +113,7 @@ extern void maxscaleCheckTable(Parse*, SrcList* pTables); extern void maxscaleCreateSequence(Parse*, Token* pDatabase, Token* pTable); extern void maxscaleDeallocate(Parse*, Token* pName); extern void maxscaleDo(Parse*, ExprList* pEList); -extern void maxscaleDrop(Parse*, MxsDrop* pDrop); +extern void maxscaleDrop(Parse*, int what, Token* pDatabase, Token* pName); extern void maxscaleExecute(Parse*, Token* pName, int type_mask); extern void maxscaleExecuteImmediate(Parse*, Token* pName, ExprSpan* pExprSpan, int type_mask); extern void maxscaleExplain(Parse*, Token* pNext); @@ -2719,11 +2719,7 @@ call ::= CALL fullname(X) call_args_opt(Y). { //////////////////////// DROP FUNCTION statement //////////////////////////////////// // cmd ::= DROP FUNCTION_KW ifexists nm(X). { - MxsDrop drop; - drop.what = MXS_DROP_FUNCTION; - drop.token = X; - - maxscaleDrop(pParse, &drop); + maxscaleDrop(pParse, MXS_DROP_FUNCTION, NULL, &X); } //////////////////////// The CHECK TABLE statement //////////////////////////////////// @@ -3305,4 +3301,22 @@ cmd ::= CREATE SEQUENCE nm(X) dbnm(Y).{ // CREATE SEQUENCE db maxscaleCreateSequence(pParse, pDatabase, pTable); } +//////////////////////// ORACLE CREATE SEQUENCE //////////////////////////////////// +// +cmd ::= DROP SEQUENCE nm(X) dbnm(Y).{ // CREATE SEQUENCE db + Token* pDatabase; + Token* pTable; + if (Y.z) + { + pDatabase = &X; + pTable = &Y; + } + else + { + pDatabase = NULL; + pTable = &X; + } + maxscaleDrop(pParse, MXS_DROP_SEQUENCE, pDatabase, pTable); +} + %endif diff --git a/query_classifier/qc_sqlite/sqlite-src-3110100/src/sqliteInt.h b/query_classifier/qc_sqlite/sqlite-src-3110100/src/sqliteInt.h index ed7e0e298..a23fc7090 100644 --- a/query_classifier/qc_sqlite/sqlite-src-3110100/src/sqliteInt.h +++ b/query_classifier/qc_sqlite/sqlite-src-3110100/src/sqliteInt.h @@ -4092,14 +4092,9 @@ int sqlite3DbstatRegister(sqlite3*); typedef enum mxs_drop { MXS_DROP_FUNCTION, + MXS_DROP_SEQUENCE, } mxs_drop_t; -typedef struct MxsDrop -{ - mxs_drop_t what; - Token token; -} MxsDrop; - typedef enum mxs_set { MXS_SET_VARIABLES,