From a2887df805483a89e40fc9f01e690a076b0e28a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Wed, 16 Nov 2022 13:52:44 +0100 Subject: [PATCH] Fix invalid reset of new 'eventslog' field 'client_stmt_id' during 'PROCESSING_STMT_PREPARE' --- lib/MySQL_Session.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index 6fafe8745..49ef87583 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -4114,10 +4114,15 @@ bool MySQL_Session::handler_rc0_PROCESSING_STMT_PREPARE(enum session_status& st, } global_stmtid=stmt_info->statement_id; myds->myconn->local_stmts->backend_insert(global_stmtid,CurrentQuery.mysql_stmt); - if (previous_status.size() == 0) - client_stmtid=client_myds->myconn->local_stmts->generate_new_client_stmt_id(global_stmtid); + // We only perform the generation for a new 'client_stmt_id' when there is no previous status, this + // is, when 'PROCESSING_STMT_PREPARE' is reached directly without transitioning from a previous status + // like 'PROCESSING_STMT_EXECUTE'. The same condition needs to hold for setting 'stmt_client_id', + // otherwise we could be resetting it's current value from the previous state. + if (previous_status.size() == 0) { + client_stmtid=client_myds->myconn->local_stmts->generate_new_client_stmt_id(global_stmtid); + CurrentQuery.stmt_client_id=client_stmtid; + } CurrentQuery.mysql_stmt=NULL; - CurrentQuery.stmt_client_id=client_stmtid; st=status; size_t sts=previous_status.size(); if (sts) {