-
Notifications
You must be signed in to change notification settings - Fork 4k
/
Copy pathsql_signal.h
185 lines (155 loc) · 5.69 KB
/
sql_signal.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/* Copyright (c) 2008, 2025, Oracle and/or its affiliates.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is designed to work with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have either included with
the program or referenced in the documentation.
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, version 2.0, 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#ifndef SQL_SIGNAL_H
#define SQL_SIGNAL_H
#include <string.h>
#include "my_sqlcommand.h"
#include "sql/sql_cmd.h" // Sql_cmd
#include "sql/sql_error.h" // Sql_condition
class Item;
class THD;
class sp_condition_value;
/**
This enumeration list all the condition item names of a condition in the
SQL condition area.
*/
enum enum_condition_item_name {
/*
Conditions that can be set by the user (SIGNAL/RESIGNAL),
and by the server implementation.
*/
CIN_CLASS_ORIGIN = 0,
CIN_FIRST_PROPERTY = CIN_CLASS_ORIGIN,
CIN_SUBCLASS_ORIGIN = 1,
CIN_CONSTRAINT_CATALOG = 2,
CIN_CONSTRAINT_SCHEMA = 3,
CIN_CONSTRAINT_NAME = 4,
CIN_CATALOG_NAME = 5,
CIN_SCHEMA_NAME = 6,
CIN_TABLE_NAME = 7,
CIN_COLUMN_NAME = 8,
CIN_CURSOR_NAME = 9,
CIN_MESSAGE_TEXT = 10,
CIN_MYSQL_ERRNO = 11,
CIN_LAST_PROPERTY = CIN_MYSQL_ERRNO
};
/**
Set_signal_information is a container used in the parsed tree to represent
the collection of assignments to condition items in the SIGNAL and RESIGNAL
statements.
*/
class Set_signal_information {
public:
Set_signal_information() { memset(m_item, 0, sizeof(m_item)); }
~Set_signal_information() = default;
bool set_item(enum_condition_item_name name, Item *item);
/**
For each condition item assignment, m_item[] contains the parsed tree
that represents the expression assigned, if any.
m_item[] is an array indexed by enum_condition_item_name.
*/
Item *m_item[CIN_LAST_PROPERTY + 1];
};
/**
Sql_cmd_common_signal represents the common properties of the
SIGNAL and RESIGNAL statements.
*/
class Sql_cmd_common_signal : public Sql_cmd {
protected:
/**
Constructor.
@param cond the condition signaled if any, or NULL.
@param set collection of signal condition item assignments.
*/
Sql_cmd_common_signal(const sp_condition_value *cond,
Set_signal_information *set)
: Sql_cmd(), m_cond(cond), m_set_signal_information(set) {}
~Sql_cmd_common_signal() override = default;
/**
Assign the condition items 'MYSQL_ERRNO', 'level' and 'MESSAGE_TEXT'
default values of a condition.
@param thd the current thread.
@param cond the condition to update.
@param set_level_code true if 'level' and 'MYSQL_ERRNO' needs to be
overwritten
@param level the level to assign
@param sqlcode the sql code to assign
*/
static void assign_defaults(THD *thd, Sql_condition *cond,
bool set_level_code,
Sql_condition::enum_severity_level level,
int sqlcode);
/**
Evaluate the condition items 'SQLSTATE', 'MYSQL_ERRNO', 'level' and
'MESSAGE_TEXT' default values for this statement.
@param thd the current thread.
@param cond the condition to update.
*/
void eval_defaults(THD *thd, Sql_condition *cond);
/**
Evaluate each signal condition items for this statement.
@param thd the current thread.
@param cond the condition to update.
@return 0 on success.
*/
int eval_signal_informations(THD *thd, Sql_condition *cond);
/**
The condition to signal or resignal.
This member is optional and can be NULL (RESIGNAL).
*/
const sp_condition_value *m_cond;
/**
Collection of 'SET item = value' assignments in the
SIGNAL/RESIGNAL statement.
*/
Set_signal_information *m_set_signal_information;
};
/**
Sql_cmd_signal represents a SIGNAL statement.
*/
class Sql_cmd_signal : public Sql_cmd_common_signal {
public:
/**
Constructor, used to represent a SIGNAL statement.
@param cond the SQL condition to signal (required).
@param set the collection of signal information to signal.
*/
Sql_cmd_signal(const sp_condition_value *cond, Set_signal_information *set)
: Sql_cmd_common_signal(cond, set) {}
~Sql_cmd_signal() override = default;
enum_sql_command sql_command_code() const override { return SQLCOM_SIGNAL; }
bool execute(THD *thd) override;
};
/**
Sql_cmd_resignal represents a RESIGNAL statement.
*/
class Sql_cmd_resignal : public Sql_cmd_common_signal {
public:
/**
Constructor, used to represent a RESIGNAL statement.
@param cond the SQL condition to resignal (optional, may be NULL).
@param set the collection of signal information to resignal.
*/
Sql_cmd_resignal(const sp_condition_value *cond, Set_signal_information *set)
: Sql_cmd_common_signal(cond, set) {}
~Sql_cmd_resignal() override = default;
enum_sql_command sql_command_code() const override { return SQLCOM_RESIGNAL; }
bool execute(THD *thd) override;
};
#endif