From cbb8505ca1cb4297a0030848be4ec7e462d76dee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Fri, 25 Apr 2025 05:45:26 +0000 Subject: [PATCH] Improvement in prepared statements logging In bufferTypeInfoMap , use sizeof(MYSQL_TIME) for the size of these types: * MYSQL_TYPE_TIMESTAMP * MYSQL_TYPE_DATE * MYSQL_TYPE_TIME * MYSQL_TYPE_DATETIME Notes: * sizeof(MYSQL_TIME) is 40 * client library may use MYSQL_TYPE_DATETIME for all of these types --- lib/MySQL_Logger.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/MySQL_Logger.cpp b/lib/MySQL_Logger.cpp index 99bb9549b..a92bcd134 100644 --- a/lib/MySQL_Logger.cpp +++ b/lib/MySQL_Logger.cpp @@ -64,6 +64,7 @@ struct BufferTypeInfo { // Helper lambda to convert binary data to a hex string. auto binaryToHex = [](const MYSQL_BIND* bind, unsigned long len, std::string &out) { std::ostringstream oss; + oss << "0x"; const unsigned char* data = reinterpret_cast(bind->buffer); for (unsigned long i = 0; i < len; i++) { oss << std::setw(2) << std::setfill('0') << std::hex << (int)data[i]; @@ -109,7 +110,7 @@ static const std::unordered_map bufferTypeInfoMap }, { MYSQL_TYPE_TIMESTAMP, { "TIMESTAMP", [](const MYSQL_BIND* bind, unsigned long len, std::string &out) { - binaryToHex(bind, len, out); + binaryToHex(bind, sizeof(MYSQL_TIME), out); }} }, { MYSQL_TYPE_LONGLONG, @@ -125,17 +126,17 @@ static const std::unordered_map bufferTypeInfoMap }, { MYSQL_TYPE_DATE, { "DATE", [](const MYSQL_BIND* bind, unsigned long len, std::string &out) { - binaryToHex(bind, len, out); + binaryToHex(bind, sizeof(MYSQL_TIME), out); }} }, { MYSQL_TYPE_TIME, { "TIME", [](const MYSQL_BIND* bind, unsigned long len, std::string &out) { - binaryToHex(bind, len, out); + binaryToHex(bind, sizeof(MYSQL_TIME), out); }} }, { MYSQL_TYPE_DATETIME, { "DATETIME", [](const MYSQL_BIND* bind, unsigned long len, std::string &out) { - binaryToHex(bind, len, out); + binaryToHex(bind, sizeof(MYSQL_TIME), out); }} }, { MYSQL_TYPE_YEAR,