aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--odb/pgsql/statement.cxx45
-rw-r--r--odb/pgsql/statement.hxx12
2 files changed, 22 insertions, 35 deletions
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 <cstdlib> // std::atol
#include <cassert>
+#include <odb/exceptions.hxx> // object_not_persistent
+
#include <odb/pgsql/statement.hxx>
#include <odb/pgsql/connection.hxx>
#include <odb/pgsql/transaction.hxx>
@@ -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<int> (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