From c1d1c5e4e6086e4d4c06d84ac5a4667ccd21afb0 Mon Sep 17 00:00:00 2001 From: Constantin Michael Date: Tue, 24 May 2011 16:51:23 +0200 Subject: Update insert_statement to use lastval() to get last insert id --- odb/pgsql/statement.cxx | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'odb/pgsql/statement.cxx') diff --git a/odb/pgsql/statement.cxx b/odb/pgsql/statement.cxx index 5a9bc28..ab1f34c 100644 --- a/odb/pgsql/statement.cxx +++ b/odb/pgsql/statement.cxx @@ -342,18 +342,24 @@ namespace odb translate_error (conn_, h1); } - oid_ = PQoidValue (h); + result_ptr r2 (PQexec (conn_.handle (), "select lastval ()")); + PGresult* h2 (r2.get ()); - return true; - } + if (!is_good_result (h2)) + translate_error (conn_, h2); - unsigned long long insert_statement:: - id () - { - // @@ Need to check what InvalidOid evaluates to. - // Is this function signature required? + const char* s (PQgetvalue (h2, 0, 0)); + + // @@ Check types for bigserial. // - return static_cast (oid_); + if (s[0] != '\0' && s[1] == '\0') + id_ = static_cast (s[0] - '0'); + else + id_ = static_cast (atol (s)); + + assert (id_ != 0); + + return true; } // -- cgit v1.1