From d12b7cf55c6843d4dbad4fd859187424cd8fac4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Sun, 23 Oct 2016 14:08:50 +0000 Subject: [PATCH] Return error in resultset , #750 Depending from the query, an error "Query execution was interrupted" can be returned either as: * a standalone ERR Packet (previously handled) * an ERR Packet at the end of a result set : this commit handle this case --- include/MySQL_Protocol.h | 1 + lib/MySQL_Protocol.cpp | 19 +++++++++++++++++++ lib/mysql_connection.cpp | 10 ++++++++++ 3 files changed, 30 insertions(+) diff --git a/include/MySQL_Protocol.h b/include/MySQL_Protocol.h index 27405565b..3b8a0f000 100644 --- a/include/MySQL_Protocol.h +++ b/include/MySQL_Protocol.h @@ -52,6 +52,7 @@ class MySQL_ResultSet { unsigned int add_row(MYSQL_ROW row); unsigned int add_row2(MYSQL_ROWS *row, unsigned char *offset); void add_eof(); + void add_err(MySQL_Data_Stream *_myds); bool get_resultset(PtrSizeArray *PSarrayFinal); unsigned char *buffer; unsigned int buffer_used; diff --git a/lib/MySQL_Protocol.cpp b/lib/MySQL_Protocol.cpp index b373f66b1..1b671cf96 100644 --- a/lib/MySQL_Protocol.cpp +++ b/lib/MySQL_Protocol.cpp @@ -1885,6 +1885,25 @@ void MySQL_ResultSet::add_eof() { resultset_completed=true; } +void MySQL_ResultSet::add_err(MySQL_Data_Stream *_myds) { + PtrSize_t pkt; + if (myprot) { + MYSQL *_mysql=_myds->myconn->mysql; + buffer_to_PSarrayOut(); + char sqlstate[10]; + sprintf(sqlstate,"%s",mysql_sqlstate(_mysql)); + if (_myds && _myds->killed_at) { // see case #750 + myprot->generate_pkt_ERR(false,&pkt.ptr,&pkt.size,sid,1907,sqlstate,"Query execution was interrupted, query_timeout exceeded"); + } else { + myprot->generate_pkt_ERR(false,&pkt.ptr,&pkt.size,sid,mysql_errno(_mysql),sqlstate,mysql_error(_mysql)); + } + PSarrayOUT->add(pkt.ptr,pkt.size); + sid++; + resultset_size+=pkt.size; + } + resultset_completed=true; +} + bool MySQL_ResultSet::get_resultset(PtrSizeArray *PSarrayFinal) { transfer_started=true; if (myprot) { diff --git a/lib/mysql_connection.cpp b/lib/mysql_connection.cpp index f92e79603..be322edae 100644 --- a/lib/mysql_connection.cpp +++ b/lib/mysql_connection.cpp @@ -899,6 +899,16 @@ handler_again: NEXT_IMMEDIATE(ASYNC_USE_RESULT_CONT); // we continue looping } } else { + if (mysql) { + int _myerrno=mysql_errno(mysql); + if (_myerrno) { + if (myds) { + MyRS->add_err(myds); + NEXT_IMMEDIATE(ASYNC_QUERY_END); + } + } + } + // we reach here if there was no error MyRS->add_eof(); NEXT_IMMEDIATE(ASYNC_QUERY_END); }