From 3c9c10f340a3013e5d67e5cac9b89990cf567538 Mon Sep 17 00:00:00 2001 From: Constantin Michael Date: Thu, 19 May 2011 17:23:54 +0200 Subject: Aesthetic changes and small corrections/re-factorings --- odb/pgsql/statement.cxx | 45 ++++++++++++++++++--------------------------- odb/pgsql/statement.hxx | 12 ++++-------- 2 files changed, 22 insertions(+), 35 deletions(-) (limited to 'odb') diff --git a/odb/pgsql/statement.cxx b/odb/pgsql/statement.cxx index f3425a6..35b2bb6 100644 --- a/odb/pgsql/statement.cxx +++ b/odb/pgsql/statement.cxx @@ -6,6 +6,8 @@ #include // std::atol #include +#include // object_not_persistent + #include #include #include @@ -27,7 +29,9 @@ namespace odb { try { - release (); + string s ("deallocate "); + s += name_; + PQexec (conn_.handle (), s.c_str ()); } catch (...) { @@ -39,34 +43,20 @@ namespace odb const string& name, const string& stmt, const Oid* types, - size_t n) + size_t types_count) : conn_ (conn), name_ (name) { result_ptr r (PQprepare (conn_.handle (), name_.c_str (), stmt.c_str (), - n, + static_cast (types_count), types)); if (!is_good_result (r.get ())) translate_error (conn_, r.get ()); } - void statement:: - release () - { - if (!name_.empty ()) - { - string s ("deallocate "); - s += name_; - - transaction t (conn_.database ().begin ()); - conn_.database ().execute (s.c_str ()); - t.commit (); - } - } - // // insert_statement // @@ -81,9 +71,9 @@ namespace odb const string& name, const string& stmt, const Oid* types, - size_t n, + size_t types_count, native_binding& data) - : statement (conn, name, stmt, types, n), + : statement (conn, name, stmt, types, types_count), data_ (data) { } @@ -142,10 +132,10 @@ namespace odb const string& name, const string& stmt, const Oid* types, - size_t n, + size_t types_count, native_binding& cond, native_binding& data) - : statement (conn, name, stmt, types, n), + : statement (conn, name, stmt, types, types_count), cond_ (cond), data_ (data) { @@ -167,9 +157,10 @@ namespace odb if (!is_good_result (h)) translate_error (conn_, h); - const char* s (PQcmdTuples (h)); - - if (s[0] == '0') + // PQcmdTuples returns a string representing the number of matching + // rows found. "0" indicates no match. + // + if (PQcmdTuples (h)[0] == '0') throw object_not_persistent (); } @@ -187,9 +178,9 @@ namespace odb const string& name, const string& stmt, const Oid* types, - size_t n, + size_t types_count, native_binding& cond) - : statement (conn, name, stmt, types, n), + : statement (conn, name, stmt, types, types_count), cond_ (cond) { } @@ -209,7 +200,7 @@ namespace odb if (!is_good_result (h)) translate_error (conn_, h); - const char* s = PQcmdTuples (h); + const char* s (PQcmdTuples (h)); unsigned long long count; if (s[0] != '\0' && s[1] == '\0') diff --git a/odb/pgsql/statement.hxx b/odb/pgsql/statement.hxx index 17d4930..0315f05 100644 --- a/odb/pgsql/statement.hxx +++ b/odb/pgsql/statement.hxx @@ -37,15 +37,11 @@ namespace odb const std::string& name, const std::string& stmt, const Oid* types, - std::size_t n); + std::size_t types_count); protected: connection& conn_; std::string name_; - - private: - void - release (); }; class LIBODB_PGSQL_EXPORT insert_statement: public statement @@ -58,7 +54,7 @@ namespace odb const std::string& name, const std::string& stmt, const Oid* types, - std::size_t n, + std::size_t types_count, native_binding& data); // Return true if successful and false if the row is a duplicate. @@ -93,7 +89,7 @@ namespace odb const std::string& name, const std::string& stmt, const Oid* types, - std::size_t n, + std::size_t types_count, native_binding& cond, native_binding& data); void @@ -118,7 +114,7 @@ namespace odb const std::string& name, const std::string& stmt, const Oid* types, - std::size_t n, + std::size_t types_count, native_binding& cond); unsigned long long -- cgit v1.1