Skip to content

Commit

Permalink
Added Transaction Error Code - 08007 (#119)
Browse files Browse the repository at this point in the history
Added 08007 for Connection failure during transaction
  • Loading branch information
ColinKYuen authored and yanw-bq committed Apr 27, 2023
1 parent 1b14e97 commit 25bb2c8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
12 changes: 10 additions & 2 deletions driver/connect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1594,17 +1594,25 @@ SQLRETURN DBC::execute_query(const char* query,
MYLOG_DBC_TRACE(dbc, "Rolling back");
dbc->mysql->real_query("ROLLBACK", 8);
}
dbc->transaction_open = false;

const char* error_code;
if (dbc->fh->trigger_failover_if_needed("08S01", error_code))
{
result = set_error(MYERR_08S02, "The active SQL connection has changed.", 0, "");
if (strcmp(error_code, "08007") == 0)
{
result = set_error(MYERR_08007, "Connection failure during transaction.", 0, "");
}
else
{
result = set_error(MYERR_08S02, "The active SQL connection has changed.", 0, "");
}
}
else
{
result = set_error(MYERR_08S01, "The active SQL connection was lost.", 0, "");
}

dbc->transaction_open = false;
}
}

Expand Down
13 changes: 7 additions & 6 deletions driver/error.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ static MYODBC3_ERR_STR myodbc3_errors[]=
{"42S22","Column not found", SQL_ERROR},
{"08S01","Communication link failure", SQL_ERROR},
{"08004","Server rejected the connection", SQL_ERROR},
{"08S02","Communication link changed", SQL_ERROR}
{"08S02","Communication link changed", SQL_ERROR},
{"08007","Connection failure during transaction", SQL_ERROR}
};


Expand Down Expand Up @@ -419,11 +420,11 @@ MySQLGetDiagRec(SQLSMALLINT handle_type, SQLHANDLE handle, SQLSMALLINT record,
bool is_odbc3_subclass(std::string sqlstate)
{
char *states[]= { "01S00", "01S01", "01S02", "01S06", "01S07", "07S01",
"08S01", "08S02", "21S01", "21S02", "25S01", "25S02", "25S03", "42S01",
"42S02", "42S11", "42S12", "42S21", "42S22", "HY095", "HY097", "HY098",
"HY099", "HY100", "HY101", "HY105", "HY107", "HY109", "HY110", "HY111",
"HYT00", "HYT01", "IM001", "IM002", "IM003", "IM004", "IM005", "IM006",
"IM007", "IM008", "IM010", "IM011", "IM012"};
"08S01", "08S02", "08007", "21S01", "21S02", "25S01", "25S02", "25S03",
"42S01", "42S02", "42S11", "42S12", "42S21", "42S22", "HY095", "HY097",
"HY098", "HY099", "HY100", "HY101", "HY105", "HY107", "HY109", "HY110",
"HY111", "HYT00", "HYT01", "IM001", "IM002", "IM003", "IM004", "IM005",
"IM006", "IM007", "IM008", "IM010", "IM011", "IM012"};
size_t i;

if (sqlstate.empty())
Expand Down
1 change: 1 addition & 0 deletions driver/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ typedef enum myodbc_errid
/* Please add new errors to the end of enum, and not in alphabet order */
MYERR_08004,
MYERR_08S02,
MYERR_08007,
} myodbc_errid;

/*
Expand Down
4 changes: 4 additions & 0 deletions driver/failover_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ bool FAILOVER_HANDLER::trigger_failover_if_needed(const char* error_code, const
}

bool failover_success = false; // If failover happened & succeeded
bool in_transaction = !autocommit_on(dbc) || dbc->transaction_open;

if (ec.rfind("08", 0) == 0) { // start with "08"

Expand All @@ -459,6 +460,9 @@ bool FAILOVER_HANDLER::trigger_failover_if_needed(const char* error_code, const
}

metrics_container->register_failover_connects(failover_success);
if (in_transaction) {
new_error_code = "08007";
}
return failover_success;
}

Expand Down

0 comments on commit 25bb2c8

Please sign in to comment.