From 9372f6e526734bfcc1ad38b87cdccd5dfc404efd Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Tue, 1 Aug 2017 12:04:14 +0400 Subject: [PATCH] MDEV-13419 Cleanup for Sp_handler::show_create_sp --- sql/sp.cc | 43 ++++++++++++++++++++++--------------------- sql/sp.h | 6 ++++++ sql/wsrep_mysqld.cc | 15 ++++++++------- 3 files changed, 36 insertions(+), 28 deletions(-) diff --git a/sql/sp.cc b/sql/sp.cc index 8aefb8b3a34..87061315987 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -862,8 +862,6 @@ Sp_handler::db_load_routine(THD *thd, const Database_qualified_name *name, thd->lex= &newlex; newlex.current_select= NULL; - // Resetting REPLACE and EXIST flags in create_info, for show_create_sp() - newlex.create_info.DDL_options_st::init(); defstr.set_charset(creation_ctx->get_client_cs()); @@ -873,10 +871,10 @@ Sp_handler::db_load_routine(THD *thd, const Database_qualified_name *name, definition for SHOW CREATE PROCEDURE later. */ - if (!show_create_sp(thd, &defstr, - null_clex_str, name->m_name, - params, returns, body, - chistics, definer, sql_mode)) + if (show_create_sp(thd, &defstr, + null_clex_str, name->m_name, + params, returns, body, + chistics, definer, DDL_options(), sql_mode)) { ret= SP_INTERNAL_ERROR; goto end; @@ -1303,12 +1301,14 @@ log: String log_query; log_query.set_charset(system_charset_info); - if (!show_create_sp(thd, &log_query, - sp->m_explicit_name ? sp->m_db : null_clex_str, - sp->m_name, - sp->m_params, returns, sp->m_body, - sp->chistics(), thd->lex->definer[0], - saved_mode)) + if (show_create_sp(thd, &log_query, + sp->m_explicit_name ? sp->m_db : null_clex_str, + sp->m_name, + sp->m_params, returns, sp->m_body, + sp->chistics(), + thd->lex->definer[0], + thd->lex->create_info, + saved_mode)) { my_error(ER_OUT_OF_RESOURCES, MYF(0)); goto done; @@ -2176,7 +2176,7 @@ int Sp_handler::sp_cache_routine(THD *thd, Generates the CREATE... string from the table information. @return - Returns TRUE on success, FALSE on (alloc) failure. + Returns false on success, true on (alloc) failure. */ bool Sp_handler::show_create_sp(THD *thd, String *buf, @@ -2187,6 +2187,7 @@ Sp_handler::show_create_sp(THD *thd, String *buf, const LEX_CSTRING &body, const st_sp_chistics &chistics, const AUTHID &definer, + const DDL_options_st ddl_options, sql_mode_t sql_mode) const { sql_mode_t old_sql_mode= thd->variables.sql_mode; @@ -2195,16 +2196,16 @@ Sp_handler::show_create_sp(THD *thd, String *buf, params.length + returns.length + chistics.comment.length + 10 /* length of " DEFINER= "*/ + USER_HOST_BUFF_SIZE)) - return FALSE; + return true; thd->variables.sql_mode= sql_mode; buf->append(STRING_WITH_LEN("CREATE ")); - if (thd->lex->create_info.or_replace()) + if (ddl_options.or_replace()) buf->append(STRING_WITH_LEN("OR REPLACE ")); append_definer(thd, buf, &definer.user, &definer.host); buf->append(type_lex_cstring()); buf->append(STRING_WITH_LEN(" ")); - if (thd->lex->create_info.if_not_exists()) + if (ddl_options.if_not_exists()) buf->append(STRING_WITH_LEN("IF NOT EXISTS ")); if (db.length > 0) @@ -2252,7 +2253,7 @@ Sp_handler::show_create_sp(THD *thd, String *buf, } buf->append(body); thd->variables.sql_mode= old_sql_mode; - return TRUE; + return false; } @@ -2300,10 +2301,10 @@ Sp_handler::sp_load_for_information_schema(THD *thd, TABLE *proc_table, Stored_program_creation_ctx *creation_ctx= Stored_routine_creation_ctx::load_from_db(thd, &sp_name_obj, proc_table); defstr.set_charset(creation_ctx->get_client_cs()); - if (!show_create_sp(thd, &defstr, - sp_name_obj.m_db, sp_name_obj.m_name, - params, returns, empty_body_lex_cstring(), - Sp_chistics(), definer, sql_mode)) + if (show_create_sp(thd, &defstr, + sp_name_obj.m_db, sp_name_obj.m_name, + params, returns, empty_body_lex_cstring(), + Sp_chistics(), definer, DDL_options(), sql_mode)) return 0; thd->lex= &newlex; diff --git a/sql/sp.h b/sql/sp.h index 060596bda1f..94638299ca3 100644 --- a/sql/sp.h +++ b/sql/sp.h @@ -150,6 +150,11 @@ public: sql_mode_t sql_mode, bool *free_sp_head) const; + /* + Make a SHOW CREATE statement. + @retval true on error + @retval false on success + */ bool show_create_sp(THD *thd, String *buf, const LEX_CSTRING &db, const LEX_CSTRING &name, @@ -158,6 +163,7 @@ public: const LEX_CSTRING &body, const st_sp_chistics &chistics, const AUTHID &definer, + const DDL_options_st ddl_options, sql_mode_t sql_mode) const; }; diff --git a/sql/wsrep_mysqld.cc b/sql/wsrep_mysqld.cc index ba8312d302a..58342b0b97a 100644 --- a/sql/wsrep_mysqld.cc +++ b/sql/wsrep_mysqld.cc @@ -2246,13 +2246,14 @@ static int wsrep_create_sp(THD *thd, uchar** buf, size_t* buf_len) sp_returns_type(thd, retstr, sp); returns= retstr.lex_cstring(); } - - if (!sp->m_handler-> - show_create_sp(thd, &log_query, - sp->m_explicit_name ? sp->m_db : null_clex_str, - sp->m_name, sp->m_params, returns, - sp->m_body, sp->chistics(), thd->lex->definer[0], - saved_mode)) + if (sp->m_handler-> + show_create_sp(thd, &log_query, + sp->m_explicit_name ? sp->m_db : null_clex_str, + sp->m_name, sp->m_params, returns, + sp->m_body, sp->chistics(), + thd->lex->definer[0], + thd->lex->create_info, + saved_mode)) { WSREP_WARN("SP create string failed: schema: %s, query: %s", (thd->db ? thd->db : "(null)"), thd->query());