MCPcopy Create free account
hub / github.com/Icinga/icinga2 / Query

Method Query

lib/db_ido_mysql/idomysqlconnection.cpp:652–702  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

650}
651
652IdoMysqlResult IdoMysqlConnection::Query(const String& query)
653{
654 AssertOnWorkQueue();
655
656 IncreasePendingQueries(1);
657 Defer decreaseQueries ([this]() { DecreasePendingQueries(1); });
658
659 /* finish all async queries to maintain the right order for queries */
660 FinishAsyncQueries();
661
662 Log(LogDebug, "IdoMysqlConnection")
663 << "Query: " << query;
664
665 IncreaseQueryCount();
666
667 if (m_Mysql->query(&m_Connection, query.CStr()) != 0) {
668 std::ostringstream msgbuf;
669 String message = m_Mysql->error(&m_Connection);
670 msgbuf << "Error \"" << message << "\" when executing query \"" << query << "\"";
671 Log(LogCritical, "IdoMysqlConnection", msgbuf.str());
672
673 BOOST_THROW_EXCEPTION(
674 database_error()
675 << errinfo_message(m_Mysql->error(&m_Connection))
676 << errinfo_database_query(query)
677 );
678 }
679
680 MYSQL_RES *result = m_Mysql->store_result(&m_Connection);
681
682 m_AffectedRows = m_Mysql->affected_rows(&m_Connection);
683
684 if (!result) {
685 if (m_Mysql->field_count(&m_Connection) > 0) {
686 std::ostringstream msgbuf;
687 String message = m_Mysql->error(&m_Connection);
688 msgbuf << "Error \"" << message << "\" when executing query \"" << query << "\"";
689 Log(LogCritical, "IdoMysqlConnection", msgbuf.str());
690
691 BOOST_THROW_EXCEPTION(
692 database_error()
693 << errinfo_message(m_Mysql->error(&m_Connection))
694 << errinfo_database_query(query)
695 );
696 }
697
698 return IdoMysqlResult();
699 }
700
701 return IdoMysqlResult(result, [this](MYSQL_RES* result) { m_Mysql->free_result(result); });
702}
703
704DbReference IdoMysqlConnection::GetLastInsertID()
705{

Callers 1

Calls 9

LogClass · 0.85
database_errorClass · 0.85
queryMethod · 0.80
CStrMethod · 0.80
errorMethod · 0.80
store_resultMethod · 0.80
affected_rowsMethod · 0.80
field_countMethod · 0.80
free_resultMethod · 0.80

Tested by

no test coverage detected