MySQL 9.1.0
Source Code Documentation
sql_error.cc File Reference
#include "sql/sql_error.h"
#include <float.h>
#include <stdarg.h>
#include <algorithm>
#include "decimal.h"
#include "m_string.h"
#include "my_dbug.h"
#include "my_inttypes.h"
#include "my_macros.h"
#include "my_sys.h"
#include "my_time.h"
#include "mysql/components/services/bits/psi_bits.h"
#include "mysql/components/services/log_builtins.h"
#include "mysql/components/services/log_shared.h"
#include "mysql/strings/dtoa.h"
#include "mysql/strings/m_ctype.h"
#include "mysql_time.h"
#include "mysqld_error.h"
#include "sql-common/my_decimal.h"
#include "sql/derror.h"
#include "sql/item.h"
#include "sql/protocol.h"
#include "sql/sql_class.h"
#include "sql/sql_const.h"
#include "sql/sql_lex.h"
#include "sql/system_variables.h"
#include "sql/thr_malloc.h"
#include "string_with_len.h"
#include "strmake.h"

Functions

static void copy_string (MEM_ROOT *mem_root, String *dst, const String *src)
 
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 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...
 
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...
 
static bool is_deprecated (const char *cs_name)
 
void warn_on_deprecated_charset (THD *thd, const CHARSET_INFO *cs, const char *alias, const char *option)
 Output warnings on deprecated character sets. More...
 
void warn_on_deprecated_collation (THD *thd, const CHARSET_INFO *collation, const char *option)
 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

static LEX_CSTRING sqlstate_origin []
 
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

◆ copy_string()

static void copy_string ( MEM_ROOT mem_root,
String dst,
const String src 
)
static

◆ 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_deprecated()

static bool is_deprecated ( const char *  cs_name)
static

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

◆ 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

◆ sqlstate_origin

LEX_CSTRING sqlstate_origin[]
static
Initial value:
= {{STRING_WITH_LEN("ISO 9075")},
{STRING_WITH_LEN("MySQL")}}
#define STRING_WITH_LEN(X)
Definition: string_with_len.h:29

◆ warning_level_names

const LEX_CSTRING warning_level_names[]
Initial value:
= {{STRING_WITH_LEN("Note")},
{STRING_WITH_LEN("Warning")},
{STRING_WITH_LEN("Error")},