MySQL 9.1.0
Source Code Documentation
Diagnostics_area Class Reference

Stores status of the currently executed statement. More...

#include <sql_error.h>

Public Types

enum  enum_diagnostics_status {
  DA_EMPTY = 0 , DA_OK , DA_EOF , DA_ERROR ,
  DA_DISABLED
}
 
typedef Sql_condition_list::Const_Iterator Sql_condition_iterator
 Const iterator used to iterate through the condition list. More...
 

Public Member Functions

 Diagnostics_area (bool allow_unlimited_conditions)
 
 ~Diagnostics_area ()
 
void set_overwrite_status (bool can_overwrite_status)
 
bool is_sent () const
 
void set_is_sent (bool is_sent)
 
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. More...
 
void set_eof_status (THD *thd)
 Set EOF status. More...
 
void set_error_status (THD *thd, uint mysql_errno)
 Set ERROR status in the Diagnostics Area. More...
 
void set_error_status (uint mysql_errno, const char *message_text, const char *returned_sqlstate)
 Set ERROR status in the Diagnostics Area. More...
 
void disable_status ()
 Mark the Diagnostics Area as 'DISABLED'. More...
 
void reset_diagnostics_area ()
 Clear this Diagnostics Area. More...
 
bool is_set () const
 
bool is_error () const
 
bool is_eof () const
 
bool is_ok () const
 
bool is_disabled () const
 
enum_diagnostics_status status () const
 
const char * message_text () const
 
uint message_text_length () const
 
uint mysql_errno () const
 
const char * returned_sqlstate () const
 
ulonglong affected_rows () const
 
ulonglong last_insert_id () const
 
uint last_statement_cond_count () const
 
ulong current_statement_cond_count () const
 Return the number of conditions raised by the current statement. More...
 
void reset_statement_cond_count ()
 Reset between two COM_ commands. More...
 
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. More...
 
bool has_sql_condition (uint sql_errno) const
 Checks if the condition list contains SQL-condition with the given error code. More...
 
void reset_condition_info (THD *thd)
 Reset the current condition information stored in the Diagnostics Area. More...
 
ulong current_row_for_condition () const
 Return the current counter value. More...
 
void inc_current_row_for_condition ()
 Increment the current row counter to point at the next row. More...
 
void set_current_row_for_condition (ulong rowno)
 Set the current row counter to point to the given row number. More...
 
void reset_current_row_for_condition ()
 Reset the current row counter. More...
 
ulong error_count (THD *thd) const
 The number of errors, or number of rows returned by SHOW ERRORS, also the value of session variable @error_count. More...
 
ulong warn_count (THD *thd) const
 Used for @warning_count system variable, which prints the number of rows returned by SHOW WARNINGS. More...
 
uint cond_count () const
 The number of conditions (errors, warnings and notes) in the list. More...
 
Sql_condition_iterator sql_conditions () const
 
const char * get_first_condition_message ()
 
void reserve_number_of_conditions (THD *thd, uint count)
 Make sure there is room for the given number of conditions. More...
 
Sql_conditionpush_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. More...
 
void mark_preexisting_sql_conditions ()
 Mark current SQL-conditions so that we can later know which SQL-conditions have been added. More...
 
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. More...
 
void copy_sql_conditions_from_da (THD *thd, const Diagnostics_area *src_da)
 Copy all SQL-conditions from src_da to this DA. More...
 
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 Area. More...
 
Sql_conditionerror_condition () const
 

Private Types

typedef 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. More...
 

Private Member Functions

Sql_conditionpush_warning (THD *thd, const Sql_condition *sql_condition)
 Add a new SQL-condition to the current list and increment the respective counters. More...
 
void push_diagnostics_area (THD *thd, Diagnostics_area *da, bool copy_conditions)
 Push the given Diagnostics Area on top of the stack. More...
 
Diagnostics_areapop_diagnostics_area ()
 Pop "this" off the Diagnostics Area stack. More...
 
