Skip to content

Commit

Permalink
Ensure that mariadb_dr_do_error() always set error with all details
Browse files Browse the repository at this point in the history
When DBIc_ERR is set to zero it indicates warning. So change zero error code to CR_UNKNOWN_ERROR.
Also ensure that DBIc_STATE is always set. Use "HY000" as fallback.
  • Loading branch information
pali committed Sep 27, 2023
1 parent 3d33da8 commit 8092bfc
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions dbdimp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1345,17 +1345,22 @@ void mariadb_dr_do_error(SV* h, unsigned int rc, const char *what, const char *s

if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)
PerlIO_printf(DBIc_LOGPIO(imp_xxh), "\t\t--> mariadb_dr_do_error\n");

if (!rc)
rc = CR_UNKNOWN_ERROR;
if (!what || !what[0])
what = "Unknown error";
if (!sqlstate || !sqlstate[0])
sqlstate = "HY000";

errstr= DBIc_ERRSTR(imp_xxh);
sv_setuv(DBIc_ERR(imp_xxh), rc); /* set err early */
SvUTF8_off(errstr);
sv_setpv(errstr, what);
sv_utf8_decode(errstr);

if (sqlstate)
{
errstate= DBIc_STATE(imp_xxh);
sv_setpv(errstate, sqlstate);
}

/* NO EFFECT DBIh_EVENT2(h, ERROR_event, DBIc_ERR(imp_xxh), errstr); */
if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)
Expand Down

0 comments on commit 8092bfc

Please sign in to comment.