Skip to content

Commit fb2631c

Browse files
committed
Cover a protocol design error for multi result statements
Error packet does not contain the server status, so client does not know if there is another multi result or not. Luckily, an error always aborts execution of a statement, so it is safe to expect that there is no result statement and turn off the SERVER_MORE_RESULTS_EXISTS flag. Applying this workaround for protocol error is needed after every failed call which may produce multi result set and we already received some multi result set. So after mysql_next_result() or after mysql_real_query() with multi statements.
1 parent b070c47 commit fb2631c

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

dbdimp.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2662,6 +2662,11 @@ IV mariadb_db_do6(SV *dbh, imp_dbh_t *imp_dbh, SV *statement_sv, SV *attribs, I3
26622662

26632663
if (next_result_rc > 0)
26642664
{
2665+
#if MYSQL_VERSION_ID < 50025
2666+
/* Cover a protocol design error: error packet does not contain the server status.
2667+
* Luckily, an error always aborts execution of a statement, so it is safe to turn off the flag. */
2668+
imp_dbh->pmysql->server_status &= ~SERVER_MORE_RESULTS_EXISTS;
2669+
#endif
26652670
/* This is error for previous unfetched result ret. So do not report server errors to caller which is expecting new result set. */
26662671
error = mysql_errno(imp_dbh->pmysql);
26672672
if (error == CR_COMMANDS_OUT_OF_SYNC || error == CR_OUT_OF_MEMORY || error == CR_SERVER_GONE_ERROR || error == CR_SERVER_LOST || error == CR_UNKNOWN_ERROR)
@@ -2841,6 +2846,12 @@ IV mariadb_db_do6(SV *dbh, imp_dbh_t *imp_dbh, SV *statement_sv, SV *attribs, I3
28412846

28422847
if (next_result_rc > 0)
28432848
{
2849+
#if MYSQL_VERSION_ID < 50025
2850+
/* Cover a protocol design error: error packet does not contain the server status.
2851+
* Luckily, an error always aborts execution of a statement, so it is safe to turn off the flag. */
2852+
imp_dbh->pmysql->server_status &= ~SERVER_MORE_RESULTS_EXISTS;
2853+
#endif
2854+
28442855
if (DBIc_DBISTATE(imp_dbh)->debug >= 2)
28452856
PerlIO_printf(DBIc_LOGPIO(imp_dbh), "\t<- do() ERROR: %s\n", mysql_error(imp_dbh->pmysql));
28462857

@@ -4021,6 +4032,12 @@ static bool mariadb_st_free_result_sets(SV *sth, imp_sth_t *imp_sth)
40214032

40224033
if (next_result_rc > 0)
40234034
{
4035+
#if MYSQL_VERSION_ID < 50025
4036+
/* Cover a protocol design error: error packet does not contain the server status.
4037+
* Luckily, an error always aborts execution of a statement, so it is safe to turn off the flag. */
4038+
imp_dbh->pmysql->server_status &= ~SERVER_MORE_RESULTS_EXISTS;
4039+
#endif
4040+
40244041
if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)
40254042
PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t<- mariadb_st_free_result_sets: Error while processing multi-result set: %s\n",
40264043
mysql_error(imp_dbh->pmysql));
@@ -4118,6 +4135,11 @@ bool mariadb_st_more_results(SV* sth, imp_sth_t* imp_sth)
41184135
*/
41194136
if (next_result_return_code > 0)
41204137
{
4138+
#if MYSQL_VERSION_ID < 50025
4139+
/* Cover a protocol design error: error packet does not contain the server status.
4140+
* Luckily, an error always aborts execution of a statement, so it is safe to turn off the flag. */
4141+
imp_dbh->pmysql->server_status &= ~SERVER_MORE_RESULTS_EXISTS;
4142+
#endif
41214143
mariadb_dr_do_error(sth, mysql_errno(imp_dbh->pmysql), mysql_error(imp_dbh->pmysql),
41224144
mysql_sqlstate(imp_dbh->pmysql));
41234145

@@ -4305,6 +4327,11 @@ static my_ulonglong mariadb_st_internal_execute(
43054327
(!mariadb_db_reconnect(h, NULL) ||
43064328
(mysql_real_query(*svsock, sbuf, slen))))
43074329
{
4330+
#if MYSQL_VERSION_ID < 50025
4331+
/* Cover a protocol design error: error packet does not contain the server status.
4332+
* Luckily, an error always aborts execution of a statement, so it is safe to turn off the flag. */
4333+
(*svsock)->server_status &= ~SERVER_MORE_RESULTS_EXISTS;
4334+
#endif
43084335
rows = -1;
43094336
} else {
43104337
/** Store the result from the Query */

0 commit comments

Comments
 (0)