const Diagnostics_areastacked_da () const
 Returns the Diagnostics Area below the current diagnostics area on the stack. More...
 

Private Attributes

Diagnostics_aream_stacked_da
 Pointer to the Diagnostics Area below on the stack. More...
 
MEM_ROOT m_condition_root {PSI_INSTRUMENT_ME, WARN_ALLOC_BLOCK_SIZE}
 A memory root to allocate conditions. More...
 
Sql_condition_list m_conditions_list
 List of conditions of all severities. More...
 
List< const Sql_conditionm_preexisting_sql_conditions
 List of conditions present in DA at handler activation. More...
 
bool m_is_sent
 True if status information is sent to the client. More...
 
bool m_can_overwrite_status
 Set to make set_error_status after set_{ok,eof}_status possible. More...
 
bool m_allow_unlimited_conditions
 Indicates if push_warning() allows unlimited number of conditions. More...
 
enum_diagnostics_status m_status
 
char m_message_text [MYSQL_ERRMSG_SIZE]
 Message buffer. More...
 
uint m_message_text_length
 Length, in bytes, of m_message_text. More...
 
char m_returned_sqlstate [SQLSTATE_LENGTH+1]
 SQL RETURNED_SQLSTATE condition item. More...
 
uint m_mysql_errno
 SQL error number. More...
 
ulonglong m_affected_rows
 The number of rows affected by the last statement. More...
 
ulonglong m_last_insert_id
 Similarly to the previous member, this is a replacement of thd->first_successful_insert_id_in_prev_stmt, which is used to implement LAST_INSERT_ID(). More...
 
uint m_last_statement_cond_count
 Number of conditions of this last statement. More...
 
uint m_current_statement_cond_count
 The number of conditions of the current statement. More...
 
uint m_current_statement_cond_count_by_qb [(uint) Sql_condition::SEVERITY_END]
 A break down of the number of conditions per severity (level). More...
 
ulong m_current_row_for_condition
 Row counter, to print in errors and warnings. More...
 
ulong m_saved_error_count
 Save @error_count before pre-clearing the DA. More...
 
ulong m_saved_warn_count
 Save @warning_count before pre-clearing the DA. More...
 

Friends

class THD
 

Detailed Description

Stores status of the currently executed statement.

Cleared at the beginning of the statement, and then can hold either OK, ERROR, or EOF status. Can not be assigned twice per statement.

Member Typedef Documentation

◆ Sql_condition_iterator

Const iterator used to iterate through the condition list.

◆ Sql_condition_list

Member Enumeration Documentation

◆ enum_diagnostics_status

Enumerator
DA_EMPTY 

The area is cleared at start of a statement.

DA_OK 

Set whenever one calls my_ok().

DA_EOF 

Set whenever one calls my_eof().

DA_ERROR 

Set whenever one calls my_error() or my_message().

DA_DISABLED 

Set in case of a custom response, such as one from COM_STMT_PREPARE.

Constructor & Destructor Documentation

◆ Diagnostics_area()

Diagnostics_area::Diagnostics_area ( bool  allow_unlimited_conditions)

◆ ~Diagnostics_area()

Diagnostics_area::~Diagnostics_area ( )

Member Function Documentation

◆ affected_rows()

ulonglong Diagnostics_area::affected_rows ( ) const
inline

◆ cond_count()

uint Diagnostics_area::cond_count ( ) const
inline

The number of conditions (errors, warnings and notes) in the list.

◆ copy_new_sql_conditions()

void Diagnostics_area::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.

Parameters
thdThread context.
src_daDiagnostics Area to copy from.

◆ copy_non_errors_from_da()

void Diagnostics_area::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 Area.

Parameters
thdThread context.
src_daDiagnostics Area to copy from.

◆ copy_sql_conditions_from_da()

void Diagnostics_area::copy_sql_conditions_from_da ( THD thd,
const Diagnostics_area src_da 
)

Copy all SQL-conditions from src_da to this DA.

Parameters
thdThread context.
src_daDiagnostics Area to copy from.

