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