Bug #9478 mysql_stmt_attr_set mysql_stmt_execute
Submitted: 30 Mar 2005 10:43 Modified: 4 Jun 2005 0:58
Reporter: Berto van de Kraats
Status: Closed
Category:Server Severity:S1 (Critical)
Version:5.0.4-beta-nightly-20050328 OS:Linux (linux)
Assigned to: Konstantin Osipov Target Version:

[30 Mar 2005 10:43] Berto van de Kraats
Description:
mysql crashes the second time a prepared statement is executed if cursor type
CURSOR_TYPE_READ_ONLY is used.

How to repeat:
compile/run attached c-program
[30 Mar 2005 10:43] Berto van de Kraats
bug4.c

Attachment: bug4.c (application/octet-stream, text), 3.99 KiB.

[30 Mar 2005 15:17] Miguel Solorzano
Thank you for the bug report.

 mysql_stmt_execute(), failed
stmt error=Lost connection to MySQL server during query
2013:Lost connection to MySQL server during query
[4 May 2005 15:58] Konstantin Osipov
I was able to repeat the bug.
[4 May 2005 16:03] Konstantin Osipov
According to our cursors design, you can't have more than one cursor open for a prepared
statement. If you need several cursors, you need to prepare several prepared statements.

The fix is going to return an error in reply to the attempt to execute a statement for
which one already has a cursor open.
[9 May 2005 11:29] Berto van de Kraats
how can one close a cursor so that the statement can be executed again without doing a new
prepare action ? (our goal is to execute the same query again with different  bind
values)

mysql_stmt_free_result(stmt) and/or mysql_stmt_reset(stmt) do not seem to achieve that.
And also according to your reply, also a new mysql_stmt_execute(stmt) does not seem to
close the old cursor.
[9 May 2005 12:13] Konstantin Osipov
Peter, thank you very much for your feedback. Your problem is exactly the reason (besides
the crash, of course), that the bug report is "In progress". 
I'm currently working on two issues:
- the server shouldn't crash, and on attempt to re-execute a statement with an open
cursor
  one should get an error message
- mysql_stmt_reset should close the pending cursor if there is one, and prepare the
statement
for reexecution.
So, the answer for your question is that there is a bug in mysql_stmt_reset which I'm
fixing.
I'm happy that the lack of abiliy to have more than one open cursor for a prepared
statement
did not cause you much trouble, it was an original design limitation we took in order to
simplify the API and the implementation.
[12 May 2005 9:17] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/internals/24804
[12 May 2005 10:48] Konstantin Osipov
To be compatible with non-cursors mode, mysql_stmt_execute now automatically closes
the cursor if there is one.
[12 May 2005 11:16] Konstantin Osipov
Pushed into 5.0 tree currently tagged 5.0.6
[4 Jun 2005 0:58] Paul DuBois
Noted in 5.0.6 changelog, and in the descriptions
of the various affected C API functions.