Skip to content

Commit efb36ac

Browse files
author
Alexey Botchkov
committed
MDEV-5273 Prepared statement doesn't return metadata after prepare.
SHOW MASTER STATUS fixed.
1 parent 75a1d86 commit efb36ac

File tree

4 files changed

+58
-14
lines changed

4 files changed

+58
-14
lines changed

sql/slave.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ void show_master_info_get_fields(THD *thd, List<Item> *field_list,
211211
bool full, size_t gtid_pos_length);
212212
bool show_master_info(THD* thd, Master_info* mi, bool full);
213213
bool show_all_master_info(THD* thd);
214+
void show_binlog_info_get_fields(THD *thd, List<Item> *field_list);
214215
bool show_binlog_info(THD* thd);
215216
bool rpl_master_has_bug(const Relay_log_info *rli, uint bug_id, bool report,
216217
bool (*pred)(const void *), const void *param);

sql/sql_prepare.cc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,6 +1916,29 @@ static bool mysql_test_show_slave_status(Prepared_statement *stmt)
19161916
}
19171917

19181918

1919+
/**
1920+
Validate and prepare for execution SHOW MASTER STATUS statement.
1921+
1922+
@param stmt prepared statement
1923+
1924+
@retval
1925+
FALSE success
1926+
@retval
1927+
TRUE error, error message is set in THD
1928+
*/
1929+
1930+
static bool mysql_test_show_master_status(Prepared_statement *stmt)
1931+
{
1932+
DBUG_ENTER("mysql_test_show_master_status");
1933+
THD *thd= stmt->thd;
1934+
List<Item> fields;
1935+
1936+
show_binlog_info_get_fields(thd, &fields);
1937+
1938+
DBUG_RETURN(send_stmt_metadata(thd, stmt, &fields));
1939+
}
1940+
1941+
19191942
/**
19201943
@brief Validate and prepare for execution CREATE VIEW statement
19211944
@@ -2277,6 +2300,13 @@ static bool check_prepared_statement(Prepared_statement *stmt)
22772300
DBUG_RETURN(FALSE);
22782301
}
22792302
break;
2303+
case SQLCOM_SHOW_MASTER_STAT:
2304+
if (!(res= mysql_test_show_master_status(stmt)))
2305+
{
2306+
/* Statement and field info has already been sent */
2307+
DBUG_RETURN(FALSE);
2308+
}
2309+
break;
22802310
case SQLCOM_CREATE_VIEW:
22812311
if (lex->create_view_mode == VIEW_ALTER)
22822312
{

sql/sql_repl.cc

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4088,6 +4088,25 @@ bool mysql_show_binlog_events(THD* thd)
40884088
}
40894089

40904090

4091+
void show_binlog_info_get_fields(THD *thd, List<Item> *field_list)
4092+
{
4093+
MEM_ROOT *mem_root= thd->mem_root;
4094+
field_list->push_back(new (mem_root)
4095+
Item_empty_string(thd, "File", FN_REFLEN),
4096+
mem_root);
4097+
field_list->push_back(new (mem_root)
4098+
Item_return_int(thd, "Position", 20,
4099+
MYSQL_TYPE_LONGLONG),
4100+
mem_root);
4101+
field_list->push_back(new (mem_root)
4102+
Item_empty_string(thd, "Binlog_Do_DB", 255),
4103+
mem_root);
4104+
field_list->push_back(new (mem_root)
4105+
Item_empty_string(thd, "Binlog_Ignore_DB", 255),
4106+
mem_root);
4107+
}
4108+
4109+
40914110
/**
40924111
Execute a SHOW MASTER STATUS statement.
40934112
@@ -4100,23 +4119,10 @@ bool mysql_show_binlog_events(THD* thd)
41004119
bool show_binlog_info(THD* thd)
41014120
{
41024121
Protocol *protocol= thd->protocol;
4103-
MEM_ROOT *mem_root= thd->mem_root;
41044122
DBUG_ENTER("show_binlog_info");
41054123

41064124
List<Item> field_list;
4107-
field_list.push_back(new (mem_root)
4108-
Item_empty_string(thd, "File", FN_REFLEN),
4109-
mem_root);
4110-
field_list.push_back(new (mem_root)
4111-
Item_return_int(thd, "Position", 20,
4112-
MYSQL_TYPE_LONGLONG),
4113-
mem_root);
4114-
field_list.push_back(new (mem_root)
4115-
Item_empty_string(thd, "Binlog_Do_DB", 255),
4116-
mem_root);
4117-
field_list.push_back(new (mem_root)
4118-
Item_empty_string(thd, "Binlog_Ignore_DB", 255),
4119-
mem_root);
4125+
show_binlog_info_get_fields(thd, &field_list);
41204126

41214127
if (protocol->send_result_set_metadata(&field_list,
41224128
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))

tests/mysql_client_test.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,13 @@ static void test_prepare_simple()
450450
DIE_UNLESS(mysql_stmt_field_count(stmt) == 47);
451451
mysql_stmt_close(stmt);
452452

453+
/* show master status */
454+
strmov(query, "SHOW MASTER STATUS");
455+
stmt= mysql_simple_prepare(mysql, query);
456+
check_stmt(stmt);
457+
DIE_UNLESS(mysql_stmt_field_count(stmt) == 4);
458+
mysql_stmt_close(stmt);
459+
453460
/* now fetch the results ..*/
454461
rc= mysql_commit(mysql);
455462
myquery(rc);

0 commit comments

Comments
 (0)