static void test_wl6797()
{
  MYSQL_STMT *stmt;
  int        rc;
  const char *stmt_text;
  my_ulonglong res;

  myheader("test_wl6797");

  if (mysql_get_server_version(mysql) < 50703)
  {
    if (!opt_silent)
      fprintf(stdout, "Skipping test_wl6797: "
             "tested feature does not exist in versions before MySQL 5.7.3\n");
    return;
  }
  /* clean up the session */
  rc= mysql_reset_connection(mysql);
  DIE_UNLESS(rc == 0);

  /* do prepare of a query */
  mysql_query(mysql, "use test");
  mysql_query(mysql, "DROP TABLE IF EXISTS t1");
  mysql_query(mysql, "CREATE TABLE t1 (a int)");

  stmt= mysql_stmt_init(mysql);
  stmt_text= "INSERT INTO t1 VALUES (1), (2)";

  rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
  check_execute(stmt, rc);

  /* Execute the insert statement */
  rc= mysql_stmt_execute(stmt);
  check_execute(stmt, rc);

  /*
   clean the session this should remove the prepare statement
   from the cache.
  */
  rc= mysql_reset_connection(mysql);
  DIE_UNLESS(rc == 0);

  /* this below stmt should report error */
  rc= mysql_stmt_execute(stmt);
  DIE_IF(rc == 0);

  /*
   bug#17653288: MYSQL_RESET_CONNECTION DOES NOT RESET LAST_INSERT_ID
  */

  rc= mysql_query(mysql, "CREATE TABLE t2 (a int NOT NULL PRIMARY KEY"\
                         " auto_increment)");
  myquery(rc);
  rc= mysql_query(mysql, "INSERT INTO t2 VALUES (null)");
  myquery(rc);
  res= mysql_insert_id(mysql);
  DIE_UNLESS(res == 1);
  rc= mysql_reset_connection(mysql);
  DIE_UNLESS(rc == 0);
  res= mysql_insert_id(mysql);
  DIE_UNLESS(res == 0);

  rc= mysql_query(mysql, "INSERT INTO t2 VALUES (last_insert_id(100))");
  myquery(rc);
  res= mysql_insert_id(mysql);
  DIE_UNLESS(res == 100);
  rc= mysql_reset_connection(mysql);
  DIE_UNLESS(rc == 0);
  res= mysql_insert_id(mysql);
  DIE_UNLESS(res == 0);

  mysql_query(mysql, "DROP TABLE IF EXISTS t1");
  mysql_query(mysql, "DROP TABLE IF EXISTS t2");
  mysql_stmt_close(stmt);
}
static void test_wl6797()
{
  MYSQL_STMT *stmt;
  int        rc;
  const char *stmt_text;
  my_ulonglong res;

  myheader("test_wl6797");

  if (mysql_get_server_version(mysql) < 50703)
  {
    if (!opt_silent)
      fprintf(stdout, "Skipping test_wl6797: "
             "tested feature does not exist in versions before MySQL 5.7.3\n");
    return;
  }
   
  rc= mysql_reset_connection(mysql);
  DIE_UNLESS(rc == 0);

   
  mysql_query(mysql, "use test");
  mysql_query(mysql, "DROP TABLE IF EXISTS t1");
  mysql_query(mysql, "CREATE TABLE t1 (a int)");

  stmt= mysql_stmt_init(mysql);
  stmt_text= "INSERT INTO t1 VALUES (1), (2)";

  rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
  check_execute(stmt, rc);

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

   
  rc= mysql_reset_connection(mysql);
  DIE_UNLESS(rc == 0);

   
  rc= mysql_stmt_execute(stmt);
  DIE_IF(rc == 0);

   

  rc= mysql_query(mysql, "CREATE TABLE t2 (a int NOT NULL PRIMARY KEY"\
                         " auto_increment)");
  myquery(rc);
  rc= mysql_query(mysql, "INSERT INTO t2 VALUES (null)");
  myquery(rc);
  res= mysql_insert_id(mysql);
  DIE_UNLESS(res == 1);
  rc= mysql_reset_connection(mysql);
  DIE_UNLESS(rc == 0);
  res= mysql_insert_id(mysql);
  DIE_UNLESS(res == 0);

  rc= mysql_query(mysql, "INSERT INTO t2 VALUES (last_insert_id(100))");
  myquery(rc);
  res= mysql_insert_id(mysql);
  DIE_UNLESS(res == 100);
  rc= mysql_reset_connection(mysql);
  DIE_UNLESS(rc == 0);
  res= mysql_insert_id(mysql);
  DIE_UNLESS(res == 0);

  mysql_query(mysql, "DROP TABLE IF EXISTS t1");
  mysql_query(mysql, "DROP TABLE IF EXISTS t2");
  mysql_stmt_close(stmt);
}