diff --git a/libbinlogevents/include/rows_event.h b/libbinlogevents/include/rows_event.h index a01a4d0547d7..1e0a25f1e620 100644 --- a/libbinlogevents/include/rows_event.h +++ b/libbinlogevents/include/rows_event.h @@ -34,8 +34,10 @@ #ifndef ROWS_EVENT_INCLUDED #define ROWS_EVENT_INCLUDED +#include #include #include "control_events.h" +#include "my_dbug.h" #include "table_id.h" /** @@ -934,7 +936,12 @@ class Rows_event : public Binary_log_event { Indicates that rows in this event are complete, that is contain values for all columns of the table. */ - COMPLETE_ROWS_F = (1U << 3) + COMPLETE_ROWS_F = (1U << 3), + /** + Flags for everything. Please update when you add new flags. + */ + ALL_FLAGS = STMT_END_F | NO_FOREIGN_KEY_CHECKS_F | RELAXED_UNIQUE_CHECKS_F | + COMPLETE_ROWS_F }; /** @@ -1068,6 +1075,28 @@ class Rows_event : public Binary_log_event { unsigned long get_width() const { return m_width; } + std::string get_enum_flag_string() const { + std::stringstream flag_str; + +#define PARSE_FLAG(__str__, __flag__) \ + if (m_flags & __flag__) { \ + __str__ << " " #__flag__; \ + } + + flag_str << " flags:"; + PARSE_FLAG(flag_str, STMT_END_F); + PARSE_FLAG(flag_str, NO_FOREIGN_KEY_CHECKS_F); + PARSE_FLAG(flag_str, RELAXED_UNIQUE_CHECKS_F); + PARSE_FLAG(flag_str, COMPLETE_ROWS_F); + auto unknown_flags = (m_flags & ~ALL_FLAGS); + if (unknown_flags) { + assert(false); + flag_str << " UNKNOWN_FLAG("; + flag_str << std::hex << "0x" << unknown_flags << ")"; + } + return flag_str.str(); + } + static std::string get_flag_string(enum_flag flag) { std::string str = ""; if (flag & STMT_END_F) str.append(" Last event of the statement"); diff --git a/sql/log_event.cc b/sql/log_event.cc index 517d41573898..54a75a8d2be2 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -11125,9 +11125,11 @@ bool Rows_log_event::write_data_body(Basic_ostream *ostream) { int Rows_log_event::pack_info(Protocol *protocol) { char buf[256]; - char const *const flagstr = get_flags(STMT_END_F) ? " flags: STMT_END_F" : ""; - size_t bytes = - snprintf(buf, sizeof(buf), "table_id: %llu%s", m_table_id.id(), flagstr); + std::string flagstr; + if (m_flags) flagstr = get_enum_flag_string(); + + size_t bytes = snprintf(buf, sizeof(buf), "table_id: %llu%s", m_table_id.id(), + flagstr.c_str()); protocol->store_string(buf, bytes, &my_charset_bin); return 0; } @@ -11139,10 +11141,12 @@ void Rows_log_event::print_helper(FILE *, IO_CACHE *const head = &print_event_info->head_cache; IO_CACHE *const body = &print_event_info->body_cache; if (!print_event_info->short_form) { + std::string flag_str = get_enum_flag_string(); + bool const last_stmt_event = get_flags(STMT_END_F); print_header(head, print_event_info, !last_stmt_event); my_b_printf(head, "\t%s: table id %llu%s\n", get_type_str(), - m_table_id.id(), last_stmt_event ? " flags: STMT_END_F" : ""); + m_table_id.id(), m_flags ? flag_str.c_str() : ""); print_base64(body, print_event_info, !last_stmt_event); } }