Permalink
Browse files

fix to allow a statement to be executed multiple times

- close the cursor if one is open
- do not clear parameter bindings between executions
  • Loading branch information...
toonen committed Aug 17, 2012
1 parent 612050e commit 0c0cffda92cd5535323b9d60190be2c84aa9220e
Showing with 8 additions and 4 deletions.
  1. +8 −4 src/backends/db2/statement.cpp
@@ -140,7 +140,8 @@ void db2_statement_backend::prepare(std::string const & query ,
statement_backend::exec_fetch_result
db2_statement_backend::execute(int number )
{
SQLULEN rows_processed = 0;
SQLUINTEGER rows_processed = 0;
SQLRETURN cliRC;
if (hasVectorUseElements)
{
@@ -149,8 +150,13 @@ db2_statement_backend::execute(int number )
// if we are called twice for the same statement we need to close the open
// cursor or an "invalid cursor state" error will occur on execute
cliRC = SQLFreeStmt(hStmt,SQL_CLOSE);
if (cliRC != SQL_SUCCESS)
{
throw db2_soci_error(db2_soci_error::sqlState("Statement execution error",SQL_HANDLE_STMT,hStmt),cliRC);
}
SQLRETURN cliRC = SQLExecute(hStmt);
cliRC = SQLExecute(hStmt);
if (cliRC != SQL_SUCCESS)
{
throw db2_soci_error(db2_soci_error::sqlState("Statement execution error",SQL_HANDLE_STMT,hStmt),cliRC);
@@ -164,8 +170,6 @@ db2_statement_backend::execute(int number )
return fetch(number);
}
SQLFreeStmt(hStmt,SQL_RESET_PARAMS); //Prepare for next call
return ef_success;
}

0 comments on commit 0c0cffd

Please sign in to comment.