summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libpqpp/connection.cpp12
-rw-r--r--libpqpp/connection.h6
-rw-r--r--libpqpp/modifycommand.cpp2
3 files changed, 10 insertions, 10 deletions
diff --git a/libpqpp/connection.cpp b/libpqpp/connection.cpp
index 11c043e..8bfc2ff 100644
--- a/libpqpp/connection.cpp
+++ b/libpqpp/connection.cpp
@@ -105,15 +105,15 @@ PQ::Connection::newModifyCommand(const std::string & sql) const
}
bool
-PQ::Connection::checkResultInt(PGresult * res, int expected)
+PQ::Connection::checkResultInt(PGresult * res, int expected, int alt)
{
- return (PQresultStatus(res) == expected);
+ return (PQresultStatus(res) == expected) || (alt != -1 && (PQresultStatus(res) == alt));
}
PGresult *
-PQ::Connection::checkResult(PGresult * res, int expected) const
+PQ::Connection::checkResult(PGresult * res, int expected, int alt) const
{
- if (!checkResultInt(res, expected)) {
+ if (!checkResultInt(res, expected, alt)) {
PQclear(res);
throw Error(PQerrorMessage(conn));
}
@@ -121,9 +121,9 @@ PQ::Connection::checkResult(PGresult * res, int expected) const
}
void
-PQ::Connection::checkResultFree(PGresult * res, int expected) const
+PQ::Connection::checkResultFree(PGresult * res, int expected, int alt) const
{
- if (!checkResultInt(res, expected)) {
+ if (!checkResultInt(res, expected, alt)) {
PQclear(res);
throw Error(PQerrorMessage(conn));
}
diff --git a/libpqpp/connection.h b/libpqpp/connection.h
index b46151d..d4cf60a 100644
--- a/libpqpp/connection.h
+++ b/libpqpp/connection.h
@@ -22,13 +22,13 @@ namespace PQ {
DB::SelectCommand * newSelectCommand(const std::string & sql) const;
DB::ModifyCommand * newModifyCommand(const std::string & sql) const;
- PGresult * checkResult(PGresult * res, int expected) const;
- void checkResultFree(PGresult * res, int expected) const;
+ PGresult * checkResult(PGresult * res, int expected, int alternative = -1) const;
+ void checkResultFree(PGresult * res, int expected, int alternative = -1) const;
PGconn * conn;
private:
- static bool checkResultInt(PGresult * res, int expected);
+ static bool checkResultInt(PGresult * res, int expected, int alternative);
mutable unsigned int txDepth;
mutable unsigned int pstmntNo;
diff --git a/libpqpp/modifycommand.cpp b/libpqpp/modifycommand.cpp
index 69cd8cc..b9ece01 100644
--- a/libpqpp/modifycommand.cpp
+++ b/libpqpp/modifycommand.cpp
@@ -48,7 +48,7 @@ PQ::ModifyCommand::execute(bool anc)
{
prepare();
PGresult * res = PQexecPrepared(c->conn, stmntName.c_str(), values.size(), &values.front(), &lengths.front(), &formats.front(), 0);
- c->checkResult(res, PGRES_COMMAND_OK);
+ c->checkResult(res, PGRES_COMMAND_OK, PGRES_TUPLES_OK);
unsigned int rows = atoi(PQcmdTuples(res));
PQclear(res);
if (rows == 0 && !anc) {