From 15606c04802bbc69a8b8350ec51d9a88dab2cf61 Mon Sep 17 00:00:00 2001 From: Yan Wang <68562925+yanw-bq@users.noreply.github.com> Date: Fri, 17 Mar 2023 18:44:31 -0700 Subject: [PATCH] Further refactor MYSQL_PROXY (#119) * create DUMMY_PROXY to handle mysql library calls, refactor MYSQL_PROXY to only forward proxy call * remove commented include * include thread header in dummy proxy * rename mysql_proxy to connection_proxy * rename dummy proxy to mysql proxy * remove secrets manager proxy as it should be a different PR * include in alphabetical order --- driver/CMakeLists.txt | 4 +- driver/ansi.cc | 2 +- driver/catalog.cc | 52 +-- driver/catalog_no_i_s.cc | 72 ++-- driver/cluster_aware_metrics_container.cc | 6 +- driver/connect.cc | 132 +++--- driver/connection_handler.cc | 14 +- driver/connection_handler.h | 7 +- driver/connection_proxy.cc | 395 ++++++++++++++++++ driver/connection_proxy.h | 172 ++++++++ driver/cursor.cc | 46 +- driver/driver.h | 14 +- driver/efm_proxy.cc | 220 +--------- driver/efm_proxy.h | 91 +--- driver/error.cc | 18 +- driver/error.h | 8 +- driver/execute.cc | 36 +- driver/failover.h | 17 +- driver/failover_handler.cc | 4 +- driver/failover_reader_handler.cc | 2 +- driver/failover_writer_handler.cc | 2 +- driver/handle.cc | 35 +- driver/info.cc | 36 +- driver/monitor.cc | 28 +- driver/monitor.h | 6 +- driver/monitor_connection_context.cc | 2 +- driver/my_prepared_stmt.cc | 48 +-- driver/my_stmt.cc | 68 +-- driver/mysql_proxy.cc | 60 +-- driver/mysql_proxy.h | 254 ++++++----- driver/myutil.h | 12 +- driver/options.cc | 34 +- driver/results.cc | 14 +- driver/topology_service.cc | 16 +- driver/topology_service.h | 11 +- driver/unicode.cc | 6 +- driver/utility.cc | 28 +- unit_testing/efm_proxy_test.cc | 32 +- unit_testing/failover_reader_handler_test.cc | 28 +- unit_testing/failover_writer_handler_test.cc | 60 +-- unit_testing/mock_objects.h | 20 +- .../monitor_connection_context_test.cc | 2 +- unit_testing/monitor_test.cc | 14 +- unit_testing/test_utils.h | 2 + unit_testing/topology_service_test.cc | 4 +- 45 files changed, 1204 insertions(+), 930 deletions(-) create mode 100644 driver/connection_proxy.cc create mode 100644 driver/connection_proxy.h diff --git a/driver/CMakeLists.txt b/driver/CMakeLists.txt index 83a26e3e3..a538269e2 100644 --- a/driver/CMakeLists.txt +++ b/driver/CMakeLists.txt @@ -60,7 +60,7 @@ WHILE(${DRIVER_INDEX} LESS ${DRIVERS_COUNT}) base_metrics_holder.cc catalog.cc catalog_no_i_s.cc cluster_topology_info.cc cluster_aware_hit_metrics_holder.cc cluster_aware_metrics_container.cc cluster_aware_metrics.cc cluster_aware_time_metrics_holder.cc - connect.cc connection_handler.cc cursor.cc desc.cc dll.cc driver.cc efm_proxy.cc + connect.cc connection_handler.cc connection_proxy.cc cursor.cc desc.cc dll.cc driver.cc efm_proxy.cc error.cc execute.cc failover_handler.cc failover_reader_handler.cc failover_writer_handler.cc handle.cc host_info.cc info.cc monitor.cc monitor_connection_context.cc monitor_service.cc monitor_thread_container.cc @@ -83,7 +83,7 @@ WHILE(${DRIVER_INDEX} LESS ${DRIVERS_COUNT}) CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/driver/driver.rc.cmake ${CMAKE_SOURCE_DIR}/driver/driver${CONNECTOR_DRIVER_TYPE_SHORT}.rc @ONLY) SET(DRIVER_SRCS ${DRIVER_SRCS} driver${CONNECTOR_DRIVER_TYPE_SHORT}.def driver${CONNECTOR_DRIVER_TYPE_SHORT}.rc base_metrics_holder.h catalog.h cluster_aware_hit_metrics_holder.h cluster_aware_metrics_container.h - cluster_aware_metrics.h cluster_aware_time_metrics_holder.h cluster_topology_info.h connection_handler.h + cluster_aware_metrics.h cluster_aware_time_metrics_holder.h cluster_topology_info.h connection_handler.h connection_proxy.h driver.h efm_proxy.h error.h failover.h host_info.h monitor.h monitor_connection_context.h monitor_service.h monitor_thread_container.h mylog.h mysql_proxy.h myutil.h parse.h query_parsing.h topology_service.h ../MYODBC_MYSQL.h ../MYODBC_CONF.h ../MYODBC_ODBC.h) diff --git a/driver/ansi.cc b/driver/ansi.cc index f9b9c7d0e..d43953a5c 100644 --- a/driver/ansi.cc +++ b/driver/ansi.cc @@ -212,7 +212,7 @@ SQLDescribeCol(SQLHSTMT hstmt, SQLUSMALLINT column, if (free_value == -1) { - set_mem_error(stmt->dbc->mysql_proxy); + set_mem_error(stmt->dbc->connection_proxy); return handle_connection_error(stmt); } diff --git a/driver/catalog.cc b/driver/catalog.cc index b3c381eb4..20cf565fd 100644 --- a/driver/catalog.cc +++ b/driver/catalog.cc @@ -160,7 +160,7 @@ create_fake_resultset(STMT *stmt, MYSQL_ROW rowval, size_t rowsize, else { if (stmt->result) - stmt->dbc->mysql_proxy->free_result(stmt->result); + stmt->dbc->connection_proxy->free_result(stmt->result); } /* Free if result data was not in row storage */ @@ -178,7 +178,7 @@ create_fake_resultset(STMT *stmt, MYSQL_ROW rowval, size_t rowsize, x_free(stmt->result); x_free(stmt->result_array); - set_mem_error(stmt->dbc->mysql_proxy); + set_mem_error(stmt->dbc->connection_proxy); return handle_connection_error(stmt); } stmt->fake_result= 1; @@ -257,7 +257,7 @@ MYSQL_RES *db_status(STMT *stmt, std::string &db) return NULL; } - return stmt->dbc->mysql_proxy->store_result(); + return stmt->dbc->connection_proxy->store_result(); } @@ -285,7 +285,7 @@ static MYSQL_RES *table_status_i_s(STMT *stmt, my_bool show_tables, my_bool show_views) { - MYSQL_PROXY *mysql_proxy= stmt->dbc->mysql_proxy; + CONNECTION_PROXY *connection_proxy= stmt->dbc->connection_proxy; /** the buffer size should count possible escapes */ my_bool clause_added= FALSE; std::string query; @@ -344,7 +344,7 @@ static MYSQL_RES *table_status_i_s(STMT *stmt, query.append("AND TABLE_NAME LIKE '"); if (wildcard) { - cnt = mysql_proxy->real_escape_string(tmpbuff, (char *)table_name, table_len); + cnt = connection_proxy->real_escape_string(tmpbuff, (char *)table_name, table_len); query.append(tmpbuff, cnt); } else @@ -365,7 +365,7 @@ static MYSQL_RES *table_status_i_s(STMT *stmt, return NULL; } - return mysql_proxy->store_result(); + return connection_proxy->store_result(); } @@ -391,7 +391,7 @@ static MYSQL_RES *table_status_i_s_old(STMT *stmt, my_bool show_tables, my_bool show_views) { - MYSQL_PROXY *mysql_proxy= stmt->dbc->mysql_proxy; + CONNECTION_PROXY *connection_proxy= stmt->dbc->connection_proxy; /** the buffer size should count possible escapes */ my_bool clause_added= FALSE; std::string query; @@ -449,7 +449,7 @@ static MYSQL_RES *table_status_i_s_old(STMT *stmt, query.append("WHERE TABLE_NAME LIKE '"); if (wildcard) { - cnt = mysql_proxy->real_escape_string(tmpbuff, (char *)table_name, table_len); + cnt = connection_proxy->real_escape_string(tmpbuff, (char *)table_name, table_len); query.append(tmpbuff, cnt); } else @@ -468,7 +468,7 @@ static MYSQL_RES *table_status_i_s_old(STMT *stmt, return NULL; } - return mysql_proxy->store_result(); + return connection_proxy->store_result(); } @@ -528,7 +528,7 @@ int add_name_condition_oa_id(HSTMT hstmt, std::string &query, SQLCHAR * name, query.append("'"); char tmpbuff[1024]; - size_t cnt = stmt->dbc->mysql_proxy->real_escape_string(tmpbuff, (char *)name, name_len); + size_t cnt = stmt->dbc->connection_proxy->real_escape_string(tmpbuff, (char *)name, name_len); query.append(tmpbuff, cnt); query.append("' "); } @@ -574,7 +574,7 @@ int add_name_condition_pv_id(HSTMT hstmt, std::string &query, SQLCHAR * name, query.append("'"); char tmpbuff[1024]; - size_t cnt = stmt->dbc->mysql_proxy->real_escape_string(tmpbuff, (char *)name, name_len); + size_t cnt = stmt->dbc->connection_proxy->real_escape_string(tmpbuff, (char *)name, name_len); query.append(tmpbuff, cnt); query.append("' "); } @@ -808,7 +808,7 @@ columns_i_s(SQLHSTMT hstmt, SQLCHAR *catalog, unsigned long catalog_len, if (no_ssps) { query.append("'"); - auto cnt = stmt->dbc->mysql_proxy->real_escape_string(temp.buf, (char*)data, len); + auto cnt = stmt->dbc->connection_proxy->real_escape_string(temp.buf, (char*)data, len); query.append(temp.buf, cnt); query.append("'"); } @@ -861,7 +861,7 @@ columns_i_s(SQLHSTMT hstmt, SQLCHAR *catalog, unsigned long catalog_len, do_bind(params, column, MYSQL_TYPE_STRING, column_len); } query.append(" ORDER BY ORDINAL_POSITION"); - ODBC_STMT local_stmt(stmt->dbc->mysql_proxy); + ODBC_STMT local_stmt(stmt->dbc->connection_proxy); if (!no_ssps) { @@ -904,7 +904,7 @@ columns_i_s(SQLHSTMT hstmt, SQLCHAR *catalog, unsigned long catalog_len, // Throwing the error for NO_SSPS case. throw stmt->dbc->error; } - mysql_res = stmt->dbc->mysql_proxy->store_result(); + mysql_res = stmt->dbc->connection_proxy->store_result(); } } catch (const MYERROR &e) @@ -920,8 +920,8 @@ columns_i_s(SQLHSTMT hstmt, SQLCHAR *catalog, unsigned long catalog_len, is_access = true; #endif - size_t rows = no_ssps ? stmt->dbc->mysql_proxy->num_rows(mysql_res) : - stmt->dbc->mysql_proxy->stmt_num_rows(local_stmt); + size_t rows = no_ssps ? stmt->dbc->connection_proxy->num_rows(mysql_res) : + stmt->dbc->connection_proxy->stmt_num_rows(local_stmt); stmt->m_row_storage.set_size(rows, SQLCOLUMNS_FIELDS); if (rows == 0) { @@ -948,19 +948,19 @@ columns_i_s(SQLHSTMT hstmt, SQLCHAR *catalog, unsigned long catalog_len, { if (no_ssps == false) { - if (stmt->dbc->mysql_proxy->stmt_fetch(local_stmt)) + if (stmt->dbc->connection_proxy->stmt_fetch(local_stmt)) return (MYSQL_ROW)nullptr; for (int i = 0; i < ccount; ++i) mysql_stmt_row[i] = (char*)ssps_res[i].buffer; return (MYSQL_ROW)mysql_stmt_row; } - return stmt->dbc->mysql_proxy->fetch_row(mysql_res); + return stmt->dbc->connection_proxy->fetch_row(mysql_res); }; while(mysql_row = _fetch_row()) { if (no_ssps) - result_lengths = stmt->dbc->mysql_proxy->fetch_lengths(mysql_res); + result_lengths = stmt->dbc->connection_proxy->fetch_lengths(mysql_res); CAT_SCHEMA_SET(data[0], data[1], db); /* TABLE_NAME */ @@ -1056,7 +1056,7 @@ columns_i_s(SQLHSTMT hstmt, SQLCHAR *catalog, unsigned long catalog_len, } if (mysql_res) - stmt->dbc->mysql_proxy->free_result(mysql_res); + stmt->dbc->connection_proxy->free_result(mysql_res); if (rows) { @@ -1459,7 +1459,7 @@ SQLRETURN foreign_keys_i_s(SQLHSTMT hstmt, SQLSMALLINT fk_table_len) { STMT *stmt=(STMT *) hstmt; - MYSQL_PROXY *mysql_proxy= stmt->dbc->mysql_proxy; + CONNECTION_PROXY *connection_proxy= stmt->dbc->connection_proxy; char tmpbuff[1024]; /* This should be big enough. */ char *update_rule, *delete_rule, *ref_constraints_join; SQLRETURN rc; @@ -1475,7 +1475,7 @@ SQLRETURN foreign_keys_i_s(SQLHSTMT hstmt, /* With 5.1, we can use REFERENTIAL_CONSTRAINTS to get even more info. */ - if (is_minimum_version(stmt->dbc->mysql_proxy->get_server_version(), "5.1")) + if (is_minimum_version(stmt->dbc->connection_proxy->get_server_version(), "5.1")) { update_rule= "CASE" " WHEN R.UPDATE_RULE = 'CASCADE' THEN 0" @@ -1544,7 +1544,7 @@ SQLRETURN foreign_keys_i_s(SQLHSTMT hstmt, if (!pk_db.empty()) { query.append("'"); - cnt = mysql_proxy->real_escape_string(tmpbuff, pk_db.c_str(), pk_db.length()); + cnt = connection_proxy->real_escape_string(tmpbuff, pk_db.c_str(), pk_db.length()); query.append(tmpbuff, cnt); query.append("' "); } @@ -1555,7 +1555,7 @@ SQLRETURN foreign_keys_i_s(SQLHSTMT hstmt, query.append("AND A.REFERENCED_TABLE_NAME = '"); - cnt =mysql_proxy->real_escape_string(tmpbuff, (char *)pk_table, pk_table_len); + cnt =connection_proxy->real_escape_string(tmpbuff, (char *)pk_table, pk_table_len); query.append(tmpbuff, cnt); query.append("' "); @@ -1569,7 +1569,7 @@ SQLRETURN foreign_keys_i_s(SQLHSTMT hstmt, if (!fk_db.empty()) { query.append("'"); - cnt = mysql_proxy->real_escape_string(tmpbuff, fk_db.c_str(), fk_db.length()); + cnt = connection_proxy->real_escape_string(tmpbuff, fk_db.c_str(), fk_db.length()); query.append(tmpbuff, cnt); query.append("' "); } @@ -1580,7 +1580,7 @@ SQLRETURN foreign_keys_i_s(SQLHSTMT hstmt, query.append("AND A.TABLE_NAME = '"); - cnt = mysql_proxy->real_escape_string(tmpbuff, (char *)fk_table, fk_table_len); + cnt = connection_proxy->real_escape_string(tmpbuff, (char *)fk_table, fk_table_len); query.append(tmpbuff, cnt); query.append("' "); diff --git a/driver/catalog_no_i_s.cc b/driver/catalog_no_i_s.cc index 0556aac2c..6a2fe92b5 100644 --- a/driver/catalog_no_i_s.cc +++ b/driver/catalog_no_i_s.cc @@ -145,7 +145,7 @@ static MYSQL_RES *server_list_dbkeys(STMT *stmt, SQLSMALLINT table_len) { DBC *dbc = stmt->dbc; - MYSQL_PROXY *mysql_proxy= dbc->mysql_proxy; + CONNECTION_PROXY *connection_proxy= dbc->connection_proxy; char tmpbuff[1024]; std::string query; query.reserve(1024); @@ -169,7 +169,7 @@ static MYSQL_RES *server_list_dbkeys(STMT *stmt, MYLOG_DBC_TRACE(dbc, query.c_str()); if (exec_stmt_query(stmt, query.c_str(), query.length(), FALSE)) return NULL; - return mysql_proxy->store_result(); + return connection_proxy->store_result(); } @@ -194,7 +194,7 @@ server_list_dbcolumns(STMT *stmt, { assert(stmt); DBC *dbc= stmt->dbc; - MYSQL_PROXY *mysql_proxy= dbc->mysql_proxy; + CONNECTION_PROXY *connection_proxy= dbc->connection_proxy; MYSQL_RES *result; char buff[NAME_LEN * 2 + 64], column_buff[NAME_LEN * 2 + 64]; @@ -211,7 +211,7 @@ server_list_dbcolumns(STMT *stmt, strncpy(buff, (const char*)szCatalog, cbCatalog); buff[cbCatalog]= '\0'; - if (mysql_proxy->select_db(buff)) + if (connection_proxy->select_db(buff)) { return NULL; } @@ -222,15 +222,15 @@ server_list_dbcolumns(STMT *stmt, strncpy(column_buff, (const char*)szColumn, cbColumn); column_buff[cbColumn]= '\0'; - result = mysql_proxy->list_fields(buff, column_buff); + result = connection_proxy->list_fields(buff, column_buff); /* If before this call no database were selected - we cannot revert that */ if (cbCatalog && !dbc->database.empty()) { - if (mysql_proxy->select_db(dbc->database.c_str())) + if (connection_proxy->select_db(dbc->database.c_str())) { /* Well, probably have to return error here */ - mysql_proxy->free_result(result); + connection_proxy->free_result(result); return NULL; } } @@ -281,7 +281,7 @@ static MYSQL_RES *table_privs_raw_data( STMT * stmt, SQLSMALLINT table_len) { DBC *dbc= stmt->dbc; - MYSQL_PROXY *mysql_proxy= dbc->mysql_proxy; + CONNECTION_PROXY *connection_proxy= dbc->connection_proxy; char tmpbuff[1024]; std::string query; size_t cnt = 0; @@ -290,7 +290,7 @@ static MYSQL_RES *table_privs_raw_data( STMT * stmt, query = "SELECT Db,User,Table_name,Grantor,Table_priv " "FROM mysql.tables_priv WHERE Table_name LIKE '"; - cnt = mysql_proxy->real_escape_string(tmpbuff, (char *)table, table_len); + cnt = connection_proxy->real_escape_string(tmpbuff, (char *)table, table_len); query.append(tmpbuff, cnt); query.append("' AND Db = "); @@ -298,7 +298,7 @@ static MYSQL_RES *table_privs_raw_data( STMT * stmt, if (catalog_len) { query.append("'"); - cnt = mysql_proxy->real_escape_string(tmpbuff, (char *)catalog, catalog_len); + cnt = connection_proxy->real_escape_string(tmpbuff, (char *)catalog, catalog_len); query.append(tmpbuff, cnt); query.append("'"); } @@ -311,7 +311,7 @@ static MYSQL_RES *table_privs_raw_data( STMT * stmt, if (exec_stmt_query(stmt, query.c_str(), query.length(), FALSE)) return NULL; - return mysql_proxy->store_result(); + return connection_proxy->store_result(); } @@ -355,7 +355,7 @@ static MYSQL_RES *column_privs_raw_data(STMT * stmt, SQLSMALLINT column_len) { DBC *dbc = stmt->dbc; - MYSQL_PROXY *mysql_proxy = dbc->mysql_proxy; + CONNECTION_PROXY *connection_proxy = dbc->connection_proxy; char tmpbuff[1024]; std::string query; @@ -368,14 +368,14 @@ static MYSQL_RES *column_privs_raw_data(STMT * stmt, "FROM mysql.columns_priv AS c, mysql.tables_priv AS t " "WHERE c.Table_name = '"; - cnt = mysql_proxy->real_escape_string(tmpbuff, (char *)table, table_len); + cnt = connection_proxy->real_escape_string(tmpbuff, (char *)table, table_len); query.append(tmpbuff, cnt); query.append("' AND c.Db = "); if (catalog_len) { query.append("'"); - cnt = mysql_proxy->real_escape_string(tmpbuff, (char *)catalog, catalog_len); + cnt = connection_proxy->real_escape_string(tmpbuff, (char *)catalog, catalog_len); query.append(tmpbuff, cnt); query.append("'"); } @@ -383,7 +383,7 @@ static MYSQL_RES *column_privs_raw_data(STMT * stmt, query.append("DATABASE()"); query.append("AND c.Column_name LIKE '"); - cnt = mysql_proxy->real_escape_string(tmpbuff, (char *)column, column_len); + cnt = connection_proxy->real_escape_string(tmpbuff, (char *)column, column_len); query.append(tmpbuff, cnt); query.append("' AND c.Table_name = t.Table_name " @@ -392,7 +392,7 @@ static MYSQL_RES *column_privs_raw_data(STMT * stmt, if (exec_stmt_query(stmt, query.c_str(), query.length(), FALSE)) return NULL; - return mysql_proxy->store_result(); + return connection_proxy->store_result(); } @@ -428,7 +428,7 @@ Lengths may not be SQL_NTS. @param[in] table_length Length of table name @return Result of SHOW CREATE TABLE , or NULL if there is an error -or empty result (check stmt->dbc->mysql_proxy->error_code() != 0) +or empty result (check stmt->dbc->connection_proxy->error_code() != 0) */ MYSQL_RES *server_show_create_table(STMT *stmt, SQLCHAR *catalog, @@ -464,7 +464,7 @@ MYSQL_RES *server_show_create_table(STMT *stmt, return NULL; } - return stmt->dbc->mysql_proxy->store_result(); + return stmt->dbc->connection_proxy->store_result(); } @@ -603,12 +603,12 @@ primary_keys_no_i_s(SQLHSTMT hstmt, if (!stmt->lengths) { - set_mem_error(stmt->dbc->mysql_proxy); + set_mem_error(stmt->dbc->connection_proxy); return handle_connection_error(stmt); } row_count= 0; - while ((row = stmt->dbc->mysql_proxy->fetch_row(stmt->result))) + while ((row = stmt->dbc->connection_proxy->fetch_row(stmt->result))) { if ( row[1][0] == '0' ) /* If unique index */ { @@ -698,23 +698,23 @@ static MYSQL_RES *server_list_proc_params(STMT *stmt, SQLSMALLINT par_name_len) { DBC *dbc = stmt->dbc; - MYSQL_PROXY *mysql_proxy= dbc->mysql_proxy; + CONNECTION_PROXY *connection_proxy= dbc->connection_proxy; char tmpbuf[1024]; std::string qbuff; qbuff.reserve(2048); - auto append_escaped_string = [&mysql_proxy, &tmpbuf](std::string &outstr, + auto append_escaped_string = [&connection_proxy, &tmpbuf](std::string &outstr, SQLCHAR* str, SQLSMALLINT len) { tmpbuf[0] = '\0'; outstr.append("'"); - mysql_proxy->real_escape_string(tmpbuf, (char *)str, len); + connection_proxy->real_escape_string(tmpbuf, (char *)str, len); outstr.append(tmpbuf).append("'"); }; - if((is_minimum_version(dbc->mysql_proxy->get_server_version(), "5.7"))) + if((is_minimum_version(dbc->connection_proxy->get_server_version(), "5.7"))) { qbuff = "select SPECIFIC_NAME, (IF(ISNULL(PARAMETER_NAME), " "concat('OUT RETURN_VALUE ', DTD_IDENTIFIER), " @@ -767,7 +767,7 @@ static MYSQL_RES *server_list_proc_params(STMT *stmt, if (exec_stmt_query(stmt, qbuff.c_str(), qbuff.length(), FALSE)) return NULL; - return mysql_proxy->store_result(); + return connection_proxy->store_result(); } @@ -817,7 +817,7 @@ procedure_columns_no_i_s(SQLHSTMT hstmt, SQLPROCEDURECOLUMNS_FIELDS); auto &data = stmt->m_row_storage; - while ((row = stmt->dbc->mysql_proxy->fetch_row(proc_list_res))) + while ((row = stmt->dbc->connection_proxy->fetch_row(proc_list_res))) { char *token; char *param_str; @@ -970,7 +970,7 @@ procedure_columns_no_i_s(SQLHSTMT hstmt, SQLPROCEDURECOLUMNS_fields, SQLPROCEDURECOLUMNS_FIELDS); free_internal_result_buffers(stmt); - stmt->dbc->mysql_proxy->free_result(proc_list_res); + stmt->dbc->connection_proxy->free_result(proc_list_res); case EXCEPTION_TYPE::GENERAL: break; } @@ -1056,8 +1056,8 @@ special_columns_no_i_s(SQLHSTMT hstmt, SQLUSMALLINT fColType, (SQLSMALLINT colType) { uint f_count = 0; - stmt->dbc->mysql_proxy->field_seek(result, 0); - while (field = stmt->dbc->mysql_proxy->fetch_field(result)) + stmt->dbc->connection_proxy->field_seek(result, 0); + while (field = stmt->dbc->connection_proxy->fetch_field(result)) { if(colType == SQL_ROWVER) { @@ -1140,7 +1140,7 @@ special_columns_no_i_s(SQLHSTMT hstmt, SQLUSMALLINT fColType, /* Check if there is a primary (unique) key */ primary_key= 0; - while ((field = stmt->dbc->mysql_proxy->fetch_field(result))) + while ((field = stmt->dbc->connection_proxy->fetch_field(result))) { if ( field->flags & PRI_KEY_FLAG ) { @@ -1225,7 +1225,7 @@ statistics_no_i_s(SQLHSTMT hstmt, sizeof(SQLSTAT_values),MYF(0)); if (!stmt->array) { - set_mem_error(stmt->dbc->mysql_proxy); + set_mem_error(stmt->dbc->connection_proxy); return handle_connection_error(stmt); } @@ -1250,7 +1250,7 @@ statistics_no_i_s(SQLHSTMT hstmt, } } (*prev)= 0; - stmt->dbc->mysql_proxy->data_seek(stmt->result,0); /* Restore pointer */ + stmt->dbc->connection_proxy->data_seek(stmt->result,0); /* Restore pointer */ } set_row_count(stmt, stmt->result->row_count); @@ -1412,10 +1412,10 @@ tables_no_i_s(SQLHSTMT hstmt, user_tables, views); } - if (!stmt->result && stmt->dbc->mysql_proxy->error_code()) + if (!stmt->result && stmt->dbc->connection_proxy->error_code()) { /* unknown DB will return empty set from SQLTables */ - switch (stmt->dbc->mysql_proxy->error_code()) + switch (stmt->dbc->connection_proxy->error_code()) { case ER_BAD_DB_ERROR: throw ODBCEXCEPTION(EXCEPTION_TYPE::EMPTY_SET); @@ -1438,7 +1438,7 @@ tables_no_i_s(SQLHSTMT hstmt, free_internal_result_buffers(stmt); if (stmt->result) { - stmt->dbc->mysql_proxy->free_result(stmt->result); + stmt->dbc->connection_proxy->free_result(stmt->result); stmt->result = nullptr; } @@ -1450,7 +1450,7 @@ tables_no_i_s(SQLHSTMT hstmt, stmt->m_row_storage.set_size(row_count, SQLTABLES_FIELDS); int name_index = 0; - while ((row = stmt->dbc->mysql_proxy->fetch_row(stmt->result))) + while ((row = stmt->dbc->connection_proxy->fetch_row(stmt->result))) { int type_index = 2; int comment_index = 1; diff --git a/driver/cluster_aware_metrics_container.cc b/driver/cluster_aware_metrics_container.cc index b8cff9b5f..ce51ff6c9 100644 --- a/driver/cluster_aware_metrics_container.cc +++ b/driver/cluster_aware_metrics_container.cc @@ -142,9 +142,9 @@ std::shared_ptr CLUSTER_AWARE_METRICS_CONTAINER::get_inst std::string CLUSTER_AWARE_METRICS_CONTAINER::get_curr_conn_url() { std::string curr_url = "[Unknown Url]"; - if (dbc && dbc->mysql_proxy) { - curr_url = dbc->mysql_proxy->get_host(); - curr_url.append(":").append(std::to_string(dbc->mysql_proxy->get_port())); + if (dbc && dbc->connection_proxy) { + curr_url = dbc->connection_proxy->get_host(); + curr_url.append(":").append(std::to_string(dbc->connection_proxy->get_port())); } return curr_url; } diff --git a/driver/connect.cc b/driver/connect.cc index 1ed5368f7..07dc7a7c9 100644 --- a/driver/connect.cc +++ b/driver/connect.cc @@ -102,7 +102,7 @@ void DBC::set_charset(std::string charset) std::string query = "SET NAMES " + charset; if (execute_query(query.c_str(), query.length(), true)) { - throw MYERROR("HY000", mysql_proxy); + throw MYERROR("HY000", connection_proxy); } } @@ -142,7 +142,7 @@ try { MY_CHARSET_INFO my_charset; - mysql_proxy->get_character_set_info(&my_charset); + connection_proxy->get_character_set_info(&my_charset); cxn_charset_info = get_charset(my_charset.number, MYF(0)); } @@ -360,7 +360,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) #endif - this->mysql_proxy->init(); + this->connection_proxy->init(); flags = get_client_flags(dsrc); @@ -368,17 +368,17 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) if (dsrc->allow_big_results || dsrc->safe) #if MYSQL_VERSION_ID >= 50709 - mysql_proxy->options(MYSQL_OPT_MAX_ALLOWED_PACKET, &max_long); + connection_proxy->options(MYSQL_OPT_MAX_ALLOWED_PACKET, &max_long); #else /* max_allowed_packet is a magical mysql macro. */ max_allowed_packet = ~0L; #endif if (dsrc->force_use_of_named_pipes) - mysql_proxy->options(MYSQL_OPT_NAMED_PIPE, NullS); + connection_proxy->options(MYSQL_OPT_NAMED_PIPE, NullS); if (dsrc->read_options_from_mycnf) - mysql_proxy->options(MYSQL_READ_DEFAULT_GROUP, "odbc"); + connection_proxy->options(MYSQL_READ_DEFAULT_GROUP, "odbc"); unsigned int connect_timeout, read_timeout, write_timeout; if (failover_enabled) @@ -394,9 +394,9 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) write_timeout = get_network_timeout(dsrc->write_timeout); } - mysql_proxy->options(MYSQL_OPT_CONNECT_TIMEOUT, &connect_timeout); - mysql_proxy->options(MYSQL_OPT_READ_TIMEOUT, &read_timeout); - mysql_proxy->options(MYSQL_OPT_WRITE_TIMEOUT, &write_timeout); + connection_proxy->options(MYSQL_OPT_CONNECT_TIMEOUT, &connect_timeout); + connection_proxy->options(MYSQL_OPT_READ_TIMEOUT, &read_timeout); + connection_proxy->options(MYSQL_OPT_WRITE_TIMEOUT, &write_timeout); /* Pluggable authentication was introduced in mysql 5.5.7 @@ -404,7 +404,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) #if MYSQL_VERSION_ID >= 50507 if (dsrc->plugin_dir) { - mysql_proxy->options(MYSQL_PLUGIN_DIR, + connection_proxy->options(MYSQL_PLUGIN_DIR, ds_get_utf8attr(dsrc->plugin_dir, &dsrc->plugin_dir8)); } @@ -415,13 +415,13 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) If plugin directory is not set we can use the dll location for a better chance of finding plugins. */ - mysql_proxy->options(MYSQL_PLUGIN_DIR, default_plugin_location.c_str()); + connection_proxy->options(MYSQL_PLUGIN_DIR, default_plugin_location.c_str()); } #endif if (dsrc->default_auth) { - mysql_proxy->options(MYSQL_DEFAULT_AUTH, + connection_proxy->options(MYSQL_DEFAULT_AUTH, ds_get_utf8attr(dsrc->default_auth, &dsrc->default_auth8)); } @@ -442,7 +442,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) if (fido_func || fido_callback_is_set) { struct st_mysql_client_plugin* plugin = - mysql_proxy->client_find_plugin( + connection_proxy->client_find_plugin( "authentication_fido_client", MYSQL_CLIENT_AUTHENTICATION_PLUGIN); @@ -470,7 +470,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) { /* load client authentication plugin if required */ struct st_mysql_client_plugin *plugin = - mysql_proxy->client_find_plugin("authentication_oci_client", + connection_proxy->client_find_plugin("authentication_oci_client", MYSQL_CLIENT_AUTHENTICATION_PLUGIN); if(!plugin) @@ -512,13 +512,13 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) { #ifdef WIN32 /* load client authentication plugin if required */ - struct st_mysql_client_plugin* plugin = mysql_proxy->client_find_plugin( + struct st_mysql_client_plugin* plugin = connection_proxy->client_find_plugin( "authentication_kerberos_client", MYSQL_CLIENT_AUTHENTICATION_PLUGIN); if (!plugin) { - return set_error("HY000", mysql_proxy->error(), 0); + return set_error("HY000", connection_proxy->error(), 0); } if (mysql_plugin_options(plugin, "plugin_authentication_kerberos_client_mode", @@ -543,7 +543,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) #endif /* set SSL parameters */ - mysql_proxy->ssl_set(ds_get_utf8attr(dsrc->sslkey, &dsrc->sslkey8), + connection_proxy->ssl_set(ds_get_utf8attr(dsrc->sslkey, &dsrc->sslkey8), ds_get_utf8attr(dsrc->sslcert, &dsrc->sslcert8), ds_get_utf8attr(dsrc->sslca, &dsrc->sslca8), ds_get_utf8attr(dsrc->sslcapath, &dsrc->sslcapath8), @@ -551,7 +551,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) #if MYSQL_VERSION_ID < 80003 if (dsrc->sslverify) - mysql_proxy->options(MYSQL_OPT_SSL_VERIFY_SERVER_CERT, + connection_proxy->options(MYSQL_OPT_SSL_VERIFY_SERVER_CERT, (const char *)&opt_ssl_verify_server_cert); #endif @@ -559,7 +559,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) if (dsrc->rsakey) { /* Read the public key on the client side */ - mysql_proxy->options(MYSQL_SERVER_PUBLIC_KEY, + connection_proxy->options(MYSQL_SERVER_PUBLIC_KEY, ds_get_utf8attr(dsrc->rsakey, &dsrc->rsakey8)); } #endif @@ -591,7 +591,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) } if (!tls_options.length() || - mysql_proxy->options(MYSQL_OPT_TLS_VERSION, tls_options.c_str())) + connection_proxy->options(MYSQL_OPT_TLS_VERSION, tls_options.c_str())) { return set_error("HY000", "SSL connection error: No valid TLS version available", 0); @@ -601,7 +601,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) if (dsrc->ssl_crl) { - if (mysql_proxy->options(MYSQL_OPT_SSL_CRL, + if (connection_proxy->options(MYSQL_OPT_SSL_CRL, ds_get_utf8attr(dsrc->ssl_crl, &dsrc->ssl_crl8))) { return set_error("HY000", "Failed to set the certificate revocation list file", 0); @@ -610,7 +610,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) if (dsrc->ssl_crlpath) { - if (mysql_proxy->options(MYSQL_OPT_SSL_CRLPATH, + if (connection_proxy->options(MYSQL_OPT_SSL_CRLPATH, ds_get_utf8attr(dsrc->ssl_crlpath, &dsrc->ssl_crlpath8))) { return set_error("HY000", "Failed to set the certificate revocation list path", 0); @@ -621,7 +621,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) if (dsrc->get_server_public_key) { /* Get the server public key */ - mysql_proxy->options(MYSQL_OPT_GET_SERVER_PUBLIC_KEY, (const void*)&on); + connection_proxy->options(MYSQL_OPT_GET_SERVER_PUBLIC_KEY, (const void*)&on); } #endif @@ -631,12 +631,12 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) Get the ANSI charset info before we change connection to UTF-8. */ MY_CHARSET_INFO my_charset; - mysql_proxy->get_character_set_info(&my_charset); + connection_proxy->get_character_set_info(&my_charset); ansi_charset_info= get_charset(my_charset.number, MYF(0)); /* We always use utf8 for the connection, and change it afterwards if needed. */ - mysql_proxy->options(MYSQL_SET_CHARSET_NAME, transport_charset); + connection_proxy->options(MYSQL_SET_CHARSET_NAME, transport_charset); cxn_charset_info= utf8_charset_info; } else @@ -650,12 +650,12 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) if (client_cs_name) { - mysql_proxy->options(MYSQL_SET_CHARSET_NAME, client_cs_name); + connection_proxy->options(MYSQL_SET_CHARSET_NAME, client_cs_name); ansi_charset_info= cxn_charset_info= get_charset_by_csname(client_cs_name, MYF(MY_CS_PRIMARY), MYF(0)); } #else MY_CHARSET_INFO my_charset; - mysql_proxy->get_character_set_info(&my_charset); + connection_proxy->get_character_set_info(&my_charset); ansi_charset_info= get_charset(my_charset.number, MYF(0)); #endif } @@ -663,30 +663,30 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) #if MYSQL_VERSION_ID >= 50610 if (dsrc->can_handle_exp_pwd) { - mysql_proxy->options(MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS, (char *)&on); + connection_proxy->options(MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS, (char *)&on); } #endif #if (MYSQL_VERSION_ID >= 50527 && MYSQL_VERSION_ID < 50600) || MYSQL_VERSION_ID >= 50607 if (dsrc->enable_cleartext_plugin) { - mysql_proxy->options(MYSQL_ENABLE_CLEARTEXT_PLUGIN, (char *)&on); + connection_proxy->options(MYSQL_ENABLE_CLEARTEXT_PLUGIN, (char *)&on); } #endif if (dsrc->enable_local_infile) { - mysql_proxy->options(MYSQL_OPT_LOCAL_INFILE, &on_int); + connection_proxy->options(MYSQL_OPT_LOCAL_INFILE, &on_int); } else { - mysql_proxy->options(MYSQL_OPT_LOCAL_INFILE, &off_int); + connection_proxy->options(MYSQL_OPT_LOCAL_INFILE, &off_int); } if (dsrc->load_data_local_dir && dsrc->load_data_local_dir[0]) { ds_get_utf8attr(dsrc->load_data_local_dir, &dsrc->load_data_local_dir8); - mysql_proxy->options(MYSQL_OPT_LOAD_DATA_LOCAL_DIR, + connection_proxy->options(MYSQL_OPT_LOAD_DATA_LOCAL_DIR, dsrc->load_data_local_dir8); } @@ -700,7 +700,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) for (auto &val : attr_list) { - mysql_proxy->options4(MYSQL_OPT_CONNECT_ATTR_ADD, + connection_proxy->options4(MYSQL_OPT_CONNECT_ATTR_ADD, val[0].c_str(), val[1].c_str()); } @@ -709,7 +709,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) { ds_get_utf8attr(dsrc->pwd1, &dsrc->pwd18); int fator = 1; - mysql_proxy->options4(MYSQL_OPT_USER_PASSWORD, + connection_proxy->options4(MYSQL_OPT_USER_PASSWORD, &fator, dsrc->pwd18); } @@ -718,7 +718,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) { ds_get_utf8attr(dsrc->pwd2, &dsrc->pwd28); int fator = 2; - mysql_proxy->options4(MYSQL_OPT_USER_PASSWORD, + connection_proxy->options4(MYSQL_OPT_USER_PASSWORD, &fator, dsrc->pwd28); } @@ -727,7 +727,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) { ds_get_utf8attr(dsrc->pwd3, &dsrc->pwd38); int fator = 3; - mysql_proxy->options4(MYSQL_OPT_USER_PASSWORD, + connection_proxy->options4(MYSQL_OPT_USER_PASSWORD, &fator, dsrc->pwd38); } @@ -750,7 +750,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) // Don't do anything if there is no match with any of the available modes if (mode) - mysql_proxy->options(MYSQL_OPT_SSL_MODE, &mode); + connection_proxy->options(MYSQL_OPT_SSL_MODE, &mode); } #endif @@ -819,7 +819,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) { protocol = MYSQL_PROTOCOL_TCP; } - mysql_proxy->options(MYSQL_OPT_PROTOCOL, &protocol); + connection_proxy->options(MYSQL_OPT_PROTOCOL, &protocol); //Setting server and port to the dsrc->server8 and dsrc->port ds_set_strnattr(&dsrc->server8, (SQLCHAR*)host, strlen(host)); @@ -830,13 +830,13 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) //Aws::ShutdownAPI(options); const bool connect_result = dsrc->enable_dns_srv ? - mysql_proxy->real_connect_dns_srv(host, + connection_proxy->real_connect_dns_srv(host, ds_get_utf8attr(dsrc->uid, &dsrc->uid8), ds_get_utf8attr(dsrc->pwd, &dsrc->pwd8), ds_get_utf8attr(dsrc->database, &dsrc->database8), flags) : - mysql_proxy->real_connect(host, + connection_proxy->real_connect(host, ds_get_utf8attr(dsrc->uid, &dsrc->uid8), ds_get_utf8attr(dsrc->pwd, &dsrc->pwd8), ds_get_utf8attr(dsrc->database, &dsrc->database8), @@ -845,7 +845,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) flags); if (!connect_result) { - unsigned int native_error= mysql_proxy->error_code(); + unsigned int native_error= connection_proxy->error_code(); /* Before 5.6.11 error returned by server was ER_MUST_CHANGE_PASSWORD(1820). In 5.6.11 it changed to ER_MUST_CHANGE_PASSWORD_LOGIN(1862) @@ -869,7 +869,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) "this functionlaity", 0); } #endif - set_error("HY000", mysql_proxy->error(), native_error); + set_error("HY000", connection_proxy->error(), native_error); translate_error((char*)error.sqlstate.c_str(), MYERR_S1000, native_error); @@ -903,7 +903,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) } else { - switch (mysql_proxy->error_code()) + switch (connection_proxy->error_code()) { case ER_CON_COUNT_ERROR: case CR_SOCKET_CREATE_ERROR: @@ -915,7 +915,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) break; default: //If SQLSTATE not 08xxx, which is used for network errors - if(strncmp(mysql_proxy->sqlstate(), "08", 2) != 0) + if(strncmp(connection_proxy->sqlstate(), "08", 2) != 0) { //Return error and do not try another host return SQL_ERROR; @@ -942,9 +942,9 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) } } - has_query_attrs = mysql_proxy->get_server_capabilities() & CLIENT_QUERY_ATTRIBUTES; + has_query_attrs = connection_proxy->get_server_capabilities() & CLIENT_QUERY_ATTRIBUTES; - if (!is_minimum_version(mysql_proxy->get_server_version(), "4.1.1")) + if (!is_minimum_version(connection_proxy->get_server_version(), "4.1.1")) { close(); return set_error("08001", "Driver does not support server versions under 4.1.1", 0); @@ -999,12 +999,12 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) /* Set the statement error prefix based on the server version. */ strxmov(st_error_prefix, MYODBC_ERROR_PREFIX, "[mysqld-", - mysql_proxy->get_server_version(), "]", NullS); + connection_proxy->get_server_version(), "]", NullS); /* This needs to be set after connection, or it doesn't stick. */ if (ds->auto_reconnect) { - mysql_proxy->options(MYSQL_OPT_RECONNECT, (char *)&on); + connection_proxy->options(MYSQL_OPT_RECONNECT, (char *)&on); } /* Make sure autocommit is set as configured. */ @@ -1018,7 +1018,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) "SQL_AUTOCOMMIT_OFF changed to SQL_AUTOCOMMIT_ON", SQL_SUCCESS_WITH_INFO); } - else if (autocommit_is_on() && mysql_proxy->autocommit(FALSE)) + else if (autocommit_is_on() && connection_proxy->autocommit(FALSE)) { /** @todo set error */ goto error; @@ -1027,7 +1027,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) else if ((commit_flag == CHECK_AUTOCOMMIT_ON) && transactions_supported() && !autocommit_is_on()) { - if (mysql_proxy->autocommit(TRUE)) + if (connection_proxy->autocommit(TRUE)) { /** @todo set error */ goto error; @@ -1066,7 +1066,7 @@ SQLRETURN DBC::connect(DataSource *dsrc, bool failover_enabled) } } - mysql_proxy->get_option(MYSQL_OPT_NET_BUFFER_LENGTH, &net_buffer_len); + connection_proxy->get_option(MYSQL_OPT_NET_BUFFER_LENGTH, &net_buffer_len); guard.set_success(rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO); return rc; @@ -1107,7 +1107,7 @@ SQLRETURN SQL_API MySQLConnect(SQLHDBC hdbc, #else /* Can't connect if we're already connected. */ - if (dbc->mysql_proxy != nullptr && dbc->mysql_proxy->is_connected()) + if (dbc->connection_proxy != nullptr && dbc->connection_proxy->is_connected()) return ((DBC*)hdbc)->set_error(MYERR_08002, NULL, 0); /* Reset error state */ @@ -1542,9 +1542,9 @@ SQLRETURN SQL_API SQLDisconnect(SQLHDBC hdbc) cluster_id_str = dbc->fh->cluster_id; } - if (((cluster_id_str == DEFAULT_CLUSTER_ID) || ds->gather_metrics_per_instance) && dbc->mysql_proxy) { - cluster_id_str = dbc->mysql_proxy->get_host(); - cluster_id_str.append(":").append(std::to_string(dbc->mysql_proxy->get_port())); + if (((cluster_id_str == DEFAULT_CLUSTER_ID) || ds->gather_metrics_per_instance) && dbc->connection_proxy) { + cluster_id_str = dbc->connection_proxy->get_host(); + cluster_id_str.append(":").append(std::to_string(dbc->connection_proxy->get_port())); } CLUSTER_AWARE_METRICS_CONTAINER::report_metrics( @@ -1580,10 +1580,10 @@ void DBC::execute_prep_stmt(MYSQL_STMT *pstmt, std::string &query, MYSQL_BIND *param_bind, MYSQL_BIND *result_bind) { if ( - mysql_proxy->stmt_prepare(pstmt, query.c_str(), query.length()) || - (param_bind && mysql_proxy->stmt_bind_param(pstmt, param_bind)) || - mysql_proxy->stmt_execute(pstmt) || - (result_bind && mysql_proxy->stmt_bind_result(pstmt, result_bind)) + connection_proxy->stmt_prepare(pstmt, query.c_str(), query.length()) || + (param_bind && connection_proxy->stmt_bind_param(pstmt, param_bind)) || + connection_proxy->stmt_execute(pstmt) || + (result_bind && connection_proxy->stmt_bind_result(pstmt, result_bind)) ) { set_error("HY000"); @@ -1592,7 +1592,7 @@ void DBC::execute_prep_stmt(MYSQL_STMT *pstmt, std::string &query, if ( - (result_bind && mysql_proxy->stmt_store_result(pstmt)) + (result_bind && connection_proxy->stmt_store_result(pstmt)) ) { set_error("HY000"); @@ -1618,23 +1618,23 @@ SQLRETURN DBC::execute_query(const char* query, } // return immediately if not connected - if (!this->mysql_proxy->is_connected()) + if (!this->connection_proxy->is_connected()) { return set_error(MYERR_08S01, "The active SQL connection was lost. Please discard this connection.", 0); } bool server_alive = is_server_alive(this); - if (!server_alive || this->mysql_proxy->real_query(query, query_length)) { - const unsigned int mysql_error_code = this->mysql_proxy->error_code(); + if (!server_alive || this->connection_proxy->real_query(query, query_length)) { + const unsigned int mysql_error_code = this->connection_proxy->error_code(); - MYLOG_DBC_TRACE(this, this->mysql_proxy->error()); - result = set_error(MYERR_S1000, this->mysql_proxy->error(), mysql_error_code); + MYLOG_DBC_TRACE(this, this->connection_proxy->error()); + result = set_error(MYERR_S1000, this->connection_proxy->error(), mysql_error_code); if (!server_alive || is_connection_lost(mysql_error_code)) { bool rollback = (!autocommit_on(this) && trans_supported(this)) || this->transaction_open; if (rollback) { MYLOG_DBC_TRACE(this, "Rolling back"); - this->mysql_proxy->real_query("ROLLBACK", 8); + this->connection_proxy->real_query("ROLLBACK", 8); } const char *error_code, *error_msg; diff --git a/driver/connection_handler.cc b/driver/connection_handler.cc index 863b39055..d934b9f0c 100644 --- a/driver/connection_handler.cc +++ b/driver/connection_handler.cc @@ -33,8 +33,8 @@ */ #include "connection_handler.h" +#include "connection_proxy.h" #include "driver.h" -#include "mysql_proxy.h" #include #include @@ -60,7 +60,7 @@ SQLRETURN CONNECTION_HANDLER::do_connect(DBC* dbc_ptr, DataSource* ds, bool fail return dbc_ptr->connect(ds, failover_enabled); } -MYSQL_PROXY* CONNECTION_HANDLER::connect(const std::shared_ptr& host_info, DataSource* ds) { +CONNECTION_PROXY* CONNECTION_HANDLER::connect(const std::shared_ptr& host_info, DataSource* ds) { if (dbc == nullptr || host_info == nullptr) { return nullptr; @@ -74,13 +74,13 @@ MYSQL_PROXY* CONNECTION_HANDLER::connect(const std::shared_ptr& host_ DBC* dbc_clone = clone_dbc(dbc, ds_to_use); ds_set_wstrnattr(&ds_to_use->server, (SQLWCHAR*)new_host.c_str(), new_host.size()); - MYSQL_PROXY* new_connection = nullptr; + CONNECTION_PROXY* new_connection = nullptr; CLEAR_DBC_ERROR(dbc_clone); const SQLRETURN rc = do_connect(dbc_clone, ds_to_use, ds_to_use->enable_cluster_failover); if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - new_connection = dbc_clone->mysql_proxy; - dbc_clone->mysql_proxy = nullptr; + new_connection = dbc_clone->connection_proxy; + dbc_clone->connection_proxy = nullptr; // postpone the deletion of ds_to_use/dbc_clone->ds until we are done with new_connection dbc_clone->ds = nullptr; } @@ -91,11 +91,11 @@ MYSQL_PROXY* CONNECTION_HANDLER::connect(const std::shared_ptr& host_ } void CONNECTION_HANDLER::update_connection( - MYSQL_PROXY* new_connection, const std::string& new_host_name) { + CONNECTION_PROXY* new_connection, const std::string& new_host_name) { if (new_connection->is_connected()) { dbc->close(); - dbc->mysql_proxy->set_connection(new_connection); + dbc->connection_proxy->set_connection(new_connection); CLEAR_DBC_ERROR(dbc); diff --git a/driver/connection_handler.h b/driver/connection_handler.h index 1cab2745a..d5423527a 100644 --- a/driver/connection_handler.h +++ b/driver/connection_handler.h @@ -31,7 +31,6 @@ #define __CONNECTION_HANDLER_H__ #include "host_info.h" - #include #ifdef __linux__ @@ -44,7 +43,7 @@ sqlwchar_string to_sqlwchar_string(const std::string& src); struct DBC; struct DataSource; -class MYSQL_PROXY; +class CONNECTION_PROXY; typedef short SQLRETURN; class CONNECTION_HANDLER { @@ -53,8 +52,8 @@ class CONNECTION_HANDLER { virtual ~CONNECTION_HANDLER(); virtual SQLRETURN do_connect(DBC* dbc_ptr, DataSource* ds, bool failover_enabled); - virtual MYSQL_PROXY* connect(const std::shared_ptr& host_info, DataSource* ds); - void update_connection(MYSQL_PROXY* new_connection, const std::string& new_host_name); + virtual CONNECTION_PROXY* connect(const std::shared_ptr& host_info, DataSource* ds); + void update_connection(CONNECTION_PROXY* new_connection, const std::string& new_host_name); private: DBC* dbc; diff --git a/driver/connection_proxy.cc b/driver/connection_proxy.cc new file mode 100644 index 000000000..7073ac3aa --- /dev/null +++ b/driver/connection_proxy.cc @@ -0,0 +1,395 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License, version 2.0 +// (GPLv2), as published by the Free Software Foundation, with the +// following additional permissions: +// +// This program is distributed with certain software that is licensed +// under separate terms, as designated in a particular file or component +// or in the license documentation. Without limiting your rights under +// the GPLv2, the authors of this program hereby grant you an additional +// permission to link the program and your derivative works with the +// separately licensed software that they have included with the program. +// +// Without limiting the foregoing grant of rights under the GPLv2 and +// additional permission as to separately licensed software, this +// program is also subject to the Universal FOSS Exception, version 1.0, +// a copy of which can be found along with its FAQ at +// http://oss.oracle.com/licenses/universal-foss-exception. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License, version 2.0, for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see +// http://www.gnu.org/licenses/gpl-2.0.html. + +#include "driver.h" + +CONNECTION_PROXY::CONNECTION_PROXY(DBC* dbc, DataSource* ds) : dbc{dbc}, ds{ds} { + if (!this->dbc) { + throw std::runtime_error("DBC cannot be null."); + } + + if (!this->ds) { + throw std::runtime_error("DataSource cannot be null."); + } +} + +CONNECTION_PROXY::~CONNECTION_PROXY() { + if (this->next_proxy) { + delete next_proxy; + } +} + +void CONNECTION_PROXY::delete_ds() { + next_proxy->delete_ds(); +} + +uint64_t CONNECTION_PROXY::num_rows(MYSQL_RES* res) { + return next_proxy->num_rows(res); +} + +unsigned int CONNECTION_PROXY::num_fields(MYSQL_RES* res) { + return next_proxy->num_fields(res); +} + +MYSQL_FIELD* CONNECTION_PROXY::fetch_field_direct(MYSQL_RES* res, unsigned int fieldnr) { + return next_proxy->fetch_field_direct(res, fieldnr); +} + +MYSQL_ROW_OFFSET CONNECTION_PROXY::row_tell(MYSQL_RES* res) { + return next_proxy->row_tell(res); +} + +unsigned int CONNECTION_PROXY::field_count() { + return next_proxy->field_count(); +} + +uint64_t CONNECTION_PROXY::affected_rows() { + return next_proxy->affected_rows(); +} + +unsigned int CONNECTION_PROXY::error_code() { + return next_proxy->error_code(); +} + +const char* CONNECTION_PROXY::error() { + return next_proxy->error(); +} + +const char* CONNECTION_PROXY::sqlstate() { + return next_proxy->sqlstate(); +} + +unsigned long CONNECTION_PROXY::thread_id() { + return next_proxy->thread_id(); +} + +int CONNECTION_PROXY::set_character_set(const char* csname) { + return next_proxy->set_character_set(csname); +} + +void CONNECTION_PROXY::init() { + next_proxy->init(); +} + +bool CONNECTION_PROXY::ssl_set(const char* key, const char* cert, const char* ca, const char* capath, const char* cipher) { + return next_proxy->ssl_set(key, cert, ca, capath, cipher); +} + +bool CONNECTION_PROXY::change_user(const char* user, const char* passwd, const char* db) { + return next_proxy->change_user(user, passwd, db); +} + +bool CONNECTION_PROXY::real_connect( + const char* host, const char* user, const char* passwd, + const char* db, unsigned int port, const char* unix_socket, + unsigned long clientflag) { + + return next_proxy->real_connect(host, user, passwd, db, port, unix_socket, clientflag); +} + +int CONNECTION_PROXY::select_db(const char* db) { + return next_proxy->select_db(db); +} + +int CONNECTION_PROXY::query(const char* q) { + return next_proxy->query(q); +} + +int CONNECTION_PROXY::real_query(const char* q, unsigned long length) { + return next_proxy->real_query(q, length); +} + +MYSQL_RES* CONNECTION_PROXY::store_result() { + return next_proxy->store_result(); +} + +MYSQL_RES* CONNECTION_PROXY::use_result() { + return next_proxy->use_result(); +} + +struct CHARSET_INFO* CONNECTION_PROXY::get_character_set() const { + return next_proxy->get_character_set(); +} + +void CONNECTION_PROXY::get_character_set_info(MY_CHARSET_INFO* charset) { + next_proxy->get_character_set_info(charset); +} + +bool CONNECTION_PROXY::autocommit(bool auto_mode) { + return next_proxy->autocommit(auto_mode); +} + +int CONNECTION_PROXY::next_result() { + return next_proxy->next_result(); +} + +int CONNECTION_PROXY::stmt_next_result(MYSQL_STMT* stmt) { + return next_proxy->stmt_next_result(stmt); +} + +void CONNECTION_PROXY::close() { + next_proxy->close(); +} + +bool CONNECTION_PROXY::real_connect_dns_srv( + const char* dns_srv_name, const char* user, + const char* passwd, const char* db, unsigned long client_flag) { + + return next_proxy->real_connect_dns_srv(dns_srv_name, user, passwd, db, client_flag); +} + +int CONNECTION_PROXY::ping() { + return next_proxy->ping(); +} + +unsigned long CONNECTION_PROXY::get_client_version(void) { + return mysql_get_client_version(); +} + +int CONNECTION_PROXY::get_option(mysql_option option, const void* arg) { + return next_proxy->get_option(option, arg); +} + +int CONNECTION_PROXY::options4(mysql_option option, const void* arg1, const void* arg2) { + return next_proxy->options4(option, arg1, arg2); +} + +int CONNECTION_PROXY::options(mysql_option option, const void* arg) { + return next_proxy->options(option, arg); +} + +void CONNECTION_PROXY::free_result(MYSQL_RES* result) { + next_proxy->free_result(result); +} + +void CONNECTION_PROXY::data_seek(MYSQL_RES* result, uint64_t offset) { + next_proxy->data_seek(result, offset); +} + +MYSQL_ROW_OFFSET CONNECTION_PROXY::row_seek(MYSQL_RES* result, MYSQL_ROW_OFFSET offset) { + return next_proxy->row_seek(result, offset); +} + +MYSQL_FIELD_OFFSET CONNECTION_PROXY::field_seek(MYSQL_RES* result, MYSQL_FIELD_OFFSET offset) { + return next_proxy->field_seek(result, offset); +} + +MYSQL_ROW CONNECTION_PROXY::fetch_row(MYSQL_RES* result) { + return next_proxy->fetch_row(result); +} + +unsigned long* CONNECTION_PROXY::fetch_lengths(MYSQL_RES* result) { + return next_proxy->fetch_lengths(result); +} + +MYSQL_FIELD* CONNECTION_PROXY::fetch_field(MYSQL_RES* result) { + return next_proxy->fetch_field(result); +} + +MYSQL_RES* CONNECTION_PROXY::list_fields(const char* table, const char* wild) { + return next_proxy->list_fields(table, wild); +} + +unsigned long CONNECTION_PROXY::real_escape_string(char* to, const char* from, unsigned long length) { + return next_proxy->real_escape_string(to, from, length); +} + +bool CONNECTION_PROXY::bind_param(unsigned n_params, MYSQL_BIND* binds, const char** names) { + return next_proxy->bind_param(n_params, binds, names); +} + +MYSQL_STMT* CONNECTION_PROXY::stmt_init() { + return next_proxy->stmt_init(); +} + +int CONNECTION_PROXY::stmt_prepare(MYSQL_STMT* stmt, const char* query, unsigned long length) { + return next_proxy->stmt_prepare(stmt, query, length); +} + +int CONNECTION_PROXY::stmt_execute(MYSQL_STMT* stmt) { + return next_proxy->stmt_execute(stmt); +} + +int CONNECTION_PROXY::stmt_fetch(MYSQL_STMT* stmt) { + return next_proxy->stmt_fetch(stmt); +} + +int CONNECTION_PROXY::stmt_fetch_column(MYSQL_STMT* stmt, MYSQL_BIND* bind_arg, unsigned int column, unsigned long offset) { + return next_proxy->stmt_fetch_column(stmt, bind_arg, column, offset); +} + +int CONNECTION_PROXY::stmt_store_result(MYSQL_STMT* stmt) { + return next_proxy->stmt_store_result(stmt); +} + +unsigned long CONNECTION_PROXY::stmt_param_count(MYSQL_STMT* stmt) { + return next_proxy->stmt_param_count(stmt); +} + +bool CONNECTION_PROXY::stmt_bind_param(MYSQL_STMT* stmt, MYSQL_BIND* bnd) { + return next_proxy->stmt_bind_param(stmt, bnd); +} + +bool CONNECTION_PROXY::stmt_bind_result(MYSQL_STMT* stmt, MYSQL_BIND* bnd) { + return next_proxy->stmt_bind_result(stmt, bnd); +} + +bool CONNECTION_PROXY::stmt_close(MYSQL_STMT* stmt) { + return next_proxy->stmt_close(stmt); +} + +bool CONNECTION_PROXY::stmt_reset(MYSQL_STMT* stmt) { + return next_proxy->stmt_reset(stmt); +} + +bool CONNECTION_PROXY::stmt_free_result(MYSQL_STMT* stmt) { + return next_proxy->stmt_free_result(stmt); +} + +bool CONNECTION_PROXY::stmt_send_long_data(MYSQL_STMT* stmt, unsigned int param_number, const char* data, + unsigned long length) { + + return next_proxy->stmt_send_long_data(stmt, param_number, data, length); +} + +MYSQL_RES* CONNECTION_PROXY::stmt_result_metadata(MYSQL_STMT* stmt) { + return next_proxy->stmt_result_metadata(stmt); +} + +unsigned int CONNECTION_PROXY::stmt_errno(MYSQL_STMT* stmt) { + return next_proxy->stmt_errno(stmt); +} + +const char* CONNECTION_PROXY::stmt_error(MYSQL_STMT* stmt) { + return next_proxy->stmt_error(stmt); +} + +MYSQL_ROW_OFFSET CONNECTION_PROXY::stmt_row_seek(MYSQL_STMT* stmt, MYSQL_ROW_OFFSET offset) { + return next_proxy->stmt_row_seek(stmt, offset); +} + +MYSQL_ROW_OFFSET CONNECTION_PROXY::stmt_row_tell(MYSQL_STMT* stmt) { + return next_proxy->stmt_row_tell(stmt); +} + +void CONNECTION_PROXY::stmt_data_seek(MYSQL_STMT* stmt, uint64_t offset) { + next_proxy->stmt_data_seek(stmt, offset); +} + +uint64_t CONNECTION_PROXY::stmt_num_rows(MYSQL_STMT* stmt) { + return next_proxy->stmt_num_rows(stmt); +} + +uint64_t CONNECTION_PROXY::stmt_affected_rows(MYSQL_STMT* stmt) { + return next_proxy->stmt_affected_rows(stmt); +} + +unsigned int CONNECTION_PROXY::stmt_field_count(MYSQL_STMT* stmt) { + return next_proxy->stmt_field_count(stmt); +} + +st_mysql_client_plugin* CONNECTION_PROXY::client_find_plugin(const char* name, int type) { + return next_proxy->client_find_plugin(name, type); +} + +bool CONNECTION_PROXY::is_connected() { + return next_proxy->is_connected(); +} + +void CONNECTION_PROXY::set_last_error_code(unsigned int error_code) { + next_proxy->set_last_error_code(error_code); +} + +char* CONNECTION_PROXY::get_last_error() const { + return next_proxy->get_last_error(); +} + +unsigned int CONNECTION_PROXY::get_last_error_code() const { + return next_proxy->get_last_error_code(); +} + +char* CONNECTION_PROXY::get_sqlstate() const { + return next_proxy->get_sqlstate(); +} + +char* CONNECTION_PROXY::get_server_version() const { + return next_proxy->get_server_version(); +} + +uint64_t CONNECTION_PROXY::get_affected_rows() const { + return next_proxy->get_affected_rows(); +} + +void CONNECTION_PROXY::set_affected_rows(uint64_t num_rows) { + next_proxy->set_affected_rows(num_rows); +} + +char* CONNECTION_PROXY::get_host_info() const { + return next_proxy->get_host_info(); +} + +std::string CONNECTION_PROXY::get_host() { + return next_proxy->get_host(); +} + +unsigned int CONNECTION_PROXY::get_port() { + return next_proxy->get_port(); +} + +unsigned long CONNECTION_PROXY::get_max_packet() const { + return next_proxy->get_max_packet(); +} + +unsigned long CONNECTION_PROXY::get_server_capabilities() const { + return next_proxy->get_server_capabilities(); +} + +unsigned int CONNECTION_PROXY::get_server_status() const { + return next_proxy->get_server_status(); +} + +void CONNECTION_PROXY::set_connection(CONNECTION_PROXY* connection_proxy) { + next_proxy->set_connection(connection_proxy); +} + +void CONNECTION_PROXY::close_socket() { + next_proxy->close_socket(); +} + +void CONNECTION_PROXY::set_next_proxy(CONNECTION_PROXY* next_proxy) { + if (this->next_proxy) { + throw std::runtime_error("There is already a next proxy present!"); + } + + this->next_proxy = next_proxy; +} + +MYSQL* CONNECTION_PROXY::move_mysql_connection() { + return next_proxy ? next_proxy->move_mysql_connection() : nullptr; +} diff --git a/driver/connection_proxy.h b/driver/connection_proxy.h new file mode 100644 index 000000000..b12160548 --- /dev/null +++ b/driver/connection_proxy.h @@ -0,0 +1,172 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License, version 2.0 +// (GPLv2), as published by the Free Software Foundation, with the +// following additional permissions: +// +// This program is distributed with certain software that is licensed +// under separate terms, as designated in a particular file or component +// or in the license documentation. Without limiting your rights under +// the GPLv2, the authors of this program hereby grant you an additional +// permission to link the program and your derivative works with the +// separately licensed software that they have included with the program. +// +// Without limiting the foregoing grant of rights under the GPLv2 and +// additional permission as to separately licensed software, this +// program is also subject to the Universal FOSS Exception, version 1.0, +// a copy of which can be found along with its FAQ at +// http://oss.oracle.com/licenses/universal-foss-exception. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License, version 2.0, for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see +// http://www.gnu.org/licenses/gpl-2.0.html. + +#ifndef __CONNECTION_PROXY__ +#define __CONNECTION_PROXY__ + +#include "MYODBC_MYSQL.h" + +struct DBC; +struct DataSource; + +class CONNECTION_PROXY { +public: + CONNECTION_PROXY(DBC* dbc, DataSource* ds); + virtual ~CONNECTION_PROXY(); + + virtual void delete_ds(); + virtual uint64_t num_rows(MYSQL_RES* res); + virtual unsigned int num_fields(MYSQL_RES* res); + virtual MYSQL_FIELD* fetch_field_direct(MYSQL_RES* res, unsigned int fieldnr); + virtual MYSQL_ROW_OFFSET row_tell(MYSQL_RES* res); + + virtual unsigned int field_count(); + virtual uint64_t affected_rows(); + virtual unsigned int error_code(); + virtual const char* error(); + virtual const char* sqlstate(); + virtual unsigned long thread_id(); + virtual int set_character_set(const char* csname); + + virtual void init(); + virtual bool ssl_set(const char* key, const char* cert, const char* ca, + const char* capath, const char* cipher); + virtual bool change_user(const char* user, const char* passwd, + const char* db); + virtual bool real_connect(const char* host, const char* user, + const char* passwd, const char* db, unsigned int port, + const char* unix_socket, unsigned long clientflag); + virtual int select_db(const char* db); + virtual int query(const char* q); + virtual int real_query(const char* q, unsigned long length); + virtual MYSQL_RES* store_result(); + virtual MYSQL_RES* use_result(); + virtual struct CHARSET_INFO* get_character_set() const; + virtual void get_character_set_info(MY_CHARSET_INFO* charset); + + virtual int ping(); + static unsigned long get_client_version(void); + virtual int options(enum mysql_option option, const void* arg); + virtual int options4(enum mysql_option option, const void* arg1, + const void* arg2); + virtual int get_option(enum mysql_option option, const void* arg); + virtual void free_result(MYSQL_RES* result); + virtual void data_seek(MYSQL_RES* result, uint64_t offset); + virtual MYSQL_ROW_OFFSET row_seek(MYSQL_RES* result, MYSQL_ROW_OFFSET offset); + virtual MYSQL_FIELD_OFFSET field_seek(MYSQL_RES* result, MYSQL_FIELD_OFFSET offset); + virtual MYSQL_ROW fetch_row(MYSQL_RES* result); + + virtual unsigned long* fetch_lengths(MYSQL_RES* result); + virtual MYSQL_FIELD* fetch_field(MYSQL_RES* result); + virtual MYSQL_RES* list_fields(const char* table, const char* wild); + virtual unsigned long real_escape_string(char* to, const char* from, + unsigned long length); + + virtual bool bind_param(unsigned n_params, MYSQL_BIND* binds, + const char** names); + + virtual MYSQL_STMT* stmt_init(); + virtual int stmt_prepare(MYSQL_STMT* stmt, const char* query, unsigned long length); + virtual int stmt_execute(MYSQL_STMT* stmt); + virtual int stmt_fetch(MYSQL_STMT* stmt); + virtual int stmt_fetch_column(MYSQL_STMT* stmt, MYSQL_BIND* bind_arg, + unsigned int column, unsigned long offset); + virtual int stmt_store_result(MYSQL_STMT* stmt); + virtual unsigned long stmt_param_count(MYSQL_STMT* stmt); + virtual bool stmt_bind_param(MYSQL_STMT* stmt, MYSQL_BIND* bnd); + virtual bool stmt_bind_result(MYSQL_STMT* stmt, MYSQL_BIND* bnd); + virtual bool stmt_close(MYSQL_STMT* stmt); + virtual bool stmt_reset(MYSQL_STMT* stmt); + virtual bool stmt_free_result(MYSQL_STMT* stmt); + virtual bool stmt_send_long_data(MYSQL_STMT* stmt, unsigned int param_number, + const char* data, unsigned long length); + virtual MYSQL_RES* stmt_result_metadata(MYSQL_STMT* stmt); + virtual unsigned int stmt_errno(MYSQL_STMT* stmt); + virtual const char* stmt_error(MYSQL_STMT* stmt); + virtual MYSQL_ROW_OFFSET stmt_row_seek(MYSQL_STMT* stmt, MYSQL_ROW_OFFSET offset); + virtual MYSQL_ROW_OFFSET stmt_row_tell(MYSQL_STMT* stmt); + virtual void stmt_data_seek(MYSQL_STMT* stmt, uint64_t offset); + virtual uint64_t stmt_num_rows(MYSQL_STMT* stmt); + virtual uint64_t stmt_affected_rows(MYSQL_STMT* stmt); + virtual unsigned int stmt_field_count(MYSQL_STMT* stmt); + + virtual bool autocommit(bool auto_mode); + virtual int next_result(); + virtual int stmt_next_result(MYSQL_STMT* stmt); + virtual void close(); + + virtual bool real_connect_dns_srv(const char* dns_srv_name, + const char* user, const char* passwd, + const char* db, unsigned long client_flag); + virtual struct st_mysql_client_plugin* client_find_plugin( + const char* name, int type); + + virtual bool is_connected(); + + virtual void set_last_error_code(unsigned int error_code); + + virtual char* get_last_error() const; + + virtual unsigned int get_last_error_code() const; + + virtual char* get_sqlstate() const; + + virtual char* get_server_version() const; + + virtual uint64_t get_affected_rows() const; + + virtual void set_affected_rows(uint64_t num_rows); + + virtual char* get_host_info() const; + + virtual std::string get_host(); + + virtual unsigned int get_port(); + + virtual unsigned long get_max_packet() const; + + virtual unsigned long get_server_capabilities() const; + + virtual unsigned int get_server_status() const; + + virtual void set_connection(CONNECTION_PROXY* connection_proxy); + + virtual void close_socket(); + + virtual void set_next_proxy(CONNECTION_PROXY* next_proxy); + + virtual MYSQL* move_mysql_connection(); + +protected: + DBC* dbc = nullptr; + DataSource* ds = nullptr; + CONNECTION_PROXY* next_proxy = nullptr; +}; + +#endif /* __CONNECTION_PROXY__ */ diff --git a/driver/cursor.cc b/driver/cursor.cc index bda25ce0b..74fc0abfc 100644 --- a/driver/cursor.cc +++ b/driver/cursor.cc @@ -51,7 +51,7 @@ /* Sets affected rows everewhere where SQLRowCOunt could look for */ void global_set_affected_rows(STMT * stmt, my_ulonglong rows) { - stmt->dbc->mysql_proxy->set_affected_rows(rows); + stmt->dbc->connection_proxy->set_affected_rows(rows); stmt->affected_rows = rows; /* Dirty hack. But not dirtier than the one above */ @@ -227,7 +227,7 @@ static my_bool check_if_usable_unique_key_exists(STMT *stmt) /* Use SHOW KEYS FROM table to check for keys. */ pos= myodbc_stpmov(buff, "SHOW KEYS FROM `"); - pos+= stmt->dbc->mysql_proxy->real_escape_string(pos, table, strlen(table)); + pos+= stmt->dbc->connection_proxy->real_escape_string(pos, table, strlen(table)); pos= myodbc_stpmov(pos, "`"); MYLOG_STMT_TRACE(stmt, buff); @@ -235,13 +235,13 @@ static my_bool check_if_usable_unique_key_exists(STMT *stmt) assert(stmt); LOCK_DBC(stmt->dbc); if (exec_stmt_query(stmt, buff, strlen(buff), FALSE) || - !(res = stmt->dbc->mysql_proxy->store_result())) + !(res = stmt->dbc->connection_proxy->store_result())) { stmt->set_error(MYERR_S1000); return FALSE; } - while ((row = stmt->dbc->mysql_proxy->fetch_row(res)) && + while ((row = stmt->dbc->connection_proxy->fetch_row(res)) && stmt->cursor.pk_count < MY_MAX_PK_PARTS) { int seq= atoi(row[3]); @@ -269,7 +269,7 @@ static my_bool check_if_usable_unique_key_exists(STMT *stmt) /* Forget about any key we had in progress, we didn't have it all. */ stmt->cursor.pk_count= seq_in_index= 0; } - stmt->dbc->mysql_proxy->free_result(res); + stmt->dbc->connection_proxy->free_result(res); /* Remember that we've figured this out already. */ stmt->cursor.pk_validated= 1; @@ -450,7 +450,7 @@ static bool insert_field_std(STMT *stmt, MYSQL_RES *result, iprec_(DESC_PARAM, DESC_IMP); DESCREC *aprec= &aprec_, *iprec= &iprec_; - MYSQL_FIELD *field= stmt->dbc->mysql_proxy->fetch_field_direct(result,nSrcCol); + MYSQL_FIELD *field= stmt->dbc->connection_proxy->fetch_field_direct(result,nSrcCol); MYSQL_ROW row_data; SQLLEN length; char as_string[50], *dummy; @@ -578,7 +578,7 @@ static SQLRETURN append_all_fields_std(STMT *stmt, std::string &str) MYLOG_STMT_TRACE(stmt, select.c_str()); LOCK_STMT(stmt); if (exec_stmt_query_std(stmt, select, false) || - !(presultAllColumns = stmt->dbc->mysql_proxy->store_result())) + !(presultAllColumns = stmt->dbc->connection_proxy->store_result())) { stmt->set_error(MYERR_S1000); return SQL_ERROR; @@ -588,10 +588,10 @@ static SQLRETURN append_all_fields_std(STMT *stmt, std::string &str) If the number of fields in the underlying table is not the same as our result set, we bail out -- we need them all! */ - if (stmt->dbc->mysql_proxy->num_fields(presultAllColumns) != - stmt->dbc->mysql_proxy->num_fields(result)) + if (stmt->dbc->connection_proxy->num_fields(presultAllColumns) != + stmt->dbc->connection_proxy->num_fields(result)) { - stmt->dbc->mysql_proxy->free_result(presultAllColumns); + stmt->dbc->connection_proxy->free_result(presultAllColumns); return SQL_ERROR; } @@ -614,7 +614,7 @@ static SQLRETURN append_all_fields_std(STMT *stmt, std::string &str) { stmt->set_error(MYERR_S1000, "Invalid use of floating point comparision in positioned operations",0); - stmt->dbc->mysql_proxy->free_result(presultAllColumns); + stmt->dbc->connection_proxy->free_result(presultAllColumns); return SQL_ERROR; } @@ -629,7 +629,7 @@ static SQLRETURN append_all_fields_std(STMT *stmt, std::string &str) str.append("="); if (insert_field_std(stmt, result, str, j)) { - stmt->dbc->mysql_proxy->free_result(presultAllColumns); + stmt->dbc->connection_proxy->free_result(presultAllColumns); return SQL_ERROR; } found_field= TRUE; @@ -642,12 +642,12 @@ static SQLRETURN append_all_fields_std(STMT *stmt, std::string &str) */ if (!found_field) { - stmt->dbc->mysql_proxy->free_result(presultAllColumns); + stmt->dbc->connection_proxy->free_result(presultAllColumns); return SQL_ERROR; } } - stmt->dbc->mysql_proxy->free_result(presultAllColumns); + stmt->dbc->connection_proxy->free_result(presultAllColumns); return SQL_SUCCESS; } @@ -732,7 +732,7 @@ static SQLRETURN build_set_clause_std(STMT *stmt, SQLULEN irow, { SQLLEN *pcbValue; - field= stmt->dbc->mysql_proxy->fetch_field_direct(result,ncol); + field= stmt->dbc->connection_proxy->fetch_field_direct(result,ncol); arrec= desc_get_rec(stmt->ard, ncol, FALSE); irrec= desc_get_rec(stmt->ird, ncol, FALSE); @@ -840,7 +840,7 @@ SQLRETURN my_pos_delete_std(STMT *stmt, STMT *stmtParam, nReturn= exec_stmt_query_std(stmt, str, false); if ( nReturn == SQL_SUCCESS || nReturn == SQL_SUCCESS_WITH_INFO ) { - stmtParam->affected_rows= stmt->dbc->mysql_proxy->affected_rows(); + stmtParam->affected_rows= stmt->dbc->connection_proxy->affected_rows(); nReturn= update_status(stmtParam,SQL_ROW_DELETED); } return nReturn; @@ -897,7 +897,7 @@ SQLRETURN my_pos_update_std( STMT * pStmtCursor, rc = my_SQLExecute( pStmtTemp ); if ( SQL_SUCCEEDED( rc ) ) { - pStmt->affected_rows = pStmtTemp->dbc->mysql_proxy->affected_rows(); + pStmt->affected_rows = pStmtTemp->dbc->connection_proxy->affected_rows(); rc = update_status( pStmt, SQL_ROW_UPDATED ); } else if (rc == SQL_NEED_DATA) @@ -1054,7 +1054,7 @@ static SQLRETURN setpos_delete_bookmark_std(STMT *stmt, std::string &query) /* execute our DELETE statement */ if (!(nReturn= exec_stmt_query_std(stmt, query, false))) { - affected_rows+= stmt->dbc->mysql_proxy->get_affected_rows(); + affected_rows+= stmt->dbc->connection_proxy->get_affected_rows(); } if (stmt->stmt_options.rowStatusPtr_ex) { @@ -1128,7 +1128,7 @@ static SQLRETURN setpos_delete_std(STMT *stmt, SQLUSMALLINT irow, /* execute our DELETE statement */ if (!(nReturn= exec_stmt_query_std(stmt, query, false))) { - affected_rows+= stmt->dbc->mysql_proxy->get_affected_rows(); + affected_rows+= stmt->dbc->connection_proxy->get_affected_rows(); } } while ( ++rowset_pos <= rowset_end ); @@ -1223,7 +1223,7 @@ static SQLRETURN setpos_update_bookmark_std(STMT *stmt, std::string &query) if (!(nReturn= exec_stmt_query_std(stmt, query, false))) { - affected+= stmt->dbc->mysql_proxy->affected_rows(); + affected+= stmt->dbc->connection_proxy->affected_rows(); } if (stmt->stmt_options.rowStatusPtr_ex) { @@ -1306,7 +1306,7 @@ static SQLRETURN setpos_update_std(STMT *stmt, SQLUSMALLINT irow, if (!(nReturn= exec_stmt_query_std(stmt, query, false))) { - affected+= stmt->dbc->mysql_proxy->affected_rows(); + affected+= stmt->dbc->connection_proxy->affected_rows(); } else if (!SQL_SUCCEEDED(nReturn)) { @@ -1387,7 +1387,7 @@ static SQLRETURN batch_insert_std( STMT *stmt, SQLULEN irow, std::string &query query.append("("); for ( ncol= 0; ncol < result->field_count; ++ncol ) { - MYSQL_FIELD *field= stmt->dbc->mysql_proxy->fetch_field_direct(result, ncol); + MYSQL_FIELD *field= stmt->dbc->connection_proxy->fetch_field_direct(result, ncol); DESCREC *arrec; SQLLEN ind_or_len= 0; @@ -1778,7 +1778,7 @@ SQLRETURN SQL_API my_SQLSetPos(SQLHSTMT hstmt, SQLSETPOSIROW irow, /* build list of column names */ for (nCol= 0; nCol < result->field_count; ++nCol) { - MYSQL_FIELD *field= stmt->dbc->mysql_proxy->fetch_field_direct(result, nCol); + MYSQL_FIELD *field= stmt->dbc->connection_proxy->fetch_field_direct(result, nCol); myodbc_append_quoted_name_std(ins_query, field->org_name); if (nCol < result->field_count - 1) ins_query.append(","); diff --git a/driver/driver.h b/driver/driver.h index 3913b64bf..d0aa2d9c9 100644 --- a/driver/driver.h +++ b/driver/driver.h @@ -41,11 +41,11 @@ #include "../MYODBC_MYSQL.h" #include "../MYODBC_CONF.h" #include "../MYODBC_ODBC.h" +#include "util/installer.h" + #include "connection_handler.h" -#include "efm_proxy.h" +#include "connection_proxy.h" #include "failover.h" -#include "mysql_proxy.h" -#include "util/installer.h" /* Disable _attribute__ on non-gcc compilers. */ #if !defined(__attribute__) && !defined(__GNUC__) @@ -613,7 +613,7 @@ static std::atomic_ulong last_dbc_id{1}; struct DBC { ENV *env; - MYSQL_PROXY *mysql_proxy; + CONNECTION_PROXY *connection_proxy; std::list stmt_list; std::list desc_list; // Explicit descriptors STMT_OPTIONS stmt_options; @@ -660,11 +660,11 @@ struct DBC void init_proxy_chain(DataSource *dsrc); inline bool transactions_supported() { - return mysql_proxy->get_server_capabilities() & CLIENT_TRANSACTIONS; + return connection_proxy->get_server_capabilities() & CLIENT_TRANSACTIONS; } inline bool autocommit_is_on() { - return mysql_proxy->get_server_status() & SERVER_STATUS_AUTOCOMMIT; + return connection_proxy->get_server_status() & SERVER_STATUS_AUTOCOMMIT; } void close(); @@ -981,7 +981,7 @@ struct ODBC_STMT { MYSQL_STMT *m_stmt; - ODBC_STMT(MYSQL_PROXY *mysql_proxy) { m_stmt = mysql_proxy->stmt_init(); } + ODBC_STMT(CONNECTION_PROXY *connection_proxy) { m_stmt = connection_proxy->stmt_init(); } operator MYSQL_STMT*() { return m_stmt; } ~ODBC_STMT() { mysql_stmt_close(m_stmt); } // TODO Replace with proxy call }; diff --git a/driver/efm_proxy.cc b/driver/efm_proxy.cc index 4329c1ea8..6fa4a8132 100644 --- a/driver/efm_proxy.cc +++ b/driver/efm_proxy.cc @@ -27,7 +27,7 @@ // along with this program. If not, see // http://www.gnu.org/licenses/gpl-2.0.html. -#include "driver.h" +#include "efm_proxy.h" namespace { const char* RETRIEVE_HOST_PORT_SQL = "SELECT CONCAT(@@hostname, ':', @@port)"; @@ -36,12 +36,12 @@ namespace { EFM_PROXY::EFM_PROXY(DBC* dbc, DataSource* ds) : EFM_PROXY( dbc, ds, nullptr, std::make_shared(ds && ds->save_queries)) {} -EFM_PROXY::EFM_PROXY(DBC* dbc, DataSource* ds, MYSQL_PROXY* next_proxy) : EFM_PROXY( +EFM_PROXY::EFM_PROXY(DBC* dbc, DataSource* ds, CONNECTION_PROXY* next_proxy) : EFM_PROXY( dbc, ds, next_proxy, std::make_shared(ds && ds->save_queries)) {} -EFM_PROXY::EFM_PROXY(DBC* dbc, DataSource* ds, MYSQL_PROXY* next_proxy, +EFM_PROXY::EFM_PROXY(DBC* dbc, DataSource* ds, CONNECTION_PROXY* next_proxy, std::shared_ptr monitor_service) - : MYSQL_PROXY(dbc, ds), + : CONNECTION_PROXY(dbc, ds), monitor_service{std::move(monitor_service)} { this->next_proxy = next_proxy; @@ -103,13 +103,13 @@ void EFM_PROXY::generate_node_keys() { } } -void EFM_PROXY::set_next_proxy(MYSQL_PROXY* next_proxy) { - MYSQL_PROXY::set_next_proxy(next_proxy); +void EFM_PROXY::set_next_proxy(CONNECTION_PROXY* next_proxy) { + CONNECTION_PROXY::set_next_proxy(next_proxy); generate_node_keys(); } -void EFM_PROXY::set_connection(MYSQL_PROXY* mysql_proxy) { - next_proxy->set_connection(mysql_proxy); +void EFM_PROXY::set_connection(CONNECTION_PROXY* connection_proxy) { + CONNECTION_PROXY::set_connection(connection_proxy); if (monitor_service != nullptr && !node_keys.empty()) { monitor_service->stop_monitoring_for_all_connections(node_keys); @@ -118,54 +118,6 @@ void EFM_PROXY::set_connection(MYSQL_PROXY* mysql_proxy) { generate_node_keys(); } -void EFM_PROXY::close_socket() { - next_proxy->close_socket(); -} - -void EFM_PROXY::delete_ds() { - next_proxy->delete_ds(); -} - -uint64_t EFM_PROXY::num_rows(MYSQL_RES* res) { - return next_proxy->num_rows(res); -} - -unsigned EFM_PROXY::num_fields(MYSQL_RES* res) { - return next_proxy->num_fields(res); -} - -MYSQL_FIELD* EFM_PROXY::fetch_field_direct(MYSQL_RES* res, unsigned fieldnr) { - return next_proxy->fetch_field_direct(res, fieldnr); -} - -MYSQL_ROW_OFFSET EFM_PROXY::row_tell(MYSQL_RES* res) { - return next_proxy->row_tell(res); -} - -unsigned EFM_PROXY::field_count() { - return next_proxy->field_count(); -} - -uint64_t EFM_PROXY::affected_rows() { - return next_proxy->affected_rows(); -} - -unsigned EFM_PROXY::error_code() { - return next_proxy->error_code(); -} - -const char* EFM_PROXY::error() { - return next_proxy->error(); -} - -const char* EFM_PROXY::sqlstate() { - return next_proxy->sqlstate(); -} - -unsigned long EFM_PROXY::thread_id() { - return next_proxy->thread_id(); -} - int EFM_PROXY::set_character_set(const char* csname) { const auto context = start_monitoring(); const int ret = next_proxy->set_character_set(csname); @@ -173,14 +125,6 @@ int EFM_PROXY::set_character_set(const char* csname) { return ret; } -void EFM_PROXY::init() { - next_proxy->init(); -} - -bool EFM_PROXY::ssl_set(const char* key, const char* cert, const char* ca, const char* capath, const char* cipher) { - return next_proxy->ssl_set(key, cert, ca, capath, cipher); -} - bool EFM_PROXY::change_user(const char* user, const char* passwd, const char* db) { const auto context = start_monitoring(); const bool ret = next_proxy->change_user(user, passwd, db); @@ -235,18 +179,6 @@ MYSQL_RES* EFM_PROXY::use_result() { return ret; } -CHARSET_INFO* EFM_PROXY::get_character_set() const { - return next_proxy->get_character_set(); -} - -void EFM_PROXY::get_character_set_info(MY_CHARSET_INFO* charset) { - next_proxy->get_character_set_info(charset); -} - -bool EFM_PROXY::autocommit(bool auto_mode) { - return next_proxy->autocommit(auto_mode); -} - int EFM_PROXY::next_result() { const auto context = start_monitoring(); const int ret = next_proxy->next_result(); @@ -261,10 +193,6 @@ int EFM_PROXY::stmt_next_result(MYSQL_STMT* stmt) { return ret; } -void EFM_PROXY::close() { - next_proxy->close(); -} - bool EFM_PROXY::real_connect_dns_srv( const char* dns_srv_name, const char* user, const char* passwd, const char* db, unsigned long client_flag) { @@ -276,40 +204,12 @@ bool EFM_PROXY::real_connect_dns_srv( return ret; } -int EFM_PROXY::ping() { - return next_proxy->ping(); -} - -int EFM_PROXY::options4(mysql_option option, const void* arg1, const void* arg2) { - return next_proxy->options4(option, arg1, arg2); -} - -int EFM_PROXY::get_option(mysql_option option, const void* arg) { - return next_proxy->get_option(option, arg); -} - -int EFM_PROXY::options(mysql_option option, const void* arg) { - return next_proxy->options(option, arg); -} - void EFM_PROXY::free_result(MYSQL_RES* result) { const auto context = start_monitoring(); next_proxy->free_result(result); stop_monitoring(context); } -void EFM_PROXY::data_seek(MYSQL_RES* result, uint64_t offset) { - next_proxy->data_seek(result, offset); -} - -MYSQL_ROW_OFFSET EFM_PROXY::row_seek(MYSQL_RES* result, MYSQL_ROW_OFFSET offset) { - return next_proxy->row_seek(result, offset); -} - -MYSQL_FIELD_OFFSET EFM_PROXY::field_seek(MYSQL_RES* result, MYSQL_FIELD_OFFSET offset) { - return next_proxy->field_seek(result, offset); -} - MYSQL_ROW EFM_PROXY::fetch_row(MYSQL_RES* result) { const auto context = start_monitoring(); const MYSQL_ROW ret = next_proxy->fetch_row(result); @@ -317,14 +217,6 @@ MYSQL_ROW EFM_PROXY::fetch_row(MYSQL_RES* result) { return ret; } -unsigned long* EFM_PROXY::fetch_lengths(MYSQL_RES* result) { - return next_proxy->fetch_lengths(result); -} - -MYSQL_FIELD* EFM_PROXY::fetch_field(MYSQL_RES* result) { - return next_proxy->fetch_field(result); -} - MYSQL_RES* EFM_PROXY::list_fields(const char* table, const char* wild) { const auto context = start_monitoring(); MYSQL_RES* ret = next_proxy->list_fields(table, wild); @@ -388,10 +280,6 @@ int EFM_PROXY::stmt_store_result(MYSQL_STMT* stmt) { return ret; } -unsigned long EFM_PROXY::stmt_param_count(MYSQL_STMT* stmt) { - return next_proxy->stmt_param_count(stmt); -} - bool EFM_PROXY::stmt_bind_param(MYSQL_STMT* stmt, MYSQL_BIND* bnd) { const auto context = start_monitoring(); const bool ret = next_proxy->stmt_bind_param(stmt, bnd); @@ -441,95 +329,3 @@ MYSQL_RES* EFM_PROXY::stmt_result_metadata(MYSQL_STMT* stmt) { stop_monitoring(context); return ret; } - -unsigned EFM_PROXY::stmt_errno(MYSQL_STMT* stmt) { - return next_proxy->stmt_errno(stmt); -} - -const char* EFM_PROXY::stmt_error(MYSQL_STMT* stmt) { - return next_proxy->stmt_error(stmt); -} - -MYSQL_ROW_OFFSET EFM_PROXY::stmt_row_seek(MYSQL_STMT* stmt, MYSQL_ROW_OFFSET offset) { - return next_proxy->stmt_row_seek(stmt, offset); -} - -MYSQL_ROW_OFFSET EFM_PROXY::stmt_row_tell(MYSQL_STMT* stmt) { - return next_proxy->stmt_row_tell(stmt); -} - -void EFM_PROXY::stmt_data_seek(MYSQL_STMT* stmt, uint64_t offset) { - next_proxy->stmt_data_seek(stmt, offset); -} - -uint64_t EFM_PROXY::stmt_num_rows(MYSQL_STMT* stmt) { - return next_proxy->stmt_num_rows(stmt); -} - -uint64_t EFM_PROXY::stmt_affected_rows(MYSQL_STMT* stmt) { - return next_proxy->stmt_affected_rows(stmt); -} - -unsigned EFM_PROXY::stmt_field_count(MYSQL_STMT* stmt) { - return next_proxy->stmt_field_count(stmt); -} - -st_mysql_client_plugin* EFM_PROXY::client_find_plugin(const char* name, int type) { - return next_proxy->client_find_plugin(name, type); -} - -bool EFM_PROXY::is_connected() { - return next_proxy->is_connected(); -} - -void EFM_PROXY::set_last_error_code(unsigned error_code) { - next_proxy->set_last_error_code(error_code); -} - -char* EFM_PROXY::get_last_error() const { - return next_proxy->get_last_error(); -} - -unsigned EFM_PROXY::get_last_error_code() const { - return next_proxy->get_last_error_code(); -} - -char* EFM_PROXY::get_sqlstate() const { - return next_proxy->get_sqlstate(); -} - -char* EFM_PROXY::get_server_version() const { - return next_proxy->get_server_version(); -} - -uint64_t EFM_PROXY::get_affected_rows() const { - return next_proxy->get_affected_rows(); -} - -void EFM_PROXY::set_affected_rows(uint64_t num_rows) { - next_proxy->set_affected_rows(num_rows); -} - -char* EFM_PROXY::get_host_info() const { - return next_proxy->get_host_info(); -} - -std::string EFM_PROXY::get_host() { - return next_proxy->get_host(); -} - -unsigned EFM_PROXY::get_port() { - return next_proxy->get_port(); -} - -unsigned long EFM_PROXY::get_max_packet() const { - return next_proxy->get_max_packet(); -} - -unsigned long EFM_PROXY::get_server_capabilities() const { - return next_proxy->get_server_capabilities(); -} - -unsigned EFM_PROXY::get_server_status() const { - return next_proxy->get_server_status(); -} diff --git a/driver/efm_proxy.h b/driver/efm_proxy.h index a2168d78f..4cdba86ad 100644 --- a/driver/efm_proxy.h +++ b/driver/efm_proxy.h @@ -30,34 +30,17 @@ #ifndef __EFM_PROXY__ #define __EFM_PROXY__ -#include - +#include "connection_proxy.h" +#include "driver.h" #include "monitor_service.h" -#include "mysql_proxy.h" -class EFM_PROXY : public MYSQL_PROXY { +class EFM_PROXY : public CONNECTION_PROXY { public: EFM_PROXY(DBC* dbc, DataSource* ds); - EFM_PROXY(DBC* dbc, DataSource* ds, MYSQL_PROXY* next_proxy); - EFM_PROXY(DBC* dbc, DataSource* ds, MYSQL_PROXY* next_proxy, std::shared_ptr monitor_service); - - void delete_ds() override; - uint64_t num_rows(MYSQL_RES* res) override; - unsigned int num_fields(MYSQL_RES* res) override; - MYSQL_FIELD* fetch_field_direct(MYSQL_RES* res, unsigned int fieldnr) override; - MYSQL_ROW_OFFSET row_tell(MYSQL_RES* res) override; + EFM_PROXY(DBC* dbc, DataSource* ds, CONNECTION_PROXY* next_proxy); + EFM_PROXY(DBC* dbc, DataSource* ds, CONNECTION_PROXY* next_proxy, std::shared_ptr monitor_service); - unsigned int field_count() override; - uint64_t affected_rows() override; - unsigned int error_code() override; - const char* error() override; - const char* sqlstate() override; - unsigned long thread_id() override; int set_character_set(const char* csname) override; - - void init() override; - bool ssl_set(const char* key, const char* cert, const char* ca, - const char* capath, const char* cipher) override; bool change_user(const char* user, const char* passwd, const char* db) override; bool real_connect(const char* host, const char* user, @@ -68,22 +51,8 @@ class EFM_PROXY : public MYSQL_PROXY { int real_query(const char* q, unsigned long length) override; MYSQL_RES* store_result() override; MYSQL_RES* use_result() override; - struct CHARSET_INFO* get_character_set() const override; - void get_character_set_info(MY_CHARSET_INFO* charset) override; - - int ping() override; - int options(enum mysql_option option, const void* arg) override; - int options4(enum mysql_option option, const void* arg1, - const void* arg2) override; - int get_option(enum mysql_option option, const void* arg) override; void free_result(MYSQL_RES* result) override; - void data_seek(MYSQL_RES* result, uint64_t offset) override; - MYSQL_ROW_OFFSET row_seek(MYSQL_RES* result, MYSQL_ROW_OFFSET offset) override; - MYSQL_FIELD_OFFSET field_seek(MYSQL_RES* result, MYSQL_FIELD_OFFSET offset) override; MYSQL_ROW fetch_row(MYSQL_RES* result) override; - - unsigned long* fetch_lengths(MYSQL_RES* result) override; - MYSQL_FIELD* fetch_field(MYSQL_RES* result) override; MYSQL_RES* list_fields(const char* table, const char* wild) override; unsigned long real_escape_string(char* to, const char* from, unsigned long length) override; @@ -98,7 +67,6 @@ class EFM_PROXY : public MYSQL_PROXY { int stmt_fetch_column(MYSQL_STMT* stmt, MYSQL_BIND* bind_arg, unsigned int column, unsigned long offset) override; int stmt_store_result(MYSQL_STMT* stmt) override; - unsigned long stmt_param_count(MYSQL_STMT* stmt) override; bool stmt_bind_param(MYSQL_STMT* stmt, MYSQL_BIND* bnd) override; bool stmt_bind_result(MYSQL_STMT* stmt, MYSQL_BIND* bnd) override; bool stmt_close(MYSQL_STMT* stmt) override; @@ -107,59 +75,14 @@ class EFM_PROXY : public MYSQL_PROXY { bool stmt_send_long_data(MYSQL_STMT* stmt, unsigned int param_number, const char* data, unsigned long length) override; MYSQL_RES* stmt_result_metadata(MYSQL_STMT* stmt) override; - unsigned int stmt_errno(MYSQL_STMT* stmt) override; - const char* stmt_error(MYSQL_STMT* stmt) override; - MYSQL_ROW_OFFSET stmt_row_seek(MYSQL_STMT* stmt, MYSQL_ROW_OFFSET offset) override; - MYSQL_ROW_OFFSET stmt_row_tell(MYSQL_STMT* stmt) override; - void stmt_data_seek(MYSQL_STMT* stmt, uint64_t offset) override; - uint64_t stmt_num_rows(MYSQL_STMT* stmt) override; - uint64_t stmt_affected_rows(MYSQL_STMT* stmt) override; - unsigned int stmt_field_count(MYSQL_STMT* stmt) override; - - bool autocommit(bool auto_mode) override; int next_result() override; int stmt_next_result(MYSQL_STMT* stmt) override; - void close() override; - bool real_connect_dns_srv(const char* dns_srv_name, const char* user, const char* passwd, const char* db, unsigned long client_flag) override; - struct st_mysql_client_plugin* client_find_plugin( - const char* name, int type) override; - - bool is_connected() override; - - void set_last_error_code(unsigned int error_code) override; - - char* get_last_error() const override; - - unsigned int get_last_error_code() const override; - - char* get_sqlstate() const override; - - char* get_server_version() const override; - - uint64_t get_affected_rows() const override; - - void set_affected_rows(uint64_t num_rows) override; - - char* get_host_info() const override; - - std::string get_host() override; - - unsigned int get_port() override; - - unsigned long get_max_packet() const override; - - unsigned long get_server_capabilities() const override; - - unsigned int get_server_status() const override; - - void set_connection(MYSQL_PROXY* mysql_proxy) override; - - void close_socket() override; - void set_next_proxy(MYSQL_PROXY* next_proxy) override; + void set_connection(CONNECTION_PROXY* connection_proxy) override; + void set_next_proxy(CONNECTION_PROXY* next_proxy) override; private: std::shared_ptr monitor_service = nullptr; diff --git a/driver/error.cc b/driver/error.cc index 46c728220..1b8369978 100644 --- a/driver/error.cc +++ b/driver/error.cc @@ -279,11 +279,11 @@ SQLRETURN set_env_error(ENV *env, myodbc_errid errid, const char *errtext, @type : myodbc3 internal @purpose : sets a myodbc_malloc() failure on a MYSQL* connection */ -void set_mem_error(MYSQL_PROXY* mysql_proxy) +void set_mem_error(CONNECTION_PROXY* connection_proxy) { - mysql_proxy->set_last_error_code(CR_OUT_OF_MEMORY); - myodbc_stpmov(mysql_proxy->get_last_error(), "Memory allocation failed"); - myodbc_stpmov(mysql_proxy->get_sqlstate(), "HY001"); + connection_proxy->set_last_error_code(CR_OUT_OF_MEMORY); + myodbc_stpmov(connection_proxy->get_last_error(), "Memory allocation failed"); + myodbc_stpmov(connection_proxy->get_sqlstate(), "HY001"); } @@ -294,7 +294,7 @@ void set_mem_error(MYSQL_PROXY* mysql_proxy) */ SQLRETURN handle_connection_error(STMT *stmt) { - unsigned int err= stmt->dbc->mysql_proxy->error_code(); + unsigned int err= stmt->dbc->connection_proxy->error_code(); switch (err) { case 0: /* no error */ return SQL_SUCCESS; @@ -307,13 +307,13 @@ SQLRETURN handle_connection_error(STMT *stmt) if (stmt->dbc->fh->trigger_failover_if_needed("08S01", error_code, error_msg)) return stmt->set_error(error_code, error_msg, 0); else - return stmt->set_error("08S01", stmt->dbc->mysql_proxy->error(), err); + return stmt->set_error("08S01", stmt->dbc->connection_proxy->error(), err); case CR_OUT_OF_MEMORY: - return stmt->set_error("HY001", stmt->dbc->mysql_proxy->error(), err); + return stmt->set_error("HY001", stmt->dbc->connection_proxy->error(), err); case CR_COMMANDS_OUT_OF_SYNC: case CR_UNKNOWN_ERROR: default: - return stmt->set_error("HY000", stmt->dbc->mysql_proxy->error(), err); + return stmt->set_error("HY000", stmt->dbc->connection_proxy->error(), err); } } @@ -488,7 +488,7 @@ MySQLGetDiagField(SQLSMALLINT handle_type, SQLHANDLE handle, SQLSMALLINT record, if (!stmt->result) *(SQLLEN *)num_value= 0; else - *(SQLLEN *)num_value= (SQLLEN) dbc->mysql_proxy->num_rows(stmt->result); + *(SQLLEN *)num_value= (SQLLEN) dbc->connection_proxy->num_rows(stmt->result); return SQL_SUCCESS; case SQL_DIAG_DYNAMIC_FUNCTION: diff --git a/driver/error.h b/driver/error.h index ad244f056..da61864ea 100644 --- a/driver/error.h +++ b/driver/error.h @@ -42,7 +42,7 @@ #ifndef __ERROR_H__ #define __ERROR_H__ -#include "mysql_proxy.h" +#include "connection_proxy.h" /* Including driver version definitions */ #include "../MYODBC_CONF.h" @@ -197,9 +197,9 @@ struct MYERROR sqlstate.clear(); } - MYERROR(const char* state, MYSQL_PROXY* mysql_proxy) : - MYERROR(state, mysql_proxy->error(), - mysql_proxy->error_code(), MYODBC_ERROR_PREFIX) + MYERROR(const char* state, CONNECTION_PROXY* connection_proxy) : + MYERROR(state, connection_proxy->error(), + connection_proxy->error_code(), MYODBC_ERROR_PREFIX) {} MYERROR(const char* state, std::string errmsg) : diff --git a/driver/execute.cc b/driver/execute.cc index ea5af4970..198c8452c 100644 --- a/driver/execute.cc +++ b/driver/execute.cc @@ -87,11 +87,11 @@ SQLRETURN do_query(STMT *stmt, char *query, SQLULEN query_length) if ( !is_server_alive( stmt->dbc ) ) { stmt->set_error("08S01" /* "HYT00" */, - stmt->dbc->mysql_proxy->error(), - stmt->dbc->mysql_proxy->error_code()); + stmt->dbc->connection_proxy->error(), + stmt->dbc->connection_proxy->error_code()); translate_error((char*)stmt->error.sqlstate.c_str(), MYERR_08S01 /* S1000 */, - stmt->dbc->mysql_proxy->error_code()); + stmt->dbc->connection_proxy->error_code()); goto exit; } @@ -135,21 +135,21 @@ SQLRETURN do_query(STMT *stmt, char *query, SQLULEN query_length) { native_error = 0; if (stmt->param_bind.size() && stmt->param_count) - native_error = stmt->dbc->mysql_proxy->stmt_bind_param(stmt->ssps, &stmt->param_bind[0]); + native_error = stmt->dbc->connection_proxy->stmt_bind_param(stmt->ssps, &stmt->param_bind[0]); if (native_error == 0) { - native_error = stmt->dbc->mysql_proxy->stmt_execute(stmt->ssps); + native_error = stmt->dbc->connection_proxy->stmt_execute(stmt->ssps); } else { stmt->set_error("HY000", - stmt->dbc->mysql_proxy->stmt_error(stmt->ssps), - stmt->dbc->mysql_proxy->stmt_errno(stmt->ssps)); + stmt->dbc->connection_proxy->stmt_error(stmt->ssps), + stmt->dbc->connection_proxy->stmt_errno(stmt->ssps)); /* For some errors - translating to more appropriate status */ translate_error((char*)stmt->error.sqlstate.c_str(), MYERR_S1000, - stmt->dbc->mysql_proxy->stmt_errno(stmt->ssps)); + stmt->dbc->connection_proxy->stmt_errno(stmt->ssps)); goto exit; } MYLOG_STMT_TRACE(stmt, "ssps has been executed"); @@ -199,10 +199,10 @@ SQLRETURN do_query(STMT *stmt, char *query, SQLULEN query_length) if (native_error) { - const auto error_code = stmt->dbc->mysql_proxy->error_code(); + const auto error_code = stmt->dbc->connection_proxy->error_code(); if (error_code) { - MYLOG_STMT_TRACE(stmt, stmt->dbc->mysql_proxy->error()); + MYLOG_STMT_TRACE(stmt, stmt->dbc->connection_proxy->error()); stmt->set_error("HY000"); // For some errors - translating to more appropriate status @@ -579,7 +579,7 @@ SQLRETURN convert_c_type2str(STMT *stmt, SQLSMALLINT ctype, DESCREC *iprec, if (has_utf8_maxlen4 && - !is_minimum_version(stmt->dbc->mysql_proxy->get_server_version(), "5.5.3")) + !is_minimum_version(stmt->dbc->connection_proxy->get_server_version(), "5.5.3")) { return stmt->set_error("HY000", "Server does not support 4-byte encoded " @@ -1289,7 +1289,7 @@ SQLRETURN insert_param(STMT *stmt, MYSQL_BIND *bind, DESC* apd, goto memerror; } - size_t added = dbc->mysql_proxy->real_escape_string(stmt->endbuf(), data, length); + size_t added = dbc->connection_proxy->real_escape_string(stmt->endbuf(), data, length); stmt->buf_add_pos(added); stmt->add_to_buffer("'", 1); } @@ -1796,7 +1796,7 @@ static SQLRETURN find_next_out_stream(STMT *stmt, SQLPOINTER *token) else { /* Magical out params fetch */ - stmt->dbc->mysql_proxy->stmt_fetch(stmt->ssps); + stmt->dbc->connection_proxy->stmt_fetch(stmt->ssps); stmt->out_params_state = OPS_PREFETCHED; return SQL_SUCCESS; @@ -1840,14 +1840,14 @@ SQLRETURN SQL_API SQLParamData(SQLHSTMT hstmt, SQLPOINTER *prbgValue) if (stmt->send_data_param > 0) { - if (stmt->dbc->mysql_proxy->stmt_bind_param(stmt->ssps, (MYSQL_BIND*)stmt->param_bind->buffer)) + if (stmt->dbc->connection_proxy->stmt_bind_param(stmt->ssps, (MYSQL_BIND*)stmt->param_bind->buffer)) { - stmt->set_error("HY000", stmt->dbc->mysql_proxy->stmt_error(stmt->ssps), - stmt->dbc->mysql_proxy->stmt_errno(stmt->ssps)); + stmt->set_error("HY000", stmt->dbc->connection_proxy->stmt_error(stmt->ssps), + stmt->dbc->connection_proxy->stmt_errno(stmt->ssps)); /* For some errors - translating to more appropriate status */ translate_error(stmt->error.sqlstate, MYERR_S1000, - stmt->dbc->mysql_proxy->stmt_errno(stmt->ssps)); + stmt->dbc->connection_proxy->stmt_errno(stmt->ssps)); return SQL_ERROR; } @@ -1980,7 +1980,7 @@ SQLRETURN SQL_API SQLCancel(SQLHSTMT hstmt) { char buff[40]; /* buff is always big enough because max length of %lu is 15 */ - snprintf(buff, sizeof(buff), "KILL /*!50000 QUERY */ %lu", dbc->mysql_proxy->thread_id()); + snprintf(buff, sizeof(buff), "KILL /*!50000 QUERY */ %lu", dbc->connection_proxy->thread_id()); if (mysql_real_query(second, buff, strlen(buff))) { mysql_close(second); diff --git a/driver/failover.h b/driver/failover.h index cae82c4f1..032a02b56 100644 --- a/driver/failover.h +++ b/driver/failover.h @@ -31,25 +31,22 @@ #define __FAILOVER_H__ #include "connection_handler.h" +#include "connection_proxy.h" #include "topology_service.h" #include "mylog.h" #include -struct DBC; -struct DataSource; -typedef short SQLRETURN; - struct READER_FAILOVER_RESULT { bool connected = false; std::shared_ptr new_host; - MYSQL_PROXY* new_connection; + CONNECTION_PROXY* new_connection; READER_FAILOVER_RESULT() : connected{false}, new_host{nullptr}, new_connection{nullptr} {} READER_FAILOVER_RESULT(bool connected, std::shared_ptr new_host, - MYSQL_PROXY* new_connection) + CONNECTION_PROXY* new_connection) : connected{connected}, new_host{new_host}, new_connection{new_connection} {} @@ -113,7 +110,7 @@ struct WRITER_FAILOVER_RESULT { bool is_new_host = false; // True if process connected to a new host. False if // process re-connected to the same host std::shared_ptr new_topology; - MYSQL_PROXY* new_connection; + CONNECTION_PROXY* new_connection; WRITER_FAILOVER_RESULT() : connected{false}, @@ -123,7 +120,7 @@ struct WRITER_FAILOVER_RESULT { WRITER_FAILOVER_RESULT(bool connected, bool is_new_host, std::shared_ptr new_topology, - MYSQL_PROXY* new_connection) + CONNECTION_PROXY* new_connection) : connected{connected}, is_new_host{is_new_host}, new_topology{new_topology}, @@ -228,7 +225,7 @@ class FAILOVER { void release_new_connection(); std::shared_ptr connection_handler; std::shared_ptr topology_service; - MYSQL_PROXY* new_connection; + CONNECTION_PROXY* new_connection; std::shared_ptr logger = nullptr; unsigned long dbc_id = 0; }; @@ -288,7 +285,7 @@ class WAIT_NEW_WRITER_HANDLER : public FAILOVER { int read_topology_interval_ms = 5000; std::shared_ptr reader_handler; std::shared_ptr current_topology; - MYSQL_PROXY* reader_connection = nullptr; // To retrieve latest topology + CONNECTION_PROXY* reader_connection = nullptr; // To retrieve latest topology std::shared_ptr current_reader_host; void refresh_topology_and_connect_to_new_writer( diff --git a/driver/failover_handler.cc b/driver/failover_handler.cc index 467f64ff5..74924bdc9 100644 --- a/driver/failover_handler.cc +++ b/driver/failover_handler.cc @@ -368,7 +368,7 @@ SQLRETURN FAILOVER_HANDLER::create_connection_and_initialize_topology() { } metrics_container->register_invalid_initial_connection(false); - current_topology = topology_service->get_topology(dbc->mysql_proxy, false); + current_topology = topology_service->get_topology(dbc->connection_proxy, false); if (current_topology) { m_is_multi_writer_cluster = current_topology->is_multi_writer_cluster; m_is_cluster_topology_available = current_topology->total_hosts() > 0; @@ -393,7 +393,7 @@ SQLRETURN FAILOVER_HANDLER::create_connection_and_initialize_topology() { } SQLRETURN FAILOVER_HANDLER::reconnect(bool failover_enabled) { - if (dbc->mysql_proxy != nullptr && dbc->mysql_proxy->is_connected()) { + if (dbc->connection_proxy != nullptr && dbc->connection_proxy->is_connected()) { dbc->close(); } return connection_handler->do_connect(dbc, ds, failover_enabled); diff --git a/driver/failover_reader_handler.cc b/driver/failover_reader_handler.cc index 99eafbf5c..cf9ebbf36 100644 --- a/driver/failover_reader_handler.cc +++ b/driver/failover_reader_handler.cc @@ -27,7 +27,7 @@ // along with this program. If not, see // http://www.gnu.org/licenses/gpl-2.0.html. -#include "failover.h" +#include "driver.h" #include #include diff --git a/driver/failover_writer_handler.cc b/driver/failover_writer_handler.cc index 33f718ba6..0baa81e24 100644 --- a/driver/failover_writer_handler.cc +++ b/driver/failover_writer_handler.cc @@ -27,7 +27,7 @@ // along with this program. If not, see // http://www.gnu.org/licenses/gpl-2.0.html. -#include "failover.h" +#include "driver.h" #include #include diff --git a/driver/handle.cc b/driver/handle.cc index d051ae8ab..59b0401df 100644 --- a/driver/handle.cc +++ b/driver/handle.cc @@ -48,6 +48,9 @@ ****************************************************************************/ #include "driver.h" +#include "efm_proxy.h" +#include "mysql_proxy.h" + #include thread_local long thread_count = 0; @@ -74,7 +77,7 @@ bool ENV::has_connections() DBC::DBC(ENV *p_env) : id{last_dbc_id++}, env(p_env), - mysql_proxy(nullptr), + connection_proxy(nullptr), txn_isolation(DEFAULT_TXN_ISOLATION), last_query_time((time_t)time((time_t *)0)) { @@ -108,16 +111,16 @@ void DBC::free_explicit_descriptors() void DBC::close() { - mysql_proxy->close(); + connection_proxy->close(); } // construct a proxy chain, example: iam->efm->mysql void DBC::init_proxy_chain(DataSource* dsrc) { - MYSQL_PROXY *head = new MYSQL_PROXY(this, dsrc); + CONNECTION_PROXY *head = new MYSQL_PROXY(this, dsrc); if (dsrc->enable_failure_detection) { - MYSQL_PROXY* efm_proxy = new EFM_PROXY(this, dsrc); + CONNECTION_PROXY* efm_proxy = new EFM_PROXY(this, dsrc); efm_proxy->set_next_proxy(head); head = efm_proxy; } @@ -125,18 +128,18 @@ void DBC::init_proxy_chain(DataSource* dsrc) ds_get_utf8attr(dsrc->auth_mode, &dsrc->auth_mode8); if (!myodbc_strcasecmp(AUTH_MODE_IAM, reinterpret_cast(dsrc->auth_mode8))) { - // MYSQL_PROXY* iam_proxy = new IAM_PROXY(his, dsrc); + // CONNECTION_PROXY* iam_proxy = new IAM_PROXY(his, dsrc); // iam_proxy->set_next_proxy(head); // head = iam_proxy; } if (!myodbc_strcasecmp(AUTH_MODE_SECRETS_MANAGER, reinterpret_cast(dsrc->auth_mode8))) { - // MYSQL_PROXY* secrets_manager_proxy = new SECRETS_MANAGER_PROXY(his, dsrc); + // CONNECTION_PROXY* secrets_manager_proxy = new SECRETS_MANAGER_PROXY(his, dsrc); // secrets_manager_proxy->set_next_proxy(head); // head = secrets_manager_proxy; } - this->mysql_proxy = head; + this->connection_proxy = head; } DBC::~DBC() @@ -147,8 +150,8 @@ DBC::~DBC() if (ds) ds_delete(ds); - if (mysql_proxy) - delete mysql_proxy; + if (connection_proxy) + delete connection_proxy; if (fh) delete fh; @@ -168,7 +171,7 @@ SQLRETURN DBC::set_error(char * state, const char * message, uint errcode) SQLRETURN DBC::set_error(char * state) { - return set_error(state, mysql_proxy->error(), mysql_proxy->error_code()); + return set_error(state, connection_proxy->error(), connection_proxy->error_code()); } @@ -285,12 +288,12 @@ SQLRETURN SQL_API my_SQLAllocConnect(SQLHENV henv, SQLHDBC *phdbc) ++thread_count; - if (MYSQL_PROXY::get_client_version() < MIN_MYSQL_VERSION) + if (CONNECTION_PROXY::get_client_version() < MIN_MYSQL_VERSION) { char buff[255]; snprintf(buff, sizeof(buff), "Wrong libmysqlclient library version: %ld. MyODBC needs at least version: %ld", - MYSQL_PROXY::get_client_version(), MIN_MYSQL_VERSION); + CONNECTION_PROXY::get_client_version(), MIN_MYSQL_VERSION); return(set_env_error((ENV*)henv, MYERR_S1000, buff, 0)); } @@ -353,7 +356,7 @@ int wakeup_connection(DBC *dbc) { ds_get_utf8attr(ds->pwd1, &ds->pwd18); int fator = 2; - dbc->mysql_proxy->options4(MYSQL_OPT_USER_PASSWORD, + dbc->connection_proxy->options4(MYSQL_OPT_USER_PASSWORD, &fator, ds->pwd18); } @@ -362,7 +365,7 @@ int wakeup_connection(DBC *dbc) { ds_get_utf8attr(ds->pwd2, &ds->pwd28); int fator = 2; - dbc->mysql_proxy->options4(MYSQL_OPT_USER_PASSWORD, + dbc->connection_proxy->options4(MYSQL_OPT_USER_PASSWORD, &fator, ds->pwd28); } @@ -371,13 +374,13 @@ int wakeup_connection(DBC *dbc) { ds_get_utf8attr(ds->pwd3, &ds->pwd38); int fator = 3; - dbc->mysql_proxy->options4(MYSQL_OPT_USER_PASSWORD, + dbc->connection_proxy->options4(MYSQL_OPT_USER_PASSWORD, &fator, ds->pwd38); } #endif - if (dbc->mysql_proxy->change_user(ds_get_utf8attr(ds->uid, &ds->uid8), + if (dbc->connection_proxy->change_user(ds_get_utf8attr(ds->uid, &ds->uid8), ds_get_utf8attr(ds->pwd, &ds->pwd8), ds_get_utf8attr(ds->database, &ds->database8))) { diff --git a/driver/info.cc b/driver/info.cc index 41bc8972e..46d6157c8 100644 --- a/driver/info.cc +++ b/driver/info.cc @@ -135,7 +135,7 @@ MySQLGetInfo(SQLHDBC hdbc, SQLUSMALLINT fInfoType, 0); case SQL_COLLATION_SEQ: - MYINFO_SET_STR(dbc->mysql_proxy->get_character_set()->name); + MYINFO_SET_STR(dbc->connection_proxy->get_character_set()->name); case SQL_COLUMN_ALIAS: MYINFO_SET_STR("Y"); @@ -201,7 +201,7 @@ MySQLGetInfo(SQLHDBC hdbc, SQLUSMALLINT fInfoType, case SQL_CREATE_VIEW: /** @todo SQL_CV_LOCAL ? */ - if (is_minimum_version(dbc->mysql_proxy->get_server_version(), "5.0")) + if (is_minimum_version(dbc->connection_proxy->get_server_version(), "5.0")) MYINFO_SET_ULONG(SQL_CV_CREATE_VIEW | SQL_CV_CHECK_OPTION | SQL_CV_CASCADED); else @@ -228,7 +228,7 @@ MySQLGetInfo(SQLHDBC hdbc, SQLUSMALLINT fInfoType, MYINFO_SET_STR("N"); case SQL_DATABASE_NAME: - if (dbc->mysql_proxy->is_connected() && reget_current_catalog(dbc)) + if (dbc->connection_proxy->is_connected() && reget_current_catalog(dbc)) return dbc->set_error("HY000", "SQLGetInfo() failed to return current catalog.", 0); @@ -243,7 +243,7 @@ MySQLGetInfo(SQLHDBC hdbc, SQLUSMALLINT fInfoType, case SQL_DBMS_VER: /** @todo technically this is not right: should be ##.##.#### */ - MYINFO_SET_STR(dbc->mysql_proxy->get_server_version()); + MYINFO_SET_STR(dbc->connection_proxy->get_server_version()); case SQL_DDL_INDEX: MYINFO_SET_ULONG(SQL_DI_CREATE_INDEX | SQL_DI_DROP_INDEX); @@ -286,7 +286,7 @@ MySQLGetInfo(SQLHDBC hdbc, SQLUSMALLINT fInfoType, MYINFO_SET_ULONG(SQL_DT_DROP_TABLE | SQL_DT_CASCADE | SQL_DT_RESTRICT); case SQL_DROP_VIEW: - if (is_minimum_version(dbc->mysql_proxy->get_server_version(), "5.0")) + if (is_minimum_version(dbc->connection_proxy->get_server_version(), "5.0")) MYINFO_SET_ULONG(SQL_DV_DROP_VIEW | SQL_DV_CASCADE | SQL_DV_RESTRICT); else MYINFO_SET_ULONG(0); @@ -361,7 +361,7 @@ MySQLGetInfo(SQLHDBC hdbc, SQLUSMALLINT fInfoType, We have INFORMATION_SCHEMA.SCHEMATA, but we don't report it because the driver exposes databases (schema) as catalogs. */ - if (is_minimum_version(dbc->mysql_proxy->get_server_version(), "5.1")) + if (is_minimum_version(dbc->connection_proxy->get_server_version(), "5.1")) MYINFO_SET_ULONG(SQL_ISV_CHARACTER_SETS | SQL_ISV_COLLATIONS | SQL_ISV_COLUMN_PRIVILEGES | SQL_ISV_COLUMNS | SQL_ISV_KEY_COLUMN_USAGE | @@ -369,7 +369,7 @@ MySQLGetInfo(SQLHDBC hdbc, SQLUSMALLINT fInfoType, /* SQL_ISV_SCHEMATA | */ SQL_ISV_TABLE_CONSTRAINTS | SQL_ISV_TABLE_PRIVILEGES | SQL_ISV_TABLES | SQL_ISV_VIEWS); - else if (is_minimum_version(dbc->mysql_proxy->get_server_version(), "5.0")) + else if (is_minimum_version(dbc->connection_proxy->get_server_version(), "5.0")) MYINFO_SET_ULONG(SQL_ISV_CHARACTER_SETS | SQL_ISV_COLLATIONS | SQL_ISV_COLUMN_PRIVILEGES | SQL_ISV_COLUMNS | SQL_ISV_KEY_COLUMN_USAGE | /* SQL_ISV_SCHEMATA | */ @@ -395,7 +395,7 @@ MySQLGetInfo(SQLHDBC hdbc, SQLUSMALLINT fInfoType, the MySQL Reference Manual (which is, in turn, generated from the source) with the pre-reserved ODBC keywords removed. */ - if (is_minimum_version(dbc->mysql_proxy->get_server_version(), "8.0.22")) + if (is_minimum_version(dbc->connection_proxy->get_server_version(), "8.0.22")) MYINFO_SET_STR("ACCESSIBLE,ANALYZE,ASENSITIVE,BEFORE,BIGINT,BINARY,BLOB," "CALL,CHANGE,CONDITION,DATABASE,DATABASES,DAY_HOUR," "DAY_MICROSECOND,DAY_MINUTE,DAY_SECOND,DELAYED," @@ -420,7 +420,7 @@ MySQLGetInfo(SQLHDBC hdbc, SQLUSMALLINT fInfoType, "TINYBLOB,TINYINT,TINYTEXT,TRIGGER,UNDO,UNLOCK,UNSIGNED," "USE,UTC_DATE,UTC_TIME,UTC_TIMESTAMP,VARBINARY," "VARCHARACTER,WHILE,X509,XOR,YEAR_MONTH,ZEROFILL"); - else if (is_minimum_version(dbc->mysql_proxy->get_server_version(), "5.7")) + else if (is_minimum_version(dbc->connection_proxy->get_server_version(), "5.7")) MYINFO_SET_STR("ACCESSIBLE,ANALYZE,ASENSITIVE,BEFORE,BIGINT,BINARY,BLOB," "CALL,CHANGE,CONDITION,DATABASE,DATABASES,DAY_HOUR," "DAY_MICROSECOND,DAY_MINUTE,DAY_SECOND,DELAYED," @@ -445,7 +445,7 @@ MySQLGetInfo(SQLHDBC hdbc, SQLUSMALLINT fInfoType, "TINYBLOB,TINYINT,TINYTEXT,TRIGGER,UNDO,UNLOCK,UNSIGNED," "USE,UTC_DATE,UTC_TIME,UTC_TIMESTAMP,VARBINARY," "VARCHARACTER,WHILE,X509,XOR,YEAR_MONTH,ZEROFILL"); - else if (is_minimum_version(dbc->mysql_proxy->get_server_version(), "5.6")) + else if (is_minimum_version(dbc->connection_proxy->get_server_version(), "5.6")) MYINFO_SET_STR("ACCESSIBLE,ANALYZE,ASENSITIVE,BEFORE,BIGINT,BINARY,BLOB," "CALL,CHANGE,CONDITION,DATABASE,DATABASES,DAY_HOUR," "DAY_MICROSECOND,DAY_MINUTE,DAY_SECOND,DELAYED," @@ -470,7 +470,7 @@ MySQLGetInfo(SQLHDBC hdbc, SQLUSMALLINT fInfoType, "TINYBLOB,TINYINT,TINYTEXT,TRIGGER,UNDO,UNLOCK,UNSIGNED," "USE,UTC_DATE,UTC_TIME,UTC_TIMESTAMP,VARBINARY," "VARCHARACTER,WHILE,X509,XOR,YEAR_MONTH,ZEROFILL"); - else if (is_minimum_version(dbc->mysql_proxy->get_server_version(), "5.5")) + else if (is_minimum_version(dbc->connection_proxy->get_server_version(), "5.5")) MYINFO_SET_STR("ACCESSIBLE,ANALYZE,ASENSITIVE,BEFORE,BIGINT,BINARY,BLOB," "CALL,CHANGE,CONDITION,DATABASE,DATABASES,DAY_HOUR," "DAY_MICROSECOND,DAY_MINUTE,DAY_SECOND,DELAYED," @@ -493,7 +493,7 @@ MySQLGetInfo(SQLHDBC hdbc, SQLUSMALLINT fInfoType, "TINYBLOB,TINYINT,TINYTEXT,TRIGGER,UNDO,UNLOCK,UNSIGNED," "USE,UTC_DATE,UTC_TIME,UTC_TIMESTAMP,VARBINARY," "VARCHARACTER,WHILE,X509,XOR,YEAR_MONTH,ZEROFILL"); - else if (is_minimum_version(dbc->mysql_proxy->get_server_version(), "5.1")) + else if (is_minimum_version(dbc->connection_proxy->get_server_version(), "5.1")) MYINFO_SET_STR("ACCESSIBLE,ANALYZE,ASENSITIVE,BEFORE,BIGINT,BINARY,BLOB," "CALL,CHANGE,CONDITION,DATABASE,DATABASES,DAY_HOUR," "DAY_MICROSECOND,DAY_MINUTE,DAY_SECOND,DELAYED," @@ -515,7 +515,7 @@ MySQLGetInfo(SQLHDBC hdbc, SQLUSMALLINT fInfoType, "TINYTEXT,TRIGGER,UNDO,UNLOCK,UNSIGNED,USE,UTC_DATE," "UTC_TIME,UTC_TIMESTAMP,VARBINARY,VARCHARACTER,WHILE,X509," "XOR,YEAR_MONTH,ZEROFILL"); - else if (is_minimum_version(dbc->mysql_proxy->get_server_version(), "5.0")) + else if (is_minimum_version(dbc->connection_proxy->get_server_version(), "5.0")) MYINFO_SET_STR("ANALYZE,ASENSITIVE,BEFORE,BIGINT,BINARY,BLOB,CALL,CHANGE," "CONDITION,DATABASE,DATABASES,DAY_HOUR,DAY_MICROSECOND," "DAY_MINUTE,DAY_SECOND,DELAYED,DETERMINISTIC,DISTINCTROW," @@ -606,7 +606,7 @@ MySQLGetInfo(SQLHDBC hdbc, SQLUSMALLINT fInfoType, MYINFO_SET_USHORT(NAME_LEN); case SQL_MAX_INDEX_SIZE: - if (is_minimum_version(dbc->mysql_proxy->get_server_version(), "5.0")) + if (is_minimum_version(dbc->connection_proxy->get_server_version(), "5.0")) MYINFO_SET_USHORT(3072); else MYINFO_SET_USHORT(1024); @@ -634,7 +634,7 @@ MySQLGetInfo(SQLHDBC hdbc, SQLUSMALLINT fInfoType, MYINFO_SET_USHORT(NAME_LEN); case SQL_MAX_TABLES_IN_SELECT: - if (is_minimum_version(dbc->mysql_proxy->get_server_version(), "5.0")) + if (is_minimum_version(dbc->connection_proxy->get_server_version(), "5.0")) MYINFO_SET_USHORT(63); else MYINFO_SET_USHORT(31); @@ -692,13 +692,13 @@ MySQLGetInfo(SQLHDBC hdbc, SQLUSMALLINT fInfoType, MYINFO_SET_ULONG(SQL_PAS_NO_BATCH); case SQL_PROCEDURE_TERM: - if (is_minimum_version(dbc->mysql_proxy->get_server_version(), "5.0")) + if (is_minimum_version(dbc->connection_proxy->get_server_version(), "5.0")) MYINFO_SET_STR("stored procedure"); else MYINFO_SET_STR(""); case SQL_PROCEDURES: - if (is_minimum_version(dbc->mysql_proxy->get_server_version(), "5.0")) + if (is_minimum_version(dbc->connection_proxy->get_server_version(), "5.0")) MYINFO_SET_STR("Y"); else MYINFO_SET_STR("N"); @@ -737,7 +737,7 @@ MySQLGetInfo(SQLHDBC hdbc, SQLUSMALLINT fInfoType, MYINFO_SET_STR("\\"); case SQL_SERVER_NAME: - MYINFO_SET_STR(dbc->mysql_proxy->get_host_info()); + MYINFO_SET_STR(dbc->connection_proxy->get_host_info()); case SQL_SPECIAL_CHARACTERS: /* We can handle anything but / and \xff. */ diff --git a/driver/monitor.cc b/driver/monitor.cc index 7aa0341e8..eac8cef25 100644 --- a/driver/monitor.cc +++ b/driver/monitor.cc @@ -31,9 +31,9 @@ #include "driver.h" #include "monitor.h" +#include "connection_proxy.h" #include "monitor_service.h" #include "mylog.h" -#include "mysql_proxy.h" MONITOR::MONITOR( std::shared_ptr host_info, @@ -57,7 +57,7 @@ MONITOR::MONITOR( std::chrono::seconds failure_detection_timeout, std::chrono::milliseconds monitor_disposal_time, DataSource* ds, - MYSQL_PROXY* proxy, + CONNECTION_PROXY* proxy, bool enable_logging) { this->host = std::move(host_info); @@ -66,7 +66,7 @@ MONITOR::MONITOR( this->disposal_time = monitor_disposal_time; this->ds = ds_new(); ds_copy(this->ds, ds); - this->mysql_proxy = proxy; + this->connection_proxy = proxy; this->connection_check_interval = (std::chrono::milliseconds::max)(); if (enable_logging) this->logger = init_log_file(); @@ -78,9 +78,9 @@ MONITOR::~MONITOR() { this->ds = nullptr; } - if (this->mysql_proxy) { - delete this->mysql_proxy; - this->mysql_proxy = nullptr; + if (this->connection_proxy) { + delete this->connection_proxy; + this->connection_proxy = nullptr; } } @@ -191,7 +191,7 @@ std::chrono::milliseconds MONITOR::get_connection_check_interval() { } CONNECTION_STATUS MONITOR::check_connection_status() { - if (this->mysql_proxy == nullptr || !this->mysql_proxy->is_connected()) { + if (this->connection_proxy == nullptr || !this->connection_proxy->is_connected()) { const auto start = this->get_current_time(); bool connected = this->connect(); return CONNECTION_STATUS{ @@ -201,7 +201,7 @@ CONNECTION_STATUS MONITOR::check_connection_status() { } auto start = this->get_current_time(); - bool is_connection_active = this->mysql_proxy->ping() == 0; + bool is_connection_active = this->connection_proxy->ping() == 0; auto duration = this->get_current_time() - start; return CONNECTION_STATUS{ @@ -211,9 +211,9 @@ CONNECTION_STATUS MONITOR::check_connection_status() { } bool MONITOR::connect() { - if (this->mysql_proxy) { - this->mysql_proxy->close(); - delete this->mysql_proxy; + if (this->connection_proxy) { + this->connection_proxy->close(); + delete this->connection_proxy; } // Timeout shouldn't be 0 by now, but double check just in case unsigned int timeout_sec = this->failure_detection_timeout.count() == 0 ? failure_detection_timeout_default : this->failure_detection_timeout.count(); @@ -230,12 +230,12 @@ bool MONITOR::connect() { this->ds->enable_cluster_failover = false; this->ds->enable_failure_detection= false; - this->mysql_proxy = this->connection_handler->connect(this->host, this->ds); - if (!this->mysql_proxy) { + this->connection_proxy = this->connection_handler->connect(this->host, this->ds); + if (!this->connection_proxy) { return false; } - return this->mysql_proxy->is_connected(); + return this->connection_proxy->is_connected(); } std::chrono::milliseconds MONITOR::find_shortest_interval() { diff --git a/driver/monitor.h b/driver/monitor.h index e946678fd..7f8095559 100644 --- a/driver/monitor.h +++ b/driver/monitor.h @@ -44,7 +44,7 @@ struct CONNECTION_STATUS { struct DataSource; class MONITOR_SERVICE; -class MYSQL_PROXY; +class CONNECTION_PROXY; namespace { const std::chrono::milliseconds thread_sleep_when_inactive = std::chrono::milliseconds(100); @@ -66,7 +66,7 @@ class MONITOR : public std::enable_shared_from_this { std::chrono::seconds failure_detection_timeout, std::chrono::milliseconds monitor_disposal_time, DataSource* ds, - MYSQL_PROXY* proxy, + CONNECTION_PROXY* proxy, bool enable_logging = false); virtual ~MONITOR(); @@ -86,7 +86,7 @@ class MONITOR : public std::enable_shared_from_this { std::chrono::milliseconds disposal_time; std::list> contexts; std::chrono::steady_clock::time_point last_context_timestamp; - MYSQL_PROXY* mysql_proxy = nullptr; + CONNECTION_PROXY* connection_proxy = nullptr; DataSource* ds = nullptr; std::shared_ptr logger; std::mutex mutex_; diff --git a/driver/monitor_connection_context.cc b/driver/monitor_connection_context.cc index dc458ab94..1fe5e8aeb 100644 --- a/driver/monitor_connection_context.cc +++ b/driver/monitor_connection_context.cc @@ -188,7 +188,7 @@ void MONITOR_CONNECTION_CONTEXT::abort_connection() { if ((!get_connection_to_abort()) || (!is_active_context())) { return; } - connection_to_abort->mysql_proxy->close_socket(); + connection_to_abort->connection_proxy->close_socket(); } std::string MONITOR_CONNECTION_CONTEXT::build_node_keys_str() { diff --git a/driver/my_prepared_stmt.cc b/driver/my_prepared_stmt.cc index 4fe3482e7..db8cdd498 100644 --- a/driver/my_prepared_stmt.cc +++ b/driver/my_prepared_stmt.cc @@ -67,7 +67,7 @@ static char * my_f_to_a(char * buf, size_t buf_size, double a) /* {{{ ssps_init() -I- */ void ssps_init(STMT *stmt) { - stmt->ssps= stmt->dbc->mysql_proxy->stmt_init(); + stmt->ssps= stmt->dbc->connection_proxy->stmt_init(); stmt->result_bind = 0; } @@ -156,7 +156,7 @@ BOOL ssps_get_out_params(STMT *stmt) /* Making bit field look "normally" */ if (stmt->result_bind[counter].buffer_type == MYSQL_TYPE_BIT) { - MYSQL_FIELD *field= stmt->dbc->mysql_proxy->fetch_field_direct(stmt->result, counter); + MYSQL_FIELD *field= stmt->dbc->connection_proxy->fetch_field_direct(stmt->result, counter); unsigned long long numeric; assert(field->type == MYSQL_TYPE_BIT); @@ -249,7 +249,7 @@ BOOL ssps_get_out_params(STMT *stmt) /* This MAGICAL fetch is required. If there are streams - it has to be after streams are all done, perhaps when stmt->out_params_state is changed from OPS_STREAMS_PENDING */ - stmt->dbc->mysql_proxy->stmt_fetch(stmt->ssps); + stmt->dbc->connection_proxy->stmt_fetch(stmt->ssps); } return TRUE; @@ -266,7 +266,7 @@ int ssps_get_result(STMT *stmt) { if (!if_forward_cache(stmt)) { - return stmt->dbc->mysql_proxy->stmt_store_result(stmt->ssps); + return stmt->dbc->connection_proxy->stmt_store_result(stmt->ssps); } else { @@ -347,7 +347,7 @@ void ssps_close(STMT *stmt) It can fail because the connection to the server is lost, which is still ok because the memory is freed anyway. */ - stmt->dbc->mysql_proxy->stmt_close(stmt->ssps); + stmt->dbc->connection_proxy->stmt_close(stmt->ssps); stmt->ssps= NULL; } stmt->buf_set_pos(0); @@ -365,9 +365,9 @@ SQLRETURN ssps_fetch_chunk(STMT *stmt, char *dest, unsigned long dest_bytes, uns bind.is_null= &is_null; bind.error= &error; - if (stmt->dbc->mysql_proxy->stmt_fetch_column(stmt->ssps, &bind, stmt->getdata.column, stmt->getdata.src_offset)) + if (stmt->dbc->connection_proxy->stmt_fetch_column(stmt->ssps, &bind, stmt->getdata.column, stmt->getdata.src_offset)) { - switch (stmt->dbc->mysql_proxy->stmt_errno(stmt->ssps)) + switch (stmt->dbc->connection_proxy->stmt_errno(stmt->ssps)) { case CR_INVALID_PARAMETER_NO: /* Shouldn't really happen here*/ @@ -600,14 +600,14 @@ static MYSQL_ROW fetch_varlength_columns(STMT *stmt, MYSQL_ROW values) } if (reallocated_buffers) - stmt->dbc->mysql_proxy->stmt_fetch_column(stmt->ssps, &stmt->result_bind[i], i, 0); + stmt->dbc->connection_proxy->stmt_fetch_column(stmt->ssps, &stmt->result_bind[i], i, 0); } } // Result buffers must be set again after reallocating if (reallocated_buffers) - stmt->dbc->mysql_proxy->stmt_bind_result(stmt->ssps, stmt->result_bind); + stmt->dbc->connection_proxy->stmt_bind_result(stmt->ssps, stmt->result_bind); fill_ird_data_lengths(stmt->ird, stmt->result_bind[0].length, stmt->result->field_count); @@ -675,7 +675,7 @@ void STMT::free_reset_out_params() if (out_params_state == OPS_STREAMS_PENDING) { /* Magical out params fetch */ - dbc->mysql_proxy->stmt_fetch(ssps); + dbc->connection_proxy->stmt_fetch(ssps); } out_params_state = OPS_UNKNOWN; apd->free_paramdata(); @@ -688,7 +688,7 @@ void STMT::free_reset_params() { if (ssps) { - // dbc->mysql_proxy->stmt_reset(ssps); + // dbc->connection_proxy->stmt_reset(ssps); } /* remove all params and reset count to 0 (per spec) */ /* http://msdn2.microsoft.com/en-us/library/ms709284.aspx */ @@ -736,7 +736,7 @@ STMT::~STMT() if (ssps != NULL) { - dbc->mysql_proxy->stmt_close(ssps); + dbc->connection_proxy->stmt_close(ssps); ssps = NULL; } @@ -767,7 +767,7 @@ SQLRETURN STMT::set_error(myodbc_errid errid, const char *errtext, SQLRETURN STMT::set_error(myodbc_errid errid) { - return set_error(errid, dbc->mysql_proxy->error(), dbc->mysql_proxy->error_code()); + return set_error(errid, dbc->connection_proxy->error(), dbc->connection_proxy->error_code()); } SQLRETURN STMT::set_error(const char *sqlstate, const char *msg, @@ -779,7 +779,7 @@ SQLRETURN STMT::set_error(const char *sqlstate, const char *msg, SQLRETURN STMT::set_error(const char *state) { - return set_error(state, dbc->mysql_proxy->error(), dbc->mysql_proxy->error_code()); + return set_error(state, dbc->connection_proxy->error(), dbc->connection_proxy->error_code()); } @@ -864,7 +864,7 @@ long STMT::compute_cur_row(unsigned fFetchType, SQLLEN irow) case SQL_NO_DATA: throw MYERROR(SQL_NO_DATA_FOUND); case SQL_ERROR: - set_error(MYERR_S1000, dbc->mysql_proxy->error(), 0); + set_error(MYERR_S1000, dbc->connection_proxy->error(), 0); throw error; } } @@ -919,7 +919,7 @@ int STMT::ssps_bind_result() for (i= 0; i < num_fields; ++i) { - MYSQL_FIELD *field= dbc->mysql_proxy->fetch_field_direct(result, i); + MYSQL_FIELD *field= dbc->connection_proxy->fetch_field_direct(result, i); st_buffer_size_type p= allocate_buffer_for_field(field, IS_PS_OUT_PARAMS(this)); @@ -946,10 +946,10 @@ int STMT::ssps_bind_result() } } - int rc = dbc->mysql_proxy->stmt_bind_result(ssps, result_bind); + int rc = dbc->connection_proxy->stmt_bind_result(ssps, result_bind); if (rc) { - set_error("HY000", dbc->mysql_proxy->stmt_error(ssps), 0); + set_error("HY000", dbc->connection_proxy->stmt_error(ssps), 0); } return rc; } @@ -1026,7 +1026,7 @@ SQLRETURN STMT::bind_query_attrs(bool use_ssps) MYSQL_BIND *bind = query_attr_bind.data(); const char** names = (const char**)query_attr_names.data(); - if (dbc->mysql_proxy->bind_param(rcount - param_count, + if (dbc->connection_proxy->bind_param(rcount - param_count, query_attr_bind.data(), (const char**)query_attr_names.data())) { @@ -1401,9 +1401,9 @@ T ssps_get_int64(STMT *stmt, ulong column_number, char *value, ulong length) SQLRETURN ssps_send_long_data(STMT *stmt, unsigned int param_number, const char *chunk, unsigned long length) { - if ( stmt->dbc->mysql_proxy->stmt_send_long_data(stmt->ssps, param_number, chunk, length)) + if ( stmt->dbc->connection_proxy->stmt_send_long_data(stmt->ssps, param_number, chunk, length)) { - uint err = stmt->dbc->mysql_proxy->stmt_errno(stmt->ssps); + uint err = stmt->dbc->connection_proxy->stmt_errno(stmt->ssps); switch (err) { case CR_INVALID_BUFFER_USE: @@ -1414,12 +1414,12 @@ SQLRETURN ssps_send_long_data(STMT *stmt, unsigned int param_number, const char if (stmt->dbc->fh->trigger_failover_if_needed("08S01", error_code, error_msg)) return stmt->set_error(error_code, error_msg, 0); else - return stmt->set_error("08S01", stmt->dbc->mysql_proxy->stmt_error(stmt->ssps), err); + return stmt->set_error("08S01", stmt->dbc->connection_proxy->stmt_error(stmt->ssps), err); case CR_COMMANDS_OUT_OF_SYNC: case CR_UNKNOWN_ERROR: - return stmt->set_error("HY000", stmt->dbc->mysql_proxy->stmt_error(stmt->ssps), err); + return stmt->set_error("HY000", stmt->dbc->connection_proxy->stmt_error(stmt->ssps), err); case CR_OUT_OF_MEMORY: - return stmt->set_error("HY001", stmt->dbc->mysql_proxy->stmt_error(stmt->ssps), err); + return stmt->set_error("HY001", stmt->dbc->connection_proxy->stmt_error(stmt->ssps), err); default: return stmt->set_error("HY000", "unhandled error from mysql_stmt_send_long_data", 0 ); } diff --git a/driver/my_stmt.cc b/driver/my_stmt.cc index 1cb9eb598..65f2cb4c4 100644 --- a/driver/my_stmt.cc +++ b/driver/my_stmt.cc @@ -53,17 +53,17 @@ BOOL returned_result(STMT *stmt) MYSQL_RES *temp_res= NULL; if ((stmt->result != NULL) || - (temp_res= stmt->dbc->mysql_proxy->stmt_result_metadata(stmt->ssps)) != NULL) + (temp_res= stmt->dbc->connection_proxy->stmt_result_metadata(stmt->ssps)) != NULL) { /* mysql_free_result checks for NULL, so we can always call it */ - stmt->dbc->mysql_proxy->free_result(temp_res); + stmt->dbc->connection_proxy->free_result(temp_res); return TRUE; } return FALSE; } else { - return stmt->dbc->mysql_proxy->field_count() > 0; + return stmt->dbc->connection_proxy->field_count() > 0; } } @@ -76,7 +76,7 @@ my_bool free_current_result(STMT *stmt) if (ssps_used(stmt)) { free_result_bind(stmt); - res= stmt->dbc->mysql_proxy->stmt_free_result(stmt->ssps); + res= stmt->dbc->connection_proxy->stmt_free_result(stmt->ssps); } free_internal_result_buffers(stmt); /* We need to always free stmt->result because SSPS keep metadata there */ @@ -95,11 +95,11 @@ static MYSQL_RES* stmt_get_result(STMT *stmt, BOOL force_use) /* We can't use USE_RESULT because SQLRowCount will fail in this case! */ if (if_forward_cache(stmt) || force_use) { - return stmt->dbc->mysql_proxy->use_result(); + return stmt->dbc->connection_proxy->use_result(); } else { - return stmt->dbc->mysql_proxy->store_result(); + return stmt->dbc->connection_proxy->store_result(); } } @@ -110,11 +110,11 @@ MYSQL_RES * get_result_metadata(STMT *stmt, BOOL force_use) { free_internal_result_buffers(stmt); /* just a precaution, mysql_free_result checks for NULL anywat */ - stmt->dbc->mysql_proxy->free_result(stmt->result); + stmt->dbc->connection_proxy->free_result(stmt->result); if (ssps_used(stmt)) { - stmt->result = stmt->dbc->mysql_proxy->stmt_result_metadata(stmt->ssps); + stmt->result = stmt->dbc->connection_proxy->stmt_result_metadata(stmt->ssps); } else { @@ -151,13 +151,13 @@ size_t STMT::field_count() { if (ssps) { - return dbc->mysql_proxy->stmt_field_count(ssps); + return dbc->connection_proxy->stmt_field_count(ssps); } else { return result && result->field_count > 0 ? result->field_count : - dbc->mysql_proxy->field_count(); + dbc->connection_proxy->field_count(); } } @@ -166,12 +166,12 @@ my_ulonglong affected_rows(STMT *stmt) { if (ssps_used(stmt)) { - return stmt->dbc->mysql_proxy->stmt_affected_rows(stmt->ssps); + return stmt->dbc->connection_proxy->stmt_affected_rows(stmt->ssps); } else { /* In some cases in c/odbc it cannot be used instead of mysql_num_rows */ - return stmt->dbc->mysql_proxy->affected_rows(); + return stmt->dbc->connection_proxy->affected_rows(); } } @@ -194,11 +194,11 @@ my_ulonglong num_rows(STMT *stmt) if (ssps_used(stmt)) { - return offset + stmt->dbc->mysql_proxy->stmt_num_rows(stmt->ssps); + return offset + stmt->dbc->connection_proxy->stmt_num_rows(stmt->ssps); } else { - return offset + stmt->dbc->mysql_proxy->num_rows(stmt->result); + return offset + stmt->dbc->connection_proxy->num_rows(stmt->result); } } @@ -216,7 +216,7 @@ MYSQL_ROW STMT::fetch_row(bool read_unbuffered) if (read_unbuffered || m_row_storage.eof()) { /* Reading results from network */ - err = dbc->mysql_proxy->stmt_fetch(ssps); + err = dbc->connection_proxy->stmt_fetch(ssps); } else { @@ -227,8 +227,8 @@ MYSQL_ROW STMT::fetch_row(bool read_unbuffered) switch (err) { case 1: - set_error("HY000", dbc->mysql_proxy->stmt_error(ssps), - dbc->mysql_proxy->stmt_errno(ssps)); + set_error("HY000", dbc->connection_proxy->stmt_error(ssps), + dbc->connection_proxy->stmt_errno(ssps)); throw error; case MYSQL_NO_DATA: return nullptr; @@ -241,7 +241,7 @@ MYSQL_ROW STMT::fetch_row(bool read_unbuffered) } else { - return dbc->mysql_proxy->fetch_row(result); + return dbc->connection_proxy->fetch_row(result); } } @@ -254,7 +254,7 @@ unsigned long* fetch_lengths(STMT *stmt) } else { - return stmt->dbc->mysql_proxy->fetch_lengths(stmt->result); + return stmt->dbc->connection_proxy->fetch_lengths(stmt->result); } } @@ -263,11 +263,11 @@ MYSQL_ROW_OFFSET row_seek(STMT *stmt, MYSQL_ROW_OFFSET offset) { if (ssps_used(stmt)) { - return stmt->dbc->mysql_proxy->stmt_row_seek(stmt->ssps, offset); + return stmt->dbc->connection_proxy->stmt_row_seek(stmt->ssps, offset); } else { - return stmt->dbc->mysql_proxy->row_seek(stmt->result, offset); + return stmt->dbc->connection_proxy->row_seek(stmt->result, offset); } } @@ -276,11 +276,11 @@ void data_seek(STMT *stmt, my_ulonglong offset) { if (ssps_used(stmt)) { - stmt->dbc->mysql_proxy->stmt_data_seek(stmt->ssps, offset); + stmt->dbc->connection_proxy->stmt_data_seek(stmt->ssps, offset); } else { - stmt->dbc->mysql_proxy->data_seek(stmt->result, offset); + stmt->dbc->connection_proxy->data_seek(stmt->result, offset); } } @@ -289,11 +289,11 @@ MYSQL_ROW_OFFSET row_tell(STMT *stmt) { if (ssps_used(stmt)) { - return stmt->dbc->mysql_proxy->stmt_row_tell(stmt->ssps); + return stmt->dbc->connection_proxy->stmt_row_tell(stmt->ssps); } else { - return stmt->dbc->mysql_proxy->row_tell(stmt->result); + return stmt->dbc->connection_proxy->row_tell(stmt->result); } } @@ -304,11 +304,11 @@ int next_result(STMT *stmt) if (ssps_used(stmt)) { - return stmt->dbc->mysql_proxy->stmt_next_result(stmt->ssps); + return stmt->dbc->connection_proxy->stmt_next_result(stmt->ssps); } else { - return stmt->dbc->mysql_proxy->next_result(); + return stmt->dbc->connection_proxy->next_result(); } } @@ -435,7 +435,7 @@ SQLRETURN prepare(STMT *stmt, char * query, SQLINTEGER query_length, actually parameter markers in it */ if (!stmt->dbc->ds->no_ssps && (PARAM_COUNT(stmt->query) || force_prepare) && !IS_BATCH(&stmt->query) - && preparable_on_server(&stmt->query, stmt->dbc->mysql_proxy->get_server_version())) + && preparable_on_server(&stmt->query, stmt->dbc->connection_proxy->get_server_version())) { MYLOG_STMT_TRACE(stmt, "Using prepared statement"); ssps_init(stmt); @@ -449,32 +449,32 @@ SQLRETURN prepare(STMT *stmt, char * query, SQLINTEGER query_length, if (reset_sql_limit) set_sql_select_limit(stmt->dbc, 0, false); - int prep_res = stmt->dbc->mysql_proxy->stmt_prepare(stmt->ssps, query, query_length); + int prep_res = stmt->dbc->connection_proxy->stmt_prepare(stmt->ssps, query, query_length); if (prep_res) { - MYLOG_STMT_TRACE(stmt, stmt->dbc->mysql_proxy->error()); + MYLOG_STMT_TRACE(stmt, stmt->dbc->connection_proxy->error()); stmt->set_error("HY000"); translate_error((char*)stmt->error.sqlstate.c_str(), MYERR_S1000, - stmt->dbc->mysql_proxy->error_code()); + stmt->dbc->connection_proxy->error_code()); return SQL_ERROR; } - stmt->param_count= stmt->dbc->mysql_proxy->stmt_param_count(stmt->ssps); + stmt->param_count= stmt->dbc->connection_proxy->stmt_param_count(stmt->ssps); free_internal_result_buffers(stmt); /* make sure we free the result from the previous time */ if (stmt->result) { - stmt->dbc->mysql_proxy->free_result(stmt->result); + stmt->dbc->connection_proxy->free_result(stmt->result); stmt->result = NULL; } /* Getting result metadata */ stmt->fake_result = false; // reset in case it was set before - if ((stmt->result = stmt->dbc->mysql_proxy->stmt_result_metadata(stmt->ssps))) + if ((stmt->result = stmt->dbc->connection_proxy->stmt_result_metadata(stmt->ssps))) { /*stmt->state= ST_SS_PREPARED;*/ fix_result_types(stmt); diff --git a/driver/mysql_proxy.cc b/driver/mysql_proxy.cc index d3c936af8..042692f8e 100644 --- a/driver/mysql_proxy.cc +++ b/driver/mysql_proxy.cc @@ -27,23 +27,16 @@ // along with this program. If not, see // http://www.gnu.org/licenses/gpl-2.0.html. -#include "driver.h" +#include "mysql_proxy.h" #include +#include namespace { const auto SOCKET_CLOSE_DELAY = std::chrono::milliseconds(100); } -MYSQL_PROXY::MYSQL_PROXY(DBC* dbc, DataSource* ds) : dbc{dbc}, ds{ds} { - if (!this->dbc) { - throw std::runtime_error("DBC cannot be null."); - } - - if (!this->ds) { - throw std::runtime_error("DataSource cannot be null."); - } - +MYSQL_PROXY::MYSQL_PROXY(DBC* dbc, DataSource* ds) : CONNECTION_PROXY(dbc, ds) { this->host = get_host_info_from_ds(ds); } @@ -51,17 +44,6 @@ MYSQL_PROXY::~MYSQL_PROXY() { if (this->mysql) { close(); } - - if (this->next_proxy) { - delete next_proxy; - } -} - -void MYSQL_PROXY::delete_ds() { - if (ds) { - ds_delete(ds); - ds = nullptr; - } } uint64_t MYSQL_PROXY::num_rows(MYSQL_RES* res) { @@ -186,10 +168,6 @@ int MYSQL_PROXY::ping() { return mysql_ping(mysql); } -unsigned long MYSQL_PROXY::get_client_version(void) { - return mysql_get_client_version(); -} - int MYSQL_PROXY::get_option(mysql_option option, const void* arg) { return mysql_get_option(mysql, option, arg); } @@ -291,7 +269,7 @@ bool MYSQL_PROXY::stmt_free_result(MYSQL_STMT* stmt) { } bool MYSQL_PROXY::stmt_send_long_data(MYSQL_STMT* stmt, unsigned int param_number, const char* data, - unsigned long length) { + unsigned long length) { return mysql_stmt_send_long_data(stmt, param_number, data, length); } @@ -392,13 +370,25 @@ unsigned int MYSQL_PROXY::get_server_status() const { return this->mysql->server_status; } -void MYSQL_PROXY::set_connection(MYSQL_PROXY* mysql_proxy) { +void MYSQL_PROXY::delete_ds() { + if (ds) { + ds_delete(ds); + ds = nullptr; + } +} + +MYSQL* MYSQL_PROXY::move_mysql_connection() { + MYSQL* ret = this->mysql; + this->mysql = nullptr; + return ret; +} + +void MYSQL_PROXY::set_connection(CONNECTION_PROXY* connection_proxy) { close(); - this->mysql = mysql_proxy->mysql; - mysql_proxy->mysql = nullptr; + this->mysql = connection_proxy->move_mysql_connection(); // delete the ds initialized in CONNECTION_HANDLER::clone_dbc() - mysql_proxy->delete_ds(); - delete mysql_proxy; + connection_proxy->delete_ds(); + delete connection_proxy; } void MYSQL_PROXY::close_socket() { @@ -413,11 +403,3 @@ void MYSQL_PROXY::close_socket() { MYLOG_DBC_TRACE(dbc, "closesocket() with return code: %d, error message: %s,", ret, strerror(socket_errno)); } } - -void MYSQL_PROXY::set_next_proxy(MYSQL_PROXY* next_proxy) { - if (this->next_proxy) { - throw std::runtime_error("There is already a next proxy present!"); - } - - this->next_proxy = next_proxy; -} diff --git a/driver/mysql_proxy.h b/driver/mysql_proxy.h index 5ec55477d..06df35d92 100644 --- a/driver/mysql_proxy.h +++ b/driver/mysql_proxy.h @@ -30,138 +30,135 @@ #ifndef __MYSQL_PROXY__ #define __MYSQL_PROXY__ -#include - +#include "connection_proxy.h" +#include "driver.h" #include "host_info.h" -struct DBC; -struct DataSource; - -class MYSQL_PROXY { +class MYSQL_PROXY : public CONNECTION_PROXY { public: MYSQL_PROXY(DBC* dbc, DataSource* ds); - virtual ~MYSQL_PROXY(); - - virtual void delete_ds(); - virtual uint64_t num_rows(MYSQL_RES* res); - virtual unsigned int num_fields(MYSQL_RES* res); - virtual MYSQL_FIELD* fetch_field_direct(MYSQL_RES* res, unsigned int fieldnr); - virtual MYSQL_ROW_OFFSET row_tell(MYSQL_RES* res); - - virtual unsigned int field_count(); - virtual uint64_t affected_rows(); - virtual unsigned int error_code(); - virtual const char* error(); - virtual const char* sqlstate(); - virtual unsigned long thread_id(); - virtual int set_character_set(const char* csname); - - virtual void init(); - virtual bool ssl_set(const char* key, const char* cert, const char* ca, - const char* capath, const char* cipher); - virtual bool change_user(const char* user, const char* passwd, - const char* db); - virtual bool real_connect(const char* host, const char* user, - const char* passwd, const char* db, unsigned int port, - const char* unix_socket, unsigned long clientflag); - virtual int select_db(const char* db); - virtual int query(const char* q); - virtual int real_query(const char* q, unsigned long length); - virtual MYSQL_RES* store_result(); - virtual MYSQL_RES* use_result(); - virtual struct CHARSET_INFO* get_character_set() const; - virtual void get_character_set_info(MY_CHARSET_INFO* charset); - - virtual int ping(); - static unsigned long get_client_version(void); - virtual int options(enum mysql_option option, const void* arg); - virtual int options4(enum mysql_option option, const void* arg1, - const void* arg2); - virtual int get_option(enum mysql_option option, const void* arg); - virtual void free_result(MYSQL_RES* result); - virtual void data_seek(MYSQL_RES* result, uint64_t offset); - virtual MYSQL_ROW_OFFSET row_seek(MYSQL_RES* result, MYSQL_ROW_OFFSET offset); - virtual MYSQL_FIELD_OFFSET field_seek(MYSQL_RES* result, MYSQL_FIELD_OFFSET offset); - virtual MYSQL_ROW fetch_row(MYSQL_RES* result); - - virtual unsigned long* fetch_lengths(MYSQL_RES* result); - virtual MYSQL_FIELD* fetch_field(MYSQL_RES* result); - virtual MYSQL_RES* list_fields(const char* table, const char* wild); - virtual unsigned long real_escape_string(char* to, const char* from, - unsigned long length); - - virtual bool bind_param(unsigned n_params, MYSQL_BIND* binds, - const char** names); - - virtual MYSQL_STMT* stmt_init(); - virtual int stmt_prepare(MYSQL_STMT* stmt, const char* query, unsigned long length); - virtual int stmt_execute(MYSQL_STMT* stmt); - virtual int stmt_fetch(MYSQL_STMT* stmt); - virtual int stmt_fetch_column(MYSQL_STMT* stmt, MYSQL_BIND* bind_arg, - unsigned int column, unsigned long offset); - virtual int stmt_store_result(MYSQL_STMT* stmt); - virtual unsigned long stmt_param_count(MYSQL_STMT* stmt); - virtual bool stmt_bind_param(MYSQL_STMT* stmt, MYSQL_BIND* bnd); - virtual bool stmt_bind_result(MYSQL_STMT* stmt, MYSQL_BIND* bnd); - virtual bool stmt_close(MYSQL_STMT* stmt); - virtual bool stmt_reset(MYSQL_STMT* stmt); - virtual bool stmt_free_result(MYSQL_STMT* stmt); - virtual bool stmt_send_long_data(MYSQL_STMT* stmt, unsigned int param_number, - const char* data, unsigned long length); - virtual MYSQL_RES* stmt_result_metadata(MYSQL_STMT* stmt); - virtual unsigned int stmt_errno(MYSQL_STMT* stmt); - virtual const char* stmt_error(MYSQL_STMT* stmt); - virtual MYSQL_ROW_OFFSET stmt_row_seek(MYSQL_STMT* stmt, MYSQL_ROW_OFFSET offset); - virtual MYSQL_ROW_OFFSET stmt_row_tell(MYSQL_STMT* stmt); - virtual void stmt_data_seek(MYSQL_STMT* stmt, uint64_t offset); - virtual uint64_t stmt_num_rows(MYSQL_STMT* stmt); - virtual uint64_t stmt_affected_rows(MYSQL_STMT* stmt); - virtual unsigned int stmt_field_count(MYSQL_STMT* stmt); - - virtual bool autocommit(bool auto_mode); - virtual int next_result(); - virtual int stmt_next_result(MYSQL_STMT* stmt); - virtual void close(); - - virtual bool real_connect_dns_srv(const char* dns_srv_name, - const char* user, const char* passwd, - const char* db, unsigned long client_flag); - virtual struct st_mysql_client_plugin* client_find_plugin( - const char* name, int type); - - virtual bool is_connected(); - - virtual void set_last_error_code(unsigned int error_code); - - virtual char* get_last_error() const; - - virtual unsigned int get_last_error_code() const; - - virtual char* get_sqlstate() const; - - virtual char* get_server_version() const; - - virtual uint64_t get_affected_rows() const; - - virtual void set_affected_rows(uint64_t num_rows); - - virtual char* get_host_info() const; - - virtual std::string get_host(); - - virtual unsigned int get_port(); - - virtual unsigned long get_max_packet() const; - - virtual unsigned long get_server_capabilities() const; - - virtual unsigned int get_server_status() const; - - virtual void set_connection(MYSQL_PROXY* mysql_proxy); - - virtual void close_socket(); - - virtual void set_next_proxy(MYSQL_PROXY* next_proxy); + ~MYSQL_PROXY() override; + + uint64_t num_rows(MYSQL_RES* res) override; + unsigned int num_fields(MYSQL_RES* res) override; + MYSQL_FIELD* fetch_field_direct(MYSQL_RES* res, unsigned int fieldnr) override; + MYSQL_ROW_OFFSET row_tell(MYSQL_RES* res) override; + + unsigned int field_count() override; + uint64_t affected_rows() override; + unsigned int error_code() override; + const char* error() override; + const char* sqlstate() override; + unsigned long thread_id() override; + int set_character_set(const char* csname) override; + + void init() override; + bool ssl_set(const char* key, const char* cert, const char* ca, + const char* capath, const char* cipher) override; + bool change_user(const char* user, const char* passwd, + const char* db) override; + bool real_connect(const char* host, const char* user, + const char* passwd, const char* db, unsigned int port, + const char* unix_socket, unsigned long clientflag) override; + int select_db(const char* db) override; + int query(const char* q) override; + int real_query(const char* q, unsigned long length) override; + MYSQL_RES* store_result() override; + MYSQL_RES* use_result() override; + struct CHARSET_INFO* get_character_set() const; + void get_character_set_info(MY_CHARSET_INFO* charset) override; + + int ping() override; + int options(enum mysql_option option, const void* arg) override; + int options4(enum mysql_option option, const void* arg1, + const void* arg2) override; + int get_option(enum mysql_option option, const void* arg) override; + void free_result(MYSQL_RES* result) override; + void data_seek(MYSQL_RES* result, uint64_t offset) override; + MYSQL_ROW_OFFSET row_seek(MYSQL_RES* result, MYSQL_ROW_OFFSET offset) override; + MYSQL_FIELD_OFFSET field_seek(MYSQL_RES* result, MYSQL_FIELD_OFFSET offset) override; + MYSQL_ROW fetch_row(MYSQL_RES* result) override; + + unsigned long* fetch_lengths(MYSQL_RES* result) override; + MYSQL_FIELD* fetch_field(MYSQL_RES* result) override; + MYSQL_RES* list_fields(const char* table, const char* wild) override; + unsigned long real_escape_string(char* to, const char* from, + unsigned long length) override; + + bool bind_param(unsigned n_params, MYSQL_BIND* binds, + const char** names) override; + + MYSQL_STMT* stmt_init() override; + int stmt_prepare(MYSQL_STMT* stmt, const char* query, unsigned long length) override; + int stmt_execute(MYSQL_STMT* stmt) override; + int stmt_fetch(MYSQL_STMT* stmt) override; + int stmt_fetch_column(MYSQL_STMT* stmt, MYSQL_BIND* bind_arg, + unsigned int column, unsigned long offset) override; + int stmt_store_result(MYSQL_STMT* stmt) override; + unsigned long stmt_param_count(MYSQL_STMT* stmt) override; + bool stmt_bind_param(MYSQL_STMT* stmt, MYSQL_BIND* bnd) override; + bool stmt_bind_result(MYSQL_STMT* stmt, MYSQL_BIND* bnd) override; + bool stmt_close(MYSQL_STMT* stmt) override; + bool stmt_reset(MYSQL_STMT* stmt) override; + bool stmt_free_result(MYSQL_STMT* stmt) override; + bool stmt_send_long_data(MYSQL_STMT* stmt, unsigned int param_number, + const char* data, unsigned long length) override; + MYSQL_RES* stmt_result_metadata(MYSQL_STMT* stmt) override; + unsigned int stmt_errno(MYSQL_STMT* stmt) override; + const char* stmt_error(MYSQL_STMT* stmt) override; + MYSQL_ROW_OFFSET stmt_row_seek(MYSQL_STMT* stmt, MYSQL_ROW_OFFSET offset) override; + MYSQL_ROW_OFFSET stmt_row_tell(MYSQL_STMT* stmt) override; + void stmt_data_seek(MYSQL_STMT* stmt, uint64_t offset) override; + uint64_t stmt_num_rows(MYSQL_STMT* stmt) override; + uint64_t stmt_affected_rows(MYSQL_STMT* stmt) override; + unsigned int stmt_field_count(MYSQL_STMT* stmt) override; + + bool autocommit(bool auto_mode) override; + int next_result() override; + int stmt_next_result(MYSQL_STMT* stmt) override; + void close() override; + + bool real_connect_dns_srv(const char* dns_srv_name, + const char* user, const char* passwd, + const char* db, unsigned long client_flag) override; + struct st_mysql_client_plugin* client_find_plugin( + const char* name, int type) override; + + bool is_connected() override; + + void set_last_error_code(unsigned int error_code) override; + + char* get_last_error() const; + + unsigned int get_last_error_code() const; + + char* get_sqlstate() const; + + char* get_server_version() const; + + uint64_t get_affected_rows() const; + + void set_affected_rows(uint64_t num_rows) override; + + char* get_host_info() const; + + std::string get_host() override; + + unsigned int get_port() override; + + unsigned long get_max_packet() const; + + unsigned long get_server_capabilities() const; + + unsigned int get_server_status() const; + + void delete_ds() override; + + MYSQL* move_mysql_connection() override; + + void set_connection(CONNECTION_PROXY* connection_proxy) override; + + void close_socket() override; protected: DBC* dbc = nullptr; @@ -173,4 +170,5 @@ class MYSQL_PROXY { std::shared_ptr host = nullptr; }; + #endif /* __MYSQL_PROXY__ */ diff --git a/driver/myutil.h b/driver/myutil.h index 3ece52c6d..6dec2dbc9 100755 --- a/driver/myutil.h +++ b/driver/myutil.h @@ -47,9 +47,9 @@ #define if_forward_cache(st) ((st)->stmt_options.cursor_type == SQL_CURSOR_FORWARD_ONLY && \ (st)->dbc->ds->dont_cache_result) -#define trans_supported(db) ((db)->mysql_proxy->get_server_capabilities() & CLIENT_TRANSACTIONS) -#define autocommit_on(db) ((db)->mysql_proxy->get_server_status() & SERVER_STATUS_AUTOCOMMIT) -#define is_no_backslashes_escape_mode(db) ((db)->mysql_proxy->get_server_status() & SERVER_STATUS_NO_BACKSLASH_ESCAPES) +#define trans_supported(db) ((db)->connection_proxy->get_server_capabilities() & CLIENT_TRANSACTIONS) +#define autocommit_on(db) ((db)->connection_proxy->get_server_status() & SERVER_STATUS_AUTOCOMMIT) +#define is_no_backslashes_escape_mode(db) ((db)->connection_proxy->get_server_status() & SERVER_STATUS_NO_BACKSLASH_ESCAPES) #define reset_ptr(x) {if (x) x= 0;} #define digit(A) ((int) (A - '0')) @@ -182,7 +182,7 @@ SQLRETURN set_desc_error (DESC *desc, char *state, const char *message, uint errcode); SQLRETURN handle_connection_error (STMT *stmt); my_bool is_connection_lost (uint errcode); -void set_mem_error (MYSQL_PROXY *mysql_proxy); +void set_mem_error (CONNECTION_PROXY *connection_proxy); void translate_error (char *save_state, myodbc_errid errid, uint mysql_err); SQLSMALLINT get_sql_data_type_from_str(const char *mysql_type_name); @@ -368,7 +368,7 @@ unsigned long long binary2ull(char* src, uint64 srcLen); void fill_ird_data_lengths (DESC *ird, ulong *lengths, uint fields); /* Functions to work with prepared and regular statements */ -#define IS_PS_OUT_PARAMS(_stmt) ((_stmt)->dbc->mysql_proxy->get_server_status() & SERVER_PS_OUT_PARAMS) +#define IS_PS_OUT_PARAMS(_stmt) ((_stmt)->dbc->connection_proxy->get_server_status() & SERVER_PS_OUT_PARAMS) /* my_stmt.c */ BOOL ssps_used (STMT *stmt); BOOL returned_result (STMT *stmt); @@ -417,7 +417,7 @@ void stmt_result_free(STMT * stmt) x_free(stmt->result); } else - stmt->dbc->mysql_proxy->free_result(stmt->result); + stmt->dbc->connection_proxy->free_result(stmt->result); stmt->result = NULL; } diff --git a/driver/options.cc b/driver/options.cc index 630df4904..f203918e4 100644 --- a/driver/options.cc +++ b/driver/options.cc @@ -272,7 +272,7 @@ MySQLSetConnectAttr(SQLHDBC hdbc, SQLINTEGER Attribute, case SQL_ATTR_AUTOCOMMIT: if (ValuePtr != (SQLPOINTER) SQL_AUTOCOMMIT_ON) { - if (dbc->mysql_proxy == nullptr || !dbc->mysql_proxy->is_connected()) + if (dbc->connection_proxy == nullptr || !dbc->connection_proxy->is_connected()) { dbc->commit_flag= CHECK_AUTOCOMMIT_OFF; return SQL_SUCCESS; @@ -284,7 +284,7 @@ MySQLSetConnectAttr(SQLHDBC hdbc, SQLINTEGER Attribute, if (autocommit_on(dbc)) return dbc->execute_query("SET AUTOCOMMIT=0", SQL_NTS, TRUE); } - else if (dbc->mysql_proxy == nullptr || !dbc->mysql_proxy->is_connected()) + else if (dbc->connection_proxy == nullptr || !dbc->connection_proxy->is_connected()) { dbc->commit_flag= CHECK_AUTOCOMMIT_ON; return SQL_SUCCESS; @@ -296,7 +296,7 @@ MySQLSetConnectAttr(SQLHDBC hdbc, SQLINTEGER Attribute, case SQL_ATTR_LOGIN_TIMEOUT: { /* we can't change timeout values in post connect state */ - if (dbc->mysql_proxy != nullptr && dbc->mysql_proxy->is_connected()) + if (dbc->connection_proxy != nullptr && dbc->connection_proxy->is_connected()) { return dbc->set_error(MYERR_S1011, NULL, 0); } @@ -340,12 +340,12 @@ MySQLSetConnectAttr(SQLHDBC hdbc, SQLINTEGER Attribute, if (!(db= fix_str((char *)ldb, (char *)ValuePtr, StringLengthPtr))) return dbc->set_error(MYERR_S1009,NULL, 0); - if (dbc->mysql_proxy != nullptr && dbc->mysql_proxy->is_connected()) + if (dbc->connection_proxy != nullptr && dbc->connection_proxy->is_connected()) { - if (dbc->mysql_proxy->select_db((char*) db)) + if (dbc->connection_proxy->select_db((char*) db)) { - dbc->set_error(MYERR_S1000, dbc->mysql_proxy->error(), - dbc->mysql_proxy->error_code()); + dbc->set_error(MYERR_S1000, dbc->connection_proxy->error(), + dbc->connection_proxy->error_code()); return SQL_ERROR; } } @@ -376,7 +376,7 @@ MySQLSetConnectAttr(SQLHDBC hdbc, SQLINTEGER Attribute, break; case SQL_ATTR_TXN_ISOLATION: - if (dbc->mysql_proxy == nullptr || !dbc->mysql_proxy->is_connected()) /* no connection yet */ + if (dbc->connection_proxy == nullptr || !dbc->connection_proxy->is_connected()) /* no connection yet */ { dbc->txn_isolation= (SQLINTEGER)(SQLLEN)ValuePtr; return SQL_SUCCESS; @@ -496,8 +496,8 @@ MySQLGetConnectAttr(SQLHDBC hdbc, SQLINTEGER attrib, SQLCHAR **char_attr, case SQL_ATTR_CONNECTION_DEAD: /* If waking up fails - we return "connection is dead", no matter what really the reason is */ if (dbc->need_to_wakeup != 0 && wakeup_connection(dbc) - || dbc->need_to_wakeup == 0 && dbc->mysql_proxy->ping() && - is_connection_lost(dbc->mysql_proxy->error_code())) + || dbc->need_to_wakeup == 0 && dbc->connection_proxy->ping() && + is_connection_lost(dbc->connection_proxy->error_code())) *((SQLUINTEGER *)num_attr)= SQL_CD_TRUE; else *((SQLUINTEGER *)num_attr)= SQL_CD_FALSE; @@ -509,7 +509,7 @@ MySQLGetConnectAttr(SQLHDBC hdbc, SQLINTEGER attrib, SQLCHAR **char_attr, break; case SQL_ATTR_CURRENT_CATALOG: - if (dbc->mysql_proxy != nullptr && dbc->mysql_proxy->is_connected()) { + if (dbc->connection_proxy != nullptr && dbc->connection_proxy->is_connected()) { if (reget_current_catalog(dbc)) { return set_handle_error(SQL_HANDLE_DBC, hdbc, MYERR_S1000, @@ -540,7 +540,7 @@ MySQLGetConnectAttr(SQLHDBC hdbc, SQLINTEGER attrib, SQLCHAR **char_attr, break; case SQL_ATTR_PACKET_SIZE: - *((SQLUINTEGER*)num_attr) = dbc->mysql_proxy->get_max_packet(); + *((SQLUINTEGER*)num_attr) = dbc->connection_proxy->get_max_packet(); break; case SQL_ATTR_TXN_ISOLATION: @@ -554,13 +554,13 @@ MySQLGetConnectAttr(SQLHDBC hdbc, SQLINTEGER attrib, SQLCHAR **char_attr, Unless we're not connected yet, then we just assume it will be REPEATABLE READ, which is the server default. */ - if (dbc->mysql_proxy == nullptr || !dbc->mysql_proxy->is_connected()) + if (dbc->connection_proxy == nullptr || !dbc->connection_proxy->is_connected()) { *((SQLINTEGER *)num_attr)= SQL_TRANSACTION_REPEATABLE_READ; break; } - if (is_minimum_version(dbc->mysql_proxy->get_server_version(), "8.0")) + if (is_minimum_version(dbc->connection_proxy->get_server_version(), "8.0")) result = dbc->execute_query("SELECT @@transaction_isolation", SQL_NTS, true); else result = dbc->execute_query("SELECT @@tx_isolation", SQL_NTS, true); @@ -575,8 +575,8 @@ MySQLGetConnectAttr(SQLHDBC hdbc, SQLINTEGER attrib, SQLCHAR **char_attr, MYSQL_RES *res; MYSQL_ROW row; - if ((res= dbc->mysql_proxy->store_result()) && - (row = dbc->mysql_proxy->fetch_row(res))) + if ((res= dbc->connection_proxy->store_result()) && + (row = dbc->connection_proxy->fetch_row(res))) { if (strncmp(row[0], "READ-UNCOMMITTED", 16) == 0) { dbc->txn_isolation= SQL_TRANSACTION_READ_UNCOMMITTED; @@ -591,7 +591,7 @@ MySQLGetConnectAttr(SQLHDBC hdbc, SQLINTEGER attrib, SQLCHAR **char_attr, dbc->txn_isolation= SQL_TRANSACTION_SERIALIZABLE; } } - dbc->mysql_proxy->free_result(res); + dbc->connection_proxy->free_result(res); } } diff --git a/driver/results.cc b/driver/results.cc index df440a868..b37f89799 100755 --- a/driver/results.cc +++ b/driver/results.cc @@ -382,7 +382,7 @@ sql_get_data(STMT *stmt, SQLSMALLINT fCType, uint column_number, SQLPOINTER rgbValue, SQLLEN cbValueMax, SQLLEN *pcbValue, char *value, ulong length, DESCREC *arrec) { - MYSQL_FIELD *field= stmt->dbc->mysql_proxy->fetch_field_direct(stmt->result, column_number); + MYSQL_FIELD *field= stmt->dbc->connection_proxy->fetch_field_direct(stmt->result, column_number); SQLLEN temp; long long numeric_value = 0; unsigned long long u_numeric_value = 0; @@ -1607,7 +1607,7 @@ SQLRETURN SQL_API SQLMoreResults( SQLHSTMT hstmt ) /* call to next_result() failed */ if (nRetVal > 0) { - nRetVal= stmt->dbc->mysql_proxy->error_code(); + nRetVal= stmt->dbc->connection_proxy->error_code(); switch ( nRetVal ) { @@ -1620,7 +1620,7 @@ SQLRETURN SQL_API SQLMoreResults( SQLHSTMT hstmt ) if (stmt->dbc->fh->trigger_failover_if_needed("08S01", error_code, error_msg)) nReturn = stmt->set_error(error_code, error_msg, 0); else - nReturn = stmt->set_error(error_code, stmt->dbc->mysql_proxy->error(), nRetVal); + nReturn = stmt->set_error(error_code, stmt->dbc->connection_proxy->error(), nRetVal); goto exitSQLMoreResults; case CR_COMMANDS_OUT_OF_SYNC: case CR_UNKNOWN_ERROR: @@ -2039,7 +2039,7 @@ SQLRETURN SQL_API myodbc_single_fetch( SQLHSTMT hstmt, stmt->set_error("01S07", "One or more row has error.", 0); return SQL_SUCCESS_WITH_INFO; //SQL_NO_DATA_FOUND case SQL_ERROR: return stmt->set_error(MYERR_S1000, - stmt->dbc->mysql_proxy->error(), 0); + stmt->dbc->connection_proxy->error(), 0); } } else @@ -2183,7 +2183,7 @@ SQLRETURN SQL_API myodbc_single_fetch( SQLHSTMT hstmt, stmt->rows_found_in_set= 1; *pcrow= cur_row; - disconnected= is_connection_lost(stmt->dbc->mysql_proxy->error_code()) + disconnected= is_connection_lost(stmt->dbc->connection_proxy->error_code()) && handle_connection_error(stmt); if ( upd_status && stmt->ird->rows_processed_ptr ) @@ -2273,7 +2273,7 @@ SQLRETURN SQL_API my_SQLExtendedFetch( SQLHSTMT hstmt, return SQL_NO_DATA_FOUND; case OPS_STREAMS_PENDING: /* Magical out params fetch */ - stmt->dbc->mysql_proxy->stmt_fetch(stmt->ssps); + stmt->dbc->connection_proxy->stmt_fetch(stmt->ssps); default: /* TODO: Need to remember real fetch' result */ /* just in case... */ @@ -2468,7 +2468,7 @@ SQLRETURN SQL_API my_SQLExtendedFetch( SQLHSTMT hstmt, stmt->rows_found_in_set= i; *pcrow= i; - disconnected= is_connection_lost(stmt->dbc->mysql_proxy->error_code()) + disconnected= is_connection_lost(stmt->dbc->connection_proxy->error_code()) && handle_connection_error(stmt); if ( upd_status && stmt->ird->rows_processed_ptr ) diff --git a/driver/topology_service.cc b/driver/topology_service.cc index 2d81f0ea0..a92632d3e 100644 --- a/driver/topology_service.cc +++ b/driver/topology_service.cc @@ -167,7 +167,7 @@ std::shared_ptr TOPOLOGY_SERVICE::get_cached_topology() { //TODO consider the return value //Note to determine whether or not force_update succeeded one would compare // CLUSTER_TOPOLOGY_INFO->time_last_updated() prior and after the call if non-null information was given prior. -std::shared_ptr TOPOLOGY_SERVICE::get_topology(MYSQL_PROXY* connection, bool force_update) +std::shared_ptr TOPOLOGY_SERVICE::get_topology(CONNECTION_PROXY* connection, bool force_update) { //TODO reconsider using this cache. It appears that we only store information for the current cluster Id. // therefore instead of a map we can just keep CLUSTER_TOPOLOGY_INFO* topology_info member variable. @@ -219,9 +219,9 @@ void TOPOLOGY_SERVICE::put_to_cache(std::shared_ptr topol lock.unlock(); } -MYSQL_RES* TOPOLOGY_SERVICE::try_execute_query(MYSQL_PROXY* mysql_proxy, const char* query) { - if (mysql_proxy != nullptr && mysql_proxy->query(query) == 0) { - return mysql_proxy->store_result(); +MYSQL_RES* TOPOLOGY_SERVICE::try_execute_query(CONNECTION_PROXY* connection_proxy, const char* query) { + if (connection_proxy != nullptr && connection_proxy->query(query) == 0) { + return connection_proxy->store_result(); } return nullptr; @@ -270,17 +270,17 @@ std::shared_ptr TOPOLOGY_SERVICE::create_host(MYSQL_ROW& row) { } // If no host information retrieved return NULL -std::shared_ptr TOPOLOGY_SERVICE::query_for_topology(MYSQL_PROXY* mysql_proxy) { +std::shared_ptr TOPOLOGY_SERVICE::query_for_topology(CONNECTION_PROXY* connection_proxy) { std::shared_ptr topology_info = nullptr; std::chrono::steady_clock::time_point start_time_ms = std::chrono::steady_clock::now(); - if (MYSQL_RES* result = try_execute_query(mysql_proxy, RETRIEVE_TOPOLOGY_SQL)) { + if (MYSQL_RES* result = try_execute_query(connection_proxy, RETRIEVE_TOPOLOGY_SQL)) { topology_info = std::make_shared(); std::map> instances; MYSQL_ROW row; int writer_count = 0; - while ((row = mysql_proxy->fetch_row(result))) { + while ((row = connection_proxy->fetch_row(result))) { std::shared_ptr host_info = create_host(row); if (host_info) { // Only mark the first/latest writer as true writer @@ -296,7 +296,7 @@ std::shared_ptr TOPOLOGY_SERVICE::query_for_topology(MYSQ } } } - mysql_proxy->free_result(result); + connection_proxy->free_result(result); topology_info->is_multi_writer_cluster = writer_count > 1; if (writer_count == 0) { diff --git a/driver/topology_service.h b/driver/topology_service.h index cf5dfd8dd..60f4b6d4d 100644 --- a/driver/topology_service.h +++ b/driver/topology_service.h @@ -30,15 +30,18 @@ #ifndef __TOPOLOGYSERVICE_H__ #define __TOPOLOGYSERVICE_H__ +#include "MYODBC_MYSQL.h" + #include "cluster_aware_metrics_container.h" #include "cluster_topology_info.h" -#include "mysql_proxy.h" +#include "connection_proxy.h" #include #include #include #include + // TODO - consider - do we really need miliseconds for refresh? - the default numbers here are already 30 seconds.000; #define DEFAULT_REFRESH_RATE_IN_MILLISECONDS 30000 #define WRITER_SESSION_ID "MASTER_SESSION_ID" @@ -60,7 +63,7 @@ class TOPOLOGY_SERVICE { virtual void set_cluster_instance_template(std::shared_ptr host_template); //is this equivalent to setcluster_instance_host virtual std::shared_ptr get_topology( - MYSQL_PROXY* connection, bool force_update = false); + CONNECTION_PROXY* connection, bool force_update = false); std::shared_ptr get_cached_topology(); std::shared_ptr get_last_used_reader(); @@ -103,7 +106,7 @@ class TOPOLOGY_SERVICE { std::shared_ptr metrics_container; bool refresh_needed(std::time_t last_updated); - std::shared_ptr query_for_topology(MYSQL_PROXY* connection); + std::shared_ptr query_for_topology(CONNECTION_PROXY* connection); std::shared_ptr create_host(MYSQL_ROW& row); std::string get_host_endpoint(const char* node_name); static bool does_instance_exist( @@ -113,7 +116,7 @@ class TOPOLOGY_SERVICE { std::shared_ptr get_from_cache(); void put_to_cache(std::shared_ptr topology_info); - MYSQL_RES* try_execute_query(MYSQL_PROXY* mysql_proxy, const char* query); + MYSQL_RES* try_execute_query(CONNECTION_PROXY* connection_proxy, const char* query); }; #endif /* __TOPOLOGYSERVICE_H__ */ diff --git a/driver/unicode.cc b/driver/unicode.cc index cfd8ef126..11039e698 100644 --- a/driver/unicode.cc +++ b/driver/unicode.cc @@ -287,7 +287,7 @@ SQLDescribeColW(SQLHSTMT hstmt, SQLUSMALLINT column, if (free_value == -1) { - set_mem_error(stmt->dbc->mysql_proxy); + set_mem_error(stmt->dbc->connection_proxy); return handle_connection_error(stmt); } @@ -299,7 +299,7 @@ SQLDescribeColW(SQLHSTMT hstmt, SQLUSMALLINT column, { if (free_value) x_free(value); - set_mem_error(stmt->dbc->mysql_proxy); + set_mem_error(stmt->dbc->connection_proxy); return handle_connection_error(stmt); } @@ -1030,7 +1030,7 @@ SQLSetConnectAttrWImpl(SQLHDBC hdbc, SQLINTEGER attribute, "than 0 but was not SQL_NTS " , 0); } - if (dbc->mysql_proxy != nullptr && dbc->mysql_proxy->is_connected()) + if (dbc->connection_proxy != nullptr && dbc->connection_proxy->is_connected()) value= sqlwchar_as_sqlchar(dbc->cxn_charset_info, (SQLWCHAR*)value, &len, &errors); else diff --git a/driver/utility.cc b/driver/utility.cc index eed9fa638..ad26305f1 100755 --- a/driver/utility.cc +++ b/driver/utility.cc @@ -126,7 +126,7 @@ void fix_row_lengths(STMT *stmt, const long* fix_rules, uint row, uint field_cou return; row_lengths = stmt->lengths.get() + row * field_count; - orig_lengths = stmt->dbc->mysql_proxy->fetch_lengths(stmt->result); + orig_lengths = stmt->dbc->connection_proxy->fetch_lengths(stmt->result); for (i= 0; i < field_count; ++i) { @@ -2457,7 +2457,7 @@ bool is_server_alive( DBC *dbc ) if ( (ulong)(seconds - dbc->last_query_time) >= CHECK_IF_ALIVE ) { - if ( dbc->mysql_proxy->ping() ) + if ( dbc->connection_proxy->ping() ) { /* BUG: 14639 @@ -2474,7 +2474,7 @@ bool is_server_alive( DBC *dbc ) PAH - 9.MAR.06 */ - if (is_connection_lost(dbc->mysql_proxy->error_code())) + if (is_connection_lost(dbc->connection_proxy->error_code())) server_alive = false; } } @@ -2516,8 +2516,8 @@ int reget_current_catalog(DBC *dbc) MYSQL_RES *res; MYSQL_ROW row; - if ( (res= dbc->mysql_proxy->store_result()) && - (row = dbc->mysql_proxy->fetch_row(res))) + if ( (res= dbc->connection_proxy->store_result()) && + (row = dbc->connection_proxy->fetch_row(res))) { /* if (cmp_database(row[0], dbc->database)) */ { @@ -2527,7 +2527,7 @@ int reget_current_catalog(DBC *dbc) } } } - dbc->mysql_proxy->free_result(res); + dbc->connection_proxy->free_result(res); } return 0; @@ -3754,7 +3754,7 @@ void set_row_count(STMT *stmt, my_ulonglong rows) if (stmt != NULL && stmt->result != NULL) { stmt->result->row_count= rows; - stmt->dbc->mysql_proxy->set_affected_rows(rows); + stmt->dbc->connection_proxy->set_affected_rows(rows); } } @@ -4203,19 +4203,19 @@ int get_session_variable(STMT *stmt, const char *var, char *result, size_t resul return 0; } - res = stmt->dbc->mysql_proxy->store_result(); + res = stmt->dbc->connection_proxy->store_result(); if (!res) return 0; - row = stmt->dbc->mysql_proxy->fetch_row(res); + row = stmt->dbc->connection_proxy->fetch_row(res); if (row) { strncpy(result, row[1], result_size); - stmt->dbc->mysql_proxy->free_result(res); + stmt->dbc->connection_proxy->free_result(res); return strlen(result); } - stmt->dbc->mysql_proxy->free_result(res); + stmt->dbc->connection_proxy->free_result(res); } return 0; @@ -4236,7 +4236,7 @@ SQLRETURN set_query_timeout(STMT *stmt, SQLULEN new_value) SQLRETURN rc= SQL_SUCCESS; if (new_value == stmt->stmt_options.query_timeout || - !is_minimum_version(stmt->dbc->mysql_proxy->get_server_version(), "5.7.8")) + !is_minimum_version(stmt->dbc->connection_proxy->get_server_version(), "5.7.8")) { /* Do nothing if setting same timeout or MySQL server older than 5.7.8 */ return SQL_SUCCESS; @@ -4266,7 +4266,7 @@ SQLULEN get_query_timeout(STMT *stmt) { SQLULEN query_timeout= SQL_QUERY_TIMEOUT_DEFAULT; /* 0 */ - if (is_minimum_version(stmt->dbc->mysql_proxy->get_server_version(), "5.7.8")) + if (is_minimum_version(stmt->dbc->connection_proxy->get_server_version(), "5.7.8")) { /* Be cautious with very long values even if they don't make sense */ char query_timeout_char[32]= {0}; @@ -4285,7 +4285,7 @@ const char get_identifier_quote(STMT *stmt) { const char tick= '`', quote= '"', empty= ' '; - if (is_minimum_version(stmt->dbc->mysql_proxy->get_server_version(), "3.23.06")) + if (is_minimum_version(stmt->dbc->connection_proxy->get_server_version(), "3.23.06")) { /* The full list of all SQL modes takes over 512 symbols, so we reserve diff --git a/unit_testing/efm_proxy_test.cc b/unit_testing/efm_proxy_test.cc index ee0412088..ee159d056 100644 --- a/unit_testing/efm_proxy_test.cc +++ b/unit_testing/efm_proxy_test.cc @@ -27,6 +27,8 @@ // along with this program. If not, see // http://www.gnu.org/licenses/gpl-2.0.html. +#include "driver/efm_proxy.h" + #include #include @@ -42,7 +44,7 @@ class EFMProxyTest : public testing::Test { DBC* dbc; DataSource* ds; std::shared_ptr mock_monitor_service; - MOCK_MYSQL_PROXY* mock_mysql_proxy; + MOCK_CONNECTION_PROXY* mock_connection_proxy; static void SetUpTestSuite() {} @@ -57,7 +59,7 @@ class EFMProxyTest : public testing::Test { ds->enable_failure_detection = true; mock_monitor_service = std::make_shared(); - mock_mysql_proxy = new MOCK_MYSQL_PROXY(dbc, ds); + mock_connection_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); } void TearDown() override { @@ -66,13 +68,13 @@ class EFMProxyTest : public testing::Test { }; TEST_F(EFMProxyTest, NullDBC) { - EXPECT_THROW(EFM_PROXY efm_proxy(nullptr, ds, mock_mysql_proxy), std::runtime_error); - delete mock_mysql_proxy; + EXPECT_THROW(EFM_PROXY efm_proxy(nullptr, ds, mock_connection_proxy), std::runtime_error); + delete mock_connection_proxy; } TEST_F(EFMProxyTest, NullDS) { - EXPECT_THROW(EFM_PROXY efm_proxy(dbc, nullptr, mock_mysql_proxy), std::runtime_error); - delete mock_mysql_proxy; + EXPECT_THROW(EFM_PROXY efm_proxy(dbc, nullptr, mock_connection_proxy), std::runtime_error); + delete mock_connection_proxy; } TEST_F(EFMProxyTest, FailureDetectionDisabled) { @@ -80,10 +82,10 @@ TEST_F(EFMProxyTest, FailureDetectionDisabled) { EXPECT_CALL(*mock_monitor_service, start_monitoring(_, _, _, _, _, _, _, _, _)).Times(0); EXPECT_CALL(*mock_monitor_service, stop_monitoring(_)).Times(0); - EXPECT_CALL(*mock_mysql_proxy, init()); - EXPECT_CALL(*mock_mysql_proxy, mock_mysql_proxy_destructor()); + EXPECT_CALL(*mock_connection_proxy, init()); + EXPECT_CALL(*mock_connection_proxy, mock_connection_proxy_destructor()); - EFM_PROXY efm_proxy(dbc, ds, mock_mysql_proxy, mock_monitor_service); + EFM_PROXY efm_proxy(dbc, ds, mock_connection_proxy, mock_monitor_service); efm_proxy.init(); } @@ -94,19 +96,19 @@ TEST_F(EFMProxyTest, FailureDetectionEnabled) { EXPECT_CALL(*mock_monitor_service, start_monitoring(_, _, _, _, _, _, _, _, _)).WillOnce(Return(mock_context)); EXPECT_CALL(*mock_monitor_service, stop_monitoring(mock_context)).Times(1); - EXPECT_CALL(*mock_mysql_proxy, query("")); - EXPECT_CALL(*mock_mysql_proxy, mock_mysql_proxy_destructor()); + EXPECT_CALL(*mock_connection_proxy, query("")); + EXPECT_CALL(*mock_connection_proxy, mock_connection_proxy_destructor()); - EFM_PROXY efm_proxy(dbc, ds, mock_mysql_proxy, mock_monitor_service); + EFM_PROXY efm_proxy(dbc, ds, mock_connection_proxy, mock_monitor_service); efm_proxy.query(""); } TEST_F(EFMProxyTest, DoesNotNeedMonitoring) { EXPECT_CALL(*mock_monitor_service, start_monitoring(_, _, _, _, _, _, _, _, _)).Times(0); EXPECT_CALL(*mock_monitor_service, stop_monitoring(_)).Times(0); - EXPECT_CALL(*mock_mysql_proxy, close()); - EXPECT_CALL(*mock_mysql_proxy, mock_mysql_proxy_destructor()); + EXPECT_CALL(*mock_connection_proxy, close()); + EXPECT_CALL(*mock_connection_proxy, mock_connection_proxy_destructor()); - EFM_PROXY efm_proxy(dbc, ds, mock_mysql_proxy, mock_monitor_service); + EFM_PROXY efm_proxy(dbc, ds, mock_connection_proxy, mock_monitor_service); efm_proxy.close(); } diff --git a/unit_testing/failover_reader_handler_test.cc b/unit_testing/failover_reader_handler_test.cc index 04724b510..00255f89d 100644 --- a/unit_testing/failover_reader_handler_test.cc +++ b/unit_testing/failover_reader_handler_test.cc @@ -57,9 +57,9 @@ class FailoverReaderHandlerTest : public testing::Test { static std::shared_ptr reader_c_host; static std::shared_ptr writer_host; - MOCK_MYSQL_PROXY* mock_reader_a_proxy; - MOCK_MYSQL_PROXY* mock_reader_b_proxy; - MOCK_MYSQL_PROXY* mock_writer_proxy; + MOCK_CONNECTION_PROXY* mock_reader_a_proxy; + MOCK_CONNECTION_PROXY* mock_reader_b_proxy; + MOCK_CONNECTION_PROXY* mock_writer_proxy; static std::shared_ptr topology; @@ -238,7 +238,7 @@ TEST_F(FailoverReaderHandlerTest, GetConnectionFromHosts_Failure) { // Verify that reader failover handler connects to a reader node that is marked up. // Expected result: new connection to reader A TEST_F(FailoverReaderHandlerTest, GetConnectionFromHosts_Success_Reader) { - mock_reader_a_proxy = new MOCK_MYSQL_PROXY(dbc, ds); + mock_reader_a_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); EXPECT_CALL(*mock_ts, get_topology(_, true)).WillRepeatedly(Return(topology)); @@ -265,7 +265,7 @@ TEST_F(FailoverReaderHandlerTest, GetConnectionFromHosts_Success_Reader) { // Verify that reader failover handler connects to a writer node. // Expected result: new connection to writer TEST_F(FailoverReaderHandlerTest, GetConnectionFromHosts_Success_Writer) { - mock_writer_proxy = new MOCK_MYSQL_PROXY(dbc, ds); + mock_writer_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); EXPECT_CALL(*mock_ts, get_topology(_, true)).WillRepeatedly(Return(topology)); @@ -291,8 +291,8 @@ TEST_F(FailoverReaderHandlerTest, GetConnectionFromHosts_Success_Writer) { // Verify that reader failover handler connects to the fastest reader node available that is marked up. // Expected result: new connection to reader A TEST_F(FailoverReaderHandlerTest, GetConnectionFromHosts_FastestHost) { - mock_reader_a_proxy = new MOCK_MYSQL_PROXY(dbc, ds); - mock_reader_b_proxy = new MOCK_MYSQL_PROXY(dbc, ds); // Will be free'd during failover as it is slower + mock_reader_a_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); + mock_reader_b_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); // Will be free'd during failover as it is slower // May not have actually connected during failover // Cannot delete at the end as it may cause double delete @@ -329,15 +329,15 @@ TEST_F(FailoverReaderHandlerTest, GetConnectionFromHosts_FastestHost) { // Expected result: no connection TEST_F(FailoverReaderHandlerTest, GetConnectionFromHosts_Timeout) { // Connections should automatically free inside failover - mock_reader_a_proxy = new MOCK_MYSQL_PROXY(dbc, ds); - mock_reader_b_proxy = new MOCK_MYSQL_PROXY(dbc, ds); + mock_reader_a_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); + mock_reader_b_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); EXPECT_CALL(*mock_ts, get_topology(_, true)).WillRepeatedly(Return(topology)); EXPECT_CALL(*mock_reader_a_proxy, is_connected()).WillRepeatedly(Return(true)); - EXPECT_CALL(*mock_reader_a_proxy, mock_mysql_proxy_destructor()); + EXPECT_CALL(*mock_reader_a_proxy, mock_connection_proxy_destructor()); EXPECT_CALL(*mock_reader_b_proxy, is_connected()).WillRepeatedly(Return(true)); - EXPECT_CALL(*mock_reader_b_proxy, mock_mysql_proxy_destructor()); + EXPECT_CALL(*mock_reader_b_proxy, mock_connection_proxy_destructor()); EXPECT_CALL(*mock_connection_handler, connect(_, nullptr)).WillRepeatedly(Return(nullptr)); EXPECT_CALL(*mock_connection_handler, connect(reader_a_host, nullptr)).WillRepeatedly(Invoke([&]() { @@ -382,8 +382,8 @@ TEST_F(FailoverReaderHandlerTest, Failover_Failure) { // Verify that reader failover handler connects to a faster reader node. // Expected result: new connection to reader A TEST_F(FailoverReaderHandlerTest, Failover_Success_Reader) { - mock_reader_a_proxy = new MOCK_MYSQL_PROXY(dbc, ds); - mock_reader_b_proxy = new MOCK_MYSQL_PROXY(dbc, ds); // Will be free'd during failover to timeout / too slow + mock_reader_a_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); + mock_reader_b_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); // Will be free'd during failover to timeout / too slow // May not have actually connected during failover // Cannot delete at the end as it may cause double delete @@ -399,7 +399,7 @@ TEST_F(FailoverReaderHandlerTest, Failover_Success_Reader) { EXPECT_CALL(*mock_reader_a_proxy, is_connected()).WillRepeatedly(Return(true)); EXPECT_CALL(*mock_reader_b_proxy, is_connected()).WillRepeatedly(Return(true)); - EXPECT_CALL(*mock_reader_b_proxy, mock_mysql_proxy_destructor()); + EXPECT_CALL(*mock_reader_b_proxy, mock_connection_proxy_destructor()); EXPECT_CALL(*mock_connection_handler, connect(_, nullptr)).WillRepeatedly(Return(nullptr)); EXPECT_CALL(*mock_connection_handler, connect(reader_a_host, nullptr)).WillRepeatedly( diff --git a/unit_testing/failover_writer_handler_test.cc b/unit_testing/failover_writer_handler_test.cc index d21cead6a..86b94b7e5 100644 --- a/unit_testing/failover_writer_handler_test.cc +++ b/unit_testing/failover_writer_handler_test.cc @@ -65,10 +65,10 @@ class FailoverWriterHandlerTest : public testing::Test { std::shared_ptr mock_ts; std::shared_ptr mock_reader_handler; std::shared_ptr mock_connection_handler; - MOCK_MYSQL_PROXY* mock_reader_a_proxy; - MOCK_MYSQL_PROXY* mock_reader_b_proxy; - MOCK_MYSQL_PROXY* mock_writer_proxy; - MOCK_MYSQL_PROXY* mock_new_writer_proxy; + MOCK_CONNECTION_PROXY* mock_reader_a_proxy; + MOCK_CONNECTION_PROXY* mock_reader_b_proxy; + MOCK_CONNECTION_PROXY* mock_writer_proxy; + MOCK_CONNECTION_PROXY* mock_new_writer_proxy; static void SetUpTestSuite() {} @@ -113,7 +113,7 @@ class FailoverWriterHandlerTest : public testing::Test { // taskB: fail to connect to any reader due to exception // expected test result: new connection by taskA TEST_F(FailoverWriterHandlerTest, ReconnectToWriter_TaskBEmptyReaderResult) { - mock_writer_proxy = new MOCK_MYSQL_PROXY(dbc, ds); + mock_writer_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); EXPECT_CALL(*mock_writer_proxy, is_connected()).WillRepeatedly(Return(true)); EXPECT_CALL(*mock_ts, get_topology(_, true)) @@ -153,8 +153,8 @@ TEST_F(FailoverWriterHandlerTest, ReconnectToWriter_TaskBEmptyReaderResult) { // time than taskA // expected test result: new connection by taskA TEST_F(FailoverWriterHandlerTest, ReconnectToWriter_SlowReaderA) { - mock_writer_proxy = new MOCK_MYSQL_PROXY(dbc, ds); - mock_reader_a_proxy = new MOCK_MYSQL_PROXY(dbc, ds); + mock_writer_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); + mock_reader_a_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); // May not have actually connected during failover // Cannot delete at the end as it may cause double delete @@ -213,12 +213,12 @@ TEST_F(FailoverWriterHandlerTest, ReconnectToWriter_SlowReaderA) { // writer is not new (defer to taskA) // expected test result: new connection by taskA TEST_F(FailoverWriterHandlerTest, ReconnectToWriter_TaskBDefers) { - mock_writer_proxy = new MOCK_MYSQL_PROXY(dbc, ds); - mock_reader_a_proxy = new MOCK_MYSQL_PROXY(dbc, ds); + mock_writer_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); + mock_reader_a_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); EXPECT_CALL(*mock_writer_proxy, is_connected()).WillRepeatedly(Return(true)); EXPECT_CALL(*mock_reader_a_proxy, is_connected()).WillRepeatedly(Return(true)); - EXPECT_CALL(*mock_reader_a_proxy, mock_mysql_proxy_destructor()); + EXPECT_CALL(*mock_reader_a_proxy, mock_connection_proxy_destructor()); EXPECT_CALL(*mock_connection_handler, connect(writer_host, nullptr)) .WillRepeatedly(Invoke([&]() { @@ -259,9 +259,9 @@ TEST_F(FailoverWriterHandlerTest, ReconnectToWriter_TaskBDefers) { // taskB: successfully connect to readerA and then to new-writer // expected test result: new connection to writer by taskB TEST_F(FailoverWriterHandlerTest, ConnectToReaderA_SlowWriter) { - mock_writer_proxy = new MOCK_MYSQL_PROXY(dbc, ds); - mock_new_writer_proxy = new MOCK_MYSQL_PROXY(dbc, ds); - mock_reader_a_proxy = new MOCK_MYSQL_PROXY(dbc, ds); + mock_writer_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); + mock_new_writer_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); + mock_reader_a_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); // May not have actually connected during failover // Cannot delete at the end as it may cause double delete @@ -274,12 +274,12 @@ TEST_F(FailoverWriterHandlerTest, ConnectToReaderA_SlowWriter) { new_topology->add_host(reader_b_host); EXPECT_CALL(*mock_writer_proxy, is_connected()).WillRepeatedly(Return(true)); - EXPECT_CALL(*mock_writer_proxy, mock_mysql_proxy_destructor()); + EXPECT_CALL(*mock_writer_proxy, mock_connection_proxy_destructor()); EXPECT_CALL(*mock_new_writer_proxy, is_connected()).WillRepeatedly(Return(true)); EXPECT_CALL(*mock_reader_a_proxy, is_connected()).WillRepeatedly(Return(true)); - EXPECT_CALL(*mock_reader_a_proxy, mock_mysql_proxy_destructor()); + EXPECT_CALL(*mock_reader_a_proxy, mock_connection_proxy_destructor()); EXPECT_CALL(*mock_connection_handler, connect(writer_host, nullptr)) .WillRepeatedly(Invoke([&]() { @@ -323,9 +323,9 @@ TEST_F(FailoverWriterHandlerTest, ConnectToReaderA_SlowWriter) { // taskB: successfully connect to readerA and then to new-writer // expected test result: new connection to writer by taskB TEST_F(FailoverWriterHandlerTest, ConnectToReaderA_TaskADefers) { - mock_writer_proxy = new MOCK_MYSQL_PROXY(dbc, ds); - mock_new_writer_proxy = new MOCK_MYSQL_PROXY(dbc, ds); - mock_reader_a_proxy = new MOCK_MYSQL_PROXY(dbc, ds); + mock_writer_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); + mock_new_writer_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); + mock_reader_a_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); auto new_topology = std::make_shared(); new_topology->add_host(new_writer_host); @@ -334,12 +334,12 @@ TEST_F(FailoverWriterHandlerTest, ConnectToReaderA_TaskADefers) { new_topology->add_host(reader_b_host); EXPECT_CALL(*mock_writer_proxy, is_connected()).WillOnce(Return(true)); - EXPECT_CALL(*mock_writer_proxy, mock_mysql_proxy_destructor()); + EXPECT_CALL(*mock_writer_proxy, mock_connection_proxy_destructor()); EXPECT_CALL(*mock_new_writer_proxy, is_connected()).WillRepeatedly(Return(true)); EXPECT_CALL(*mock_reader_a_proxy, is_connected()).WillRepeatedly(Return(true)); - EXPECT_CALL(*mock_reader_a_proxy, mock_mysql_proxy_destructor()); + EXPECT_CALL(*mock_reader_a_proxy, mock_connection_proxy_destructor()); EXPECT_CALL(*mock_connection_handler, connect(writer_host, nullptr)) .WillOnce(Return(mock_writer_proxy)) @@ -382,10 +382,10 @@ TEST_F(FailoverWriterHandlerTest, ConnectToReaderA_TaskADefers) { // taskB: successfully connect to readerA and then fail to connect to writer due to failover timeout // expected test result: no connection TEST_F(FailoverWriterHandlerTest, FailedToConnect_FailoverTimeout) { - mock_writer_proxy = new MOCK_MYSQL_PROXY(dbc, ds); - mock_new_writer_proxy = new MOCK_MYSQL_PROXY(dbc, ds); - mock_reader_a_proxy = new MOCK_MYSQL_PROXY(dbc, ds); - mock_reader_b_proxy = new MOCK_MYSQL_PROXY(dbc, ds); + mock_writer_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); + mock_new_writer_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); + mock_reader_a_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); + mock_reader_b_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); auto new_topology = std::make_shared(); new_topology->add_host(new_writer_host); @@ -393,13 +393,13 @@ TEST_F(FailoverWriterHandlerTest, FailedToConnect_FailoverTimeout) { new_topology->add_host(reader_b_host); EXPECT_CALL(*mock_writer_proxy, is_connected()).WillRepeatedly(Return(true)); - EXPECT_CALL(*mock_writer_proxy, mock_mysql_proxy_destructor()); + EXPECT_CALL(*mock_writer_proxy, mock_connection_proxy_destructor()); EXPECT_CALL(*mock_new_writer_proxy, is_connected()).WillRepeatedly(Return(true)); - EXPECT_CALL(*mock_new_writer_proxy, mock_mysql_proxy_destructor()); + EXPECT_CALL(*mock_new_writer_proxy, mock_connection_proxy_destructor()); EXPECT_CALL(*mock_reader_a_proxy, is_connected()).WillRepeatedly(Return(true)); - EXPECT_CALL(*mock_reader_a_proxy, mock_mysql_proxy_destructor()); + EXPECT_CALL(*mock_reader_a_proxy, mock_connection_proxy_destructor()); EXPECT_CALL(*mock_reader_b_proxy, is_connected()).WillRepeatedly(Return(true)); @@ -448,8 +448,8 @@ TEST_F(FailoverWriterHandlerTest, FailedToConnect_FailoverTimeout) { // taskB: successfully connect to readerA and then fail to connect to writer // expected test result: no connection TEST_F(FailoverWriterHandlerTest, FailedToConnect_TaskAFailed_TaskBWriterFailed) { - mock_reader_a_proxy = new MOCK_MYSQL_PROXY(dbc, ds); - mock_reader_b_proxy = new MOCK_MYSQL_PROXY(dbc, ds); + mock_reader_a_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); + mock_reader_b_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); auto new_topology = std::make_shared(); new_topology->add_host(new_writer_host); @@ -457,7 +457,7 @@ TEST_F(FailoverWriterHandlerTest, FailedToConnect_TaskAFailed_TaskBWriterFailed) new_topology->add_host(reader_b_host); EXPECT_CALL(*mock_reader_a_proxy, is_connected()).WillRepeatedly(Return(true)); - EXPECT_CALL(*mock_reader_a_proxy, mock_mysql_proxy_destructor()); + EXPECT_CALL(*mock_reader_a_proxy, mock_connection_proxy_destructor()); EXPECT_CALL(*mock_reader_b_proxy, is_connected()).WillRepeatedly(Return(true)); diff --git a/unit_testing/mock_objects.h b/unit_testing/mock_objects.h index bc22bd6b0..ec26c0d50 100644 --- a/unit_testing/mock_objects.h +++ b/unit_testing/mock_objects.h @@ -32,9 +32,10 @@ #include -#include "driver/mysql_proxy.h" +#include "driver/connection_proxy.h" #include "driver/failover.h" #include "driver/monitor_thread_container.h" +#include "driver/monitor_service.h" #ifdef WIN32 #ifdef _DEBUG @@ -50,14 +51,14 @@ DataSource* ds_new(); void ds_delete(DataSource* ds); void ds_copy(DataSource* ds, DataSource* ds_source); -class MOCK_MYSQL_PROXY : public MYSQL_PROXY { +class MOCK_CONNECTION_PROXY : public CONNECTION_PROXY { public: - MOCK_MYSQL_PROXY(DBC* dbc, DataSource* ds) : MYSQL_PROXY(dbc, ds) { + MOCK_CONNECTION_PROXY(DBC* dbc, DataSource* ds) : CONNECTION_PROXY(dbc, ds) { this->ds = ds_new(); ds_copy(this->ds, ds); }; - ~MOCK_MYSQL_PROXY() override { - mock_mysql_proxy_destructor(); + ~MOCK_CONNECTION_PROXY() override { + mock_connection_proxy_destructor(); if (this->ds) { ds_delete(this->ds); this->ds = nullptr; @@ -76,10 +77,11 @@ class MOCK_MYSQL_PROXY : public MYSQL_PROXY { MOCK_METHOD(char**, fetch_row, (MYSQL_RES*)); MOCK_METHOD(void, free_result, (MYSQL_RES*)); MOCK_METHOD(void, close_socket, ()); - MOCK_METHOD(void, mock_mysql_proxy_destructor, ()); + MOCK_METHOD(void, mock_connection_proxy_destructor, ()); MOCK_METHOD(void, close, ()); MOCK_METHOD(void, init, ()); MOCK_METHOD(int, ping, ()); + MOCK_METHOD(void, delete_ds, ()); }; class MOCK_TOPOLOGY_SERVICE : public TOPOLOGY_SERVICE { @@ -88,7 +90,7 @@ class MOCK_TOPOLOGY_SERVICE : public TOPOLOGY_SERVICE { MOCK_METHOD(void, set_cluster_id, (std::string)); MOCK_METHOD(void, set_cluster_instance_template, (std::shared_ptr)); - MOCK_METHOD(std::shared_ptr, get_topology, (MYSQL_PROXY*, bool)); + MOCK_METHOD(std::shared_ptr, get_topology, (CONNECTION_PROXY*, bool)); MOCK_METHOD(void, mark_host_down, (std::shared_ptr)); MOCK_METHOD(void, mark_host_up, (std::shared_ptr)); }; @@ -103,7 +105,7 @@ class MOCK_READER_HANDLER : public FAILOVER_READER_HANDLER { class MOCK_CONNECTION_HANDLER : public CONNECTION_HANDLER { public: MOCK_CONNECTION_HANDLER() : CONNECTION_HANDLER(nullptr) {} - MOCK_METHOD(MYSQL_PROXY*, connect, (const std::shared_ptr&, DataSource*)); + MOCK_METHOD(CONNECTION_PROXY*, connect, (const std::shared_ptr&, DataSource*)); MOCK_METHOD(SQLRETURN, do_connect, (DBC*, DataSource*, bool)); }; @@ -128,7 +130,7 @@ class MOCK_CLUSTER_AWARE_METRICS_CONTAINER : public CLUSTER_AWARE_METRICS_CONTAI class MOCK_MONITOR : public MONITOR { public: MOCK_MONITOR(std::shared_ptr host, std::chrono::milliseconds disposal_time, - MYSQL_PROXY* monitor_proxy) + CONNECTION_PROXY* monitor_proxy) : MONITOR(host, nullptr, std::chrono::seconds{5}, disposal_time, nullptr, monitor_proxy) {} MOCK_METHOD(void, start_monitoring, (std::shared_ptr)); diff --git a/unit_testing/monitor_connection_context_test.cc b/unit_testing/monitor_connection_context_test.cc index 1cf963412..88595c0b2 100644 --- a/unit_testing/monitor_connection_context_test.cc +++ b/unit_testing/monitor_connection_context_test.cc @@ -60,7 +60,7 @@ class MonitorConnectionContextTest : public testing::Test { void SetUp() override { allocate_odbc_handles(env, connection_to_abort, ds); - connection_to_abort->mysql_proxy = new MOCK_MYSQL_PROXY(connection_to_abort, ds); + connection_to_abort->connection_proxy = new MOCK_CONNECTION_PROXY(connection_to_abort, ds); context = new MONITOR_CONNECTION_CONTEXT(connection_to_abort, node_keys, failure_detection_time, diff --git a/unit_testing/monitor_test.cc b/unit_testing/monitor_test.cc index 52e27d8c7..584cc970c 100644 --- a/unit_testing/monitor_test.cc +++ b/unit_testing/monitor_test.cc @@ -62,7 +62,7 @@ class MonitorTest : public testing::Test { DataSource* ds; std::shared_ptr host; std::shared_ptr monitor; - MOCK_MYSQL_PROXY* mock_proxy; + MOCK_CONNECTION_PROXY* mock_proxy; std::shared_ptr mock_connection_handler; std::shared_ptr mock_context_short_interval; std::shared_ptr mock_context_long_interval; @@ -142,7 +142,7 @@ TEST_F(MonitorTest, StopMonitoringTwiceWithSameContext) { } TEST_F(MonitorTest, IsConnectionHealthyWithNoExistingConnection) { - mock_proxy = new MOCK_MYSQL_PROXY(dbc, ds); + mock_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); EXPECT_CALL(*mock_connection_handler, connect(host, _)) .WillOnce(Return(mock_proxy)); @@ -156,7 +156,7 @@ TEST_F(MonitorTest, IsConnectionHealthyWithNoExistingConnection) { } TEST_F(MonitorTest, IsConnectionHealthyOrUnhealthy) { - mock_proxy = new MOCK_MYSQL_PROXY(dbc, ds); + mock_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); EXPECT_CALL(*mock_connection_handler, connect(host, _)) .WillRepeatedly(Return(mock_proxy)); @@ -179,7 +179,7 @@ TEST_F(MonitorTest, IsConnectionHealthyOrUnhealthy) { } TEST_F(MonitorTest, IsConnectionHealthyAfterFailedConnection) { - mock_proxy = new MOCK_MYSQL_PROXY(dbc, ds); + mock_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); EXPECT_CALL(*mock_connection_handler, connect(host, _)) .WillOnce(Return(mock_proxy)); @@ -224,7 +224,7 @@ TEST_F(MonitorTest, RunWithoutContext) { } TEST_F(MonitorTest, RunWithContext) { - auto proxy = new MOCK_MYSQL_PROXY(dbc, ds); + auto proxy = new MOCK_CONNECTION_PROXY(dbc, ds); EXPECT_CALL(*mock_connection_handler, connect(host, _)) .WillOnce(Return(proxy)); @@ -275,7 +275,7 @@ TEST_F(MonitorTest, RunWithContext) { // Verify that if 0 timeout is passed in, we should set it to default value TEST_F(MonitorTest, ZeroEFMTimeout) { - auto proxy = new MOCK_MYSQL_PROXY(dbc, ds); + auto proxy = new MOCK_CONNECTION_PROXY(dbc, ds); EXPECT_CALL(*proxy, is_connected()).WillRepeatedly(Return(true)); @@ -299,7 +299,7 @@ TEST_F(MonitorTest, ZeroEFMTimeout) { // Verify that if non-zero timeout is passed in, we should set it to that value TEST_F(MonitorTest, NonZeroEFMTimeout) { - auto proxy = new MOCK_MYSQL_PROXY(dbc, ds); + auto proxy = new MOCK_CONNECTION_PROXY(dbc, ds); auto timeout = std::chrono::seconds(1); EXPECT_CALL(*proxy, is_connected()).WillRepeatedly(Return(true)); diff --git a/unit_testing/test_utils.h b/unit_testing/test_utils.h index 01ca1f504..2231adcca 100644 --- a/unit_testing/test_utils.h +++ b/unit_testing/test_utils.h @@ -31,6 +31,8 @@ #define __TESTUTILS_H__ #include "driver/driver.h" +#include "driver/monitor.h" +#include "driver/monitor_thread_container.h" void allocate_odbc_handles(SQLHENV& env, DBC*& dbc, DataSource*& ds); void cleanup_odbc_handles(SQLHENV& env, DBC*& dbc, DataSource*& ds, bool call_myodbc_end = false); diff --git a/unit_testing/topology_service_test.cc b/unit_testing/topology_service_test.cc index 3fddab7c9..6db9d5035 100644 --- a/unit_testing/topology_service_test.cc +++ b/unit_testing/topology_service_test.cc @@ -41,7 +41,7 @@ using ::testing::ReturnNew; using ::testing::StrEq; namespace { - MOCK_MYSQL_PROXY* mock_proxy; + MOCK_CONNECTION_PROXY* mock_proxy; TOPOLOGY_SERVICE* ts; std::shared_ptr cluster_instance; @@ -75,7 +75,7 @@ class TopologyServiceTest : public testing::Test { void SetUp() override { allocate_odbc_handles(env, dbc, ds); - mock_proxy = new MOCK_MYSQL_PROXY(dbc, ds); + mock_proxy = new MOCK_CONNECTION_PROXY(dbc, ds); EXPECT_CALL(*mock_proxy, store_result()).WillRepeatedly(ReturnNew()); EXPECT_CALL(*mock_proxy, free_result(_)).WillRepeatedly(DeleteArg<0>()); ts->set_refresh_rate(DEFAULT_REFRESH_RATE_IN_MILLISECONDS);