From 046cbdbe76936e60c23812dc2aba24cc20de4e37 Mon Sep 17 00:00:00 2001 From: Richard Holland Date: Fri, 14 Feb 2025 15:37:16 +1100 Subject: [PATCH] more debugging on mysql nodestore fetch --- src/ripple/nodestore/backend/MySQLFactory.cpp | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/ripple/nodestore/backend/MySQLFactory.cpp b/src/ripple/nodestore/backend/MySQLFactory.cpp index bddea30d1..5df5b08cc 100644 --- a/src/ripple/nodestore/backend/MySQLFactory.cpp +++ b/src/ripple/nodestore/backend/MySQLFactory.cpp @@ -351,6 +351,7 @@ public: return dataCorrupt; } + // After binding the result... if (mysql_stmt_store_result(stmt)) { std::cout << "fetch: Failed to store result. Error: " @@ -365,23 +366,26 @@ public: return notFound; } - if (mysql_stmt_fetch(stmt)) + // Get the metadata to find out the length of the BLOB column + MYSQL_RES* metadata = mysql_stmt_result_metadata(stmt); + if (!metadata) { - std::cout << "fetch: Failed to fetch row. Error: " - << mysql_stmt_error(stmt) << "\n"; + std::cout << "fetch: Failed to get result metadata\n"; mysql_stmt_close(stmt); return dataCorrupt; } + unsigned long max_length = mysql_fetch_field(metadata)->max_length; + mysql_free_result(metadata); - std::cout << "fetch: Retrieved data length: " << length << "\n"; - - std::vector buffer(length); + // Allocate buffer with the max length + std::vector buffer(max_length); bindResult.buffer = buffer.data(); - bindResult.buffer_length = length; + bindResult.buffer_length = max_length; - if (mysql_stmt_fetch_column(stmt, &bindResult, 0, 0)) + // Single fetch for the row + if (mysql_stmt_fetch(stmt)) { - std::cout << "fetch: Failed to fetch column. Error: " + std::cout << "fetch: Failed to fetch row. Error: " << mysql_stmt_error(stmt) << "\n"; mysql_stmt_close(stmt); return dataCorrupt;