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