The world's most popular open source database
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.
Defines | |
| #define | SP_OK 0 |
| #define | SP_KEY_NOT_FOUND -1 |
| #define | SP_OPEN_TABLE_FAILED -2 |
| #define | SP_WRITE_ROW_FAILED -3 |
| #define | SP_DELETE_ROW_FAILED -4 |
| #define | SP_GET_FIELD_FAILED -5 |
| #define | SP_PARSE_ERROR -6 |
| #define | SP_INTERNAL_ERROR -7 |
| #define | SP_NO_DB_ERROR -8 |
| #define | SP_BAD_IDENTIFIER -9 |
| #define | SP_BODY_TOO_LONG -10 |
Functions | |
| int | sp_drop_db_routines (THD *thd, char *db) |
| sp_head * | sp_find_routine (THD *thd, int type, sp_name *name, sp_cache **cp, bool cache_only) |
| int | sp_exist_routines (THD *thd, TABLE_LIST *procs, bool any, bool no_error) |
| int | sp_routine_exists_in_table (THD *thd, int type, sp_name *name) |
| int | sp_create_procedure (THD *thd, sp_head *sp) |
| int | sp_drop_procedure (THD *thd, sp_name *name) |
| int | sp_update_procedure (THD *thd, sp_name *name, st_sp_chistics *chistics) |
| int | sp_show_create_procedure (THD *thd, sp_name *name) |
| int | sp_show_status_procedure (THD *thd, const char *wild) |
| int | sp_create_function (THD *thd, sp_head *sp) |
| int | sp_drop_function (THD *thd, sp_name *name) |
| int | sp_update_function (THD *thd, sp_name *name, st_sp_chistics *chistics) |
| int | sp_show_create_function (THD *thd, sp_name *name) |
| int | sp_show_status_function (THD *thd, const char *wild) |
| void | sp_get_prelocking_info (THD *thd, bool *need_prelocking, bool *first_no_prelocking) |
| void | sp_add_used_routine (LEX *lex, Query_arena *arena, sp_name *rt, char rt_type) |
| void | sp_remove_not_own_routines (LEX *lex) |
| void | sp_update_sp_used_routines (HASH *dst, HASH *src) |
| int | sp_cache_routines_and_add_tables (THD *thd, LEX *lex, bool first_no_prelock) |
| int | sp_cache_routines_and_add_tables_for_view (THD *thd, LEX *lex, TABLE_LIST *view) |
| int | sp_cache_routines_and_add_tables_for_triggers (THD *thd, LEX *lex, TABLE_LIST *table) |
| byte * | sp_sroutine_key (const byte *ptr, uint *plen, my_bool first) |
| TABLE * | open_proc_table_for_read (THD *thd, Open_tables_state *backup) |
| void | close_proc_table (THD *thd, Open_tables_state *backup) |
| int | sp_use_new_db (THD *thd, LEX_STRING new_db, LEX_STRING *old_db, bool no_access_check, bool *dbchangedp) |
| #define SP_BAD_IDENTIFIER -9 |
| #define SP_BODY_TOO_LONG -10 |
| #define SP_DELETE_ROW_FAILED -4 |
| #define SP_GET_FIELD_FAILED -5 |
| #define SP_INTERNAL_ERROR -7 |
Definition at line 29 of file sp.h.
Referenced by db_create_routine(), db_load_routine(), db_show_routine_status(), mysql_execute_command(), and print_field_values().
| #define SP_KEY_NOT_FOUND -1 |
Definition at line 23 of file sp.h.
Referenced by db_find_routine_aux(), mysql_execute_command(), sp_cache_routines_and_add_tables_aux(), sp_drop_db_routines(), sp_routine_exists_in_table(), sp_show_create_function(), and sp_show_create_procedure().
| #define SP_NO_DB_ERROR -8 |
| #define SP_OK 0 |
Definition at line 22 of file sp.h.
Referenced by db_create_routine(), db_drop_routine(), db_find_routine(), db_find_routine_aux(), db_show_routine_status(), db_update_routine(), mysql_execute_command(), sp_cache_routines_and_add_tables_aux(), sp_drop_db_routines(), sp_find_routine(), and sp_routine_exists_in_table().
| #define SP_OPEN_TABLE_FAILED -2 |
Definition at line 24 of file sp.h.
Referenced by db_create_routine(), db_drop_routine(), db_find_routine(), db_show_routine_status(), db_update_routine(), sp_cache_routines_and_add_tables_aux(), sp_drop_db_routines(), and sp_routine_exists_in_table().
| #define SP_PARSE_ERROR -6 |
Definition at line 28 of file sp.h.
Referenced by db_load_routine(), and sp_cache_routines_and_add_tables_aux().
| #define SP_WRITE_ROW_FAILED -3 |
Definition at line 25 of file sp.h.
Referenced by db_create_routine(), db_update_routine(), and mysql_execute_command().
| void close_proc_table | ( | THD * | thd, | |
| Open_tables_state * | backup | |||
| ) |
Definition at line 85 of file sp.cc.
References close_thread_tables().
Referenced by db_find_routine(), fill_schema_proc(), open_proc_table_for_read(), and sp_routine_exists_in_table().
00086 { 00087 close_thread_tables(thd); 00088 thd->restore_backup_open_tables_state(backup); 00089 }
Here is the call graph for this function:

