Skip to content

Commit

Permalink
fix to allow a statement to be executed multiple times
Browse files Browse the repository at this point in the history
- close the cursor if one is open
- do not clear parameter bindings between executions
  • Loading branch information
toonen committed Mar 7, 2013
1 parent 612050e commit 0c0cffd
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/backends/db2/statement.cpp
Expand Up @@ -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)
{
Expand All @@ -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);
Expand All @@ -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;
}

Expand Down

0 comments on commit 0c0cffd

Please sign in to comment.