aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-10-11 16:52:45 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-10-21 19:06:55 +0200
commite514a43339bbce7c8d15fb1350674ecfc5649e14 (patch)
tree3dc9d152ead52740fd0dc470fc62eb85108b8ebe
parent0cd9d3b8bbe0e243c37336b3b8ffb3d40e968034 (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/sqlite/forward.hxx7
-rw-r--r--odb/sqlite/object-result.txx18
-rw-r--r--odb/sqlite/object-statements.hxx158
-rw-r--r--odb/sqlite/object-statements.txx25
4 files changed, 113 insertions, 95 deletions
diff --git a/odb/sqlite/forward.hxx b/odb/sqlite/forward.hxx
index 5203434..23d995e 100644
--- a/odb/sqlite/forward.hxx
+++ b/odb/sqlite/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/sqlite/object-result.txx b/odb/sqlite/object-result.txx
index 7675262..6e3a0c9 100644
--- a/odb/sqlite/object-result.txx
+++ b/odb/sqlite/object-result.txx
@@ -94,11 +94,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++;
}
@@ -106,14 +106,14 @@ namespace odb
if (r == select_statement::truncated)
{
- 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_->reload ();
}
diff --git a/odb/sqlite/object-statements.hxx b/odb/sqlite/object-statements.hxx
index 4816d66..a651507 100644
--- a/odb/sqlite/object-statements.hxx
+++ b/odb/sqlite/object-statements.hxx
@@ -101,10 +101,10 @@ namespace odb
typename object_traits::container_statement_cache_type
container_statement_cache_type;
- typedef sqlite::insert_statement persist_statement_type;
- typedef sqlite::select_statement find_statement_type;
+ typedef sqlite::insert_statement insert_statement_type;
+ typedef sqlite::select_statement select_statement_type;
typedef sqlite::update_statement update_statement_type;
- typedef sqlite::delete_statement erase_statement_type;
+ typedef sqlite::delete_statement delete_statement_type;
// Automatic lock.
//
@@ -177,89 +177,70 @@ namespace odb
// Object image.
//
image_type&
- image ()
- {
- return image_;
- }
-
- std::size_t
- in_image_version () const
- {
- return in_image_version_;
- }
+ image () {return image_;}
+ // Insert binding.
+ //
std::size_t
- out_image_version () const
- {
- return out_image_version_;
- }
+ insert_image_version () const { return insert_image_version_;}
void
- in_image_version (std::size_t v)
- {
- in_image_version_ = v;
- }
+ insert_image_version (std::size_t v) {insert_image_version_ = v;}
+
+ binding&
+ insert_image_binding () {return insert_image_binding_;}
+
+ // Update binding.
+ //
+ std::size_t
+ update_image_version () const { return update_image_version_;}
void
- out_image_version (std::size_t v)
- {
- out_image_version_ = v;
- }
+ update_image_version (std::size_t v) {update_image_version_ = v;}
binding&
- in_image_binding ()
- {
- return in_image_binding_;
- }
+ update_image_binding () {return update_image_binding_;}
+
+ // Select binding.
+ //
+ std::size_t
+ select_image_version () const { return select_image_version_;}
+
+ void
+ select_image_version (std::size_t v) {select_image_version_ = v;}
binding&
- out_image_binding ()
- {
- return out_image_binding_;
- }
+ select_image_binding () {return select_image_binding_;}
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_;}
// Statements.
//
- persist_statement_type&
+ 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_));
persist_->cached (true);
}
@@ -267,17 +248,17 @@ namespace odb
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_));
find_->cached (true);
}
@@ -295,7 +276,7 @@ namespace odb
conn_,
object_traits::update_statement,
id_image_binding_,
- in_image_binding_));
+ update_image_binding_));
update_->cached (true);
}
@@ -303,13 +284,13 @@ namespace odb
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_));
@@ -340,33 +321,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.
+ // Select binding.
+ //
+ std::size_t select_image_version_;
+ binding select_image_binding_;
+ bind select_image_bind_[select_column_count];
+ bool select_image_truncated_[select_column_count];
+
+ // Insert binding.
//
- std::size_t in_image_version_;
- binding in_image_binding_;
- bind in_image_bind_[object_traits::in_column_count + 1];
+ std::size_t insert_image_version_;
+ binding insert_image_binding_;
+ bind insert_image_bind_[insert_column_count];
- // Out (receive) binding.
+ // Update binding. The suffix of the bind array is object id. We
+ // do it this way for consistency with other database runtimes.
//
- std::size_t out_image_version_;
- binding out_image_binding_;
- bind out_image_bind_[object_traits::out_column_count];
- bool out_image_truncated_[object_traits::out_column_count];
+ std::size_t update_image_version_;
+ binding update_image_binding_;
+ 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/sqlite/object-statements.txx b/odb/sqlite/object-statements.txx
index 04d57c8..fd596e7 100644
--- a/odb/sqlite/object-statements.txx
+++ b/odb/sqlite/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].truncated = out_image_truncated_ + i;
+ for (std::size_t i (0); i < select_column_count; ++i)
+ select_image_bind_[i].truncated = select_image_truncated_ + i;
}
template <typename T>