MySQL  8.0.27
Source Code Documentation
Show_create_error_handler Class Reference

An Internal_error_handler that suppresses errors regarding views' underlying tables that occur during privilege checking within SHOW CREATE VIEW commands. More...

Inheritance diagram for Show_create_error_handler:
Internal_error_handler

Public Member Functions

 Show_create_error_handler (THD *thd, TABLE_LIST *top_view)
 Creates a new Show_create_error_handler for the particular security context and view. More...
 
bool handle_condition (THD *thd, uint sql_errno, const char *, Sql_condition::enum_severity_level *, const char *msg) override
 Handle a sql condition. More...
 

Private Member Functions

const char * get_view_access_denied_message (THD *thd[[maybe_unused]])
 Lazy instantiation of 'view access denied' message. More...
 

Private Attributes

TABLE_LISTm_top_view
 
bool m_handling
 
Security_contextm_sctx
 
char m_view_access_denied_message [MYSQL_ERRMSG_SIZE]
 
const char * m_view_access_denied_message_ptr
 

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

An Internal_error_handler that suppresses errors regarding views' underlying tables that occur during privilege checking within SHOW CREATE VIEW commands.

This happens in the cases when

  • A view's underlying table (e.g. referenced in its SELECT list) does not exist or columns of underlying table are altered. There should not be an error as no attempt was made to access it per se.
  • Access is denied for some table, column, function or stored procedure such as mentioned above. This error gets raised automatically, since we can't untangle its access checking from that of the view itself.

Constructor & Destructor Documentation

◆ Show_create_error_handler()

Show_create_error_handler::Show_create_error_handler ( THD thd,
TABLE_LIST top_view 
)
inlineexplicit

Creates a new Show_create_error_handler for the particular security context and view.

Parameters
thdThread context, used for security context information if needed.
top_viewThe view. We do not verify at this point that top_view is in fact a view since, alas, these things do not stay constant.

Member Function Documentation

◆ get_view_access_denied_message()

const char* Show_create_error_handler::get_view_access_denied_message ( THD *thd]  [[maybe_unused])
inlineprivate

Lazy instantiation of 'view access denied' message.

The purpose of the Show_create_error_handler is to hide details of underlying tables for which we have no privileges behind ER_VIEW_INVALID messages. But this obviously does not apply if we lack privileges on the view itself. Unfortunately the information about for which table privilege checking failed is not available at this point. The only way for us to check is by reconstructing the actual error message and see if it's the same.

◆ handle_condition()

bool Show_create_error_handler::handle_condition ( THD thd,
uint  sql_errno,
const char *  sqlstate,
Sql_condition::enum_severity_level level,
const char *  msg 
)
inlineoverridevirtual

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().
Parameters
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.
Returns
true if the condition is handled

Implements Internal_error_handler.

Member Data Documentation

◆ m_handling

bool Show_create_error_handler::m_handling
private

◆ m_sctx

Security_context* Show_create_error_handler::m_sctx
private

◆ m_top_view

TABLE_LIST* Show_create_error_handler::m_top_view
private

◆ m_view_access_denied_message

char Show_create_error_handler::m_view_access_denied_message[MYSQL_ERRMSG_SIZE]
private

◆ m_view_access_denied_message_ptr

const char* Show_create_error_handler::m_view_access_denied_message_ptr
private

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