From b820128512133c443799b27265e28a27622497e6 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 1 Nov 2011 12:41:02 +0200 Subject: Implement support for optimistic concurrency New pragmas: optimistic, version. New test: optimistic. New database function: reload(). --- odb/pgsql/statement.cxx | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'odb/pgsql/statement.cxx') diff --git a/odb/pgsql/statement.cxx b/odb/pgsql/statement.cxx index f119fd0..049a00d 100644 --- a/odb/pgsql/statement.cxx +++ b/odb/pgsql/statement.cxx @@ -9,8 +9,6 @@ #include -#include // object_not_persistent - #include #include #include @@ -28,6 +26,26 @@ namespace odb { using namespace details; + static unsigned long long + affected_row_count (PGresult* h) + { + const char* s (PQcmdTuples (h)); + unsigned long long count; + + if (s[0] != '\0' && s[1] == '\0') + count = static_cast (s[0] - '0'); + else + { + // @@ Using stringstream conversion for now. See if we can optimize + // this (atoll possibly, even though it is not standard). + // + istringstream ss (s); + ss >> count; + } + + return count; + } + // // statement // @@ -102,7 +120,7 @@ namespace odb continue; } - n.values[i] = reinterpret_cast (current_bind.buffer); + n.values[i] = static_cast (current_bind.buffer); size_t l (0); @@ -547,7 +565,7 @@ namespace odb { } - void update_statement:: + unsigned long long update_statement:: execute () { bind_param (native_param_, param_); @@ -564,11 +582,7 @@ namespace odb if (!is_good_result (h)) translate_error (conn_, h); - // PQcmdTuples returns a string representing the number of matching - // rows found. "0" indicates no match. - // - if (PQcmdTuples (h)[0] == '0') - throw object_not_persistent (); + return affected_row_count (h); } // @@ -625,21 +639,7 @@ namespace odb if (!is_good_result (h)) translate_error (conn_, h); - const char* s (PQcmdTuples (h)); - unsigned long long count; - - if (s[0] != '\0' && s[1] == '\0') - count = static_cast (s[0] - '0'); - else - { - // @@ Using stringstream conversion for now. See if we can optimize - // this (atoll possibly, even though it is not standard). - // - istringstream ss (s); - ss >> count; - } - - return count; + return affected_row_count (h); } } } -- cgit v1.1