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