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