From 10a83d0453f65c41c3915c906f2d6cf9d6ff349e Mon Sep 17 00:00:00 2001 From: Constantin Michael Date: Fri, 13 May 2011 15:56:57 +0200 Subject: Add PGresult pointer wrapper --- odb/pgsql/database.cxx | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'odb/pgsql/database.cxx') diff --git a/odb/pgsql/database.cxx b/odb/pgsql/database.cxx index ac7a991..721e600 100644 --- a/odb/pgsql/database.cxx +++ b/odb/pgsql/database.cxx @@ -4,12 +4,14 @@ // license : GNU GPL v2; see accompanying LICENSE file #include +#include // std::atol #include #include #include #include #include +#include #include @@ -217,21 +219,23 @@ namespace odb connection_type& c (transaction::current ().connection ()); - PGresult* r = PQexec (c.handle (), s); + result_ptr r (PQexec (c.handle (), s)); + PGresult* h (r.get ()); - ExecStatusType status; unsigned long long count (0); - if (!r) - translate_result_error (c); - else if (!is_good_result (r, &status)) - translate_result_error (c, r, status); - else if (status == PGRES_TUPLES_OK) - count = static_cast (PQntuples (r)); + if (!is_good_result (h)) + translate_error (c, h); + else if (PGRES_TUPLES_OK == PQresultStatus (h)) + count = static_cast (PQntuples (h)); else { - istringstream ss (PQcmdTuples (r)); - ss >> count; + const char* s (PQcmdTuples (h)); + + if (s[0] != '\0' && s[1] == '\0') + count = static_cast (s[0] - '0'); + else + count = static_cast (atol (s)); } return count; -- cgit v1.1