summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
Diffstat (limited to 'sql')
-rw-r--r--sql/CMakeLists.txt2
-rw-r--r--sql/Makefile.am6
-rw-r--r--sql/event_executor.cc15
-rw-r--r--sql/event_scheduler.cc53
-rw-r--r--sql/event_scheduler.h11
-rw-r--r--sql/event_timed.cc11
-rw-r--r--sql/event_timed.h (renamed from sql/event.h)85
-rw-r--r--sql/events.cc (renamed from sql/event.cc)99
-rw-r--r--sql/events.h97
-rw-r--r--sql/events_priv.h (renamed from sql/event_priv.h)9
-rw-r--r--sql/mysql_priv.h4
-rw-r--r--sql/mysqld.cc2
-rw-r--r--sql/sql_db.cc2
-rw-r--r--sql/sql_parse.cc12
-rw-r--r--sql/sql_show.cc110
-rw-r--r--sql/sql_yacc.yy2
-rw-r--r--sql/time.cc56
17 files changed, 318 insertions, 258 deletions
diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt
index fe6c54b2391..9a97b79813b 100644
--- a/sql/CMakeLists.txt
+++ b/sql/CMakeLists.txt
@@ -52,7 +52,7 @@ ADD_EXECUTABLE(mysqld ../sql-common/client.c derror.cc des_key_file.cc
sql_update.cc sql_view.cc strfunc.cc table.cc thr_malloc.cc
time.cc tztime.cc uniques.cc unireg.cc item_xmlfunc.cc
rpl_tblmap.cc sql_binlog.cc event_scheduler.cc event_timed.cc
- sql_tablespace.cc event.cc ../sql-common/my_user.c
+ sql_tablespace.cc events.cc ../sql-common/my_user.c
partition_info.cc rpl_injector.cc
${PROJECT_SOURCE_DIR}/sql/sql_yacc.cc
${PROJECT_SOURCE_DIR}/sql/sql_yacc.h
diff --git a/sql/Makefile.am b/sql/Makefile.am
index ffc5b2c2573..387f18c2ae9 100644
--- a/sql/Makefile.am
+++ b/sql/Makefile.am
@@ -64,8 +64,8 @@ noinst_HEADERS = item.h item_func.h item_sum.h item_cmpfunc.h \
tztime.h my_decimal.h\
sp_head.h sp_pcontext.h sp_rcontext.h sp.h sp_cache.h \
parse_file.h sql_view.h sql_trigger.h \
- sql_array.h sql_cursor.h event.h event_priv.h \
- sql_plugin.h authors.h sql_partition.h \
+ sql_array.h sql_cursor.h events.h events_priv.h \
+ sql_plugin.h authors.h sql_partition.h event_timed.h \
partition_info.h partition_element.h event_scheduler.h \
contributors.h
mysqld_SOURCES = sql_lex.cc sql_handler.cc sql_partition.cc \
@@ -104,7 +104,7 @@ mysqld_SOURCES = sql_lex.cc sql_handler.cc sql_partition.cc \
tztime.cc my_time.c my_user.c my_decimal.cc\
sp_head.cc sp_pcontext.cc sp_rcontext.cc sp.cc \
sp_cache.cc parse_file.cc sql_trigger.cc \
- event_scheduler.cc event.cc event_timed.cc \
+ event_scheduler.cc events.cc event_timed.cc \
sql_plugin.cc sql_binlog.cc \
sql_builtin.cc sql_tablespace.cc partition_info.cc
diff --git a/sql/event_executor.cc b/sql/event_executor.cc
deleted file mode 100644
index f236fb47771..00000000000
--- a/sql/event_executor.cc
+++ /dev/null
@@ -1,15 +0,0 @@
-/* Copyright (C) 2004-2005 MySQL AB
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
diff --git a/sql/event_scheduler.cc b/sql/event_scheduler.cc
index db855e9135b..1b4a0d290e6 100644
--- a/sql/event_scheduler.cc
+++ b/sql/event_scheduler.cc
@@ -14,8 +14,10 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-#include "event_priv.h"
-#include "event.h"
+#include "mysql_priv.h"
+#include "events_priv.h"
+#include "events.h"
+#include "event_timed.h"
#include "event_scheduler.h"
#include "sp_head.h"
@@ -46,8 +48,8 @@
The scheduler only manages execution of the events. Their creation,
alteration and deletion is delegated to other routines found in event.cc .
These routines interact with the scheduler :
- - CREATE EVENT -> Event_scheduler::add_event()
- - ALTER EVENT -> Event_scheduler::replace_event()
+ - CREATE EVENT -> Event_scheduler::create_event()
+ - ALTER EVENT -> Event_scheduler::update_event()
- DROP EVENT -> Event_scheduler::drop_event()
There is one mutex in the single Event_scheduler object which controls
@@ -299,6 +301,35 @@ public:
/*
+ Compares the execute_at members of 2 Event_timed instances.
+ Used as callback for the prioritized queue when shifting
+ elements inside.
+
+ SYNOPSIS
+ event_timed_compare_q()
+
+ vptr - not used (set it to NULL)
+ a - first Event_timed object
+ b - second Event_timed object
+
+ RETURN VALUE
+ -1 - a->execute_at < b->execute_at
+ 0 - a->execute_at == b->execute_at
+ 1 - a->execute_at > b->execute_at
+
+ NOTES
+ execute_at.second_part is not considered during comparison
+*/
+
+static int
+event_timed_compare_q(void *vptr, byte* a, byte *b)
+{
+ return my_time_compare(&((Event_timed *)a)->execute_at,
+ &((Event_timed *)b)->execute_at);
+}
+
+
+/*
Prints the stack of infos, warnings, errors from thd to
the console so it can be fetched by the logs-into-tables and
checked later.
@@ -740,10 +771,10 @@ Event_scheduler::destroy()
/*
- Adds an event to the scheduler queue
+ Creates an event in the scheduler queue
SYNOPSIS
- Event_scheduler::add_event()
+ Event_scheduler::create_event()
et The event to add
check_existence Whether to check if already loaded.
@@ -753,11 +784,11 @@ Event_scheduler::destroy()
*/
enum Event_scheduler::enum_error_code
-Event_scheduler::add_event(THD *thd, Event_timed *et, bool check_existence)
+Event_scheduler::create_event(THD *thd, Event_timed *et, bool check_existence)
{
enum enum_error_code res;
Event_timed *et_new;
- DBUG_ENTER("Event_scheduler::add_event");
+ DBUG_ENTER("Event_scheduler::create_event");
DBUG_PRINT("enter", ("thd=%p et=%p lock=%p",thd,et,&LOCK_scheduler_data));
LOCK_SCHEDULER_DATA();
@@ -859,7 +890,7 @@ Event_scheduler::drop_event(THD *thd, Event_timed *et)
/*
- Replaces an event in the scheduler queue
+ Updates an event from the scheduler queue
SYNOPSIS
Event_scheduler::replace_event()
@@ -873,7 +904,7 @@ Event_scheduler::drop_event(THD *thd, Event_timed *et)
*/
enum Event_scheduler::enum_error_code
-Event_scheduler::replace_event(THD *thd, Event_timed *et,
+Event_scheduler::update_event(THD *thd, Event_timed *et,
LEX_STRING *new_schema,
LEX_STRING *new_name)
{
@@ -886,7 +917,7 @@ Event_scheduler::replace_event(THD *thd, Event_timed *et,
LINT_INIT(old_name.str);
LINT_INIT(old_name.length);
- DBUG_ENTER("Event_scheduler::replace_event");
+ DBUG_ENTER("Event_scheduler::update_event");
DBUG_PRINT("enter", ("thd=%p et=%p et=[%s.%s] lock=%p",
thd, et, et->dbname.str, et->name.str, &LOCK_scheduler_data));
diff --git a/sql/event_scheduler.h b/sql/event_scheduler.h
index dffd47539fa..5ae310bab2a 100644
--- a/sql/event_scheduler.h
+++ b/sql/event_scheduler.h
@@ -16,6 +16,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+class Event_timed;
class THD;
typedef bool * (*event_timed_identifier_comparator)(Event_timed*, Event_timed*);
@@ -26,7 +27,6 @@ events_init();
void
events_shutdown();
-
class Event_scheduler
{
public:
@@ -66,14 +66,15 @@ public:
/* Methods for queue management follow */
enum enum_error_code
- add_event(THD *thd, Event_timed *et, bool check_existence);
+ create_event(THD *thd, Event_timed *et, bool check_existence);
+
+ enum enum_error_code
+ update_event(THD *thd, Event_timed *et, LEX_STRING *new_schema,
+ LEX_STRING *new_name);
bool
drop_event(THD *thd, Event_timed *et);
- enum enum_error_code
- replace_event(THD *thd, Event_timed *et, LEX_STRING *new_schema,
- LEX_STRING *new_name);
int
drop_schema_events(THD *thd, LEX_STRING *schema);
diff --git a/sql/event_timed.cc b/sql/event_timed.cc
index d6d6dddf971..4ec875f32a3 100644
--- a/sql/event_timed.cc
+++ b/sql/event_timed.cc
@@ -15,8 +15,10 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#define MYSQL_LEX 1
-#include "event_priv.h"
-#include "event.h"
+#include "mysql_priv.h"
+#include "events_priv.h"
+#include "events.h"
+#include "event_timed.h"
#include "sp_head.h"
@@ -395,6 +397,8 @@ Event_timed::init_interval(THD *thd, Item *expr, interval_type new_interval)
break;
case INTERVAL_MICROSECOND:
DBUG_RETURN(EVEX_MICROSECOND_UNSUP);
+ case INTERVAL_LAST:
+ DBUG_ASSERT(0);
}
if (interval_tmp.neg || expression > EVEX_MAX_INTERVAL_VALUE)
DBUG_RETURN(EVEX_BAD_PARAMS);
@@ -834,6 +838,8 @@ bool get_next_time(TIME *next, TIME *start, TIME *time_now, TIME *last_exec,
*/
DBUG_RETURN(1);
break;
+ case INTERVAL_LAST:
+ DBUG_ASSERT(0);
}
DBUG_PRINT("info", ("seconds=%ld months=%ld", seconds, months));
if (seconds)
@@ -1279,7 +1285,6 @@ done:
DBUG_RETURN(ret);
}
-extern LEX_STRING interval_type_to_name[];
/*
Get SHOW CREATE EVENT as string
diff --git a/sql/event.h b/sql/event_timed.h
index 02c5fa78150..0652cece361 100644
--- a/sql/event.h
+++ b/sql/event_timed.h
@@ -1,5 +1,5 @@
-#ifndef _EVENT_H_
-#define _EVENT_H_
+#ifndef _EVENT_TIMED_H_
+#define _EVENT_TIMED_H_
/* Copyright (C) 2004-2006 MySQL AB
This program is free software; you can redistribute it and/or modify
@@ -17,7 +17,6 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-
#define EVEX_OK 0
#define EVEX_KEY_NOT_FOUND -1
#define EVEX_OPEN_TABLE_FAILED -2
@@ -40,83 +39,6 @@
#define EVENT_NOT_USED (1L << 1)
#define EVENT_FREE_WHEN_FINISHED (1L << 2)
-class Event_timed;
-
-class Events
-{
-public:
- static ulong opt_event_scheduler;
- static TYPELIB opt_typelib;
-
- enum enum_table_field
- {
- FIELD_DB = 0,
- FIELD_NAME,
- FIELD_BODY,
- FIELD_DEFINER,
- FIELD_EXECUTE_AT,
- FIELD_INTERVAL_EXPR,
- FIELD_TRANSIENT_INTERVAL,
- FIELD_CREATED,
- FIELD_MODIFIED,
- FIELD_LAST_EXECUTED,
- FIELD_STARTS,
- FIELD_ENDS,
- FIELD_STATUS,
- FIELD_ON_COMPLETION,
- FIELD_SQL_MODE,
- FIELD_COMMENT,
- FIELD_COUNT /* a cool trick to count the number of fields :) */
- };
-
- static int
- create_event(THD *thd, Event_timed *et, uint create_options,
- uint *rows_affected);
-
- static int
- update_event(THD *thd, Event_timed *et, sp_name *new_name,
- uint *rows_affected);
-
- static int
- drop_event(THD *thd, Event_timed *et, bool drop_if_exists,
- uint *rows_affected);
-
- static int
- open_event_table(THD *thd, enum thr_lock_type lock_type, TABLE **table);
-
- static int
- show_create_event(THD *thd, sp_name *spn);
-
- static int
- reconstruct_interval_expression(String *buf, interval_type interval,
- longlong expression);
-
- static int
- drop_schema_events(THD *thd, char *db);
-
- static int
- dump_internal_status(THD *thd);
-
- static int
- init();
-
- static void
- shutdown();
-
- static void
- init_mutexes();
-
- static void
- destroy_mutexes();
-
-
-private:
- /* Prevent use of these */
- Events(const Events &);
- void operator=(Events &);
-};
-
-
class sp_head;
@@ -291,6 +213,5 @@ public:
void
set_thread_id(ulong tid) { thread_id= tid; }
};
-
-
+
#endif /* _EVENT_H_ */
diff --git a/sql/event.cc b/sql/events.cc
index 2e78ef3e3d8..d67c42326e3 100644
--- a/sql/event.cc
+++ b/sql/events.cc
@@ -14,8 +14,10 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-#include "event_priv.h"
-#include "event.h"
+#include "mysql_priv.h"
+#include "events_priv.h"
+#include "events.h"
+#include "event_timed.h"
#include "event_scheduler.h"
#include "sp.h"
#include "sp_head.h"
@@ -160,35 +162,11 @@ TABLE_FIELD_W_TYPE event_table_fields[Events::FIELD_COUNT] = {
};
-LEX_STRING interval_type_to_name[] = {
- {(char *) STRING_WITH_LEN("YEAR")},
- {(char *) STRING_WITH_LEN("QUARTER")},
- {(char *) STRING_WITH_LEN("MONTH")},
- {(char *) STRING_WITH_LEN("DAY")},
- {(char *) STRING_WITH_LEN("HOUR")},
- {(char *) STRING_WITH_LEN("MINUTE")},
- {(char *) STRING_WITH_LEN("WEEK")},
- {(char *) STRING_WITH_LEN("SECOND")},
- {(char *) STRING_WITH_LEN("MICROSECOND")},
- {(char *) STRING_WITH_LEN("YEAR_MONTH")},
- {(char *) STRING_WITH_LEN("DAY_HOUR")},
- {(char *) STRING_WITH_LEN("DAY_MINUTE")},
- {(char *) STRING_WITH_LEN("DAY_SECOND")},
- {(char *) STRING_WITH_LEN("HOUR_MINUTE")},
- {(char *) STRING_WITH_LEN("HOUR_SECOND")},
- {(char *) STRING_WITH_LEN("MINUTE_SECOND")},
- {(char *) STRING_WITH_LEN("DAY_MICROSECOND")},
- {(char *) STRING_WITH_LEN("HOUR_MICROSECOND")},
- {(char *) STRING_WITH_LEN("MINUTE_MICROSECOND")},
- {(char *) STRING_WITH_LEN("SECOND_MICROSECOND")}
-};
-
-
/*
Compares 2 LEX strings regarding case.
SYNOPSIS
- my_time_compare()
+ sortcmp_lex_string()
s - first LEX_STRING
t - second LEX_STRING
@@ -211,68 +189,6 @@ int sortcmp_lex_string(LEX_STRING s, LEX_STRING t, CHARSET_INFO *cs)
/*
- Compares 2 TIME structures
-
- SYNOPSIS
- my_time_compare()
-
- a - first TIME
- b - second time
-
- RETURN VALUE
- -1 - a < b
- 0 - a == b
- 1 - a > b
-
- NOTES
- TIME.second_part is not considered during comparison
-*/
-
-int
-my_time_compare(TIME *a, TIME *b)
-{
- my_ulonglong a_t= TIME_to_ulonglong_datetime(a);
- my_ulonglong b_t= TIME_to_ulonglong_datetime(b);
-
- if (a_t > b_t)
- return 1;
- else if (a_t < b_t)
- return -1;
-
- return 0;
-}
-
-
-/*
- Compares the execute_at members of 2 Event_timed instances.
- Used as callback for the prioritized queue when shifting
- elements inside.
-
- SYNOPSIS
- event_timed_compare()
-
- vptr - not used (set it to NULL)
- a - first Event_timed object
- b - second Event_timed object
-
- RETURNS:
- -1 - a->execute_at < b->execute_at
- 0 - a->execute_at == b->execute_at
- 1 - a->execute_at > b->execute_at
-
- Notes
- execute_at.second_part is not considered during comparison
-*/
-
-int
-event_timed_compare_q(void *vptr, byte* a, byte *b)
-{
- return my_time_compare(&((Event_timed *)a)->execute_at,
- &((Event_timed *)b)->execute_at);
-}
-
-
-/*
Reconstructs interval expression from interval type and expression
value that is in form of a value of the smalles entity:
For
@@ -1002,7 +918,8 @@ Events::create_event(THD *thd, Event_timed *et, uint create_options,
rows_affected)))
{
Event_scheduler *scheduler= Event_scheduler::get_instance();
- if (scheduler->initialized() && (ret= scheduler->add_event(thd, et, true)))
+ if (scheduler->initialized() &&
+ (ret= scheduler->create_event(thd, et, true)))
my_error(ER_EVENT_MODIFY_QUEUE_ERROR, MYF(0), ret);
}
/* No need to close the table, it will be closed in sql_parse::do_command */
@@ -1047,7 +964,7 @@ Events::update_event(THD *thd, Event_timed *et, sp_name *new_name,
{
Event_scheduler *scheduler= Event_scheduler::get_instance();
if (scheduler->initialized() &&
- (ret= scheduler->replace_event(thd, et,
+ (ret= scheduler->update_event(thd, et,
new_name? &new_name->m_db: NULL,
new_name? &new_name->m_name: NULL)))
my_error(ER_EVENT_MODIFY_QUEUE_ERROR, MYF(0), ret);
diff --git a/sql/events.h b/sql/events.h
new file mode 100644
index 00000000000..66cce6e7777
--- /dev/null
+++ b/sql/events.h
@@ -0,0 +1,97 @@
+#ifndef _EVENT_H_
+#define _EVENT_H_
+/* Copyright (C) 2004-2006 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+
+class Event_timed;
+
+class Events
+{
+public:
+ static ulong opt_event_scheduler;
+ static TYPELIB opt_typelib;
+
+ enum enum_table_field
+ {
+ FIELD_DB = 0,
+ FIELD_NAME,
+ FIELD_BODY,
+ FIELD_DEFINER,
+ FIELD_EXECUTE_AT,
+ FIELD_INTERVAL_EXPR,
+ FIELD_TRANSIENT_INTERVAL,
+ FIELD_CREATED,
+ FIELD_MODIFIED,
+ FIELD_LAST_EXECUTED,
+ FIELD_STARTS,
+ FIELD_ENDS,
+ FIELD_STATUS,
+ FIELD_ON_COMPLETION,
+ FIELD_SQL_MODE,
+ FIELD_COMMENT,
+ FIELD_COUNT /* a cool trick to count the number of fields :) */
+ };
+
+ static int
+ create_event(THD *thd, Event_timed *et, uint create_options,
+ uint *rows_affected);
+
+ static int
+ update_event(THD *thd, Event_timed *et, sp_name *new_name,
+ uint *rows_affected);
+
+ static int
+ drop_event(THD *thd, Event_timed *et, bool drop_if_exists,
+ uint *rows_affected);
+
+ static int
+ open_event_table(THD *thd, enum thr_lock_type lock_type, TABLE **table);
+
+ static int
+ show_create_event(THD *thd, sp_name *spn);
+
+ static int
+ reconstruct_interval_expression(String *buf, interval_type interval,
+ longlong expression);
+
+ static int
+ drop_schema_events(THD *thd, char *db);
+
+ static int
+ dump_internal_status(THD *thd);
+
+ static int
+ init();
+
+ static void
+ shutdown();
+
+ static void
+ init_mutexes();
+
+ static void
+ destroy_mutexes();
+
+
+private:
+ /* Prevent use of these */
+ Events(const Events &);
+ void operator=(Events &);
+};
+
+
+#endif /* _EVENT_H_ */
diff --git a/sql/event_priv.h b/sql/events_priv.h
index 43ef30a659f..ed02cb7055b 100644
--- a/sql/event_priv.h
+++ b/sql/events_priv.h
@@ -16,9 +16,6 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-#include "mysql_priv.h"
-
-
#define EVENT_EXEC_STARTED 0
#define EVENT_EXEC_ALREADY_EXEC 1
#define EVENT_EXEC_CANT_FORK 2
@@ -27,8 +24,7 @@
#define EVEX_NAME_FIELD_LEN 64
#define EVEX_MAX_INTERVAL_VALUE 2147483647L
-int
-my_time_compare(TIME *a, TIME *b);
+class Event_timed;
int
evex_db_find_event_by_name(THD *thd, const LEX_STRING dbname,
@@ -36,9 +32,6 @@ evex_db_find_event_by_name(THD *thd, const LEX_STRING dbname,
TABLE *table);
int
-event_timed_compare_q(void *vptr, byte* a, byte *b);
-
-int
db_drop_event(THD *thd, Event_timed *et, bool drop_if_exists,
uint *rows_affected);
int
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index e3d28a23c15..72fd60169fd 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -1759,6 +1759,8 @@ bool date_add_interval(TIME *ltime, interval_type int_type, INTERVAL interval);
bool calc_time_diff(TIME *l_time1, TIME *l_time2, int l_sign,
longlong *seconds_out, long *microseconds_out);
+extern LEX_STRING interval_type_to_name[];
+
extern DATE_TIME_FORMAT *date_time_format_make(timestamp_type format_type,
const char *format_str,
uint format_length);
@@ -1774,6 +1776,7 @@ void make_date(const DATE_TIME_FORMAT *format, const TIME *l_time,
String *str);
void make_time(const DATE_TIME_FORMAT *format, const TIME *l_time,
String *str);
+int my_time_compare(TIME *a, TIME *b);
int test_if_number(char *str,int *res,bool allow_wildcards);
void change_byte(byte *,uint,char,char);
@@ -1791,6 +1794,7 @@ void filesort_free_buffers(TABLE *table);
void change_double_for_sort(double nr,byte *to);
double my_double_round(double value, int dec, bool truncate);
int get_quick_record(SQL_SELECT *select);
+
int calc_weekday(long daynr,bool sunday_first_day_of_week);
uint calc_week(TIME *l_time, uint week_behaviour, uint *year);
void find_date(char *pos,uint *vek,uint flag);
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 6063eb170b2..4ab1b365f73 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -24,7 +24,7 @@
#include "stacktrace.h"
#include "mysqld_suffix.h"
#include "mysys_err.h"
-#include "event.h"
+#include "events.h"
#include "ha_myisam.h"
diff --git a/sql/sql_db.cc b/sql/sql_db.cc
index 11c892fee44..8dd62fc8494 100644
--- a/sql/sql_db.cc
+++ b/sql/sql_db.cc
@@ -20,7 +20,7 @@
#include "mysql_priv.h"
#include <mysys_err.h>
#include "sp.h"
-#include "event.h"
+#include "events.h"
#include <my_dir.h>
#include <m_ctype.h>
#ifdef __WIN__
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index ea4eea19e34..d2d32caa7c8 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -26,7 +26,8 @@
#include "sp_head.h"
#include "sp.h"
#include "sp_cache.h"
-#include "event.h"
+#include "events.h"
+#include "event_timed.h"
#ifdef HAVE_OPENSSL
/*
@@ -3835,7 +3836,9 @@ end_with_restore_list:
uint rows_affected= 1;
DBUG_ASSERT(lex->et);
do {
- if (! lex->et->dbname.str)
+ if (! lex->et->dbname.str ||
+ (lex->sql_command == SQLCOM_ALTER_EVENT && lex->spname &&
+ !lex->spname->m_db.str))
{
my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0));
res= true;
@@ -3843,7 +3846,10 @@ end_with_restore_list:
}
if (check_access(thd, EVENT_ACL, lex->et->dbname.str, 0, 0, 0,
- is_schema_db(lex->et->dbname.str)))
+ is_schema_db(lex->et->dbname.str)) ||
+ (lex->sql_command == SQLCOM_ALTER_EVENT && lex->spname &&
+ (check_access(thd, EVENT_ACL, lex->spname->m_db.str, 0, 0, 0,
+ is_schema_db(lex->spname->m_db.str)))))
break;
if (end_active_trans(thd))
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 2071b08ae26..8f8c84c2db5 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -26,13 +26,38 @@
#include "sql_trigger.h"
#include "authors.h"
#include "contributors.h"
-#include "event.h"
+#include "events.h"
+#include "event_timed.h"
#include <my_dir.h>
#ifdef WITH_PARTITION_STORAGE_ENGINE
#include "ha_partition.h"
#endif
+enum enum_i_s_events_fields
+{
+ ISE_EVENT_CATALOG= 0,
+ ISE_EVENT_SCHEMA,
+ ISE_EVENT_NAME,
+ ISE_DEFINER,
+ ISE_EVENT_BODY,
+ ISE_EVENT_DEFINITION,
+ ISE_EVENT_TYPE,
+ ISE_EXECUTE_AT,
+ ISE_INTERVAL_VALUE,
+ ISE_INTERVAL_FIELD,
+ ISE_SQL_MODE,
+ ISE_STARTS,
+ ISE_ENDS,
+ ISE_STATUS,
+ ISE_ON_COMPLETION,
+ ISE_CREATED,
+ ISE_LAST_ALTERED,
+ ISE_LAST_EXECUTED,
+ ISE_EVENT_COMMENT
+};
+
+
static const char *grant_names[]={
"select","insert","update","delete","create","drop","reload","shutdown",
"process","file","grant","references","index","alter"};
@@ -4116,6 +4141,8 @@ static interval_type get_real_interval_type(interval_type i_type)
case INTERVAL_SECOND_MICROSECOND:
case INTERVAL_MICROSECOND:
return INTERVAL_MICROSECOND;
+ case INTERVAL_LAST:
+ DBUG_ASSERT(0);
}
DBUG_ASSERT(0);
return INTERVAL_SECOND;
@@ -4171,85 +4198,101 @@ copy_event_to_schema_table(THD *thd, TABLE *sch_table, TABLE *event_table)
/* ->field[0] is EVENT_CATALOG and is by default NULL */
- sch_table->field[1]->store(et.dbname.str, et.dbname.length, scs);
- sch_table->field[2]->store(et.name.str, et.name.length, scs);
- sch_table->field[3]->store(et.definer.str, et.definer.length, scs);
- sch_table->field[4]->store(et.body.str, et.body.length, scs);
-
- /* [9] is SQL_MODE */
+ sch_table->field[ISE_EVENT_SCHEMA]->
+ store(et.dbname.str, et.dbname.length,scs);
+ sch_table->field[ISE_EVENT_NAME]->
+ store(et.name.str, et.name.length, scs);
+ sch_table->field[ISE_DEFINER]->
+ store(et.definer.str, et.definer.length, scs);
+ sch_table->field[ISE_EVENT_BODY]->
+ store(STRING_WITH_LEN("SQL"), scs);
+ sch_table->field[ISE_EVENT_DEFINITION]->
+ store(et.body.str, et.body.length, scs);
+
+ /* SQL_MODE */
{
byte *sql_mode_str;
- ulong sql_mode_len=0;
+ ulong sql_mode_len= 0;
sql_mode_str=
sys_var_thd_sql_mode::symbolic_mode_representation(thd, et.sql_mode,
&sql_mode_len);
- sch_table->field[9]->store((const char*)sql_mode_str, sql_mode_len, scs);
+ sch_table->field[ISE_SQL_MODE]->
+ store((const char*)sql_mode_str, sql_mode_len, scs);
}
if (et.expression)
{
String show_str;
/* type */
- sch_table->field[5]->store(STRING_WITH_LEN("RECURRING"), scs);
+ sch_table->field[ISE_EVENT_TYPE]->store(STRING_WITH_LEN("RECURRING"), scs);
if (Events::reconstruct_interval_expression(&show_str, et.interval,
et.expression))
DBUG_RETURN(1);
- sch_table->field[7]->set_notnull();
- sch_table->field[7]->store(show_str.ptr(), show_str.length(), scs);
+ sch_table->field[ISE_INTERVAL_VALUE]->set_notnull();
+ sch_table->field[ISE_INTERVAL_VALUE]->
+ store(show_str.ptr(), show_str.length(), scs);
LEX_STRING *ival= &interval_type_to_name[et.interval];
- sch_table->field[8]->set_notnull();
- sch_table->field[8]->store(ival->str, ival->length, scs);
+ sch_table->field[ISE_INTERVAL_FIELD]->set_notnull();
+ sch_table->field[ISE_INTERVAL_FIELD]->store(ival->str, ival->length, scs);
- /* starts & ends */
- sch_table->field[10]->set_notnull();
- sch_table->field[10]->store_time(&et.starts, MYSQL_TIMESTAMP_DATETIME);
+ /* starts & ends . STARTS is always set - see sql_yacc.yy */
+ sch_table->field[ISE_STARTS]->set_notnull();
+ sch_table->field[ISE_STARTS]->
+ store_time(&et.starts, MYSQL_TIMESTAMP_DATETIME);
if (!et.ends_null)
{
- sch_table->field[11]->set_notnull();
- sch_table->field[11]->store_time(&et.ends, MYSQL_TIMESTAMP_DATETIME);
+ sch_table->field[ISE_ENDS]->set_notnull();
+ sch_table->field[ISE_ENDS]->
+ store_time(&et.ends, MYSQL_TIMESTAMP_DATETIME);
}
}
else
{
- //type
- sch_table->field[5]->store(STRING_WITH_LEN("ONE TIME"), scs);
+ /* type */
+ sch_table->field[ISE_EVENT_TYPE]->store(STRING_WITH_LEN("ONE TIME"), scs);
- sch_table->field[6]->set_notnull();
- sch_table->field[6]->store_time(&et.execute_at, MYSQL_TIMESTAMP_DATETIME);
+ sch_table->field[ISE_EXECUTE_AT]->set_notnull();
+ sch_table->field[ISE_EXECUTE_AT]->
+ store_time(&et.execute_at, MYSQL_TIMESTAMP_DATETIME);
}
/* status */
if (et.status == Event_timed::ENABLED)
- sch_table->field[12]->store(STRING_WITH_LEN("ENABLED"), scs);
+ sch_table->field[ISE_STATUS]->store(STRING_WITH_LEN("ENABLED"), scs);
else
- sch_table->field[12]->store(STRING_WITH_LEN("DISABLED"), scs);
+ sch_table->field[ISE_STATUS]->store(STRING_WITH_LEN("DISABLED"), scs);
/* on_completion */
if (et.on_completion == Event_timed::ON_COMPLETION_DROP)
- sch_table->field[13]->store(STRING_WITH_LEN("NOT PRESERVE"), scs);
+ sch_table->field[ISE_ON_COMPLETION]->
+ store(STRING_WITH_LEN("NOT PRESERVE"), scs);
else
- sch_table->field[13]->store(STRING_WITH_LEN("PRESERVE"), scs);
+ sch_table->field[ISE_ON_COMPLETION]->
+ store(STRING_WITH_LEN("PRESERVE"), scs);
int not_used=0;
number_to_datetime(et.created, &time, 0, &not_used);
DBUG_ASSERT(not_used==0);
- sch_table->field[14]->store_time(&time, MYSQL_TIMESTAMP_DATETIME);
+ sch_table->field[ISE_CREATED]->store_time(&time, MYSQL_TIMESTAMP_DATETIME);
number_to_datetime(et.modified, &time, 0, &not_used);
DBUG_ASSERT(not_used==0);
- sch_table->field[15]->store_time(&time, MYSQL_TIMESTAMP_DATETIME);
+ sch_table->field[ISE_LAST_ALTERED]->
+ store_time(&time, MYSQL_TIMESTAMP_DATETIME);
if (et.last_executed.year)
{
- sch_table->field[16]->set_notnull();
- sch_table->field[16]->store_time(&et.last_executed,MYSQL_TIMESTAMP_DATETIME);
+ sch_table->field[ISE_LAST_EXECUTED]->set_notnull();
+ sch_table->field[ISE_LAST_EXECUTED]->
+ store_time(&et.last_executed, MYSQL_TIMESTAMP_DATETIME);
}
- sch_table->field[17]->store(et.comment.str, et.comment.length, scs);
+ sch_table->field[ISE_EVENT_COMMENT]->
+ store(et.comment.str, et.comment.length, scs);
if (schema_table_store_record(thd, sch_table))
DBUG_RETURN(1);
@@ -5173,7 +5216,8 @@ ST_FIELD_INFO events_fields_info[]=
{"EVENT_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, "Db"},
{"EVENT_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, "Name"},
{"DEFINER", 77, MYSQL_TYPE_STRING, 0, 0, "Definer"},
- {"EVENT_BODY", 65535, MYSQL_TYPE_STRING, 0, 0, 0},
+ {"EVENT_BODY", 8, MYSQL_TYPE_STRING, 0, 0, 0},
+ {"EVENT_DEFINITION", 65535, MYSQL_TYPE_STRING, 0, 0, 0},
{"EVENT_TYPE", 9, MYSQL_TYPE_STRING, 0, 0, "Type"},
{"EXECUTE_AT", 0, MYSQL_TYPE_TIMESTAMP, 0, 1, "Execute at"},
{"INTERVAL_VALUE", 256, MYSQL_TYPE_STRING, 0, 1, "Interval value"},
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 277078580a8..0632e2298cd 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -38,7 +38,7 @@
#include "sp_pcontext.h"
#include "sp_rcontext.h"
#include "sp.h"
-#include "event.h"
+#include "event_timed.h"
#include <myisam.h>
#include <myisammrg.h>
diff --git a/sql/time.cc b/sql/time.cc
index be1e4f10825..ae776a32aab 100644
--- a/sql/time.cc
+++ b/sql/time.cc
@@ -24,6 +24,30 @@
/* Some functions to calculate dates */
#ifndef TESTTIME
+
+LEX_STRING interval_type_to_name[INTERVAL_LAST] = {
+ { C_STRING_WITH_LEN("YEAR")},
+ { C_STRING_WITH_LEN("QUARTER")},
+ { C_STRING_WITH_LEN("MONTH")},
+ { C_STRING_WITH_LEN("DAY")},
+ { C_STRING_WITH_LEN("HOUR")},
+ { C_STRING_WITH_LEN("MINUTE")},
+ { C_STRING_WITH_LEN("WEEK")},
+ { C_STRING_WITH_LEN("SECOND")},
+ { C_STRING_WITH_LEN("MICROSECOND")},
+ { C_STRING_WITH_LEN("YEAR_MONTH")},
+ { C_STRING_WITH_LEN("DAY_HOUR")},
+ { C_STRING_WITH_LEN("DAY_MINUTE")},
+ { C_STRING_WITH_LEN("DAY_SECOND")},
+ { C_STRING_WITH_LEN("HOUR_MINUTE")},
+ { C_STRING_WITH_LEN("HOUR_SECOND")},
+ { C_STRING_WITH_LEN("MINUTE_SECOND")},
+ { C_STRING_WITH_LEN("DAY_MICROSECOND")},
+ { C_STRING_WITH_LEN("HOUR_MICROSECOND")},
+ { C_STRING_WITH_LEN("MINUTE_MICROSECOND")},
+ { C_STRING_WITH_LEN("SECOND_MICROSECOND")}
+};
+
/* Calc weekday from daynr */
/* Returns 0 for monday, 1 for tuesday .... */
@@ -910,4 +934,36 @@ calc_time_diff(TIME *l_time1, TIME *l_time2, int l_sign, longlong *seconds_out,
}
+/*
+ Compares 2 TIME structures
+
+ SYNOPSIS
+ my_time_compare()
+
+ a - first time
+ b - second time
+
+ RETURN VALUE
+ -1 - a < b
+ 0 - a == b
+ 1 - a > b
+
+ NOTES
+ TIME.second_part is not considered during comparison
+*/
+
+int
+my_time_compare(TIME *a, TIME *b)
+{
+ my_ulonglong a_t= TIME_to_ulonglong_datetime(a);
+ my_ulonglong b_t= TIME_to_ulonglong_datetime(b);
+
+ if (a_t > b_t)
+ return 1;
+ else if (a_t < b_t)
+ return -1;
+
+ return 0;
+}
+
#endif