Here is the caller graph for this function:

| TABLE* open_proc_table_for_read | ( | THD * | thd, | |
| Open_tables_state * | backup | |||
| ) |
Definition at line 114 of file sp.cc.
References bzero, close_proc_table(), DBUG_ASSERT, DBUG_ENTER, DBUG_RETURN, st_reginfo::lock_type, mysql_lock_tables(), mysql_proc_table_exists, open_table(), st_table::reginfo, st_table::s, st_table_share::system_table, TL_READ, and st_table::use_all_columns().
Referenced by db_find_routine(), fill_schema_proc(), and sp_routine_exists_in_table().
00115 { 00116 TABLE_LIST tables; 00117 TABLE *table; 00118 bool not_used; 00119 DBUG_ENTER("open_proc_table"); 00120 00121 /* 00122 Speed up things if mysql.proc doesn't exists. mysql_proc_table_exists 00123 is set when we create or read stored procedure or on flush privileges. 00124 */ 00125 if (!mysql_proc_table_exists) 00126 DBUG_RETURN(0); 00127 00128 thd->reset_n_backup_open_tables_state(backup); 00129 00130 bzero((char*) &tables, sizeof(tables)); 00131 tables.db= (char*) "mysql"; 00132 tables.table_name= tables.alias= (char*)"proc"; 00133 if (!(table= open_table(thd, &tables, thd->mem_root, ¬_used, 00134 MYSQL_LOCK_IGNORE_FLUSH))) 00135 { 00136 thd->restore_backup_open_tables_state(backup); 00137 mysql_proc_table_exists= 0; 00138 DBUG_RETURN(0); 00139 } 00140 table->use_all_columns(); 00141 00142 DBUG_ASSERT(table->s->system_table); 00143 00144 table->reginfo.lock_type= TL_READ; 00145 /* 00146 We have to ensure we are not blocked by a flush tables, as this 00147 could lead to a deadlock if we have other tables opened. 00148 */ 00149 if (!(thd->lock= mysql_lock_tables(thd, &table, 1, 00150 MYSQL_LOCK_IGNORE_FLUSH, ¬_used))) 00151 { 00152 close_proc_table(thd, backup); 00153 DBUG_RETURN(0); 00154 } 00155 DBUG_RETURN(table); 00156 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void sp_add_used_routine | ( | LEX * | lex, | |
| Query_arena * | arena, | |||
| sp_name * | rt, | |||
| char | rt_type | |||
| ) |
Definition at line 1420 of file sp.cc.
References add_used_routine(), sp_name::m_sroutines_key, and sp_name::set_routine_type().
01422 { 01423 rt->set_routine_type(rt_type); 01424 (void)add_used_routine(lex, arena, &rt->m_sroutines_key, 0); 01425 lex->sroutines_list_own_last= lex->sroutines_list.next; 01426 lex->sroutines_list_own_elements= lex->sroutines_list.elements; 01427 }
Here is the call graph for this function:

| int sp_cache_routines_and_add_tables | ( | THD * | thd, | |
| LEX * | lex, | |||
| bool | first_no_prelock | |||
| ) |
Definition at line 1669 of file sp.cc.
References sp_cache_routines_and_add_tables_aux().
Referenced by open_tables().
01670 { 01671 return sp_cache_routines_and_add_tables_aux(thd, lex, 01672 (Sroutine_hash_entry *)lex->sroutines_list.first, 01673 first_no_prelock); 01674 }
Here is the call graph for this function:

Here is the caller graph for this function:

| int sp_cache_routines_and_add_tables_for_triggers | ( | THD * | thd, | |
| LEX * | lex, | |||
| TABLE_LIST * | table | |||
| ) |
Definition at line 1722 of file sp.cc.
References add_used_routine(), st_table_list::belong_to_view, Table_triggers_list::bodies, FALSE, int(), sp_cache_routines_and_add_tables_aux(), sp_update_stmt_used_routines(), Table_triggers_list::sroutines_key, st_table_list::table, TRG_ACTION_MAX, TRG_EVENT_MAX, and st_table::triggers.
01724 { 01725 int ret= 0; 01726 Table_triggers_list *triggers= table->table->triggers; 01727 if (add_used_routine(lex, thd->stmt_arena, &triggers->sroutines_key, 01728 table->belong_to_view)) 01729 { 01730 Sroutine_hash_entry **last_cached_routine_ptr= 01731 (Sroutine_hash_entry **)lex->sroutines_list.next; 01732 for (int i= 0; i < (int)TRG_EVENT_MAX; i++) 01733 { 01734 for (int j= 0; j < (int)TRG_ACTION_MAX; j++) 01735 { 01736 sp_head *trigger_body= triggers->bodies[i][j]; 01737 if (trigger_body) 01738 { 01739 (void)trigger_body-> 01740 add_used_tables_to_table_list(thd, &lex->query_tables_last, 01741 table->belong_to_view); 01742 sp_update_stmt_used_routines(thd, lex, 01743 &trigger_body->m_sroutines, 01744 table->belong_to_view); 01745 trigger_body->propagate_attributes(lex); 01746 } 01747 } 01748 } 01749 ret= sp_cache_routines_and_add_tables_aux(thd, lex, 01750 *last_cached_routine_ptr, FALSE); 01751 } 01752 return ret; 01753 }
Here is the call graph for this function:

| int sp_cache_routines_and_add_tables_for_view | ( | THD * | thd, | |
| LEX * | lex, | |||
| TABLE_LIST * | view | |||
| ) |
Definition at line 1694 of file sp.cc.
References FALSE, sp_cache_routines_and_add_tables_aux(), sp_update_stmt_used_routines(), st_table_list::top_table(), and st_table_list::view.
01695 { 01696 Sroutine_hash_entry **last_cached_routine_ptr= 01697 (Sroutine_hash_entry **)lex->sroutines_list.next; 01698 sp_update_stmt_used_routines(thd, lex, &view->view->sroutines_list, 01699 view->top_table()); 01700 return sp_cache_routines_and_add_tables_aux(thd, lex, 01701 *last_cached_routine_ptr, FALSE); 01702 }
Here is the call graph for this function:

| int sp_create_function | ( | THD * | thd, | |
| sp_head * | sp | |||
| ) |
Definition at line 1209 of file sp.cc.
References db_create_routine(), DBUG_ENTER, DBUG_PRINT, DBUG_RETURN, LEX_STRING::length, sp_head::m_name, LEX_STRING::str, and TYPE_ENUM_FUNCTION.
Referenced by sp_head::create().
01210 { 01211 int ret; 01212 DBUG_ENTER("sp_create_function"); 01213 DBUG_PRINT("enter", ("name: %.*s", sp->m_name.length, sp->m_name.str)); 01214 01215 ret= db_create_routine(thd, TYPE_ENUM_FUNCTION, sp); 01216 DBUG_RETURN(ret); 01217 }
Here is the call graph for this function:

Here is the caller graph for this function:

| int sp_create_procedure | ( | THD * | thd, | |
| sp_head * | sp | |||
| ) |
Definition at line 1138 of file sp.cc.
References db_create_routine(), DBUG_ENTER, DBUG_PRINT, DBUG_RETURN, LEX_STRING::length, sp_head::m_name, LEX_STRING::str, and TYPE_ENUM_PROCEDURE.
Referenced by sp_head::create().
01139 { 01140 int ret; 01141 DBUG_ENTER("sp_create_procedure"); 01142 DBUG_PRINT("enter", ("name: %.*s", sp->m_name.length, sp->m_name.str)); 01143 01144 ret= db_create_routine(thd, TYPE_ENUM_PROCEDURE, sp); 01145 DBUG_RETURN(ret); 01146 }
Here is the call graph for this function:

Here is the caller graph for this function:

| int sp_drop_db_routines | ( | THD * | thd, | |
| char * | db | |||
| ) |
Definition at line 895 of file sp.cc.
References close_thread_tables(), DBUG_ENTER, DBUG_PRINT, DBUG_RETURN, err, FALSE, st_table::field, st_table::file, handler::ha_delete_row(), HA_ERR_END_OF_FILE, handler::ha_index_end(), handler::ha_index_init(), HA_READ_KEY_EXACT, handler::index_next_same(), handler::index_read(), st_table::key_info, st_key::key_part, MYSQL_PROC_FIELD_DB, open_proc_table_for_update(), Field::ptr, st_table::record, sp_cache_invalidate(), SP_DELETE_ROW_FAILED, SP_KEY_NOT_FOUND, SP_OK, SP_OPEN_TABLE_FAILED, Field::store(), st_key_part_info::store_length, strlen(), system_charset_info, and TRUE.
Referenced by mysql_rm_db().
00896 { 00897 TABLE *table; 00898 int ret; 00899 uint key_len; 00900 DBUG_ENTER("sp_drop_db_routines"); 00901 DBUG_PRINT("enter", ("db: %s", db)); 00902 00903 ret= SP_OPEN_TABLE_FAILED; 00904 if (!(table= open_proc_table_for_update(thd))) 00905 goto err; 00906 00907 table->field[MYSQL_PROC_FIELD_DB]->store(db, strlen(db), system_charset_info); 00908 key_len= table->key_info->key_part[0].store_length; 00909 00910 ret= SP_OK; 00911 table->file->ha_index_init(0, 1); 00912 if (! table->file->index_read(table->record[0], 00913 (byte *)table->field[MYSQL_PROC_FIELD_DB]->ptr, 00914 key_len, HA_READ_KEY_EXACT)) 00915 { 00916 int nxtres; 00917 bool deleted= FALSE; 00918 00919 do 00920 { 00921 if (! table->file->ha_delete_row(table->record[0])) 00922 deleted= TRUE; /* We deleted something */ 00923 else 00924 { 00925 ret= SP_DELETE_ROW_FAILED; 00926 nxtres= 0; 00927 break; 00928 } 00929 } while (! (nxtres= table->file->index_next_same(table->record[0], 00930 (byte *)table->field[MYSQL_PROC_FIELD_DB]->ptr, 00931 key_len))); 00932 if (nxtres != HA_ERR_END_OF_FILE) 00933 ret= SP_KEY_NOT_FOUND; 00934 if (deleted) 00935 sp_cache_invalidate(); 00936 } 00937 table->file->ha_index_end(); 00938 00939 close_thread_tables(thd); 00940 00941 err: 00942 DBUG_RETURN(ret); 00943 }
Here is the call graph for this function:

Here is the caller graph for this function:

| int sp_drop_function | ( | THD * | thd, | |
| sp_name * | name | |||
| ) |
Definition at line 1221 of file sp.cc.
References db_drop_routine(), DBUG_ENTER, DBUG_PRINT, DBUG_RETURN, name, sp_cache_invalidate(), and TYPE_ENUM_FUNCTION.
Referenced by mysql_execute_command().
01222 { 01223 int ret; 01224 DBUG_ENTER("sp_drop_function"); 01225 DBUG_PRINT("enter", ("name: %.*s", name->m_name.length, name->m_name.str)); 01226 01227 ret= db_drop_routine(thd, TYPE_ENUM_FUNCTION, name); 01228 if (!ret) 01229 sp_cache_invalidate(); 01230 DBUG_RETURN(ret); 01231 }
Here is the call graph for this function:

Here is the caller graph for this function:

| int sp_drop_procedure | ( | THD * | thd, | |
| sp_name * | name | |||
| ) |
Definition at line 1150 of file sp.cc.
References db_drop_routine(), DBUG_ENTER, DBUG_PRINT, DBUG_RETURN, name, sp_cache_invalidate(), and TYPE_ENUM_PROCEDURE.
Referenced by mysql_execute_command().
01151 { 01152 int ret; 01153 DBUG_ENTER("sp_drop_procedure"); 01154 DBUG_PRINT("enter", ("name: %.*s", name->m_name.length, name->m_name.str)); 01155 01156 ret= db_drop_routine(thd, TYPE_ENUM_PROCEDURE, name); 01157 if (!ret) 01158 sp_cache_invalidate(); 01159 DBUG_RETURN(ret); 01160 }
Here is the call graph for this function:

Here is the caller graph for this function:

| int sp_exist_routines | ( | THD * | thd, | |
| TABLE_LIST * | procs, | |||
| bool | any, | |||
| bool | no_error | |||
| ) |
Definition at line 1061 of file sp.cc.
References st_table_list::db, DBUG_ENTER, DBUG_RETURN, ER_SP_DOES_NOT_EXIST, FALSE, LEX_STRING::length, my_error(), MYF, mysql_reset_errors(), name, st_table_list::next_global, NULL, sp_find_routine(), LEX_STRING::str, strlen(), st_table_list::table_name, TRUE, TYPE_ENUM_FUNCTION, and TYPE_ENUM_PROCEDURE.
Referenced by mysql_routine_grant().
01062 { 01063 TABLE_LIST *routine; 01064 bool result= 0; 01065 bool sp_object_found; 01066 DBUG_ENTER("sp_exists_routine"); 01067 for (routine= routines; routine; routine= routine->next_global) 01068 { 01069 sp_name *name; 01070 LEX_STRING lex_db; 01071 LEX_STRING lex_name; 01072 lex_db.length= strlen(routine->db); 01073 lex_name.length= strlen(routine->table_name); 01074 lex_db.str= thd->strmake(routine->db, lex_db.length); 01075 lex_name.str= thd->strmake(routine->table_name, lex_name.length); 01076 name= new sp_name(lex_db, lex_name); 01077 name->init_qname(thd); 01078 sp_object_found= sp_find_routine(thd, TYPE_ENUM_PROCEDURE, name, 01079 &thd->sp_proc_cache, FALSE) != NULL || 01080 sp_find_routine(thd, TYPE_ENUM_FUNCTION, name, 01081 &thd->sp_func_cache, FALSE) != NULL; 01082 mysql_reset_errors(thd, TRUE); 01083 if (sp_object_found) 01084 { 01085 if (any) 01086 DBUG_RETURN(1); 01087 result= 1; 01088 } 01089 else if (!any) 01090 { 01091 if (!no_error) 01092 { 01093 my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION or PROCEDURE", 01094 routine->table_name); 01095 DBUG_RETURN(-1); 01096 } 01097 DBUG_RETURN(0); 01098 } 01099 } 01100 DBUG_RETURN(result); 01101 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 969 of file sp.cc.
References db_find_routine(), db_load_routine(), DBUG_ASSERT, DBUG_ENTER, DBUG_PRINT, DBUG_RETURN, sp_head::IS_INVOKED, sp_head::m_first_free_instance, sp_head::m_first_instance, sp_head::m_last_cached_sp, sp_head::m_recursion_level, sp_head::m_sql_mode, name, NullS, String::ptr(), sp_cache_insert(), sp_cache_lookup(), SP_OK, sp_returns_type(), strxmov(), TYPE_ENUM_FUNCTION, TYPE_ENUM_PROCEDURE, and USER_HOST_BUFF_SIZE.
Referenced by Item_func_sp::find_and_check_access(), mysql_execute_command(), sp_exist_routines(), Item_func_sp::sp_result_field(), sp_show_create_function(), and sp_show_create_procedure().
00971 { 00972 sp_head *sp; 00973 ulong depth= (type == TYPE_ENUM_PROCEDURE ? 00974 thd->variables.max_sp_recursion_depth : 00975 0); 00976 DBUG_ENTER("sp_find_routine"); 00977 DBUG_PRINT("enter", ("name: %.*s.%.*s, type: %d, cache only %d", 00978 name->m_db.length, name->m_db.str, 00979 name->m_name.length, name->m_name.str, 00980 type, cache_only)); 00981 00982 if ((sp= sp_cache_lookup(cp, name))) 00983 { 00984 ulong level; 00985 sp_head *new_sp; 00986 const char *returns= ""; 00987 char definer[USER_HOST_BUFF_SIZE]; 00988 00989 /* 00990 String buffer for RETURNS data type must have system charset; 00991 64 -- size of "returns" column of mysql.proc. 00992 */ 00993 String retstr(64); 00994 00995 DBUG_PRINT("info", ("found: 0x%lx", (ulong)sp)); 00996 if (sp->m_first_free_instance) 00997 { 00998 DBUG_PRINT("info", ("first free: 0x%lx, level: %lu, flags %x", 00999 (ulong)sp->m_first_free_instance, 01000 sp->m_first_free_instance->m_recursion_level, 01001 sp->m_first_free_instance->m_flags)); 01002 DBUG_ASSERT(!(sp->m_first_free_instance->m_flags & sp_head::IS_INVOKED)); 01003 if (sp->m_first_free_instance->m_recursion_level > depth) 01004 { 01005 sp->recursion_level_error(thd); 01006 DBUG_RETURN(0); 01007 } 01008 DBUG_RETURN(sp->m_first_free_instance); 01009 } 01010 01011 level= sp->m_last_cached_sp->m_recursion_level + 1; 01012 if (level > depth) 01013 { 01014 sp->recursion_level_error(thd); 01015 DBUG_RETURN(0); 01016 } 01017 01018 strxmov(definer, sp->m_definer_user.str, "@", 01019 sp->m_definer_host.str, NullS); 01020 if (type == TYPE_ENUM_FUNCTION) 01021 { 01022 sp_returns_type(thd, retstr, sp); 01023 returns= retstr.ptr(); 01024 } 01025 if (db_load_routine(thd, type, name, &new_sp, 01026 sp->m_sql_mode, sp->m_params.str, returns, 01027 sp->m_body.str, *sp->m_chistics, definer, 01028 sp->m_created, sp->m_modified) == SP_OK) 01029 { 01030 sp->m_last_cached_sp->m_next_cached_sp= new_sp; 01031 new_sp->m_recursion_level= level; 01032 new_sp->m_first_instance= sp; 01033 sp->m_last_cached_sp= sp->m_first_free_instance= new_sp; 01034 DBUG_PRINT("info", ("added level: 0x%lx, level: %lu, flags %x", 01035 (ulong)new_sp, new_sp->m_recursion_level, 01036 new_sp->m_flags)); 01037 DBUG_RETURN(new_sp); 01038 } 01039 DBUG_RETURN(0); 01040 } 01041 if (!cache_only) 01042 { 01043 if (db_find_routine(thd, type, name, &sp) == SP_OK) 01044 { 01045 sp_cache_insert(cp, sp); 01046 DBUG_PRINT("info", ("added new: 0x%lx, level: %lu, flags %x", 01047 (ulong)sp, sp->m_recursion_level, 01048 sp->m_flags)); 01049 } 01050 } 01051 DBUG_RETURN(sp); 01052 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void sp_get_prelocking_info | ( | THD * | thd, |
| bool * | < |

