aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-09-05 10:14:34 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-09-05 10:14:34 +0200
commit141253ea17264e122e440cae441bf3d952329d35 (patch)
tree8eee6d9b1bf3ad7d628cbb7a636bc66cd88d5780
parentb51a2071da2169ced13dd3da669486a6f82dada4 (diff)
Allow select statement without parameters
-rw-r--r--odb/mysql/statement.cxx24
-rw-r--r--odb/mysql/statement.hxx7
2 files changed, 26 insertions, 5 deletions
diff --git a/odb/mysql/statement.cxx b/odb/mysql/statement.cxx
index 3a76c4d..d1b90e1 100644
--- a/odb/mysql/statement.cxx
+++ b/odb/mysql/statement.cxx
@@ -68,7 +68,7 @@ namespace odb
end_ (false),
cached_ (false),
rows_ (0),
- cond_ (cond),
+ cond_ (&cond),
cond_version_ (0),
data_ (data),
data_version_ (0)
@@ -79,6 +79,22 @@ namespace odb
translate_error (conn_, stmt_);
}
+ select_statement::
+ select_statement (connection& conn, const string& s, binding& data)
+ : statement (conn),
+ end_ (false),
+ cached_ (false),
+ rows_ (0),
+ cond_ (0),
+ data_ (data),
+ data_version_ (0)
+ {
+ conn_.clear ();
+
+ if (mysql_stmt_prepare (stmt_, s.c_str (), s.size ()) != 0)
+ translate_error (conn_, stmt_);
+ }
+
void select_statement::
execute ()
{
@@ -93,12 +109,12 @@ namespace odb
if (mysql_stmt_reset (stmt_))
translate_error (conn_, stmt_);
- if (cond_version_ != cond_.version)
+ if (cond_ != 0 && cond_version_ != cond_->version)
{
- if (mysql_stmt_bind_param (stmt_, cond_.bind))
+ if (mysql_stmt_bind_param (stmt_, cond_->bind))
translate_error (conn_, stmt_);
- cond_version_ = cond_.version;
+ cond_version_ = cond_->version;
}
if (data_version_ != data_.version)
diff --git a/odb/mysql/statement.hxx b/odb/mysql/statement.hxx
index 7cc1e1f..0c15f8c 100644
--- a/odb/mysql/statement.hxx
+++ b/odb/mysql/statement.hxx
@@ -57,6 +57,11 @@ namespace odb
const std::string& statement,
binding& cond,
binding& data);
+
+ select_statement (connection& conn,
+ const std::string& statement,
+ binding& data);
+
enum result
{
success,
@@ -114,7 +119,7 @@ namespace odb
std::size_t rows_;
std::size_t size_;
- binding& cond_;
+ binding* cond_;
std::size_t cond_version_;
binding& data_;