Bug #32624 Error with multi queries in MySQL Embedded Server 5.1.22
Submitted: 22 Nov 2007 14:36 Modified: 11 Jan 2008 16:15
Reporter: Oleg Yaroshevych Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Embedded Library ( libmysqld ) Severity:S2 (Serious)
Version:5.0, 5.1.22-rc-community OS:Any (WinXP SP2, Linux, probably all)
Assigned to: Alexey Botchkov CPU Architecture:Any
Tags: embedded

[22 Nov 2007 14:36] Oleg Yaroshevych
Description:
I use embedded library from "mysql-noinstall-5.1.22-rc-win32.zip" and receive an access violation when executing multiple queries in MySQL Embedded Server 5.1.22.

The same code works fine with 4.1.18.

How to repeat:
Use following code to reproduce the problem (I use VS2005):

static char *server_options[] = { "mysql_test", "--defaults-file=my.ini", NULL };

int num_elements = (sizeof(server_options) / sizeof(char *)) - 1;

static char *server_groups[] = { "embedded", "server",  "this_program_SERVER",  (char *)NULL};

int main(void)
{
  mysql_library_init(num_elements, server_options, server_groups);
  MYSQL *mysql = mysql_init(NULL);
  mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, "libmysqld_client");
  mysql_options(mysql, MYSQL_OPT_USE_EMBEDDED_CONNECTION, NULL);
  int clientflag = CLIENT_FOUND_ROWS | CLIENT_MULTI_QUERIES | CLIENT_MULTI_STATEMENTS;
  mysql_real_connect(mysql, NULL,NULL,NULL, "mysql", 0,NULL,clientflag);

  cout << mysql_get_server_info(mysql) << endl;

  cout << mysql_next_result(mysql) << endl;
  mysql_query(mysql, "SELECT User FROM user;select * from no_such_table");
  mysql_free_result(mysql_store_result(mysql)); // "SELECT User FROM user" OK
  cout << mysql_next_result(mysql) << endl; // "select * from no_such_table" Error
  cout << mysql_next_result(mysql) << endl; // AV here

  mysql_close(mysql);
  mysql_library_end();
  return 0;
}
-----------------------------
%windir%\my.ini file:

[embedded]
basedir=d:/servers/embedded/
datadir=d:/servers/embedded/data/
max_allowed_packet=167772160
-----------------------------
Output for 5.1.22:

5.1.22-rc-community-debug-embedded
-1
1
Press any key to continue . . .
-----------------------------
Output for 4.1.18:

4.1.18-embedded-debug
-1
1
-1
Press any key to continue . . .
[23 Nov 2007 16:30] Hartmut Holzgraefe
Verified with a slightly modified test program on linux,
works fine non-embedded and with 4.1 embedded but crashes
on 5.0 and 5.1

Will attach test project in the bugs "Files" section,
to compile embedded just do

  ./configure --with-mysql=...
  make
  ./bug32624

To build non-embedded replace MYSQL_USE_EMBEDDED_API()
with MYSQL_USE_CLIENT_API() and run autgen.sh, then
re-build as shown above

4.1 output looks like this:

  4.1.22-embedded-debug
  -1
  1
  1
  Table 'mysql.no_such_table' doesn't exist

5.1.22 output looks like this:

  5.1.22-rc-embedded-debug
  -1
  1
  1
  Table 'mysql.no_such_table' doesn't exist
  Segmentation fault (core dumped)

The gdb backtrace for a build against 5.1.22 looks like this:

(gdb) bt
#0  0x080a6228 in emb_read_query_result (mysql=0x87eabe0) at lib_sql.cc:234
#1  0x080a0add in mysql_next_result (mysql=0x87eabe0) at libmysql.c:5199
#2  0x0804df49 in main () at bug32624.c:53
Current language:  auto; currently c++

(gdb) bt full
#0  0x080a6228 in emb_read_query_result (mysql=0x87eabe0) at lib_sql.cc:234
        thd = (class THD *) 0x8df0348
        res = (MYSQL_DATA *) 0x0
        __PRETTY_FUNCTION__ = "my_bool emb_read_query_result(MYSQL*)"
#1  0x080a0add in mysql_next_result (mysql=0x87eabe0) at libmysql.c:5199
        _db_func_ = 0x856c244 "?func"
        _db_file_ = 0x856c24a "?file"
        _db_level_ = 1
        _db_framep_ = (char **) 0x1
#2  0x0804df49 in main () at bug32624.c:53
        res = <value optimized out>
        mysql = (MYSQL *) 0x87eabe0
[23 Nov 2007 16:33] Hartmut Holzgraefe
test project

Attachment: bug32624-0.1.tar.gz (application/x-gunzip, text), 294.97 KiB.

[29 Nov 2007 6:43] 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/38786

ChangeSet@1.2581, 2007-11-29 10:37:07+04:00, holyfoot@mysql.com +3 -0
  Bug #32624 Error with multi queries in MySQL embedded server 5.1.22.
  
  server status wasn't properly sent to the client after the error
  by the embedded server. Wasn't noticed before as one usually stopped
  retrieving results after he gets an error.
[14 Dec 2007 8:14] Bugs System
Pushed into 5.0.54
[14 Dec 2007 8:16] Bugs System
Pushed into 5.1.23-rc
[14 Dec 2007 8:19] Bugs System
Pushed into 6.0.5-alpha
[11 Jan 2008 16:15] Paul DuBois
Noted in 5.0.54, 5.1.23, 6.0.5 changelogs.

Use of CLIENT_MULTI_QUERIES caused libmysqld to crash.