MySQL 9.6.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 In debug mode, assert that the status is not set, as required before setting
554 the status; unless the new status is DA_ERROR and m_overwrite_flag is set.
555 In case the assertion is raised, print an error message that includes the
556 previous status, the new status, the previous ER_* symbol (if any), and the
557 new ER_* symbol (if any).
558
559 @param new_status The new status we attempt to set.
560 @param new_errno The new mysql_errno we attempt to set, or 0 if not given.
561 */
562 void assert_not_set(enum_diagnostics_status new_status, int new_errno = 0);
563
564 /**
565 Add a new SQL-condition to the current list and increment the respective
566 counters.
567
568 @param thd Thread context.
569 @param sql_condition SQL-condition to copy values from.
570
571 @return a pointer to the added SQL-condition.
572 */
573 Sql_condition *push_warning(THD *thd, const Sql_condition *sql_condition);
574
575 /**
576 Push the given Diagnostics Area on top of the stack.
577 "This" will then become the stacked Diagnostics Area.
578 Conditions present in the new stacked Diagnostics Area
579 will be copied to the new top Diagnostics Area.
580
581 @note This function will not set THD::m_stmt_da.
582 Use THD::push_diagnostics_area() instead.
583
584 @param thd Thread context
585 @param da Diagnostics Area to be come the top of
586 the Diagnostics Area stack.
587 @param copy_conditions
588 Copy the conditions from the new second Diagnostics Area
589 to the new first Diagnostics Area, as per SQL standard.
590 */
592 bool copy_conditions);
593
594 /**
595 Pop "this" off the Diagnostics Area stack.
596
597 @note This function will not set THD::m_stmt_da.
598 Use THD::pop_diagnostics_area() instead.
599
600 @returns The new top of the Diagnostics Area stack.
601 */
603
604 /**
605 Returns the Diagnostics Area below the current diagnostics
606 area on the stack.
607 */
608 const Diagnostics_area *stacked_da() const { return m_stacked_da; }
609
610 private:
611 /** Pointer to the Diagnostics Area below on the stack. */
613
614 /** A memory root to allocate conditions */
616
617 /** List of conditions of all severities. */
619
620 /** List of conditions present in DA at handler activation. */
622
623 /** True if status information is sent to the client. */
625
626 /** Set to make set_error_status after set_{ok,eof}_status possible. */
628
629 /** Indicates if push_warning() allows unlimited number of conditions. */
631
633
634 private:
635 /*
636 This section contains basic attributes of Sql_condition to store
637 information about error (SQL-condition of error severity) or OK-message.
638 The attributes are inlined here (instead of using Sql_condition) to be able
639 to store the information in case of out-of-memory error.
640 */
641
642 /**
643 Message buffer. It is used only when DA is in OK or ERROR status.
644 If DA status is ERROR, it's the MESSAGE_TEXT attribute of SQL-condition.
645 If DA status is OK, it's the OK-message to be sent.
646 */
648
649 /**
650 Length, in bytes, of m_message_text.
651 */
653
654 /**
655 SQL RETURNED_SQLSTATE condition item.
656 This member is always NUL terminated.
657 */
659
660 /**
661 SQL error number. One of ER_ codes from share/errmsg.txt.
662 Set by set_error_status.
663 */
665
666 /**
667 The number of rows affected by the last statement. This is
668 semantically close to thd->row_count_func, but has a different
669 life cycle. thd->row_count_func stores the value returned by
670 function ROW_COUNT() and is cleared only by statements that
671 update its value, such as INSERT, UPDATE, DELETE and few others.
672 This member is cleared at the beginning of the next statement.
673
674 We could possibly merge the two, but life cycle of thd->row_count_func
675 can not be changed.
676 */
678
679 /**
680 Similarly to the previous member, this is a replacement of
681 thd->first_successful_insert_id_in_prev_stmt, which is used
682 to implement LAST_INSERT_ID().
683 */
685
686 /**
687 Number of conditions of this last statement. May differ from
688 the number of conditions returned by SHOW WARNINGS e.g. in case
689 the statement doesn't clear the conditions, and doesn't generate
690 them.
691 */
693
694 /**
695 The number of conditions of the current statement. m_conditions_list
696 life cycle differs from statement life cycle -- it may span
697 multiple statements. In that case we get
698 m_current_statement_cond_count 0, whereas m_conditions_list is not empty.
699 */
701
702 /** A break down of the number of conditions per severity (level). */
704
705 /**
706 Row counter, to print in errors and warnings. Not increased in
707 create_sort_index(); may differ from examined_row_count.
708 */
710
711 /** Save @@error_count before pre-clearing the DA. */
713
714 /** Save @@warning_count before pre-clearing the DA. */
716
717 friend class THD;
718};
719
720///////////////////////////////////////////////////////////////////////////
721
723 uint code, const char *message_text);
724
725/**
726 Convenience function for sending a warning with level SL_WARNING and no
727 arguments to the message.
728
729 @param thd The session to send the warning to.
730 @param code The warning number.
731*/
732void push_warning(THD *thd, uint code);
733
734/*
735 Note that this MY_ATTRIBUTE check cannot detect number/type mismatch
736 since the format string is not known at compile time.
737 It can however detect if push_warning_printf() is used without any
738 printf arguments. In such cases, use push_warning() instead.
739*/
741 uint code, const char *format, ...)
742 MY_ATTRIBUTE((format(printf, 4, 5)));
743
744/*
745 @see push_warning_printf
746*/
747void push_warning_vprintf(THD *thd, Sql_condition::enum_severity_level severity,
748 uint code, const char *format, va_list args)
749 MY_ATTRIBUTE((format(printf, 4, 0)));
750
751/**
752 Generates a warning that a feature is deprecated.
753
754 Using it as
755 push_deprecated_warn(thd, "BAD", "'GOOD'");
756 Will result in a warning:
757 "The syntax 'BAD' is deprecated and will be removed in a
758 future release. Please use 'GOOD' instead"
759
760 If a function is deprecated, it should implement
761 Item_func::is_deprecated() to return true to prevent the
762 usage of the function in the generated column expression.
763
764 @param thd Thread context. If NULL, warning is written
765 to the error log, otherwise the warning is
766 sent to the client.
767 @param old_syntax Deprecated syntax.
768 @param new_syntax Replacement syntax.
769*/
770void push_deprecated_warn(THD *thd, const char *old_syntax,
771 const char *new_syntax);
772
773/**
774 Generates a warning that a feature is deprecated.
775
776 Using it as
777 push_deprecated_warn_no_replacement(thd, "old");
778 Will result in a warning:
779 "The syntax 'old' is deprecated and will be removed in a
780 future release.
781
782 If a function is deprecated, it should implement
783 Item_func::is_deprecated() to return true to prevent the
784 usage of the function in the generated column expression.
785
786 @param thd Thread context. If NULL, warning is written
787 to the error log, otherwise the warning is
788 sent to the client.
789 @param old_syntax Deprecated syntax.
790*/
791void push_deprecated_warn_no_replacement(THD *thd, const char *old_syntax);
792
793bool mysqld_show_warnings(THD *thd, ulong levels_to_show);
794
795size_t convert_error_message(char *to, size_t to_length,
796 const CHARSET_INFO *to_cs, const char *from,
797 size_t from_length, const CHARSET_INFO *from_cs,
798 uint *errors);
799
800extern const LEX_CSTRING warning_level_names[];
801
802bool is_sqlstate_valid(const LEX_STRING *sqlstate);
803
804/**
805 Checks if the specified SQL-state-string defines COMPLETION condition.
806 This function assumes that the given string contains a valid SQL-state.
807
808 @param s the condition SQLSTATE.
809
810 @retval true if the given string defines COMPLETION condition.
811 @retval false otherwise.
812*/
813inline bool is_sqlstate_completion(const char *s) {
814 return s[0] == '0' && s[1] == '0';
815}
816
817/**
818 Checks if the specified SQL-state-string defines WARNING condition.
819 This function assumes that the given string contains a valid SQL-state.
820
821 @param s the condition SQLSTATE.
822
823 @retval true if the given string defines WARNING condition.
824 @retval false otherwise.
825*/
826inline bool is_sqlstate_warning(const char *s) {
827 return s[0] == '0' && s[1] == '1';
828}
829
830/**
831 Checks if the specified SQL-state-string defines NOT FOUND condition.
832 This function assumes that the given string contains a valid SQL-state.
833
834 @param s the condition SQLSTATE.
835
836 @retval true if the given string defines NOT FOUND condition.
837 @retval false otherwise.
838*/
839inline bool is_sqlstate_not_found(const char *s) {
840 return s[0] == '0' && s[1] == '2';
841}
842
843/**
844 Checks if the specified SQL-state-string defines EXCEPTION condition.
845 This function assumes that the given string contains a valid SQL-state.
846
847 @param s the condition SQLSTATE.
848
849 @retval true if the given string defines EXCEPTION condition.
850 @retval false otherwise.
851*/
852inline bool is_sqlstate_exception(const char *s) {
853 return s[0] != '0' || s[1] > '2';
854}
855
857 const char *alias,
858 const char *option = nullptr);
860 const char *option = nullptr);
861
864#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: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:462
uint m_message_text_length
Length, in bytes, of m_message_text.
Definition: sql_error.h:652
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: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:563
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:536
ulong m_current_row_for_condition
Row counter, to print in errors and warnings.
Definition: sql_error.h:709
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: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:427
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:624
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:632
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: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:664
MEM_ROOT m_condition_root
A memory root to allocate conditions.
Definition: sql_error.h:615
~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:700
Diagnostics_area * m_stacked_da
Pointer to the Diagnostics Area below on the stack.
Definition: sql_error.h:612
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:692
void reset_diagnostics_area()
Clear this Diagnostics Area.
Definition: sql_error.cc:362
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:613
ulong m_saved_warn_count
Save @warning_count before pre-clearing the DA.
Definition: sql_error.h:715
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:302
List< const Sql_condition > m_preexisting_sql_conditions
List of conditions present in DA at handler activation.
Definition: sql_error.h:621
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: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:630
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:618
ulonglong last_insert_id() const
Definition: sql_error.h:405
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:703
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:581
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:627
char m_returned_sqlstate[SQLSTATE_LENGTH+1]
SQL RETURNED_SQLSTATE condition item.
Definition: sql_error.h:658
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:712
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:569
const Diagnostics_area * stacked_da() const
Returns the Diagnostics Area below the current diagnostics area on the stack.
Definition: sql_error.h:608
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:647
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:684
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:507
ulonglong m_affected_rows
The number of rows affected by the last statement.
Definition: sql_error.h:677
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: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: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: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:926
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:813
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:1145
bool is_sqlstate_not_found(const char *s)
Checks if the specified SQL-state-string defines NOT FOUND condition.
Definition: sql_error.h:839
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:983
bool is_sqlstate_exception(const char *s)
Checks if the specified SQL-state-string defines EXCEPTION condition.
Definition: sql_error.h:852
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:826
bool is_sqlstate_valid(const LEX_STRING *sqlstate)
Sanity check for SQLSTATEs.
Definition: sql_error.cc:1049
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