Bug #39519 mysql_stmt_close() should flush all data associated with the statement
Submitted: 18 Sep 2008 14:40 Modified: 12 Nov 2009 18:46
Reporter: Alexander Nozdrin Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: C API (client library) Severity:S3 (Non-critical)
Version:6.0-TRUNK OS:Any
Assigned to: Alexander Nozdrin
Triage: Triaged: D2 (Serious)

[18 Sep 2008 14:40] Alexander Nozdrin
Description:
mysql_stmt_close() should flush all pending result sets associated
with the prepared statement. Now it does not.

This bug came to the light after WL#4435 was pushed.

How to repeat:
Add and run the following test case in mysql_client_test.c:
static void test_wl4435_2()
{
 MYSQL_STMT *stmt;
 int  rc;
 char query[MAX_TEST_QUERY_LENGTH];

 myheader("test_wl4435_2");
 mct_start_logging("test_wl4435_2");

 rc= mysql_query(mysql, "DROP PROCEDURE IF EXISTS p1");
 myquery(rc);

 rc= mysql_query(mysql,
   "CREATE PROCEDURE p1()"
   "BEGIN "
   "  SELECT 1; "
   "  SELECT 2; "
   "  SELECT 3; "
   "END");
 myquery(rc);

 strmov(query, "CALL p1()");
 stmt= mysql_simple_prepare(mysql, query);
 check_stmt(stmt);

 /* Execute! */

 rc= mysql_stmt_execute(stmt);
 check_execute(stmt, rc);

 mysql_stmt_close(stmt);

 rc= mysql_commit(mysql);
 myquery(rc);
}

mysql_commit() will return the following error:
Commands out of sync; you can't run this command now
[5 Nov 2008 9:53] Alexander Nozdrin
See also Bug#40503.
[21 Dec 2008 18:14] Jim Winstead
The "my_bool more_results_exist" in client.c needs to be at the beginning of a block, not the middle, since it's a .c file.
[15 Jan 2009 22:16] Jim Winstead
Unless I'm missing something, you need to implement support for this new flag in emb_flush_use_result().

Otherwise the changes look good.

I'm re-adding Kostja as the second reviewer for this.
[20 Jan 2009 22:21] Alexander Nozdrin
If you mean calling THD::clear_data_list() when the flag is TRUE,
I don't think that is necessary:

  - mysql_stmt_close() firstly calls flush_use_result() with the flag set,
    then it calls stmt_command(COM_STMT_CLOSE, ...).

  - stmt_command() ends up in emb_advanced_command(),  which calls
    THD::clear_data_list().
[25 Feb 2009 10:03] 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/commits/67479

2732 Alexander Nozdrin	2009-02-25
      Bug#39519: mysql_stmt_close() should flush all data
      associated with the statement.
      modified:
        include/mysql.h
        include/mysql.h.pp
        libmysql/libmysql.c
        libmysqld/lib_sql.cc
        sql-common/client.c
        tests/mysql_client_test.c
[25 Feb 2009 10:05] Alexander Nozdrin
Patch pushed into 6.0-runtime.
[6 Mar 2009 19:19] Bugs System
Pushed into 6.0.11-alpha (revid:alik@sun.com-20090306190634-6s4zeti557q6stly) (version source revid:alik@sun.com-20090225100318-wuq1neir30bl127k) (merge vers: 6.0.10-alpha) (pib:6)
[6 Mar 2009 23:59] Paul Dubois
Noted in 6.0.11 changelog.

The mysql_stmt_close() C API function did not flush all pending data
associated with the prepared statement.
[21 Oct 2009 12:51] 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/commits/87637

2933 Konstantin Osipov	2009-10-21
      Backport of:
      ------------------------------------------------------------
      revno: 2617.23.14
      committer: Alexander Nozdrin <alik@sun.com>
      branch nick: 6.0-rt-bug39519
      timestamp: Wed 2009-02-25 13:03:18 +0300
      message:
        Bug#39519: mysql_stmt_close() should flush all data
        associated with the statement.
[3 Nov 2009 7:17] Bugs System
Pushed into 6.0.14-alpha (revid:alik@sun.com-20091102151658-j9o4wgro47m5v84d) (version source revid:alik@sun.com-20091023064702-2f8jdmny61bdl94u) (merge vers: 6.0.14-alpha) (pib:13)
[3 Nov 2009 15:12] Paul Dubois
Already fixed in earlier 6.0.x release.
[12 Nov 2009 8:22] Bugs System
Pushed into 5.5.0-beta (revid:alik@sun.com-20091110093229-0bh5hix780cyeicl) (version source revid:mikael@mysql.com-20091103113702-p61dlwc6ml6fxg18) (merge vers: 5.5.0-beta) (pib:13)
[12 Nov 2009 18:46] Paul Dubois
Noted in 5.5.0 changelog.