mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-26 23:24:09 +02:00
DB IDO: Make sure that all result sets are processed before sending another query
fixes #12597
This commit is contained in:
parent
56e9a23a65
commit
b028ff2c33
@ -513,20 +513,21 @@ void IdoMysqlConnection::FinishAsyncQueries(void)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<IdoMysqlResultInfo> resultSets;
|
||||||
|
|
||||||
for (std::vector<IdoAsyncQuery>::size_type i = offset; i < offset + count; i++) {
|
for (std::vector<IdoAsyncQuery>::size_type i = offset; i < offset + count; i++) {
|
||||||
const IdoAsyncQuery& aq = queries[i];
|
const IdoAsyncQuery& aq = queries[i];
|
||||||
|
|
||||||
MYSQL_RES *result = mysql_store_result(&m_Connection);
|
MYSQL_RES *result = mysql_store_result(&m_Connection);
|
||||||
|
|
||||||
m_AffectedRows = mysql_affected_rows(&m_Connection);
|
int affectedRows = mysql_affected_rows(&m_Connection);
|
||||||
|
|
||||||
IdoMysqlResult iresult;
|
IdoMysqlResult iresult;
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
if (mysql_field_count(&m_Connection) > 0) {
|
if (mysql_field_count(&m_Connection) > 0) {
|
||||||
std::ostringstream msgbuf;
|
std::ostringstream msgbuf;
|
||||||
String message = mysql_error(&m_Connection);
|
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());
|
Log(LogCritical, "IdoMysqlConnection", msgbuf.str());
|
||||||
|
|
||||||
BOOST_THROW_EXCEPTION(
|
BOOST_THROW_EXCEPTION(
|
||||||
@ -538,8 +539,11 @@ void IdoMysqlConnection::FinishAsyncQueries(void)
|
|||||||
} else
|
} else
|
||||||
iresult = IdoMysqlResult(result, std::ptr_fun(mysql_free_result));
|
iresult = IdoMysqlResult(result, std::ptr_fun(mysql_free_result));
|
||||||
|
|
||||||
if (aq.Callback)
|
IdoMysqlResultInfo resultInfo;
|
||||||
aq.Callback(iresult);
|
resultInfo.Result = iresult;
|
||||||
|
resultInfo.AffectedRows = affectedRows;
|
||||||
|
|
||||||
|
resultSets.push_back(resultInfo);
|
||||||
|
|
||||||
if (mysql_next_result(&m_Connection) > 0) {
|
if (mysql_next_result(&m_Connection) > 0) {
|
||||||
std::ostringstream msgbuf;
|
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;
|
offset += count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,12 @@ struct IdoAsyncQuery
|
|||||||
IdoAsyncCallback Callback;
|
IdoAsyncCallback Callback;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct IdoMysqlResultInfo
|
||||||
|
{
|
||||||
|
IdoMysqlResult Result;
|
||||||
|
int AffectedRows;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An IDO MySQL database connection.
|
* An IDO MySQL database connection.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user