Force to read all unread packets on stmt_close
tests/client_test.c: tests for un cleared packets
This commit is contained in:
parent
28f3c41f49
commit
b58dd39b99
@ -5340,22 +5340,42 @@ int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt)
|
||||
*/
|
||||
static my_bool stmt_close(MYSQL_STMT *stmt, my_bool skip_list)
|
||||
{
|
||||
MYSQL *mysql;
|
||||
my_bool error= 0;
|
||||
DBUG_ENTER("mysql_stmt_close");
|
||||
|
||||
DBUG_ASSERT(stmt != 0);
|
||||
|
||||
mysql= stmt->mysql;
|
||||
if (mysql->status != MYSQL_STATUS_READY)
|
||||
{
|
||||
/* Clear the current execution status */
|
||||
DBUG_PRINT("warning",("Not all packets read, clearing them"));
|
||||
for (;;)
|
||||
{
|
||||
ulong pkt_len;
|
||||
if ((pkt_len= net_safe_read(mysql)) == packet_error)
|
||||
break;
|
||||
if (pkt_len <= 8 && mysql->net.read_pos[0] == 254)
|
||||
break;
|
||||
}
|
||||
mysql->status= MYSQL_STATUS_READY;
|
||||
}
|
||||
if (stmt->state == MY_ST_PREPARE || stmt->state == MY_ST_EXECUTE)
|
||||
{
|
||||
char buff[4];
|
||||
int4store(buff, stmt->stmt_id);
|
||||
error= simple_command(stmt->mysql, COM_CLOSE_STMT, buff, 4, 1);
|
||||
error= simple_command(mysql, COM_CLOSE_STMT, buff, 4, 1);
|
||||
}
|
||||
if (!error)
|
||||
{
|
||||
mysql_free_result(stmt->result);
|
||||
free_root(&stmt->mem_root, MYF(0));
|
||||
if (!skip_list)
|
||||
mysql->stmts= list_delete(mysql->stmts, &stmt->list);
|
||||
mysql->status= MYSQL_STATUS_READY;
|
||||
my_free((gptr) stmt, MYF(MY_WME));
|
||||
}
|
||||
mysql_free_result(stmt->result);
|
||||
free_root(&stmt->mem_root, MYF(0));
|
||||
if (!skip_list)
|
||||
stmt->mysql->stmts= list_delete(stmt->mysql->stmts, &stmt->list);
|
||||
stmt->mysql->status= MYSQL_STATUS_READY;
|
||||
my_free((gptr) stmt, MYF(MY_WME));
|
||||
DBUG_RETURN(error);
|
||||
}
|
||||
|
||||
|
@ -5332,6 +5332,44 @@ static void test_open_direct()
|
||||
|
||||
myassert(2 == my_process_result_set(result));
|
||||
mysql_stmt_close(stmt);
|
||||
|
||||
/* run a direct query in the middle of a fetch */
|
||||
stmt= mysql_prepare(mysql,"SELECT * FROM test_open_direct",100);
|
||||
mystmt_init(stmt);
|
||||
|
||||
rc = mysql_execute(stmt);
|
||||
mystmt(stmt, rc);
|
||||
|
||||
rc = mysql_fetch(stmt);
|
||||
mystmt(stmt, rc);
|
||||
|
||||
rc = mysql_query(mysql,"INSERT INTO test_open_direct(id) VALUES(20)");
|
||||
myquery_r(rc);
|
||||
|
||||
rc = mysql_stmt_close(stmt);
|
||||
mystmt(stmt, rc);
|
||||
|
||||
rc = mysql_query(mysql,"INSERT INTO test_open_direct(id) VALUES(20)");
|
||||
myquery(rc);
|
||||
|
||||
/* run a direct query with store result */
|
||||
stmt= mysql_prepare(mysql,"SELECT * FROM test_open_direct",100);
|
||||
mystmt_init(stmt);
|
||||
|
||||
rc = mysql_execute(stmt);
|
||||
mystmt(stmt, rc);
|
||||
|
||||
rc = mysql_stmt_store_result(stmt);
|
||||
mystmt(stmt, rc);
|
||||
|
||||
rc = mysql_fetch(stmt);
|
||||
mystmt(stmt, rc);
|
||||
|
||||
rc = mysql_query(mysql,"drop table test_open_direct");
|
||||
myquery(rc);
|
||||
|
||||
rc = mysql_stmt_close(stmt);
|
||||
mystmt(stmt, rc);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -5378,10 +5416,10 @@ static void test_fetch_nobuffs()
|
||||
while (mysql_fetch(stmt) != MYSQL_NO_DATA)
|
||||
{
|
||||
rc++;
|
||||
fprintf(stdout, "\n CURRENT_DATABASE(): %s(%ld)", str[0]);
|
||||
fprintf(stdout, "\n CURRENT_USER() : %s(%ld)", str[1]);
|
||||
fprintf(stdout, "\n CURRENT_DATE() : %s(%ld)", str[2]);
|
||||
fprintf(stdout, "\n CURRENT_TIME() : %s(%ld)", str[3]);
|
||||
fprintf(stdout, "\n CURRENT_DATABASE(): %s", str[0]);
|
||||
fprintf(stdout, "\n CURRENT_USER() : %s", str[1]);
|
||||
fprintf(stdout, "\n CURRENT_DATE() : %s", str[2]);
|
||||
fprintf(stdout, "\n CURRENT_TIME() : %s", str[3]);
|
||||
}
|
||||
fprintf(stdout, "\n total rows: %d", rc);
|
||||
myassert(rc == 1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user