1 #ifndef _EVENT_DATA_OBJECTS_H_
2 #define _EVENT_DATA_OBJECTS_H_
3 /* Copyright (c) 2004, 2021, Oracle and/or its affiliates.
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 "my_global.h"
33 #include "m_string.h"                   // LEX_CSTRING
34 #include "my_alloc.h"                   // MEM_ROOT
35 #include "my_time.h"                    // my_time_t
36 #include "mysql/mysql_lex_string.h"     // LEX_STRING
37 
38 #include "my_thread.h"                  // Needed for psi.h
39 #include <pfs_stage_provider.h>
40 #include <mysql/psi/mysql_stage.h>
41 
42 #include <pfs_statement_provider.h>
43 #include <mysql/psi/mysql_statement.h>
44 
45 class Field;
46 class String;
47 class THD;
48 class Time_zone;
49 struct TABLE;
50 typedef ulonglong sql_mode_t;
51 typedef struct st_mysql_lex_string LEX_STRING;
52 
53 void init_scheduler_psi_keys(void);
54 
55 class Event_queue_element_for_exec
56 {
57 public:
Event_queue_element_for_exec()58   Event_queue_element_for_exec(){};
59   ~Event_queue_element_for_exec();
60 
61   bool
62   init(LEX_STRING dbname, LEX_STRING name);
63 
64   LEX_STRING dbname;
65   LEX_STRING name;
66   bool dropped;
67   THD *thd;
68 
69   void claim_memory_ownership();
70 
71 private:
72   /* Prevent use of these */
73   Event_queue_element_for_exec(const Event_queue_element_for_exec &);
74   void operator=(Event_queue_element_for_exec &);
75 #ifdef HAVE_PSI_INTERFACE
76 public:
get_psi_info()77   PSI_statement_info* get_psi_info()
78   {
79     return & psi_info;
80   }
81 
82   static PSI_statement_info psi_info;
83 #endif
84 };
85 
86 
87 class Event_basic
88 {
89 protected:
90   MEM_ROOT mem_root;
91 
92 public:
93 
94   LEX_STRING dbname;
95   LEX_STRING name;
96   LEX_STRING definer;// combination of user and host
97 
98   Time_zone *time_zone;
99 
100   Event_basic();
101   virtual ~Event_basic();
102 
103   virtual bool
104   load_from_row(THD *thd, TABLE *table) = 0;
105 
106 protected:
107   bool
108   load_string_fields(Field **fields, ...);
109 
110   bool
111   load_time_zone(THD *thd, const LEX_STRING tz_name);
112 };
113 
114 
115 
116 class Event_queue_element : public Event_basic
117 {
118 public:
119   int on_completion;
120   int status;
121   longlong originator;
122 
123   my_time_t last_executed;
124   my_time_t execute_at;
125   my_time_t starts;
126   my_time_t ends;
127   my_bool starts_null;
128   my_bool ends_null;
129   my_bool execute_at_null;
130 
131   longlong expression;
132   interval_type interval;
133 
134   bool dropped;
135 
136   uint execution_count;
137 
138   Event_queue_element();
139   virtual ~Event_queue_element();
140 
141   virtual bool
142   load_from_row(THD *thd, TABLE *table);
143 
144   bool
145   compute_next_execution_time();
146 
147   void
148   mark_last_executed(THD *thd);
149 };
150 
151 
152 class Event_timed : public Event_queue_element
153 {
154   Event_timed(const Event_timed &);	/* Prevent use of these */
155   void operator=(Event_timed &);
156 
157 public:
158   LEX_STRING body;
159 
160   LEX_CSTRING definer_user;
161   LEX_CSTRING definer_host;
162 
163   LEX_STRING comment;
164 
165   ulonglong created;
166   ulonglong modified;
167 
168   sql_mode_t sql_mode;
169 
170   class Stored_program_creation_ctx *creation_ctx;
171   LEX_STRING body_utf8;
172 
173   Event_timed();
174   virtual ~Event_timed();
175 
176   void
177   init();
178 
179   virtual bool
180   load_from_row(THD *thd, TABLE *table);
181 
182   int
183   get_create_event(THD *thd, String *buf);
184 };
185 
186 
187 class Event_job_data : public Event_basic
188 {
189 public:
190   LEX_STRING body;
191   LEX_CSTRING definer_user;
192   LEX_CSTRING definer_host;
193 
194   sql_mode_t sql_mode;
195 
196   class Stored_program_creation_ctx *creation_ctx;
197 
198   Event_job_data();
199 
200   virtual bool
201   load_from_row(THD *thd, TABLE *table);
202 
203   bool
204   execute(THD *thd, bool drop);
205 private:
206   bool
207   construct_sp_sql(THD *thd, String *sp_sql);
208   Event_job_data(const Event_job_data &);       /* Prevent use of these */
209   void operator=(Event_job_data &);
210 };
211 
212 /**
213   Build an SQL drop event string.
214 
215   @param[in]     thd         Thread handle
216   @param[in,out] sp_sql      Pointer to String object where the SQL query will
217                              be stored
218   @param[in]     db_name     The schema name
219   @param[in]     event_name  The event name
220 
221   @retval        false       The drop event SQL query is built
222   @retval        true        Otherwise
223 */
224 bool construct_drop_event_sql(THD *thd, String *sp_sql,
225                               const LEX_STRING &db_name,
226                               const LEX_STRING &event_name);
227 
228 
229 /* Compares only the schema part of the identifier */
230 bool
231 event_basic_db_equal(LEX_STRING db, Event_basic *et);
232 
233 /* Compares the whole identifier*/
234 bool
235 event_basic_identifier_equal(LEX_STRING db, LEX_STRING name, Event_basic *b);
236 
237 /**
238   @} (End of group Event_Scheduler)
239 */
240 
241 #endif /* _EVENT_DATA_OBJECTS_H_ */
242