summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-06-02 00:43:47 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2015-06-02 00:43:47 +0100
commit93da8da13f7af27d9a884bacf9e0157f31827905 (patch)
treee56427fdbe38d4cc2f035b8751068a9001c8ca34
parentAdd support for RDBMS boolean/bit types (diff)
downloadlibdbpp-mysql-93da8da13f7af27d9a884bacf9e0157f31827905.tar.bz2
libdbpp-mysql-93da8da13f7af27d9a884bacf9e0157f31827905.tar.xz
libdbpp-mysql-93da8da13f7af27d9a884bacf9e0157f31827905.zip
Fix behaviour of multiple executions
-rw-r--r--libmysqlpp/selectcommand.cpp7
-rw-r--r--libmysqlpp/selectcommand.h1
2 files changed, 7 insertions, 1 deletions
diff --git a/libmysqlpp/selectcommand.cpp b/libmysqlpp/selectcommand.cpp
index 41b28b6..f0a5974 100644
--- a/libmysqlpp/selectcommand.cpp
+++ b/libmysqlpp/selectcommand.cpp
@@ -8,6 +8,7 @@ MySQL::SelectCommand::SelectCommand(const Connection * conn, const std::string &
DB::Command(sql),
DB::SelectCommand(sql),
MySQL::Command(conn, sql),
+ prepared(false),
executed(false)
{
}
@@ -15,7 +16,7 @@ MySQL::SelectCommand::SelectCommand(const Connection * conn, const std::string &
void
MySQL::SelectCommand::execute()
{
- if (!executed) {
+ if (!prepared) {
bindParams();
fields.resize(mysql_stmt_field_count(stmt));
for (Binds::iterator i = fields.begin(); i != fields.end(); ++i) {
@@ -68,6 +69,9 @@ MySQL::SelectCommand::execute()
if (mysql_stmt_bind_result(stmt, &fields.front())) {
throw Error(mysql_stmt_error(stmt));
}
+ prepared = true;
+ }
+ if (!executed) {
if (mysql_stmt_execute(stmt)) {
throw Error(mysql_stmt_error(stmt));
}
@@ -86,6 +90,7 @@ MySQL::SelectCommand::fetch()
case 0:
return true;
case MYSQL_NO_DATA:
+ executed = false;
return false;
default:
throw Error(mysql_stmt_error(stmt));
diff --git a/libmysqlpp/selectcommand.h b/libmysqlpp/selectcommand.h
index 7ffff54..58c569b 100644
--- a/libmysqlpp/selectcommand.h
+++ b/libmysqlpp/selectcommand.h
@@ -15,6 +15,7 @@ namespace MySQL {
void execute();
private:
+ bool prepared;
bool executed;
Binds fields;
};