MySQL 9.7.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 /** Return the number of conditions raised by the current statement. */
419 }
420
421 /**
422 Reset between two COM_ commands. Conditions are preserved
423 between commands, but m_current_statement_cond_count indicates
424 the number of conditions of this particular statement only.
425 */
427
428 /**
429 Checks if the condition list contains SQL-condition with the given message.
430
431 @param message_text Message text
432 @param message_length Length of message_text
433
434 @return true if the condition list contains an SQL-condition with the given
435 message text.
436 */
437 bool has_sql_condition(const char *message_text, size_t message_length) const;
438
439 /**
440 Checks if the condition list contains SQL-condition with the given error
441 code.
442
443 @param sql_errno Error code
444
445 @return true if the condition list contains an SQL-condition with the given
446 error code.
447 */
448 bool has_sql_condition(uint sql_errno) const;
449
450 /**
451 Reset the current condition information stored in the Diagnostics Area.
452 Clear all conditions, the number of conditions, reset current row counter
453 to point to the first row.
454 */
455 void reset_condition_info(THD *thd);
456
457 /** Return the current counter value. */
460 }
461
462 /** Increment the current row counter to point at the next row. */
464
465 /** Set the current row counter to point to the given row number. */
468 }
469
470 /** Reset the current row counter. Start counting from 1. */
472
473 /**
474 The number of errors, or number of rows returned by SHOW ERRORS,
475 also the value of session variable @@error_count.
476 */
477 ulong error_count(THD *thd) const;
478
479 /**
480 Used for @@warning_count system variable, which prints
481 the number of rows returned by SHOW WARNINGS.
482 */
483 ulong warn_count(THD *thd) const;
484
485 /**
486 The number of conditions (errors, warnings and notes) in the list.
487 */
488 uint cond_count() const { return m_conditions_list.elements(); }
489
491
492 const char *get_first_condition_message();
493
494 /** Make sure there is room for the given number of conditions. */
495 void reserve_number_of_conditions(THD *thd, uint count);
496
497 /**
498 Add a new SQL-condition to the current list and increment the respective
499 counters.
500
501 @param thd Thread context.
502 @param mysql_errno SQL-condition error number.
503 @param returned_sqlstate SQL-condition state.
504 @param severity SQL-condition severity.
505 @param message_text SQL-condition message.
506
507 @return a pointer to the added SQL-condition.
508 */
510 const char *returned_sqlstate,
512 const char *message_text);
513
514 /**
515 Mark current SQL-conditions so that we can later know which
516 SQL-conditions have been added.
517 */
519
520 /**
521 Copy SQL-conditions that have been added since
522 mark_preexisting_sql_conditions() was called.
523
524 @param thd Thread context.
525 @param src_da Diagnostics Area to copy from.
526 */
527 void copy_new_sql_conditions(THD *thd, const Diagnostics_area *src_da);
528
529 /**
530 Copy all SQL-conditions from src_da to this DA.
531
532 @param thd Thread context.
533 @param src_da Diagnostics Area to copy from.
534 */
535 void copy_sql_conditions_from_da(THD *thd, const Diagnostics_area *src_da);
536
537 /**
538 Copy Sql_conditions that are not SL_ERROR from the source
539 Diagnostics Area to the current Diagnostics Area.
540
541 @param thd Thread context.
542 @param src_da Diagnostics Area to copy from.
543 */
544 void copy_non_errors_from_da(THD *thd, const Diagnostics_area *src_da);
545
546 /**
547 @return SQL-condition, which corresponds to the error state in
548 Diagnostics Area.
549 */
551
552 private:
553 /**
554 In debug mode, assert that the status is not set, as required before setting
555 the status; unless the new status is DA_ERROR and m_overwrite_flag is set.
556 In case the assertion is raised, print an error message that includes the
557 previous status, the new status, the previous ER_* symbol (if any), and the
558 new ER_* symbol (if any).
559
560 @param new_status The new status we attempt to set.
561 @param new_errno The new mysql_errno we attempt to set, or 0 if not given.
562 */
563 void assert_not_set(enum_diagnostics_status new_status, int new_errno = 0);
564
565 /**
566 Add a new SQL-condition to the current list and increment the respective
567 counters.
568
569 @param thd Thread context.
570 @param sql_condition SQL-condition to copy values from.
571
572 @return a pointer to the added SQL-condition.
573 */
574 Sql_condition *push_warning(THD *thd, const Sql_condition *sql_condition);
575
576 /**
577 Push the given Diagnostics Area on top of the stack.
578 "This" will then become the stacked Diagnostics Area.
579 Conditions present in the new stacked Diagnostics Area
580 will be copied to the new top Diagnostics Area.
581
582 @note This function will not set THD::m_stmt_da.
583 Use THD::push_diagnostics_area() instead.
584
585 @param thd Thread context
586 @param da Diagnostics Area to be come the top of
587 the Diagnostics Area stack.
588 @param copy_conditions
589 Copy the conditions from the new second Diagnostics Area
590 to the new first Diagnostics Area, as per SQL standard.
591 */
593 bool copy_conditions);
594
595 /**
596 Pop "this" off the Diagnostics Area stack.
597
598 @note This function will not set THD::m_stmt_da.
599 Use THD::pop_diagnostics_area() instead.
600
601 @returns The new top of the Diagnostics Area stack.
602 */
604
605 /**
606 Returns the Diagnostics Area below the current diagnostics
607 area on the stack.
608 */
609 const Diagnostics_area *stacked_da() const { return m_stacked_da; }
610
611 private:
612 /** Pointer to the Diagnostics Area below on the stack. */
614
615 /** A memory root to allocate conditions */
617
618 /** List of conditions of all severities. */
620
621 /** List of conditions present in DA at handler activation. */
623
624 /** True if status information is sent to the client. */
626
627 /** Set to make set_error_status after set_{ok,eof}_status possible. */
629
630 /** Indicates if push_warning() allows unlimited number of conditions. */
632
634
635 private:
636 /*
637 This section contains basic attributes of Sql_condition to store
638 information about error (SQL-condition of error severity) or OK-message.
639 The attributes are inlined here (instead of using Sql_condition) to be able
640 to store the information in case of out-of-memory error.
641 */
642
643 /**
644 Message buffer. It is used only when DA is in OK or ERROR status.
645 If DA status is ERROR, it's the MESSAGE_TEXT attribute of SQL-condition.
646 If DA status is OK, it's the OK-message to be sent.
647 */
649
650 /**
651 Length, in bytes, of m_message_text.
652 */
654
655 /**
656 SQL RETURNED_SQLSTATE condition item.
657 This member is always NUL terminated.
658 */
660
661 /**
662 SQL error number. One of ER_ codes from share/errmsg.txt.
663 Set by set_error_status.
664 */
666
667 /**
668 The number of rows affected by the last statement. This is
669 semantically close to thd->row_count_func, but has a different
670 life cycle. thd->row_count_func stores the value returned by
671 function ROW_COUNT() and is cleared only by statements that
672 update its value, such as INSERT, UPDATE, DELETE and few others.
673 This member is cleared at the beginning of the next statement.
674
675 We could possibly merge the two, but life cycle of thd->row_count_func
676 can not be changed.
677 */
679
680 /**
681 Similarly to the previous member, this is a replacement of
682 thd->first_successful_insert_id_in_prev_stmt, which is used
683 to implement LAST_INSERT_ID().
684 */
686
687 /**
688 Number of conditions of this last statement. May differ from
689 the number of conditions returned by SHOW WARNINGS e.g. in case
690 the statement doesn't clear the conditions, and doesn't generate
691 them.
692 */
694
695 /**
696 The number of conditions of the current statement. m_conditions_list
697 life cycle differs from statement life cycle -- it may span
698 multiple statements. In that case we get
699 m_current_statement_cond_count 0, whereas m_conditions_list is not empty.
700 */
702
703 /** A break down of the number of conditions per severity (level). */
705
706 /**
707 Row counter, to print in errors and warnings. Not increased in
708 create_sort_index(); may differ from examined_row_count.
709 */
711
712 /** Save @@error_count before pre-clearing the DA. */
714
715 /** Save @@warning_count before pre-clearing the DA. */
717
718 friend class THD;
719};
720
721///////////////////////////////////////////////////////////////////////////
722
724 uint code, const char *message_text);
725
726/**
727 Convenience function for sending a warning with level SL_WARNING and no
728 arguments to the message.
729
730 @param thd The session to send the warning to.
731 @param code The warning number.
732*/
733void push_warning(THD *thd, uint code);
734
735/*
736 Note that this MY_ATTRIBUTE check cannot detect number/type mismatch
737 since the format string is not known at compile time.
738 It can however detect if push_warning_printf() is used without any
739 printf arguments. In such cases, use push_warning() instead.
740*/
742 uint code, const char *format, ...)
743 MY_ATTRIBUTE((format(printf, 4, 5)));
744
745/*
746 @see push_warning_printf
747*/
748void push_warning_vprintf(THD *thd, Sql_condition::enum_severity_level severity,
749 uint code, const char *format, va_list args)
750 MY_ATTRIBUTE((format(printf, 4, 0)));
751
752/**
753 Generates a warning that a feature is deprecated.
754
755 Using it as
756 push_deprecated_warn(thd, "BAD", "'GOOD'");
757 Will result in a warning:
758 "The syntax 'BAD' is deprecated and will be removed in a
759 future release. Please use 'GOOD' instead"
760
761 If a function is deprecated, it should implement
762 Item_func::is_deprecated() to return true to prevent the
763 usage of the function in the generated column expression.
764
765 @param thd Thread context. If NULL, warning is written
766 to the error log, otherwise the warning is
767 sent to the client.
768 @param old_syntax Deprecated syntax.
769 @param new_syntax Replacement syntax.
770*/
771void push_deprecated_warn(THD *thd, const char *old_syntax,
772 const char *new_syntax);
773
774/**
775 Generates a warning that a feature is deprecated.
776
777 Using it as
778 push_deprecated_warn_no_replacement(thd, "old");
779 Will result in a warning:
780 "The syntax 'old' is deprecated and will be removed in a
781 future release.
782
783 If a function is deprecated, it should implement
784 Item_func::is_deprecated() to return true to prevent the
785 usage of the function in the generated column expression.
786
787 @param thd Thread context. If NULL, warning is written
788 to the error log, otherwise the warning is
789 sent to the client.
790 @param old_syntax Deprecated syntax.
791*/
792void push_deprecated_warn_no_replacement(THD *thd, const char *old_syntax);
793
794bool mysqld_show_warnings(THD *thd, ulong levels_to_show);
795
796size_t convert_error_message(char *to, size_t to_length,
797 const CHARSET_INFO *to_cs, const char *from,
798 size_t from_length, const CHARSET_INFO *from_cs,
799 uint *errors);
800
801extern const LEX_CSTRING warning_level_names[];
802
803bool is_sqlstate_valid(const LEX_STRING *sqlstate);
804
805/**
806 Checks if the specified SQL-state-string defines COMPLETION condition.
807 This function assumes that the given string contains a valid SQL-state.
808
809 @param s the condition SQLSTATE.
810
811 @retval true if the given string defines COMPLETION condition.
812 @retval false otherwise.
813*/
814inline bool is_sqlstate_completion(const char *s) {
815 return s[0] == '0' && s[1] == '0';
816}
817
818/**
819 Checks if the specified SQL-state-string defines WARNING condition.
820 This function assumes that the given string contains a valid SQL-state.
821
822 @param s the condition SQLSTATE.
823
824 @retval true if the given string defines WARNING condition.
825 @retval false otherwise.
826*/
827inline bool is_sqlstate_warning(const char *s) {
828 return s[0] == '0' && s[1] == '1';
829}
830
831/**
832 Checks if the specified SQL-state-string defines NOT FOUND condition.
833 This function assumes that the given string contains a valid SQL-state.
834
835 @param s the condition SQLSTATE.
836
837 @retval true if the given string defines NOT FOUND condition.
838 @retval false otherwise.
839*/
840inline bool is_sqlstate_not_found(const char *s) {
841 return s[0] == '0' && s[1] == '2';
842}
843
844/**
845 Checks if the specified SQL-state-string defines EXCEPTION condition.
846 This function assumes that the given string contains a valid SQL-state.
847
848 @param s the condition SQLSTATE.
849
850 @retval true if the given string defines EXCEPTION condition.
851 @retval false otherwise.
852*/
853inline bool is_sqlstate_exception(const char *s) {
854 return s[0] != '0' || s[1] > '2';
855}
856
858 const char *alias,
859 const char *option = nullptr);
861 const char *option = nullptr);
862
865#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:463
uint m_message_text_length
Length, in bytes, of m_message_text.
Definition: sql_error.h:653
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:458
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:710
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:625
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:633
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:665
MEM_ROOT m_condition_root
A memory root to allocate conditions.
Definition: sql_error.h:616
~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:701
Diagnostics_area * m_stacked_da
Pointer to the Diagnostics Area below on the stack.
Definition: sql_error.h:613
ulong current_statement_cond_count() const
Return the number of conditions raised by the current statement.
Definition: sql_error.h:417
uint m_last_statement_cond_count
Number of conditions of this last statement.
Definition: sql_error.h:693
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:466
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:716
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:622
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:631
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:619
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:704
void reset_statement_cond_count()
Reset between two COM_ commands.
Definition: sql_error.h:426
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:488
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:471
bool m_can_overwrite_status
Set to make set_error_status after set_{ok,eof}_status possible.
Definition: sql_error.h:628
char m_returned_sqlstate[SQLSTATE_LENGTH+1]
SQL RETURNED_SQLSTATE condition item.
Definition: sql_error.h:659
bool is_set() const
Definition: sql_error.h:369
Sql_condition_iterator sql_conditions() const
Definition: sql_error.h:490
ulong m_saved_error_count
Save @error_count before pre-clearing the DA.
Definition: sql_error.h:713
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:609
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:648
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:685
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:678
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: 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: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:814
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:840
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:853
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:827
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