◆ current_row_for_condition()

ulong Diagnostics_area::current_row_for_condition ( ) const
inline

Return the current counter value.

◆ current_statement_cond_count()

ulong Diagnostics_area::current_statement_cond_count ( ) const
inline

Return the number of conditions raised by the current statement.

◆ disable_status()

void Diagnostics_area::disable_status ( )
inline

Mark the Diagnostics Area as 'DISABLED'.

This is used in rare cases when the COM_ command at hand sends a response in a custom format. One example is COM_STMT_PREPARE.

◆ error_condition()

Sql_condition * Diagnostics_area::error_condition ( ) const
Returns
SQL-condition, which corresponds to the error state in Diagnostics Area.

◆ error_count()

ulong Diagnostics_area::error_count ( THD thd) const

The number of errors, or number of rows returned by SHOW ERRORS, also the value of session variable @error_count.

◆ get_first_condition_message()

const char * Diagnostics_area::get_first_condition_message ( )

◆ has_sql_condition() [1/2]

bool Diagnostics_area::has_sql_condition ( const char *  message_text,
size_t  message_length 
) const

Checks if the condition list contains SQL-condition with the given message.

Parameters
message_textMessage text
message_lengthLength of message_text
Returns
true if the condition list contains an SQL-condition with the given message text.

◆ has_sql_condition() [2/2]

bool Diagnostics_area::has_sql_condition ( uint  sql_errno) const

Checks if the condition list contains SQL-condition with the given error code.

Parameters
sql_errnoError code
Returns
true if the condition list contains an SQL-condition with the given error code.

◆ inc_current_row_for_condition()

void Diagnostics_area::inc_current_row_for_condition ( )
inline

Increment the current row counter to point at the next row.

◆ is_disabled()

bool Diagnostics_area::is_disabled ( ) const
inline

◆ is_eof()

bool Diagnostics_area::is_eof ( ) const
inline

◆ is_error()

bool Diagnostics_area::is_error ( ) const
inline

◆ is_ok()

bool Diagnostics_area::is_ok ( ) const
inline

◆ is_sent()

bool Diagnostics_area::is_sent ( ) const
inline

◆ is_set()

bool Diagnostics_area::is_set ( ) const
inline

◆ last_insert_id()

ulonglong Diagnostics_area::last_insert_id ( ) const
inline

◆ last_statement_cond_count()

uint Diagnostics_area::last_statement_cond_count ( ) const
inline

◆ mark_preexisting_sql_conditions()

void Diagnostics_area::mark_preexisting_sql_conditions ( )

Mark current SQL-conditions so that we can later know which SQL-conditions have been added.

◆ message_text()

const char * Diagnostics_area::message_text ( ) const
inline

◆ message_text_length()

uint Diagnostics_area::message_text_length ( ) const
inline

◆ mysql_errno()

uint Diagnostics_area::mysql_errno ( ) const
inline

◆ pop_diagnostics_area()

Diagnostics_area * Diagnostics_area::pop_diagnostics_area ( )
private

Pop "this" off the Diagnostics Area stack.

Note
This function will not set THD::m_stmt_da. Use THD::pop_diagnostics_area() instead.
Returns
The new top of the Diagnostics Area stack.

◆ push_diagnostics_area()

void Diagnostics_area::push_diagnostics_area ( THD thd,
Diagnostics_area da,
bool  copy_conditions 
)
private

Push the given Diagnostics Area on top of the stack.

"This" will then become the stacked Diagnostics Area. Conditions present in the new stacked Diagnostics Area will be copied to the new top Diagnostics Area.

Note
This function will not set THD::m_stmt_da. Use THD::push_diagnostics_area() instead.
Parameters
thdThread context
daDiagnostics Area to be come the top of the Diagnostics Area stack.
copy_conditionsCopy the conditions from the new second Diagnostics Area to the new first Diagnostics Area, as per SQL standard.

◆ push_warning() [1/2]

