Commit 0b0f37f0 authored by unknown's avatar unknown

Merge bk-internal.mysql.com:/home/bk/mysql-5.1-runtime

into  ibm.:/home/alik/Documents/MySQL/devel/5.1-rt-cs-3

parents d4b3c91e 0e9f4eaa
This diff is collapsed.
...@@ -44,37 +44,20 @@ sp_exist_routines(THD *thd, TABLE_LIST *procs, bool any, bool no_error); ...@@ -44,37 +44,20 @@ sp_exist_routines(THD *thd, TABLE_LIST *procs, bool any, bool no_error);
int int
sp_routine_exists_in_table(THD *thd, int type, sp_name *name); sp_routine_exists_in_table(THD *thd, int type, sp_name *name);
int bool
sp_create_procedure(THD *thd, sp_head *sp); sp_show_create_routine(THD *thd, int type, sp_name *name);
int
sp_drop_procedure(THD *thd, sp_name *name);
int int
sp_update_procedure(THD *thd, sp_name *name, st_sp_chistics *chistics); sp_show_status_routine(THD *thd, int type, const char *wild);
int int
sp_show_create_procedure(THD *thd, sp_name *name); sp_create_routine(THD *thd, int type, sp_head *sp);
int int
sp_show_status_procedure(THD *thd, const char *wild); sp_update_routine(THD *thd, int type, sp_name *name, st_sp_chistics *chistics);
int int
sp_create_function(THD *thd, sp_head *sp); sp_drop_routine(THD *thd, int type, sp_name *name);
int
sp_drop_function(THD *thd, sp_name *name);
int
sp_update_function(THD *thd, sp_name *name, st_sp_chistics *chistics);
int
sp_show_create_function(THD *thd, sp_name *name);
int
sp_show_status_function(THD *thd, const char *wild);
/* /*
Procedures for pre-caching of stored routines and building table list Procedures for pre-caching of stored routines and building table list
......
...@@ -637,17 +637,10 @@ int ...@@ -637,17 +637,10 @@ int
sp_head::create(THD *thd) sp_head::create(THD *thd)
{ {
DBUG_ENTER("sp_head::create"); DBUG_ENTER("sp_head::create");
int ret;
DBUG_PRINT("info", ("type: %d name: %s params: %s body: %s", DBUG_PRINT("info", ("type: %d name: %s params: %s body: %s",
m_type, m_name.str, m_params.str, m_body.str)); m_type, m_name.str, m_params.str, m_body.str));
if (m_type == TYPE_ENUM_FUNCTION) DBUG_RETURN(sp_create_routine(thd, m_type, this));
ret= sp_create_function(thd, this);
else
ret= sp_create_procedure(thd, this);
DBUG_RETURN(ret);
} }
sp_head::~sp_head() sp_head::~sp_head()
...@@ -2104,49 +2097,97 @@ bool check_show_routine_access(THD *thd, sp_head *sp, bool *full_access) ...@@ -2104,49 +2097,97 @@ bool check_show_routine_access(THD *thd, sp_head *sp, bool *full_access)
} }
int /**
sp_head::show_create_procedure(THD *thd) Implement SHOW CREATE statement for stored routines.
@param thd Thread context.
@param type Stored routine type
(TYPE_ENUM_PROCEDURE or TYPE_ENUM_FUNCTION)
@return Error status.
@retval FALSE on success
@retval TRUE on error
*/
bool
sp_head::show_create_routine(THD *thd, int type)
{ {
const char *col1_caption= type == TYPE_ENUM_PROCEDURE ?
"Procedure" : "Function";
const char *col3_caption= type == TYPE_ENUM_PROCEDURE ?
"Create Procedure" : "Create Function";
bool err_status;
Protocol *protocol= thd->protocol; Protocol *protocol= thd->protocol;
char buff[2048]; List<Item> fields;
String buffer(buff, sizeof(buff), system_charset_info);
int res;
List<Item> field_list;
LEX_STRING sql_mode; LEX_STRING sql_mode;
bool full_access; bool full_access;
DBUG_ENTER("sp_head::show_create_procedure");
DBUG_PRINT("info", ("procedure %s", m_name.str)); DBUG_ENTER("sp_head::show_create_routine");
DBUG_PRINT("info", ("routine %s", m_name.str));
DBUG_ASSERT(type == TYPE_ENUM_PROCEDURE ||
type == TYPE_ENUM_FUNCTION);
if (check_show_routine_access(thd, this, &full_access)) if (check_show_routine_access(thd, this, &full_access))
DBUG_RETURN(1); DBUG_RETURN(TRUE);
sys_var_thd_sql_mode::symbolic_mode_representation(thd, m_sql_mode, sys_var_thd_sql_mode::symbolic_mode_representation(
&sql_mode); thd, m_sql_mode, &sql_mode);
field_list.push_back(new Item_empty_string("Procedure", NAME_CHAR_LEN));
field_list.push_back(new Item_empty_string("sql_mode", sql_mode.length)); /* Send header. */
// 1024 is for not to confuse old clients
Item_empty_string *definition= fields.push_back(new Item_empty_string(col1_caption, NAME_LEN));
new Item_empty_string("Create Procedure", max(buffer.length(),1024)); fields.push_back(new Item_empty_string("sql_mode", sql_mode.length));
definition->maybe_null= TRUE;
field_list.push_back(definition); {
/*
NOTE: SQL statement field must be not less than 1024 in order not to
confuse old clients.
*/
Item_empty_string *stmt_fld=
new Item_empty_string(col3_caption,
max(m_defstr.length, 1024));
stmt_fld->maybe_null= TRUE;
fields.push_back(stmt_fld);
}
if (protocol->send_fields(&fields,
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
{
DBUG_RETURN(TRUE);
}
/* Send data. */
if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS |
Protocol::SEND_EOF))
DBUG_RETURN(1);
protocol->prepare_for_resend(); protocol->prepare_for_resend();
protocol->store(m_name.str, m_name.length, system_charset_info); protocol->store(m_name.str, m_name.length, system_charset_info);
protocol->store((char*) sql_mode.str, sql_mode.length, system_charset_info); protocol->store(sql_mode.str, sql_mode.length, system_charset_info);
if (full_access) if (full_access)
protocol->store(m_defstr.str, m_defstr.length, system_charset_info); protocol->store(m_defstr.str, m_defstr.length, &my_charset_bin);
else else
protocol->store_null(); protocol->store_null();
res= protocol->write();
send_eof(thd);
DBUG_RETURN(res); err_status= protocol->write();
if (!err_status)
send_eof(thd);
DBUG_RETURN(err_status);
} }
/* /*
Add instruction to SP Add instruction to SP
...@@ -2170,48 +2211,6 @@ void sp_head::add_instr(sp_instr *instr) ...@@ -2170,48 +2211,6 @@ void sp_head::add_instr(sp_instr *instr)
} }
int
sp_head::show_create_function(THD *thd)
{
Protocol *protocol= thd->protocol;
char buff[2048];
String buffer(buff, sizeof(buff), system_charset_info);
int res;
List<Item> field_list;
LEX_STRING sql_mode;
bool full_access;
DBUG_ENTER("sp_head::show_create_function");
DBUG_PRINT("info", ("procedure %s", m_name.str));
if (check_show_routine_access(thd, this, &full_access))
DBUG_RETURN(1);
sys_var_thd_sql_mode::symbolic_mode_representation(thd, m_sql_mode,
&sql_mode);
field_list.push_back(new Item_empty_string("Function",NAME_CHAR_LEN));
field_list.push_back(new Item_empty_string("sql_mode", sql_mode.length));
Item_empty_string *definition=
new Item_empty_string("Create Function", max(buffer.length(),1024));
definition->maybe_null= TRUE;
field_list.push_back(definition);
if (protocol->send_fields(&field_list,
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
DBUG_RETURN(1);
protocol->prepare_for_resend();
protocol->store(m_name.str, m_name.length, system_charset_info);
protocol->store(sql_mode.str, sql_mode.length, system_charset_info);
if (full_access)
protocol->store(m_defstr.str, m_defstr.length, system_charset_info);
else
protocol->store_null();
res= protocol->write();
send_eof(thd);
DBUG_RETURN(res);
}
/* /*
Do some minimal optimization of the code: Do some minimal optimization of the code:
1) Mark used instructions 1) Mark used instructions
......
...@@ -225,11 +225,8 @@ public: ...@@ -225,11 +225,8 @@ public:
bool bool
execute_procedure(THD *thd, List<Item> *args); execute_procedure(THD *thd, List<Item> *args);
int bool
show_create_procedure(THD *thd); show_create_routine(THD *thd, int type);
int
show_create_function(THD *thd);
void void
add_instr(sp_instr *instr); add_instr(sp_instr *instr);
......
...@@ -3928,11 +3928,15 @@ create_sp_error: ...@@ -3928,11 +3928,15 @@ create_sp_error:
already puts on CREATE FUNCTION. already puts on CREATE FUNCTION.
*/ */
/* Conditionally writes to binlog */ /* Conditionally writes to binlog */
if (lex->sql_command == SQLCOM_ALTER_PROCEDURE)
sp_result= sp_update_procedure(thd, lex->spname, int type= lex->sql_command == SQLCOM_ALTER_PROCEDURE ?
&lex->sp_chistics); TYPE_ENUM_PROCEDURE :
else TYPE_ENUM_FUNCTION;
sp_result= sp_update_function(thd, lex->spname, &lex->sp_chistics);
sp_result= sp_update_routine(thd,
type,
lex->spname,
&lex->sp_chistics);
} }
} }
switch (sp_result) switch (sp_result)
...@@ -3982,10 +3986,12 @@ create_sp_error: ...@@ -3982,10 +3986,12 @@ create_sp_error:
} }
#endif #endif
/* Conditionally writes to binlog */ /* Conditionally writes to binlog */
if (lex->sql_command == SQLCOM_DROP_PROCEDURE)
sp_result= sp_drop_procedure(thd, lex->spname); int type= lex->sql_command == SQLCOM_DROP_PROCEDURE ?
else TYPE_ENUM_PROCEDURE :
sp_result= sp_drop_function(thd, lex->spname); TYPE_ENUM_FUNCTION;
sp_result= sp_drop_routine(thd, type, lex->spname);
} }
else else
{ {
...@@ -4042,8 +4048,8 @@ create_sp_error: ...@@ -4042,8 +4048,8 @@ create_sp_error:
} }
case SQLCOM_SHOW_CREATE_PROC: case SQLCOM_SHOW_CREATE_PROC:
{ {
if (sp_show_create_procedure(thd, lex->spname) != SP_OK) if (sp_show_create_routine(thd, TYPE_ENUM_PROCEDURE, lex->spname))
{ /* We don't distinguish between errors for now */ {
my_error(ER_SP_DOES_NOT_EXIST, MYF(0), my_error(ER_SP_DOES_NOT_EXIST, MYF(0),
SP_COM_STRING(lex), lex->spname->m_name.str); SP_COM_STRING(lex), lex->spname->m_name.str);
goto error; goto error;
...@@ -4052,8 +4058,8 @@ create_sp_error: ...@@ -4052,8 +4058,8 @@ create_sp_error:
} }
case SQLCOM_SHOW_CREATE_FUNC: case SQLCOM_SHOW_CREATE_FUNC:
{ {
if (sp_show_create_function(thd, lex->spname) != SP_OK) if (sp_show_create_routine(thd, TYPE_ENUM_FUNCTION, lex->spname))
{ /* We don't distinguish between errors for now */ {
my_error(ER_SP_DOES_NOT_EXIST, MYF(0), my_error(ER_SP_DOES_NOT_EXIST, MYF(0),
SP_COM_STRING(lex), lex->spname->m_name.str); SP_COM_STRING(lex), lex->spname->m_name.str);
goto error; goto error;
...@@ -4063,14 +4069,14 @@ create_sp_error: ...@@ -4063,14 +4069,14 @@ create_sp_error:
#ifdef NOT_USED #ifdef NOT_USED
case SQLCOM_SHOW_STATUS_PROC: case SQLCOM_SHOW_STATUS_PROC:
{ {
res= sp_show_status_procedure(thd, (lex->wild ? res= sp_show_status_routine(thd, TYPE_ENUM_PROCEDURE,
lex->wild->ptr() : NullS)); (lex->wild ? lex->wild->ptr() : NullS));
break; break;
} }
case SQLCOM_SHOW_STATUS_FUNC: case SQLCOM_SHOW_STATUS_FUNC:
{ {
res= sp_show_status_function(thd, (lex->wild ? res= sp_show_status_routine(thd, TYPE_ENUM_FUNCTION,
lex->wild->ptr() : NullS)); (lex->wild ? lex->wild->ptr() : NullS));
break; break;
} }
#endif #endif
......
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