aboutsummaryrefslogtreecommitdiff
path: root/odb/sqlite
diff options
context:
space:
mode:
Diffstat (limited to 'odb/sqlite')
-rw-r--r--odb/sqlite/object-statements.hxx14
-rw-r--r--odb/sqlite/object-statements.txx4
-rw-r--r--odb/sqlite/statement.cxx50
-rw-r--r--odb/sqlite/statement.hxx26
4 files changed, 51 insertions, 43 deletions
diff --git a/odb/sqlite/object-statements.hxx b/odb/sqlite/object-statements.hxx
index 15c848d..53445b8 100644
--- a/odb/sqlite/object-statements.hxx
+++ b/odb/sqlite/object-statements.hxx
@@ -220,6 +220,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_;}
@@ -297,7 +303,6 @@ namespace odb
new (details::shared) update_statement_type (
conn_,
object_traits::update_statement,
- id_image_binding_,
update_image_binding_));
update_->cached (true);
@@ -377,10 +382,13 @@ namespace odb
binding insert_image_binding_;
bind insert_image_bind_[insert_column_count];
- // Update binding. The suffix of the bind array is object id. We
- // do it this way for consistency with other database runtimes.
+ // 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];
diff --git a/odb/sqlite/object-statements.txx b/odb/sqlite/object-statements.txx
index d2bd06f..7c5c178 100644
--- a/odb/sqlite/object-statements.txx
+++ b/odb/sqlite/object-statements.txx
@@ -33,7 +33,8 @@ namespace odb
container_statement_cache_ (conn),
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),
+ update_image_binding_ (update_image_bind_,
+ update_column_count + id_column_count),
id_image_binding_ (update_image_bind_ + update_column_count,
id_column_count)
{
@@ -41,6 +42,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/sqlite/statement.cxx b/odb/sqlite/statement.cxx
index 9071f68..a7ace7a 100644
--- a/odb/sqlite/statement.cxx
+++ b/odb/sqlite/statement.cxx
@@ -56,15 +56,17 @@ namespace odb
}
void statement::
- bind_param (const bind* p, size_t n, size_t start_param)
+ bind_param (const bind* p, size_t n)
{
int e (SQLITE_OK);
- start_param++; // SQLite parameters are counted from 1.
- for (size_t i (0); e == SQLITE_OK && i < n; ++i)
+ // SQLite parameters are counted from 1.
+ //
+ n++;
+ for (size_t i (1); e == SQLITE_OK && i < n; ++i, ++p)
{
- const bind& b (p[i]);
- int j (static_cast<int> (i + start_param));
+ const bind& b (*p);
+ int j (static_cast<int> (i));
if (b.is_null != 0 && *b.is_null)
{
@@ -244,17 +246,17 @@ namespace odb
select_statement::
select_statement (connection& conn,
const string& s,
- binding& cond,
- binding& data)
- : statement (conn, s), cond_ (&cond), data_ (data)
+ binding& param,
+ binding& result)
+ : statement (conn, s), param_ (&param), result_ (result)
{
}
select_statement::
select_statement (connection& conn,
const string& s,
- binding& data)
- : statement (conn, s), cond_ (0), data_ (data)
+ binding& result)
+ : statement (conn, s), param_ (0), result_ (result)
{
}
@@ -266,8 +268,8 @@ namespace odb
done_ = false;
- if (cond_ != 0)
- bind_param (cond_->bind, cond_->count);
+ if (param_ != 0)
+ bind_param (param_->bind, param_->count);
active (true);
}
@@ -314,7 +316,7 @@ namespace odb
if (done_)
return no_data;
- return bind_result (data_.bind, data_.count) ? success : truncated;
+ return bind_result (result_.bind, result_.count) ? success : truncated;
}
void select_statement::
@@ -322,7 +324,7 @@ namespace odb
{
assert (!done_);
- if (!bind_result (data_.bind, data_.count, true))
+ if (!bind_result (result_.bind, result_.count, true))
assert (false);
}
@@ -330,15 +332,15 @@ namespace odb
//
insert_statement::
- insert_statement (connection& conn, const string& s, binding& data)
- : statement (conn, s), data_ (data)
+ insert_statement (connection& conn, const string& s, binding& param)
+ : statement (conn, s), param_ (param)
{
}
bool insert_statement::
execute ()
{
- bind_param (data_.bind, data_.count);
+ bind_param (param_.bind, param_.count);
int e;
sqlite3* h (conn_.handle ());
@@ -382,17 +384,15 @@ namespace odb
update_statement::
update_statement (connection& conn,
const string& s,
- binding& cond,
- binding& data)
- : statement (conn, s), cond_ (cond), data_ (data)
+ binding& param)
+ : statement (conn, s), param_ (param)
{
}
void update_statement::
execute ()
{
- bind_param (data_.bind, data_.count);
- bind_param (cond_.bind, cond_.count, data_.count);
+ bind_param (param_.bind, param_.count);
int e;
sqlite3* h (conn_.handle ());
@@ -418,15 +418,15 @@ namespace odb
//
delete_statement::
- delete_statement (connection& conn, const string& s, binding& cond)
- : statement (conn, s), cond_ (cond)
+ delete_statement (connection& conn, const string& s, binding& param)
+ : statement (conn, s), param_ (param)
{
}
unsigned long long delete_statement::
execute ()
{
- bind_param (cond_.bind, cond_.count);
+ bind_param (param_.bind, param_.count);
int e;
sqlite3* h (conn_.handle ());
diff --git a/odb/sqlite/statement.hxx b/odb/sqlite/statement.hxx
index 69f5a95..2bf770c 100644
--- a/odb/sqlite/statement.hxx
+++ b/odb/sqlite/statement.hxx
@@ -80,7 +80,7 @@ namespace odb
protected:
void
- bind_param (const bind*, std::size_t count, std::size_t start_param = 0);
+ bind_param (const bind*, std::size_t count);
// Extract row columns into the bound buffers. If the truncated
// argument is true, then only truncated columns are extracted.
@@ -213,12 +213,12 @@ namespace odb
public:
select_statement (connection& conn,
const std::string& statement,
- binding& cond,
- binding& data);
+ binding& param,
+ binding& result);
select_statement (connection& conn,
const std::string& statement,
- binding& data);
+ binding& result);
// Common select interface expected by the generated code.
//
@@ -277,8 +277,8 @@ namespace odb
private:
bool done_;
- binding* cond_;
- binding& data_;
+ binding* param_;
+ binding& result_;
};
class LIBODB_SQLITE_EXPORT insert_statement: public statement
@@ -286,7 +286,7 @@ namespace odb
public:
insert_statement (connection& conn,
const std::string& statement,
- binding& data);
+ binding& param);
// Return true if successful and false if the row is a duplicate.
// All other errors are reported by throwing exceptions.
@@ -302,7 +302,7 @@ namespace odb
insert_statement& operator= (const insert_statement&);
private:
- binding& data_;
+ binding& param_;
};
class LIBODB_SQLITE_EXPORT update_statement: public statement
@@ -310,8 +310,7 @@ namespace odb
public:
update_statement (connection& conn,
const std::string& statement,
- binding& cond,
- binding& data);
+ binding& param);
void
execute ();
@@ -320,8 +319,7 @@ namespace odb
update_statement& operator= (const update_statement&);
private:
- binding& cond_;
- binding& data_;
+ binding& param_;
};
class LIBODB_SQLITE_EXPORT delete_statement: public statement
@@ -329,7 +327,7 @@ namespace odb
public:
delete_statement (connection& conn,
const std::string& statement,
- binding& cond);
+ binding& param);
unsigned long long
execute ();
@@ -339,7 +337,7 @@ namespace odb
delete_statement& operator= (const delete_statement&);
private:
- binding& cond_;
+ binding& param_;
};
}
}