MySQL 9.0.0
Source Code Documentation
sql_error.h File Reference
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include "lex_string.h"
#include "my_alloc.h"
#include "my_compiler.h"
#include "my_inttypes.h"
#include "mysql/strings/int2str.h"
#include "mysql/strings/m_ctype.h"
#include "mysql_com.h"
#include "sql/sql_list.h"
#include "sql/sql_plist.h"
#include "sql_string.h"

Go to the source code of this file.

Classes

class  Sql_condition
 Representation of a SQL condition. More...
 
class  ErrConvString
 
class  Diagnostics_area
 Stores status of the currently executed statement. More...
 

Functions

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). More...
 
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. More...
 
void push_warning (THD *thd, uint code)
 Convenience function for sending a warning with level SL_WARNING and no arguments to the message. More...
 
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. More...
 
void push_deprecated_warn (THD *thd, const char *old_syntax, const char *new_syntax)
 Generates a warning that a feature is deprecated. More...
 
void push_deprecated_warn_no_replacement (THD *thd, const char *old_syntax)
 Generates a warning that a feature is deprecated. More...
 
bool mysqld_show_warnings (THD *thd, ulong levels_to_show)
 Send all notes, errors or warnings to the client in a result set. More...
 
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). More...
 
bool is_sqlstate_valid (const LEX_STRING *sqlstate)
 Sanity check for SQLSTATEs. More...
 
bool is_sqlstate_completion (const char *s)
 Checks if the specified SQL-state-string defines COMPLETION condition. More...
 
bool is_sqlstate_warning (const char *s)
 Checks if the specified SQL-state-string defines WARNING condition. More...
 
bool is_sqlstate_not_found (const char *s)
 Checks if the specified SQL-state-string defines NOT FOUND condition. More...
 
bool is_sqlstate_exception (const char *s)
 Checks if the specified SQL-state-string defines EXCEPTION condition. More...
 
void warn_on_deprecated_charset (THD *thd, const CHARSET_INFO *cs, const char *alias, const char *option=nullptr)
 Output warnings on deprecated character sets. More...
 
void warn_on_deprecated_collation (THD *thd, const CHARSET_INFO *collation, const char *option=nullptr)
 Output warnings on deprecated character collations. More...
 
void check_deprecated_datetime_format (THD *thd, const CHARSET_INFO *cs, MYSQL_TIME_STATUS &status)
 Check if status contains a deprecation warning. More...
 

Variables

constexpr const size_t WARN_ALLOC_BLOCK_SIZE {2048}
 
const LEX_CSTRING warning_level_names []
 

Function Documentation

◆ check_deprecated_datetime_format()

void check_deprecated_datetime_format ( THD thd,
const CHARSET_INFO cs,
MYSQL_TIME_STATUS status 
)

Check if status contains a deprecation warning.

If it does, issue the warning and reset the status indication.

◆ convert_error_message()

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).

Parameters
tobuffer to convert
to_lengthbuffer length
to_cschraset to convert
fromstring from convert
from_lengthstring length
from_cscharset from convert
errorscount of errors during conversion
Return values
lengthof converted string

◆ err_conv()

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).

Parameters
buffbuffer for converted string, 0-terminated
to_lengthsize of the buffer
fromstring which should be converted
from_lengthstring length
from_cscharset from convert
Return values
numberof bytes written to "to"

◆ is_sqlstate_completion()

bool is_sqlstate_completion ( const char *  s)
inline

Checks if the specified SQL-state-string defines COMPLETION condition.

This function assumes that the given string contains a valid SQL-state.

Parameters
sthe condition SQLSTATE.
Return values
trueif the given string defines COMPLETION condition.
falseotherwise.

◆ is_sqlstate_exception()

bool is_sqlstate_exception ( const char *  s)
inline

Checks if the specified SQL-state-string defines EXCEPTION condition.

This function assumes that the given string contains a valid SQL-state.

Parameters
sthe condition SQLSTATE.
Return values
trueif the given string defines EXCEPTION condition.
falseotherwise.

◆ is_sqlstate_not_found()

bool is_sqlstate_not_found ( const char *  s)
inline

