Commit c7aeb8f3 authored by unknown's avatar unknown

This is the 3-rd part of patch for BUG#11986:

remove redundant "body" from Event_parse_data (use sp_head::m_body).


sql/event_data_objects.cc:
  Use sp_head::m_body to store SQL-statement.
  Polishing.
sql/event_data_objects.h:
  Use sp_head::m_body to store SQL-statement.
  Polishing.
sql/event_db_repository.cc:
  Use sp_head::m_body to store SQL-statement.
sql/sql_yacc.yy:
  Use sp_head::m_body to store SQL-statement.
parent efaaeeca
...@@ -94,6 +94,7 @@ Event_parse_data::Event_parse_data() ...@@ -94,6 +94,7 @@ Event_parse_data::Event_parse_data()
:on_completion(Event_basic::ON_COMPLETION_DROP), :on_completion(Event_basic::ON_COMPLETION_DROP),
status(Event_basic::ENABLED), status(Event_basic::ENABLED),
do_not_create(FALSE), do_not_create(FALSE),
body_changed(FALSE),
item_starts(NULL), item_ends(NULL), item_execute_at(NULL), item_starts(NULL), item_ends(NULL), item_execute_at(NULL),
starts_null(TRUE), ends_null(TRUE), execute_at_null(TRUE), starts_null(TRUE), ends_null(TRUE), execute_at_null(TRUE),
item_expression(NULL), expression(0) item_expression(NULL), expression(0)
...@@ -103,8 +104,8 @@ Event_parse_data::Event_parse_data() ...@@ -103,8 +104,8 @@ Event_parse_data::Event_parse_data()
/* Actually in the parser STARTS is always set */ /* Actually in the parser STARTS is always set */
starts= ends= execute_at= 0; starts= ends= execute_at= 0;
body.str= comment.str= NULL; comment.str= NULL;
body.length= comment.length= 0; comment.length= 0;
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
...@@ -137,36 +138,6 @@ Event_parse_data::init_name(THD *thd, sp_name *spn) ...@@ -137,36 +138,6 @@ Event_parse_data::init_name(THD *thd, sp_name *spn)
} }
/*
Set body of the event - what should be executed.
SYNOPSIS
Event_parse_data::init_body()
thd THD
NOTE
The body is extracted by copying all data between the
start of the body set by another method and the current pointer in Lex.
See related code in sp_head::init_strings().
*/
void
Event_parse_data::init_body(THD *thd)
{
DBUG_ENTER("Event_parse_data::init_body");
/* This method is called from within the parser, from sql_yacc.yy */
DBUG_ASSERT(thd->m_lip != NULL);
body.length= thd->m_lip->get_cpp_ptr() - body_begin;
body.str= thd->strmake(body_begin, body.length);
trim_whitespace(thd->charset(), & body);
DBUG_VOID_RETURN;
}
/* /*
This function is called on CREATE EVENT or ALTER EVENT. When either This function is called on CREATE EVENT or ALTER EVENT. When either
ENDS or AT is in the past, we are trying to create an event that ENDS or AT is in the past, we are trying to create an event that
...@@ -788,36 +759,32 @@ Event_timed::init() ...@@ -788,36 +759,32 @@ Event_timed::init()
} }
/* /**
Loads an event's body from a row from mysql.event Load an event's body from a row from mysql.event.
@details This method is silent on errors and should behave like that.
SYNOPSIS Callers should handle throwing of error messages. The reason is that the
Event_job_data::load_from_row(THD *thd, TABLE *table) class should not know about how to deal with communication.
RETURN VALUE @return Operation status
0 OK @retval FALSE OK
EVEX_GET_FIELD_FAILED Error @retval TRUE Error
NOTES
This method is silent on errors and should behave like that. Callers
should handle throwing of error messages. The reason is that the class
should not know about how to deal with communication.
*/ */
int bool
Event_job_data::load_from_row(THD *thd, TABLE *table) Event_job_data::load_from_row(THD *thd, TABLE *table)
{ {
char *ptr; char *ptr;
uint len; uint len;
LEX_STRING tz_name;
DBUG_ENTER("Event_job_data::load_from_row"); DBUG_ENTER("Event_job_data::load_from_row");
if (!table) if (!table)
goto error; DBUG_RETURN(TRUE);
if (table->s->fields < ET_FIELD_COUNT) if (table->s->fields < ET_FIELD_COUNT)
goto error; DBUG_RETURN(TRUE);
LEX_STRING tz_name;
if (load_string_fields(table->field, if (load_string_fields(table->field,
ET_FIELD_DB, &dbname, ET_FIELD_DB, &dbname,
ET_FIELD_NAME, &name, ET_FIELD_NAME, &name,
...@@ -825,10 +792,10 @@ Event_job_data::load_from_row(THD *thd, TABLE *table) ...@@ -825,10 +792,10 @@ Event_job_data::load_from_row(THD *thd, TABLE *table)
ET_FIELD_DEFINER, &definer, ET_FIELD_DEFINER, &definer,
ET_FIELD_TIME_ZONE, &tz_name, ET_FIELD_TIME_ZONE, &tz_name,
ET_FIELD_COUNT)) ET_FIELD_COUNT))
goto error; DBUG_RETURN(TRUE);
if (load_time_zone(thd, tz_name)) if (load_time_zone(thd, tz_name))
goto error; DBUG_RETURN(TRUE);
ptr= strchr(definer.str, '@'); ptr= strchr(definer.str, '@');
...@@ -845,29 +812,23 @@ Event_job_data::load_from_row(THD *thd, TABLE *table) ...@@ -845,29 +812,23 @@ Event_job_data::load_from_row(THD *thd, TABLE *table)
sql_mode= (ulong) table->field[ET_FIELD_SQL_MODE]->val_int(); sql_mode= (ulong) table->field[ET_FIELD_SQL_MODE]->val_int();
DBUG_RETURN(0); DBUG_RETURN(FALSE);
error:
DBUG_RETURN(EVEX_GET_FIELD_FAILED);
} }
/* /**
Loads an event from a row from mysql.event Load an event's body from a row from mysql.event.
SYNOPSIS
Event_queue_element::load_from_row(THD *thd, TABLE *table)
RETURN VALUE @details This method is silent on errors and should behave like that.
0 OK Callers should handle throwing of error messages. The reason is that the
EVEX_GET_FIELD_FAILED Error class should not know about how to deal with communication.
NOTES @return Operation status
This method is silent on errors and should behave like that. Callers @retval FALSE OK
should handle throwing of error messages. The reason is that the class @retval TRUE Error
should not know about how to deal with communication.
*/ */
int bool
Event_queue_element::load_from_row(THD *thd, TABLE *table) Event_queue_element::load_from_row(THD *thd, TABLE *table)
{ {
char *ptr; char *ptr;
...@@ -877,10 +838,10 @@ Event_queue_element::load_from_row(THD *thd, TABLE *table) ...@@ -877,10 +838,10 @@ Event_queue_element::load_from_row(THD *thd, TABLE *table)
DBUG_ENTER("Event_queue_element::load_from_row"); DBUG_ENTER("Event_queue_element::load_from_row");
if (!table) if (!table)
goto error; DBUG_RETURN(TRUE);
if (table->s->fields < ET_FIELD_COUNT) if (table->s->fields < ET_FIELD_COUNT)
goto error; DBUG_RETURN(TRUE);
if (load_string_fields(table->field, if (load_string_fields(table->field,
ET_FIELD_DB, &dbname, ET_FIELD_DB, &dbname,
...@@ -888,10 +849,10 @@ Event_queue_element::load_from_row(THD *thd, TABLE *table) ...@@ -888,10 +849,10 @@ Event_queue_element::load_from_row(THD *thd, TABLE *table)
ET_FIELD_DEFINER, &definer, ET_FIELD_DEFINER, &definer,
ET_FIELD_TIME_ZONE, &tz_name, ET_FIELD_TIME_ZONE, &tz_name,
ET_FIELD_COUNT)) ET_FIELD_COUNT))
goto error; DBUG_RETURN(TRUE);
if (load_time_zone(thd, tz_name)) if (load_time_zone(thd, tz_name))
goto error; DBUG_RETURN(TRUE);
starts_null= table->field[ET_FIELD_STARTS]->is_null(); starts_null= table->field[ET_FIELD_STARTS]->is_null();
if (!starts_null) if (!starts_null)
...@@ -921,7 +882,7 @@ Event_queue_element::load_from_row(THD *thd, TABLE *table) ...@@ -921,7 +882,7 @@ Event_queue_element::load_from_row(THD *thd, TABLE *table)
{ {
if (table->field[ET_FIELD_EXECUTE_AT]->get_date(&time, if (table->field[ET_FIELD_EXECUTE_AT]->get_date(&time,
TIME_NO_ZERO_DATE)) TIME_NO_ZERO_DATE))
goto error; DBUG_RETURN(TRUE);
execute_at= sec_since_epoch_TIME(&time); execute_at= sec_since_epoch_TIME(&time);
} }
...@@ -940,13 +901,13 @@ Event_queue_element::load_from_row(THD *thd, TABLE *table) ...@@ -940,13 +901,13 @@ Event_queue_element::load_from_row(THD *thd, TABLE *table)
table->field[ET_FIELD_TRANSIENT_INTERVAL]->val_str(&str); table->field[ET_FIELD_TRANSIENT_INTERVAL]->val_str(&str);
if (!(tmp.length= str.length())) if (!(tmp.length= str.length()))
goto error; DBUG_RETURN(TRUE);
tmp.str= str.c_ptr_safe(); tmp.str= str.c_ptr_safe();
i= find_string_in_array(interval_type_to_name, &tmp, system_charset_info); i= find_string_in_array(interval_type_to_name, &tmp, system_charset_info);
if (i < 0) if (i < 0)
goto error; DBUG_RETURN(TRUE);
interval= (interval_type) i; interval= (interval_type) i;
} }
...@@ -959,7 +920,7 @@ Event_queue_element::load_from_row(THD *thd, TABLE *table) ...@@ -959,7 +920,7 @@ Event_queue_element::load_from_row(THD *thd, TABLE *table)
last_executed_changed= FALSE; last_executed_changed= FALSE;
if ((ptr= get_field(&mem_root, table->field[ET_FIELD_STATUS])) == NullS) if ((ptr= get_field(&mem_root, table->field[ET_FIELD_STATUS])) == NullS)
goto error; DBUG_RETURN(TRUE);
DBUG_PRINT("load_from_row", ("Event [%s] is [%s]", name.str, ptr)); DBUG_PRINT("load_from_row", ("Event [%s] is [%s]", name.str, ptr));
...@@ -978,40 +939,34 @@ Event_queue_element::load_from_row(THD *thd, TABLE *table) ...@@ -978,40 +939,34 @@ Event_queue_element::load_from_row(THD *thd, TABLE *table)
break; break;
} }
if ((ptr= get_field(&mem_root, table->field[ET_FIELD_ORIGINATOR])) == NullS) if ((ptr= get_field(&mem_root, table->field[ET_FIELD_ORIGINATOR])) == NullS)
goto error; DBUG_RETURN(TRUE);
originator = table->field[ET_FIELD_ORIGINATOR]->val_int(); originator = table->field[ET_FIELD_ORIGINATOR]->val_int();
/* ToDo : Andrey . Find a way not to allocate ptr on event_mem_root */ /* ToDo : Andrey . Find a way not to allocate ptr on event_mem_root */
if ((ptr= get_field(&mem_root, if ((ptr= get_field(&mem_root,
table->field[ET_FIELD_ON_COMPLETION])) == NullS) table->field[ET_FIELD_ON_COMPLETION])) == NullS)
goto error; DBUG_RETURN(TRUE);
on_completion= (ptr[0]=='D'? Event_queue_element::ON_COMPLETION_DROP: on_completion= (ptr[0]=='D'? Event_queue_element::ON_COMPLETION_DROP:
Event_queue_element::ON_COMPLETION_PRESERVE); Event_queue_element::ON_COMPLETION_PRESERVE);
DBUG_RETURN(0); DBUG_RETURN(FALSE);
error:
DBUG_RETURN(EVEX_GET_FIELD_FAILED);
} }
/* /**
Loads an event from a row from mysql.event Load an event's body from a row from mysql.event.
SYNOPSIS
Event_timed::load_from_row(THD *thd, TABLE *table)
RETURN VALUE @details This method is silent on errors and should behave like that.
0 OK Callers should handle throwing of error messages. The reason is that the
EVEX_GET_FIELD_FAILED Error class should not know about how to deal with communication.
NOTES @return Operation status
This method is silent on errors and should behave like that. Callers @retval FALSE OK
should handle throwing of error messages. The reason is that the class @retval TRUE Error
should not know about how to deal with communication.
*/ */
int bool
Event_timed::load_from_row(THD *thd, TABLE *table) Event_timed::load_from_row(THD *thd, TABLE *table)
{ {
char *ptr; char *ptr;
...@@ -1020,12 +975,12 @@ Event_timed::load_from_row(THD *thd, TABLE *table) ...@@ -1020,12 +975,12 @@ Event_timed::load_from_row(THD *thd, TABLE *table)
DBUG_ENTER("Event_timed::load_from_row"); DBUG_ENTER("Event_timed::load_from_row");
if (Event_queue_element::load_from_row(thd, table)) if (Event_queue_element::load_from_row(thd, table))
goto error; DBUG_RETURN(TRUE);
if (load_string_fields(table->field, if (load_string_fields(table->field,
ET_FIELD_BODY, &body, ET_FIELD_BODY, &body,
ET_FIELD_COUNT)) ET_FIELD_COUNT))
goto error; DBUG_RETURN(TRUE);
ptr= strchr(definer.str, '@'); ptr= strchr(definer.str, '@');
...@@ -1052,9 +1007,7 @@ Event_timed::load_from_row(THD *thd, TABLE *table) ...@@ -1052,9 +1007,7 @@ Event_timed::load_from_row(THD *thd, TABLE *table)
sql_mode= (ulong) table->field[ET_FIELD_SQL_MODE]->val_int(); sql_mode= (ulong) table->field[ET_FIELD_SQL_MODE]->val_int();
DBUG_RETURN(0); DBUG_RETURN(FALSE);
error:
DBUG_RETURN(EVEX_GET_FIELD_FAILED);
} }
......
...@@ -77,7 +77,7 @@ class Event_basic ...@@ -77,7 +77,7 @@ class Event_basic
Event_basic(); Event_basic();
virtual ~Event_basic(); virtual ~Event_basic();
virtual int virtual bool
load_from_row(THD *thd, TABLE *table) = 0; load_from_row(THD *thd, TABLE *table) = 0;
protected: protected:
...@@ -119,7 +119,7 @@ class Event_queue_element : public Event_basic ...@@ -119,7 +119,7 @@ class Event_queue_element : public Event_basic
Event_queue_element(); Event_queue_element();
virtual ~Event_queue_element(); virtual ~Event_queue_element();
virtual int virtual bool
load_from_row(THD *thd, TABLE *table); load_from_row(THD *thd, TABLE *table);
bool bool
...@@ -157,7 +157,7 @@ class Event_timed : public Event_queue_element ...@@ -157,7 +157,7 @@ class Event_timed : public Event_queue_element
void void
init(); init();
virtual int virtual bool
load_from_row(THD *thd, TABLE *table); load_from_row(THD *thd, TABLE *table);
int int
...@@ -176,7 +176,7 @@ class Event_job_data : public Event_basic ...@@ -176,7 +176,7 @@ class Event_job_data : public Event_basic
Event_job_data(); Event_job_data();
virtual int virtual bool
load_from_row(THD *thd, TABLE *table); load_from_row(THD *thd, TABLE *table);
bool bool
...@@ -205,12 +205,11 @@ class Event_parse_data : public Sql_alloc ...@@ -205,12 +205,11 @@ class Event_parse_data : public Sql_alloc
*/ */
bool do_not_create; bool do_not_create;
const char *body_begin; bool body_changed;
LEX_STRING dbname; LEX_STRING dbname;
LEX_STRING name; LEX_STRING name;
LEX_STRING definer;// combination of user and host LEX_STRING definer;// combination of user and host
LEX_STRING body;
LEX_STRING comment; LEX_STRING comment;
Item* item_starts; Item* item_starts;
...@@ -235,9 +234,6 @@ class Event_parse_data : public Sql_alloc ...@@ -235,9 +234,6 @@ class Event_parse_data : public Sql_alloc
bool bool
check_parse_data(THD *thd); check_parse_data(THD *thd);
void
init_body(THD *thd);
private: private:
void void
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "mysql_priv.h" #include "mysql_priv.h"
#include "event_db_repository.h" #include "event_db_repository.h"
#include "sp_head.h"
#include "event_data_objects.h" #include "event_data_objects.h"
#include "events.h" #include "events.h"
#include "sql_show.h" #include "sql_show.h"
...@@ -141,7 +142,10 @@ const TABLE_FIELD_W_TYPE event_table_fields[ET_FIELD_COUNT] = ...@@ -141,7 +142,10 @@ const TABLE_FIELD_W_TYPE event_table_fields[ET_FIELD_COUNT] =
*/ */
static bool static bool
mysql_event_fill_row(THD *thd, TABLE *table, Event_parse_data *et, mysql_event_fill_row(THD *thd,
TABLE *table,
Event_parse_data *et,
sp_head *sp,
my_bool is_update) my_bool is_update)
{ {
CHARSET_INFO *scs= system_charset_info; CHARSET_INFO *scs= system_charset_info;
...@@ -152,7 +156,6 @@ mysql_event_fill_row(THD *thd, TABLE *table, Event_parse_data *et, ...@@ -152,7 +156,6 @@ mysql_event_fill_row(THD *thd, TABLE *table, Event_parse_data *et,
DBUG_PRINT("info", ("dbname=[%s]", et->dbname.str)); DBUG_PRINT("info", ("dbname=[%s]", et->dbname.str));
DBUG_PRINT("info", ("name =[%s]", et->name.str)); DBUG_PRINT("info", ("name =[%s]", et->name.str));
DBUG_PRINT("info", ("body =[%s]", et->body.str));
if (table->s->fields < ET_FIELD_COUNT) if (table->s->fields < ET_FIELD_COUNT)
{ {
...@@ -187,12 +190,19 @@ mysql_event_fill_row(THD *thd, TABLE *table, Event_parse_data *et, ...@@ -187,12 +190,19 @@ mysql_event_fill_row(THD *thd, TABLE *table, Event_parse_data *et,
Change the SQL_MODE only if body was present in an ALTER EVENT and of course Change the SQL_MODE only if body was present in an ALTER EVENT and of course
always during CREATE EVENT. always during CREATE EVENT.
*/ */
if (et->body.str) if (et->body_changed)
{ {
DBUG_ASSERT(sp->m_body.str);
fields[ET_FIELD_SQL_MODE]->store((longlong)thd->variables.sql_mode, TRUE); fields[ET_FIELD_SQL_MODE]->store((longlong)thd->variables.sql_mode, TRUE);
if (fields[f_num= ET_FIELD_BODY]->store(et->body.str, et->body.length, scs))
if (fields[f_num= ET_FIELD_BODY]->store(sp->m_body.str,
sp->m_body.length,
scs))
{
goto err_truncate; goto err_truncate;
} }
}
if (et->expression) if (et->expression)
{ {
...@@ -513,10 +523,12 @@ Event_db_repository::create_event(THD *thd, Event_parse_data *parse_data, ...@@ -513,10 +523,12 @@ Event_db_repository::create_event(THD *thd, Event_parse_data *parse_data,
{ {
int ret= 1; int ret= 1;
TABLE *table= NULL; TABLE *table= NULL;
sp_head *sp= thd->lex->sphead;
DBUG_ENTER("Event_db_repository::create_event"); DBUG_ENTER("Event_db_repository::create_event");
DBUG_PRINT("info", ("open mysql.event for update")); DBUG_PRINT("info", ("open mysql.event for update"));
DBUG_ASSERT(sp);
if (open_event_table(thd, TL_WRITE, &table)) if (open_event_table(thd, TL_WRITE, &table))
goto end; goto end;
...@@ -561,7 +573,7 @@ Event_db_repository::create_event(THD *thd, Event_parse_data *parse_data, ...@@ -561,7 +573,7 @@ Event_db_repository::create_event(THD *thd, Event_parse_data *parse_data,
goto end; goto end;
} }
if (parse_data->body.length > table->field[ET_FIELD_BODY]->field_length) if (sp->m_body.length > table->field[ET_FIELD_BODY]->field_length)
{ {
my_error(ER_TOO_LONG_BODY, MYF(0), parse_data->name.str); my_error(ER_TOO_LONG_BODY, MYF(0), parse_data->name.str);
goto end; goto end;
...@@ -573,7 +585,7 @@ Event_db_repository::create_event(THD *thd, Event_parse_data *parse_data, ...@@ -573,7 +585,7 @@ Event_db_repository::create_event(THD *thd, Event_parse_data *parse_data,
mysql_event_fill_row() calls my_error() in case of error so no need to mysql_event_fill_row() calls my_error() in case of error so no need to
handle it here handle it here
*/ */
if (mysql_event_fill_row(thd, table, parse_data, FALSE)) if (mysql_event_fill_row(thd, table, parse_data, sp, FALSE))
goto end; goto end;
table->field[ET_FIELD_STATUS]->store((longlong)parse_data->status, TRUE); table->field[ET_FIELD_STATUS]->store((longlong)parse_data->status, TRUE);
...@@ -617,7 +629,9 @@ Event_db_repository::update_event(THD *thd, Event_parse_data *parse_data, ...@@ -617,7 +629,9 @@ Event_db_repository::update_event(THD *thd, Event_parse_data *parse_data,
{ {
CHARSET_INFO *scs= system_charset_info; CHARSET_INFO *scs= system_charset_info;
TABLE *table= NULL; TABLE *table= NULL;
sp_head *sp= thd->lex->sphead;
int ret= 1; int ret= 1;
DBUG_ENTER("Event_db_repository::update_event"); DBUG_ENTER("Event_db_repository::update_event");
/* None or both must be set */ /* None or both must be set */
...@@ -661,7 +675,7 @@ Event_db_repository::update_event(THD *thd, Event_parse_data *parse_data, ...@@ -661,7 +675,7 @@ Event_db_repository::update_event(THD *thd, Event_parse_data *parse_data,
mysql_event_fill_row() calls my_error() in case of error so no need to mysql_event_fill_row() calls my_error() in case of error so no need to
handle it here handle it here
*/ */
if (mysql_event_fill_row(thd, table, parse_data, TRUE)) if (mysql_event_fill_row(thd, table, parse_data, sp, TRUE))
goto end; goto end;
if (new_dbname) if (new_dbname)
......
...@@ -1873,9 +1873,6 @@ ev_sql_stmt: ...@@ -1873,9 +1873,6 @@ ev_sql_stmt:
lex->sphead->m_chistics= &lex->sp_chistics; lex->sphead->m_chistics= &lex->sp_chistics;
lex->sphead->m_body_begin= lip->get_cpp_ptr(); lex->sphead->m_body_begin= lip->get_cpp_ptr();
lex->event_parse_data->body_begin= lip->get_cpp_ptr();
} }
ev_sql_stmt_inner ev_sql_stmt_inner
{ {
...@@ -1888,7 +1885,7 @@ ev_sql_stmt: ...@@ -1888,7 +1885,7 @@ ev_sql_stmt:
lex->sp_chistics.suid= SP_IS_SUID; //always the definer! lex->sp_chistics.suid= SP_IS_SUID; //always the definer!
lex->event_parse_data->init_body(thd); lex->event_parse_data->body_changed= TRUE;
} }
; ;
......
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