20 #include "event_parse_data.h"
37 Event_parse_data::new_instance(THD *thd)
50 Event_parse_data::Event_parse_data()
53 do_not_create(FALSE), body_changed(FALSE),
54 item_starts(NULL), item_ends(NULL), item_execute_at(NULL),
55 starts_null(TRUE), ends_null(TRUE), execute_at_null(TRUE),
56 item_expression(NULL), expression(0)
58 DBUG_ENTER(
"Event_parse_data::Event_parse_data");
61 starts= ends= execute_at= 0;
80 Event_parse_data::init_name(THD *thd,
sp_name *spn)
82 DBUG_ENTER(
"Event_parse_data::init_name");
85 dbname.length= spn->m_db.length;
86 dbname.str= thd->strmake(spn->m_db.str, spn->m_db.length);
87 name.length= spn->m_name.length;
88 name.str= thd->strmake(spn->m_name.str, spn->m_name.length);
90 if (spn->m_qname.length == 0)
114 Event_parse_data::check_if_in_the_past(THD *thd, my_time_t ltime_utc)
116 if (ltime_utc >= (my_time_t) thd->query_start())
122 if (on_completion == Event_parse_data::ON_COMPLETION_DEFAULT)
125 if (on_completion == Event_parse_data::ON_COMPLETION_DROP)
127 switch (thd->lex->sql_command) {
128 case SQLCOM_CREATE_EVENT:
129 push_warning(thd, Sql_condition::WARN_LEVEL_NOTE,
130 ER_EVENT_CANNOT_CREATE_IN_THE_PAST,
131 ER(ER_EVENT_CANNOT_CREATE_IN_THE_PAST));
133 case SQLCOM_ALTER_EVENT:
134 my_error(ER_EVENT_CANNOT_ALTER_IN_THE_PAST, MYF(0));
142 else if (status == Event_parse_data::ENABLED)
144 status= Event_parse_data::DISABLED;
145 status_changed=
true;
146 push_warning(thd, Sql_condition::WARN_LEVEL_NOTE,
147 ER_EVENT_EXEC_TIME_IN_THE_PAST,
148 ER(ER_EVENT_EXEC_TIME_IN_THE_PAST));
174 Event_parse_data::check_dates(THD *thd,
int previous_on_completion)
176 if (on_completion == Event_parse_data::ON_COMPLETION_DEFAULT)
178 on_completion= previous_on_completion;
180 check_if_in_the_past(thd, ends);
181 if (!execute_at_null)
182 check_if_in_the_past(thd, execute_at);
184 return do_not_create;
202 Event_parse_data::init_execute_at(THD *thd)
208 DBUG_ENTER(
"Event_parse_data::init_execute_at");
210 if (!item_execute_at)
213 if (item_execute_at->fix_fields(thd, &item_execute_at))
217 DBUG_PRINT(
"info", (
"starts_null && ends_null should be 1 is %d",
218 (starts_null && ends_null)));
219 DBUG_ASSERT(starts_null && ends_null);
221 if ((not_used= item_execute_at->get_date(<ime, TIME_NO_ZERO_DATE)))
224 ltime_utc= TIME_to_timestamp(thd,<ime,¬_used);
227 DBUG_PRINT(
"error", (
"Execute AT after year 2037"));
231 check_if_in_the_past(thd, ltime_utc);
233 execute_at_null= FALSE;
234 execute_at= ltime_utc;
238 report_bad_value(
"AT", item_execute_at);
239 DBUG_RETURN(ER_WRONG_VALUE);
257 Event_parse_data::init_interval(THD *thd)
262 DBUG_ENTER(
"Event_parse_data::init_interval");
263 if (!item_expression)
267 case INTERVAL_MINUTE_MICROSECOND:
268 case INTERVAL_HOUR_MICROSECOND:
269 case INTERVAL_DAY_MICROSECOND:
270 case INTERVAL_SECOND_MICROSECOND:
271 case INTERVAL_MICROSECOND:
272 my_error(ER_NOT_SUPPORTED_YET, MYF(0),
"MICROSECOND");
273 DBUG_RETURN(EVEX_BAD_PARAMS);
278 if (item_expression->fix_fields(thd, &item_expression))
281 value.alloc(MAX_DATETIME_FULL_WIDTH*MY_CHARSET_BIN_MB_MAXLEN);
289 expression= interval_tmp.year;
291 case INTERVAL_QUARTER:
293 expression= interval_tmp.month;
297 expression= interval_tmp.day;
300 expression= interval_tmp.hour;
302 case INTERVAL_MINUTE:
303 expression= interval_tmp.minute;
305 case INTERVAL_SECOND:
306 expression= interval_tmp.second;
308 case INTERVAL_YEAR_MONTH:
309 expression= interval_tmp.year* 12 + interval_tmp.month;
311 case INTERVAL_DAY_HOUR:
312 expression= interval_tmp.day* 24 + interval_tmp.hour;
314 case INTERVAL_DAY_MINUTE:
315 expression= (interval_tmp.day* 24 + interval_tmp.hour) * 60 +
318 case INTERVAL_HOUR_SECOND:
319 case INTERVAL_DAY_SECOND:
321 expression= ((interval_tmp.day* 24 + interval_tmp.hour) * 60 +
322 interval_tmp.minute)*60
323 + interval_tmp.second;
325 case INTERVAL_HOUR_MINUTE:
326 expression= interval_tmp.hour * 60 + interval_tmp.minute;
328 case INTERVAL_MINUTE_SECOND:
329 expression= interval_tmp.minute * 60 + interval_tmp.second;
336 if (interval_tmp.neg || expression == 0 ||
337 expression > EVEX_MAX_INTERVAL_VALUE)
339 my_error(ER_EVENT_INTERVAL_NOT_POSITIVE_OR_TOO_BIG, MYF(0));
340 DBUG_RETURN(EVEX_BAD_PARAMS);
346 report_bad_value(
"INTERVAL", item_expression);
347 DBUG_RETURN(ER_WRONG_VALUE);
372 Event_parse_data::init_starts(THD *thd)
378 DBUG_ENTER(
"Event_parse_data::init_starts");
382 if (item_starts->fix_fields(thd, &item_starts))
385 if ((not_used= item_starts->get_date(<ime, TIME_NO_ZERO_DATE)))
388 ltime_utc= TIME_to_timestamp(thd, <ime, ¬_used);
392 DBUG_PRINT(
"info",(
"now: %ld starts: %ld",
393 (
long) thd->query_start(), (long) ltime_utc));
400 report_bad_value(
"STARTS", item_starts);
401 DBUG_RETURN(ER_WRONG_VALUE);
426 Event_parse_data::init_ends(THD *thd)
432 DBUG_ENTER(
"Event_parse_data::init_ends");
436 if (item_ends->fix_fields(thd, &item_ends))
437 goto error_bad_params;
439 DBUG_PRINT(
"info", (
"convert to TIME"));
440 if ((not_used= item_ends->get_date(<ime, TIME_NO_ZERO_DATE)))
441 goto error_bad_params;
443 ltime_utc= TIME_to_timestamp(thd, <ime, ¬_used);
445 goto error_bad_params;
448 DBUG_PRINT(
"info", (
"ENDS after STARTS?"));
449 if (!starts_null && starts >= ltime_utc)
450 goto error_bad_params;
452 check_if_in_the_past(thd, ltime_utc);
459 my_error(ER_EVENT_ENDS_BEFORE_STARTS, MYF(0));
460 DBUG_RETURN(EVEX_BAD_PARAMS);
475 Event_parse_data::report_bad_value(
const char *item_name,
Item *bad_item)
478 String str(buff,(uint32)
sizeof(buff), system_charset_info);
479 String *str2= bad_item->fixed? bad_item->val_str(&str):NULL;
480 my_error(ER_WRONG_VALUE, MYF(0), item_name, str2? str2->c_ptr_safe():
"NULL");
497 Event_parse_data::check_parse_data(THD *thd)
500 DBUG_ENTER(
"Event_parse_data::check_parse_data");
501 DBUG_PRINT(
"info", (
"execute_at: 0x%lx expr=0x%lx starts=0x%lx ends=0x%lx",
502 (
long) item_execute_at, (
long) item_expression,
503 (
long) item_starts, (
long) item_ends));
505 init_name(thd, identifier);
509 ret= init_execute_at(thd) || init_interval(thd) || init_starts(thd) ||
511 check_originator_id(thd);
525 Event_parse_data::init_definer(THD *thd)
527 DBUG_ENTER(
"Event_parse_data::init_definer");
529 DBUG_ASSERT(thd->lex->definer);
531 const char *definer_user= thd->lex->definer->user.str;
532 const char *definer_host= thd->lex->definer->host.str;
533 size_t definer_user_len= thd->lex->definer->user.length;
534 size_t definer_host_len= thd->lex->definer->host.length;
536 DBUG_PRINT(
"info",(
"init definer_user thd->mem_root: 0x%lx "
537 "definer_user: 0x%lx", (
long) thd->mem_root,
538 (
long) definer_user));
541 DBUG_PRINT(
"info",(
"init definer as whole"));
542 definer.length= definer_user_len + definer_host_len + 1;
543 definer.str= (
char*) thd->alloc(definer.length + 1);
545 DBUG_PRINT(
"info",(
"copy the user"));
546 memcpy(definer.str, definer_user, definer_user_len);
547 definer.str[definer_user_len]=
'@';
549 DBUG_PRINT(
"info",(
"copy the host"));
550 memcpy(definer.str + definer_user_len + 1, definer_host, definer_host_len);
551 definer.str[definer.length]=
'\0';
552 DBUG_PRINT(
"info",(
"definer [%s] initted", definer.str));
566 void Event_parse_data::check_originator_id(THD *thd)
569 if ((thd->system_thread == SYSTEM_THREAD_SLAVE_SQL) ||
570 (thd->system_thread == SYSTEM_THREAD_SLAVE_WORKER) ||
571 (thd->system_thread == SYSTEM_THREAD_SLAVE_IO))
573 DBUG_PRINT(
"info", (
"Invoked object status set to SLAVESIDE_DISABLED."));
574 if ((status == Event_parse_data::ENABLED) ||
575 (status == Event_parse_data::DISABLED))
577 status= Event_parse_data::SLAVESIDE_DISABLED;
578 status_changed=
true;
580 originator = thd->server_id;
583 originator = server_id;