Bug #89733 mysqlclient does not return correct warning_count after ping()
Submitted: 20 Feb 2018 15:20 Modified: 21 Feb 2018 5:44
Reporter: Daniël van Eeden (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: C API (client library) Severity:S3 (Non-critical)
Version:5.7.21, 8.0.3, 8.0.4 OS:Any
Assigned to: CPU Architecture:Any

[20 Feb 2018 15:20] Daniël van Eeden
Description:
This behaves differently with 5.6 and 5.7 client libraries:

mysql_real_query(mysql, "FOOBAR", strlen("FOOBAR"));
printf("Got %u warnings\n", mysql_warning_count(mysql));
mysql_ping(mysql);
printf("Got %u warnings\n", mysql_warning_count(mysql));

With 5.6: this returns zero warnings both times.
With 5.7: this returns zero warnings the first time and 1 the second time.

Closely related to:
Bug #89139 	mysqlclient does not return correct mysql_insert_id after ping()

How to repeat:
======================================================
#include <mysql.h>
#include <stdio.h>
#include <string.h>

int main()
{
  MYSQL *mysql, *conn;
  mysql = mysql_init(NULL);

  conn = mysql_real_connect(mysql, "127.0.0.1", "msandbox", "msandbox",
                            "test", 5720, NULL, 0);

  if (conn == NULL)
  {
    printf("Uhoh: %s\n", mysql_error(mysql));
  }

  printf("Client compile version: %d\n", MYSQL_VERSION_ID);
  printf("Client runtime version: %s\n", mysql_get_client_info());
  printf("Server version: %lu\n", mysql_get_server_version(mysql));

  printf("Query result: %d\n", mysql_real_query(mysql, "FOOBAR", strlen("FOOBAR")));
  printf("Got %u warnings\n", mysql_warning_count(mysql));

  printf("Sending ping\n");
  mysql_ping(mysql);

  printf("Got %u warnings\n", mysql_warning_count(mysql));

  mysql_close(mysql);
}
======================================================

Output against different version:
+ ./mysql_bug_warningcount_57
Client compile version: 50721
Client runtime version: 5.7.21
Server version: 50720
Query result: 1
Got 0 warnings
Sending ping
Got 1 warnings
+ LD_LIBRARY_PATH=/opt/mysql/5.7.20/lib
+ ./mysql_bug_warningcount_57_fixed
Client compile version: 50720
Client runtime version: 5.7.20
Server version: 50720
Query result: 1
Got 0 warnings
Sending ping
Got 0 warnings
+ LD_LIBRARY_PATH=/opt/mysql/5.6.38/lib
+ ./mysql_bug_warningcount_56
Client compile version: 50638
Client runtime version: 5.6.38
Server version: 50720
Query result: 1
Got 0 warnings
Sending ping
Got 0 warnings
+ LD_LIBRARY_PATH=/opt/mysql/8.0.3/lib
+ ./mysql_bug_warningcount_80
Client compile version: 80003
Client runtime version: 8.0.3-rc
Server version: 50720
Query result: 1
Got 0 warnings
Sending ping
Got 1 warnings

The 57_fixed one has the patch from Bug #89139 applied.

Suggested fix:
Apply the patch from the linked bug.
[21 Feb 2018 5:44] Umesh Shastry
Hello Daniël,

Thank you for the report and test case.

Thanks,
Umesh