Sql_condition * Diagnostics_area::push_warning ( THD thd,
const Sql_condition sql_condition 
)
private

Add a new SQL-condition to the current list and increment the respective counters.

Parameters
thdThread context.
sql_conditionSQL-condition to copy values from.
Returns
a pointer to the added SQL-condition.

◆ push_warning() [2/2]

Sql_condition * Diagnostics_area::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.

Parameters
thdThread context.
mysql_errnoSQL-condition error number.
returned_sqlstateSQL-condition state.
severitySQL-condition severity.
message_textSQL-condition message.
Returns
a pointer to the added SQL-condition.

◆ reserve_number_of_conditions()

void Diagnostics_area::reserve_number_of_conditions ( THD thd,
uint  count 
)

Make sure there is room for the given number of conditions.

◆ reset_condition_info()

void Diagnostics_area::reset_condition_info ( THD thd)

Reset the current condition information stored in the Diagnostics Area.

Clear all conditions, the number of conditions, reset current row counter to point to the first row.

◆ reset_current_row_for_condition()

void Diagnostics_area::reset_current_row_for_condition ( )
inline

Reset the current row counter.

Start counting from 1.

◆ reset_diagnostics_area()

void Diagnostics_area::reset_diagnostics_area ( )

Clear this Diagnostics Area.

Normally called at the end of a statement.

◆ reset_statement_cond_count()

void Diagnostics_area::reset_statement_cond_count ( )
inline

Reset between two COM_ commands.

Conditions are preserved between commands, but m_current_statement_cond_count indicates the number of conditions of this particular statement only.

◆ returned_sqlstate()

const char * Diagnostics_area::returned_sqlstate ( ) const
inline

◆ set_current_row_for_condition()

void Diagnostics_area::set_current_row_for_condition ( ulong  rowno)
inline

Set the current row counter to point to the given row number.

◆ set_eof_status()

void Diagnostics_area::set_eof_status ( THD thd)

Set EOF status.

Parameters
thdThread context.

◆ set_error_status() [1/2]

void Diagnostics_area::set_error_status ( THD thd,
uint  mysql_errno 
)

Set ERROR status in the Diagnostics Area.

This function should be used to report fatal errors (such as out-of-memory errors) when no further processing is possible.

Parameters
thdThread handle
mysql_errnoSQL-condition error number

◆ set_error_status() [2/2]

void Diagnostics_area::set_error_status ( uint  mysql_errno,
const char *  message_text,
const char *  returned_sqlstate 
)

Set ERROR status in the Diagnostics Area.

Parameters
mysql_errnoSQL-condition error number
message_textSQL-condition message
returned_sqlstateSQL-condition state

◆ set_is_sent()

void Diagnostics_area::set_is_sent ( bool  is_sent)
inline

◆ set_ok_status()

void Diagnostics_area::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.

INSERT/UPDATE/DELETE.

Parameters
affected_rowsThe number of rows affected by the last statement.
See also
Diagnostics_area::m_affected_rows.
Parameters
last_insert_idThe value to be returned by LAST_INSERT_ID().
See also
Diagnostics_area::m_last_insert_id.
Parameters
message_textThe OK-message text.

◆ set_overwrite_status()

void Diagnostics_area::set_overwrite_status ( bool  can_overwrite_status)
inline

◆ sql_conditions()

Sql_condition_iterator Diagnostics_area::sql_conditions ( ) const
inline

◆ stacked_da()

const Diagnostics_area * Diagnostics_area::stacked_da ( ) const
inlineprivate

Returns the Diagnostics Area below the current diagnostics area on the stack.

◆ status()

enum_diagnostics_status Diagnostics_area::status ( ) const
inline

◆ warn_count()

ulong Diagnostics_area::warn_count ( THD thd) const

Used for @warning_count system variable, which prints the number of rows returned by SHOW WARNINGS.

Friends And Related Function Documentation

◆ THD

friend class THD
friend

Member Data Documentation

◆ m_affected_rows

