Add debugging of db failures

pull/3850/head
Isaac Connor 2024-03-04 13:20:21 -05:00
parent 6f467dd0d4
commit 067ca68549
1 changed files with 9 additions and 1 deletions

View File

@ -197,6 +197,14 @@ int zmDbDo(const std::string &query) {
return 0;
int rc;
while ((rc = mysql_query(&dbconn, query.c_str())) and !zm_terminate) {
Logger *logger = Logger::fetch();
Logger::Level oldLevel = logger->databaseLevel();
logger->databaseLevel(Logger::NOLOG);
std::string reason = mysql_error(&dbconn);
Debug(1, "Failed running sql query %s, thread_id: %lu, %s", query.c_str(), db_thread_id, reason.c_str());
logger->databaseLevel(oldLevel);
if (mysql_ping(&dbconn)) {
// Was a connection error
while (!zmDbReconnect() and !zm_terminate) {
@ -206,7 +214,7 @@ int zmDbDo(const std::string &query) {
if (zm_terminate) return 0;
} else {
// Not a connection error
Error("Can't run query %s: %s", query.c_str(), mysql_error(&dbconn));
Error("Can't run query %s: %s", query.c_str(), reason.c_str());
if (mysql_errno(&dbconn) != ER_LOCK_WAIT_TIMEOUT) {
return rc;
}