diff options
Diffstat (limited to 'libpqpp')
-rw-r--r-- | libpqpp/pq-connection.cpp | 11 | ||||
-rw-r--r-- | libpqpp/pq-connection.h | 6 |
2 files changed, 5 insertions, 12 deletions
diff --git a/libpqpp/pq-connection.cpp b/libpqpp/pq-connection.cpp index dc3cf13..ed00d8d 100644 --- a/libpqpp/pq-connection.cpp +++ b/libpqpp/pq-connection.cpp @@ -124,16 +124,11 @@ PQ::Connection::modify(const std::string & sql, const DB::CommandOptionsCPtr & o return std::make_shared<ModifyCommand>(this, sql, opts); } -bool -PQ::Connection::checkResultInt(PGresult * res, int expected, int alt) -{ - return (PQresultStatus(res) == expected) || (alt != -1 && (PQresultStatus(res) == alt)); -} - +template<std::same_as<ExecStatusType>... Expected> PQ::ResultPtr -PQ::Connection::checkResult(PGresult * res, int expected, int alt) const +PQ::Connection::checkResult(PGresult * res, Expected... expected) const { - if (!checkResultInt(res, expected, alt)) { + if (const auto status = PQresultStatus(res); (... && (status != expected))) { PQclear(res); throw Error(conn); } diff --git a/libpqpp/pq-connection.h b/libpqpp/pq-connection.h index af013ab..39f7f2a 100644 --- a/libpqpp/pq-connection.h +++ b/libpqpp/pq-connection.h @@ -47,13 +47,11 @@ namespace PQ { void endBulkUpload(const char *) override; size_t bulkUploadData(const char *, size_t) const override; - ResultPtr checkResult(PGresult * res, int expected, int alternative = -1) const; + template<std::same_as<ExecStatusType>... Expected> + ResultPtr checkResult(PGresult * res, Expected... expected) const; PGconn * conn; mutable PreparedStatements preparedStatements; - - private: - static bool checkResultInt(PGresult * res, int expected, int alternative); }; } |