]> granicus.if.org Git - icinga2/commitdiff
DB IDO: Make sure that all result sets are processed before sending another query
authorMichael Friedrich <michael.friedrich@icinga.com>
Tue, 22 Nov 2016 14:54:56 +0000 (15:54 +0100)
committerMichael Friedrich <michael.friedrich@icinga.com>
Tue, 22 Nov 2016 14:56:05 +0000 (15:56 +0100)
fixes #12597

lib/db_ido_mysql/idomysqlconnection.cpp
lib/db_ido_mysql/idomysqlconnection.hpp

index 7b4153932ea10b950fa58bc70601a51bc2de4df0..4d15ae3b19e6236e707682c90f71d951b441f06e 100644 (file)
@@ -513,20 +513,21 @@ void IdoMysqlConnection::FinishAsyncQueries(void)
                        );
                }
 
+               std::vector<IdoMysqlResultInfo> resultSets;
+
                for (std::vector<IdoAsyncQuery>::size_type i = offset; i < offset + count; i++) {
                        const IdoAsyncQuery& aq = queries[i];
 
                        MYSQL_RES *result = mysql_store_result(&m_Connection);
 
-                       m_AffectedRows = mysql_affected_rows(&m_Connection);
-
+                       int affectedRows = mysql_affected_rows(&m_Connection);
                        IdoMysqlResult iresult;
 
                        if (!result) {
                                if (mysql_field_count(&m_Connection) > 0) {
                                        std::ostringstream msgbuf;
                                        String message = mysql_error(&m_Connection);
-                                       msgbuf << "Error \"" << message << "\" when executing query \"" << aq.Query << "\"";
+                                       msgbuf << "Error \"" << message << "\" when checking field count \"" << aq.Query << "\"";
                                        Log(LogCritical, "IdoMysqlConnection", msgbuf.str());
 
                                        BOOST_THROW_EXCEPTION(
@@ -538,8 +539,11 @@ void IdoMysqlConnection::FinishAsyncQueries(void)
                        } else
                                iresult = IdoMysqlResult(result, std::ptr_fun(mysql_free_result));
 
-                       if (aq.Callback)
-                               aq.Callback(iresult);
+                       IdoMysqlResultInfo resultInfo;
+                       resultInfo.Result = iresult;
+                       resultInfo.AffectedRows = affectedRows;
+
+                       resultSets.push_back(resultInfo);
 
                        if (mysql_next_result(&m_Connection) > 0) {
                                std::ostringstream msgbuf;
@@ -555,6 +559,17 @@ void IdoMysqlConnection::FinishAsyncQueries(void)
                        }
                }
 
+               for (std::vector<IdoAsyncQuery>::size_type i = offset; i < offset + count; i++) {
+                       const IdoAsyncQuery& aq = queries[i];
+
+                       const IdoMysqlResultInfo ri = resultSets[i - offset];
+
+                       m_AffectedRows = ri.AffectedRows;
+
+                       if (aq.Callback)
+                               aq.Callback(ri.Result);
+               }
+
                offset += count;
        }
 }
index c134cf7fe8c3ad93158dba35fe6cbe42c9a65cb3..3be79da7ec8373b65649a5ac29b7867e0ea62ff3 100644 (file)
@@ -39,6 +39,12 @@ struct IdoAsyncQuery
        IdoAsyncCallback Callback;
 };
 
+struct IdoMysqlResultInfo
+{
+       IdoMysqlResult Result;
+       int AffectedRows;
+};
+
 /**
  * An IDO MySQL database connection.
  *