2005-12-08 00:17:05 +01:00
|
|
|
/* Copyright (C) 2004-2005 MySQL AB
|
2005-12-05 11:45:04 +01:00
|
|
|
|
|
|
|
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 */
|
|
|
|
|
|
|
|
#include "event_priv.h"
|
2005-12-12 21:19:19 +01:00
|
|
|
#include "event.h"
|
2005-12-05 11:45:04 +01:00
|
|
|
#include "sp.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extern int yyparse(void *thd);
|
|
|
|
|
|
|
|
/*
|
2006-02-15 19:08:44 +01:00
|
|
|
Init all member variables
|
2005-12-05 11:45:04 +01:00
|
|
|
|
2006-02-15 19:08:44 +01:00
|
|
|
SYNOPSIS
|
|
|
|
event_timed::init()
|
2005-12-05 11:45:04 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
event_timed::init()
|
|
|
|
{
|
|
|
|
DBUG_ENTER("event_timed::init");
|
|
|
|
|
2005-12-08 00:17:05 +01:00
|
|
|
dbname.str= name.str= body.str= comment.str= 0;
|
|
|
|
dbname.length= name.length= body.length= comment.length= 0;
|
2006-02-15 19:08:44 +01:00
|
|
|
|
2005-12-08 00:17:05 +01:00
|
|
|
set_zero_time(&starts, MYSQL_TIMESTAMP_DATETIME);
|
|
|
|
set_zero_time(&ends, MYSQL_TIMESTAMP_DATETIME);
|
|
|
|
set_zero_time(&execute_at, MYSQL_TIMESTAMP_DATETIME);
|
|
|
|
set_zero_time(&last_executed, MYSQL_TIMESTAMP_DATETIME);
|
2006-02-28 11:43:10 +01:00
|
|
|
starts_null= ends_null= execute_at_null= TRUE;
|
2005-12-05 11:45:04 +01:00
|
|
|
|
2005-12-08 00:17:05 +01:00
|
|
|
definer_user.str= definer_host.str= 0;
|
|
|
|
definer_user.length= definer_host.length= 0;
|
2006-02-15 19:08:44 +01:00
|
|
|
|
2006-02-20 23:52:22 +01:00
|
|
|
sql_mode= 0;
|
|
|
|
|
2005-12-05 11:45:04 +01:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2006-02-15 19:08:44 +01:00
|
|
|
Set a name of the event
|
2005-12-05 11:45:04 +01:00
|
|
|
|
2006-02-15 19:08:44 +01:00
|
|
|
SYNOPSIS
|
|
|
|
event_timed::init_name()
|
|
|
|
thd THD
|
|
|
|
spn the name extracted in the parser
|
2005-12-05 11:45:04 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2005-12-08 00:17:05 +01:00
|
|
|
event_timed::init_name(THD *thd, sp_name *spn)
|
2005-12-05 11:45:04 +01:00
|
|
|
{
|
|
|
|
DBUG_ENTER("event_timed::init_name");
|
2006-02-15 19:08:44 +01:00
|
|
|
uint n; /* Counter for nul trimming */
|
2005-12-05 11:45:04 +01:00
|
|
|
/* During parsing, we must use thd->mem_root */
|
|
|
|
MEM_ROOT *root= thd->mem_root;
|
|
|
|
|
|
|
|
/* We have to copy strings to get them into the right memroot */
|
2005-12-08 00:17:05 +01:00
|
|
|
if (spn)
|
2005-12-05 11:45:04 +01:00
|
|
|
{
|
2005-12-08 00:17:05 +01:00
|
|
|
dbname.length= spn->m_db.length;
|
|
|
|
if (spn->m_db.length == 0)
|
|
|
|
dbname.str= NULL;
|
2005-12-05 11:45:04 +01:00
|
|
|
else
|
2005-12-08 00:17:05 +01:00
|
|
|
dbname.str= strmake_root(root, spn->m_db.str, spn->m_db.length);
|
|
|
|
name.length= spn->m_name.length;
|
|
|
|
name.str= strmake_root(root, spn->m_name.str, spn->m_name.length);
|
2005-12-05 11:45:04 +01:00
|
|
|
|
2005-12-08 00:17:05 +01:00
|
|
|
if (spn->m_qname.length == 0)
|
|
|
|
spn->init_qname(thd);
|
2005-12-05 11:45:04 +01:00
|
|
|
}
|
|
|
|
else if (thd->db)
|
|
|
|
{
|
2005-12-08 00:17:05 +01:00
|
|
|
dbname.length= thd->db_length;
|
|
|
|
dbname.str= strmake_root(root, thd->db, dbname.length);
|
2005-12-05 11:45:04 +01:00
|
|
|
}
|
2006-02-15 19:08:44 +01:00
|
|
|
|
|
|
|
DBUG_PRINT("dbname", ("len=%d db=%s",dbname.length, dbname.str));
|
|
|
|
DBUG_PRINT("name", ("len=%d name=%s",name.length, name.str));
|
2005-12-05 11:45:04 +01:00
|
|
|
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2006-02-15 19:08:44 +01:00
|
|
|
Set body of the event - what should be executed.
|
2005-12-05 11:45:04 +01:00
|
|
|
|
2006-02-15 19:08:44 +01:00
|
|
|
SYNOPSIS
|
|
|
|
event_timed::init_body()
|
|
|
|
thd THD
|
2005-12-05 11:45:04 +01:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
event_timed::init_body(THD *thd)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("event_timed::init_body");
|
2006-02-21 02:40:23 +01:00
|
|
|
DBUG_PRINT("info", ("body=[%s] body_begin=0x%ld end=0x%ld", body_begin,
|
|
|
|
body_begin, thd->lex->ptr));
|
2005-12-05 11:45:04 +01:00
|
|
|
|
2005-12-08 00:17:05 +01:00
|
|
|
body.length= thd->lex->ptr - body_begin;
|
2006-02-28 14:43:49 +01:00
|
|
|
/* Trim nuls at the end */
|
2005-12-08 00:17:05 +01:00
|
|
|
while (body.length && body_begin[body.length-1] == '\0')
|
|
|
|
body.length--;
|
2005-12-05 11:45:04 +01:00
|
|
|
|
2006-02-21 02:40:23 +01:00
|
|
|
/* the first is always whitespace which I cannot skip in the parser */
|
|
|
|
while (my_isspace(thd->variables.character_set_client, *body_begin))
|
|
|
|
{
|
|
|
|
++body_begin;
|
|
|
|
--body.length;
|
|
|
|
}
|
|
|
|
body.str= strmake_root(thd->mem_root, (char *)body_begin, body.length);
|
2005-12-05 11:45:04 +01:00
|
|
|
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2006-02-15 19:08:44 +01:00
|
|
|
Set time for execution for one time events.
|
2005-12-05 11:45:04 +01:00
|
|
|
|
2006-02-15 19:08:44 +01:00
|
|
|
SYNOPSIS
|
|
|
|
event_timed::init_execute_at()
|
|
|
|
expr when (datetime)
|
2005-12-05 11:45:04 +01:00
|
|
|
|
2006-02-15 19:08:44 +01:00
|
|
|
RETURN VALUE
|
|
|
|
0 OK
|
|
|
|
EVEX_PARSE_ERROR fix_fields failed
|
|
|
|
EVEX_BAD_PARAMS datetime is in the past
|
|
|
|
ER_WRONG_VALUE wrong value for execute at
|
2005-12-05 11:45:04 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
event_timed::init_execute_at(THD *thd, Item *expr)
|
|
|
|
{
|
|
|
|
my_bool not_used;
|
|
|
|
TIME ltime;
|
|
|
|
my_time_t my_time_tmp;
|
|
|
|
|
|
|
|
TIME time_tmp;
|
|
|
|
DBUG_ENTER("event_timed::init_execute_at");
|
|
|
|
|
|
|
|
if (expr->fix_fields(thd, &expr))
|
|
|
|
DBUG_RETURN(EVEX_PARSE_ERROR);
|
2006-02-28 11:43:10 +01:00
|
|
|
|
|
|
|
/* no starts and/or ends in case of execute_at */
|
|
|
|
DBUG_PRINT("info", ("starts_null && ends_null should be 1 is %d",
|
2006-02-28 14:43:49 +01:00
|
|
|
(starts_null && ends_null)));
|
2006-02-28 11:43:10 +01:00
|
|
|
DBUG_ASSERT(starts_null && ends_null);
|
|
|
|
|
2006-02-28 14:43:49 +01:00
|
|
|
/* let's check whether time is in the past */
|
2005-12-05 11:45:04 +01:00
|
|
|
thd->variables.time_zone->gmt_sec_to_TIME(&time_tmp,
|
2006-02-28 14:43:49 +01:00
|
|
|
(my_time_t) thd->query_start());
|
2005-12-05 11:45:04 +01:00
|
|
|
|
|
|
|
if ((not_used= expr->get_date(<ime, TIME_NO_ZERO_DATE)))
|
2006-01-26 21:21:21 +01:00
|
|
|
DBUG_RETURN(ER_WRONG_VALUE);
|
|
|
|
|
|
|
|
if (TIME_to_ulonglong_datetime(<ime) <
|
|
|
|
TIME_to_ulonglong_datetime(&time_tmp))
|
2005-12-05 11:45:04 +01:00
|
|
|
DBUG_RETURN(EVEX_BAD_PARAMS);
|
|
|
|
|
2006-01-26 21:21:21 +01:00
|
|
|
|
2005-12-05 11:45:04 +01:00
|
|
|
/*
|
2006-02-15 19:08:44 +01:00
|
|
|
This may result in a 1970-01-01 date if ltime is > 2037-xx-xx.
|
|
|
|
CONVERT_TZ has similar problem.
|
2005-12-05 11:45:04 +01:00
|
|
|
*/
|
|
|
|
my_tz_UTC->gmt_sec_to_TIME(<ime, TIME_to_timestamp(thd,<ime, ¬_used));
|
|
|
|
|
2006-02-28 11:43:10 +01:00
|
|
|
execute_at_null= FALSE;
|
2005-12-08 00:17:05 +01:00
|
|
|
execute_at= ltime;
|
2005-12-05 11:45:04 +01:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2006-02-15 19:08:44 +01:00
|
|
|
Set time for execution for transient events.
|
2005-12-05 11:45:04 +01:00
|
|
|
|
2006-02-15 19:08:44 +01:00
|
|
|
SYNOPSIS
|
|
|
|
event_timed::init_interval()
|
|
|
|
expr how much?
|
|
|
|
new_interval what is the interval
|
2005-12-05 11:45:04 +01:00
|
|
|
|
2006-02-15 19:08:44 +01:00
|
|
|
RETURNS
|
|
|
|
0 OK
|
|
|
|
EVEX_PARSE_ERROR fix_fields failed
|
|
|
|
EVEX_BAD_PARAMS Interval is not positive
|
2006-02-20 16:06:05 +01:00
|
|
|
EVEX_MICROSECOND_UNSUP Microseconds are not supported.
|
2005-12-05 11:45:04 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
2005-12-08 00:17:05 +01:00
|
|
|
event_timed::init_interval(THD *thd, Item *expr, interval_type new_interval)
|
2005-12-05 11:45:04 +01:00
|
|
|
{
|
|
|
|
longlong tmp;
|
2006-01-18 20:41:22 +01:00
|
|
|
String value;
|
|
|
|
INTERVAL interval;
|
2006-02-15 19:08:44 +01:00
|
|
|
|
2005-12-05 11:45:04 +01:00
|
|
|
DBUG_ENTER("event_timed::init_interval");
|
|
|
|
|
|
|
|
if (expr->fix_fields(thd, &expr))
|
|
|
|
DBUG_RETURN(EVEX_PARSE_ERROR);
|
|
|
|
|
2006-01-18 20:41:22 +01:00
|
|
|
value.alloc(MAX_DATETIME_FULL_WIDTH*MY_CHARSET_BIN_MB_MAXLEN);
|
|
|
|
if (get_interval_value(expr, new_interval, &value, &interval))
|
|
|
|
DBUG_RETURN(EVEX_PARSE_ERROR);
|
2005-12-05 11:45:04 +01:00
|
|
|
|
2006-01-18 20:41:22 +01:00
|
|
|
expression= 0;
|
|
|
|
|
|
|
|
switch (new_interval) {
|
|
|
|
case INTERVAL_YEAR:
|
|
|
|
expression= interval.year;
|
|
|
|
break;
|
|
|
|
case INTERVAL_QUARTER:
|
|
|
|
case INTERVAL_MONTH:
|
|
|
|
expression= interval.month;
|
|
|
|
break;
|
|
|
|
case INTERVAL_WEEK:
|
|
|
|
case INTERVAL_DAY:
|
|
|
|
expression= interval.day;
|
|
|
|
break;
|
|
|
|
case INTERVAL_HOUR:
|
|
|
|
expression= interval.hour;
|
|
|
|
break;
|
|
|
|
case INTERVAL_MINUTE:
|
|
|
|
expression= interval.minute;
|
|
|
|
break;
|
|
|
|
case INTERVAL_SECOND:
|
|
|
|
expression= interval.second;
|
|
|
|
break;
|
2006-02-15 19:08:44 +01:00
|
|
|
case INTERVAL_YEAR_MONTH: // Allow YEAR-MONTH YYYYYMM
|
2006-01-18 20:41:22 +01:00
|
|
|
expression= interval.year* 12 + interval.month;
|
|
|
|
break;
|
|
|
|
case INTERVAL_DAY_HOUR:
|
|
|
|
expression= interval.day* 24 + interval.hour;
|
|
|
|
break;
|
|
|
|
case INTERVAL_DAY_MINUTE:
|
|
|
|
expression= (interval.day* 24 + interval.hour) * 60 + interval.minute;
|
|
|
|
break;
|
2006-02-28 14:43:49 +01:00
|
|
|
case INTERVAL_HOUR_SECOND: /* day is anyway 0 */
|
2006-01-18 20:41:22 +01:00
|
|
|
case INTERVAL_DAY_SECOND:
|
|
|
|
/* DAY_SECOND having problems because of leap seconds? */
|
|
|
|
expression= ((interval.day* 24 + interval.hour) * 60 + interval.minute)*60
|
|
|
|
+ interval.second;
|
|
|
|
break;
|
2006-02-28 14:43:49 +01:00
|
|
|
case INTERVAL_MINUTE_MICROSECOND: /* day and hour are 0 */
|
|
|
|
case INTERVAL_HOUR_MICROSECOND: /* day is anyway 0 */
|
2006-01-18 20:41:22 +01:00
|
|
|
case INTERVAL_DAY_MICROSECOND:
|
2006-02-20 16:06:05 +01:00
|
|
|
DBUG_RETURN(EVEX_MICROSECOND_UNSUP);
|
2006-01-18 20:41:22 +01:00
|
|
|
expression= ((((interval.day*24) + interval.hour)*60+interval.minute)*60 +
|
|
|
|
interval.second) * 1000000L + interval.second_part;
|
|
|
|
break;
|
|
|
|
case INTERVAL_HOUR_MINUTE:
|
|
|
|
expression= interval.hour * 60 + interval.minute;
|
|
|
|
break;
|
|
|
|
case INTERVAL_MINUTE_SECOND:
|
|
|
|
expression= interval.minute * 60 + interval.second;
|
|
|
|
break;
|
|
|
|
case INTERVAL_SECOND_MICROSECOND:
|
2006-02-20 16:06:05 +01:00
|
|
|
DBUG_RETURN(EVEX_MICROSECOND_UNSUP);
|
2006-01-18 20:41:22 +01:00
|
|
|
expression= interval.second * 1000000L + interval.second_part;
|
|
|
|
break;
|
2006-02-20 16:06:05 +01:00
|
|
|
case INTERVAL_MICROSECOND:
|
|
|
|
DBUG_RETURN(EVEX_MICROSECOND_UNSUP);
|
2006-01-18 20:41:22 +01:00
|
|
|
}
|
|
|
|
if (interval.neg || expression > EVEX_MAX_INTERVAL_VALUE)
|
|
|
|
DBUG_RETURN(EVEX_BAD_PARAMS);
|
2006-02-15 19:08:44 +01:00
|
|
|
|
2006-01-18 20:41:22 +01:00
|
|
|
this->interval= new_interval;
|
2005-12-05 11:45:04 +01:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2006-02-15 19:08:44 +01:00
|
|
|
Set activation time.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
event_timed::init_starts()
|
|
|
|
expr how much?
|
|
|
|
interval what is the interval
|
|
|
|
|
|
|
|
NOTES
|
|
|
|
Note that activation time is not execution time.
|
|
|
|
EVERY 5 MINUTE STARTS "2004-12-12 10:00:00" means that
|
|
|
|
the event will be executed every 5 minutes but this will
|
|
|
|
start at the date shown above. Expressions are possible :
|
|
|
|
DATE_ADD(NOW(), INTERVAL 1 DAY) -- start tommorow at
|
|
|
|
same time.
|
|
|
|
|
|
|
|
RETURNS
|
|
|
|
0 OK
|
|
|
|
EVEX_PARSE_ERROR fix_fields failed
|
2005-12-05 11:45:04 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
2005-12-08 00:17:05 +01:00
|
|
|
event_timed::init_starts(THD *thd, Item *new_starts)
|
2005-12-05 11:45:04 +01:00
|
|
|
{
|
|
|
|
my_bool not_used;
|
2006-01-26 21:21:21 +01:00
|
|
|
TIME ltime, time_tmp;
|
2005-12-05 11:45:04 +01:00
|
|
|
|
|
|
|
DBUG_ENTER("event_timed::init_starts");
|
|
|
|
|
2005-12-08 00:17:05 +01:00
|
|
|
if (new_starts->fix_fields(thd, &new_starts))
|
2005-12-05 11:45:04 +01:00
|
|
|
DBUG_RETURN(EVEX_PARSE_ERROR);
|
|
|
|
|
2005-12-08 00:17:05 +01:00
|
|
|
if ((not_used= new_starts->get_date(<ime, TIME_NO_ZERO_DATE)))
|
2005-12-05 11:45:04 +01:00
|
|
|
DBUG_RETURN(EVEX_BAD_PARAMS);
|
|
|
|
|
2006-02-15 19:08:44 +01:00
|
|
|
/* Let's check whether time is in the past */
|
|
|
|
thd->variables.time_zone->gmt_sec_to_TIME(&time_tmp,
|
|
|
|
(my_time_t) thd->query_start());
|
2006-01-26 21:21:21 +01:00
|
|
|
|
2006-01-30 17:12:30 +01:00
|
|
|
DBUG_PRINT("info",("now =%lld", TIME_to_ulonglong_datetime(&time_tmp)));
|
|
|
|
DBUG_PRINT("info",("starts=%lld", TIME_to_ulonglong_datetime(<ime)));
|
2006-01-26 21:21:21 +01:00
|
|
|
if (TIME_to_ulonglong_datetime(<ime) <
|
|
|
|
TIME_to_ulonglong_datetime(&time_tmp))
|
|
|
|
DBUG_RETURN(EVEX_BAD_PARAMS);
|
|
|
|
|
2005-12-05 11:45:04 +01:00
|
|
|
/*
|
2006-02-15 19:08:44 +01:00
|
|
|
This may result in a 1970-01-01 date if ltime is > 2037-xx-xx
|
|
|
|
CONVERT_TZ has similar problem
|
2005-12-05 11:45:04 +01:00
|
|
|
*/
|
2005-12-08 00:17:05 +01:00
|
|
|
my_tz_UTC->gmt_sec_to_TIME(<ime, TIME_to_timestamp(thd, <ime, ¬_used));
|
2005-12-05 11:45:04 +01:00
|
|
|
|
2005-12-08 00:17:05 +01:00
|
|
|
starts= ltime;
|
2006-02-28 11:43:10 +01:00
|
|
|
starts_null= FALSE;
|
2005-12-05 11:45:04 +01:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2006-02-15 19:08:44 +01:00
|
|
|
Set deactivation time.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
event_timed::init_ends()
|
|
|
|
thd THD
|
|
|
|
new_ends when?
|
|
|
|
|
|
|
|
NOTES
|
|
|
|
Note that activation time is not execution time.
|
|
|
|
EVERY 5 MINUTE ENDS "2004-12-12 10:00:00" means that
|
|
|
|
the event will be executed every 5 minutes but this will
|
|
|
|
end at the date shown above. Expressions are possible :
|
|
|
|
DATE_ADD(NOW(), INTERVAL 1 DAY) -- end tommorow at
|
|
|
|
same time.
|
|
|
|
|
|
|
|
RETURNS
|
|
|
|
0 OK
|
|
|
|
EVEX_PARSE_ERROR fix_fields failed
|
|
|
|
EVEX_BAD_PARAMS ENDS before STARTS
|
2005-12-05 11:45:04 +01:00
|
|
|
*/
|
|
|
|
|
2006-02-15 19:08:44 +01:00
|
|
|
int
|
2005-12-08 00:17:05 +01:00
|
|
|
event_timed::init_ends(THD *thd, Item *new_ends)
|
2005-12-05 11:45:04 +01:00
|
|
|
{
|
2006-02-28 11:43:10 +01:00
|
|
|
TIME ltime, ltime_now;
|
2005-12-05 11:45:04 +01:00
|
|
|
my_bool not_used;
|
|
|
|
|
|
|
|
DBUG_ENTER("event_timed::init_ends");
|
|
|
|
|
2005-12-08 00:17:05 +01:00
|
|
|
if (new_ends->fix_fields(thd, &new_ends))
|
2005-12-05 11:45:04 +01:00
|
|
|
DBUG_RETURN(EVEX_PARSE_ERROR);
|
|
|
|
|
2006-02-28 11:43:10 +01:00
|
|
|
DBUG_PRINT("info", ("convert to TIME"));
|
2005-12-08 00:17:05 +01:00
|
|
|
if ((not_used= new_ends->get_date(<ime, TIME_NO_ZERO_DATE)))
|
2005-12-05 11:45:04 +01:00
|
|
|
DBUG_RETURN(EVEX_BAD_PARAMS);
|
|
|
|
|
|
|
|
/*
|
2006-02-28 11:43:10 +01:00
|
|
|
This may result in a 1970-01-01 date if ltime is > 2037-xx-xx ?
|
|
|
|
CONVERT_TZ has similar problem ?
|
2005-12-05 11:45:04 +01:00
|
|
|
*/
|
2006-02-28 11:43:10 +01:00
|
|
|
DBUG_PRINT("info", ("get the UTC time"));
|
2005-12-05 11:45:04 +01:00
|
|
|
my_tz_UTC->gmt_sec_to_TIME(<ime, TIME_to_timestamp(thd, <ime, ¬_used));
|
2006-02-15 19:08:44 +01:00
|
|
|
|
2006-02-28 11:43:10 +01:00
|
|
|
/* Check whether ends is after starts */
|
|
|
|
DBUG_PRINT("info", ("ENDS after STARTS?"));
|
|
|
|
if (!starts_null && my_time_compare(&starts, <ime) != -1)
|
|
|
|
DBUG_RETURN(EVEX_BAD_PARAMS);
|
|
|
|
|
|
|
|
/*
|
|
|
|
The parser forces starts to be provided but one day STARTS could be
|
|
|
|
set before NOW() and in this case the following check should be done.
|
|
|
|
Check whether ENDS is not in the past.
|
|
|
|
*/
|
|
|
|
DBUG_PRINT("info", ("ENDS after NOW?"));
|
2006-02-28 14:43:49 +01:00
|
|
|
my_tz_UTC->gmt_sec_to_TIME(<ime_now, thd->query_start());
|
2006-02-28 11:43:10 +01:00
|
|
|
if (my_time_compare(<ime_now, <ime) == 1)
|
2005-12-05 11:45:04 +01:00
|
|
|
DBUG_RETURN(EVEX_BAD_PARAMS);
|
|
|
|
|
2005-12-08 00:17:05 +01:00
|
|
|
ends= ltime;
|
2006-02-28 11:43:10 +01:00
|
|
|
ends_null= FALSE;
|
2005-12-05 11:45:04 +01:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2006-02-15 19:08:44 +01:00
|
|
|
Sets comment.
|
2005-12-05 11:45:04 +01:00
|
|
|
|
2006-02-15 19:08:44 +01:00
|
|
|
SYNOPSIS
|
|
|
|
event_timed::init_comment()
|
|
|
|
thd THD - used for memory allocation
|
|
|
|
comment the string.
|
2005-12-05 11:45:04 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2005-12-08 00:17:05 +01:00
|
|
|
event_timed::init_comment(THD *thd, LEX_STRING *set_comment)
|
2005-12-05 11:45:04 +01:00
|
|
|
{
|
|
|
|
DBUG_ENTER("event_timed::init_comment");
|
|
|
|
|
2005-12-08 00:17:05 +01:00
|
|
|
comment.str= strmake_root(thd->mem_root, set_comment->str,
|
2006-02-28 11:43:10 +01:00
|
|
|
comment.length= set_comment->length);
|
2005-12-05 11:45:04 +01:00
|
|
|
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2006-02-15 19:08:44 +01:00
|
|
|
Inits definer (definer_user and definer_host) during parsing.
|
2005-12-05 11:45:04 +01:00
|
|
|
|
2006-02-15 19:08:44 +01:00
|
|
|
SYNOPSIS
|
|
|
|
event_timed::init_definer()
|
2005-12-05 11:45:04 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
event_timed::init_definer(THD *thd)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("event_timed::init_definer");
|
|
|
|
|
2006-02-16 05:21:02 +01:00
|
|
|
DBUG_PRINT("info",("init definer_user thd->mem_root=0x%lx "
|
|
|
|
"thd->sec_ctx->priv_user=0x%lx", thd->mem_root,
|
|
|
|
thd->security_ctx->priv_user));
|
2005-12-08 00:17:05 +01:00
|
|
|
definer_user.str= strdup_root(thd->mem_root, thd->security_ctx->priv_user);
|
|
|
|
definer_user.length= strlen(thd->security_ctx->priv_user);
|
2005-12-05 11:45:04 +01:00
|
|
|
|
2006-02-16 05:21:02 +01:00
|
|
|
DBUG_PRINT("info",("init definer_host thd->s_c->priv_host=0x%lx",
|
|
|
|
thd->security_ctx->priv_host));
|
2005-12-08 00:17:05 +01:00
|
|
|
definer_host.str= strdup_root(thd->mem_root, thd->security_ctx->priv_host);
|
|
|
|
definer_host.length= strlen(thd->security_ctx->priv_host);
|
2006-02-15 19:08:44 +01:00
|
|
|
|
2006-02-16 05:21:02 +01:00
|
|
|
DBUG_PRINT("info",("init definer as whole"));
|
fix for bug#16642 (Events: No INFORMATION_SCHEMA.EVENTS table)
post-review change - use pointer instead of copy on the stack.
WL#1034 (Internal CRON)
This patch adds INFORMATION_SCHEMA.EVENTS table with the following format:
EVENT_CATALOG - MYSQL_TYPE_STRING (Always NULL)
EVENT_SCHEMA - MYSQL_TYPE_STRING (the database)
EVENT_NAME - MYSQL_TYPE_STRING (the name)
DEFINER - MYSQL_TYPE_STRING (user@host)
EVENT_BODY - MYSQL_TYPE_STRING (the body from mysql.event)
EVENT_TYPE - MYSQL_TYPE_STRING ("ONE TIME" | "RECURRING")
EXECUTE_AT - MYSQL_TYPE_TIMESTAMP (set for "ONE TIME" otherwise NULL)
INTERVAL_VALUE - MYSQL_TYPE_LONG (set for RECURRING otherwise NULL)
INTERVAL_FIELD - MYSQL_TYPE_STRING (set for RECURRING otherwise NULL)
SQL_MODE - MYSQL_TYPE_STRING (for now NULL)
STARTS - MYSQL_TYPE_TIMESTAMP (starts from mysql.event)
ENDS - MYSQL_TYPE_TIMESTAMP (ends from mysql.event)
STATUS - MYSQL_TYPE_STRING (ENABLED | DISABLED)
ON_COMPLETION - MYSQL_TYPE_STRING (NOT PRESERVE | PRESERVE)
CREATED - MYSQL_TYPE_TIMESTAMP
LAST_ALTERED - MYSQL_TYPE_TIMESTAMP
LAST_EXECUTED - MYSQL_TYPE_TIMESTAMP
EVENT_COMMENT - MYSQL_TYPE_STRING
SQL_MODE is NULL for now, because the value is still not stored in mysql.event .
Support will be added as a fix for another bug.
This patch also adds SHOW [FULL] EVENTS [FROM db] [LIKE pattern]
1. SHOW EVENTS shows always only the events on the same user,
because the PK of mysql.event is (definer, db, name) several
users may have event with the same name -> no information disclosure.
2. SHOW FULL EVENTS - shows the events (in the current db as SHOW EVENTS)
of all users. The user has to have PROCESS privilege, if not then
SHOW FULL EVENTS behave like SHOW EVENTS.
3. If [FROM db] is specified then this db is considered.
4. Event names can be filtered with LIKE pattern.
SHOW EVENTS returns table with the following columns, which are subset of
the data which is returned by SELECT * FROM I_S.EVENTS
Db
Name
Definer
Type
Execute at
Interval value
Interval field
Starts
Ends
Status
mysql-test/lib/init_db.sql:
change the PK - (definer, db, name)
quicker searches when SHOW EVENTS;
allow also different users to have events with the same name ->
no information disclosure
mysql-test/r/events.result:
result of new tests
mysql-test/r/information_schema.result:
result of new tests
mysql-test/r/information_schema_db.result:
result of new tests
mysql-test/r/system_mysql_db.result:
result of new tests
mysql-test/t/events.test:
new tests for information_schema.events
scripts/mysql_create_system_tables.sh:
change the PK of mysql.event to (definer, db, name)
scripts/mysql_fix_privilege_tables.sql:
change the PK of mysql.event to (definer, db, name)
sql/event.cc:
pass around the definer of the event because of the new PK
which is (definer, db, name). It's needed for index searching.
sql/event.h:
- make enum evex_table_field again public so it can be used
in sql_show.cc
- make created and modified ulonglong, because they should be such
- make public evex_open_event_table so it can be used in sql_show.cc
sql/event_executor.cc:
- cosmetics
sql/event_priv.h:
- moved enum evex_table_field and evex_open_event_table()
to event.h (made them therefore public)
sql/event_timed.cc:
- in event_timed::init_definer() always fill this.definer with
the concatenated value of definer_user@definer_host. Makes
later the work easier.
- pass around the definer wherever is needed for searching
(new prototype of evex_db_find_evex_aux)
sql/mysqld.cc:
- add counter for SHOW EVENTS
sql/sql_lex.h:
- register SHOW EVENTS as command
sql/sql_parse.cc:
- handle SCH_EVENTS (I_S.EVENTS like SCH_TRIGGERS)
- make additional check in case of SHOW EVENTS (check for EVENT on
the current database. if it is null check_access() gives appropriate
message back.
sql/sql_show.cc:
- add INFORMATION_SCHEMA.EVENTS and SHOW EVENTS
- I_S.EVENTS.SQL_MODE is NULL for now -> not implemented. Trudy
asked to be added so bug #16642 can be completely closed. There
is another bug report which will fix the lack of storage of
SQL_MODE during event creation.
sql/sql_yacc.yy:
- always call event_timed::init_definer() when CREATE/ALTER/DROP
EVENT but not when just compiling the body of the event because
in this case this operation is not needed, it takes memory and
CPU time and at the end the result is not used. event_timed::definer
is used only on SQLCOM_CREATE/ALTER/DROP_EVENT execution not on
statement compilation.
- add SHOW [FULL] EVENTS [FROM db] [LIKE pattern]
in case of FULL and the user has PROCESS privilege then he will see
also others' events in the current database, otherwise the output
is the same as of SHOW EVENTS. Because the events are per DB only
the events from the current database are shown. pattern is applied
against event name. FROM db is self explanatory.
sql/table.h:
add SCH_EVENTS as part of INFORMATION_SCHEMA
2006-01-30 13:15:23 +01:00
|
|
|
definer.length= definer_user.length + definer_host.length + 1;
|
|
|
|
definer.str= alloc_root(thd->mem_root, definer.length + 1);
|
|
|
|
|
2006-02-16 05:21:02 +01:00
|
|
|
DBUG_PRINT("info",("copy the user"));
|
fix for bug#16642 (Events: No INFORMATION_SCHEMA.EVENTS table)
post-review change - use pointer instead of copy on the stack.
WL#1034 (Internal CRON)
This patch adds INFORMATION_SCHEMA.EVENTS table with the following format:
EVENT_CATALOG - MYSQL_TYPE_STRING (Always NULL)
EVENT_SCHEMA - MYSQL_TYPE_STRING (the database)
EVENT_NAME - MYSQL_TYPE_STRING (the name)
DEFINER - MYSQL_TYPE_STRING (user@host)
EVENT_BODY - MYSQL_TYPE_STRING (the body from mysql.event)
EVENT_TYPE - MYSQL_TYPE_STRING ("ONE TIME" | "RECURRING")
EXECUTE_AT - MYSQL_TYPE_TIMESTAMP (set for "ONE TIME" otherwise NULL)
INTERVAL_VALUE - MYSQL_TYPE_LONG (set for RECURRING otherwise NULL)
INTERVAL_FIELD - MYSQL_TYPE_STRING (set for RECURRING otherwise NULL)
SQL_MODE - MYSQL_TYPE_STRING (for now NULL)
STARTS - MYSQL_TYPE_TIMESTAMP (starts from mysql.event)
ENDS - MYSQL_TYPE_TIMESTAMP (ends from mysql.event)
STATUS - MYSQL_TYPE_STRING (ENABLED | DISABLED)
ON_COMPLETION - MYSQL_TYPE_STRING (NOT PRESERVE | PRESERVE)
CREATED - MYSQL_TYPE_TIMESTAMP
LAST_ALTERED - MYSQL_TYPE_TIMESTAMP
LAST_EXECUTED - MYSQL_TYPE_TIMESTAMP
EVENT_COMMENT - MYSQL_TYPE_STRING
SQL_MODE is NULL for now, because the value is still not stored in mysql.event .
Support will be added as a fix for another bug.
This patch also adds SHOW [FULL] EVENTS [FROM db] [LIKE pattern]
1. SHOW EVENTS shows always only the events on the same user,
because the PK of mysql.event is (definer, db, name) several
users may have event with the same name -> no information disclosure.
2. SHOW FULL EVENTS - shows the events (in the current db as SHOW EVENTS)
of all users. The user has to have PROCESS privilege, if not then
SHOW FULL EVENTS behave like SHOW EVENTS.
3. If [FROM db] is specified then this db is considered.
4. Event names can be filtered with LIKE pattern.
SHOW EVENTS returns table with the following columns, which are subset of
the data which is returned by SELECT * FROM I_S.EVENTS
Db
Name
Definer
Type
Execute at
Interval value
Interval field
Starts
Ends
Status
mysql-test/lib/init_db.sql:
change the PK - (definer, db, name)
quicker searches when SHOW EVENTS;
allow also different users to have events with the same name ->
no information disclosure
mysql-test/r/events.result:
result of new tests
mysql-test/r/information_schema.result:
result of new tests
mysql-test/r/information_schema_db.result:
result of new tests
mysql-test/r/system_mysql_db.result:
result of new tests
mysql-test/t/events.test:
new tests for information_schema.events
scripts/mysql_create_system_tables.sh:
change the PK of mysql.event to (definer, db, name)
scripts/mysql_fix_privilege_tables.sql:
change the PK of mysql.event to (definer, db, name)
sql/event.cc:
pass around the definer of the event because of the new PK
which is (definer, db, name). It's needed for index searching.
sql/event.h:
- make enum evex_table_field again public so it can be used
in sql_show.cc
- make created and modified ulonglong, because they should be such
- make public evex_open_event_table so it can be used in sql_show.cc
sql/event_executor.cc:
- cosmetics
sql/event_priv.h:
- moved enum evex_table_field and evex_open_event_table()
to event.h (made them therefore public)
sql/event_timed.cc:
- in event_timed::init_definer() always fill this.definer with
the concatenated value of definer_user@definer_host. Makes
later the work easier.
- pass around the definer wherever is needed for searching
(new prototype of evex_db_find_evex_aux)
sql/mysqld.cc:
- add counter for SHOW EVENTS
sql/sql_lex.h:
- register SHOW EVENTS as command
sql/sql_parse.cc:
- handle SCH_EVENTS (I_S.EVENTS like SCH_TRIGGERS)
- make additional check in case of SHOW EVENTS (check for EVENT on
the current database. if it is null check_access() gives appropriate
message back.
sql/sql_show.cc:
- add INFORMATION_SCHEMA.EVENTS and SHOW EVENTS
- I_S.EVENTS.SQL_MODE is NULL for now -> not implemented. Trudy
asked to be added so bug #16642 can be completely closed. There
is another bug report which will fix the lack of storage of
SQL_MODE during event creation.
sql/sql_yacc.yy:
- always call event_timed::init_definer() when CREATE/ALTER/DROP
EVENT but not when just compiling the body of the event because
in this case this operation is not needed, it takes memory and
CPU time and at the end the result is not used. event_timed::definer
is used only on SQLCOM_CREATE/ALTER/DROP_EVENT execution not on
statement compilation.
- add SHOW [FULL] EVENTS [FROM db] [LIKE pattern]
in case of FULL and the user has PROCESS privilege then he will see
also others' events in the current database, otherwise the output
is the same as of SHOW EVENTS. Because the events are per DB only
the events from the current database are shown. pattern is applied
against event name. FROM db is self explanatory.
sql/table.h:
add SCH_EVENTS as part of INFORMATION_SCHEMA
2006-01-30 13:15:23 +01:00
|
|
|
memcpy(definer.str, definer_user.str, definer_user.length);
|
|
|
|
definer.str[definer_user.length]= '@';
|
2006-02-15 19:08:44 +01:00
|
|
|
|
2006-02-16 05:21:02 +01:00
|
|
|
DBUG_PRINT("info",("copy the host"));
|
fix for bug#16642 (Events: No INFORMATION_SCHEMA.EVENTS table)
post-review change - use pointer instead of copy on the stack.
WL#1034 (Internal CRON)
This patch adds INFORMATION_SCHEMA.EVENTS table with the following format:
EVENT_CATALOG - MYSQL_TYPE_STRING (Always NULL)
EVENT_SCHEMA - MYSQL_TYPE_STRING (the database)
EVENT_NAME - MYSQL_TYPE_STRING (the name)
DEFINER - MYSQL_TYPE_STRING (user@host)
EVENT_BODY - MYSQL_TYPE_STRING (the body from mysql.event)
EVENT_TYPE - MYSQL_TYPE_STRING ("ONE TIME" | "RECURRING")
EXECUTE_AT - MYSQL_TYPE_TIMESTAMP (set for "ONE TIME" otherwise NULL)
INTERVAL_VALUE - MYSQL_TYPE_LONG (set for RECURRING otherwise NULL)
INTERVAL_FIELD - MYSQL_TYPE_STRING (set for RECURRING otherwise NULL)
SQL_MODE - MYSQL_TYPE_STRING (for now NULL)
STARTS - MYSQL_TYPE_TIMESTAMP (starts from mysql.event)
ENDS - MYSQL_TYPE_TIMESTAMP (ends from mysql.event)
STATUS - MYSQL_TYPE_STRING (ENABLED | DISABLED)
ON_COMPLETION - MYSQL_TYPE_STRING (NOT PRESERVE | PRESERVE)
CREATED - MYSQL_TYPE_TIMESTAMP
LAST_ALTERED - MYSQL_TYPE_TIMESTAMP
LAST_EXECUTED - MYSQL_TYPE_TIMESTAMP
EVENT_COMMENT - MYSQL_TYPE_STRING
SQL_MODE is NULL for now, because the value is still not stored in mysql.event .
Support will be added as a fix for another bug.
This patch also adds SHOW [FULL] EVENTS [FROM db] [LIKE pattern]
1. SHOW EVENTS shows always only the events on the same user,
because the PK of mysql.event is (definer, db, name) several
users may have event with the same name -> no information disclosure.
2. SHOW FULL EVENTS - shows the events (in the current db as SHOW EVENTS)
of all users. The user has to have PROCESS privilege, if not then
SHOW FULL EVENTS behave like SHOW EVENTS.
3. If [FROM db] is specified then this db is considered.
4. Event names can be filtered with LIKE pattern.
SHOW EVENTS returns table with the following columns, which are subset of
the data which is returned by SELECT * FROM I_S.EVENTS
Db
Name
Definer
Type
Execute at
Interval value
Interval field
Starts
Ends
Status
mysql-test/lib/init_db.sql:
change the PK - (definer, db, name)
quicker searches when SHOW EVENTS;
allow also different users to have events with the same name ->
no information disclosure
mysql-test/r/events.result:
result of new tests
mysql-test/r/information_schema.result:
result of new tests
mysql-test/r/information_schema_db.result:
result of new tests
mysql-test/r/system_mysql_db.result:
result of new tests
mysql-test/t/events.test:
new tests for information_schema.events
scripts/mysql_create_system_tables.sh:
change the PK of mysql.event to (definer, db, name)
scripts/mysql_fix_privilege_tables.sql:
change the PK of mysql.event to (definer, db, name)
sql/event.cc:
pass around the definer of the event because of the new PK
which is (definer, db, name). It's needed for index searching.
sql/event.h:
- make enum evex_table_field again public so it can be used
in sql_show.cc
- make created and modified ulonglong, because they should be such
- make public evex_open_event_table so it can be used in sql_show.cc
sql/event_executor.cc:
- cosmetics
sql/event_priv.h:
- moved enum evex_table_field and evex_open_event_table()
to event.h (made them therefore public)
sql/event_timed.cc:
- in event_timed::init_definer() always fill this.definer with
the concatenated value of definer_user@definer_host. Makes
later the work easier.
- pass around the definer wherever is needed for searching
(new prototype of evex_db_find_evex_aux)
sql/mysqld.cc:
- add counter for SHOW EVENTS
sql/sql_lex.h:
- register SHOW EVENTS as command
sql/sql_parse.cc:
- handle SCH_EVENTS (I_S.EVENTS like SCH_TRIGGERS)
- make additional check in case of SHOW EVENTS (check for EVENT on
the current database. if it is null check_access() gives appropriate
message back.
sql/sql_show.cc:
- add INFORMATION_SCHEMA.EVENTS and SHOW EVENTS
- I_S.EVENTS.SQL_MODE is NULL for now -> not implemented. Trudy
asked to be added so bug #16642 can be completely closed. There
is another bug report which will fix the lack of storage of
SQL_MODE during event creation.
sql/sql_yacc.yy:
- always call event_timed::init_definer() when CREATE/ALTER/DROP
EVENT but not when just compiling the body of the event because
in this case this operation is not needed, it takes memory and
CPU time and at the end the result is not used. event_timed::definer
is used only on SQLCOM_CREATE/ALTER/DROP_EVENT execution not on
statement compilation.
- add SHOW [FULL] EVENTS [FROM db] [LIKE pattern]
in case of FULL and the user has PROCESS privilege then he will see
also others' events in the current database, otherwise the output
is the same as of SHOW EVENTS. Because the events are per DB only
the events from the current database are shown. pattern is applied
against event name. FROM db is self explanatory.
sql/table.h:
add SCH_EVENTS as part of INFORMATION_SCHEMA
2006-01-30 13:15:23 +01:00
|
|
|
memcpy(definer.str + definer_user.length + 1, definer_host.str,
|
|
|
|
definer_host.length);
|
2006-02-15 19:08:44 +01:00
|
|
|
definer.str[definer.length]= '\0';
|
2006-02-16 05:21:02 +01:00
|
|
|
DBUG_PRINT("info",("definer initted"));
|
2005-12-05 11:45:04 +01:00
|
|
|
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2006-02-15 19:08:44 +01:00
|
|
|
Loads an event from a row from mysql.event
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
event_timed::load_from_row(MEM_ROOT *mem_root, TABLE *table)
|
|
|
|
|
|
|
|
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.
|
2005-12-05 11:45:04 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
event_timed::load_from_row(MEM_ROOT *mem_root, TABLE *table)
|
|
|
|
{
|
|
|
|
longlong created;
|
|
|
|
longlong modified;
|
|
|
|
char *ptr;
|
|
|
|
event_timed *et;
|
|
|
|
uint len;
|
|
|
|
bool res1, res2;
|
|
|
|
|
|
|
|
DBUG_ENTER("event_timed::load_from_row");
|
|
|
|
|
|
|
|
if (!table)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
et= this;
|
2006-02-15 19:08:44 +01:00
|
|
|
|
2005-12-05 11:45:04 +01:00
|
|
|
if (table->s->fields != EVEX_FIELD_COUNT)
|
|
|
|
goto error;
|
|
|
|
|
2005-12-08 00:17:05 +01:00
|
|
|
if ((et->dbname.str= get_field(mem_root,
|
2005-12-05 11:45:04 +01:00
|
|
|
table->field[EVEX_FIELD_DB])) == NULL)
|
|
|
|
goto error;
|
|
|
|
|
2005-12-08 00:17:05 +01:00
|
|
|
et->dbname.length= strlen(et->dbname.str);
|
2005-12-05 11:45:04 +01:00
|
|
|
|
2005-12-08 00:17:05 +01:00
|
|
|
if ((et->name.str= get_field(mem_root,
|
2005-12-05 11:45:04 +01:00
|
|
|
table->field[EVEX_FIELD_NAME])) == NULL)
|
|
|
|
goto error;
|
|
|
|
|
2005-12-08 00:17:05 +01:00
|
|
|
et->name.length= strlen(et->name.str);
|
2005-12-05 11:45:04 +01:00
|
|
|
|
2005-12-08 00:17:05 +01:00
|
|
|
if ((et->body.str= get_field(mem_root,
|
2005-12-05 11:45:04 +01:00
|
|
|
table->field[EVEX_FIELD_BODY])) == NULL)
|
|
|
|
goto error;
|
|
|
|
|
2005-12-08 00:17:05 +01:00
|
|
|
et->body.length= strlen(et->body.str);
|
2005-12-05 11:45:04 +01:00
|
|
|
|
2005-12-08 00:17:05 +01:00
|
|
|
if ((et->definer.str= get_field(mem_root,
|
2005-12-05 11:45:04 +01:00
|
|
|
table->field[EVEX_FIELD_DEFINER])) == NullS)
|
|
|
|
goto error;
|
2005-12-08 00:17:05 +01:00
|
|
|
et->definer.length= strlen(et->definer.str);
|
2005-12-05 11:45:04 +01:00
|
|
|
|
2005-12-08 00:17:05 +01:00
|
|
|
ptr= strchr(et->definer.str, '@');
|
2005-12-05 11:45:04 +01:00
|
|
|
|
|
|
|
if (! ptr)
|
2005-12-08 00:17:05 +01:00
|
|
|
ptr= et->definer.str;
|
2005-12-05 11:45:04 +01:00
|
|
|
|
2005-12-08 00:17:05 +01:00
|
|
|
len= ptr - et->definer.str;
|
2005-12-05 11:45:04 +01:00
|
|
|
|
2005-12-08 00:17:05 +01:00
|
|
|
et->definer_user.str= strmake_root(mem_root, et->definer.str, len);
|
|
|
|
et->definer_user.length= len;
|
2006-02-28 14:43:49 +01:00
|
|
|
len= et->definer.length - len - 1; //1 is because of @
|
|
|
|
et->definer_host.str= strmake_root(mem_root, ptr + 1, len);/* 1:because of @*/
|
2005-12-08 00:17:05 +01:00
|
|
|
et->definer_host.length= len;
|
2005-12-05 11:45:04 +01:00
|
|
|
|
2006-02-28 11:43:10 +01:00
|
|
|
et->starts_null= table->field[EVEX_FIELD_STARTS]->is_null();
|
|
|
|
res1= table->field[EVEX_FIELD_STARTS]->get_date(&et->starts,TIME_NO_ZERO_DATE);
|
2006-02-15 19:08:44 +01:00
|
|
|
|
2006-02-28 11:43:10 +01:00
|
|
|
et->ends_null= table->field[EVEX_FIELD_ENDS]->is_null();
|
|
|
|
res2= table->field[EVEX_FIELD_ENDS]->get_date(&et->ends, TIME_NO_ZERO_DATE);
|
2005-12-05 11:45:04 +01:00
|
|
|
|
2006-02-28 11:43:10 +01:00
|
|
|
if (!table->field[EVEX_FIELD_INTERVAL_EXPR]->is_null())
|
|
|
|
et->expression= table->field[EVEX_FIELD_INTERVAL_EXPR]->val_int();
|
|
|
|
else
|
|
|
|
et->expression= 0;
|
2005-12-05 11:45:04 +01:00
|
|
|
/*
|
|
|
|
If res1 and res2 are true then both fields are empty.
|
2006-02-15 19:08:44 +01:00
|
|
|
Hence if EVEX_FIELD_EXECUTE_AT is empty there is an error.
|
2005-12-05 11:45:04 +01:00
|
|
|
*/
|
2006-02-28 11:43:10 +01:00
|
|
|
et->execute_at_null= table->field[EVEX_FIELD_EXECUTE_AT]->is_null();
|
|
|
|
DBUG_ASSERT(!(et->starts_null && et->ends_null && !et->expression &&
|
|
|
|
et->execute_at_null));
|
|
|
|
if (!et->expression &&
|
|
|
|
table->field[EVEX_FIELD_EXECUTE_AT]->get_date(&et->execute_at,
|
|
|
|
TIME_NO_ZERO_DATE))
|
2005-12-05 11:45:04 +01:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
/*
|
|
|
|
In DB the values start from 1 but enum interval_type starts
|
|
|
|
from 0
|
|
|
|
*/
|
2006-02-28 11:43:10 +01:00
|
|
|
if (!table->field[EVEX_FIELD_TRANSIENT_INTERVAL]->is_null())
|
|
|
|
et->interval= (interval_type)
|
2005-12-05 11:45:04 +01:00
|
|
|
((ulonglong) table->field[EVEX_FIELD_TRANSIENT_INTERVAL]->val_int() - 1);
|
2006-02-28 11:43:10 +01:00
|
|
|
else
|
|
|
|
et->interval= (interval_type) 0;
|
2005-12-05 11:45:04 +01:00
|
|
|
|
2005-12-08 00:17:05 +01:00
|
|
|
et->modified= table->field[EVEX_FIELD_CREATED]->val_int();
|
|
|
|
et->created= table->field[EVEX_FIELD_MODIFIED]->val_int();
|
2005-12-05 11:45:04 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
ToDo Andrey : Ask PeterG & Serg what to do in this case.
|
|
|
|
Whether on load last_executed_at should be loaded
|
|
|
|
or it must be 0ed. If last_executed_at is loaded
|
|
|
|
then an event can be scheduled for execution
|
|
|
|
instantly. Let's say an event has to be executed
|
|
|
|
every 15 mins. The server has been stopped for
|
|
|
|
more than this time and then started. If L_E_AT
|
|
|
|
is loaded from DB, execution at L_E_AT+15min
|
|
|
|
will be scheduled. However this time is in the past.
|
|
|
|
Hence immediate execution. Due to patch of
|
2005-12-08 00:17:05 +01:00
|
|
|
::mark_last_executed() last_executed gets time_now
|
|
|
|
and not execute_at. If not like this a big
|
2005-12-05 11:45:04 +01:00
|
|
|
queue can be scheduled for times which are still in
|
|
|
|
the past (2, 3 and more executions which will be
|
|
|
|
consequent).
|
|
|
|
*/
|
2005-12-08 00:17:05 +01:00
|
|
|
set_zero_time(&last_executed, MYSQL_TIMESTAMP_DATETIME);
|
2005-12-05 11:45:04 +01:00
|
|
|
#ifdef ANDREY_0
|
|
|
|
table->field[EVEX_FIELD_LAST_EXECUTED]->
|
2005-12-08 00:17:05 +01:00
|
|
|
get_date(&et->last_executed, TIME_NO_ZERO_DATE);
|
2005-12-05 11:45:04 +01:00
|
|
|
#endif
|
2005-12-08 00:17:05 +01:00
|
|
|
last_executed_changed= false;
|
2005-12-05 11:45:04 +01:00
|
|
|
|
2006-02-28 14:43:49 +01:00
|
|
|
/* ToDo : Andrey . Find a way not to allocate ptr on event_mem_root */
|
2005-12-05 11:45:04 +01:00
|
|
|
if ((ptr= get_field(mem_root, table->field[EVEX_FIELD_STATUS])) == NullS)
|
|
|
|
goto error;
|
2006-02-15 19:08:44 +01:00
|
|
|
|
2005-12-08 00:17:05 +01:00
|
|
|
DBUG_PRINT("load_from_row", ("Event [%s] is [%s]", et->name.str, ptr));
|
fix for bug#16642 (Events: No INFORMATION_SCHEMA.EVENTS table)
post-review change - use pointer instead of copy on the stack.
WL#1034 (Internal CRON)
This patch adds INFORMATION_SCHEMA.EVENTS table with the following format:
EVENT_CATALOG - MYSQL_TYPE_STRING (Always NULL)
EVENT_SCHEMA - MYSQL_TYPE_STRING (the database)
EVENT_NAME - MYSQL_TYPE_STRING (the name)
DEFINER - MYSQL_TYPE_STRING (user@host)
EVENT_BODY - MYSQL_TYPE_STRING (the body from mysql.event)
EVENT_TYPE - MYSQL_TYPE_STRING ("ONE TIME" | "RECURRING")
EXECUTE_AT - MYSQL_TYPE_TIMESTAMP (set for "ONE TIME" otherwise NULL)
INTERVAL_VALUE - MYSQL_TYPE_LONG (set for RECURRING otherwise NULL)
INTERVAL_FIELD - MYSQL_TYPE_STRING (set for RECURRING otherwise NULL)
SQL_MODE - MYSQL_TYPE_STRING (for now NULL)
STARTS - MYSQL_TYPE_TIMESTAMP (starts from mysql.event)
ENDS - MYSQL_TYPE_TIMESTAMP (ends from mysql.event)
STATUS - MYSQL_TYPE_STRING (ENABLED | DISABLED)
ON_COMPLETION - MYSQL_TYPE_STRING (NOT PRESERVE | PRESERVE)
CREATED - MYSQL_TYPE_TIMESTAMP
LAST_ALTERED - MYSQL_TYPE_TIMESTAMP
LAST_EXECUTED - MYSQL_TYPE_TIMESTAMP
EVENT_COMMENT - MYSQL_TYPE_STRING
SQL_MODE is NULL for now, because the value is still not stored in mysql.event .
Support will be added as a fix for another bug.
This patch also adds SHOW [FULL] EVENTS [FROM db] [LIKE pattern]
1. SHOW EVENTS shows always only the events on the same user,
because the PK of mysql.event is (definer, db, name) several
users may have event with the same name -> no information disclosure.
2. SHOW FULL EVENTS - shows the events (in the current db as SHOW EVENTS)
of all users. The user has to have PROCESS privilege, if not then
SHOW FULL EVENTS behave like SHOW EVENTS.
3. If [FROM db] is specified then this db is considered.
4. Event names can be filtered with LIKE pattern.
SHOW EVENTS returns table with the following columns, which are subset of
the data which is returned by SELECT * FROM I_S.EVENTS
Db
Name
Definer
Type
Execute at
Interval value
Interval field
Starts
Ends
Status
mysql-test/lib/init_db.sql:
change the PK - (definer, db, name)
quicker searches when SHOW EVENTS;
allow also different users to have events with the same name ->
no information disclosure
mysql-test/r/events.result:
result of new tests
mysql-test/r/information_schema.result:
result of new tests
mysql-test/r/information_schema_db.result:
result of new tests
mysql-test/r/system_mysql_db.result:
result of new tests
mysql-test/t/events.test:
new tests for information_schema.events
scripts/mysql_create_system_tables.sh:
change the PK of mysql.event to (definer, db, name)
scripts/mysql_fix_privilege_tables.sql:
change the PK of mysql.event to (definer, db, name)
sql/event.cc:
pass around the definer of the event because of the new PK
which is (definer, db, name). It's needed for index searching.
sql/event.h:
- make enum evex_table_field again public so it can be used
in sql_show.cc
- make created and modified ulonglong, because they should be such
- make public evex_open_event_table so it can be used in sql_show.cc
sql/event_executor.cc:
- cosmetics
sql/event_priv.h:
- moved enum evex_table_field and evex_open_event_table()
to event.h (made them therefore public)
sql/event_timed.cc:
- in event_timed::init_definer() always fill this.definer with
the concatenated value of definer_user@definer_host. Makes
later the work easier.
- pass around the definer wherever is needed for searching
(new prototype of evex_db_find_evex_aux)
sql/mysqld.cc:
- add counter for SHOW EVENTS
sql/sql_lex.h:
- register SHOW EVENTS as command
sql/sql_parse.cc:
- handle SCH_EVENTS (I_S.EVENTS like SCH_TRIGGERS)
- make additional check in case of SHOW EVENTS (check for EVENT on
the current database. if it is null check_access() gives appropriate
message back.
sql/sql_show.cc:
- add INFORMATION_SCHEMA.EVENTS and SHOW EVENTS
- I_S.EVENTS.SQL_MODE is NULL for now -> not implemented. Trudy
asked to be added so bug #16642 can be completely closed. There
is another bug report which will fix the lack of storage of
SQL_MODE during event creation.
sql/sql_yacc.yy:
- always call event_timed::init_definer() when CREATE/ALTER/DROP
EVENT but not when just compiling the body of the event because
in this case this operation is not needed, it takes memory and
CPU time and at the end the result is not used. event_timed::definer
is used only on SQLCOM_CREATE/ALTER/DROP_EVENT execution not on
statement compilation.
- add SHOW [FULL] EVENTS [FROM db] [LIKE pattern]
in case of FULL and the user has PROCESS privilege then he will see
also others' events in the current database, otherwise the output
is the same as of SHOW EVENTS. Because the events are per DB only
the events from the current database are shown. pattern is applied
against event name. FROM db is self explanatory.
sql/table.h:
add SCH_EVENTS as part of INFORMATION_SCHEMA
2006-01-30 13:15:23 +01:00
|
|
|
et->status= (ptr[0]=='E'? MYSQL_EVENT_ENABLED:MYSQL_EVENT_DISABLED);
|
2005-12-05 11:45:04 +01:00
|
|
|
|
2006-02-28 14:43:49 +01:00
|
|
|
/* ToDo : Andrey . Find a way not to allocate ptr on event_mem_root */
|
2005-12-05 11:45:04 +01:00
|
|
|
if ((ptr= get_field(mem_root,
|
|
|
|
table->field[EVEX_FIELD_ON_COMPLETION])) == NullS)
|
|
|
|
goto error;
|
|
|
|
|
2005-12-08 00:17:05 +01:00
|
|
|
et->on_completion= (ptr[0]=='D'? MYSQL_EVENT_ON_COMPLETION_DROP:
|
2006-02-28 14:43:49 +01:00
|
|
|
MYSQL_EVENT_ON_COMPLETION_PRESERVE);
|
2005-12-05 11:45:04 +01:00
|
|
|
|
2005-12-08 00:17:05 +01:00
|
|
|
et->comment.str= get_field(mem_root, table->field[EVEX_FIELD_COMMENT]);
|
|
|
|
if (et->comment.str != NullS)
|
|
|
|
et->comment.length= strlen(et->comment.str);
|
2005-12-05 11:45:04 +01:00
|
|
|
else
|
2005-12-08 00:17:05 +01:00
|
|
|
et->comment.length= 0;
|
2005-12-05 11:45:04 +01:00
|
|
|
|
2006-02-20 23:52:22 +01:00
|
|
|
|
|
|
|
et->sql_mode= (ulong) table->field[EVEX_FIELD_SQL_MODE]->val_int();
|
2006-02-15 19:08:44 +01:00
|
|
|
|
2005-12-05 11:45:04 +01:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
error:
|
|
|
|
DBUG_RETURN(EVEX_GET_FIELD_FAILED);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-12-08 00:17:05 +01:00
|
|
|
/*
|
2006-02-15 19:08:44 +01:00
|
|
|
Computes the sum of a timestamp plus interval
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
get_next_time(TIME *start, int interval_value, interval_type interval)
|
|
|
|
next the sum
|
|
|
|
start add interval_value to this time
|
|
|
|
i_value quantity of time type interval to add
|
|
|
|
i_type type of interval to add (SECOND, MINUTE, HOUR, WEEK ...)
|
2006-01-18 20:41:22 +01:00
|
|
|
*/
|
2005-12-08 00:17:05 +01:00
|
|
|
|
2006-01-18 20:41:22 +01:00
|
|
|
static
|
|
|
|
bool get_next_time(TIME *next, TIME *start, int i_value, interval_type i_type)
|
|
|
|
{
|
|
|
|
bool ret;
|
|
|
|
INTERVAL interval;
|
|
|
|
TIME tmp;
|
2006-02-15 19:08:44 +01:00
|
|
|
|
2006-01-18 20:41:22 +01:00
|
|
|
bzero(&interval, sizeof(interval));
|
|
|
|
|
|
|
|
switch (i_type) {
|
|
|
|
case INTERVAL_YEAR:
|
|
|
|
interval.year= (ulong) i_value;
|
|
|
|
break;
|
|
|
|
case INTERVAL_QUARTER:
|
|
|
|
interval.month= (ulong)(i_value*3);
|
|
|
|
break;
|
|
|
|
case INTERVAL_YEAR_MONTH:
|
|
|
|
case INTERVAL_MONTH:
|
|
|
|
interval.month= (ulong) i_value;
|
|
|
|
break;
|
|
|
|
case INTERVAL_WEEK:
|
|
|
|
interval.day= (ulong)(i_value*7);
|
|
|
|
break;
|
|
|
|
case INTERVAL_DAY:
|
|
|
|
interval.day= (ulong) i_value;
|
|
|
|
break;
|
|
|
|
case INTERVAL_DAY_HOUR:
|
|
|
|
case INTERVAL_HOUR:
|
|
|
|
interval.hour= (ulong) i_value;
|
|
|
|
break;
|
|
|
|
case INTERVAL_DAY_MINUTE:
|
|
|
|
case INTERVAL_HOUR_MINUTE:
|
|
|
|
case INTERVAL_MINUTE:
|
|
|
|
interval.minute=i_value;
|
|
|
|
break;
|
|
|
|
case INTERVAL_DAY_SECOND:
|
|
|
|
case INTERVAL_HOUR_SECOND:
|
|
|
|
case INTERVAL_MINUTE_SECOND:
|
|
|
|
case INTERVAL_SECOND:
|
|
|
|
interval.second=i_value;
|
|
|
|
break;
|
|
|
|
case INTERVAL_DAY_MICROSECOND:
|
|
|
|
case INTERVAL_HOUR_MICROSECOND:
|
|
|
|
case INTERVAL_MINUTE_MICROSECOND:
|
|
|
|
case INTERVAL_SECOND_MICROSECOND:
|
|
|
|
case INTERVAL_MICROSECOND:
|
|
|
|
interval.second_part=i_value;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
tmp= *start;
|
|
|
|
if (!(ret= date_add_interval(&tmp, i_type, interval)))
|
|
|
|
*next= tmp;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2006-02-15 19:08:44 +01:00
|
|
|
Computes next execution time.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
event_timed::compute_next_execution_time()
|
|
|
|
|
|
|
|
NOTES
|
|
|
|
The time is set in execute_at, if no more executions the latter is set to
|
|
|
|
0000-00-00.
|
2005-12-08 00:17:05 +01:00
|
|
|
*/
|
|
|
|
|
2005-12-05 11:45:04 +01:00
|
|
|
bool
|
|
|
|
event_timed::compute_next_execution_time()
|
|
|
|
{
|
|
|
|
TIME time_now;
|
|
|
|
my_time_t now;
|
|
|
|
int tmp;
|
|
|
|
|
|
|
|
DBUG_ENTER("event_timed::compute_next_execution_time");
|
|
|
|
|
2005-12-08 00:17:05 +01:00
|
|
|
if (status == MYSQL_EVENT_DISABLED)
|
2005-12-05 11:45:04 +01:00
|
|
|
{
|
|
|
|
DBUG_PRINT("compute_next_execution_time",
|
2005-12-08 00:17:05 +01:00
|
|
|
("Event %s is DISABLED", name.str));
|
2005-12-05 11:45:04 +01:00
|
|
|
goto ret;
|
|
|
|
}
|
2006-02-15 19:08:44 +01:00
|
|
|
/* If one-time, no need to do computation */
|
2005-12-08 00:17:05 +01:00
|
|
|
if (!expression)
|
2005-12-05 11:45:04 +01:00
|
|
|
{
|
2006-02-15 19:08:44 +01:00
|
|
|
/* Let's check whether it was executed */
|
2005-12-08 00:17:05 +01:00
|
|
|
if (last_executed.year)
|
2005-12-05 11:45:04 +01:00
|
|
|
{
|
2006-02-28 11:43:10 +01:00
|
|
|
DBUG_PRINT("info",("One-time event %s.%s of was already executed",
|
|
|
|
dbname.str, name.str, definer.str));
|
|
|
|
dropped= (on_completion == MYSQL_EVENT_ON_COMPLETION_DROP);
|
|
|
|
DBUG_PRINT("info",("One-time event will be dropped=%d.", dropped));
|
|
|
|
|
2005-12-08 00:17:05 +01:00
|
|
|
status= MYSQL_EVENT_DISABLED;
|
|
|
|
status_changed= true;
|
2005-12-05 11:45:04 +01:00
|
|
|
}
|
|
|
|
goto ret;
|
|
|
|
}
|
2006-01-12 16:51:45 +01:00
|
|
|
time((time_t *)&now);
|
2005-12-05 11:45:04 +01:00
|
|
|
my_tz_UTC->gmt_sec_to_TIME(&time_now, now);
|
fix for bug#16642 (Events: No INFORMATION_SCHEMA.EVENTS table)
post-review change - use pointer instead of copy on the stack.
WL#1034 (Internal CRON)
This patch adds INFORMATION_SCHEMA.EVENTS table with the following format:
EVENT_CATALOG - MYSQL_TYPE_STRING (Always NULL)
EVENT_SCHEMA - MYSQL_TYPE_STRING (the database)
EVENT_NAME - MYSQL_TYPE_STRING (the name)
DEFINER - MYSQL_TYPE_STRING (user@host)
EVENT_BODY - MYSQL_TYPE_STRING (the body from mysql.event)
EVENT_TYPE - MYSQL_TYPE_STRING ("ONE TIME" | "RECURRING")
EXECUTE_AT - MYSQL_TYPE_TIMESTAMP (set for "ONE TIME" otherwise NULL)
INTERVAL_VALUE - MYSQL_TYPE_LONG (set for RECURRING otherwise NULL)
INTERVAL_FIELD - MYSQL_TYPE_STRING (set for RECURRING otherwise NULL)
SQL_MODE - MYSQL_TYPE_STRING (for now NULL)
STARTS - MYSQL_TYPE_TIMESTAMP (starts from mysql.event)
ENDS - MYSQL_TYPE_TIMESTAMP (ends from mysql.event)
STATUS - MYSQL_TYPE_STRING (ENABLED | DISABLED)
ON_COMPLETION - MYSQL_TYPE_STRING (NOT PRESERVE | PRESERVE)
CREATED - MYSQL_TYPE_TIMESTAMP
LAST_ALTERED - MYSQL_TYPE_TIMESTAMP
LAST_EXECUTED - MYSQL_TYPE_TIMESTAMP
EVENT_COMMENT - MYSQL_TYPE_STRING
SQL_MODE is NULL for now, because the value is still not stored in mysql.event .
Support will be added as a fix for another bug.
This patch also adds SHOW [FULL] EVENTS [FROM db] [LIKE pattern]
1. SHOW EVENTS shows always only the events on the same user,
because the PK of mysql.event is (definer, db, name) several
users may have event with the same name -> no information disclosure.
2. SHOW FULL EVENTS - shows the events (in the current db as SHOW EVENTS)
of all users. The user has to have PROCESS privilege, if not then
SHOW FULL EVENTS behave like SHOW EVENTS.
3. If [FROM db] is specified then this db is considered.
4. Event names can be filtered with LIKE pattern.
SHOW EVENTS returns table with the following columns, which are subset of
the data which is returned by SELECT * FROM I_S.EVENTS
Db
Name
Definer
Type
Execute at
Interval value
Interval field
Starts
Ends
Status
mysql-test/lib/init_db.sql:
change the PK - (definer, db, name)
quicker searches when SHOW EVENTS;
allow also different users to have events with the same name ->
no information disclosure
mysql-test/r/events.result:
result of new tests
mysql-test/r/information_schema.result:
result of new tests
mysql-test/r/information_schema_db.result:
result of new tests
mysql-test/r/system_mysql_db.result:
result of new tests
mysql-test/t/events.test:
new tests for information_schema.events
scripts/mysql_create_system_tables.sh:
change the PK of mysql.event to (definer, db, name)
scripts/mysql_fix_privilege_tables.sql:
change the PK of mysql.event to (definer, db, name)
sql/event.cc:
pass around the definer of the event because of the new PK
which is (definer, db, name). It's needed for index searching.
sql/event.h:
- make enum evex_table_field again public so it can be used
in sql_show.cc
- make created and modified ulonglong, because they should be such
- make public evex_open_event_table so it can be used in sql_show.cc
sql/event_executor.cc:
- cosmetics
sql/event_priv.h:
- moved enum evex_table_field and evex_open_event_table()
to event.h (made them therefore public)
sql/event_timed.cc:
- in event_timed::init_definer() always fill this.definer with
the concatenated value of definer_user@definer_host. Makes
later the work easier.
- pass around the definer wherever is needed for searching
(new prototype of evex_db_find_evex_aux)
sql/mysqld.cc:
- add counter for SHOW EVENTS
sql/sql_lex.h:
- register SHOW EVENTS as command
sql/sql_parse.cc:
- handle SCH_EVENTS (I_S.EVENTS like SCH_TRIGGERS)
- make additional check in case of SHOW EVENTS (check for EVENT on
the current database. if it is null check_access() gives appropriate
message back.
sql/sql_show.cc:
- add INFORMATION_SCHEMA.EVENTS and SHOW EVENTS
- I_S.EVENTS.SQL_MODE is NULL for now -> not implemented. Trudy
asked to be added so bug #16642 can be completely closed. There
is another bug report which will fix the lack of storage of
SQL_MODE during event creation.
sql/sql_yacc.yy:
- always call event_timed::init_definer() when CREATE/ALTER/DROP
EVENT but not when just compiling the body of the event because
in this case this operation is not needed, it takes memory and
CPU time and at the end the result is not used. event_timed::definer
is used only on SQLCOM_CREATE/ALTER/DROP_EVENT execution not on
statement compilation.
- add SHOW [FULL] EVENTS [FROM db] [LIKE pattern]
in case of FULL and the user has PROCESS privilege then he will see
also others' events in the current database, otherwise the output
is the same as of SHOW EVENTS. Because the events are per DB only
the events from the current database are shown. pattern is applied
against event name. FROM db is self explanatory.
sql/table.h:
add SCH_EVENTS as part of INFORMATION_SCHEMA
2006-01-30 13:15:23 +01:00
|
|
|
|
|
|
|
#ifdef ANDREY_0
|
2005-12-08 00:17:05 +01:00
|
|
|
sql_print_information("[%s.%s]", dbname.str, name.str);
|
2006-02-15 19:08:44 +01:00
|
|
|
sql_print_information("time_now : [%d-%d-%d %d:%d:%d ]",
|
2005-12-07 22:29:00 +01:00
|
|
|
time_now.year, time_now.month, time_now.day,
|
|
|
|
time_now.hour, time_now.minute, time_now.second);
|
2005-12-08 00:17:05 +01:00
|
|
|
sql_print_information("starts : [%d-%d-%d %d:%d:%d ]", starts.year,
|
|
|
|
starts.month, starts.day, starts.hour,
|
|
|
|
starts.minute, starts.second);
|
|
|
|
sql_print_information("ends : [%d-%d-%d %d:%d:%d ]", ends.year,
|
|
|
|
ends.month, ends.day, ends.hour,
|
|
|
|
ends.minute, ends.second);
|
|
|
|
sql_print_information("m_last_ex: [%d-%d-%d %d:%d:%d ]", last_executed.year,
|
|
|
|
last_executed.month, last_executed.day,
|
|
|
|
last_executed.hour, last_executed.minute,
|
|
|
|
last_executed.second);
|
fix for bug#16642 (Events: No INFORMATION_SCHEMA.EVENTS table)
post-review change - use pointer instead of copy on the stack.
WL#1034 (Internal CRON)
This patch adds INFORMATION_SCHEMA.EVENTS table with the following format:
EVENT_CATALOG - MYSQL_TYPE_STRING (Always NULL)
EVENT_SCHEMA - MYSQL_TYPE_STRING (the database)
EVENT_NAME - MYSQL_TYPE_STRING (the name)
DEFINER - MYSQL_TYPE_STRING (user@host)
EVENT_BODY - MYSQL_TYPE_STRING (the body from mysql.event)
EVENT_TYPE - MYSQL_TYPE_STRING ("ONE TIME" | "RECURRING")
EXECUTE_AT - MYSQL_TYPE_TIMESTAMP (set for "ONE TIME" otherwise NULL)
INTERVAL_VALUE - MYSQL_TYPE_LONG (set for RECURRING otherwise NULL)
INTERVAL_FIELD - MYSQL_TYPE_STRING (set for RECURRING otherwise NULL)
SQL_MODE - MYSQL_TYPE_STRING (for now NULL)
STARTS - MYSQL_TYPE_TIMESTAMP (starts from mysql.event)
ENDS - MYSQL_TYPE_TIMESTAMP (ends from mysql.event)
STATUS - MYSQL_TYPE_STRING (ENABLED | DISABLED)
ON_COMPLETION - MYSQL_TYPE_STRING (NOT PRESERVE | PRESERVE)
CREATED - MYSQL_TYPE_TIMESTAMP
LAST_ALTERED - MYSQL_TYPE_TIMESTAMP
LAST_EXECUTED - MYSQL_TYPE_TIMESTAMP
EVENT_COMMENT - MYSQL_TYPE_STRING
SQL_MODE is NULL for now, because the value is still not stored in mysql.event .
Support will be added as a fix for another bug.
This patch also adds SHOW [FULL] EVENTS [FROM db] [LIKE pattern]
1. SHOW EVENTS shows always only the events on the same user,
because the PK of mysql.event is (definer, db, name) several
users may have event with the same name -> no information disclosure.
2. SHOW FULL EVENTS - shows the events (in the current db as SHOW EVENTS)
of all users. The user has to have PROCESS privilege, if not then
SHOW FULL EVENTS behave like SHOW EVENTS.
3. If [FROM db] is specified then this db is considered.
4. Event names can be filtered with LIKE pattern.
SHOW EVENTS returns table with the following columns, which are subset of
the data which is returned by SELECT * FROM I_S.EVENTS
Db
Name
Definer
Type
Execute at
Interval value
Interval field
Starts
Ends
Status
mysql-test/lib/init_db.sql:
change the PK - (definer, db, name)
quicker searches when SHOW EVENTS;
allow also different users to have events with the same name ->
no information disclosure
mysql-test/r/events.result:
result of new tests
mysql-test/r/information_schema.result:
result of new tests
mysql-test/r/information_schema_db.result:
result of new tests
mysql-test/r/system_mysql_db.result:
result of new tests
mysql-test/t/events.test:
new tests for information_schema.events
scripts/mysql_create_system_tables.sh:
change the PK of mysql.event to (definer, db, name)
scripts/mysql_fix_privilege_tables.sql:
change the PK of mysql.event to (definer, db, name)
sql/event.cc:
pass around the definer of the event because of the new PK
which is (definer, db, name). It's needed for index searching.
sql/event.h:
- make enum evex_table_field again public so it can be used
in sql_show.cc
- make created and modified ulonglong, because they should be such
- make public evex_open_event_table so it can be used in sql_show.cc
sql/event_executor.cc:
- cosmetics
sql/event_priv.h:
- moved enum evex_table_field and evex_open_event_table()
to event.h (made them therefore public)
sql/event_timed.cc:
- in event_timed::init_definer() always fill this.definer with
the concatenated value of definer_user@definer_host. Makes
later the work easier.
- pass around the definer wherever is needed for searching
(new prototype of evex_db_find_evex_aux)
sql/mysqld.cc:
- add counter for SHOW EVENTS
sql/sql_lex.h:
- register SHOW EVENTS as command
sql/sql_parse.cc:
- handle SCH_EVENTS (I_S.EVENTS like SCH_TRIGGERS)
- make additional check in case of SHOW EVENTS (check for EVENT on
the current database. if it is null check_access() gives appropriate
message back.
sql/sql_show.cc:
- add INFORMATION_SCHEMA.EVENTS and SHOW EVENTS
- I_S.EVENTS.SQL_MODE is NULL for now -> not implemented. Trudy
asked to be added so bug #16642 can be completely closed. There
is another bug report which will fix the lack of storage of
SQL_MODE during event creation.
sql/sql_yacc.yy:
- always call event_timed::init_definer() when CREATE/ALTER/DROP
EVENT but not when just compiling the body of the event because
in this case this operation is not needed, it takes memory and
CPU time and at the end the result is not used. event_timed::definer
is used only on SQLCOM_CREATE/ALTER/DROP_EVENT execution not on
statement compilation.
- add SHOW [FULL] EVENTS [FROM db] [LIKE pattern]
in case of FULL and the user has PROCESS privilege then he will see
also others' events in the current database, otherwise the output
is the same as of SHOW EVENTS. Because the events are per DB only
the events from the current database are shown. pattern is applied
against event name. FROM db is self explanatory.
sql/table.h:
add SCH_EVENTS as part of INFORMATION_SCHEMA
2006-01-30 13:15:23 +01:00
|
|
|
#endif
|
|
|
|
|
2006-02-28 12:08:13 +01:00
|
|
|
/* if time_now is after ends don't execute anymore */
|
2006-02-28 11:43:10 +01:00
|
|
|
if (!ends_null && (tmp= my_time_compare(&ends, &time_now)) == -1)
|
2005-12-05 11:45:04 +01:00
|
|
|
{
|
2006-02-15 19:08:44 +01:00
|
|
|
/* time_now is after ends. don't execute anymore */
|
2005-12-08 00:17:05 +01:00
|
|
|
set_zero_time(&execute_at, MYSQL_TIMESTAMP_DATETIME);
|
2006-02-28 11:43:10 +01:00
|
|
|
execute_at_null= TRUE;
|
2005-12-08 00:17:05 +01:00
|
|
|
if (on_completion == MYSQL_EVENT_ON_COMPLETION_DROP)
|
|
|
|
dropped= true;
|
|
|
|
status= MYSQL_EVENT_DISABLED;
|
|
|
|
status_changed= true;
|
2005-12-05 11:45:04 +01:00
|
|
|
|
|
|
|
goto ret;
|
|
|
|
}
|
2006-02-15 19:08:44 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
Here time_now is before or equals ends if the latter is set.
|
|
|
|
Let's check whether time_now is before starts.
|
|
|
|
If so schedule for starts.
|
2005-12-05 11:45:04 +01:00
|
|
|
*/
|
2006-02-28 11:43:10 +01:00
|
|
|
if (!starts_null && (tmp= my_time_compare(&time_now, &starts)) < 1)
|
2005-12-05 11:45:04 +01:00
|
|
|
{
|
2005-12-08 00:17:05 +01:00
|
|
|
if (tmp == 0 && my_time_compare(&starts, &last_executed) == 0)
|
2005-12-05 11:45:04 +01:00
|
|
|
{
|
2006-02-15 19:08:44 +01:00
|
|
|
/*
|
2005-12-08 00:17:05 +01:00
|
|
|
time_now = starts = last_executed
|
|
|
|
do nothing or we will schedule for second time execution at starts.
|
2005-12-05 11:45:04 +01:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-12-08 00:17:05 +01:00
|
|
|
/*
|
|
|
|
starts is in the future
|
|
|
|
time_now before starts. Scheduling for starts
|
|
|
|
*/
|
|
|
|
execute_at= starts;
|
2006-02-28 11:43:10 +01:00
|
|
|
execute_at_null= FALSE;
|
2005-12-05 11:45:04 +01:00
|
|
|
goto ret;
|
|
|
|
}
|
|
|
|
}
|
2006-02-28 14:43:49 +01:00
|
|
|
|
2006-02-28 11:43:10 +01:00
|
|
|
if (!starts_null && !ends_null)
|
2005-12-05 11:45:04 +01:00
|
|
|
{
|
2006-02-15 19:08:44 +01:00
|
|
|
/*
|
2005-12-08 00:17:05 +01:00
|
|
|
Both starts and m_ends are set and time_now is between them (incl.)
|
|
|
|
If last_executed is set then increase with m_expression. The new TIME is
|
|
|
|
after m_ends set execute_at to 0. And check for on_completion
|
2005-12-05 11:45:04 +01:00
|
|
|
If not set then schedule for now.
|
|
|
|
*/
|
2005-12-08 00:17:05 +01:00
|
|
|
if (!last_executed.year)
|
2006-02-28 11:43:10 +01:00
|
|
|
{
|
2005-12-08 00:17:05 +01:00
|
|
|
execute_at= time_now;
|
2006-02-28 11:43:10 +01:00
|
|
|
execute_at_null= FALSE;
|
|
|
|
}
|
2005-12-05 11:45:04 +01:00
|
|
|
else
|
|
|
|
{
|
2006-01-18 20:41:22 +01:00
|
|
|
TIME next_exec;
|
2006-02-15 19:08:44 +01:00
|
|
|
|
2006-01-18 20:41:22 +01:00
|
|
|
if (get_next_time(&next_exec, &last_executed, expression, interval))
|
|
|
|
goto err;
|
2006-02-15 19:08:44 +01:00
|
|
|
|
|
|
|
/* There was previous execution */
|
2006-01-18 20:41:22 +01:00
|
|
|
if (my_time_compare(&ends, &next_exec) == -1)
|
2005-12-05 11:45:04 +01:00
|
|
|
{
|
2006-02-15 19:08:44 +01:00
|
|
|
/* Next execution after ends. No more executions */
|
2005-12-08 00:17:05 +01:00
|
|
|
set_zero_time(&execute_at, MYSQL_TIMESTAMP_DATETIME);
|
2006-02-28 11:43:10 +01:00
|
|
|
execute_at_null= TRUE;
|
2005-12-08 00:17:05 +01:00
|
|
|
if (on_completion == MYSQL_EVENT_ON_COMPLETION_DROP)
|
|
|
|
dropped= true;
|
2005-12-05 11:45:04 +01:00
|
|
|
}
|
|
|
|
else
|
2006-02-28 11:43:10 +01:00
|
|
|
{
|
2006-01-18 20:41:22 +01:00
|
|
|
execute_at= next_exec;
|
2006-02-28 11:43:10 +01:00
|
|
|
execute_at_null= FALSE;
|
|
|
|
}
|
2005-12-05 11:45:04 +01:00
|
|
|
}
|
|
|
|
goto ret;
|
|
|
|
}
|
2006-02-28 11:43:10 +01:00
|
|
|
else if (starts_null && ends_null)
|
2005-12-05 11:45:04 +01:00
|
|
|
{
|
2006-02-15 19:08:44 +01:00
|
|
|
/*
|
|
|
|
Both starts and m_ends are not set, so we schedule for the next
|
|
|
|
based on last_executed.
|
|
|
|
*/
|
2006-01-18 20:41:22 +01:00
|
|
|
if (last_executed.year)
|
|
|
|
{
|
|
|
|
if (get_next_time(&execute_at, &last_executed, expression, interval))
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
else
|
2006-02-15 19:08:44 +01:00
|
|
|
{
|
|
|
|
/* last_executed not set. Schedule the event for now */
|
2005-12-08 00:17:05 +01:00
|
|
|
execute_at= time_now;
|
2006-02-15 19:08:44 +01:00
|
|
|
}
|
2006-02-28 11:43:10 +01:00
|
|
|
execute_at_null= FALSE;
|
2005-12-05 11:45:04 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-02-28 12:08:13 +01:00
|
|
|
/* either starts or m_ends is set */
|
2006-02-28 11:43:10 +01:00
|
|
|
if (!starts_null)
|
2005-12-05 11:45:04 +01:00
|
|
|
{
|
|
|
|
/*
|
2005-12-08 00:17:05 +01:00
|
|
|
- starts is set.
|
|
|
|
- starts is not in the future according to check made before
|
|
|
|
Hence schedule for starts + m_expression in case last_executed
|
|
|
|
is not set, otherwise to last_executed + m_expression
|
2005-12-05 11:45:04 +01:00
|
|
|
*/
|
2005-12-08 00:17:05 +01:00
|
|
|
if (last_executed.year)
|
2006-01-18 20:41:22 +01:00
|
|
|
{
|
|
|
|
if (get_next_time(&execute_at, &last_executed, expression, interval))
|
|
|
|
goto err;
|
|
|
|
}
|
2005-12-05 11:45:04 +01:00
|
|
|
else
|
2006-01-18 20:41:22 +01:00
|
|
|
execute_at= starts;
|
2006-02-28 11:43:10 +01:00
|
|
|
execute_at_null= FALSE;
|
2005-12-05 11:45:04 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
- m_ends is set
|
|
|
|
- m_ends is after time_now or is equal
|
2005-12-08 00:17:05 +01:00
|
|
|
Hence check for m_last_execute and increment with m_expression.
|
|
|
|
If last_executed is not set then schedule for now
|
2005-12-05 11:45:04 +01:00
|
|
|
*/
|
|
|
|
|
2005-12-08 00:17:05 +01:00
|
|
|
if (!last_executed.year)
|
|
|
|
execute_at= time_now;
|
2005-12-05 11:45:04 +01:00
|
|
|
else
|
|
|
|
{
|
2006-01-18 20:41:22 +01:00
|
|
|
TIME next_exec;
|
|
|
|
|
|
|
|
if (get_next_time(&next_exec, &last_executed, expression, interval))
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
if (my_time_compare(&ends, &next_exec) == -1)
|
2005-12-05 11:45:04 +01:00
|
|
|
{
|
2005-12-08 00:17:05 +01:00
|
|
|
set_zero_time(&execute_at, MYSQL_TIMESTAMP_DATETIME);
|
2006-02-28 11:43:10 +01:00
|
|
|
execute_at_null= TRUE;
|
2005-12-08 00:17:05 +01:00
|
|
|
if (on_completion == MYSQL_EVENT_ON_COMPLETION_DROP)
|
|
|
|
dropped= true;
|
2005-12-05 11:45:04 +01:00
|
|
|
}
|
|
|
|
else
|
2006-02-28 11:43:10 +01:00
|
|
|
{
|
2006-01-18 20:41:22 +01:00
|
|
|
execute_at= next_exec;
|
2006-02-28 11:43:10 +01:00
|
|
|
execute_at_null= FALSE;
|
|
|
|
}
|
2005-12-05 11:45:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
goto ret;
|
|
|
|
}
|
|
|
|
ret:
|
|
|
|
|
|
|
|
DBUG_RETURN(false);
|
2006-01-18 20:41:22 +01:00
|
|
|
err:
|
|
|
|
DBUG_RETURN(true);
|
2005-12-05 11:45:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-14 16:20:48 +01:00
|
|
|
/*
|
|
|
|
Set the internal last_executed TIME struct to now. NOW is the
|
|
|
|
time according to thd->query_start(), so the THD's clock.
|
2006-02-15 19:08:44 +01:00
|
|
|
|
|
|
|
SYNOPSIS
|
2006-02-14 16:20:48 +01:00
|
|
|
event_timed::drop()
|
2006-02-15 19:08:44 +01:00
|
|
|
thd thread context
|
2006-02-14 16:20:48 +01:00
|
|
|
*/
|
|
|
|
|
2005-12-05 11:45:04 +01:00
|
|
|
void
|
2006-01-18 20:41:22 +01:00
|
|
|
event_timed::mark_last_executed(THD *thd)
|
2005-12-05 11:45:04 +01:00
|
|
|
{
|
|
|
|
TIME time_now;
|
|
|
|
|
2006-01-18 20:41:22 +01:00
|
|
|
thd->end_time();
|
|
|
|
my_tz_UTC->gmt_sec_to_TIME(&time_now, (my_time_t) thd->query_start());
|
2005-12-05 11:45:04 +01:00
|
|
|
|
2006-02-28 14:43:49 +01:00
|
|
|
last_executed= time_now; /* was execute_at */
|
2005-12-05 11:45:04 +01:00
|
|
|
#ifdef ANDREY_0
|
2005-12-08 00:17:05 +01:00
|
|
|
last_executed= execute_at;
|
2005-12-05 11:45:04 +01:00
|
|
|
#endif
|
2005-12-08 00:17:05 +01:00
|
|
|
last_executed_changed= true;
|
2005-12-05 11:45:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-12-20 13:21:02 +01:00
|
|
|
/*
|
2006-02-14 16:20:48 +01:00
|
|
|
Drops the event
|
2006-02-15 19:08:44 +01:00
|
|
|
|
|
|
|
SYNOPSIS
|
2006-02-14 16:20:48 +01:00
|
|
|
event_timed::drop()
|
2006-02-15 19:08:44 +01:00
|
|
|
thd thread context
|
2006-02-14 16:20:48 +01:00
|
|
|
|
2006-02-15 19:08:44 +01:00
|
|
|
RETURN VALUE
|
|
|
|
0 OK
|
|
|
|
-1 Cannot open mysql.event
|
|
|
|
-2 Cannot find the event in mysql.event (already deleted?)
|
|
|
|
|
|
|
|
others return code from SE in case deletion of the event row
|
2005-12-20 13:21:02 +01:00
|
|
|
failed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
2005-12-05 11:45:04 +01:00
|
|
|
event_timed::drop(THD *thd)
|
|
|
|
{
|
2005-12-20 13:21:02 +01:00
|
|
|
TABLE *table;
|
2006-02-07 19:28:33 +01:00
|
|
|
uint tmp= 0;
|
2005-12-20 13:21:02 +01:00
|
|
|
DBUG_ENTER("event_timed::drop");
|
|
|
|
|
2006-02-07 19:28:33 +01:00
|
|
|
DBUG_RETURN(db_drop_event(thd, this, false, &tmp));
|
2005-12-05 11:45:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-14 16:20:48 +01:00
|
|
|
/*
|
|
|
|
Saves status and last_executed_at to the disk if changed.
|
2006-02-15 19:08:44 +01:00
|
|
|
|
|
|
|
SYNOPSIS
|
2006-02-16 01:27:36 +01:00
|
|
|
event_timed::update_fields()
|
2006-02-14 16:20:48 +01:00
|
|
|
thd - thread context
|
|
|
|
|
2006-02-15 19:08:44 +01:00
|
|
|
RETURN VALUE
|
|
|
|
0 OK
|
|
|
|
SP_OPEN_TABLE_FAILED Error while opening mysql.event for writing
|
|
|
|
EVEX_WRITE_ROW_FAILED On error to write to disk
|
|
|
|
|
|
|
|
others return code from SE in case deletion of the event
|
|
|
|
row failed.
|
2006-02-14 16:20:48 +01:00
|
|
|
*/
|
|
|
|
|
2005-12-05 11:45:04 +01:00
|
|
|
bool
|
|
|
|
event_timed::update_fields(THD *thd)
|
|
|
|
{
|
|
|
|
TABLE *table;
|
2005-12-13 23:10:29 +01:00
|
|
|
Open_tables_state backup;
|
2005-12-05 11:45:04 +01:00
|
|
|
int ret= 0;
|
|
|
|
bool opened;
|
|
|
|
|
|
|
|
DBUG_ENTER("event_timed::update_time_fields");
|
|
|
|
|
2005-12-08 00:17:05 +01:00
|
|
|
DBUG_PRINT("enter", ("name: %*s", name.length, name.str));
|
2006-02-15 19:08:44 +01:00
|
|
|
|
|
|
|
/* No need to update if nothing has changed */
|
2005-12-08 00:17:05 +01:00
|
|
|
if (!(status_changed || last_executed_changed))
|
2005-12-05 11:45:04 +01:00
|
|
|
goto done;
|
2006-02-15 19:08:44 +01:00
|
|
|
|
2005-12-13 23:10:29 +01:00
|
|
|
thd->reset_n_backup_open_tables_state(&backup);
|
|
|
|
|
2005-12-16 12:42:39 +01:00
|
|
|
if (evex_open_event_table(thd, TL_WRITE, &table))
|
2005-12-13 23:10:29 +01:00
|
|
|
{
|
|
|
|
ret= SP_OPEN_TABLE_FAILED;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2005-12-05 11:45:04 +01:00
|
|
|
|
2006-02-16 00:43:11 +01:00
|
|
|
if ((ret= evex_db_find_event_by_name(thd, dbname, name, definer, table)))
|
2005-12-05 11:45:04 +01:00
|
|
|
goto done;
|
|
|
|
|
|
|
|
store_record(table,record[1]);
|
2006-02-15 19:08:44 +01:00
|
|
|
/* Don't update create on row update. */
|
|
|
|
table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
|
2005-12-05 11:45:04 +01:00
|
|
|
|
2005-12-08 00:17:05 +01:00
|
|
|
if (last_executed_changed)
|
2005-12-05 11:45:04 +01:00
|
|
|
{
|
|
|
|
table->field[EVEX_FIELD_LAST_EXECUTED]->set_notnull();
|
2005-12-08 00:17:05 +01:00
|
|
|
table->field[EVEX_FIELD_LAST_EXECUTED]->store_time(&last_executed,
|
2005-12-05 11:45:04 +01:00
|
|
|
MYSQL_TIMESTAMP_DATETIME);
|
2005-12-08 00:17:05 +01:00
|
|
|
last_executed_changed= false;
|
2005-12-05 11:45:04 +01:00
|
|
|
}
|
2005-12-08 00:17:05 +01:00
|
|
|
if (status_changed)
|
2005-12-05 11:45:04 +01:00
|
|
|
{
|
|
|
|
table->field[EVEX_FIELD_STATUS]->set_notnull();
|
2005-12-08 00:17:05 +01:00
|
|
|
table->field[EVEX_FIELD_STATUS]->store((longlong)status);
|
|
|
|
status_changed= false;
|
2005-12-05 11:45:04 +01:00
|
|
|
}
|
2006-02-15 19:08:44 +01:00
|
|
|
|
2006-01-11 12:49:56 +01:00
|
|
|
if ((table->file->ha_update_row(table->record[1],table->record[0])))
|
2005-12-05 11:45:04 +01:00
|
|
|
ret= EVEX_WRITE_ROW_FAILED;
|
|
|
|
|
|
|
|
done:
|
|
|
|
close_thread_tables(thd);
|
2005-12-13 23:10:29 +01:00
|
|
|
thd->restore_backup_open_tables_state(&backup);
|
2005-12-05 11:45:04 +01:00
|
|
|
|
|
|
|
DBUG_RETURN(ret);
|
|
|
|
}
|
|
|
|
|
2006-02-16 13:11:16 +01:00
|
|
|
extern LEX_STRING interval_type_to_name[];
|
2005-12-05 11:45:04 +01:00
|
|
|
|
2006-02-14 16:20:48 +01:00
|
|
|
/*
|
|
|
|
Get SHOW CREATE EVENT as string
|
2006-02-15 19:08:44 +01:00
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
event_timed::get_create_event(THD *thd, String *buf)
|
|
|
|
thd Thread
|
|
|
|
buf String*, should be already allocated. CREATE EVENT goes inside.
|
|
|
|
|
|
|
|
RETURN VALUE
|
2006-02-20 16:06:05 +01:00
|
|
|
0 OK
|
|
|
|
EVEX_MICROSECOND_UNSUP Error (for now if mysql.event has been
|
|
|
|
tampered and MICROSECONDS interval or
|
|
|
|
derivative has been put there.
|
2006-02-14 16:20:48 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
event_timed::get_create_event(THD *thd, String *buf)
|
2005-12-05 11:45:04 +01:00
|
|
|
{
|
2006-02-14 16:20:48 +01:00
|
|
|
int multipl= 0;
|
|
|
|
char tmp_buff[128];
|
|
|
|
String expr_buf(tmp_buff, sizeof(tmp_buff), system_charset_info);
|
|
|
|
expr_buf.length(0);
|
|
|
|
|
|
|
|
DBUG_ENTER("get_create_event");
|
2006-01-20 22:24:58 +01:00
|
|
|
DBUG_PRINT("ret_info",("body_len=[%d]body=[%s]", body.length, body.str));
|
2005-12-05 11:45:04 +01:00
|
|
|
|
2006-02-14 16:20:48 +01:00
|
|
|
if (expression &&
|
|
|
|
event_reconstruct_interval_expression(&expr_buf, interval, expression))
|
2006-02-20 16:06:05 +01:00
|
|
|
DBUG_RETURN(EVEX_MICROSECOND_UNSUP);
|
2006-02-14 16:20:48 +01:00
|
|
|
|
|
|
|
buf->append(STRING_WITH_LEN("CREATE EVENT "));
|
|
|
|
append_identifier(thd, buf, dbname.str, dbname.length);
|
|
|
|
buf->append(STRING_WITH_LEN("."));
|
|
|
|
append_identifier(thd, buf, name.str, name.length);
|
|
|
|
|
|
|
|
buf->append(STRING_WITH_LEN(" ON SCHEDULE "));
|
|
|
|
if (expression)
|
|
|
|
{
|
|
|
|
buf->append(STRING_WITH_LEN("EVERY "));
|
|
|
|
buf->append(expr_buf);
|
2006-02-16 13:11:16 +01:00
|
|
|
buf->append(' ');
|
|
|
|
LEX_STRING *ival= &interval_type_to_name[interval];
|
|
|
|
buf->append(ival->str, ival->length);
|
2006-02-14 16:20:48 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-02-28 14:43:49 +01:00
|
|
|
char dtime_buff[20*2+32];/* +32 to make my_snprintf_{8bit|ucs2} happy */
|
2006-02-14 16:20:48 +01:00
|
|
|
buf->append(STRING_WITH_LEN("AT '"));
|
2006-02-15 19:08:44 +01:00
|
|
|
/*
|
|
|
|
Pass the buffer and the second param tells fills the buffer and
|
|
|
|
returns the number of chars to copy.
|
2006-02-14 16:20:48 +01:00
|
|
|
*/
|
|
|
|
buf->append(dtime_buff, my_datetime_to_str(&execute_at, dtime_buff));
|
|
|
|
buf->append(STRING_WITH_LEN("'"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (on_completion == MYSQL_EVENT_ON_COMPLETION_DROP)
|
|
|
|
buf->append(STRING_WITH_LEN(" ON COMPLETION NOT PRESERVE "));
|
|
|
|
else
|
|
|
|
buf->append(STRING_WITH_LEN(" ON COMPLETION PRESERVE "));
|
|
|
|
|
|
|
|
if (status == MYSQL_EVENT_ENABLED)
|
|
|
|
buf->append(STRING_WITH_LEN("ENABLE"));
|
|
|
|
else
|
|
|
|
buf->append(STRING_WITH_LEN("DISABLE"));
|
|
|
|
|
|
|
|
if (comment.length)
|
|
|
|
{
|
|
|
|
buf->append(STRING_WITH_LEN(" COMMENT "));
|
|
|
|
append_unescaped(buf, comment.str, comment.length);
|
|
|
|
}
|
|
|
|
buf->append(STRING_WITH_LEN(" DO "));
|
2006-02-15 19:08:44 +01:00
|
|
|
buf->append(body.str, body.length);
|
2006-02-14 16:20:48 +01:00
|
|
|
|
|
|
|
DBUG_RETURN(0);
|
2005-12-05 11:45:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2006-02-15 19:08:44 +01:00
|
|
|
Executes the event (the underlying sp_head object);
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
evex_fill_row()
|
|
|
|
thd THD
|
|
|
|
mem_root If != NULL use it to compile the event on it
|
|
|
|
|
|
|
|
RETURNS
|
|
|
|
0 success
|
2006-02-15 22:32:25 +01:00
|
|
|
-99 No rights on this.dbname.str
|
2006-02-15 19:08:44 +01:00
|
|
|
-100 event in execution (parallel execution is impossible)
|
|
|
|
others retcodes of sp_head::execute_procedure()
|
2005-12-05 11:45:04 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
event_timed::execute(THD *thd, MEM_ROOT *mem_root)
|
|
|
|
{
|
2006-02-10 15:02:57 +01:00
|
|
|
Security_context *save_ctx;
|
2006-02-16 05:21:02 +01:00
|
|
|
/* this one is local and not needed after exec */
|
|
|
|
Security_context security_ctx;
|
2005-12-05 11:45:04 +01:00
|
|
|
int ret= 0;
|
2006-02-15 19:08:44 +01:00
|
|
|
|
2005-12-05 11:45:04 +01:00
|
|
|
DBUG_ENTER("event_timed::execute");
|
2006-02-10 15:02:57 +01:00
|
|
|
DBUG_PRINT("info", (" EVEX EXECUTING event %s.%s [EXPR:%d]",
|
|
|
|
dbname.str, name.str, (int) expression));
|
2005-12-05 11:45:04 +01:00
|
|
|
|
2005-12-20 13:21:02 +01:00
|
|
|
VOID(pthread_mutex_lock(&this->LOCK_running));
|
2006-02-15 19:08:44 +01:00
|
|
|
if (running)
|
2005-12-05 11:45:04 +01:00
|
|
|
{
|
2005-12-20 13:21:02 +01:00
|
|
|
VOID(pthread_mutex_unlock(&this->LOCK_running));
|
2005-12-05 11:45:04 +01:00
|
|
|
DBUG_RETURN(-100);
|
|
|
|
}
|
|
|
|
running= true;
|
2005-12-20 13:21:02 +01:00
|
|
|
VOID(pthread_mutex_unlock(&this->LOCK_running));
|
2005-12-05 11:45:04 +01:00
|
|
|
|
2006-02-10 15:02:57 +01:00
|
|
|
DBUG_PRINT("info", ("master_access=%d db_access=%d",
|
|
|
|
thd->security_ctx->master_access, thd->security_ctx->db_access));
|
2006-02-16 05:21:02 +01:00
|
|
|
change_security_context(thd, &security_ctx, &save_ctx);
|
2006-02-10 15:02:57 +01:00
|
|
|
DBUG_PRINT("info", ("master_access=%d db_access=%d",
|
|
|
|
thd->security_ctx->master_access, thd->security_ctx->db_access));
|
2006-02-16 05:21:02 +01:00
|
|
|
|
|
|
|
if (!sphead && (ret= compile(thd, mem_root)))
|
|
|
|
goto done;
|
|
|
|
/* Now we are sure we have valid this->sphead so we can copy the context */
|
|
|
|
sphead->m_security_ctx= security_ctx;
|
|
|
|
thd->db= dbname.str;
|
|
|
|
thd->db_length= dbname.length;
|
|
|
|
if (!check_access(thd, EVENT_ACL,dbname.str, 0, 0, 0,is_schema_db(dbname.str)))
|
2006-02-10 15:02:57 +01:00
|
|
|
{
|
|
|
|
List<Item> empty_item_list;
|
|
|
|
empty_item_list.empty();
|
|
|
|
ret= sphead->execute_procedure(thd, &empty_item_list);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DBUG_PRINT("error", ("%s@%s has no rights on %s", definer_user.str,
|
|
|
|
definer_host.str, dbname.str));
|
|
|
|
ret= -99;
|
|
|
|
}
|
|
|
|
restore_security_context(thd, save_ctx);
|
|
|
|
DBUG_PRINT("info", ("master_access=%d db_access=%d",
|
|
|
|
thd->security_ctx->master_access, thd->security_ctx->db_access));
|
2006-02-16 05:21:02 +01:00
|
|
|
thd->db= 0;
|
2005-12-05 11:45:04 +01:00
|
|
|
|
2005-12-20 13:21:02 +01:00
|
|
|
VOID(pthread_mutex_lock(&this->LOCK_running));
|
2005-12-05 11:45:04 +01:00
|
|
|
running= false;
|
2005-12-20 13:21:02 +01:00
|
|
|
VOID(pthread_mutex_unlock(&this->LOCK_running));
|
2005-12-05 11:45:04 +01:00
|
|
|
|
|
|
|
done:
|
2006-02-16 05:21:02 +01:00
|
|
|
/*
|
|
|
|
1. Don't cache sphead if allocated on another mem_root
|
|
|
|
2. Don't call security_ctx.destroy() because this will free our dbname.str
|
|
|
|
name.str and definer.str
|
|
|
|
*/
|
2005-12-08 00:17:05 +01:00
|
|
|
if (mem_root && sphead)
|
2005-12-05 11:45:04 +01:00
|
|
|
{
|
2005-12-08 00:17:05 +01:00
|
|
|
delete sphead;
|
|
|
|
sphead= 0;
|
2005-12-05 11:45:04 +01:00
|
|
|
}
|
2006-02-10 15:02:57 +01:00
|
|
|
DBUG_PRINT("info", (" EVEX EXECUTED event %s.%s [EXPR:%d]. RetCode=%d",
|
|
|
|
dbname.str, name.str, (int) expression, ret));
|
2005-12-05 11:45:04 +01:00
|
|
|
|
|
|
|
DBUG_RETURN(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-10 15:02:57 +01:00
|
|
|
/*
|
|
|
|
Switches the security context
|
|
|
|
Synopsis
|
|
|
|
event_timed::change_security_context()
|
|
|
|
thd - thread
|
|
|
|
backup - where to store the old context
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
0 - OK
|
|
|
|
1 - Error (generates error too)
|
|
|
|
*/
|
|
|
|
bool
|
2006-02-16 05:21:02 +01:00
|
|
|
event_timed::change_security_context(THD *thd, Security_context *s_ctx,
|
|
|
|
Security_context **backup)
|
2006-02-10 15:02:57 +01:00
|
|
|
{
|
|
|
|
DBUG_ENTER("event_timed::change_security_context");
|
|
|
|
DBUG_PRINT("info",("%s@%s@%s",definer_user.str,definer_host.str, dbname.str));
|
2006-02-15 23:43:11 +01:00
|
|
|
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
2006-02-16 05:21:02 +01:00
|
|
|
s_ctx->init();
|
2006-02-10 15:02:57 +01:00
|
|
|
*backup= 0;
|
2006-02-16 05:21:02 +01:00
|
|
|
if (acl_getroot_no_password(s_ctx, definer_user.str, definer_host.str,
|
|
|
|
definer_host.str, dbname.str))
|
2006-02-10 15:02:57 +01:00
|
|
|
{
|
|
|
|
my_error(ER_NO_SUCH_USER, MYF(0), definer_user.str, definer_host.str);
|
|
|
|
DBUG_RETURN(TRUE);
|
|
|
|
}
|
|
|
|
*backup= thd->security_ctx;
|
2006-02-16 05:21:02 +01:00
|
|
|
thd->security_ctx= s_ctx;
|
2006-02-15 23:43:11 +01:00
|
|
|
#endif
|
2006-02-10 15:02:57 +01:00
|
|
|
DBUG_RETURN(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Restores the security context
|
|
|
|
Synopsis
|
|
|
|
event_timed::restore_security_context()
|
|
|
|
thd - thread
|
|
|
|
backup - switch to this context
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
event_timed::restore_security_context(THD *thd, Security_context *backup)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("event_timed::change_security_context");
|
2006-02-15 23:43:11 +01:00
|
|
|
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
2006-02-10 15:02:57 +01:00
|
|
|
if (backup)
|
|
|
|
thd->security_ctx= backup;
|
2006-02-15 23:43:11 +01:00
|
|
|
#endif
|
2006-02-10 15:02:57 +01:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-12-08 15:34:11 +01:00
|
|
|
/*
|
2006-02-14 16:20:48 +01:00
|
|
|
Compiles an event before it's execution. Compiles the anonymous
|
|
|
|
sp_head object held by the event
|
2006-02-15 19:08:44 +01:00
|
|
|
|
|
|
|
SYNOPSIS
|
2006-02-14 16:20:48 +01:00
|
|
|
event_timed::compile()
|
2006-02-15 19:08:44 +01:00
|
|
|
thd thread context, used for memory allocation mostly
|
|
|
|
mem_root if != NULL then this memory root is used for allocs
|
|
|
|
instead of thd->mem_root
|
2005-12-08 15:34:11 +01:00
|
|
|
|
2006-02-15 19:08:44 +01:00
|
|
|
RETURN VALUE
|
2006-02-20 16:06:05 +01:00
|
|
|
0 success
|
|
|
|
EVEX_COMPILE_ERROR error during compilation
|
|
|
|
EVEX_MICROSECOND_UNSUP mysql.event was tampered
|
2005-12-08 15:34:11 +01:00
|
|
|
*/
|
|
|
|
|
2005-12-05 11:45:04 +01:00
|
|
|
int
|
|
|
|
event_timed::compile(THD *thd, MEM_ROOT *mem_root)
|
|
|
|
{
|
2005-12-08 20:37:54 +01:00
|
|
|
int ret= 0;
|
2005-12-05 11:45:04 +01:00
|
|
|
MEM_ROOT *tmp_mem_root= 0;
|
|
|
|
LEX *old_lex= thd->lex, lex;
|
|
|
|
char *old_db;
|
2006-02-16 00:43:11 +01:00
|
|
|
int old_db_length;
|
2005-12-05 11:45:04 +01:00
|
|
|
event_timed *ett;
|
|
|
|
sp_name *spn;
|
|
|
|
char *old_query;
|
|
|
|
uint old_query_len;
|
|
|
|
st_sp_chistics *p;
|
2006-02-20 23:52:22 +01:00
|
|
|
ulong old_sql_mode= thd->variables.sql_mode;
|
2006-02-14 16:20:48 +01:00
|
|
|
char create_buf[2048];
|
|
|
|
String show_create(create_buf, sizeof(create_buf), system_charset_info);
|
|
|
|
CHARSET_INFO *old_character_set_client,
|
|
|
|
*old_collation_connection,
|
2005-12-08 20:37:54 +01:00
|
|
|
*old_character_set_results;
|
2006-02-15 19:08:44 +01:00
|
|
|
|
2006-02-20 16:06:05 +01:00
|
|
|
DBUG_ENTER("event_timed::compile");
|
|
|
|
|
2006-02-14 16:20:48 +01:00
|
|
|
show_create.length(0);
|
2006-02-20 16:06:05 +01:00
|
|
|
|
|
|
|
switch (get_create_event(thd, &show_create)) {
|
|
|
|
case EVEX_MICROSECOND_UNSUP:
|
|
|
|
sql_print_error("Scheduler");
|
|
|
|
DBUG_RETURN(EVEX_MICROSECOND_UNSUP);
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DBUG_ASSERT(0);
|
|
|
|
}
|
|
|
|
|
2005-12-08 20:37:54 +01:00
|
|
|
old_character_set_client= thd->variables.character_set_client;
|
|
|
|
old_character_set_results= thd->variables.character_set_results;
|
|
|
|
old_collation_connection= thd->variables.collation_connection;
|
2006-02-15 19:08:44 +01:00
|
|
|
|
|
|
|
thd->variables.character_set_client=
|
2005-12-08 20:37:54 +01:00
|
|
|
thd->variables.character_set_results=
|
|
|
|
thd->variables.collation_connection=
|
|
|
|
get_charset_by_csname("utf8", MY_CS_PRIMARY, MYF(MY_WME));
|
|
|
|
|
|
|
|
thd->update_charset();
|
2006-02-15 19:08:44 +01:00
|
|
|
|
2006-02-20 23:52:22 +01:00
|
|
|
DBUG_PRINT("info",("old_sql_mode=%d new_sql_mode=%d",old_sql_mode, sql_mode));
|
|
|
|
thd->variables.sql_mode= this->sql_mode;
|
2006-02-15 19:08:44 +01:00
|
|
|
/* Change the memory root for the execution time */
|
2005-12-05 11:45:04 +01:00
|
|
|
if (mem_root)
|
|
|
|
{
|
|
|
|
tmp_mem_root= thd->mem_root;
|
|
|
|
thd->mem_root= mem_root;
|
|
|
|
}
|
|
|
|
old_query_len= thd->query_length;
|
|
|
|
old_query= thd->query;
|
|
|
|
old_db= thd->db;
|
2006-02-16 00:43:11 +01:00
|
|
|
old_db_length= thd->db_length;
|
2005-12-08 00:17:05 +01:00
|
|
|
thd->db= dbname.str;
|
2006-02-16 00:43:11 +01:00
|
|
|
thd->db_length= dbname.length;
|
2006-02-14 16:20:48 +01:00
|
|
|
|
|
|
|
thd->query= show_create.c_ptr();
|
|
|
|
thd->query_length= show_create.length();
|
2005-12-05 11:45:04 +01:00
|
|
|
DBUG_PRINT("event_timed::compile", ("query:%s",thd->query));
|
|
|
|
|
|
|
|
thd->lex= &lex;
|
|
|
|
lex_start(thd, (uchar*)thd->query, thd->query_length);
|
|
|
|
lex.et_compile_phase= TRUE;
|
|
|
|
if (yyparse((void *)thd) || thd->is_fatal_error)
|
|
|
|
{
|
2006-01-20 22:24:58 +01:00
|
|
|
DBUG_PRINT("error", ("error during compile or thd->is_fatal_error=%d",
|
|
|
|
thd->is_fatal_error));
|
2006-02-15 19:08:44 +01:00
|
|
|
/*
|
|
|
|
Free lex associated resources
|
|
|
|
QQ: Do we really need all this stuff here?
|
|
|
|
*/
|
2006-01-20 22:24:58 +01:00
|
|
|
sql_print_error("error during compile of %s.%s or thd->is_fatal_error=%d",
|
|
|
|
dbname.str, name.str, thd->is_fatal_error);
|
2005-12-05 11:45:04 +01:00
|
|
|
if (lex.sphead)
|
|
|
|
{
|
|
|
|
if (&lex != thd->lex)
|
|
|
|
thd->lex->sphead->restore_lex(thd);
|
|
|
|
delete lex.sphead;
|
|
|
|
lex.sphead= 0;
|
|
|
|
}
|
2005-12-08 20:37:54 +01:00
|
|
|
ret= EVEX_COMPILE_ERROR;
|
|
|
|
goto done;
|
2005-12-05 11:45:04 +01:00
|
|
|
}
|
2006-01-20 22:24:58 +01:00
|
|
|
DBUG_PRINT("note", ("success compiling %s.%s", dbname.str, name.str));
|
2006-02-15 19:08:44 +01:00
|
|
|
|
2005-12-15 14:12:28 +01:00
|
|
|
sphead= lex.et->sphead;
|
2005-12-08 00:17:05 +01:00
|
|
|
sphead->m_db= dbname;
|
2006-02-28 12:08:13 +01:00
|
|
|
|
2005-12-08 00:17:05 +01:00
|
|
|
sphead->set_definer(definer.str, definer.length);
|
2006-02-20 23:52:22 +01:00
|
|
|
sphead->set_info(0, 0, &lex.sp_chistics, sql_mode);
|
2005-12-08 00:17:05 +01:00
|
|
|
sphead->optimize();
|
2005-12-08 20:37:54 +01:00
|
|
|
ret= 0;
|
|
|
|
done:
|
2005-12-15 14:12:28 +01:00
|
|
|
lex.et->free_sphead_on_delete= false;
|
2005-12-13 19:16:00 +01:00
|
|
|
delete lex.et;
|
2005-12-05 11:45:04 +01:00
|
|
|
lex_end(&lex);
|
2006-01-20 22:24:58 +01:00
|
|
|
DBUG_PRINT("note", ("return old data on its place. set back NAMES"));
|
|
|
|
|
2005-12-05 11:45:04 +01:00
|
|
|
thd->lex= old_lex;
|
|
|
|
thd->query= old_query;
|
|
|
|
thd->query_length= old_query_len;
|
|
|
|
thd->db= old_db;
|
2005-12-08 20:37:54 +01:00
|
|
|
|
2006-02-20 23:52:22 +01:00
|
|
|
thd->variables.sql_mode= old_sql_mode;
|
2005-12-08 20:37:54 +01:00
|
|
|
thd->variables.character_set_client= old_character_set_client;
|
|
|
|
thd->variables.character_set_results= old_character_set_results;
|
|
|
|
thd->variables.collation_connection= old_collation_connection;
|
|
|
|
thd->update_charset();
|
|
|
|
|
2006-02-15 19:08:44 +01:00
|
|
|
/* Change the memory root for the execution time. */
|
2005-12-05 11:45:04 +01:00
|
|
|
if (mem_root)
|
|
|
|
thd->mem_root= tmp_mem_root;
|
|
|
|
|
2005-12-08 20:37:54 +01:00
|
|
|
DBUG_RETURN(ret);
|
2005-12-05 11:45:04 +01:00
|
|
|
}
|
|
|
|
|
2006-02-16 00:43:11 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
Checks whether this thread can lock the object for modification ->
|
|
|
|
preventing being spawned for execution, and locks if possible.
|
|
|
|
use ::can_spawn_now() only for basic checking because a race
|
|
|
|
condition may occur between the check and eventual modification (deletion)
|
|
|
|
of the object.
|
|
|
|
|
|
|
|
Returns
|
|
|
|
true - locked
|
|
|
|
false - cannot lock
|
|
|
|
*/
|
|
|
|
|
|
|
|
my_bool
|
|
|
|
event_timed::can_spawn_now_n_lock(THD *thd)
|
|
|
|
{
|
|
|
|
my_bool ret= FALSE;
|
|
|
|
VOID(pthread_mutex_lock(&this->LOCK_running));
|
|
|
|
if (!in_spawned_thread)
|
|
|
|
{
|
|
|
|
in_spawned_thread= TRUE;
|
|
|
|
ret= TRUE;
|
|
|
|
locked_by_thread_id= thd->thread_id;
|
|
|
|
}
|
|
|
|
VOID(pthread_mutex_unlock(&this->LOCK_running));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extern pthread_attr_t connection_attrib;
|
|
|
|
|
|
|
|
/*
|
|
|
|
Checks whether is possible and forks a thread. Passes self as argument.
|
2006-02-28 14:43:49 +01:00
|
|
|
|
2006-02-16 00:43:11 +01:00
|
|
|
Returns
|
|
|
|
EVENT_EXEC_STARTED - OK
|
|
|
|
EVENT_EXEC_ALREADY_EXEC - Thread not forked, already working
|
|
|
|
EVENT_EXEC_CANT_FORK - Unable to spawn thread (error)
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
event_timed::spawn_now(void * (*thread_func)(void*))
|
|
|
|
{
|
|
|
|
int ret= EVENT_EXEC_STARTED;
|
|
|
|
static uint exec_num= 0;
|
|
|
|
DBUG_ENTER("event_timed::spawn_now");
|
|
|
|
DBUG_PRINT("info", ("[%s.%s]", dbname.str, name.str));
|
|
|
|
|
|
|
|
VOID(pthread_mutex_lock(&this->LOCK_running));
|
|
|
|
if (!in_spawned_thread)
|
|
|
|
{
|
|
|
|
pthread_t th;
|
|
|
|
in_spawned_thread= true;
|
|
|
|
if (pthread_create(&th, &connection_attrib, thread_func, (void*)this))
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("problem while spawning thread"));
|
|
|
|
ret= EVENT_EXEC_CANT_FORK;
|
|
|
|
in_spawned_thread= false;
|
|
|
|
}
|
|
|
|
#ifndef DBUG_OFF
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sql_print_information("SCHEDULER: Started thread %d", ++exec_num);
|
|
|
|
DBUG_PRINT("info", ("thread spawned"));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("already in spawned thread. skipping"));
|
|
|
|
ret= EVENT_EXEC_ALREADY_EXEC;
|
|
|
|
}
|
|
|
|
VOID(pthread_mutex_unlock(&this->LOCK_running));
|
|
|
|
|
|
|
|
DBUG_RETURN(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
event_timed::spawn_thread_finish(THD *thd)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("event_timed::spawn_thread_finish");
|
|
|
|
VOID(pthread_mutex_lock(&this->LOCK_running));
|
|
|
|
in_spawned_thread= false;
|
|
|
|
if ((flags & EVENT_EXEC_NO_MORE) || status == MYSQL_EVENT_DISABLED)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("%s exec no more. to drop=%d", name.str, dropped));
|
|
|
|
if (dropped)
|
|
|
|
drop(thd);
|
|
|
|
VOID(pthread_mutex_unlock(&this->LOCK_running));
|
|
|
|
delete this;
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
VOID(pthread_mutex_unlock(&this->LOCK_running));
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Unlocks the object after it has been locked with ::can_spawn_now_n_lock()
|
|
|
|
|
|
|
|
Returns
|
|
|
|
0 - ok
|
|
|
|
1 - not locked by this thread
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
event_timed::spawn_unlock(THD *thd)
|
|
|
|
{
|
|
|
|
int ret= 0;
|
|
|
|
VOID(pthread_mutex_lock(&this->LOCK_running));
|
|
|
|
if (!in_spawned_thread)
|
|
|
|
{
|
|
|
|
if (locked_by_thread_id == thd->thread_id)
|
|
|
|
{
|
|
|
|
in_spawned_thread= FALSE;
|
|
|
|
locked_by_thread_id= 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sql_print_error("A thread tries to unlock when he hasn't locked. "
|
|
|
|
"thread_id=%ld locked by %ld",
|
|
|
|
thd->thread_id, locked_by_thread_id);
|
|
|
|
DBUG_ASSERT(0);
|
|
|
|
ret= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
VOID(pthread_mutex_unlock(&this->LOCK_running));
|
2006-02-28 14:43:49 +01:00
|
|
|
return ret;
|
2006-02-16 00:43:11 +01:00
|
|
|
}
|