aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-10-30 17:52:31 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-10-30 17:52:31 +0200
commit1adbed32a10e327bc1ab108133fcd2961ea1e07e (patch)
treeadf0cb24d93b39d16734685f9685987d95c786c9
parentf3e83073310e5fbafb142bb8d3cd1b03ed6088e9 (diff)
Rework statement interfaces wrt param/result passing
-rw-r--r--odb/pgsql/object-statements.hxx15
-rw-r--r--odb/pgsql/object-statements.txx6
-rw-r--r--odb/pgsql/statement.cxx138
-rw-r--r--odb/pgsql/statement.hxx55
4 files changed, 104 insertions, 110 deletions
diff --git a/odb/pgsql/object-statements.hxx b/odb/pgsql/object-statements.hxx
index 2a26cce..f80ab42 100644
--- a/odb/pgsql/object-statements.hxx
+++ b/odb/pgsql/object-statements.hxx
@@ -219,6 +219,12 @@ namespace odb
void
update_image_version (std::size_t v) {update_image_version_ = v;}
+ std::size_t
+ update_id_image_version () const { return update_id_image_version_;}
+
+ void
+ update_id_image_version (std::size_t v) {update_id_image_version_ = v;}
+
binding&
update_image_binding () {return update_image_binding_;}
@@ -304,8 +310,6 @@ namespace odb
object_traits::update_statement,
object_traits::update_statement_types,
update_column_count + id_column_count,
- id_image_binding_,
- id_image_native_binding_,
update_image_binding_,
update_image_native_binding_));
}
@@ -390,10 +394,13 @@ namespace odb
int insert_image_lengths_[insert_column_count];
int insert_image_formats_[insert_column_count];
- // Update binding. The suffix of the bind array is object id. we
- // do it this way for consistency with other databases.
+ // Update binding. Note that the id suffix is bound to id_image_
+ // below instead of image_ which makes this binding effectively
+ // bound to two images. As a result, we have to track versions
+ // for both of them.
//
std::size_t update_image_version_;
+ std::size_t update_id_image_version_;
binding update_image_binding_;
bind update_image_bind_[update_column_count + id_column_count];
native_binding update_image_native_binding_;
diff --git a/odb/pgsql/object-statements.txx b/odb/pgsql/object-statements.txx
index ba8b0f4..0e61715 100644
--- a/odb/pgsql/object-statements.txx
+++ b/odb/pgsql/object-statements.txx
@@ -40,11 +40,12 @@ namespace odb
insert_image_formats_,
insert_column_count),
// update
- update_image_binding_ (update_image_bind_, update_column_count),
+ update_image_binding_ (update_image_bind_,
+ update_column_count + id_column_count),
update_image_native_binding_ (update_image_values_,
update_image_lengths_,
update_image_formats_,
- update_column_count),
+ update_column_count + id_column_count),
// id
id_image_binding_ (update_image_bind_ + update_column_count,
id_column_count),
@@ -58,6 +59,7 @@ namespace odb
select_image_version_ = 0;
insert_image_version_ = 0;
update_image_version_ = 0;
+ update_id_image_version_ = 0;
id_image_.version = 0;
id_image_version_ = 0;
diff --git a/odb/pgsql/statement.cxx b/odb/pgsql/statement.cxx
index e76e081..f119fd0 100644
--- a/odb/pgsql/statement.cxx
+++ b/odb/pgsql/statement.cxx
@@ -315,13 +315,13 @@ namespace odb
const std::string& stmt,
const Oid* types,
std::size_t types_count,
- binding& cond,
- native_binding& native_cond,
- binding& data)
+ binding& param,
+ native_binding& native_param,
+ binding& result)
: statement (conn, name, stmt, types, types_count),
- cond_ (&cond),
- native_cond_ (&native_cond),
- data_ (data),
+ param_ (&param),
+ native_param_ (&native_param),
+ result_ (result),
row_count_ (0),
current_row_ (0)
{
@@ -333,12 +333,12 @@ namespace odb
const std::string& stmt,
const Oid* types,
std::size_t types_count,
- native_binding& native_cond,
- binding& data)
+ native_binding& native_param,
+ binding& result)
: statement (conn, name, stmt, types, types_count),
- cond_ (0),
- native_cond_ (&native_cond),
- data_ (data),
+ param_ (0),
+ native_param_ (&native_param),
+ result_ (result),
row_count_ (0),
current_row_ (0)
{
@@ -348,11 +348,11 @@ namespace odb
select_statement (connection& conn,
const std::string& name,
const std::string& stmt,
- binding& data)
+ binding& result)
: statement (conn, name, stmt, 0, 0),
- cond_ (0),
- native_cond_ (0),
- data_ (data),
+ param_ (0),
+ native_param_ (0),
+ result_ (result),
row_count_ (0),
current_row_ (0)
{
@@ -361,33 +361,33 @@ namespace odb
void select_statement::
execute ()
{
- result_.reset ();
+ handle_.reset ();
- if (cond_ != 0)
- bind_param (*native_cond_, *cond_);
+ if (param_ != 0)
+ bind_param (*native_param_, *param_);
- bool in (native_cond_ != 0);
+ bool in (native_param_ != 0);
- result_.reset (
+ handle_.reset (
PQexecPrepared (conn_.handle (),
name_.c_str (),
- in ? native_cond_->count : 0,
- in ? native_cond_->values : 0,
- in ? native_cond_->lengths : 0,
- in ? native_cond_->formats : 0,
+ in ? native_param_->count : 0,
+ in ? native_param_->values : 0,
+ in ? native_param_->lengths : 0,
+ in ? native_param_->formats : 0,
1));
- if (!is_good_result (result_))
- translate_error (conn_, result_);
+ if (!is_good_result (handle_))
+ translate_error (conn_, handle_);
- row_count_ = static_cast<size_t> (PQntuples (result_));
+ row_count_ = static_cast<size_t> (PQntuples (handle_));
current_row_ = 0;
}
void select_statement::
free_result ()
{
- result_.reset ();
+ handle_.reset ();
row_count_ = 0;
current_row_ = 0;
}
@@ -408,7 +408,10 @@ namespace odb
return no_data;
assert (current_row_ > 0);
- return bind_result (data_.bind, data_.count, result_, current_row_ - 1)
+ return bind_result (result_.bind,
+ result_.count,
+ handle_,
+ current_row_ - 1)
? success
: truncated;
}
@@ -419,9 +422,9 @@ namespace odb
assert (current_row_ > 0);
assert (current_row_ <= row_count_);
- if (!bind_result (data_.bind,
- data_.count,
- result_,
+ if (!bind_result (result_.bind,
+ result_.count,
+ handle_,
current_row_ - 1,
true))
assert (false);
@@ -442,12 +445,12 @@ namespace odb
const string& stmt,
const Oid* types,
size_t types_count,
- binding& data,
- native_binding& native_data,
+ binding& param,
+ native_binding& native_param,
bool returning)
: statement (conn, name, stmt, types, types_count),
- data_ (data),
- native_data_ (native_data),
+ param_ (param),
+ native_param_ (native_param),
returning_ (returning)
{
}
@@ -455,15 +458,15 @@ namespace odb
bool insert_statement::
execute ()
{
- bind_param (native_data_, data_);
+ bind_param (native_param_, param_);
auto_handle<PGresult> h (
PQexecPrepared (conn_.handle (),
name_.c_str (),
- native_data_.count,
- native_data_.values,
- native_data_.lengths,
- native_data_.formats,
+ native_param_.count,
+ native_param_.values,
+ native_param_.lengths,
+ native_param_.formats,
1));
ExecStatusType stat (PGRES_FATAL_ERROR);
@@ -536,35 +539,26 @@ namespace odb
const string& stmt,
const Oid* types,
size_t types_count,
- binding& cond,
- native_binding& native_cond,
- binding& data,
- native_binding& native_data)
+ binding& param,
+ native_binding& native_param)
: statement (conn, name, stmt, types, types_count),
- cond_ (cond),
- native_cond_ (native_cond),
- data_ (data),
- native_data_ (native_data)
+ param_ (param),
+ native_param_ (native_param)
{
}
void update_statement::
execute ()
{
- // We assume that the values, lengths, and formats members of
- // native_cond_ are suffixes of the corresponding members of
- // native_data_.
- //
- bind_param (native_data_, data_);
- bind_param (native_cond_, cond_);
+ bind_param (native_param_, param_);
auto_handle<PGresult> h (
PQexecPrepared (conn_.handle (),
name_.c_str (),
- native_data_.count + native_cond_.count,
- native_data_.values,
- native_data_.lengths,
- native_data_.formats,
+ native_param_.count,
+ native_param_.values,
+ native_param_.lengths,
+ native_param_.formats,
1));
if (!is_good_result (h))
@@ -592,11 +586,11 @@ namespace odb
const string& stmt,
const Oid* types,
size_t types_count,
- binding& cond,
- native_binding& native_cond)
+ binding& param,
+ native_binding& native_param)
: statement (conn, name, stmt, types, types_count),
- cond_ (&cond),
- native_cond_ (native_cond)
+ param_ (&param),
+ native_param_ (native_param)
{
}
@@ -606,26 +600,26 @@ namespace odb
const string& stmt,
const Oid* types,
size_t types_count,
- native_binding& native_cond)
+ native_binding& native_param)
: statement (conn, name, stmt, types, types_count),
- cond_ (0),
- native_cond_ (native_cond)
+ param_ (0),
+ native_param_ (native_param)
{
}
unsigned long long delete_statement::
execute ()
{
- if (cond_ != 0)
- bind_param (native_cond_, *cond_);
+ if (param_ != 0)
+ bind_param (native_param_, *param_);
auto_handle<PGresult> h (
PQexecPrepared (conn_.handle (),
name_.c_str (),
- native_cond_.count,
- native_cond_.values,
- native_cond_.lengths,
- native_cond_.formats,
+ native_param_.count,
+ native_param_.values,
+ native_param_.lengths,
+ native_param_.formats,
1));
if (!is_good_result (h))
diff --git a/odb/pgsql/statement.hxx b/odb/pgsql/statement.hxx
index 8488e12..0432920 100644
--- a/odb/pgsql/statement.hxx
+++ b/odb/pgsql/statement.hxx
@@ -78,22 +78,22 @@ namespace odb
const std::string& stmt,
const Oid* types,
std::size_t types_count,
- binding& cond,
- native_binding& native_cond,
- binding& data);
+ binding& param,
+ native_binding& native_param,
+ binding& result);
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);
+ native_binding& native_param,
+ binding& result);
select_statement (connection& conn,
const std::string& name,
const std::string& stmt,
- binding& data);
+ binding& result);
// Common select interface expected by the generated code.
//
@@ -158,12 +158,12 @@ namespace odb
select_statement& operator= (const select_statement&);
private:
- binding* cond_;
- native_binding* native_cond_;
+ binding* param_;
+ native_binding* native_param_;
- binding& data_;
+ binding& result_;
- auto_handle<PGresult> result_;
+ auto_handle<PGresult> handle_;
std::size_t row_count_;
std::size_t current_row_;
};
@@ -179,8 +179,8 @@ namespace odb
const std::string& stmt,
const Oid* types,
std::size_t types_count,
- binding& data,
- native_binding& native_data,
+ binding& param,
+ native_binding& native_param,
bool returning);
// Return true if successful and false if the row is a duplicate.
@@ -200,8 +200,8 @@ namespace odb
insert_statement& operator= (const insert_statement&);
private:
- binding& data_;
- native_binding& native_data_;
+ binding& param_;
+ native_binding& native_param_;
bool returning_;
unsigned long long id_;
@@ -213,19 +213,13 @@ namespace odb
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 types_count,
- binding& cond,
- native_binding& native_cond,
- binding& data,
- native_binding& native_data);
+ binding& param,
+ native_binding& native_param);
void
execute ();
@@ -235,11 +229,8 @@ namespace odb
update_statement& operator= (const update_statement&);
private:
- binding& cond_;
- native_binding& native_cond_;
-
- binding& data_;
- native_binding& native_data_;
+ binding& param_;
+ native_binding& native_param_;
};
class LIBODB_PGSQL_EXPORT delete_statement: public statement
@@ -253,15 +244,15 @@ namespace odb
const std::string& stmt,
const Oid* types,
std::size_t types_count,
- binding& cond,
- native_binding& native_cond);
+ binding& param,
+ native_binding& native_param);
delete_statement (connection& conn,
const std::string& name,
const std::string& stmt,
const Oid* types,
std::size_t types_count,
- native_binding& native_cond);
+ native_binding& native_param);
unsigned long long
execute ();
@@ -271,8 +262,8 @@ namespace odb
delete_statement& operator= (const delete_statement&);
private:
- binding* cond_;
- native_binding& native_cond_;
+ binding* param_;
+ native_binding& native_param_;
};
}
}