Checks if the specified SQL-state-string defines NOT FOUND condition.

This function assumes that the given string contains a valid SQL-state.

Parameters
sthe condition SQLSTATE.
Return values
trueif the given string defines NOT FOUND condition.
falseotherwise.

◆ is_sqlstate_valid()

bool is_sqlstate_valid ( const LEX_STRING sqlstate)

Sanity check for SQLSTATEs.

The function does not check if it's really an existing SQL-state (there are just too many), it just checks string length and looks for bad characters.

Parameters
sqlstatethe condition SQLSTATE.
Return values
trueif it's ok.
falseif it's bad.

◆ is_sqlstate_warning()

bool is_sqlstate_warning ( const char *  s)
inline

Checks if the specified SQL-state-string defines WARNING condition.

This function assumes that the given string contains a valid SQL-state.

Parameters
sthe condition SQLSTATE.
Return values
trueif the given string defines WARNING condition.
falseotherwise.

◆ mysqld_show_warnings()

bool mysqld_show_warnings ( THD thd,
ulong  levels_to_show 
)

Send all notes, errors or warnings to the client in a result set.

The function takes into account the current LIMIT.

Parameters
thdThread handler
levels_to_showBitmap for which levels to show
Returns
error status.

◆ push_deprecated_warn()

void push_deprecated_warn ( THD thd,
const char *  old_syntax,
const char *  new_syntax 
)
inline

Generates a warning that a feature is deprecated.

Using it as push_deprecated_warn(thd, "BAD", "'GOOD'"); Will result in a warning: "The syntax 'BAD' is deprecated and will be removed in a future release. Please use 'GOOD' instead"

If a function is deprecated, it should implement Item_func::is_deprecated() to return true to prevent the usage of the function in the generated column expression.

Parameters
thdThread context. If NULL, warning is written to the error log, otherwise the warning is sent to the client.
old_syntaxDeprecated syntax.
new_syntaxReplacement syntax.

◆ push_deprecated_warn_no_replacement()

void push_deprecated_warn_no_replacement ( THD thd,
const char *  old_syntax 
)
inline

Generates a warning that a feature is deprecated.

Using it as push_deprecated_warn_no_replacement(thd, "old"); Will result in a warning: "The syntax 'old' is deprecated and will be removed in a future release.

If a function is deprecated, it should implement Item_func::is_deprecated() to return true to prevent the usage of the function in the generated column expression.

Parameters
thdThread context. If NULL, warning is written to the error log, otherwise the warning is sent to the client.
old_syntaxDeprecated syntax.

◆ push_warning() [1/2]

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.

Parameters
thdThread handle
severitySeverity of warning (note, warning)
codeError number
message_textClear error message

◆ push_warning() [2/2]

void push_warning ( THD thd,
uint  code 
)

Convenience function for sending a warning with level SL_WARNING and no arguments to the message.

Parameters
thdThe session to send the warning to.
codeThe warning number.

◆ push_warning_printf()

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.

Parameters
thdThread handle
severitySeverity of warning (note, warning)
codeError number
formatError message printf format, or nullptr to go by the error code.

◆ warn_on_deprecated_charset()

void warn_on_deprecated_charset ( THD thd,
const CHARSET_INFO cs,
const char *  alias,
const char *  option 
)
inline

Output warnings on deprecated character sets.

Parameters
[in]thdThe connection handler.
[in]csThe character set to check for a deprecation.
[in]aliasThe name/alias of cs.
[in]optionCommand line/config file option name, otherwise NULL.

◆ warn_on_deprecated_collation()

void warn_on_deprecated_collation ( THD thd,
const CHARSET_INFO collation,
const char *  option 
)
inline

Output warnings on deprecated character collations.

Parameters
[in]thdThe connection handler.
[in]collationThe collation to check for a deprecation.
[in]optionCommand line/config file option name, otherwise NULL.

Variable Documentation

◆ WARN_ALLOC_BLOCK_SIZE

constexpr const size_t WARN_ALLOC_BLOCK_SIZE {2048}
constexpr

◆ warning_level_names

const LEX_CSTRING warning_level_names[]
extern