MySQL  8.0.27
Source Code Documentation
anonymous_namespace{}::Parse_error_anonymizer Class Reference

Error handler that wraps parse error messages, removes details and silences warnings. More...

Inheritance diagram for anonymous_namespace{}::Parse_error_anonymizer:

Public Member Functions

 Parse_error_anonymizer (THD *thd, Item *arg)
bool handle_condition (THD *, uint, const char *, Sql_condition::enum_severity_level *level, const char *message) override
 Handle a sql condition. More...
 ~Parse_error_anonymizer () override

Private Attributes

bool is_handling = false
 This avoids infinte recursion through my_error(). More...

Additional Inherited Members

- Protected Member Functions inherited from Internal_error_handler
 Internal_error_handler ()
Internal_error_handlerprev_internal_handler () const
virtual ~Internal_error_handler ()=default

Detailed Description

Error handler that wraps parse error messages, removes details and silences warnings.

We don't want statement_digest() to raise warnings about deprecated syntax or semantic problems. This is likely not interesting to the caller. Therefore this handler issues a blanket silencing of all warnings.

The reason we want to anonymize parse errors is to avoid leaking information in error messages that may be unintentionally visible to users of an application. For instance an application may in error insert an expression instead of a string:

SELECT statement_digest( (SELECT * FROM( SELECT user() ) t) );

The parser would normally raise an error saying:

You have an error in your SQL syntax; /.../ near 'root@localhost'

thus leaking data from the user table. Therefore, the errors are in this not disclosed.

Constructor & Destructor Documentation

◆ Parse_error_anonymizer()

anonymous_namespace{}::Parse_error_anonymizer::Parse_error_anonymizer ( THD thd,
Item arg 

◆ ~Parse_error_anonymizer()

anonymous_namespace{}::Parse_error_anonymizer::~Parse_error_anonymizer ( )

Member Function Documentation

◆ handle_condition()

bool anonymous_namespace{}::Parse_error_anonymizer::handle_condition ( THD thd,
uint  sql_errno,
const char *  sqlstate,
Sql_condition::enum_severity_level level,
const char *  msg 

Handle a sql condition.

This method can be implemented by a subclass to achieve any of the following:

  • mask a warning/error internally, prevent exposing it to the user,
  • mask a warning/error and throw another one instead. When this method returns true, the sql condition is considered 'handled', and will not be propagated to upper layers. It is the responsibility of the code installing an internal handler to then check for trapped conditions, and implement logic to recover from the anticipated conditions trapped during runtime.

This mechanism is similar to C++ try/throw/catch:

  • 'try' correspond to THD::push_internal_handler(),
  • 'throw' correspond to my_error(), which invokes my_message_sql(),
  • 'catch' correspond to checking how/if an internal handler was invoked, before removing it from the exception stack with THD::pop_internal_handler().
thdthe calling thread
sql_errnothe error number for the condition raised.
sqlstatethe SQLSTATE for the condition raised.
levelthe severity level for the condition raised.
msgthe error message for the condition raised.
true if the condition is handled

Implements Internal_error_handler.

Member Data Documentation

◆ is_handling

bool anonymous_namespace{}::Parse_error_anonymizer::is_handling = false

This avoids infinte recursion through my_error().

◆ m_arg

Item* anonymous_namespace{}::Parse_error_anonymizer::m_arg

◆ m_thd

THD* anonymous_namespace{}::Parse_error_anonymizer::m_thd

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