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