From 0fba3bc7e0747e23ca2698e0acc82e80b569e531 Mon Sep 17 00:00:00 2001 From: Constantin Michael Date: Tue, 5 Jul 2011 13:02:03 +0200 Subject: Implement PostgreSQL specific fetch operations for select_statement --- odb/pgsql/statement.cxx | 70 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 22 deletions(-) (limited to 'odb/pgsql/statement.cxx') diff --git a/odb/pgsql/statement.cxx b/odb/pgsql/statement.cxx index 233519c..b06646e 100644 --- a/odb/pgsql/statement.cxx +++ b/odb/pgsql/statement.cxx @@ -282,7 +282,25 @@ namespace odb native_binding& native_cond, binding& data) : statement (conn, name, stmt, types, types_count), - cond_ (cond), + cond_ (&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, + const Oid* types, + std::size_t types_count, + native_binding& native_cond, + binding& data) + : statement (conn, name, stmt, types, types_count), + cond_ (0), native_cond_ (native_cond), data_ (data), row_count_ (0), @@ -295,7 +313,9 @@ namespace odb execute () { result_.reset (); - bind_param (native_cond_, cond_); + + if (cond_ != 0) + bind_param (native_cond_, *cond_); result_.reset (PQexecPrepared (conn_.handle (), name_.c_str (), @@ -314,44 +334,50 @@ namespace odb current_row_ = 0; } + void select_statement:: + free_result () + { + result_.reset (); + row_count_ = 0; + current_row_ = 0; + } + + bool select_statement:: + next () + { + if (current_row_ <= row_count_) + ++current_row_; + + return current_row_ <= row_count_; + } + select_statement::result select_statement:: - fetch () + load () { - if (current_row_ >= row_count_) + if (current_row_ > row_count_) return no_data; PGresult* h (result_.get ()); - if (bind_result (data_.bind, data_.count, h, current_row_)) - { - ++current_row_; - return success; - } - - return truncated; + assert (current_row_ > 0); + return bind_result (data_.bind, data_.count, h, current_row_ - 1) ? + success : truncated; } void select_statement:: - refetch () + reload () { - assert (current_row_ < row_count_); + assert (current_row_ > 0); + assert (current_row_ <= row_count_); if (!bind_result (data_.bind, data_.count, result_.get (), - current_row_++, + current_row_ - 1, true)) assert (false); } - void select_statement:: - free_result () - { - result_.reset (); - row_count_ = 0; - current_row_ = 0; - } - // // insert_statement // -- cgit v1.1