summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
Diffstat (limited to 'sql')
-rw-r--r--sql/event_db_repository.cc14
-rw-r--r--sql/event_parse_data.cc44
-rw-r--r--sql/event_parse_data.h10
-rw-r--r--sql/sql_yacc.yy2
4 files changed, 68 insertions, 2 deletions
diff --git a/sql/event_db_repository.cc b/sql/event_db_repository.cc
index 401f76f5d26..e33cae18cee 100644
--- a/sql/event_db_repository.cc
+++ b/sql/event_db_repository.cc
@@ -185,6 +185,8 @@ mysql_event_fill_row(THD *thd,
DBUG_PRINT("info", ("dbname=[%s]", et->dbname.str));
DBUG_PRINT("info", ("name =[%s]", et->name.str));
+ DBUG_ASSERT(et->on_completion != Event_parse_data::ON_COMPLETION_DEFAULT);
+
if (table->s->fields < ET_FIELD_COUNT)
{
/*
@@ -745,6 +747,18 @@ Event_db_repository::update_event(THD *thd, Event_parse_data *parse_data,
store_record(table,record[1]);
+ /*
+ We check whether ALTER EVENT was given dates that are in the past.
+ However to know how to react, we need the ON COMPLETION type. The
+ check is deferred to this point because by now we have the previous
+ setting (from the event-table) to fall back on if nothing was specified
+ in the ALTER EVENT-statement.
+ */
+
+ if (parse_data->check_dates(thd,
+ table->field[ET_FIELD_ON_COMPLETION]->val_int()))
+ goto end;
+
/* Don't update create on row update. */
table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
diff --git a/sql/event_parse_data.cc b/sql/event_parse_data.cc
index e87e4593f8f..df419e92d0d 100644
--- a/sql/event_parse_data.cc
+++ b/sql/event_parse_data.cc
@@ -45,7 +45,7 @@ Event_parse_data::new_instance(THD *thd)
*/
Event_parse_data::Event_parse_data()
- :on_completion(Event_parse_data::ON_COMPLETION_DROP),
+ :on_completion(Event_parse_data::ON_COMPLETION_DEFAULT),
status(Event_parse_data::ENABLED),
do_not_create(FALSE),
body_changed(FALSE),
@@ -114,6 +114,12 @@ Event_parse_data::check_if_in_the_past(THD *thd, my_time_t ltime_utc)
if (ltime_utc >= (my_time_t) thd->query_start())
return;
+ /*
+ We'll come back later when we have the real on_completion value
+ */
+ if (on_completion == Event_parse_data::ON_COMPLETION_DEFAULT)
+ return;
+
if (on_completion == Event_parse_data::ON_COMPLETION_DROP)
{
switch (thd->lex->sql_command) {
@@ -142,6 +148,42 @@ Event_parse_data::check_if_in_the_past(THD *thd, my_time_t ltime_utc)
/*
+ Check time/dates in ALTER EVENT
+
+ We check whether ALTER EVENT was given dates that are in the past.
+ However to know how to react, we need the ON COMPLETION type. Hence,
+ the check is deferred until we have the previous ON COMPLETION type
+ from the event-db to fall back on if nothing was specified in the
+ ALTER EVENT-statement.
+
+ SYNOPSIS
+ Event_parse_data::check_dates()
+ thd Thread
+ on_completion ON COMPLETION value currently in event-db.
+ Will be overridden by value in ALTER EVENT if given.
+
+ RETURN VALUE
+ TRUE an error occurred, do not ALTER
+ FALSE OK
+*/
+
+bool
+Event_parse_data::check_dates(THD *thd, int previous_on_completion)
+{
+ if (on_completion == Event_parse_data::ON_COMPLETION_DEFAULT)
+ {
+ on_completion= previous_on_completion;
+ if (!ends_null)
+ check_if_in_the_past(thd, ends);
+ if (!execute_at_null)
+ check_if_in_the_past(thd, execute_at);
+ }
+ return do_not_create;
+}
+
+
+
+/*
Sets time for execution for one-time event.
SYNOPSIS
diff --git a/sql/event_parse_data.h b/sql/event_parse_data.h
index 221bf92664f..87a800c2078 100644
--- a/sql/event_parse_data.h
+++ b/sql/event_parse_data.h
@@ -38,7 +38,12 @@ public:
enum enum_on_completion
{
- ON_COMPLETION_DROP = 1,
+ /*
+ On CREATE EVENT, DROP is the DEFAULT as per the docs.
+ On ALTER EVENT, "no change" is the DEFAULT.
+ */
+ ON_COMPLETION_DEFAULT = 0,
+ ON_COMPLETION_DROP,
ON_COMPLETION_PRESERVE
};
@@ -80,6 +85,9 @@ public:
bool
check_parse_data(THD *thd);
+ bool
+ check_dates(THD *thd, int previous_on_completion);
+
private:
void
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 54399c3791c..90dad3994c6 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -1786,6 +1786,8 @@ event_tail:
if (!(lex->event_parse_data= Event_parse_data::new_instance(thd)))
MYSQL_YYABORT;
lex->event_parse_data->identifier= $3;
+ lex->event_parse_data->on_completion=
+ Event_parse_data::ON_COMPLETION_DROP;
/*
We have to turn of CLIENT_MULTI_QUERIES while parsing a