MySQL 8.0.31
Source Code Documentation
sql_signal.h
Go to the documentation of this file.
1/* Copyright (c) 2008, 2022, 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 also distributed 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 included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef SQL_SIGNAL_H
24#define SQL_SIGNAL_H
25
26#include <string.h>
27
28#include "my_sqlcommand.h"
29#include "sql/sql_cmd.h" // Sql_cmd
30#include "sql/sql_error.h" // Sql_condition
31
32class Item;
33class THD;
35
36/**
37 This enumeration list all the condition item names of a condition in the
38 SQL condition area.
39*/
41 /*
42 Conditions that can be set by the user (SIGNAL/RESIGNAL),
43 and by the server implementation.
44 */
45
60};
61
62/**
63 Set_signal_information is a container used in the parsed tree to represent
64 the collection of assignments to condition items in the SIGNAL and RESIGNAL
65 statements.
66*/
68 public:
69 Set_signal_information() { memset(m_item, 0, sizeof(m_item)); }
70
72
74
75 /**
76 For each condition item assignment, m_item[] contains the parsed tree
77 that represents the expression assigned, if any.
78 m_item[] is an array indexed by enum_condition_item_name.
79 */
81};
82
83/**
84 Sql_cmd_common_signal represents the common properties of the
85 SIGNAL and RESIGNAL statements.
86*/
88 protected:
89 /**
90 Constructor.
91 @param cond the condition signaled if any, or NULL.
92 @param set collection of signal condition item assignments.
93 */
97
98 ~Sql_cmd_common_signal() override = default;
99
100 /**
101 Assign the condition items 'MYSQL_ERRNO', 'level' and 'MESSAGE_TEXT'
102 default values of a condition.
103 @param thd the current thread.
104 @param cond the condition to update.
105 @param set_level_code true if 'level' and 'MYSQL_ERRNO' needs to be
106 overwritten
107 @param level the level to assign
108 @param sqlcode the sql code to assign
109 */
110 static void assign_defaults(THD *thd, Sql_condition *cond,
111 bool set_level_code,
113 int sqlcode);
114
115 /**
116 Evaluate the condition items 'SQLSTATE', 'MYSQL_ERRNO', 'level' and
117 'MESSAGE_TEXT' default values for this statement.
118 @param thd the current thread.
119 @param cond the condition to update.
120 */
121 void eval_defaults(THD *thd, Sql_condition *cond);
122
123 /**
124 Evaluate each signal condition items for this statement.
125 @param thd the current thread.
126 @param cond the condition to update.
127 @return 0 on success.
128 */
130
131 /**
132 The condition to signal or resignal.
133 This member is optional and can be NULL (RESIGNAL).
134 */
136
137 /**
138 Collection of 'SET item = value' assignments in the
139 SIGNAL/RESIGNAL statement.
140 */
142};
143
144/**
145 Sql_cmd_signal represents a SIGNAL statement.
146*/
148 public:
149 /**
150 Constructor, used to represent a SIGNAL statement.
151 @param cond the SQL condition to signal (required).
152 @param set the collection of signal information to signal.
153 */
155 : Sql_cmd_common_signal(cond, set) {}
156
157 ~Sql_cmd_signal() override = default;
158
160
161 bool execute(THD *thd) override;
162};
163
164/**
165 Sql_cmd_resignal represents a RESIGNAL statement.
166*/
168 public:
169 /**
170 Constructor, used to represent a RESIGNAL statement.
171 @param cond the SQL condition to resignal (optional, may be NULL).
172 @param set the collection of signal information to resignal.
173 */
175 : Sql_cmd_common_signal(cond, set) {}
176
177 ~Sql_cmd_resignal() override = default;
178
180
181 bool execute(THD *thd) override;
182};
183
184#endif
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:802
Set_signal_information is a container used in the parsed tree to represent the collection of assignme...
Definition: sql_signal.h:67
~Set_signal_information()=default
Set_signal_information()
Definition: sql_signal.h:69
Item * m_item[CIN_LAST_PROPERTY+1]
For each condition item assignment, m_item[] contains the parsed tree that represents the expression ...
Definition: sql_signal.h:80
bool set_item(enum_condition_item_name name, Item *item)
Definition: sql_signal.cc:87
Sql_cmd_common_signal represents the common properties of the SIGNAL and RESIGNAL statements.
Definition: sql_signal.h:87
Sql_cmd_common_signal(const sp_condition_value *cond, Set_signal_information *set)
Constructor.
Definition: sql_signal.h:94
~Sql_cmd_common_signal() override=default
const sp_condition_value * m_cond
The condition to signal or resignal.
Definition: sql_signal.h:135
Set_signal_information * m_set_signal_information
Collection of 'SET item = value' assignments in the SIGNAL/RESIGNAL statement.
Definition: sql_signal.h:141
int eval_signal_informations(THD *thd, Sql_condition *cond)
Evaluate each signal condition items for this statement.
Definition: sql_signal.cc:235
static void assign_defaults(THD *thd, Sql_condition *cond, bool set_level_code, Sql_condition::enum_severity_level level, int sqlcode)
Assign the condition items 'MYSQL_ERRNO', 'level' and 'MESSAGE_TEXT' default values of a condition.
Definition: sql_signal.cc:97
void eval_defaults(THD *thd, Sql_condition *cond)
Evaluate the condition items 'SQLSTATE', 'MYSQL_ERRNO', 'level' and 'MESSAGE_TEXT' default values for...
Definition: sql_signal.cc:108
Sql_cmd_resignal represents a RESIGNAL statement.
Definition: sql_signal.h:167
~Sql_cmd_resignal() override=default
bool execute(THD *thd) override
Execute RESIGNAL SQL-statement.
Definition: sql_signal.cc:420
Sql_cmd_resignal(const sp_condition_value *cond, Set_signal_information *set)
Constructor, used to represent a RESIGNAL statement.
Definition: sql_signal.h:174
enum_sql_command sql_command_code() const override
Return the command code for this statement.
Definition: sql_signal.h:179
Sql_cmd_signal represents a SIGNAL statement.
Definition: sql_signal.h:147
enum_sql_command sql_command_code() const override
Return the command code for this statement.
Definition: sql_signal.h:159
~Sql_cmd_signal() override=default
Sql_cmd_signal(const sp_condition_value *cond, Set_signal_information *set)
Constructor, used to represent a SIGNAL statement.
Definition: sql_signal.h:154
bool execute(THD *thd) override
Execute this SQL statement.
Definition: sql_signal.cc:365
Representation of an SQL command.
Definition: sql_cmd.h:64
Representation of a SQL condition.
Definition: sql_error.h:57
enum_severity_level
Enumeration value describing the severity of the condition.
Definition: sql_error.h:62
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:922
This class represents condition-value term in DECLARE CONDITION or DECLARE HANDLER statements.
Definition: sp_pcontext.h:132
enum_sql_command
Definition: my_sqlcommand.h:45
@ SQLCOM_RESIGNAL
Definition: my_sqlcommand.h:177
@ SQLCOM_SIGNAL
Definition: my_sqlcommand.h:176
std::set< Key, Compare, ut::allocator< Key > > set
Specialization of set which uses ut_allocator.
Definition: ut0new.h:2863
Representation of an SQL command.
enum_condition_item_name
This enumeration list all the condition item names of a condition in the SQL condition area.
Definition: sql_signal.h:40
@ CIN_TABLE_NAME
Definition: sql_signal.h:54
@ CIN_CURSOR_NAME
Definition: sql_signal.h:56
@ CIN_SCHEMA_NAME
Definition: sql_signal.h:53
@ CIN_FIRST_PROPERTY
Definition: sql_signal.h:47
@ CIN_CLASS_ORIGIN
Definition: sql_signal.h:46
@ CIN_MYSQL_ERRNO
Definition: sql_signal.h:58
@ CIN_CONSTRAINT_SCHEMA
Definition: sql_signal.h:50
@ CIN_SUBCLASS_ORIGIN
Definition: sql_signal.h:48
@ CIN_LAST_PROPERTY
Definition: sql_signal.h:59
@ CIN_COLUMN_NAME
Definition: sql_signal.h:55
@ CIN_CONSTRAINT_CATALOG
Definition: sql_signal.h:49
@ CIN_MESSAGE_TEXT
Definition: sql_signal.h:57
@ CIN_CONSTRAINT_NAME
Definition: sql_signal.h:51
@ CIN_CATALOG_NAME
Definition: sql_signal.h:52
case opt name
Definition: sslopt-case.h:32