MySQL 8.4.0
Source Code Documentation
sql_get_diagnostics.h
Go to the documentation of this file.
1/* Copyright (c) 2011, 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_GET_DIAGNOSTICS_H
25#define SQL_GET_DIAGNOSTICS_H
26
27#include <assert.h>
28
29#include "my_sqlcommand.h"
30#include "sql/sql_cmd.h" // Sql_cmd
31
34class Item;
35class Sql_condition;
36class String;
37class THD;
38template <class T>
39class List;
40
41/**
42 Sql_cmd_get_diagnostics represents a GET DIAGNOSTICS statement.
43
44 The GET DIAGNOSTICS statement retrieves exception or completion
45 condition information from a Diagnostics Area, usually pertaining
46 to the last non-diagnostic SQL statement that was executed.
47*/
49 public:
50 /**
51 Constructor, used to represent a GET DIAGNOSTICS statement.
52
53 @param info Diagnostics information to be obtained.
54 */
56
59 }
60
61 bool execute(THD *thd) override;
62
63 private:
64 /** The information to be obtained. */
66};
67
68/**
69 Represents the diagnostics information to be obtained.
70
71 Diagnostic information is made available through statement
72 information and condition information items.
73*/
75 public:
76 /**
77 Which Diagnostics Area to access.
78 */
80 /** Access the first Diagnostics Area. */
82 /** Access the second Diagnostics Area. */
84 };
85
86 /** Set which Diagnostics Area to access. */
88
89 /** Get which Diagnostics Area to access. */
90 Which_area get_which_da(void) const { return m_area; }
91
92 /**
93 Aggregate diagnostics information.
94
95 @param thd The current thread.
96 @param da The Diagnostics Area.
97
98 @retval false on success.
99 @retval true on error
100 */
101 virtual bool aggregate(THD *thd, const Diagnostics_area *da) = 0;
102
103 protected:
104 /**
105 Diagnostics_information objects are allocated in thd->mem_root.
106 Do not rely on the destructor for any cleanup.
107 */
108 virtual ~Diagnostics_information() { assert(false); }
109
110 /**
111 Evaluate a diagnostics information item in a specific context.
112
113 @param thd The current thread.
114 @param diag_item The diagnostics information item.
115 @param ctx The context to evaluate the item.
116
117 @retval false on success.
118 @retval true on error.
119 */
120 template <typename Diag_item, typename Context>
121 bool evaluate(THD *thd, Diag_item *diag_item, Context ctx) {
122 Item *value;
123
124 /* Get this item's value. */
125 if (!(value = diag_item->get_value(thd, ctx))) return true;
126
127 /* Set variable/parameter value. */
128 return diag_item->set_value(thd, &value);
129 }
130
131 private:
132 /** Which Diagnostics Area to access. */
134};
135
136/**
137 A diagnostics information item. Used to associate a specific
138 diagnostics information item to a target variable.
139*/
141 public:
142 /**
143 Set a value for this item.
144
145 @param thd The current thread.
146 @param value The obtained value.
147
148 @retval false on success.
149 @retval true on error.
150 */
151 bool set_value(THD *thd, Item **value);
152
153 protected:
154 /**
155 Constructor, used to represent a diagnostics information item.
156
157 @param target A target that gets the value of this item.
158 */
160
161 /**
162 Diagnostics_information_item objects are allocated in thd->mem_root.
163 Do not rely on the destructor for any cleanup.
164 */
165 virtual ~Diagnostics_information_item() { assert(false); }
166
167 private:
168 /** The target variable that will receive the value of this item. */
170};
171
172/**
173 A statement information item.
174*/
176 public:
177 /** The name of a statement information item. */
179
180 /**
181 Constructor, used to represent a statement information item.
182
183 @param name The name of this item.
184 @param target A target that gets the value of this item.
185 */
188
189 /** Obtain value of this statement information item. */
190 Item *get_value(THD *thd, const Diagnostics_area *da);
191
192 private:
193 /** The name of this statement information item. */
195};
196
197/**
198 Statement information.
199
200 @remark Provides information about the execution of a statement.
201*/
203 public:
204 /**
205 Constructor, used to represent the statement information of a
206 GET DIAGNOSTICS statement.
207
208 @param items List of requested statement information items.
209 */
211 : m_items(items) {}
212
213 /** Obtain statement information in the context of a Diagnostics Area. */
214 bool aggregate(THD *thd, const Diagnostics_area *da) override;
215
216 private:
217 /* List of statement information items. */
219};
220
221/**
222 A condition information item.
223*/
225 public:
226 /**
227 The name of a condition information item.
228 */
229 enum Name {
243 };
244
245 /**
246 Constructor, used to represent a condition information item.
247
248 @param name The name of this item.
249 @param target A target that gets the value of this item.
250 */
253
254 /** Obtain value of this condition information item. */
255 Item *get_value(THD *thd, const Sql_condition *cond);
256
257 private:
258 /** The name of this condition information item. */
260
261 /** Create an string item to represent a condition item string. */
262 Item *make_utf8_string_item(THD *thd, const String *str);
263};
264
265/**
266 Condition information.
267
268 @remark Provides information about conditions raised during the
269 execution of a statement.
270*/
272 public:
273 /**
274 Constructor, used to represent the condition information of a
275 GET DIAGNOSTICS statement.
276
277 @param cond_number_expr Number that identifies the diagnostic condition.
278 @param items List of requested condition information items.
279 */
280 Condition_information(Item *cond_number_expr,
282 : m_cond_number_expr(cond_number_expr), m_items(items) {}
283
284 /** Obtain condition information in the context of a Diagnostics Area. */
285 bool aggregate(THD *thd, const Diagnostics_area *da) override;
286
287 private:
288 /**
289 Number that identifies the diagnostic condition for which
290 information is to be obtained.
291 */
293
294 /** List of condition information items. */
296};
297
298#endif
A condition information item.
Definition: sql_get_diagnostics.h:224
Condition_information_item(Name name, Item *target)
Constructor, used to represent a condition information item.
Definition: sql_get_diagnostics.h:251
Item * make_utf8_string_item(THD *thd, const String *str)
Create an string item to represent a condition item string.
Definition: sql_get_diagnostics.cc:274
Item * get_value(THD *thd, const Sql_condition *cond)
Obtain value of this condition information item.
Definition: sql_get_diagnostics.cc:296
Name
The name of a condition information item.
Definition: sql_get_diagnostics.h:229
@ CLASS_ORIGIN
Definition: sql_get_diagnostics.h:230
@ CONSTRAINT_SCHEMA
Definition: sql_get_diagnostics.h:233
@ SUBCLASS_ORIGIN
Definition: sql_get_diagnostics.h:231
@ RETURNED_SQLSTATE
Definition: sql_get_diagnostics.h:242
@ MESSAGE_TEXT
Definition: sql_get_diagnostics.h:240
@ CURSOR_NAME
Definition: sql_get_diagnostics.h:239
@ MYSQL_ERRNO
Definition: sql_get_diagnostics.h:241
@ COLUMN_NAME
Definition: sql_get_diagnostics.h:238
@ SCHEMA_NAME
Definition: sql_get_diagnostics.h:236
@ CONSTRAINT_NAME
Definition: sql_get_diagnostics.h:234
@ TABLE_NAME
Definition: sql_get_diagnostics.h:237
@ CATALOG_NAME
Definition: sql_get_diagnostics.h:235
@ CONSTRAINT_CATALOG
Definition: sql_get_diagnostics.h:232
Name m_name
The name of this condition information item.
Definition: sql_get_diagnostics.h:259
Condition information.
Definition: sql_get_diagnostics.h:271
bool aggregate(THD *thd, const Diagnostics_area *da) override
Obtain condition information in the context of a Diagnostics Area.
Definition: sql_get_diagnostics.cc:221
List< Condition_information_item > * m_items
List of condition information items.
Definition: sql_get_diagnostics.h:295
Condition_information(Item *cond_number_expr, List< Condition_information_item > *items)
Constructor, used to represent the condition information of a GET DIAGNOSTICS statement.
Definition: sql_get_diagnostics.h:280
Item * m_cond_number_expr
Number that identifies the diagnostic condition for which information is to be obtained.
Definition: sql_get_diagnostics.h:292
Stores status of the currently executed statement.
Definition: sql_error.h:269
A diagnostics information item.
Definition: sql_get_diagnostics.h:140
bool set_value(THD *thd, Item **value)
Set a value for this item.
Definition: sql_get_diagnostics.cc:129
Diagnostics_information_item(Item *target)
Constructor, used to represent a diagnostics information item.
Definition: sql_get_diagnostics.h:159
Item * m_target
The target variable that will receive the value of this item.
Definition: sql_get_diagnostics.h:169
virtual ~Diagnostics_information_item()
Diagnostics_information_item objects are allocated in thd->mem_root.
Definition: sql_get_diagnostics.h:165
Represents the diagnostics information to be obtained.
Definition: sql_get_diagnostics.h:74
Which_area m_area
Which Diagnostics Area to access.
Definition: sql_get_diagnostics.h:133
virtual ~Diagnostics_information()
Diagnostics_information objects are allocated in thd->mem_root.
Definition: sql_get_diagnostics.h:108
virtual bool aggregate(THD *thd, const Diagnostics_area *da)=0
Aggregate diagnostics information.
void set_which_da(Which_area area)
Set which Diagnostics Area to access.
Definition: sql_get_diagnostics.h:87
bool evaluate(THD *thd, Diag_item *diag_item, Context ctx)
Evaluate a diagnostics information item in a specific context.
Definition: sql_get_diagnostics.h:121
Which_area
Which Diagnostics Area to access.
Definition: sql_get_diagnostics.h:79
@ STACKED_AREA
Access the second Diagnostics Area.
Definition: sql_get_diagnostics.h:83
@ CURRENT_AREA
Access the first Diagnostics Area.
Definition: sql_get_diagnostics.h:81
Which_area get_which_da(void) const
Get which Diagnostics Area to access.
Definition: sql_get_diagnostics.h:90
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:934
Definition: sql_list.h:467
Sql_cmd_get_diagnostics represents a GET DIAGNOSTICS statement.
Definition: sql_get_diagnostics.h:48
enum_sql_command sql_command_code() const override
Return the command code for this statement.
Definition: sql_get_diagnostics.h:57
Diagnostics_information * m_info
The information to be obtained.
Definition: sql_get_diagnostics.h:65
bool execute(THD *thd) override
Execute this GET DIAGNOSTICS statement.
Definition: sql_get_diagnostics.cc:62
Sql_cmd_get_diagnostics(Diagnostics_information *info)
Constructor, used to represent a GET DIAGNOSTICS statement.
Definition: sql_get_diagnostics.h:55
Representation of an SQL command.
Definition: sql_cmd.h:83
Representation of a SQL condition.
Definition: sql_error.h:58
A statement information item.
Definition: sql_get_diagnostics.h:175
Name m_name
The name of this statement information item.
Definition: sql_get_diagnostics.h:194
Statement_information_item(Name name, Item *target)
Constructor, used to represent a statement information item.
Definition: sql_get_diagnostics.h:186
Item * get_value(THD *thd, const Diagnostics_area *da)
Obtain value of this statement information item.
Definition: sql_get_diagnostics.cc:183
Name
The name of a statement information item.
Definition: sql_get_diagnostics.h:178
@ ROW_COUNT
Definition: sql_get_diagnostics.h:178
@ NUMBER
Definition: sql_get_diagnostics.h:178
Statement information.
Definition: sql_get_diagnostics.h:202
Statement_information(List< Statement_information_item > *items)
Constructor, used to represent the statement information of a GET DIAGNOSTICS statement.
Definition: sql_get_diagnostics.h:210
bool aggregate(THD *thd, const Diagnostics_area *da) override
Obtain statement information in the context of a Diagnostics Area.
Definition: sql_get_diagnostics.cc:155
List< Statement_information_item > * m_items
Definition: sql_get_diagnostics.h:218
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:167
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
enum_sql_command
Definition: my_sqlcommand.h:46
@ SQLCOM_GET_DIAGNOSTICS
Definition: my_sqlcommand.h:180
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1073
bool area(const dd::Spatial_reference_system *srs, const Geometry *g, const char *func_name, double *result, bool *result_null) noexcept
Definition: area.cc:79
Representation of an SQL command.
case opt name
Definition: sslopt-case.h:29