Commit 552d3309 authored by Alexey Botchkov's avatar Alexey Botchkov

MDEV-5273 Prepared statement doesn't return metadata after prepare.

        Fix for SHOW GRANTS statement.
parent f3926cd1
......@@ -7740,6 +7740,16 @@ static int show_grants_callback(ACL_USER_BASE *role, void *data)
}
void mysql_show_grants_get_fields(THD *thd, List<Item> *fields,
const char *name)
{
Item_string *field=new (thd->mem_root) Item_string_ascii(thd, "", 0);
field->name= (char *) name;
field->max_length=1024;
fields->push_back(field, thd->mem_root);
}
/*
SHOW GRANTS; Send grants for a user to the client
......@@ -7805,15 +7815,14 @@ bool mysql_show_grants(THD *thd, LEX_USER *lex_user)
}
DBUG_ASSERT(rolename || username);
Item_string *field=new (thd->mem_root) Item_string_ascii(thd, "", 0);
List<Item> field_list;
field->name=buff;
field->max_length=1024;
if (!username)
strxmov(buff,"Grants for ",rolename, NullS);
else
strxmov(buff,"Grants for ",username,"@",hostname, NullS);
field_list.push_back(field, thd->mem_root);
mysql_show_grants_get_fields(thd, &field_list, buff);
if (protocol->send_result_set_metadata(&field_list,
Protocol::SEND_NUM_ROWS |
Protocol::SEND_EOF))
......
......@@ -241,6 +241,8 @@ ulong get_table_grant(THD *thd, TABLE_LIST *table);
ulong get_column_grant(THD *thd, GRANT_INFO *grant,
const char *db_name, const char *table_name,
const char *field_name);
void mysql_show_grants_get_fields(THD *thd, List<Item> *fields,
const char *name);
bool mysql_show_grants(THD *thd, LEX_USER *user);
int fill_schema_enabled_roles(THD *thd, TABLE_LIST *tables, COND *cond);
int fill_schema_applicable_roles(THD *thd, TABLE_LIST *tables, COND *cond);
......
......@@ -1869,6 +1869,29 @@ static bool mysql_test_show_create_db(Prepared_statement *stmt)
}
/**
Validate and prepare for execution SHOW GRANTS statement.
@param stmt prepared statement
@retval
FALSE success
@retval
TRUE error, error message is set in THD
*/
static bool mysql_test_show_grants(Prepared_statement *stmt)
{
DBUG_ENTER("mysql_test_show_grants");
THD *thd= stmt->thd;
List<Item> fields;
mysql_show_grants_get_fields(thd, &fields, "Grants for");
DBUG_RETURN(send_stmt_metadata(thd, stmt, &fields));
}
/**
@brief Validate and prepare for execution CREATE VIEW statement
......@@ -2216,6 +2239,13 @@ static bool check_prepared_statement(Prepared_statement *stmt)
DBUG_RETURN(FALSE);
}
break;
case SQLCOM_SHOW_GRANTS:
if (!(res= mysql_test_show_grants(stmt)))
{
/* Statement and field info has already been sent */
DBUG_RETURN(FALSE);
}
break;
case SQLCOM_CREATE_VIEW:
if (lex->create_view_mode == VIEW_ALTER)
{
......
......@@ -436,6 +436,13 @@ static void test_prepare_simple()
DIE_UNLESS(mysql_stmt_field_count(stmt) == 2);
mysql_stmt_close(stmt);
/* show grants */
strmov(query, "SHOW GRANTS");
stmt= mysql_simple_prepare(mysql, query);
check_stmt(stmt);
DIE_UNLESS(mysql_stmt_field_count(stmt) == 1);
mysql_stmt_close(stmt);
/* now fetch the results ..*/
rc= mysql_commit(mysql);
myquery(rc);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment