| 479 | } |
| 480 | |
| 481 | IdoPgsqlResult IdoPgsqlConnection::Query(const String& query) |
| 482 | { |
| 483 | AssertOnWorkQueue(); |
| 484 | |
| 485 | Defer decreaseQueries ([this]() { DecreasePendingQueries(1); }); |
| 486 | |
| 487 | Log(LogDebug, "IdoPgsqlConnection") |
| 488 | << "Query: " << query; |
| 489 | |
| 490 | IncreaseQueryCount(); |
| 491 | |
| 492 | PGresult *result = m_Pgsql->exec(m_Connection, query.CStr()); |
| 493 | |
| 494 | if (!result) { |
| 495 | String message = m_Pgsql->errorMessage(m_Connection); |
| 496 | Log(LogCritical, "IdoPgsqlConnection") |
| 497 | << "Error \"" << message << "\" when executing query \"" << query << "\""; |
| 498 | |
| 499 | BOOST_THROW_EXCEPTION( |
| 500 | database_error() |
| 501 | << errinfo_message(message) |
| 502 | << errinfo_database_query(query) |
| 503 | ); |
| 504 | } |
| 505 | |
| 506 | char *rowCount = m_Pgsql->cmdTuples(result); |
| 507 | m_AffectedRows = atoi(rowCount); |
| 508 | |
| 509 | if (m_Pgsql->resultStatus(result) == PGRES_COMMAND_OK) { |
| 510 | m_Pgsql->clear(result); |
| 511 | return IdoPgsqlResult(); |
| 512 | } |
| 513 | |
| 514 | if (m_Pgsql->resultStatus(result) != PGRES_TUPLES_OK) { |
| 515 | String message = m_Pgsql->resultErrorMessage(result); |
| 516 | m_Pgsql->clear(result); |
| 517 | |
| 518 | Log(LogCritical, "IdoPgsqlConnection") |
| 519 | << "Error \"" << message << "\" when executing query \"" << query << "\""; |
| 520 | |
| 521 | BOOST_THROW_EXCEPTION( |
| 522 | database_error() |
| 523 | << errinfo_message(message) |
| 524 | << errinfo_database_query(query) |
| 525 | ); |
| 526 | } |
| 527 | |
| 528 | return IdoPgsqlResult(result, [this](PGresult* result) { m_Pgsql->clear(result); }); |
| 529 | } |
| 530 | |
| 531 | DbReference IdoPgsqlConnection::GetSequenceValue(const String& table, const String& column) |
| 532 | { |
nothing calls this directly
no test coverage detected