MySQL 9.1.0
Source Code Documentation
sql_signal.h
Go to the documentation of this file.
1/* Copyright (c) 2008, 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 SQL_SIGNAL_H
25#define SQL_SIGNAL_H
26
27#include <string.h>
28
29#include "my_sqlcommand.h"
30#include "sql/sql_cmd.h" // Sql_cmd
31#include "sql/sql_error.h" // Sql_condition
32
33class Item;
34class THD;
36
37/**
38 This enumeration list all the condition item names of a condition in the
39 SQL condition area.
40*/
42 /*
43 Conditions that can be set by the user (SIGNAL/RESIGNAL),
44 and by the server implementation.
45 */
46
61};
62
63/**
64 Set_signal_information is a container used in the parsed tree to represent
65 the collection of assignments to condition items in the SIGNAL and RESIGNAL
66 statements.
67*/
69 public:
70 Set_signal_information() { memset(m_item, 0, sizeof(m_item)); }
71
73
75
76 /**
77 For each condition item assignment, m_item[] contains the parsed tree
78 that represents the expression assigned, if any.
79 m_item[] is an array indexed by enum_condition_item_name.
80 */
82};
83
84/**
85 Sql_cmd_common_signal represents the common properties of the
86 SIGNAL and RESIGNAL statements.
87*/
89 protected:
90 /**
91 Constructor.
92 @param cond the condition signaled if any, or NULL.
93 @param set collection of signal condition item assignments.
94 */
98
99 ~Sql_cmd_common_signal() override = default;
100
101 /**
102 Assign the condition items 'MYSQL_ERRNO', 'level' and 'MESSAGE_TEXT'
103 default values of a condition.
104 @param thd the current thread.
105 @param cond the condition to update.
106 @param set_level_code true if 'level' and 'MYSQL_ERRNO' needs to be
107 overwritten
108 @param level the level to assign
109 @param sqlcode the sql code to assign
110 */
111 static void assign_defaults(THD *thd, Sql_condition *cond,
112 bool set_level_code,
114 int sqlcode);
115
116 /**
117 Evaluate the condition items 'SQLSTATE', 'MYSQL_ERRNO', 'level' and
118 'MESSAGE_TEXT' default values for this statement.
119 @param thd the current thread.
120 @param cond the condition to update.
121 */
122 void eval_defaults(THD *thd, Sql_condition *cond);
123
124 /**
125 Evaluate each signal condition items for this statement.
126 @param thd the current thread.
127 @param cond the condition to update.
128 @return 0 on success.
129 */
131
132 /**
133 The condition to signal or resignal.
134 This member is optional and can be NULL (RESIGNAL).
135 */
137
138 /**
139 Collection of 'SET item = value' assignments in the
140 SIGNAL/RESIGNAL statement.
141 */
143};
144
145/**
146 Sql_cmd_signal represents a SIGNAL statement.
147*/
149 public:
150 /**
151 Constructor, used to represent a SIGNAL statement.
152 @param cond the SQL condition to signal (required).
153 @param set the collection of signal information to signal.
154 */
156 : Sql_cmd_common_signal(cond, set) {}
157
158 ~Sql_cmd_signal() override = default;
159
161
162 bool execute(THD *thd) override;
163};
164
165/**
166 Sql_cmd_resignal represents a RESIGNAL statement.
167*/
169 public:
170 /**
171 Constructor, used to represent a RESIGNAL statement.
172 @param cond the SQL condition to resignal (optional, may be NULL).
173 @param set the collection of signal information to resignal.
174 */
176 : Sql_cmd_common_signal(cond, set) {}
177
178 ~Sql_cmd_resignal() override = default;
179
181
182 bool execute(THD *thd) override;
183};
184
185#endif
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:930
Set_signal_information is a container used in the parsed tree to represent the collection of assignme...
Definition: sql_signal.h:68
~Set_signal_information()=default
Set_signal_information()
Definition: sql_signal.h:70
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:81
bool set_item(enum_condition_item_name name, Item *item)
Definition: sql_signal.cc:88
Sql_cmd_common_signal represents the common properties of the SIGNAL and RESIGNAL statements.
Definition: sql_signal.h:88
Sql_cmd_common_signal(const sp_condition_value *cond, Set_signal_information *set)
Constructor.
Definition: sql_signal.h:95
~Sql_cmd_common_signal() override=default
const sp_condition_value * m_cond
The condition to signal or resignal.
Definition: sql_signal.h:136
Set_signal_information * m_set_signal_information
Collection of 'SET item = value' assignments in the SIGNAL/RESIGNAL statement.
Definition: sql_signal.h:142
int eval_signal_informations(THD *thd, Sql_condition *cond)
Evaluate each signal condition items for this statement.
Definition: sql_signal.cc:236
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:98
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:109
Sql_cmd_resignal represents a RESIGNAL statement.
Definition: sql_signal.h:168
~Sql_cmd_resignal() override=default
bool execute(THD *thd) override
Execute RESIGNAL SQL-statement.
Definition: sql_signal.cc:421
Sql_cmd_resignal(const sp_condition_value *cond, Set_signal_information *set)
Constructor, used to represent a RESIGNAL statement.
Definition: sql_signal.h:175
enum_sql_command sql_command_code() const override
Return the command code for this statement.
Definition: sql_signal.h:180
Sql_cmd_signal represents a SIGNAL statement.
Definition: sql_signal.h:148
enum_sql_command sql_command_code() const override
Return the command code for this statement.
Definition: sql_signal.h:160
~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:155
bool execute(THD *thd) override
Execute this SQL statement.
Definition: sql_signal.cc:366
Representation of an SQL command.
Definition: sql_cmd.h:83
Representation of a SQL condition.
Definition: sql_error.h:58
enum_severity_level
Enumeration value describing the severity of the condition.
Definition: sql_error.h:63
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
This class represents condition-value term in DECLARE CONDITION or DECLARE HANDLER statements.
Definition: sp_pcontext.h:133
enum_sql_command
Definition: my_sqlcommand.h:46
@ SQLCOM_RESIGNAL
Definition: my_sqlcommand.h:178
@ SQLCOM_SIGNAL
Definition: my_sqlcommand.h:177
std::set< Key, Compare, ut::allocator< Key > > set
Specialization of set which uses ut_allocator.
Definition: ut0new.h:2884
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:41
@ CIN_TABLE_NAME
Definition: sql_signal.h:55
@ CIN_CURSOR_NAME
Definition: sql_signal.h:57
@ CIN_SCHEMA_NAME
Definition: sql_signal.h:54
@ CIN_FIRST_PROPERTY
Definition: sql_signal.h:48
@ CIN_CLASS_ORIGIN
Definition: sql_signal.h:47
@ CIN_MYSQL_ERRNO
Definition: sql_signal.h:59
@ CIN_CONSTRAINT_SCHEMA
Definition: sql_signal.h:51
@ CIN_SUBCLASS_ORIGIN
Definition: sql_signal.h:49
@ CIN_LAST_PROPERTY
Definition: sql_signal.h:60
@ CIN_COLUMN_NAME
Definition: sql_signal.h:56
@ CIN_CONSTRAINT_CATALOG
Definition: sql_signal.h:50
@ CIN_MESSAGE_TEXT
Definition: sql_signal.h:58
@ CIN_CONSTRAINT_NAME
Definition: sql_signal.h:52
@ CIN_CATALOG_NAME
Definition: sql_signal.h:53
case opt name
Definition: sslopt-case.h:29