aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-10-11 16:52:44 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-10-21 19:03:04 +0200
commit889e08e66a975d6deb6468f9ce608a7c3e263073 (patch)
treeca8f31f538fd2dd2383ec686e9c0c57d5c279a0c
parent0f878bebf2dcb0332614cd8acfe429152779c2c9 (diff)
Split 'in' binding into insert/update pair; rename 'out' to select
Also add the initial infrastructure for the readonly members support. Right now the split insert/update bindings allows us to avoid sending object id in UPDATE statements. It will also allows us to support readonly members.
-rw-r--r--odb/mysql/forward.hxx7
-rw-r--r--odb/mysql/object-result.txx19
-rw-r--r--odb/mysql/object-statements.hxx161
-rw-r--r--odb/mysql/object-statements.txx25
4 files changed, 116 insertions, 96 deletions
diff --git a/odb/mysql/forward.hxx b/odb/mysql/forward.hxx
index 08ada00..5d665dc 100644
--- a/odb/mysql/forward.hxx
+++ b/odb/mysql/forward.hxx
@@ -23,6 +23,13 @@ namespace odb
// Implementation details.
//
+ enum statement_kind
+ {
+ statement_select,
+ statement_insert,
+ statement_update
+ };
+
class binding;
class select_statement;
diff --git a/odb/mysql/object-result.txx b/odb/mysql/object-result.txx
index 3b0c0ca..d745537 100644
--- a/odb/mysql/object-result.txx
+++ b/odb/mysql/object-result.txx
@@ -109,11 +109,11 @@ namespace odb
{
typename object_traits::image_type& im (statements_.image ());
- if (im.version != statements_.out_image_version ())
+ if (im.version != statements_.select_image_version ())
{
- binding& b (statements_.out_image_binding ());
- object_traits::bind (b.bind, im, true);
- statements_.out_image_version (im.version);
+ binding& b (statements_.select_image_binding ());
+ object_traits::bind (b.bind, im, statement_select);
+ statements_.select_image_version (im.version);
b.version++;
}
}
@@ -133,14 +133,15 @@ namespace odb
typename object_traits::image_type& im (statements_.image ());
- if (object_traits::grow (im, statements_.out_image_truncated ()))
+ if (object_traits::grow (
+ im, statements_.select_image_truncated ()))
im.version++;
- if (im.version != statements_.out_image_version ())
+ if (im.version != statements_.select_image_version ())
{
- binding& b (statements_.out_image_binding ());
- object_traits::bind (b.bind, im, true);
- statements_.out_image_version (im.version);
+ binding& b (statements_.select_image_binding ());
+ object_traits::bind (b.bind, im, statement_select);
+ statements_.select_image_version (im.version);
b.version++;
statement_->refetch ();
}
diff --git a/odb/mysql/object-statements.hxx b/odb/mysql/object-statements.hxx
index 863271b..f259feb 100644
--- a/odb/mysql/object-statements.hxx
+++ b/odb/mysql/object-statements.hxx
@@ -101,10 +101,10 @@ namespace odb
typename object_traits::container_statement_cache_type
container_statement_cache_type;
- typedef mysql::insert_statement persist_statement_type;
- typedef mysql::select_statement find_statement_type;
+ typedef mysql::insert_statement insert_statement_type;
+ typedef mysql::select_statement select_statement_type;
typedef mysql::update_statement update_statement_type;
- typedef mysql::delete_statement erase_statement_type;
+ typedef mysql::delete_statement delete_statement_type;
// Automatic lock.
//
@@ -176,100 +176,83 @@ namespace odb
// Object image.
//
image_type&
- image ()
- {
- return image_;
- }
+ image () {return image_;}
+ // Insert binding.
+ //
std::size_t
- in_image_version () const
- {
- return in_image_version_;
- }
+ insert_image_version () const { return insert_image_version_;}
+
+ void
+ insert_image_version (std::size_t v) {insert_image_version_ = v;}
+ binding&
+ insert_image_binding () {return insert_image_binding_;}
+
+ // Update binding.
+ //
std::size_t
- out_image_version () const
- {
- return out_image_version_;
- }
+ update_image_version () const { return update_image_version_;}
void
- in_image_version (std::size_t v)
- {
- in_image_version_ = v;
- }
+ update_image_version (std::size_t v) {update_image_version_ = v;}
+
+ binding&
+ update_image_binding () {return update_image_binding_;}
+
+ // Select binding.
+ //
+ std::size_t
+ select_image_version () const { return select_image_version_;}
void
- out_image_version (std::size_t v)
- {
- out_image_version_ = v;
- }
+ select_image_version (std::size_t v) {select_image_version_ = v;}
binding&
- in_image_binding ()
- {
- return in_image_binding_;
- }
-
- binding&
- out_image_binding ()
- {
- return out_image_binding_;
- }
+ select_image_binding () {return select_image_binding_;}
my_bool*
- out_image_truncated ()
- {
- return out_image_truncated_;
- }
+ select_image_truncated () {return select_image_truncated_;}
- // Object id image.
+ // Object id image and binding.
//
id_image_type&
- id_image ()
- {
- return id_image_;
- }
+ id_image () {return id_image_;}
std::size_t
- id_image_version () const
- {
- return id_image_version_;
- }
+ id_image_version () const {return id_image_version_;}
void
- id_image_version (std::size_t v)
- {
- id_image_version_ = v;
- }
+ id_image_version (std::size_t v) {id_image_version_ = v;}
binding&
- id_image_binding ()
- {
- return id_image_binding_;
- }
+ id_image_binding () {return id_image_binding_;}
- persist_statement_type&
+ // Statements.
+ //
+ insert_statement_type&
persist_statement ()
{
if (persist_ == 0)
persist_.reset (
- new (details::shared) persist_statement_type (
- conn_, object_traits::persist_statement, in_image_binding_));
+ new (details::shared) insert_statement_type (
+ conn_,
+ object_traits::persist_statement,
+ insert_image_binding_));
return *persist_;
}
- find_statement_type&
+ select_statement_type&
find_statement ()
{
if (find_ == 0)
find_.reset (
- new (details::shared) find_statement_type (
+ new (details::shared) select_statement_type (
conn_,
object_traits::find_statement,
id_image_binding_,
- out_image_binding_));
+ select_image_binding_));
return *find_;
}
@@ -283,17 +266,17 @@ namespace odb
conn_,
object_traits::update_statement,
id_image_binding_,
- in_image_binding_));
+ update_image_binding_));
return *update_;
}
- erase_statement_type&
+ delete_statement_type&
erase_statement ()
{
if (erase_ == 0)
erase_.reset (
- new (details::shared) erase_statement_type (
+ new (details::shared) delete_statement_type (
conn_,
object_traits::erase_statement,
id_image_binding_));
@@ -321,34 +304,58 @@ namespace odb
clear_delayed_ ();
private:
+ // select = total
+ // insert = total - inverse
+ // update = total - inverse - id - readonly
+ //
+ static const std::size_t select_column_count =
+ object_traits::column_count;
+
+ static const std::size_t insert_column_count =
+ object_traits::column_count - object_traits::inverse_column_count;
+
+ static const std::size_t update_column_count = insert_column_count -
+ object_traits::id_column_count - object_traits::readonly_column_count;
+
+ static const std::size_t id_column_count =
+ object_traits::id_column_count;
+
+ private:
container_statement_cache_type container_statement_cache_;
image_type image_;
- // In (send) binding. The last element is the id parameter. The
- // update statement depends on this being one contiguous arrays.
+ // Select binding.
//
- std::size_t in_image_version_;
- binding in_image_binding_;
- MYSQL_BIND in_image_bind_[object_traits::in_column_count + 1];
+ std::size_t select_image_version_;
+ binding select_image_binding_;
+ MYSQL_BIND select_image_bind_[select_column_count];
+ my_bool select_image_truncated_[select_column_count];
- // Out (receive) binding.
+ // Insert binding.
+ //
+ std::size_t insert_image_version_;
+ binding insert_image_binding_;
+ MYSQL_BIND insert_image_bind_[insert_column_count];
+
+ // Update binding. The suffix of the bind array is object id. The
+ // update statement depends on this being one contiguous arrays.
//
- std::size_t out_image_version_;
- binding out_image_binding_;
- MYSQL_BIND out_image_bind_[object_traits::out_column_count];
- my_bool out_image_truncated_[object_traits::out_column_count];
+ std::size_t update_image_version_;
+ binding update_image_binding_;
+ MYSQL_BIND update_image_bind_[update_column_count + id_column_count];
- // Id image binding (only in).
+ // Id image binding (only used as a parameter). Uses the suffix in
+ // the update bind.
//
id_image_type id_image_;
std::size_t id_image_version_;
binding id_image_binding_;
- details::shared_ptr<persist_statement_type> persist_;
- details::shared_ptr<find_statement_type> find_;
+ details::shared_ptr<insert_statement_type> persist_;
+ details::shared_ptr<select_statement_type> find_;
details::shared_ptr<update_statement_type> update_;
- details::shared_ptr<erase_statement_type> erase_;
+ details::shared_ptr<delete_statement_type> erase_;
// Delayed loading.
//
diff --git a/odb/mysql/object-statements.txx b/odb/mysql/object-statements.txx
index b124689..740a7d9 100644
--- a/odb/mysql/object-statements.txx
+++ b/odb/mysql/object-statements.txx
@@ -27,23 +27,28 @@ namespace odb
object_statements (connection_type& conn)
: object_statements_base (conn),
container_statement_cache_ (conn),
- in_image_binding_ (in_image_bind_, object_traits::in_column_count),
- out_image_binding_ (out_image_bind_, object_traits::out_column_count),
- id_image_binding_ (in_image_bind_ + object_traits::in_column_count, 1)
+ select_image_binding_ (select_image_bind_, select_column_count),
+ insert_image_binding_ (insert_image_bind_, insert_column_count),
+ update_image_binding_ (update_image_bind_, update_column_count),
+ id_image_binding_ (update_image_bind_ + update_column_count,
+ id_column_count)
{
image_.version = 0;
- in_image_version_ = 0;
- out_image_version_ = 0;
+ select_image_version_ = 0;
+ insert_image_version_ = 0;
+ update_image_version_ = 0;
id_image_.version = 0;
id_image_version_ = 0;
- std::memset (in_image_bind_, 0, sizeof (in_image_bind_));
- std::memset (out_image_bind_, 0, sizeof (out_image_bind_));
- std::memset (out_image_truncated_, 0, sizeof (out_image_truncated_));
+ std::memset (insert_image_bind_, 0, sizeof (insert_image_bind_));
+ std::memset (update_image_bind_, 0, sizeof (update_image_bind_));
+ std::memset (select_image_bind_, 0, sizeof (select_image_bind_));
+ std::memset (
+ select_image_truncated_, 0, sizeof (select_image_truncated_));
- for (std::size_t i (0); i < object_traits::out_column_count; ++i)
- out_image_bind_[i].error = out_image_truncated_ + i;
+ for (std::size_t i (0); i < select_column_count; ++i)
+ select_image_bind_[i].error = select_image_truncated_ + i;
}
template <typename T>