From ddd0ad90327be9c7915d1ae4c3c349a628ec977f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Sat, 4 Jun 2016 10:31:51 +0000 Subject: [PATCH] Preparing the handling of _MYSQL_COM_STMT_PREPARE --- include/MySQL_Session.h | 2 +- lib/MySQL_Session.cpp | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/include/MySQL_Session.h b/include/MySQL_Session.h index b5eb5008a..38b2e7721 100644 --- a/include/MySQL_Session.h +++ b/include/MySQL_Session.h @@ -60,7 +60,7 @@ class MySQL_Session void handler___status_WAITING_SERVER_DATA___STATE_READING_COM_STMT_PREPARE_RESPONSE(PtrSize_t *); void handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_SET_OPTION(PtrSize_t *); void handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_STATISTICS(PtrSize_t *); - bool handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_QUERY_qpo(PtrSize_t *); + bool handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_QUERY_qpo(PtrSize_t *, bool ps=false); void handler___client_DSS_QUERY_SENT___server_DSS_NOT_INITIALIZED__get_connection(); diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index f2ad0332a..9f905f8c6 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -773,7 +773,6 @@ __get_pkts_from_client: case _MYSQL_COM_CHANGE_USER: handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_CHANGE_USER(&pkt, &wrong_pass); break; - case _MYSQL_COM_STMT_PREPARE: case _MYSQL_COM_STMT_EXECUTE: case _MYSQL_COM_STMT_CLOSE: l_free(pkt.size,pkt.ptr); @@ -782,6 +781,31 @@ __get_pkts_from_client: client_myds->DSS=STATE_SLEEP; status=WAITING_CLIENT_DATA; break; + case _MYSQL_COM_STMT_PREPARE: + if (admin==true) { // admin module will not support prepared statement!! + l_free(pkt.size,pkt.ptr); + client_myds->setDSS_STATE_QUERY_SENT_NET(); + client_myds->myprot.generate_pkt_ERR(true,NULL,NULL,1,1045,(char *)"#28000",(char *)"Command not supported"); + client_myds->DSS=STATE_SLEEP; + status=WAITING_CLIENT_DATA; + break; + } else { + // if we reach here, we are not on admin + bool rc_break=false; + + // Note: CurrentQuery sees the query as sent by the client. + // shortly after, the packets it used to contain the query will be deallocated + // Note2 : we call the next function as if it was _MYSQL_COM_QUERY + // because the offset will be identical + CurrentQuery.begin((unsigned char *)pkt.ptr,pkt.size,false); + + qpo=GloQPro->process_mysql_query(this,pkt.ptr,pkt.size,&CurrentQuery); + assert(qpo); // GloQPro->process_mysql_query() should always return a qpo + rc_break=handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_QUERY_qpo(&pkt); + if (rc_break==true) { + } + } + break; // case _MYSQL_COM_STMT_PREPARE: // handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_STMT_PREPARE(&pkt); // break; @@ -1819,7 +1843,7 @@ void MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C -bool MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_QUERY_qpo(PtrSize_t *pkt) { +bool MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_QUERY_qpo(PtrSize_t *pkt, bool prepared) { if (qpo->new_query) { // the query was rewritten l_free(pkt->size,pkt->ptr); // free old pkt @@ -1849,6 +1873,11 @@ bool MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C RequestEnd(NULL); return true; } + + if (prepared) { // for prepared statement we exit here + return false; + } + if (mirror==true) { // for mirror session we exit here current_hostgroup=qpo->destination_hostgroup; return false;