MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sp.h
1 /* Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software
14  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15 
16 #ifndef _SP_H_
17 #define _SP_H_
18 
19 #include "sql_string.h" // LEX_STRING
20 #include "sp_head.h" // enum_sp_type
21 
22 
23 class Field;
24 class Open_tables_backup;
25 class Open_tables_state;
26 class Query_arena;
27 class Query_tables_list;
29 class THD;
30 class sp_cache;
31 struct st_sp_chistics;
32 struct LEX;
33 struct TABLE;
34 struct TABLE_LIST;
35 typedef struct st_hash HASH;
36 template <typename T> class SQL_I_List;
37 
38 
39 /* Tells what SP_DEFAULT_ACCESS should be mapped to */
40 #define SP_DEFAULT_ACCESS_MAPPING SP_CONTAINS_SQL
41 
42 // Return codes from sp_create_*, sp_drop_*, and sp_show_*:
43 #define SP_OK 0
44 #define SP_KEY_NOT_FOUND -1
45 #define SP_OPEN_TABLE_FAILED -2
46 #define SP_WRITE_ROW_FAILED -3
47 #define SP_DELETE_ROW_FAILED -4
48 #define SP_GET_FIELD_FAILED -5
49 #define SP_PARSE_ERROR -6
50 #define SP_INTERNAL_ERROR -7
51 #define SP_NO_DB_ERROR -8
52 #define SP_BAD_IDENTIFIER -9
53 #define SP_BODY_TOO_LONG -10
54 #define SP_FLD_STORE_FAILED -11
55 
56 /* DB storage of Stored PROCEDUREs and FUNCTIONs */
57 enum
58 {
59  MYSQL_PROC_FIELD_DB = 0,
60  MYSQL_PROC_FIELD_NAME,
61  MYSQL_PROC_MYSQL_TYPE,
62  MYSQL_PROC_FIELD_SPECIFIC_NAME,
63  MYSQL_PROC_FIELD_LANGUAGE,
64  MYSQL_PROC_FIELD_ACCESS,
65  MYSQL_PROC_FIELD_DETERMINISTIC,
66  MYSQL_PROC_FIELD_SECURITY_TYPE,
67  MYSQL_PROC_FIELD_PARAM_LIST,
68  MYSQL_PROC_FIELD_RETURNS,
69  MYSQL_PROC_FIELD_BODY,
70  MYSQL_PROC_FIELD_DEFINER,
71  MYSQL_PROC_FIELD_CREATED,
72  MYSQL_PROC_FIELD_MODIFIED,
73  MYSQL_PROC_FIELD_SQL_MODE,
74  MYSQL_PROC_FIELD_COMMENT,
75  MYSQL_PROC_FIELD_CHARACTER_SET_CLIENT,
76  MYSQL_PROC_FIELD_COLLATION_CONNECTION,
77  MYSQL_PROC_FIELD_DB_COLLATION,
78  MYSQL_PROC_FIELD_BODY_UTF8,
79  MYSQL_PROC_FIELD_COUNT
80 };
81 
82 /* Drop all routines in database 'db' */
83 int sp_drop_db_routines(THD *thd, char *db);
84 
95 bool lock_db_routines(THD *thd, char *db);
96 
97 sp_head *sp_find_routine(THD *thd, enum_sp_type type, sp_name *name,
98  sp_cache **cp, bool cache_only);
99 
100 int sp_cache_routine(THD *thd, Sroutine_hash_entry *rt,
101  bool lookup_only, sp_head **sp);
102 
103 int sp_cache_routine(THD *thd, enum_sp_type type, sp_name *name,
104  bool lookup_only, sp_head **sp);
105 
106 bool sp_exist_routines(THD *thd, TABLE_LIST *procs, bool is_proc);
107 
108 bool sp_show_create_routine(THD *thd, enum_sp_type type, sp_name *name);
109 
110 int sp_create_routine(THD *thd, sp_head *sp);
111 
112 int sp_update_routine(THD *thd, enum_sp_type type, sp_name *name,
113  st_sp_chistics *chistics);
114 
115 int sp_drop_routine(THD *thd, enum_sp_type type, sp_name *name);
116 
117 
124 {
125 public:
152 };
153 
154 
155 /*
156  Procedures for handling sets of stored routines used by statement or routine.
157 */
158 void sp_add_used_routine(Query_tables_list *prelocking_ctx, Query_arena *arena,
159  sp_name *rt, enum_sp_type rt_type);
160 bool sp_add_used_routine(Query_tables_list *prelocking_ctx, Query_arena *arena,
161  const MDL_key *key, TABLE_LIST *belong_to_view);
162 void sp_remove_not_own_routines(Query_tables_list *prelocking_ctx);
163 void sp_update_stmt_used_routines(THD *thd, Query_tables_list *prelocking_ctx,
164  HASH *src, TABLE_LIST *belong_to_view);
165 void sp_update_stmt_used_routines(THD *thd, Query_tables_list *prelocking_ctx,
167  TABLE_LIST *belong_to_view);
168 
169 extern "C" uchar* sp_sroutine_key(const uchar *ptr, size_t *plen,
170  my_bool first);
171 
172 /*
173  Routines which allow open/lock and close mysql.proc table even when
174  we already have some tables open and locked.
175 */
176 TABLE *open_proc_table_for_read(THD *thd, Open_tables_backup *backup);
177 
178 sp_head *sp_load_for_information_schema(THD *thd, TABLE *proc_table, String *db,
179  String *name, sql_mode_t sql_mode,
180  enum_sp_type type,
181  const char *returns, const char *params,
182  bool *free_sp_head);
183 
184 bool load_charset(MEM_ROOT *mem_root,
185  Field *field,
186  const CHARSET_INFO *dflt_cs,
187  const CHARSET_INFO **cs);
188 
189 bool load_collation(MEM_ROOT *mem_root,
190  Field *field,
191  const CHARSET_INFO *dflt_cl,
192  const CHARSET_INFO **cl);
193 
195 
196 sp_head *sp_start_parsing(THD *thd,
197  enum_sp_type sp_type,
198  sp_name *sp_name);
199 
200 void sp_finish_parsing(THD *thd);
201 
203 
204 Item_result sp_map_result_type(enum enum_field_types type);
205 Item::Type sp_map_item_type(enum enum_field_types type);
206 uint sp_get_flags_for_command(LEX *lex);
207 
208 bool sp_check_name(LEX_STRING *ident);
209 
210 TABLE_LIST *sp_add_to_query_tables(THD *thd, LEX *lex,
211  const char *db, const char *name,
212  thr_lock_type locktype,
213  enum_mdl_type mdl_type);
214 
215 bool sp_check_show_access(THD *thd, sp_head *sp, bool *full_access);
216 
217 Item *sp_prepare_func_item(THD* thd, Item **it_addr);
218 
219 bool sp_eval_expr(THD *thd, Field *result_field, Item **expr_item_ptr);
220 
221 String *sp_get_item_value(THD *thd, Item *item, String *str);
222 
224 
225 #endif /* _SP_H_ */