From 9ab29e154a7568e70e84546bc4eaf882303a43e8 Mon Sep 17 00:00:00 2001 From: Chris Hofstaedtler Date: Fri, 4 Sep 2020 10:20:36 +0200 Subject: [PATCH] auth: Handle the extra single-row result set of MySQL stored procedures Backport of #9423, master commit f8289e595a8dc1b8c9738833ffa3d5a98b711268. --- modules/gmysqlbackend/smysql.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/gmysqlbackend/smysql.cc b/modules/gmysqlbackend/smysql.cc index 152c987739..0687cec7eb 100644 --- a/modules/gmysqlbackend/smysql.cc +++ b/modules/gmysqlbackend/smysql.cc @@ -301,7 +301,10 @@ public: d_resnum = mysql_stmt_num_rows(d_stmt); // XXX: For some reason mysql_stmt_result_metadata returns NULL here, so we cannot // ensure row field count matches first result set. - if (d_resnum > 0) { // ignore empty result set + // We need to check the field count as stored procedure return the final values of OUT and INOUT parameters + // as an extra single-row result set following any result sets produced by the procedure itself. + // mysql_stmt_field_count() will return 0 for those. + if (mysql_stmt_field_count(d_stmt) > 0 && d_resnum > 0) { // ignore empty result set if (d_res_bind != nullptr && mysql_stmt_bind_result(d_stmt, d_res_bind) != 0) { string error(mysql_stmt_error(d_stmt)); releaseStatement(); -- 2.47.2