MySQL 8.0.40
Source Code Documentation
trigger_impl.h
Go to the documentation of this file.
1/* Copyright (c) 2016, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef DD__TRIGGER_IMPL_INCLUDED
25#define DD__TRIGGER_IMPL_INCLUDED
26
27#include "my_config.h"
28
29#include "my_inttypes.h"
30#include "sql/dd/string_type.h"
31
32#ifdef HAVE_SYS_TIME_H
33#include <sys/time.h>
34#endif
35#include <sys/types.h>
36#include <new>
37
39#include "sql/dd/impl/types/entity_object_impl.h" // dd::Entity_object_impl
40#include "sql/dd/impl/types/table_impl.h" // dd::Table_impl
42#include "sql/dd/object_id.h"
43#include "sql/dd/types/trigger.h" // dd::Trigger
44
45namespace dd {
46
47///////////////////////////////////////////////////////////////////////////
48
49class Object_table;
50class Open_dictionary_tables_ctx;
51class Table;
52class Weak_object;
53
54class Trigger_impl : virtual public Entity_object_impl, virtual public Trigger {
55 public:
57
59
60 Trigger_impl(const Trigger_impl &src, Table_impl *parent);
61
62 public:
63 const Object_table &object_table() const override;
64
65 bool validate() const override;
66
67 bool restore_attributes(const Raw_record &r) override;
68
69 bool store_attributes(Raw_record *r) override;
70
71 void debug_print(String_type &outb) const override;
72
75 }
76
78
79 public:
81
82 /////////////////////////////////////////////////////////////////////////
83 // Table.
84 /////////////////////////////////////////////////////////////////////////
85
86 virtual const Table &table() const;
87
88 virtual Table &table();
89
90 /* non-virtual */ void set_table(Table_impl *parent) { m_table = parent; }
91
92 /* non-virtual */ const Table_impl &table_impl() const { return *m_table; }
93
94 /* non-virtual */ Table_impl &table_impl() { return *m_table; }
95
96 /////////////////////////////////////////////////////////////////////////
97 // schema.
98 /////////////////////////////////////////////////////////////////////////
99
100 Object_id schema_id() const override {
101 return (m_table != nullptr ? m_table->schema_id() : INVALID_OBJECT_ID);
102 }
103
104 /////////////////////////////////////////////////////////////////////////
105 // event type
106 /////////////////////////////////////////////////////////////////////////
107
108 enum_event_type event_type() const override { return m_event_type; }
109
112 }
113
114 /////////////////////////////////////////////////////////////////////////
115 // table.
116 /////////////////////////////////////////////////////////////////////////
117
118 Object_id table_id() const override { return m_table->id(); }
119
120 /////////////////////////////////////////////////////////////////////////
121 // action timing
122 /////////////////////////////////////////////////////////////////////////
123
125
128 }
129
130 /////////////////////////////////////////////////////////////////////////
131 // action_order.
132 /////////////////////////////////////////////////////////////////////////
133
134 uint action_order() const override { return m_action_order; }
135
138 }
139
140 /////////////////////////////////////////////////////////////////////////
141 // action_statement/utf8.
142 /////////////////////////////////////////////////////////////////////////
143
144 const String_type &action_statement() const override {
145 return m_action_statement;
146 }
147
150 }
151
152 const String_type &action_statement_utf8() const override {
154 }
155
157 const String_type &action_statement_utf8) override {
159 }
160
161 /////////////////////////////////////////////////////////////////////////
162 // created.
163 /////////////////////////////////////////////////////////////////////////
164
165 my_timeval created() const override { return m_created; }
166
168
169 /////////////////////////////////////////////////////////////////////////
170 // last altered.
171 /////////////////////////////////////////////////////////////////////////
172
173 my_timeval last_altered() const override { return m_last_altered; }
174
177 }
178
179 /////////////////////////////////////////////////////////////////////////
180 // sql_mode
181 /////////////////////////////////////////////////////////////////////////
182
183 ulonglong sql_mode() const override { return m_sql_mode; }
184
186
187 /////////////////////////////////////////////////////////////////////////
188 // definer.
189 /////////////////////////////////////////////////////////////////////////
190
191 const String_type &definer_user() const override { return m_definer_user; }
192
193 const String_type &definer_host() const override { return m_definer_host; }
194
195 void set_definer(const String_type &username,
196 const String_type &hostname) override {
197 m_definer_user = username;
198 m_definer_host = hostname;
199 }
200
201 /////////////////////////////////////////////////////////////////////////
202 // collation.
203 /////////////////////////////////////////////////////////////////////////
204
207 }
208
211 }
212
215 }
216
219 }
220
223 }
224
227 }
228
229 // Fix "inherits ... via dominance" warnings
231
232 const Entity_object_impl *impl() const override {
234 }
235
236 Object_id id() const override { return Entity_object_impl::id(); }
237
238 bool is_persistent() const override {
240 }
241
242 const String_type &name() const override {
244 }
245
246 void set_name(const String_type &name) override {
248 }
249
250 public:
252 return new (std::nothrow) Trigger_impl(table);
253 }
254
256 return new (std::nothrow) Trigger_impl(other, table);
257 }
258
259 private:
262
263 /*
264 We use m_ordinal_position to help implement
265 add_trigger_following and add_trigger_preceding.
266 This is required mainly because we maintain a single
267 collection to maintain all triggers.
268 */
271
275
280
281 // References to tightly-coupled objects.
282
284
285 // References to loosely-coupled objects.
286
290};
291
292///////////////////////////////////////////////////////////////////////////
293
294/**
295 Used to sort Triggers of the same table by action timing, event type and
296 action order.
297*/
298
300 bool operator()(const dd::Trigger *t1, const dd::Trigger *t2) const {
301 return ((t1->action_timing() < t2->action_timing()) ||
302 (t1->action_timing() == t2->action_timing() &&
303 t1->event_type() < t2->event_type()) ||
304 (t1->action_timing() == t2->action_timing() &&
305 t1->event_type() == t2->event_type() &&
306 t1->action_order() < t2->action_order()));
307 }
308};
309
310///////////////////////////////////////////////////////////////////////////
311} // namespace dd
312
313#endif // DD__TRIGGER_IMPL_INCLUDED
Definition: entity_object_impl.h:44
void set_name(const String_type &name) override
Definition: entity_object_impl.h:62
Object_id id() const override
The unique dictionary object id.
Definition: entity_object_impl.h:49
const String_type & name() const override
Definition: entity_object_impl.h:60
Entity_object_impl * impl() override
Definition: entity_object_impl.h:68
bool is_persistent() const override
Is dictionary object persistent in dictionary tables ?
Definition: entity_object_impl.h:57
This class represents all data dictionary table like mysql.tables, mysql.columns and more.
Definition: object_table.h:72
Auxiliary class for opening dictionary tables.
Definition: transaction_impl.h:76
Definition: raw_record.h:46
Definition: table_impl.h:68
Object_id schema_id() const override
Definition: table_impl.h:431
Object_id id() const override
The unique dictionary object id.
Definition: table_impl.h:421
Definition: table.h:47
Definition: trigger_impl.h:54
Object_id schema_collation_id() const override
Definition: trigger_impl.h:221
static Trigger_impl * clone(const Trigger_impl &other, Table_impl *table)
Definition: trigger_impl.h:255
uint ordinal_position() const
Definition: trigger_impl.h:77
String_type m_action_statement
Definition: trigger_impl.h:277
bool store_attributes(Raw_record *r) override
Definition: trigger_impl.cc:151
enum_event_type event_type() const override
Definition: trigger_impl.h:108
ulonglong m_sql_mode
Definition: trigger_impl.h:272
void set_table(Table_impl *parent)
Definition: trigger_impl.h:90
my_timeval last_altered() const override
Definition: trigger_impl.h:173
void set_definer(const String_type &username, const String_type &hostname) override
Definition: trigger_impl.h:195
void set_last_altered(my_timeval last_altered) override
Definition: trigger_impl.h:175
String_type m_definer_host
Definition: trigger_impl.h:279
void set_sql_mode(ulonglong sql_mode) override
Definition: trigger_impl.h:185
String_type m_definer_user
Definition: trigger_impl.h:278
const String_type & action_statement_utf8() const override
Definition: trigger_impl.h:152
Object_id client_collation_id() const override
Definition: trigger_impl.h:205
Object_id schema_id() const override
Definition: trigger_impl.h:100
String_type m_action_statement_utf8
Definition: trigger_impl.h:276
void set_connection_collation_id(Object_id connection_collation_id) override
Definition: trigger_impl.h:217
void set_client_collation_id(Object_id client_collation_id) override
Definition: trigger_impl.h:209
const Entity_object_impl * impl() const override
Definition: trigger_impl.h:232
const String_type & definer_host() const override
Definition: trigger_impl.h:193
bool restore_attributes(const Raw_record &r) override
Definition: trigger_impl.cc:95
static Trigger_impl * restore_item(Table_impl *table)
Definition: trigger_impl.h:251
void set_action_statement(const String_type &action_statement) override
Definition: trigger_impl.h:148
const String_type & action_statement() const override
Definition: trigger_impl.h:144
static void register_tables(Open_dictionary_tables_ctx *otx)
Definition: trigger_impl.cc:230
const Object_table & object_table() const override
Definition: trigger_impl.cc:224
void set_event_type(enum_event_type event_type) override
Definition: trigger_impl.h:110
uint m_ordinal_position
Definition: trigger_impl.h:269
bool is_persistent() const override
Is dictionary object persistent in dictionary tables ?
Definition: trigger_impl.h:238
Object_id id() const override
The unique dictionary object id.
Definition: trigger_impl.h:236
void set_ordinal_position(uint ordinal_position)
Definition: trigger_impl.h:73
my_timeval m_last_altered
Definition: trigger_impl.h:274
Object_id m_client_collation_id
Definition: trigger_impl.h:287
const Table_impl & table_impl() const
Definition: trigger_impl.h:92
void set_name(const String_type &name) override
Definition: trigger_impl.h:246
Trigger_impl()
Definition: trigger_impl.cc:54
void set_action_statement_utf8(const String_type &action_statement_utf8) override
Definition: trigger_impl.h:156
Entity_object_impl * impl() override
Definition: trigger_impl.h:230
void set_created(my_timeval created) override
Definition: trigger_impl.h:167
my_timeval created() const override
Definition: trigger_impl.h:165
ulonglong sql_mode() const override
Definition: trigger_impl.h:183
enum_event_type m_event_type
Definition: trigger_impl.h:260
enum_action_timing m_action_timing
Definition: trigger_impl.h:261
void debug_print(String_type &outb) const override
Definition: trigger_impl.cc:177
virtual const Table & table() const
Definition: trigger_impl.cc:77
Table_impl & table_impl()
Definition: trigger_impl.h:94
Object_id m_connection_collation_id
Definition: trigger_impl.h:288
void set_action_timing(enum_action_timing action_timing) override
Definition: trigger_impl.h:126
bool validate() const override
Definition: trigger_impl.cc:83
const String_type & definer_user() const override
Definition: trigger_impl.h:191
void set_action_order(uint action_order) override
Definition: trigger_impl.h:136
uint action_order() const override
Definition: trigger_impl.h:134
uint m_action_order
Definition: trigger_impl.h:270
Object_id m_schema_collation_id
Definition: trigger_impl.h:289
Table_impl * m_table
Definition: trigger_impl.h:283
const String_type & name() const override
Definition: trigger_impl.h:242
Object_id connection_collation_id() const override
Definition: trigger_impl.h:213
void set_schema_collation_id(Object_id schema_collation_id) override
Definition: trigger_impl.h:225
Object_id table_id() const override
Definition: trigger_impl.h:118
enum_action_timing action_timing() const override
Definition: trigger_impl.h:124
my_timeval m_created
Definition: trigger_impl.h:273
Class representing a Trigger in DD framework.
Definition: trigger.h:54
virtual uint action_order() const =0
virtual enum_action_timing action_timing() const =0
enum_action_timing
Definition: trigger.h:62
virtual enum_event_type event_type() const =0
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:43
unsigned long long Object_id
Definition: object_id.h:31
const Object_id INVALID_OBJECT_ID
The default object ID which represents that the DD object is new and not persistent in dictionary tab...
Definition: object_id.h:37
Char_string_template< String_type_allocator > String_type
Definition: string_type.h:51
enum_event_type
Enum values for the NESTING_EVENT_TYPE columns.
Definition: pfs_column_types.h:270
const mysql_service_registry_t * r
Definition: pfs_example_plugin_employee.cc:86
Used to sort Triggers of the same table by action timing, event type and action order.
Definition: trigger_impl.h:299
bool operator()(const dd::Trigger *t1, const dd::Trigger *t2) const
Definition: trigger_impl.h:300
Replacement of system's struct timeval to ensure we can carry 64 bit values even on a platform which ...
Definition: my_time_t.h:45
Include file for Sun RPC to compile out of the box.
unsigned int uint
Definition: uca9-dump.cc:75