[icinga-checkins] icinga.org: icinga2/fix/ido-result-processing-13321-12597: WIP DB IDO: Make sure that all result sets are processed before sending another query

git at icinga.org git at icinga.org
Fri Nov 25 15:53:44 CET 2016


Module: icinga2
Branch: fix/ido-result-processing-13321-12597
Commit: b1d3d44f497de736ff4c579ca47b2f62086068d5
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=b1d3d44f497de736ff4c579ca47b2f62086068d5

Author: Michael Friedrich <michael.friedrich at icinga.com>
Date:   Tue Nov 22 15:54:56 2016 +0100

WIP DB IDO: Make sure that all result sets are processed before sending another query

---

 lib/db_ido_mysql/idomysqlconnection.cpp |   25 ++++++++++++++++++++-----
 lib/db_ido_mysql/idomysqlconnection.hpp |    6 ++++++
 2 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/lib/db_ido_mysql/idomysqlconnection.cpp b/lib/db_ido_mysql/idomysqlconnection.cpp
index 7b41539..4d15ae3 100644
--- a/lib/db_ido_mysql/idomysqlconnection.cpp
+++ b/lib/db_ido_mysql/idomysqlconnection.cpp
@@ -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;
 	}
 }
diff --git a/lib/db_ido_mysql/idomysqlconnection.hpp b/lib/db_ido_mysql/idomysqlconnection.hpp
index c134cf7..3be79da 100644
--- a/lib/db_ido_mysql/idomysqlconnection.hpp
+++ b/lib/db_ido_mysql/idomysqlconnection.hpp
@@ -39,6 +39,12 @@ struct IdoAsyncQuery
 	IdoAsyncCallback Callback;
 };
 
+struct IdoMysqlResultInfo
+{
+	IdoMysqlResult Result;
+	int AffectedRows;
+};
+
 /**
  * An IDO MySQL database connection.
  *



More information about the icinga-checkins mailing list