aboutsummaryrefslogtreecommitdiff
path: root/odb/pgsql/statement.cxx
diff options
context:
space:
mode:
authorConstantin Michael <constantin@codesynthesis.com>2011-07-05 13:02:03 +0200
committerConstantin Michael <constantin@codesynthesis.com>2011-07-05 13:02:03 +0200
commit0fba3bc7e0747e23ca2698e0acc82e80b569e531 (patch)
treeb39290a6334adc2b451a9e7fd397c35a09389487 /odb/pgsql/statement.cxx
parent283fec23e49a9e62a8717879808343420338d01e (diff)
Implement PostgreSQL specific fetch operations for select_statement
Diffstat (limited to 'odb/pgsql/statement.cxx')
-rw-r--r--odb/pgsql/statement.cxx70
1 files changed, 48 insertions, 22 deletions
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
//