diff options
author | Constantin Michael <constantin@codesynthesis.com> | 2011-05-13 15:56:57 +0200 |
---|---|---|
committer | Constantin Michael <constantin@codesynthesis.com> | 2011-05-13 15:56:57 +0200 |
commit | 10a83d0453f65c41c3915c906f2d6cf9d6ff349e (patch) | |
tree | ca13498579d9f15c1265eccd3b28755454580cbd /odb/pgsql/database.cxx | |
parent | 3faf8e7a8aa2411f207fa09fe81982615d90a726 (diff) |
Add PGresult pointer wrapper
Diffstat (limited to 'odb/pgsql/database.cxx')
-rw-r--r-- | odb/pgsql/database.cxx | 24 |
1 files changed, 14 insertions, 10 deletions
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 <sstream> +#include <cstdlib> // std::atol #include <odb/pgsql/database.hxx> #include <odb/pgsql/error.hxx> #include <odb/pgsql/exceptions.hxx> #include <odb/pgsql/connection-factory.hxx> #include <odb/pgsql/transaction.hxx> +#include <odb/pgsql/result-ptr.hxx> #include <odb/pgsql/details/options.hxx> @@ -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<unsigned long long> (PQntuples (r)); + if (!is_good_result (h)) + translate_error (c, h); + else if (PGRES_TUPLES_OK == PQresultStatus (h)) + count = static_cast<unsigned long long> (PQntuples (h)); else { - istringstream ss (PQcmdTuples (r)); - ss >> count; + const char* s (PQcmdTuples (h)); + + if (s[0] != '\0' && s[1] == '\0') + count = static_cast<unsigned long long> (s[0] - '0'); + else + count = static_cast<unsigned long long> (atol (s)); } return count; |