21 #include "sql_string.h"
22 #include "sql_plist.h"
23 #include "mysql_com.h"
44 enum enum_warning_level
45 { WARN_LEVEL_NOTE, WARN_LEVEL_WARN, WARN_LEVEL_ERROR, WARN_LEVEL_END};
64 {
return m_returned_sqlstate; }
71 {
return m_sql_errno; }
140 void set(uint sql_errno,
const char* sqlstate,
141 Sql_condition::enum_warning_level
level,
149 void set_builtin_message_text(
const char* str);
152 void set_sqlstate(
const char* sqlstate);
155 void set_class_origins();
170 String m_constraint_catalog;
173 String m_constraint_schema;
203 char m_returned_sqlstate[SQLSTATE_LENGTH+1];
206 Sql_condition::enum_warning_level m_level;
226 &Sql_condition::next_in_wi,
227 &Sql_condition::prev_in_wi>,
239 uint m_warn_count[(uint) Sql_condition::WARN_LEVEL_END];
247 uint m_current_statement_warn_count;
253 ulong m_current_row_for_warning;
275 bool m_allow_unlimited_warnings;
287 Warning_info(ulonglong warn_id_arg,
bool allow_unlimited_warnings);
303 bool has_sql_condition(
const char *message_str, ulong message_length)
const;
312 void clear(ulonglong new_id);
326 void opt_clear(ulonglong query_id)
328 if (query_id != m_warn_id)
341 void append_warning_info(THD *thd,
const Warning_info *source);
348 void reset_for_next_command()
349 { m_current_statement_warn_count= 0; }
355 void mark_sql_conditions_for_removal();
361 void unmark_sql_conditions_from_removal()
362 { m_marked_sql_conditions.empty(); }
368 void remove_marked_sql_conditions();
387 { m_marked_sql_conditions.push_back(cond, &m_warn_root); }
393 ulong warn_count()
const
399 return (m_warn_count[(uint) Sql_condition::WARN_LEVEL_NOTE] +
400 m_warn_count[(uint) Sql_condition::WARN_LEVEL_ERROR] +
401 m_warn_count[(uint) Sql_condition::WARN_LEVEL_WARN]);
408 ulong error_count()
const
409 {
return m_warn_count[(uint) Sql_condition::WARN_LEVEL_ERROR]; }
414 uint cond_count()
const
416 return m_warn_list.elements();
420 ulonglong id()
const {
return m_warn_id; }
423 void id(ulonglong
id) { m_warn_id= id; }
426 bool is_empty()
const {
return m_warn_list.is_empty(); }
429 void inc_current_row_for_warning() { m_current_row_for_warning++; }
432 void reset_current_row_for_warning() { m_current_row_for_warning= 1; }
435 ulong current_row_for_warning()
const {
return m_current_row_for_warning; }
438 ulong current_statement_warn_count()
const
439 {
return m_current_statement_warn_count; }
442 void reserve_space(THD *thd, uint count);
458 const char* sqlstate,
459 Sql_condition::enum_warning_level
level,
484 void set_read_only(
bool read_only)
485 { m_read_only= read_only; }
491 bool is_read_only()
const
492 {
return m_read_only; }
501 {
return m_error_condition; }
508 void set_error_condition(
const Sql_condition *error_condition)
509 { m_error_condition= error_condition; }
517 void clear_error_condition()
518 { m_error_condition= NULL; }
526 uint err_conv(
char *buff,
size_t to_length,
const char *from,
531 char err_buffer[MYSQL_ERRMSG_SIZE];
536 buf_length= err_conv(err_buffer,
sizeof(err_buffer), str->ptr(),
537 str->length(), str->charset());
542 buf_length= err_conv(err_buffer,
sizeof(err_buffer), str, strlen(str), cs);
547 buf_length= err_conv(err_buffer,
sizeof(err_buffer), str, length,
553 buf_length= err_conv(err_buffer,
sizeof(err_buffer), str, length, cs);
558 buf_length= my_snprintf(err_buffer,
sizeof(err_buffer),
"%lld", nr);
563 buf_length= longlong10_to_str(nr, err_buffer, unsigned_flag ? 10 : -10) -
572 char *ptr() {
return err_buffer; }
573 size_t length()
const {
return buf_length; }
590 &Warning_info::m_next_in_da,
591 &Warning_info::m_prev_in_da>,
615 void set_overwrite_status(
bool can_overwrite_status)
616 { m_can_overwrite_status= can_overwrite_status; }
618 bool is_sent()
const {
return m_is_sent; }
620 void set_is_sent(
bool is_sent) { m_is_sent= is_sent; }
623 ulonglong last_insert_id,
632 const char *sqlstate,
639 bool is_set()
const {
return m_status !=
DA_EMPTY; }
641 bool is_error()
const {
return m_status ==
DA_ERROR; }
643 bool is_eof()
const {
return m_status ==
DA_EOF; }
645 bool is_ok()
const {
return m_status ==
DA_OK; }
647 bool is_disabled()
const {
return m_status ==
DA_DISABLED; }
652 { DBUG_ASSERT(m_status ==
DA_ERROR || m_status ==
DA_OK);
return m_message; }
654 uint sql_errno()
const
655 { DBUG_ASSERT(m_status ==
DA_ERROR);
return m_sql_errno; }
657 const char* get_sqlstate()
const
658 { DBUG_ASSERT(m_status ==
DA_ERROR);
return m_sqlstate; }
660 ulonglong affected_rows()
const
661 { DBUG_ASSERT(m_status ==
DA_OK);
return m_affected_rows; }
663 ulonglong last_insert_id()
const
664 { DBUG_ASSERT(m_status ==
DA_OK);
return m_last_insert_id; }
666 uint statement_warn_count()
const
668 DBUG_ASSERT(m_status ==
DA_OK || m_status ==
DA_EOF);
669 return m_statement_warn_count;
676 { m_wi_stack.push_front(wi); }
678 void pop_warning_info()
680 DBUG_ASSERT(m_wi_stack.elements() > 0);
681 m_wi_stack.remove(m_wi_stack.front());
684 void set_warning_info_id(ulonglong
id)
685 { get_warning_info()->id(
id); }
687 ulonglong warning_info_id()
const
688 {
return get_warning_info()->id(); }
701 {
return get_warning_info()->id() != wi->id(); }
703 bool is_warning_info_empty()
const
704 {
return get_warning_info()->is_empty(); }
706 ulong current_statement_warn_count()
const
707 {
return get_warning_info()->current_statement_warn_count(); }
709 bool has_sql_condition(
const char *message_str, ulong message_length)
const
710 {
return get_warning_info()->has_sql_condition(message_str, message_length); }
712 void reset_for_next_command()
713 { get_warning_info()->reset_for_next_command(); }
715 void clear_warning_info(ulonglong
id)
716 { get_warning_info()->clear(
id); }
718 void opt_clear_warning_info(ulonglong query_id)
719 { get_warning_info()->opt_clear(query_id); }
721 ulong current_row_for_warning()
const
722 {
return get_warning_info()->current_row_for_warning(); }
724 void inc_current_row_for_warning()
725 { get_warning_info()->inc_current_row_for_warning(); }
727 void reset_current_row_for_warning()
728 { get_warning_info()->reset_current_row_for_warning(); }
730 bool is_warning_info_read_only()
const
731 {
return get_warning_info()->is_read_only(); }
733 void set_warning_info_read_only(
bool read_only)
734 { get_warning_info()->set_read_only(read_only); }
736 ulong error_count()
const
737 {
return get_warning_info()->error_count(); }
739 ulong warn_count()
const
740 {
return get_warning_info()->warn_count(); }
742 uint cond_count()
const
743 {
return get_warning_info()->cond_count(); }
746 {
return get_warning_info()->m_warn_list; }
748 void reserve_space(THD *thd, uint count)
749 { get_warning_info()->reserve_space(thd, count); }
752 {
return get_warning_info()->push_warning(thd, sql_condition); }
756 const char* sqlstate,
757 Sql_condition::enum_warning_level
level,
760 return get_warning_info()->push_warning(thd,
761 sql_errno, sqlstate, level, msg);
764 void mark_sql_conditions_for_removal()
765 { get_warning_info()->mark_sql_conditions_for_removal(); }
767 void unmark_sql_conditions_from_removal()
768 { get_warning_info()->unmark_sql_conditions_from_removal(); }
770 void remove_marked_sql_conditions()
771 { get_warning_info()->remove_marked_sql_conditions(); }
774 {
return get_warning_info()->get_error_condition(); }
776 void copy_sql_conditions_to_wi(THD *thd,
Warning_info *dst_wi)
const
777 { dst_wi->append_warning_info(thd, get_warning_info()); }
779 void copy_sql_conditions_from_wi(THD *thd,
const Warning_info *src_wi)
780 { get_warning_info()->append_warning_info(thd, src_wi); }
785 Warning_info *get_warning_info() {
return m_wi_stack.front(); }
787 const Warning_info *get_warning_info()
const {
return m_wi_stack.front(); }
794 bool m_can_overwrite_status;
797 char m_message[MYSQL_ERRMSG_SIZE];
805 char m_sqlstate[SQLSTATE_LENGTH+1];
818 ulonglong m_affected_rows;
825 ulonglong m_last_insert_id;
833 uint m_statement_warn_count;
839 Warning_info_list m_wi_stack;
845 void push_warning(THD *thd, Sql_condition::enum_warning_level level,
846 uint
code,
const char *msg);
848 void push_warning_printf(THD *thd, Sql_condition::enum_warning_level level,
849 uint
code,
const char *format, ...);
851 bool mysqld_show_warnings(THD *thd, ulong levels_to_show);
853 uint32 convert_error_message(
char *
to, uint32 to_length,
855 const char *from, uint32 from_length,
858 extern const LEX_STRING warning_level_names[];
860 bool is_sqlstate_valid(
const LEX_STRING *sqlstate);
872 inline bool is_sqlstate_completion(
const char *s)
873 {
return s[0] ==
'0' && s[1] ==
'0'; }
885 inline bool is_sqlstate_warning(
const char *s)
886 {
return s[0] ==
'0' && s[1] ==
'1'; }
898 inline bool is_sqlstate_not_found(
const char *s)
899 {
return s[0] ==
'0' && s[1] ==
'2'; }
911 inline bool is_sqlstate_exception(
const char *s)
912 {
return s[0] !=
'0' || s[1] >
'2'; }
915 #endif // SQL_ERROR_H