@@ -3695,7 +3695,7 @@ AV *mariadb_db_data_sources(SV *dbh, imp_dbh_t *imp_dbh, SV *attr)
3695
3695
return av ;
3696
3696
}
3697
3697
3698
- static int mariadb_st_free_result_sets (SV * sth , imp_sth_t * imp_sth );
3698
+ static bool mariadb_st_free_result_sets (SV * sth , imp_sth_t * imp_sth );
3699
3699
3700
3700
/*
3701
3701
**************************************************************************
@@ -3827,7 +3827,8 @@ mariadb_st_prepare_sv(
3827
3827
Clean-up previous result set(s) for sth to prevent
3828
3828
'Commands out of sync' error
3829
3829
*/
3830
- mariadb_st_free_result_sets (sth , imp_sth );
3830
+ if (!mariadb_st_free_result_sets (sth , imp_sth ))
3831
+ return 0 ;
3831
3832
3832
3833
if (imp_sth -> use_server_side_prepare )
3833
3834
{
@@ -3971,18 +3972,20 @@ mariadb_st_prepare_sv(
3971
3972
* Inputs: sth - Statement handle
3972
3973
* imp_sth - driver's private statement handle
3973
3974
*
3974
- * Returns: 1 ok
3975
- * 0 error
3975
+ * Returns: TRUE ok
3976
+ * FALSE error; mariadb_dr_do_error will be called
3976
3977
*************************************************************************/
3977
- static int mariadb_st_free_result_sets (SV * sth , imp_sth_t * imp_sth )
3978
+ static bool mariadb_st_free_result_sets (SV * sth , imp_sth_t * imp_sth )
3978
3979
{
3979
3980
dTHX ;
3980
3981
D_imp_dbh_from_sth ;
3981
3982
D_imp_xxh (sth );
3982
3983
int next_result_rc = -1 ;
3984
+ unsigned int error ;
3983
3985
3986
+ /* No connection, nothing to clean, no error */
3984
3987
if (!imp_dbh -> pmysql )
3985
- return 0 ;
3988
+ return TRUE ;
3986
3989
3987
3990
if (DBIc_TRACE_LEVEL (imp_xxh ) >= 2 )
3988
3991
PerlIO_printf (DBIc_LOGPIO (imp_xxh ), "\t>- mariadb_st_free_result_sets\n" );
@@ -4005,7 +4008,7 @@ static int mariadb_st_free_result_sets (SV * sth, imp_sth_t * imp_sth)
4005
4008
4006
4009
mariadb_dr_do_error (sth , mysql_errno (imp_dbh -> pmysql ), mysql_error (imp_dbh -> pmysql ),
4007
4010
mysql_sqlstate (imp_dbh -> pmysql ));
4008
- return 0 ;
4011
+ return FALSE ;
4009
4012
}
4010
4013
}
4011
4014
}
@@ -4022,14 +4025,19 @@ static int mariadb_st_free_result_sets (SV * sth, imp_sth_t * imp_sth)
4022
4025
PerlIO_printf (DBIc_LOGPIO (imp_xxh ), "\t<- mariadb_st_free_result_sets: Error while processing multi-result set: %s\n" ,
4023
4026
mysql_error (imp_dbh -> pmysql ));
4024
4027
4025
- mariadb_dr_do_error (sth , mysql_errno (imp_dbh -> pmysql ), mysql_error (imp_dbh -> pmysql ),
4026
- mysql_sqlstate (imp_dbh -> pmysql ));
4028
+ /* This is error for previous unfetched result ret. So do not report server errors to caller which is expecting new result set. */
4029
+ error = mysql_errno (imp_dbh -> pmysql );
4030
+ 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 )
4031
+ {
4032
+ mariadb_dr_do_error (sth , mysql_errno (imp_dbh -> pmysql ), mysql_error (imp_dbh -> pmysql ), mysql_sqlstate (imp_dbh -> pmysql ));
4033
+ return FALSE;
4034
+ }
4027
4035
}
4028
4036
4029
4037
if (DBIc_TRACE_LEVEL (imp_xxh ) >= 2 )
4030
4038
PerlIO_printf (DBIc_LOGPIO (imp_xxh ), "\t<- mariadb_st_free_result_sets\n" );
4031
4039
4032
- return 1 ;
4040
+ return TRUE ;
4033
4041
}
4034
4042
4035
4043
@@ -4565,7 +4573,8 @@ IV mariadb_st_execute_iv(SV* sth, imp_sth_t* imp_sth)
4565
4573
Clean-up previous result set(s) for sth to prevent
4566
4574
'Commands out of sync' error
4567
4575
*/
4568
- mariadb_st_free_result_sets (sth , imp_sth );
4576
+ if (!mariadb_st_free_result_sets (sth , imp_sth ))
4577
+ return -2 ;
4569
4578
4570
4579
if (use_server_side_prepare )
4571
4580
{
@@ -5359,7 +5368,8 @@ int mariadb_st_finish(SV* sth, imp_sth_t* imp_sth) {
5359
5368
Clean-up previous result set(s) for sth to prevent
5360
5369
'Commands out of sync' error
5361
5370
*/
5362
- mariadb_st_free_result_sets (sth , imp_sth );
5371
+ if (!mariadb_st_free_result_sets (sth , imp_sth ))
5372
+ return 0 ;
5363
5373
}
5364
5374
DBIc_ACTIVE_off (imp_sth );
5365
5375
if (DBIc_TRACE_LEVEL (imp_xxh ) >= 2 )
0 commit comments