From 4ea7b750fd01d49203d37b7f13988eb79de99e1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Mon, 9 Aug 2021 15:00:42 +0200 Subject: [PATCH] Moved helper function 'proxy_mysql_stmt_close' from 'gen_utils' to 'MySQL_Protocol' #3525 --- include/MySQL_Protocol.h | 16 ++++++++++++++++ include/gen_utils.h | 16 ---------------- lib/MySQL_PreparedStatement.cpp | 1 + lib/MySQL_Protocol.cpp | 12 ++++++++++++ lib/gen_utils.cpp | 11 ----------- 5 files changed, 29 insertions(+), 27 deletions(-) diff --git a/include/MySQL_Protocol.h b/include/MySQL_Protocol.h index 34a5918fe..c55e1cc8a 100644 --- a/include/MySQL_Protocol.h +++ b/include/MySQL_Protocol.h @@ -64,6 +64,22 @@ class MySQL_Prepared_Stmt_info { uint8_t mysql_decode_length(unsigned char *ptr, uint64_t *len); +/** + * @brief ProxySQL replacement function for 'mysql_stmt_close'. Closes a + * MYSQL_STMT avoiding any blocking commands that are sent by default + * 'mysql_stmt_close'. + * + * NOTE: This function is not safe, caller must check that the supplied + * argument is not NULL. + * + * @param mysql_stmt An already initialized 'MYSQL_STMT'. Caller must ensure + * that the supplied argument is not NULL. + * + * @return The result of calling 'mysql_stmt_close' function over the internally + * modified 'MYSQL_STMT'. + */ +my_bool proxy_mysql_stmt_close(MYSQL_STMT* mysql_stmt); + class MySQL_Protocol { private: MySQL_Connection_userinfo *userinfo; diff --git a/include/gen_utils.h b/include/gen_utils.h index ea9b8fbcb..7cda6981d 100644 --- a/include/gen_utils.h +++ b/include/gen_utils.h @@ -230,22 +230,6 @@ inline unsigned long long realtime_time() { return (((unsigned long long) ts.tv_sec) * 1000000) + (ts.tv_nsec / 1000); } -/** - * @brief ProxySQL replacement function for 'mysql_stmt_close'. Closes a - * MYSQL_STMT avoiding any blocking commands that are sent by default - * 'mysql_stmt_close'. - * - * NOTE: This function is not safe, caller must check that the supplied - * argument is not NULL. - * - * @param mysql_stmt An already initialized 'MYSQL_STMT'. Caller must ensure - * that the supplied argument is not NULL. - * - * @return The result of calling 'mysql_stmt_close' function over the internally - * modified 'MYSQL_STMT'. - */ -my_bool proxy_mysql_stmt_close(MYSQL_STMT* mysql_stmt); - #endif /* __GEN_FUNCTIONS */ bool Proxy_file_exists(const char *); diff --git a/lib/MySQL_PreparedStatement.cpp b/lib/MySQL_PreparedStatement.cpp index 3007461a4..cb970dc1f 100644 --- a/lib/MySQL_PreparedStatement.cpp +++ b/lib/MySQL_PreparedStatement.cpp @@ -4,6 +4,7 @@ #include "SpookyV2.h" #include "MySQL_PreparedStatement.h" +#include "MySQL_Protocol.h" //extern MySQL_STMT_Manager *GloMyStmt; //static uint32_t add_prepared_statement_calls = 0; diff --git a/lib/MySQL_Protocol.cpp b/lib/MySQL_Protocol.cpp index 86850d315..9c450e216 100644 --- a/lib/MySQL_Protocol.cpp +++ b/lib/MySQL_Protocol.cpp @@ -2925,3 +2925,15 @@ unsigned long long MySQL_ResultSet::current_size() { } return intsize; } + +my_bool proxy_mysql_stmt_close(MYSQL_STMT* stmt) { + // Clean internal structures for 'stmt->mysql->stmts'. + if (stmt->mysql) { + stmt->mysql->stmts = + list_delete(stmt->mysql->stmts, &stmt->list); + } + // Nullify 'mysql' field to avoid sending a blocking command to the server. + stmt->mysql = NULL; + // Perform the regular close operation. + return mysql_stmt_close(stmt); +} diff --git a/lib/gen_utils.cpp b/lib/gen_utils.cpp index f24ed64f3..0f7edf8c5 100644 --- a/lib/gen_utils.cpp +++ b/lib/gen_utils.cpp @@ -220,14 +220,3 @@ bool Proxy_file_regular(const char *path) { return false; } -my_bool proxy_mysql_stmt_close(MYSQL_STMT* stmt) { - // Clean internal structures for 'stmt->mysql->stmts'. - if (stmt->mysql) { - stmt->mysql->stmts = - list_delete(stmt->mysql->stmts, &stmt->list); - } - // Nullify 'mysql' field to avoid sending a blocking command to the server. - stmt->mysql = NULL; - // Perform the regular close operation. - return mysql_stmt_close(stmt); -}