From 5eb6718b752b12e8b7eb5f3cd8c9ed25efd0172e Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Tue, 8 May 2018 15:06:47 +0300 Subject: [PATCH] MXS-1861 Detect and handle multistatement responses Multi-statement SELECTs were properly detected and handled, but e.g. multi-statement UPDATESs were not, with the result that erronous warnings were logged. Now the responses are detected and handled properly. --- .../filter/masking/maskingfiltersession.cc | 16 ++++- server/modules/filter/masking/mysql.hh | 59 +++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/server/modules/filter/masking/maskingfiltersession.cc b/server/modules/filter/masking/maskingfiltersession.cc index 2dd3503e3..49ab3f652 100644 --- a/server/modules/filter/masking/maskingfiltersession.cc +++ b/server/modules/filter/masking/maskingfiltersession.cc @@ -131,7 +131,21 @@ void MaskingFilterSession::handle_response(GWBUF* pPacket) switch (response.type()) { case ComResponse::OK_PACKET: - // We'll end up here also in the case of a multi-result. + { + ComOK ok(response); + + if (ok.status() & SERVER_MORE_RESULTS_EXIST) + { + m_res.reset_multi(); + m_state = EXPECTING_RESPONSE; + } + else + { + m_state = EXPECTING_NOTHING; + } + } + break; + case ComResponse::LOCAL_INFILE_PACKET: // GET_MORE_CLIENT_DATA/SEND_MORE_CLIENT_DATA m_state = EXPECTING_NOTHING; break; diff --git a/server/modules/filter/masking/mysql.hh b/server/modules/filter/masking/mysql.hh index 47654e458..6d5ba0d92 100644 --- a/server/modules/filter/masking/mysql.hh +++ b/server/modules/filter/masking/mysql.hh @@ -658,6 +658,65 @@ private: uint16_t m_status; }; +class ComOK : public ComResponse +{ +public: + ComOK(GWBUF* pPacket) + : ComResponse(pPacket) + { + ss_dassert(m_type == OK_PACKET); + + extract_payload(); + } + + ComOK(const ComResponse& response) + : ComResponse(response) + { + ss_dassert(m_type == OK_PACKET); + + extract_payload(); + } + + uint64_t affected_rows() const + { + return m_affected_rows; + } + + uint64_t last_insert_id() const + { + return m_last_insert_id; + } + + uint16_t warnings() const + { + return m_warnings; + } + + uint16_t status() const + { + return m_status; + } + +private: + void extract_payload() + { + m_affected_rows = LEncInt(&m_pData).value(); + m_last_insert_id = LEncInt(&m_pData).value(); + + m_status = *m_pData++; + m_status += (*m_pData++ << 8); + + m_warnings = *m_pData++; + m_warnings += (*m_pData++ << 8); + } + +private: + uint64_t m_affected_rows; + uint64_t m_last_insert_id; + uint16_t m_status; + uint16_t m_warnings; +}; + /** * @class ComRequest *