MCPcopy Create free account
hub / github.com/MariaDB/server / mysql_create_routine

Function mysql_create_routine

sql/sql_parse.cc:3102–3217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3100
3101
3102static int __attribute__ ((noinline))
3103mysql_create_routine(THD *thd, LEX *lex)
3104{
3105 DBUG_ASSERT(lex->sphead != 0);
3106 DBUG_ASSERT(lex->sphead->m_db.str); /* Must be initialized in the parser */
3107 DBUG_ASSERT(lower_case_table_names != 1 ||
3108 Lex_ident_fs(lex->sphead->m_db).is_in_lower_case());
3109
3110 if (Lex_ident_db::check_name_with_error(lex->sphead->m_db))
3111 return true;
3112
3113 if (check_access(thd, CREATE_PROC_ACL, lex->sphead->m_db.str,
3114 NULL, NULL, 0, 0))
3115 return true;
3116
3117 /* Checking the drop permissions if CREATE OR REPLACE is used */
3118 if (lex->create_info.or_replace())
3119 {
3120 if (check_routine_access(thd, ALTER_PROC_ACL, &lex->sphead->m_db,
3121 &lex->sphead->m_name,
3122 Sp_handler::handler(lex->sql_command), 0))
3123 return true;
3124 }
3125
3126 const Lex_ident_routine name= Lex_ident_routine(*lex->sphead->name());
3127#ifdef HAVE_DLOPEN
3128 if (lex->sphead->m_handler->type() == SP_TYPE_FUNCTION)
3129 {
3130 udf_func *udf= find_udf(name.str, name.length);
3131
3132 if (udf)
3133 {
3134 my_error(ER_UDF_EXISTS, MYF(0), name.str);
3135 return true;
3136 }
3137 }
3138#endif
3139
3140 if (sp_process_definer(thd))
3141 return true;
3142
3143 WSREP_TO_ISOLATION_BEGIN(WSREP_MYSQL_DB, NULL, NULL);
3144
3145 if (!lex->sphead->m_handler->sp_create_routine(thd, lex->sphead))
3146 {
3147#ifndef NO_EMBEDDED_ACCESS_CHECKS
3148 /* only add privileges if really neccessary */
3149
3150 Security_context security_context;
3151 bool restore_backup_context= false;
3152 Security_context *backup= NULL;
3153 LEX_USER *definer= thd->lex->definer;
3154 /*
3155 We're going to issue an implicit GRANT statement so we close all
3156 open tables. We have to keep metadata locks as this ensures that
3157 this statement is atomic against concurent FLUSH TABLES WITH READ
3158 LOCK. Deadlocks which can arise due to fact that this implicit
3159 statement takes metadata locks should be detected by a deadlock

Callers 1

sql_parse.ccFile · 0.85

Calls 15

Lex_ident_fsClass · 0.85
Lex_ident_routineClass · 0.85
find_udfFunction · 0.85
my_errorFunction · 0.85
sp_process_definerFunction · 0.85
trans_commit_stmtFunction · 0.85
close_thread_tablesFunction · 0.85
is_acl_userFunction · 0.85
sp_grant_privilegesFunction · 0.85
push_warningFunction · 0.85
is_in_lower_caseMethod · 0.80
or_replaceMethod · 0.80

Tested by

no test coverage detected