Subject EXECUTE BLOCK statement and ISC_DSQL_EXECUTE2() problem.
Author kylixguru
It seems that Firebird 2.5 has an issue where repeated executions of an EXECUTE BLOCK statement are not possible via ISC_DSQL_EXECUTE2() due to the error:

"Attempt to reopen an open cursor"


Here is a trace in IB Objects (using a TIB_DSQL component) of what happened:


/*---
ALLOCATE STATEMENT
DB_HANDLE = 1
STMT_HANDLE = 188
----*/
/*---
PREPARE STATEMENT
TR_HANDLE = 186
STMT_HANDLE = 188

EXECUTE BLOCK
RETURNS (I INTEGER)
AS

BEGIN
SELECT FIRST 1 MON$ATTACHMENT_ID FROM MON$ATTACHMENTS
INTO :I;
EXIT;
END

PLAN (MON$ATTACHMENTS NATURAL)

FIELDS = [ Version 1 SQLd 1 SQLn 30
I = <NIL> ]

SECONDS = 0.016
----*/
/*---
STATEMENT INFO
STMT_HANDLE = 188
----*/
/*---
STATEMENT INFO
STMT_HANDLE = 188
----*/
/*---
EXECUTE2 ROW SINGLETON
TR_HANDLE = 186
STMT_HANDLE = 188
PARAMS = [ ]
FIELDS = [ Version 1 SQLd 1 SQLn 1
I = 53765 ]
----*/
/*---
EXECUTE2 ROW SINGLETON
TR_HANDLE = 186
STMT_HANDLE = 188
PARAMS = [ ]
FIELDS = [ Version 1 SQLd 1 SQLn 1
I = 53765 ]

ERRCODE = 335544569
----*/
/*---
INTERPRET BUFFER =

ERRCODE = 17
----*/
/*---
INTERPRET BUFFER = Dynamic SQL Error

ERRCODE = 21
----*/
/*---
INTERPRET BUFFER = SQL error code = -502

ERRCODE = 32
----*/
/*---
INTERPRET BUFFER = Attempt to reopen an open cursor

ERRCODE = -1
----*/
/*---
COMMIT
TR_HANDLE = 186
----*/

The call shown as EXECUTE2 ROW SINGLETON is the isc_dsql_execute2() API call.

Thanks to anyone who can do a low-level verification of this. It seems to me there shouldn't be an error here. It seems to me anything executed via ISC_DSQL_EXECUTE2() should not have an opened cursor.

Thanks,
Jason Wharton