You've already forked mariadb-connector-c
mirror of
https://github.com/mariadb-corporation/mariadb-connector-c.git
synced 2025-08-08 14:02:17 +03:00
Fix for mariadb_stmt_execute_direct():
- If prepare failed, we need to ignore errormessage from mysql_stmt_execute() (which is always an error packet, mentioning invalid sttmt_id) - Added additional check in mysql_stmt_reset for stmt_id == -1.
This commit is contained in:
@@ -2228,7 +2228,10 @@ MYSQL_RES * STDCALL mysql_stmt_result_metadata(MYSQL_STMT *stmt)
|
||||
|
||||
my_bool STDCALL mysql_stmt_reset(MYSQL_STMT *stmt)
|
||||
{
|
||||
return mysql_stmt_internal_reset(stmt, 0);
|
||||
if (stmt->stmt_id > 0 &&
|
||||
stmt->stmt_id != (unsigned long) -1)
|
||||
return mysql_stmt_internal_reset(stmt, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char * STDCALL mysql_stmt_sqlstate(MYSQL_STMT *stmt)
|
||||
@@ -2381,6 +2384,7 @@ int STDCALL mariadb_stmt_execute_direct(MYSQL_STMT *stmt,
|
||||
{
|
||||
MYSQL *mysql;
|
||||
my_bool emulate_cmd;
|
||||
my_bool clear_result= 0;
|
||||
|
||||
if (!stmt)
|
||||
return 1;
|
||||
@@ -2448,6 +2452,10 @@ int STDCALL mariadb_stmt_execute_direct(MYSQL_STMT *stmt,
|
||||
if (mysql->methods->db_command(mysql, COM_STMT_PREPARE, stmt_str, length, 1, stmt))
|
||||
goto fail;
|
||||
|
||||
/* in case prepare fails, we need to clear the result package from execute, which
|
||||
is always an error packet (invalid statement id) */
|
||||
clear_result= 1;
|
||||
|
||||
stmt->state= MYSQL_STMT_PREPARED;
|
||||
/* Since we can't determine stmt_id here, we need to set it to -1, so server will know that the
|
||||
* execute command belongs to previous prepare */
|
||||
@@ -2464,6 +2472,8 @@ int STDCALL mariadb_stmt_execute_direct(MYSQL_STMT *stmt,
|
||||
mysql->methods->db_read_prepare_response(stmt))
|
||||
goto fail;
|
||||
|
||||
clear_result= 0;
|
||||
|
||||
/* metadata not supported yet */
|
||||
|
||||
if (stmt->param_count &&
|
||||
@@ -2498,9 +2508,11 @@ fail:
|
||||
/* check if we need to set error message */
|
||||
if (!mysql_stmt_errno(stmt))
|
||||
UPDATE_STMT_ERROR(stmt);
|
||||
do {
|
||||
stmt->mysql->methods->db_stmt_flush_unbuffered(stmt);
|
||||
} while(mysql_stmt_more_results(stmt));
|
||||
if (clear_result) {
|
||||
do {
|
||||
stmt->mysql->methods->db_stmt_flush_unbuffered(stmt);
|
||||
} while(mysql_stmt_more_results(stmt));
|
||||
}
|
||||
stmt->state= MYSQL_STMT_INITTED;
|
||||
return 1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user