MySQL  8.0.26
Source Code Documentation
sql_error.h
Go to the documentation of this file.
1 /* Copyright (c) 2005, 2021, 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_ERROR_H
24 #define SQL_ERROR_H
25 
26 #include <assert.h>
27 #include <stdio.h>
28 #include <string.h>
29 #include <sys/types.h>
30 
31 #include "lex_string.h"
32 #include "m_ctype.h"
33 #include "m_string.h"
34 #include "my_alloc.h"
35 #include "my_compiler.h"
36 
37 #include "my_inttypes.h"
38 #include "mysql_com.h" /* MYSQL_ERRMSG_SIZE */
39 #include "sql/sql_list.h"
40 #include "sql/sql_plist.h" /* I_P_List */
41 #include "sql_string.h" /* String */
42 
43 class THD;
44 class my_decimal;
45 struct MYSQL_TIME;
46 
47 ///////////////////////////////////////////////////////////////////////////
48 
49 /**
50  Representation of a SQL condition.
51  A SQL condition can be a completion condition (note, warning),
52  or an exception condition (error, not found).
53 */
55  public:
56  /**
57  Enumeration value describing the severity of the condition.
58  */
60 
61  /**
62  Get the MESSAGE_TEXT of this condition.
63  @return the message text.
64  */
65  const char *message_text() const { return m_message_text.ptr(); }
66 
67  /**
68  Get the MESSAGE_OCTET_LENGTH of this condition.
69  @return the length in bytes of the message text.
70  */
71  size_t message_octet_length() const { return m_message_text.length(); }
72 
73  /**
74  Get the RETURNED_SQLSTATE of this condition.
75  @return the sql state.
76  */
77  const char *returned_sqlstate() const { return m_returned_sqlstate; }
78 
79  /**
80  Get the MYSQL_ERRNO of this condition.
81  @return the sql error number condition item.
82  */
83  uint mysql_errno() const { return m_mysql_errno; }
84 
85  /**
86  Get the severity level of this condition.
87  @return the severity level condition item.
88  */
90  return m_severity_level;
91  }
92 
93  private:
94  /*
95  The interface of Sql_condition is mostly private, by design,
96  so that only the following code:
97  - various raise_error() or raise_warning() methods in class THD,
98  - the implementation of SIGNAL / RESIGNAL / GET DIAGNOSTICS
99  - catch / re-throw of SQL conditions in stored procedures (sp_rcontext)
100  is allowed to create / modify a SQL condition.
101  Enforcing this policy prevents confusion, since the only public
102  interface available to the rest of the server implementation
103  is the interface offered by the THD methods (THD::raise_error()),
104  which should be used.
105  */
106  friend class THD;
107  friend class Diagnostics_area;
108  friend class Sql_cmd_common_signal;
109  friend class Sql_cmd_signal;
110  friend class Sql_cmd_resignal;
111  friend class sp_rcontext;
113 
114  /**
115  Constructor.
116 
117  @param mem_root Memory root to use for the condition items
118  of this condition.
119  */
121 
122  /**
123  Constructor.
124 
125  @param mem_root Memory root to use for the condition items
126  of this condition.
127  @param mysql_errno MYSQL_ERRNO
128  @param returned_sqlstate RETURNED_SQLSTATE
129  @param severity Severity level - error, warning or note.
130  @param message_text MESSAGE_TEXT
131  */
133  const char *returned_sqlstate,
135  const char *message_text);
136 
137  /** Destructor. */
138  ~Sql_condition() = default;
139 
140  /**
141  Copy optional condition items attributes.
142  @param cond the condition to copy.
143  */
144  void copy_opt_attributes(const Sql_condition *cond);
145 
146  /**
147  Set the condition message test.
148  @param message_text Message text, expressed in the character set derived
149  from the server --language option
150  */
151  void set_message_text(const char *message_text);
152 
153  /** Set the RETURNED_SQLSTATE of this condition. */
154  void set_returned_sqlstate(const char *sqlstate) {
155  memcpy(m_returned_sqlstate, sqlstate, SQLSTATE_LENGTH);
157  }
158 
159  /** Set the CLASS_ORIGIN and SUBCLASS_ORIGIN of this condition. */
160  void set_class_origins();
161 
162  private:
163  /** SQL CLASS_ORIGIN condition item. */
165 
166  /** SQL SUBCLASS_ORIGIN condition item. */
168 
169  /** SQL CONSTRAINT_CATALOG condition item. */
171 
172  /** SQL CONSTRAINT_SCHEMA condition item. */
174 
175  /** SQL CONSTRAINT_NAME condition item. */
177 
178  /** SQL CATALOG_NAME condition item. */
180 
181  /** SQL SCHEMA_NAME condition item. */
183 
184  /** SQL TABLE_NAME condition item. */
186 
187  /** SQL COLUMN_NAME condition item. */
189 
190  /** SQL CURSOR_NAME condition item. */
192 
193  /** Message text, expressed in the character set implied by --language. */
195 
196  /** MySQL extension, MYSQL_ERRNO condition item. */
198 
199  /**
200  SQL RETURNED_SQLSTATE condition item.
201  This member is always NUL terminated.
202  */
204 
205  /** Severity (error, warning, note) of this condition. */
207 
208  /** Pointers for participating in the list of conditions. */
211 
212  /** Memory root to use to hold condition item values. */
214 };
215 
216 ///////////////////////////////////////////////////////////////////////////
217 
218 size_t err_conv(char *buff, size_t to_length, const char *from,
219  size_t from_length, const CHARSET_INFO *from_cs);
220 
223  size_t buf_length;
224 
225  public:
226  explicit ErrConvString(const String *str) {
227  buf_length = err_conv(err_buffer, sizeof(err_buffer), str->ptr(),
228  str->length(), str->charset());
229  }
230 
231  ErrConvString(const char *str, size_t length) {
234  }
235 
236  ErrConvString(const char *str, size_t length, const CHARSET_INFO *cs) {
238  }
239 
241  buf_length = snprintf(err_buffer, sizeof(err_buffer), "%lld", nr);
242  }
243 
244  ErrConvString(longlong nr, bool unsigned_flag) {
245  buf_length = longlong10_to_str(nr, err_buffer, unsigned_flag ? 10 : -10) -
246  err_buffer;
247  }
248 
249  ErrConvString(double nr);
250  ErrConvString(const my_decimal *nr);
251  ErrConvString(const MYSQL_TIME *ltime, uint dec);
252 
253  const char *ptr() const { return err_buffer; }
254  size_t length() const { return buf_length; }
255 };
256 
257 ///////////////////////////////////////////////////////////////////////////
258 
259 /**
260  Stores status of the currently executed statement.
261  Cleared at the beginning of the statement, and then
262  can hold either OK, ERROR, or EOF status.
263  Can not be assigned twice per statement.
264 */
266  /** The type of the counted and doubly linked list of conditions. */
267  typedef I_P_List<
273 
274  public:
275  /** Const iterator used to iterate through the condition list. */
277 
279  /** The area is cleared at start of a statement. */
280  DA_EMPTY = 0,
281  /** Set whenever one calls my_ok(). */
283  /** Set whenever one calls my_eof(). */
285  /** Set whenever one calls my_error() or my_message(). */
287  /** Set in case of a custom response, such as one from COM_STMT_PREPARE. */
289  };
290 
291  Diagnostics_area(bool allow_unlimited_conditions);
293 
294  void set_overwrite_status(bool can_overwrite_status) {
295  m_can_overwrite_status = can_overwrite_status;
296  }
297 
298  bool is_sent() const { return m_is_sent; }
299 
301 
302  /**
303  Set OK status -- ends commands that do not return a
304  result set, e.g. INSERT/UPDATE/DELETE.
305 
306  @param affected_rows The number of rows affected by the last statement.
307  @sa Diagnostics_area::m_affected_rows.
308  @param last_insert_id The value to be returned by LAST_INSERT_ID().
309  @sa Diagnostics_area::m_last_insert_id.
310  @param message_text The OK-message text.
311  */
313  const char *message_text);
314 
315  /**
316  Set EOF status.
317 
318  @param thd Thread context.
319  */
320  void set_eof_status(THD *thd);
321 
322  /**
323  Set ERROR status in the Diagnostics Area. This function should be used to
324  report fatal errors (such as out-of-memory errors) when no further
325  processing is possible.
326 
327  @param thd Thread handle
328  @param mysql_errno SQL-condition error number
329  */
330  void set_error_status(THD *thd, uint mysql_errno);
331 
332  /**
333  Set ERROR status in the Diagnostics Area.
334 
335  @param mysql_errno SQL-condition error number
336  @param message_text SQL-condition message
337  @param returned_sqlstate SQL-condition state
338  */
339  void set_error_status(uint mysql_errno, const char *message_text,
340  const char *returned_sqlstate);
341 
342  /**
343  Mark the Diagnostics Area as 'DISABLED'.
344 
345  This is used in rare cases when the COM_ command at hand sends a response
346  in a custom format. One example is COM_STMT_PREPARE.
347  */
348  void disable_status() {
349  assert(m_status == DA_EMPTY);
351  }
352 
353  /**
354  Clear this Diagnostics Area.
355 
356  Normally called at the end of a statement.
357  */
358  void reset_diagnostics_area();
359 
360  bool is_set() const { return m_status != DA_EMPTY; }
361 
362  bool is_error() const { return m_status == DA_ERROR; }
363 
364  bool is_eof() const { return m_status == DA_EOF; }
365 
366  bool is_ok() const { return m_status == DA_OK; }
367 
368  bool is_disabled() const { return m_status == DA_DISABLED; }
369 
371 
372  const char *message_text() const {
373  assert(m_status == DA_ERROR || m_status == DA_OK);
374  return m_message_text;
375  }
376 
377  uint mysql_errno() const {
378  assert(m_status == DA_ERROR);
379  return m_mysql_errno;
380  }
381 
382  const char *returned_sqlstate() const {
383  assert(m_status == DA_ERROR);
384  return m_returned_sqlstate;
385  }
386 
388  assert(m_status == DA_OK);
389  return m_affected_rows;
390  }
391 
393  assert(m_status == DA_OK);
394  return m_last_insert_id;
395  }
396 
398  assert(m_status == DA_OK || m_status == DA_EOF);
400  }
401 
402  /** Return the number of conditions raised by the current statement. */
405  }
406 
407  /**
408  Reset between two COM_ commands. Conditions are preserved
409  between commands, but m_current_statement_cond_count indicates
410  the number of conditions of this particular statement only.
411  */
413 
414  /**
415  Checks if the condition list contains SQL-condition with the given message.
416 
417  @param message_text Message text
418  @param message_length Length of message_text
419 
420  @return true if the condition list contains an SQL-condition with the given
421  message text.
422  */
423  bool has_sql_condition(const char *message_text, size_t message_length) const;
424 
425  /**
426  Checks if the condition list contains SQL-condition with the given error
427  code.
428 
429  @param sql_errno Error code
430 
431  @return true if the condition list contains an SQL-condition with the given
432  error code.
433  */
434  bool has_sql_condition(uint sql_errno) const;
435 
436  /**
437  Reset the current condition information stored in the Diagnostics Area.
438  Clear all conditions, the number of conditions, reset current row counter
439  to point to the first row.
440  */
441  void reset_condition_info(THD *thd);
442 
443  /** Return the current counter value. */
446  }
447 
448  /** Increment the current row counter to point at the next row. */
450 
451  /** Set the current row counter to point to the given row number. */
452  void set_current_row_for_condition(ulong rowno) {
454  }
455 
456  /** Reset the current row counter. Start counting from 1. */
458 
459  /**
460  The number of errors, or number of rows returned by SHOW ERRORS,
461  also the value of session variable @@error_count.
462  */
463  ulong error_count(THD *thd) const;
464 
465  /**
466  Used for @@warning_count system variable, which prints
467  the number of rows returned by SHOW WARNINGS.
468  */
469  ulong warn_count(THD *thd) const;
470 
471  /**
472  The number of conditions (errors, warnings and notes) in the list.
473  */
475 
477 
478  const char *get_first_condition_message();
479 
480  /** Make sure there is room for the given number of conditions. */
482 
483  /**
484  Add a new SQL-condition to the current list and increment the respective
485  counters.
486 
487  @param thd Thread context.
488  @param mysql_errno SQL-condition error number.
489  @param returned_sqlstate SQL-condition state.
490  @param severity SQL-condition severity.
491  @param message_text SQL-condition message.
492 
493  @return a pointer to the added SQL-condition.
494  */
496  const char *returned_sqlstate,
498  const char *message_text);
499 
500  /**
501  Mark current SQL-conditions so that we can later know which
502  SQL-conditions have been added.
503  */
505 
506  /**
507  Copy SQL-conditions that have been added since
508  mark_preexisting_sql_conditions() was called.
509 
510  @param thd Thread context.
511  @param src_da Diagnostics Area to copy from.
512  */
513  void copy_new_sql_conditions(THD *thd, const Diagnostics_area *src_da);
514 
515  /**
516  Copy all SQL-conditions from src_da to this DA.
517 
518  @param thd Thread context.
519  @param src_da Diagnostics Area to copy from.
520  */
521  void copy_sql_conditions_from_da(THD *thd, const Diagnostics_area *src_da);
522 
523  /**
524  Copy Sql_conditions that are not SL_ERROR from the source
525  Diagnostics Area to the current Diagnostics Area.
526 
527  @param thd Thread context.
528  @param src_da Diagnostics Area to copy from.
529  */
530  void copy_non_errors_from_da(THD *thd, const Diagnostics_area *src_da);
531 
532  /**
533  @return SQL-condition, which corresponds to the error state in
534  Diagnostics Area.
535  */
537 
538  private:
539  /**
540  Add a new SQL-condition to the current list and increment the respective
541  counters.
542 
543  @param thd Thread context.
544  @param sql_condition SQL-condition to copy values from.
545 
546  @return a pointer to the added SQL-condition.
547  */
548  Sql_condition *push_warning(THD *thd, const Sql_condition *sql_condition);
549 
550  /**
551  Push the given Diagnostics Area on top of the stack.
552  "This" will then become the stacked Diagnostics Area.
553  Conditions present in the new stacked Diagnostics Area
554  will be copied to the new top Diagnostics Area.
555 
556  @note This function will not set THD::m_stmt_da.
557  Use THD::push_diagnostics_area() instead.
558 
559  @param thd Thread context
560  @param da Diagnostics Area to be come the top of
561  the Diagnostics Area stack.
562  @param copy_conditions
563  Copy the conditions from the new second Diagnostics Area
564  to the new first Diagnostics Area, as per SQL standard.
565  */
567  bool copy_conditions);
568 
569  /**
570  Pop "this" off the Diagnostics Area stack.
571 
572  @note This function will not set THD::m_stmt_da.
573  Use THD::pop_diagnostics_area() instead.
574 
575  @returns The new top of the Diagnostics Area stack.
576  */
578 
579  /**
580  Returns the Diagnostics Area below the current diagnostics
581  area on the stack.
582  */
583  const Diagnostics_area *stacked_da() const { return m_stacked_da; }
584 
585  private:
586  /** Pointer to the Diagnostics Area below on the stack. */
588 
589  /** A memory root to allocate conditions */
591 
592  /** List of conditions of all severities. */
594 
595  /** List of conditions present in DA at handler activation. */
597 
598  /** True if status information is sent to the client. */
599  bool m_is_sent;
600 
601  /** Set to make set_error_status after set_{ok,eof}_status possible. */
603 
604  /** Indicates if push_warning() allows unlimited number of conditions. */
606 
608 
609  private:
610  /*
611  This section contains basic attributes of Sql_condition to store
612  information about error (SQL-condition of error severity) or OK-message.
613  The attributes are inlined here (instead of using Sql_condition) to be able
614  to store the information in case of out-of-memory error.
615  */
616 
617  /**
618  Message buffer. It is used only when DA is in OK or ERROR status.
619  If DA status is ERROR, it's the MESSAGE_TEXT attribute of SQL-condition.
620  If DA status is OK, it's the OK-message to be sent.
621  */
623 
624  /**
625  SQL RETURNED_SQLSTATE condition item.
626  This member is always NUL terminated.
627  */
629 
630  /**
631  SQL error number. One of ER_ codes from share/errmsg.txt.
632  Set by set_error_status.
633  */
635 
636  /**
637  The number of rows affected by the last statement. This is
638  semantically close to thd->row_count_func, but has a different
639  life cycle. thd->row_count_func stores the value returned by
640  function ROW_COUNT() and is cleared only by statements that
641  update its value, such as INSERT, UPDATE, DELETE and few others.
642  This member is cleared at the beginning of the next statement.
643 
644  We could possibly merge the two, but life cycle of thd->row_count_func
645  can not be changed.
646  */
648 
649  /**
650  Similarly to the previous member, this is a replacement of
651  thd->first_successful_insert_id_in_prev_stmt, which is used
652  to implement LAST_INSERT_ID().
653  */
655 
656  /**
657  Number of conditions of this last statement. May differ from
658  the number of conditions returned by SHOW WARNINGS e.g. in case
659  the statement doesn't clear the conditions, and doesn't generate
660  them.
661  */
663 
664  /**
665  The number of conditions of the current statement. m_conditions_list
666  life cycle differs from statement life cycle -- it may span
667  multiple statements. In that case we get
668  m_current_statement_cond_count 0, whereas m_conditions_list is not empty.
669  */
671 
672  /** A break down of the number of conditions per severity (level). */
674 
675  /**
676  Row counter, to print in errors and warnings. Not increased in
677  create_sort_index(); may differ from examined_row_count.
678  */
680 
681  /** Save @@error_count before pre-clearing the DA. */
683 
684  /** Save @@warning_count before pre-clearing the DA. */
686 
687  friend class THD;
688 };
689 
690 ///////////////////////////////////////////////////////////////////////////
691 
693  uint code, const char *message_text);
694 
695 /**
696  Convenience function for sending a warning with level SL_WARNING and no
697  arguments to the message.
698 
699  @param thd The session to send the warning to.
700  @param code The warning number.
701 */
702 void push_warning(THD *thd, uint code);
703 
704 /*
705  Note that this MY_ATTRIBUTE check cannot detect number/type mismatch
706  since the format string is not known at compile time.
707  It can however detect if push_warning_printf() is used without any
708  printf arguments. In such cases, use push_warning() instead.
709 */
711  uint code, const char *format, ...)
712  MY_ATTRIBUTE((format(printf, 4, 5)));
713 
714 /**
715  Generates a warning that a feature is deprecated.
716 
717  Using it as
718  push_deprecated_warn(thd, "BAD", "'GOOD'");
719  Will result in a warning:
720  "The syntax 'BAD' is deprecated and will be removed in a
721  future release. Please use 'GOOD' instead"
722 
723  If a function is deprecated, it should implement
724  Item_func::is_deprecated() to return true to prevent the
725  usage of the function in the generated column expression.
726 
727  @param thd Thread context. If NULL, warning is written
728  to the error log, otherwise the warning is
729  sent to the client.
730  @param old_syntax Deprecated syntax.
731  @param new_syntax Replacement syntax.
732 */
733 void push_deprecated_warn(THD *thd, const char *old_syntax,
734  const char *new_syntax);
735 
736 /**
737  Generates a warning that a feature is deprecated.
738 
739  Using it as
740  push_deprecated_warn_no_replacement(thd, "old");
741  Will result in a warning:
742  "The syntax 'old' is deprecated and will be removed in a
743  future release.
744 
745  If a function is deprecated, it should implement
746  Item_func::is_deprecated() to return true to prevent the
747  usage of the function in the generated column expression.
748 
749  @param thd Thread context. If NULL, warning is written
750  to the error log, otherwise the warning is
751  sent to the client.
752  @param old_syntax Deprecated syntax.
753 */
754 void push_deprecated_warn_no_replacement(THD *thd, const char *old_syntax);
755 
756 bool mysqld_show_warnings(THD *thd, ulong levels_to_show);
757 
758 size_t convert_error_message(char *to, size_t to_length,
759  const CHARSET_INFO *to_cs, const char *from,
760  size_t from_length, const CHARSET_INFO *from_cs,
761  uint *errors);
762 
763 extern const LEX_CSTRING warning_level_names[];
764 
765 bool is_sqlstate_valid(const LEX_STRING *sqlstate);
766 
767 /**
768  Checks if the specified SQL-state-string defines COMPLETION condition.
769  This function assumes that the given string contains a valid SQL-state.
770 
771  @param s the condition SQLSTATE.
772 
773  @retval true if the given string defines COMPLETION condition.
774  @retval false otherwise.
775 */
776 inline bool is_sqlstate_completion(const char *s) {
777  return s[0] == '0' && s[1] == '0';
778 }
779 
780 /**
781  Checks if the specified SQL-state-string defines WARNING condition.
782  This function assumes that the given string contains a valid SQL-state.
783 
784  @param s the condition SQLSTATE.
785 
786  @retval true if the given string defines WARNING condition.
787  @retval false otherwise.
788 */
789 inline bool is_sqlstate_warning(const char *s) {
790  return s[0] == '0' && s[1] == '1';
791 }
792 
793 /**
794  Checks if the specified SQL-state-string defines NOT FOUND condition.
795  This function assumes that the given string contains a valid SQL-state.
796 
797  @param s the condition SQLSTATE.
798 
799  @retval true if the given string defines NOT FOUND condition.
800  @retval false otherwise.
801 */
802 inline bool is_sqlstate_not_found(const char *s) {
803  return s[0] == '0' && s[1] == '2';
804 }
805 
806 /**
807  Checks if the specified SQL-state-string defines EXCEPTION condition.
808  This function assumes that the given string contains a valid SQL-state.
809 
810  @param s the condition SQLSTATE.
811 
812  @retval true if the given string defines EXCEPTION condition.
813  @retval false otherwise.
814 */
815 inline bool is_sqlstate_exception(const char *s) {
816  return s[0] != '0' || s[1] > '2';
817 }
818 
820  const char *alias,
821  const char *option = nullptr);
823  const char *option = nullptr);
824 
825 #endif // SQL_ERROR_H
A condition information item.
Definition: sql_get_diagnostics.h:223
Stores status of the currently executed statement.
Definition: sql_error.h:265
void reserve_number_of_conditions(THD *thd, uint count)
Make sure there is room for the given number of conditions.
Definition: sql_error.cc:587
void set_error_status(THD *thd, uint mysql_errno)
Set ERROR status in the Diagnostics Area.
Definition: sql_error.cc:414
void inc_current_row_for_condition()
Increment the current row counter to point at the next row.
Definition: sql_error.h:449
Sql_condition * push_warning(THD *thd, uint mysql_errno, const char *returned_sqlstate, Sql_condition::enum_severity_level severity, const char *message_text)
Add a new SQL-condition to the current list and increment the respective counters.
Definition: sql_error.cc:594
bool is_ok() const
Definition: sql_error.h:366
ulong error_count(THD *thd) const
The number of errors, or number of rows returned by SHOW ERRORS, also the value of session variable @...
Definition: sql_error.cc:508
uint last_statement_cond_count() const
Definition: sql_error.h:397
bool is_sent() const
Definition: sql_error.h:298
ulong current_row_for_condition() const
Return the current counter value.
Definition: sql_error.h:444
void reset_condition_info(THD *thd)
Reset the current condition information stored in the Diagnostics Area.
Definition: sql_error.cc:481
ulong m_current_row_for_condition
Row counter, to print in errors and warnings.
Definition: sql_error.h:679
const Diagnostics_area * stacked_da() const
Returns the Diagnostics Area below the current diagnostics area on the stack.
Definition: sql_error.h:583
void set_eof_status(THD *thd)
Set EOF status.
Definition: sql_error.cc:393
const char * get_first_condition_message()
Definition: sql_error.cc:475
void disable_status()
Mark the Diagnostics Area as 'DISABLED'.
Definition: sql_error.h:348
void set_ok_status(ulonglong affected_rows, ulonglong last_insert_id, const char *message_text)
Set OK status – ends commands that do not return a result set, e.g.
Definition: sql_error.cc:372
const char * returned_sqlstate() const
Definition: sql_error.h:382
void set_is_sent(bool is_sent)
Definition: sql_error.h:300
bool m_is_sent
True if status information is sent to the client.
Definition: sql_error.h:599
enum_diagnostics_status m_status
Definition: sql_error.h:607
void mark_preexisting_sql_conditions()
Mark current SQL-conditions so that we can later know which SQL-conditions have been added.
Definition: sql_error.cc:550
Diagnostics_area(bool allow_unlimited_conditions)
Definition: sql_error.cc:331
bool is_error() const
Definition: sql_error.h:362
Sql_condition_list::Const_Iterator Sql_condition_iterator
Const iterator used to iterate through the condition list.
Definition: sql_error.h:276
uint m_mysql_errno
SQL error number.
Definition: sql_error.h:634
MEM_ROOT m_condition_root
A memory root to allocate conditions.
Definition: sql_error.h:590
~Diagnostics_area()
Definition: sql_error.cc:354
uint m_current_statement_cond_count
The number of conditions of the current statement.
Definition: sql_error.h:670
Diagnostics_area * m_stacked_da
Pointer to the Diagnostics Area below on the stack.
Definition: sql_error.h:587
ulong current_statement_cond_count() const
Return the number of conditions raised by the current statement.
Definition: sql_error.h:403
uint m_last_statement_cond_count
Number of conditions of this last statement.
Definition: sql_error.h:662
void reset_diagnostics_area()
Clear this Diagnostics Area.
Definition: sql_error.cc:356
enum_diagnostics_status
Definition: sql_error.h:278
@ DA_OK
Set whenever one calls my_ok().
Definition: sql_error.h:282
@ DA_EMPTY
The area is cleared at start of a statement.
Definition: sql_error.h:280
@ DA_ERROR
Set whenever one calls my_error() or my_message().
Definition: sql_error.h:286
@ DA_DISABLED
Set in case of a custom response, such as one from COM_STMT_PREPARE.
Definition: sql_error.h:288
@ DA_EOF
Set whenever one calls my_eof().
Definition: sql_error.h:284
void set_current_row_for_condition(ulong rowno)
Set the current row counter to point to the given row number.
Definition: sql_error.h:452
void copy_new_sql_conditions(THD *thd, const Diagnostics_area *src_da)
Copy SQL-conditions that have been added since mark_preexisting_sql_conditions() was called.
Definition: sql_error.cc:558
ulong m_saved_warn_count
Save @warning_count before pre-clearing the DA.
Definition: sql_error.h:685
void copy_non_errors_from_da(THD *thd, const Diagnostics_area *src_da)
Copy Sql_conditions that are not SL_ERROR from the source Diagnostics Area to the current Diagnostics...
Definition: sql_error.cc:537
void set_overwrite_status(bool can_overwrite_status)
Definition: sql_error.h:294
List< const Sql_condition > m_preexisting_sql_conditions
List of conditions present in DA at handler activation.
Definition: sql_error.h:596
Diagnostics_area * pop_diagnostics_area()
Pop "this" off the Diagnostics Area stack.
Definition: sql_error.cc:633
enum_diagnostics_status status() const
Definition: sql_error.h:370
bool is_disabled() const
Definition: sql_error.h:368
bool m_allow_unlimited_conditions
Indicates if push_warning() allows unlimited number of conditions.
Definition: sql_error.h:605
I_P_List< Sql_condition, I_P_List_adapter< Sql_condition, &Sql_condition::m_next_condition, &Sql_condition::m_prev_condition >, I_P_List_counter, I_P_List_fast_push_back< Sql_condition > > Sql_condition_list
The type of the counted and doubly linked list of conditions.
Definition: sql_error.h:272
uint mysql_errno() const
Definition: sql_error.h:377
Sql_condition_list m_conditions_list
List of conditions of all severities.
Definition: sql_error.h:593
ulonglong last_insert_id() const
Definition: sql_error.h:392
Sql_condition * error_condition() const
Definition: sql_error.cc:574
uint m_current_statement_cond_count_by_qb[(uint) Sql_condition::SEVERITY_END]
A break down of the number of conditions per severity (level).
Definition: sql_error.h:673
void reset_statement_cond_count()
Reset between two COM_ commands.
Definition: sql_error.h:412
void copy_sql_conditions_from_da(THD *thd, const Diagnostics_area *src_da)
Copy all SQL-conditions from src_da to this DA.
Definition: sql_error.cc:526
uint cond_count() const
The number of conditions (errors, warnings and notes) in the list.
Definition: sql_error.h:474
ulonglong affected_rows() const
Definition: sql_error.h:387
void reset_current_row_for_condition()
Reset the current row counter.
Definition: sql_error.h:457
bool m_can_overwrite_status
Set to make set_error_status after set_{ok,eof}_status possible.
Definition: sql_error.h:602
char m_returned_sqlstate[SQLSTATE_LENGTH+1]
SQL RETURNED_SQLSTATE condition item.
Definition: sql_error.h:628
bool is_set() const
Definition: sql_error.h:360
Sql_condition_iterator sql_conditions() const
Definition: sql_error.h:476
ulong m_saved_error_count
Save @error_count before pre-clearing the DA.
Definition: sql_error.h:682
bool is_eof() const
Definition: sql_error.h:364
ulong warn_count(THD *thd) const
Used for @warning_count system variable, which prints the number of rows returned by SHOW WARNINGS.
Definition: sql_error.cc:514
void push_diagnostics_area(THD *thd, Diagnostics_area *da, bool copy_conditions)
Push the given Diagnostics Area on top of the stack.
Definition: sql_error.cc:622
char m_message_text[MYSQL_ERRMSG_SIZE]
Message buffer.
Definition: sql_error.h:622
ulonglong m_last_insert_id
Similarly to the previous member, this is a replacement of thd->first_successful_insert_id_in_prev_st...
Definition: sql_error.h:654
bool has_sql_condition(const char *message_text, size_t message_length) const
Checks if the condition list contains SQL-condition with the given message.
Definition: sql_error.cc:452
ulonglong m_affected_rows
The number of rows affected by the last statement.
Definition: sql_error.h:647
const char * message_text() const
Definition: sql_error.h:372
Definition: sql_error.h:221
ErrConvString(const char *str, size_t length)
Definition: sql_error.h:231
size_t length() const
Definition: sql_error.h:254
const char * ptr() const
Definition: sql_error.h:253
ErrConvString(const String *str)
Definition: sql_error.h:226
char err_buffer[MYSQL_ERRMSG_SIZE]
Definition: sql_error.h:222
ErrConvString(longlong nr)
Definition: sql_error.h:240
size_t buf_length
Definition: sql_error.h:223
ErrConvString(const char *str, size_t length, const CHARSET_INFO *cs)
Definition: sql_error.h:236
ErrConvString(longlong nr, bool unsigned_flag)
Definition: sql_error.h:244
Element counting policy class for I_P_List which provides basic element counting.
Definition: sql_plist.h:221
uint elements() const
Definition: sql_plist.h:232
An insertion policy class for I_P_List which can be used when fast push_back() operation is required.
Definition: sql_plist.h:259
Iterator for I_P_List.
Definition: sql_plist.h:167
Intrusive parameterized list.
Definition: sql_plist.h:74
Sql_cmd_common_signal represents the common properties of the SIGNAL and RESIGNAL statements.
Definition: sql_signal.h:87
Sql_cmd_resignal represents a RESIGNAL statement.
Definition: sql_signal.h:167
Sql_cmd_signal represents a SIGNAL statement.
Definition: sql_signal.h:147
Representation of a SQL condition.
Definition: sql_error.h:54
const char * returned_sqlstate() const
Get the RETURNED_SQLSTATE of this condition.
Definition: sql_error.h:77
String m_catalog_name
SQL CATALOG_NAME condition item.
Definition: sql_error.h:179
Sql_condition(MEM_ROOT *mem_root)
Constructor.
Definition: sql_error.cc:215
String m_cursor_name
SQL CURSOR_NAME condition item.
Definition: sql_error.h:191
String m_message_text
Message text, expressed in the character set implied by –language.
Definition: sql_error.h:194
void set_message_text(const char *message_text)
Set the condition message test.
Definition: sql_error.cc:276
size_t message_octet_length() const
Get the MESSAGE_OCTET_LENGTH of this condition.
Definition: sql_error.h:71
String m_schema_name
SQL SCHEMA_NAME condition item.
Definition: sql_error.h:182
String m_table_name
SQL TABLE_NAME condition item.
Definition: sql_error.h:185
String m_constraint_name
SQL CONSTRAINT_NAME condition item.
Definition: sql_error.h:176
const char * message_text() const
Get the MESSAGE_TEXT of this condition.
Definition: sql_error.h:65
void set_returned_sqlstate(const char *sqlstate)
Set the RETURNED_SQLSTATE of this condition.
Definition: sql_error.h:154
MEM_ROOT * m_mem_root
Memory root to use to hold condition item values.
Definition: sql_error.h:213
String m_class_origin
SQL CLASS_ORIGIN condition item.
Definition: sql_error.h:164
Sql_condition * m_next_condition
Pointers for participating in the list of conditions.
Definition: sql_error.h:209
String m_constraint_schema
SQL CONSTRAINT_SCHEMA condition item.
Definition: sql_error.h:173
uint mysql_errno() const
Get the MYSQL_ERRNO of this condition.
Definition: sql_error.h:83
void copy_opt_attributes(const Sql_condition *cond)
Copy optional condition items attributes.
Definition: sql_error.cc:262
enum_severity_level
Enumeration value describing the severity of the condition.
Definition: sql_error.h:59
@ SL_NOTE
Definition: sql_error.h:59
@ SL_ERROR
Definition: sql_error.h:59
@ SL_WARNING
Definition: sql_error.h:59
@ SEVERITY_END
Definition: sql_error.h:59
Sql_condition::enum_severity_level m_severity_level
Severity (error, warning, note) of this condition.
Definition: sql_error.h:206
String m_subclass_origin
SQL SUBCLASS_ORIGIN condition item.
Definition: sql_error.h:167
char m_returned_sqlstate[SQLSTATE_LENGTH+1]
SQL RETURNED_SQLSTATE condition item.
Definition: sql_error.h:203
void set_class_origins()
Set the CLASS_ORIGIN and SUBCLASS_ORIGIN of this condition.
Definition: sql_error.cc:287
Sql_condition::enum_severity_level severity() const
Get the severity level of this condition.
Definition: sql_error.h:89
~Sql_condition()=default
Destructor.
String m_constraint_catalog
SQL CONSTRAINT_CATALOG condition item.
Definition: sql_error.h:170
uint m_mysql_errno
MySQL extension, MYSQL_ERRNO condition item.
Definition: sql_error.h:197
String m_column_name
SQL COLUMN_NAME condition item.
Definition: sql_error.h:188
Sql_condition ** m_prev_condition
Definition: sql_error.h:210
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:165
const char * ptr() const
Definition: sql_string.h:247
size_t length() const
Definition: sql_string.h:239
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:821
my_decimal class limits 'decimal_t' type to what we need in MySQL.
Definition: my_decimal.h:92
Definition: sp_rcontext.h:76
static MEM_ROOT mem_root
Definition: client_plugin.cc:109
static const std::string dec("DECRYPTION")
A better implementation of the UNIX ctype(3) library.
MYSQL_PLUGIN_IMPORT CHARSET_INFO my_charset_latin1
Definition: ctype-latin1.cc:367
char * longlong10_to_str(int64_t val, char *dst, int radix)
Converts a 64-bit integer to its string representation in decimal notation.
Definition: int2str.cc:100
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
Header for compiler-dependent features.
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:55
long long int longlong
Definition: my_inttypes.h:54
static int count
Definition: myisam_ftdump.cc:42
Common definition between mysql server & client.
#define MYSQL_ERRMSG_SIZE
Max length of a error message.
Definition: mysql_com.h:850
#define SQLSTATE_LENGTH
Definition: mysql_com.h:74
const char * collation
Definition: audit_api_message_emit.cc:184
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1022
Definition: commit_order_queue.h:33
const LEX_CSTRING warning_level_names[]
Definition: sql_error.cc:717
size_t err_conv(char *buff, size_t to_length, const char *from, size_t from_length, const CHARSET_INFO *from_cs)
Convert value for dispatch to error message(see WL#751).
Definition: sql_error.cc:838
bool is_sqlstate_completion(const char *s)
Checks if the specified SQL-state-string defines COMPLETION condition.
Definition: sql_error.h:776
bool is_sqlstate_not_found(const char *s)
Checks if the specified SQL-state-string defines NOT FOUND condition.
Definition: sql_error.h:802
void push_deprecated_warn_no_replacement(THD *thd, const char *old_syntax)
Generates a warning that a feature is deprecated.
Definition: sql_error.cc:707
void warn_on_deprecated_collation(THD *thd, const CHARSET_INFO *collation, const char *option=nullptr)
Output warnings on deprecated character collations.
Definition: sql_error.cc:1006
void push_warning(THD *thd, Sql_condition::enum_severity_level severity, uint code, const char *message_text)
Push the warning to error list if there is still room in the list.
Definition: sql_error.cc:649
size_t convert_error_message(char *to, size_t to_length, const CHARSET_INFO *to_cs, const char *from, size_t from_length, const CHARSET_INFO *from_cs, uint *errors)
Convert string for dispatch to client(see WL#751).
Definition: sql_error.cc:895
bool is_sqlstate_exception(const char *s)
Checks if the specified SQL-state-string defines EXCEPTION condition.
Definition: sql_error.h:815
void push_warning_printf(THD *thd, Sql_condition::enum_severity_level severity, uint code, const char *format,...)
Push the warning to error list if there is still room in the list.
Definition: sql_error.cc:680
bool mysqld_show_warnings(THD *thd, ulong levels_to_show)
Send all notes, errors or warnings to the client in a result set.
Definition: sql_error.cc:732
void push_deprecated_warn(THD *thd, const char *old_syntax, const char *new_syntax)
Generates a warning that a feature is deprecated.
Definition: sql_error.cc:696
bool is_sqlstate_warning(const char *s)
Checks if the specified SQL-state-string defines WARNING condition.
Definition: sql_error.h:789
bool is_sqlstate_valid(const LEX_STRING *sqlstate)
Sanity check for SQLSTATEs.
Definition: sql_error.cc:961
void warn_on_deprecated_charset(THD *thd, const CHARSET_INFO *cs, const char *alias, const char *option=nullptr)
Output warnings on deprecated character sets.
Definition: sql_error.cc:981
Our own string classes, used pervasively throughout the executor.
Definition: m_ctype.h:354
Hook class which via its methods specifies which members of T should be used for participating in a i...
Definition: sql_plist.h:197
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:78
Definition: mysql_lex_string.h:39
Definition: mysql_lex_string.h:34
Definition: mysql_time.h:81
unsigned int uint
Definition: uca-dump.cc:29