ulonglong Diagnostics_area::m_affected_rows
private

The number of rows affected by the last statement.

This is semantically close to thd->row_count_func, but has a different life cycle. thd->row_count_func stores the value returned by function ROW_COUNT() and is cleared only by statements that update its value, such as INSERT, UPDATE, DELETE and few others. This member is cleared at the beginning of the next statement.

We could possibly merge the two, but life cycle of thd->row_count_func can not be changed.

◆ m_allow_unlimited_conditions

bool Diagnostics_area::m_allow_unlimited_conditions
private

Indicates if push_warning() allows unlimited number of conditions.

◆ m_can_overwrite_status

bool Diagnostics_area::m_can_overwrite_status
private

Set to make set_error_status after set_{ok,eof}_status possible.

◆ m_condition_root

MEM_ROOT Diagnostics_area::m_condition_root {PSI_INSTRUMENT_ME, WARN_ALLOC_BLOCK_SIZE}
private

A memory root to allocate conditions.

◆ m_conditions_list

Sql_condition_list Diagnostics_area::m_conditions_list
private

List of conditions of all severities.

◆ m_current_row_for_condition

ulong Diagnostics_area::m_current_row_for_condition
private

Row counter, to print in errors and warnings.

Not increased in create_sort_index(); may differ from examined_row_count.

◆ m_current_statement_cond_count

uint Diagnostics_area::m_current_statement_cond_count
private

The number of conditions of the current statement.

m_conditions_list life cycle differs from statement life cycle – it may span multiple statements. In that case we get m_current_statement_cond_count 0, whereas m_conditions_list is not empty.

◆ m_current_statement_cond_count_by_qb

uint Diagnostics_area::m_current_statement_cond_count_by_qb[(uint) Sql_condition::SEVERITY_END]
private

A break down of the number of conditions per severity (level).

◆ m_is_sent

bool Diagnostics_area::m_is_sent
private

True if status information is sent to the client.

◆ m_last_insert_id

ulonglong Diagnostics_area::m_last_insert_id
private

Similarly to the previous member, this is a replacement of thd->first_successful_insert_id_in_prev_stmt, which is used to implement LAST_INSERT_ID().

◆ m_last_statement_cond_count

uint Diagnostics_area::m_last_statement_cond_count
private

Number of conditions of this last statement.

May differ from the number of conditions returned by SHOW WARNINGS e.g. in case the statement doesn't clear the conditions, and doesn't generate them.

◆ m_message_text

char Diagnostics_area::m_message_text[MYSQL_ERRMSG_SIZE]
private

Message buffer.

It is used only when DA is in OK or ERROR status. If DA status is ERROR, it's the MESSAGE_TEXT attribute of SQL-condition. If DA status is OK, it's the OK-message to be sent.

◆ m_message_text_length

uint Diagnostics_area::m_message_text_length
private

Length, in bytes, of m_message_text.

◆ m_mysql_errno

uint Diagnostics_area::m_mysql_errno
private

SQL error number.

One of ER_ codes from share/errmsg.txt. Set by set_error_status.

◆ m_preexisting_sql_conditions

List<const Sql_condition> Diagnostics_area::m_preexisting_sql_conditions
private

List of conditions present in DA at handler activation.

◆ m_returned_sqlstate

char Diagnostics_area::m_returned_sqlstate[SQLSTATE_LENGTH+1]
private

SQL RETURNED_SQLSTATE condition item.

This member is always NUL terminated.

◆ m_saved_error_count

ulong Diagnostics_area::m_saved_error_count
private

Save @error_count before pre-clearing the DA.

◆ m_saved_warn_count

ulong Diagnostics_area::m_saved_warn_count
private

Save @warning_count before pre-clearing the DA.

◆ m_stacked_da

Diagnostics_area* Diagnostics_area::m_stacked_da
private

Pointer to the Diagnostics Area below on the stack.

◆ m_status

enum_diagnostics_status Diagnostics_area::m_status
private

The documentation for this class was generated from the following files: