[CONC-266] mysql_stmt_execute hangs up 2nd time if mysql_stmt_bind_result is called and if mysql_stmt_fetch is not called Created: 2017-07-08  Updated: 2017-07-08  Resolved: 2017-07-08

Status: Closed
Project: MariaDB Connector/C
Component/s: None
Affects Version/s: 2.0.0, N/A
Fix Version/s: N/A

Type: Bug Priority: Trivial
Reporter: Shin Yoshida Assignee: Georg Richter
Resolution: Cannot Reproduce Votes: 0
Labels: None
Environment:

Client: Ubuntu 16.04 (Virtual Box on Windows 10)
Server: mariadb docker (docker pull mariadb, Image ID: 411c062636f4, docker on Ubuntu 16.04)

Connector Version
Both Ubuntu 16.04 libmariadb-client-lgpl-dev package (aka, 2.0.0), and self build (git hash is c596c1633253609a35be0f3aa8d9cdf916305475)



 Description   

Function mysql_stmt_execute can hang up under the following conditions.

1. Call mysql_stmt_bind_result in advance.
2. Call mysql_stmt_execute (It is OK)
3. Do NOT call mysql_stmt_fetch
4. Call mysql_stmt_execute again (hang up)

In case of the following sample code, function good_select can be called twice. On the other hand, bad_select works only once.

#include <cstring>
#include <iostream>
#include <mariadb/mysql.h>
#include <new>
 
using namespace std;
 
static const char create_table_sql[] =
    "CREATE TABLE IF NOT EXISTS test.ids (id INT AUTO_INCREMENT PRIMARY KEY)";
 
static const char select_sql[] = "SELECT * from test.ids";
 
void show_mysql_error(MYSQL *mysql) {
  cerr << "Error(" << mysql_errno(mysql) << ") [" << mysql_sqlstate(mysql)
       << "] " << mysql_error(mysql) << endl;
  exit(-1);
}
 
void show_mysql_error(MYSQL_STMT *stmt) {
  cerr << "Error(" << mysql_stmt_errno(stmt) << ") ["
       << mysql_stmt_sqlstate(stmt) << "] " << mysql_stmt_error(stmt) << endl;
  exit(-1);
}
 
void create_table(MYSQL *mysql) {
 
  if (mysql_query(mysql, create_table_sql))
    show_mysql_error(mysql);
}
 
void bad_select(MYSQL_STMT *stmt) {
 
  if (mysql_stmt_execute(stmt))
    show_mysql_error(stmt);
 
  if (mysql_stmt_store_result(stmt))
    show_mysql_error(stmt);
}
 
void good_select(MYSQL_STMT *stmt) {
 
  if (mysql_stmt_execute(stmt))
    show_mysql_error(stmt);
 
  if (mysql_stmt_store_result(stmt))
    show_mysql_error(stmt);
 
  if (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA)
    show_mysql_error(stmt);
}
 
int main() {
 
  MYSQL *mysql = mysql_init(nullptr);
  if (!mysql)
    throw bad_alloc();
 
  if (!mysql_real_connect(mysql, "127.0.0.1", "test_user", "", "test", 3306,
                          nullptr, CLIENT_REMEMBER_OPTIONS))
    show_mysql_error(mysql);
 
  create_table(mysql);
 
  MYSQL_STMT *stmt = mysql_stmt_init(mysql);
  if (!stmt)
    show_mysql_error(mysql);
 
  if (mysql_stmt_prepare(stmt, select_sql, strlen(select_sql)))
    show_mysql_error(stmt);
 
  MYSQL_BIND result;
  memset(&result, 0, sizeof(result));
 
  int id;
  result.buffer = &id;
  result.buffer_length = sizeof(id);
  result.buffer_type = MYSQL_TYPE_LONG;
 
  if (mysql_stmt_bind_result(stmt, &result))
    show_mysql_error(stmt);
 
  good_select(stmt);
  cout << "good_select done (1st time)" << endl;
 
  good_select(stmt);
  cout << "good_select done (2nd time)" << endl;
 
  bad_select(stmt);
  cout << "bad_select done (1st time)" << endl;
 
  bad_select(stmt);
  cout << "bad_select done (2nd time)" << endl;
 
  return 0;
}



 Comments   
Comment by Georg Richter [ 2017-07-08 ]

I wasn't able to reproduce this bug with Connector/C 2.3.3 and 3.0.2. Connector/C 2.0.0 is quite old, so please consider to upgrade to latest version.

Comment by Shin Yoshida [ 2017-07-08 ]

George

As you said, this problem does not occur at the newest version.
I checked it.

This is my mistake.
Thank you.

Generated at Thu Feb 08 03:04:05 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.