From 0b762135ae0e28fcda69d58523364aa8bef9637a Mon Sep 17 00:00:00 2001 From: Constantin Michael Date: Thu, 19 May 2011 17:08:03 +0200 Subject: Add update_statement --- odb/pgsql/statement.cxx | 44 ++++++++++++++++++++++++++++++++++++++++++++ odb/pgsql/statement.hxx | 29 +++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) (limited to 'odb') diff --git a/odb/pgsql/statement.cxx b/odb/pgsql/statement.cxx index efd7f8e..f3425a6 100644 --- a/odb/pgsql/statement.cxx +++ b/odb/pgsql/statement.cxx @@ -128,6 +128,50 @@ namespace odb return static_cast (oid_); } + // + // update_statement + // + + update_statement:: + ~update_statement () + { + } + + update_statement:: + update_statement (connection& conn, + const string& name, + const string& stmt, + const Oid* types, + size_t n, + native_binding& cond, + native_binding& data) + : statement (conn, name, stmt, types, n), + cond_ (cond), + data_ (data) + { + } + + void update_statement:: + execute () + { + result_ptr r (PQexecPrepared (conn_.handle (), + name_.c_str (), + cond_.count, + cond_.values, + cond_.lengths, + cond_.formats, + 1)); + + PGresult* h (r.get ()); + + if (!is_good_result (h)) + translate_error (conn_, h); + + const char* s (PQcmdTuples (h)); + + if (s[0] == '0') + throw object_not_persistent (); + } // // delete_statement diff --git a/odb/pgsql/statement.hxx b/odb/pgsql/statement.hxx index 88b1c14..17d4930 100644 --- a/odb/pgsql/statement.hxx +++ b/odb/pgsql/statement.hxx @@ -79,6 +79,35 @@ namespace odb Oid oid_; }; + class LIBODB_PGSQL_EXPORT update_statement: public statement + { + public: + virtual + ~update_statement (); + + // Asssumes that cond.values, cond.lengths, and cond.formats are + // suffixes of data.values, data.lengths, and data.formats + // respectively. + // + update_statement (connection& conn, + const std::string& name, + const std::string& stmt, + const Oid* types, + std::size_t n, + native_binding& cond, + native_binding& data); + void + execute (); + + private: + update_statement (const update_statement&); + update_statement& operator= (const update_statement&); + + private: + native_binding& cond_; + native_binding& data_; + }; + class LIBODB_PGSQL_EXPORT delete_statement: public statement { public: -- cgit v1.1