initial matador ng commit
This commit is contained in:
@@ -6,6 +6,30 @@
|
||||
|
||||
namespace matador::backends::postgres {
|
||||
|
||||
utils::error make_error(const sql::error_code ec, const PGresult *res, const PGconn *db, const std::string &msg,
|
||||
const std::string &sql) {
|
||||
utils::error err(ec, msg);
|
||||
err.add_error_info("dbms", "postgres");
|
||||
if (!sql.empty()) {
|
||||
err.add_error_info("sql", sql);
|
||||
}
|
||||
if (res == nullptr) {
|
||||
err.add_error_info("message", PQerrorMessage(db));
|
||||
} else if (const auto status = PQresultStatus(res); status != PGRES_COMMAND_OK && status != PGRES_TUPLES_OK) {
|
||||
err.add_error_info("message", PQresultErrorField(res, PG_DIAG_SQLSTATE));
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
bool is_result_error(const PGresult *res) {
|
||||
if (res == nullptr) {
|
||||
return true;
|
||||
}
|
||||
const auto status = PQresultStatus(res);
|
||||
return status != PGRES_TUPLES_OK && status == PGRES_COMMAND_OK;
|
||||
}
|
||||
|
||||
void throw_postgres_error(const char *what, const std::string &source)
|
||||
{
|
||||
std::stringstream msg;
|
||||
@@ -26,8 +50,9 @@ void throw_postgres_error(PGresult *res, PGconn *db, const std::string &source,
|
||||
std::stringstream msg;
|
||||
msg << "postgres error (" << source << ", " << PQerrorMessage(db) << ": " << sql;
|
||||
throw std::logic_error(msg.str());
|
||||
} else if ((PQresultStatus(res) != PGRES_COMMAND_OK &&
|
||||
PQresultStatus(res) != PGRES_TUPLES_OK)) {
|
||||
}
|
||||
if (const auto status = PQresultStatus(res); status != PGRES_COMMAND_OK &&
|
||||
status != PGRES_TUPLES_OK) {
|
||||
std::stringstream msg;
|
||||
msg << "postgres error (" << source << ", " << PQresultErrorField(res, PG_DIAG_SQLSTATE) << ") " << PQerrorMessage(db) << ": " << sql;
|
||||
throw std::logic_error(msg.str());
|
||||
|
||||
Reference in New Issue
Block a user