Commit d16d40be authored by Alexey Botchkov's avatar Alexey Botchkov

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

        SHOW CREATE PROCEDURE/FUNCTION fixed.
parent 34df3140
...@@ -2531,6 +2531,69 @@ bool check_show_routine_access(THD *thd, sp_head *sp, bool *full_access) ...@@ -2531,6 +2531,69 @@ bool check_show_routine_access(THD *thd, sp_head *sp, bool *full_access)
} }
/**
Collect metadata for SHOW CREATE statement for stored routines.
@param thd Thread context.
@param type Stored routine type
@param type Stored routine type
(TYPE_ENUM_PROCEDURE or TYPE_ENUM_FUNCTION)
@return Error status.
@retval FALSE on success
@retval TRUE on error
*/
void
sp_head::show_create_routine_get_fields(THD *thd, int type, List<Item> *fields)
{
const char *col1_caption= type == TYPE_ENUM_PROCEDURE ?
"Procedure" : "Function";
const char *col3_caption= type == TYPE_ENUM_PROCEDURE ?
"Create Procedure" : "Create Function";
MEM_ROOT *mem_root= thd->mem_root;
/* Send header. */
fields->push_back(new (mem_root)
Item_empty_string(thd, col1_caption, NAME_CHAR_LEN),
mem_root);
fields->push_back(new (mem_root)
Item_empty_string(thd, "sql_mode", 256),
mem_root);
{
/*
NOTE: SQL statement field must be not less than 1024 in order not to
confuse old clients.
*/
Item_empty_string *stmt_fld=
new (mem_root) Item_empty_string(thd, col3_caption, 1024);
stmt_fld->maybe_null= TRUE;
fields->push_back(stmt_fld, mem_root);
}
fields->push_back(new (mem_root)
Item_empty_string(thd, "character_set_client",
MY_CS_NAME_SIZE),
mem_root);
fields->push_back(new (mem_root)
Item_empty_string(thd, "collation_connection",
MY_CS_NAME_SIZE),
mem_root);
fields->push_back(new (mem_root)
Item_empty_string(thd, "Database Collation",
MY_CS_NAME_SIZE),
mem_root);
}
/** /**
Implement SHOW CREATE statement for stored routines. Implement SHOW CREATE statement for stored routines.
......
...@@ -340,6 +340,9 @@ class sp_head :private Query_arena ...@@ -340,6 +340,9 @@ class sp_head :private Query_arena
bool bool
execute_procedure(THD *thd, List<Item> *args); execute_procedure(THD *thd, List<Item> *args);
static void
show_create_routine_get_fields(THD *thd, int type, List<Item> *fields);
bool bool
show_create_routine(THD *thd, int type); show_create_routine(THD *thd, int type);
......
...@@ -1963,6 +1963,29 @@ static bool mysql_test_show_binlogs(Prepared_statement *stmt) ...@@ -1963,6 +1963,29 @@ static bool mysql_test_show_binlogs(Prepared_statement *stmt)
} }
/**
Validate and prepare for execution SHOW CREATE PROC/FUNC statement.
@param stmt prepared statement
@retval
FALSE success
@retval
TRUE error, error message is set in THD
*/
static bool mysql_test_show_create_routine(Prepared_statement *stmt, int type)
{
DBUG_ENTER("mysql_test_show_binlogs");
THD *thd= stmt->thd;
List<Item> fields;
sp_head::show_create_routine_get_fields(thd, type, &fields);
DBUG_RETURN(send_stmt_metadata(thd, stmt, &fields));
}
/** /**
@brief Validate and prepare for execution CREATE VIEW statement @brief Validate and prepare for execution CREATE VIEW statement
...@@ -2338,6 +2361,20 @@ static bool check_prepared_statement(Prepared_statement *stmt) ...@@ -2338,6 +2361,20 @@ static bool check_prepared_statement(Prepared_statement *stmt)
DBUG_RETURN(FALSE); DBUG_RETURN(FALSE);
} }
break; break;
case SQLCOM_SHOW_CREATE_PROC:
if (!(res= mysql_test_show_create_routine(stmt, TYPE_ENUM_PROCEDURE)))
{
/* Statement and field info has already been sent */
DBUG_RETURN(FALSE);
}
break;
case SQLCOM_SHOW_CREATE_FUNC:
if (!(res= mysql_test_show_create_routine(stmt, TYPE_ENUM_FUNCTION)))
{
/* Statement and field info has already been sent */
DBUG_RETURN(FALSE);
}
break;
case SQLCOM_CREATE_VIEW: case SQLCOM_CREATE_VIEW:
if (lex->create_view_mode == VIEW_ALTER) if (lex->create_view_mode == VIEW_ALTER)
{ {
......
...@@ -457,6 +457,20 @@ static void test_prepare_simple() ...@@ -457,6 +457,20 @@ static void test_prepare_simple()
DIE_UNLESS(mysql_stmt_field_count(stmt) == 4); DIE_UNLESS(mysql_stmt_field_count(stmt) == 4);
mysql_stmt_close(stmt); mysql_stmt_close(stmt);
/* show create procedure */
strmov(query, "SHOW CREATE PROCEDURE e1;");
stmt= mysql_simple_prepare(mysql, query);
check_stmt(stmt);
DIE_UNLESS(mysql_stmt_field_count(stmt) == 6);
mysql_stmt_close(stmt);
/* show create function */
strmov(query, "SHOW CREATE FUNCTION e1;");
stmt= mysql_simple_prepare(mysql, query);
check_stmt(stmt);
DIE_UNLESS(mysql_stmt_field_count(stmt) == 6);
mysql_stmt_close(stmt);
/* now fetch the results ..*/ /* now fetch the results ..*/
rc= mysql_commit(mysql); rc= mysql_commit(mysql);
myquery(rc); 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