Improved support from removing rows in crud tabs.

It can handle now complex selections and reports back errors encountered
when removing the rows fails.
This commit is contained in:
eelke 2018-12-15 11:24:58 +01:00
parent 950fea873c
commit 62c6ad5bfb
10 changed files with 365 additions and 116 deletions

View file

@ -1,5 +1,6 @@
#include "Pgsql_Connection.h"
#include "Pgsql_declare.h"
#include "Pgsql_PgException.h"
#include "Pgsql_Params.h"
#include <memory>
#include <stdexcept>
@ -107,6 +108,7 @@ std::string Connection::getErrorMessage() const
Result Connection::query(const char * command)
{
PGresult *result = PQexec(conn, command);
throwError(result);
return Result(result);
}
@ -114,6 +116,7 @@ Result Connection::queryParam(const char * command, const Params &params)
{
PGresult *result = PQexecParams(conn, command, params.size(), params.types(),
params.values(), params.lengths(), params.formats(), 0);
throwError(result);
return Result(result);
}
@ -142,6 +145,7 @@ std::shared_ptr<Result> Connection::getResult()
{
PGresult *r = PQgetResult(conn);
if (r) {
throwError(r);
return std::make_shared<Result>(r);
}
else {
@ -225,3 +229,32 @@ QString Connection::getDBName() const
{
return QString::fromUtf8(PQdb(conn));
}
void Connection::throwError(PGresult *result) const
{
auto state = PQresultStatus(result);
if (state == PGRES_BAD_RESPONSE) {
// communication problem
}
else if (state == PGRES_FATAL_ERROR) {
auto details = Pgsql::ErrorDetails::createErrorDetailsFromPGresult(result);
throw PgResultError(details);
}
}
//PGRES_EMPTY_QUERY = 0, /* empty query string was executed */
//PGRES_COMMAND_OK, /* a query command that doesn't return
// * anything was executed properly by the
// * backend */
//PGRES_TUPLES_OK, /* a query command that returns tuples was
// * executed properly by the backend, PGresult
// * contains the result tuples */
//PGRES_COPY_OUT, /* Copy Out data transfer in progress */
//PGRES_COPY_IN, /* Copy In data transfer in progress */
//PGRES_BAD_RESPONSE, /* an unexpected response was recv'd from the
// * backend */
//PGRES_NONFATAL_ERROR, /* notice or warning message */
//PGRES_FATAL_ERROR, /* query failed */
//PGRES_COPY_BOTH, /* Copy In/Out data transfer in progress */
//PGRES_SINGLE_TUPLE /* single tuple from larger resultset */