1 #ifndef _EVENT_DATA_OBJECTS_H_
2 #define _EVENT_DATA_OBJECTS_H_
3 /* Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
4 
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License, version 2.0,
7    as published by the Free Software Foundation.
8 
9    This program is also distributed with certain software (including
10    but not limited to OpenSSL) that is licensed under separate terms,
11    as designated in a particular file or component or in included license
12    documentation.  The authors of MySQL hereby grant you an additional
13    permission to link the program and your derivative works with the
14    separately licensed software that they have included with MySQL.
15 
16    This program is distributed in the hope that it will be useful,
17    but WITHOUT ANY WARRANTY; without even the implied warranty of
18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19    GNU General Public License, version 2.0, for more details.
20 
21    You should have received a copy of the GNU General Public License
22    along with this program; if not, write to the Free Software Foundation,
23    51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
24 
25 /**
26   @addtogroup Event_Scheduler
27   @{
28 
29   @file event_data_objects.h
30 */
31 
32 #include "event_parse_data.h"
33 #include "thr_lock.h"                           /* thr_lock_type */
34 
35 class Field;
36 class THD;
37 class Time_zone;
38 struct TABLE;
39 
40 class Event_queue_element_for_exec
41 {
42 public:
Event_queue_element_for_exec()43   Event_queue_element_for_exec(){};
44   ~Event_queue_element_for_exec();
45 
46   bool
47   init(LEX_STRING dbname, LEX_STRING name);
48 
49   LEX_STRING dbname;
50   LEX_STRING name;
51   bool dropped;
52   THD *thd;
53 
54 private:
55   /* Prevent use of these */
56   Event_queue_element_for_exec(const Event_queue_element_for_exec &);
57   void operator=(Event_queue_element_for_exec &);
58 };
59 
60 
61 class Event_basic
62 {
63 protected:
64   MEM_ROOT mem_root;
65 
66 public:
67 
68   LEX_STRING dbname;
69   LEX_STRING name;
70   LEX_STRING definer;// combination of user and host
71 
72   Time_zone *time_zone;
73 
74   Event_basic();
75   virtual ~Event_basic();
76 
77   virtual bool
78   load_from_row(THD *thd, TABLE *table) = 0;
79 
80 protected:
81   bool
82   load_string_fields(Field **fields, ...);
83 
84   bool
85   load_time_zone(THD *thd, const LEX_STRING tz_name);
86 };
87 
88 
89 
90 class Event_queue_element : public Event_basic
91 {
92 public:
93   int on_completion;
94   int status;
95   longlong originator;
96 
97   my_time_t last_executed;
98   my_time_t execute_at;
99   my_time_t starts;
100   my_time_t ends;
101   my_bool starts_null;
102   my_bool ends_null;
103   my_bool execute_at_null;
104 
105   longlong expression;
106   interval_type interval;
107 
108   bool dropped;
109 
110   uint execution_count;
111 
112   Event_queue_element();
113   virtual ~Event_queue_element();
114 
115   virtual bool
116   load_from_row(THD *thd, TABLE *table);
117 
118   bool
119   compute_next_execution_time();
120 
121   void
122   mark_last_executed(THD *thd);
123 };
124 
125 
126 class Event_timed : public Event_queue_element
127 {
128   Event_timed(const Event_timed &);	/* Prevent use of these */
129   void operator=(Event_timed &);
130 
131 public:
132   LEX_STRING body;
133 
134   LEX_STRING definer_user;
135   LEX_STRING definer_host;
136 
137   LEX_STRING comment;
138 
139   ulonglong created;
140   ulonglong modified;
141 
142   sql_mode_t sql_mode;
143 
144   class Stored_program_creation_ctx *creation_ctx;
145   LEX_STRING body_utf8;
146 
147   Event_timed();
148   virtual ~Event_timed();
149 
150   void
151   init();
152 
153   virtual bool
154   load_from_row(THD *thd, TABLE *table);
155 
156   int
157   get_create_event(THD *thd, String *buf);
158 };
159 
160 
161 class Event_job_data : public Event_basic
162 {
163 public:
164   LEX_STRING body;
165   LEX_STRING definer_user;
166   LEX_STRING definer_host;
167 
168   sql_mode_t sql_mode;
169 
170   class Stored_program_creation_ctx *creation_ctx;
171 
172   Event_job_data();
173 
174   virtual bool
175   load_from_row(THD *thd, TABLE *table);
176 
177   bool
178   execute(THD *thd, bool drop);
179 private:
180   bool
181   construct_sp_sql(THD *thd, String *sp_sql);
182   bool
183   construct_drop_event_sql(THD *thd, String *sp_sql);
184 
185   Event_job_data(const Event_job_data &);       /* Prevent use of these */
186   void operator=(Event_job_data &);
187 };
188 
189 
190 /* Compares only the schema part of the identifier */
191 bool
192 event_basic_db_equal(LEX_STRING db, Event_basic *et);
193 
194 /* Compares the whole identifier*/
195 bool
196 event_basic_identifier_equal(LEX_STRING db, LEX_STRING name, Event_basic *b);
197 
198 /**
199   @} (End of group Event_Scheduler)
200 */
201 
202 #endif /* _EVENT_DATA_OBJECTS_H_ */
203