MySQL 26.10.0
Source Code Documentation
sql_error.h
Go to the documentation of this file.
1/* Copyright (c) 2005, 2026, 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(const Time_val time, uint dec);
260 ErrConvString(const Date_val date);
261
262 const char *ptr() const { return err_buffer; }
263 size_t length() const { return buf_length; }
264};
265
266///////////////////////////////////////////////////////////////////////////
267
268/**
269 Stores status of the currently executed statement.
270 Cleared at the beginning of the statement, and then
271 can hold either OK, ERROR, or EOF status.
272 Can not be assigned twice per statement.
273*/
275 /** The type of the counted and doubly linked list of conditions. */
276 typedef I_P_List<
282
283 public:
284 /** Const iterator used to iterate through the condition list. */
286
288 /** The area is cleared at start of a statement. */
290 /** Set whenever one calls my_ok(). */
292 /** Set whenever one calls my_eof(). */
294 /** Set whenever one calls my_error() or my_message(). */
296 /** Set in case of a custom response, such as one from COM_STMT_PREPARE. */
298 };
299
300 Diagnostics_area(bool allow_unlimited_conditions);
302
303 void set_overwrite_status(bool can_overwrite_status) {
304 m_can_overwrite_status = can_overwrite_status;
305 }
306
307 bool is_sent() const { return m_is_sent; }
308
310
311 /**
312 Set OK status -- ends commands that do not return a
313 result set, e.g. INSERT/UPDATE/DELETE.
314
315 @param affected_rows The number of rows affected by the last statement.
316 @sa Diagnostics_area::m_affected_rows.
317 @param last_insert_id The value to be returned by LAST_INSERT_ID().
318 @sa Diagnostics_area::m_last_insert_id.
319 @param message_text The OK-message text.
320 */
322 const char *message_text);
323
324 /**
325 Set EOF status.
326
327 @param thd Thread context.
328 */
329 void set_eof_status(THD *thd);
330
331 /**
332 Set ERROR status in the Diagnostics Area. This function should be used to
333 report fatal errors (such as out-of-memory errors) when no further
334 processing is possible.
335
336 @param thd Thread handle
337 @param mysql_errno SQL-condition error number
338 */
339 void set_error_status(THD *thd, uint mysql_errno);
340
341 /**
342 Set ERROR status in the Diagnostics Area.
343
344 @param mysql_errno SQL-condition error number
345 @param message_text SQL-condition message
346 @param returned_sqlstate SQL-condition state
347 */
348 void set_error_status(uint mysql_errno, const char *message_text,
349 const char *returned_sqlstate);
350
351 /**
352 Mark the Diagnostics Area as 'DISABLED'.
353
354 This is used in rare cases when the COM_ command at hand sends a response
355 in a custom format. One example is COM_STMT_PREPARE.
356 */
358 assert(m_status == DA_EMPTY);
360 }
361
362 /**
363 Clear this Diagnostics Area.
364
365 Normally called at the end of a statement.
366 */
368
369 bool is_set() const { return m_status != DA_EMPTY; }
370
371 bool is_error() const { return m_status == DA_ERROR; }
372
373 bool is_eof() const { return m_status == DA_EOF; }
374
375 bool is_ok() const { return m_status == DA_OK; }
376
377 bool is_disabled() const { return m_status == DA_DISABLED; }
378
380
381 const char *message_text() const {
382 assert(m_status == DA_ERROR || m_status == DA_OK);
383 return m_message_text;
384 }
385
386 uint message_text_length() const {
387 assert(m_status == DA_ERROR || m_status == DA_OK);
389 }
390
391 uint mysql_errno() const {
392 assert(m_status == DA_ERROR);
393 return m_mysql_errno;
394 }
395
396 const char *returned_sqlstate() const {
397 assert(m_status == DA_ERROR);
398 return m_returned_sqlstate;
399 }
400
402 assert(m_status == DA_OK);
403 return m_affected_rows;
404 }
405
407 assert(m_status == DA_OK);
408 return m_last_insert_id;
409 }
410
412 assert(m_status == DA_OK || m_status == DA_EOF);
414 }
415
416 /** Refresh the condition count stored in an already-set OK or EOF status. */
419 }
420
421 /** Return the number of conditions raised by the current statement. */
424 }
425
426 /**
427 Reset between two COM_ commands. Conditions are preserved
428 between commands, but m_current_statement_cond_count indicates
429 the number of conditions of this particular statement only.
430 */
432
433 /**
434 Checks if the condition list contains SQL-condition with the given message.
435
436 @param message_text Message text
437 @param message_length Length of message_text
438
439 @return true if the condition list contains an SQL-condition with the given
440 message text.
441 */
442 bool has_sql_condition(const char *message_text, size_t message_length) const;
443
444 /**
445 Checks if the condition list contains SQL-condition with the given error
446 code.
447
448 @param sql_errno Error code
449
450 @return true if the condition list contains an SQL-condition with the given
451 error code.
452 */
453 bool has_sql_condition(uint sql_errno) const;
454
455 /**
456 Reset the current condition information stored in the Diagnostics Area.
457 Clear all conditions, the number of conditions, reset current row counter
458 to point to the first row.
459 */
460 void reset_condition_info(THD *thd);
461
462 /** Return the current counter value. */
465 }
466
467 /** Increment the current row counter to point at the next row. */
469
470 /** Set the current row counter to point to the given row number. */
473 }
474
475 /** Reset the current row counter. Start counting from 1. */
477
478 /**
479 The number of errors, or number of rows returned by SHOW ERRORS,
480 also the value of session variable @@error_count.
481 */
482 ulong error_count(THD *thd) const;
483
484 /**
485 Used for @@warning_count system variable, which prints
486 the number of rows returned by SHOW WARNINGS.
487 */
488 ulong warn_count(THD *thd) const;
489
490 /**
491 The number of conditions (errors, warnings and notes) in the list.
492 */
493 uint cond_count() const { return m_conditions_list.elements(); }
494
496
497 const char *get_first_condition_message();
498
499 /** Make sure there is room for the given number of conditions. */
500 void reserve_number_of_conditions(THD *thd, uint count);
501
502 /**
503 Add a new SQL-condition to the current list and increment the respective
504 counters.
505
506 @param thd Thread context.
507 @param mysql_errno SQL-condition error number.
508 @param returned_sqlstate SQL-condition state.
509 @param severity SQL-condition severity.
510 @param message_text SQL-condition message.
511
512 @return a pointer to the added SQL-condition.
513 */
515 const char *returned_sqlstate,
517 const char *message_text);
518
519 /**
520 Mark current SQL-conditions so that we can later know which
521 SQL-conditions have been added.
522 */
524
525 /**
526 Copy SQL-conditions that have been added since
527 mark_preexisting_sql_conditions() was called.
528
529 @param thd Thread context.
530 @param src_da Diagnostics Area to copy from.
531 */
532 void copy_new_sql_conditions(THD *thd, const Diagnostics_area *src_da);
533
534 /**
535 Copy all SQL-conditions from src_da to this DA.
536
537 @param thd Thread context.
538 @param src_da Diagnostics Area to copy from.
539 */
540 void copy_sql_conditions_from_da(THD *thd, const Diagnostics_area *src_da);
541
542 /**
543 Copy Sql_conditions that are not SL_ERROR from the source
544 Diagnostics Area to the current Diagnostics Area.
545
546 @param thd Thread context.
547 @param src_da Diagnostics Area to copy from.
548 */
549 void copy_non_errors_from_da(THD *thd, const Diagnostics_area *src_da);
550
551 /**
552 @return SQL-condition, which corresponds to the error state in
553 Diagnostics Area.
554 */
556
557 private:
558 /**
559 In debug mode, assert that the status is not set, as required before setting
560 the status; unless the new status is DA_ERROR and m_overwrite_flag is set.
561 In case the assertion is raised, print an error message that includes the
562 previous status, the new status, the previous ER_* symbol (if any), and the
563 new ER_* symbol (if any).
564
565 @param new_status The new status we attempt to set.
566 @param new_errno The new mysql_errno we attempt to set, or 0 if not given.
567 */
568 void assert_not_set(enum_diagnostics_status new_status, int new_errno = 0);
569
570 /**
571 Add a new SQL-condition to the current list and increment the respective
572 counters.
573
574 @param thd Thread context.
575 @param sql_condition SQL-condition to copy values from.
576
577 @return a pointer to the added SQL-condition.
578 */
579 Sql_condition *push_warning(THD *thd, const Sql_condition *sql_condition);
580
581 /**
582 Push the given Diagnostics Area on top of the stack.
583 "This" will then become the stacked Diagnostics Area.
584 Conditions present in the new stacked Diagnostics Area
585 will be copied to the new top Diagnostics Area.
586
587 @note This function will not set THD::m_stmt_da.
588 Use THD::push_diagnostics_area() instead.
589
590 @param thd Thread context
591 @param da Diagnostics Area to be come the top of
592 the Diagnostics Area stack.
593 @param copy_conditions
594 Copy the conditions from the new second Diagnostics Area
595 to the new first Diagnostics Area, as per SQL standard.
596 */
598 bool copy_conditions);
599
600 /**
601 Pop "this" off the Diagnostics Area stack.
602
603 @note This function will not set THD::m_stmt_da.
604 Use THD::pop_diagnostics_area() instead.
605
606 @returns The new top of the Diagnostics Area stack.
607 */
609
610 /**
611 Returns the Diagnostics Area below the current diagnostics
612 area on the stack.
613 */
614 const Diagnostics_area *stacked_da() const { return m_stacked_da; }
615
616 private:
617 /** Pointer to the Diagnostics Area below on the stack. */
619
620 /** A memory root to allocate conditions */
622
623 /** List of conditions of all severities. */
625
626 /** List of conditions present in DA at handler activation. */
628
629 /** True if status information is sent to the client. */
631
632 /** Set to make set_error_status after set_{ok,eof}_status possible. */
634
635 /** Indicates if push_warning() allows unlimited number of conditions. */
637
639
640 private:
641 /*
642 This section contains basic attributes of Sql_condition to store
643 information about error (SQL-condition of error severity) or OK-message.
644 The attributes are inlined here (instead of using Sql_condition) to be able
645 to store the information in case of out-of-memory error.
646 */
647
648 /**
649 Message buffer. It is used only when DA is in OK or ERROR status.
650 If DA status is ERROR, it's the MESSAGE_TEXT attribute of SQL-condition.
651 If DA status is OK, it's the OK-message to be sent.
652 */
654
655 /**
656 Length, in bytes, of m_message_text.
657 */
659
660 /**
661 SQL RETURNED_SQLSTATE condition item.
662 This member is always NUL terminated.
663 */
665
666 /**
667 SQL error number. One of ER_ codes from share/errmsg.txt.
668 Set by set_error_status.
669 */
671
672 /**
673 The number of rows affected by the last statement. This is
674 semantically close to thd->row_count_func, but has a different
675 life cycle. thd->row_count_func stores the value returned by
676 function ROW_COUNT() and is cleared only by statements that
677 update its value, such as INSERT, UPDATE, DELETE and few others.
678 This member is cleared at the beginning of the next statement.
679
680 We could possibly merge the two, but life cycle of thd->row_count_func
681 can not be changed.
682 */
684
685 /**
686 Similarly to the previous member, this is a replacement of
687 thd->first_successful_insert_id_in_prev_stmt, which is used
688 to implement LAST_INSERT_ID().
689 */
691
692 /**
693 Number of conditions of this last statement. May differ from
694 the number of conditions returned by SHOW WARNINGS e.g. in case
695 the statement doesn't clear the conditions, and doesn't generate
696 them.
697 */
699
700 /**
701 The number of conditions of the current statement. m_conditions_list
702 life cycle differs from statement life cycle -- it may span
703 multiple statements. In that case we get
704 m_current_statement_cond_count 0, whereas m_conditions_list is not empty.
705 */
707
708 /** A break down of the number of conditions per severity (level). */
710
711 /**
712 Row counter, to print in errors and warnings. Not increased in
713 create_sort_index(); may differ from examined_row_count.
714 */
716
717 /** Save @@error_count before pre-clearing the DA. */
719
720 /** Save @@warning_count before pre-clearing the DA. */
722
723 friend class THD;
724};
725
726///////////////////////////////////////////////////////////////////////////
727
729 uint code, const char *message_text);
730
731/**
732 Convenience function for sending a warning with level SL_WARNING and no
733 arguments to the message.
734
735 @param thd The session to send the warning to.
736 @param code The warning number.
737*/
738void push_warning(THD *thd, uint code);
739
740/*
741 Note that this MY_ATTRIBUTE check cannot detect number/type mismatch
742 since the format string is not known at compile time.
743 It can however detect if push_warning_printf() is used without any
744 printf arguments. In such cases, use push_warning() instead.
745*/
747 uint code, const char *format, ...)
748 MY_ATTRIBUTE((format(printf, 4, 5)));
749
750/*
751 @see push_warning_printf
752*/
753void push_warning_vprintf(THD *thd, Sql_condition::enum_severity_level severity,
754 uint code, const char *format, va_list args)
755 MY_ATTRIBUTE((format(printf, 4, 0)));
756
757/**
758 Generates a warning that a feature is deprecated.
759
760 Using it as
761 push_deprecated_warn(thd, "BAD", "'GOOD'");
762 Will result in a warning:
763 "The syntax 'BAD' is deprecated and will be removed in a
764 future release. Please use 'GOOD' instead"
765
766 If a function is deprecated, it should implement
767 Item_func::is_deprecated() to return true to prevent the
768 usage of the function in the generated column expression.
769
770 @param thd Thread context. If NULL, warning is written
771 to the error log, otherwise the warning is
772 sent to the client.
773 @param old_syntax Deprecated syntax.
774 @param new_syntax Replacement syntax.
775*/
776void push_deprecated_warn(THD *thd, const char *old_syntax,
777 const char *new_syntax);
778
779/**
780 Generates a warning that a feature is deprecated.
781
782 Using it as
783 push_deprecated_warn_no_replacement(thd, "old");
784 Will result in a warning:
785 "The syntax 'old' is deprecated and will be removed in a
786 future release.
787
788 If a function is deprecated, it should implement
789 Item_func::is_deprecated() to return true to prevent the
790 usage of the function in the generated column expression.
791
792 @param thd Thread context. If NULL, warning is written
793 to the error log, otherwise the warning is
794 sent to the client.
795 @param old_syntax Deprecated syntax.
796*/
797void push_deprecated_warn_no_replacement(THD *thd, const char *old_syntax);
798
799bool mysqld_show_warnings(THD *thd, ulong levels_to_show);
800
801size_t convert_error_message(char *to, size_t to_length,
802 const CHARSET_INFO *to_cs, const char *from,
803 size_t from_length, const CHARSET_INFO *from_cs,
804 uint *errors);
805
806extern const LEX_CSTRING warning_level_names[];
807
808bool is_sqlstate_valid(const LEX_STRING *sqlstate);
809
810/**
811 Checks if the specified SQL-state-string defines COMPLETION condition.
812 This function assumes that the given string contains a valid SQL-state.
813
814 @param s the condition SQLSTATE.
815
816 @retval true if the given string defines COMPLETION condition.
817 @retval false otherwise.
818*/
819inline bool is_sqlstate_completion(const char *s) {
820 return s[0] == '0' && s[1] == '0';
821}
822
823/**
824 Checks if the specified SQL-state-string defines WARNING condition.
825 This function assumes that the given string contains a valid SQL-state.
826
827 @param s the condition SQLSTATE.
828
829 @retval true if the given string defines WARNING condition.
830 @retval false otherwise.
831*/
832inline bool is_sqlstate_warning(const char *s) {
833 return s[0] == '0' && s[1] == '1';
834}
835
836/**
837 Checks if the specified SQL-state-string defines NOT FOUND condition.
838 This function assumes that the given string contains a valid SQL-state.
839
840 @param s the condition SQLSTATE.
841
842 @retval true if the given string defines NOT FOUND condition.
843 @retval false otherwise.
844*/
845inline bool is_sqlstate_not_found(const char *s) {
846 return s[0] == '0' && s[1] == '2';
847}
848
849/**
850 Checks if the specified SQL-state-string defines EXCEPTION condition.
851 This function assumes that the given string contains a valid SQL-state.
852
853 @param s the condition SQLSTATE.
854
855 @retval true if the given string defines EXCEPTION condition.
856 @retval false otherwise.
857*/
858inline bool is_sqlstate_exception(const char *s) {
859 return s[0] != '0' || s[1] > '2';
860}
861
863 const char *alias,
864 const char *option = nullptr);
866 const char *option = nullptr);
867
870#endif // SQL_ERROR_H
A condition information item.
Definition: sql_get_diagnostics.h:224
Date_val is a temporal type that represents dates within the range 0000-01-01 and 9999-12-31.
Definition: my_temporal.h:421
Stores status of the currently executed statement.
Definition: sql_error.h:274
void reserve_number_of_conditions(THD *thd, uint count)
Make sure there is room for the given number of conditions.
Definition: sql_error.cc:642
void set_error_status(THD *thd, uint mysql_errno)
Set ERROR status in the Diagnostics Area.
Definition: sql_error.cc:473
void inc_current_row_for_condition()
Increment the current row counter to point at the next row.
Definition: sql_error.h:468
uint m_message_text_length
Length, in bytes, of m_message_text.
Definition: sql_error.h:658
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:649
bool is_ok() const
Definition: sql_error.h:375
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:563
uint last_statement_cond_count() const
Definition: sql_error.h:411
bool is_sent() const
Definition: sql_error.h:307
ulong current_row_for_condition() const
Return the current counter value.
Definition: sql_error.h:463
void refresh_last_statement_cond_count()
Refresh the condition count stored in an already-set OK or EOF status.
Definition: sql_error.h:417
void reset_condition_info(THD *thd)
Reset the current condition information stored in the Diagnostics Area.
Definition: sql_error.cc:536
ulong m_current_row_for_condition
Row counter, to print in errors and warnings.
Definition: sql_error.h:715
void set_eof_status(THD *thd)
Set EOF status.
Definition: sql_error.cc:452
const char * get_first_condition_message()
Definition: sql_error.cc:530
void disable_status()
Mark the Diagnostics Area as 'DISABLED'.
Definition: sql_error.h:357
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:427
void set_is_sent(bool is_sent)
Definition: sql_error.h:309
bool m_is_sent
True if status information is sent to the client.
Definition: sql_error.h:630
void assert_not_set(enum_diagnostics_status new_status, int new_errno=0)
In debug mode, assert that the status is not set, as required before setting the status; unless the n...
Definition: sql_error.cc:400
enum_diagnostics_status m_status
Definition: sql_error.h:638
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:605
Diagnostics_area(bool allow_unlimited_conditions)
Definition: sql_error.cc:338
bool is_error() const
Definition: sql_error.h:371
Sql_condition_list::Const_Iterator Sql_condition_iterator
Const iterator used to iterate through the condition list.
Definition: sql_error.h:285
uint m_mysql_errno
SQL error number.
Definition: sql_error.h:670
MEM_ROOT m_condition_root
A memory root to allocate conditions.
Definition: sql_error.h:621
~Diagnostics_area()
Definition: sql_error.cc:360
uint m_current_statement_cond_count
The number of conditions of the current statement.
Definition: sql_error.h:706
Diagnostics_area * m_stacked_da
Pointer to the Diagnostics Area below on the stack.
Definition: sql_error.h:618
ulong current_statement_cond_count() const
Return the number of conditions raised by the current statement.
Definition: sql_error.h:422
uint m_last_statement_cond_count
Number of conditions of this last statement.
Definition: sql_error.h:698
void reset_diagnostics_area()
Clear this Diagnostics Area.
Definition: sql_error.cc:362
enum_diagnostics_status
Definition: sql_error.h:287
@ DA_OK
Set whenever one calls my_ok().
Definition: sql_error.h:291
@ DA_EMPTY
The area is cleared at start of a statement.
Definition: sql_error.h:289
@ DA_ERROR
Set whenever one calls my_error() or my_message().
Definition: sql_error.h:295
@ DA_DISABLED
Set in case of a custom response, such as one from COM_STMT_PREPARE.
Definition: sql_error.h:297
@ DA_EOF
Set whenever one calls my_eof().
Definition: sql_error.h:293
void set_current_row_for_condition(ulong rowno)
Set the current row counter to point to the given row number.
Definition: sql_error.h:471
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:613
ulong m_saved_warn_count
Save @warning_count before pre-clearing the DA.
Definition: sql_error.h:721
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:592
void set_overwrite_status(bool can_overwrite_status)
Definition: sql_error.h:303
List< const Sql_condition > m_preexisting_sql_conditions
List of conditions present in DA at handler activation.
Definition: sql_error.h:627
Diagnostics_area * pop_diagnostics_area()
Pop "this" off the Diagnostics Area stack.
Definition: sql_error.cc:688
enum_diagnostics_status status() const
Definition: sql_error.h:379
bool is_disabled() const
Definition: sql_error.h:377
const char * message_text() const
Definition: sql_error.h:381
bool m_allow_unlimited_conditions
Indicates if push_warning() allows unlimited number of conditions.
Definition: sql_error.h:636
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:281
uint mysql_errno() const
Definition: sql_error.h:391
Sql_condition_list m_conditions_list
List of conditions of all severities.
Definition: sql_error.h:624
ulonglong last_insert_id() const
Definition: sql_error.h:406
Sql_condition * error_condition() const
Definition: sql_error.cc:629
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:709
void reset_statement_cond_count()
Reset between two COM_ commands.
Definition: sql_error.h:431
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:581
uint cond_count() const
The number of conditions (errors, warnings and notes) in the list.
Definition: sql_error.h:493
const char * returned_sqlstate() const
Definition: sql_error.h:396
ulonglong affected_rows() const
Definition: sql_error.h:401
void reset_current_row_for_condition()
Reset the current row counter.
Definition: sql_error.h:476
bool m_can_overwrite_status
Set to make set_error_status after set_{ok,eof}_status possible.
Definition: sql_error.h:633
char m_returned_sqlstate[SQLSTATE_LENGTH+1]
SQL RETURNED_SQLSTATE condition item.
Definition: sql_error.h:664
bool is_set() const
Definition: sql_error.h:369
Sql_condition_iterator sql_conditions() const
Definition: sql_error.h:495
ulong m_saved_error_count
Save @error_count before pre-clearing the DA.
Definition: sql_error.h:718
bool is_eof() const
Definition: sql_error.h:373
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:569
const Diagnostics_area * stacked_da() const
Returns the Diagnostics Area below the current diagnostics area on the stack.
Definition: sql_error.h:614
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:677
char m_message_text[MYSQL_ERRMSG_SIZE]
Message buffer.
Definition: sql_error.h:653
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:690
uint message_text_length() const
Definition: sql_error.h:386
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:507
ulonglong m_affected_rows
The number of rows affected by the last statement.
Definition: sql_error.h:683
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:263
ErrConvString(const String *str)
Definition: sql_error.h:233
const char * ptr() const
Definition: sql_error.h:262
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:222
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:283
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:269
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:294
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:57
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:1077
std::string format(const routing_guidelines::Session_info &session_info, bool extended_session_info)
Definition: dest_metadata_cache.cc:170
Definition: applier_version.h:27
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:800
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:930
void push_warning_vprintf(THD *thd, Sql_condition::enum_severity_level severity, uint code, const char *format, va_list args)
Push the warning to error list if there is still room in the list.
Definition: sql_error.cc:761
bool is_sqlstate_completion(const char *s)
Checks if the specified SQL-state-string defines COMPLETION condition.
Definition: sql_error.h:819
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:1149
bool is_sqlstate_not_found(const char *s)
Checks if the specified SQL-state-string defines NOT FOUND condition.
Definition: sql_error.h:845
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:704
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:987
bool is_sqlstate_exception(const char *s)
Checks if the specified SQL-state-string defines EXCEPTION condition.
Definition: sql_error.h:858
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:735
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:815
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:832
bool is_sqlstate_valid(const LEX_STRING *sqlstate)
Sanity check for SQLSTATEs.
Definition: sql_error.cc:1053
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(), int_to_datetime(),...
Definition: my_time.h:173
Definition: mysql_time.h:82