From 3ee1f474f72d093e27974e040372c53342702b12 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 6 Sep 2011 14:58:16 +0200 Subject: Allow select statement without parameters --- odb/pgsql/statement.cxx | 30 +++++++++++++++++++++++------- odb/pgsql/statement.hxx | 7 ++++++- 2 files changed, 29 insertions(+), 8 deletions(-) (limited to 'odb') diff --git a/odb/pgsql/statement.cxx b/odb/pgsql/statement.cxx index 7e5b5aa..c839e92 100644 --- a/odb/pgsql/statement.cxx +++ b/odb/pgsql/statement.cxx @@ -314,7 +314,7 @@ namespace odb binding& data) : statement (conn, name, stmt, types, types_count), cond_ (&cond), - native_cond_ (native_cond), + native_cond_ (&native_cond), data_ (data), row_count_ (0), current_row_ (0) @@ -331,7 +331,21 @@ namespace odb binding& data) : statement (conn, name, stmt, types, types_count), cond_ (0), - native_cond_ (native_cond), + native_cond_ (&native_cond), + data_ (data), + row_count_ (0), + current_row_ (0) + { + } + + select_statement:: + select_statement (connection& conn, + const std::string& name, + const std::string& stmt, + binding& data) + : statement (conn, name, stmt, 0, 0), + cond_ (0), + native_cond_ (0), data_ (data), row_count_ (0), current_row_ (0) @@ -344,15 +358,17 @@ namespace odb result_.reset (); if (cond_ != 0) - bind_param (native_cond_, *cond_); + bind_param (*native_cond_, *cond_); + + bool in (native_cond_ != 0); result_.reset ( PQexecPrepared (conn_.handle (), name_.c_str (), - native_cond_.count, - native_cond_.values, - native_cond_.lengths, - native_cond_.formats, + in ? native_cond_->count : 0, + in ? native_cond_->values : 0, + in ? native_cond_->lengths : 0, + in ? native_cond_->formats : 0, 1)); if (!is_good_result (result_)) diff --git a/odb/pgsql/statement.hxx b/odb/pgsql/statement.hxx index 6e5484a..d7cf6dc 100644 --- a/odb/pgsql/statement.hxx +++ b/odb/pgsql/statement.hxx @@ -90,6 +90,11 @@ namespace odb native_binding& native_cond, binding& data); + select_statement (connection& conn, + const std::string& name, + const std::string& stmt, + binding& data); + // Common select interface expected by the generated code. // public: @@ -154,7 +159,7 @@ namespace odb private: binding* cond_; - native_binding& native_cond_; + native_binding* native_cond_; binding& data_; -- cgit v1.1