From 25bb2c8535616e255639395003f570f8c8fecf1a Mon Sep 17 00:00:00 2001 From: Colin <70862826+ColinKYuen@users.noreply.github.com> Date: Thu, 31 Mar 2022 16:48:48 -0700 Subject: [PATCH] Added Transaction Error Code - 08007 (#119) Added 08007 for Connection failure during transaction --- driver/connect.cc | 12 ++++++++++-- driver/error.cc | 13 +++++++------ driver/error.h | 1 + driver/failover_handler.cc | 4 ++++ 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/driver/connect.cc b/driver/connect.cc index 5c2e2769f..497579109 100644 --- a/driver/connect.cc +++ b/driver/connect.cc @@ -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; } } diff --git a/driver/error.cc b/driver/error.cc index 3da44d673..258ec52e0 100644 --- a/driver/error.cc +++ b/driver/error.cc @@ -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} }; @@ -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()) diff --git a/driver/error.h b/driver/error.h index 163b01387..450f29558 100644 --- a/driver/error.h +++ b/driver/error.h @@ -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; /* diff --git a/driver/failover_handler.cc b/driver/failover_handler.cc index 08dd48790..aa4024ac6 100644 --- a/driver/failover_handler.cc +++ b/driver/failover_handler.cc @@ -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" @@ -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; }