My Project
sp.h
00001 /* Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
00002 
00003    This program is free software; you can redistribute it and/or modify
00004    it under the terms of the GNU General Public License as published by
00005    the Free Software Foundation; version 2 of the License.
00006 
00007    This program is distributed in the hope that it will be useful,
00008    but WITHOUT ANY WARRANTY; without even the implied warranty of
00009    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010    GNU General Public License for more details.
00011 
00012    You should have received a copy of the GNU General Public License
00013    along with this program; if not, write to the Free Software
00014    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
00015 
00016 #ifndef _SP_H_
00017 #define _SP_H_
00018 
00019 #include "sql_string.h"                         // LEX_STRING
00020 #include "sp_head.h"                            // enum_sp_type
00021 
00022 
00023 class Field;
00024 class Open_tables_backup;
00025 class Open_tables_state;
00026 class Query_arena;
00027 class Query_tables_list;
00028 class Sroutine_hash_entry;
00029 class THD;
00030 class sp_cache;
00031 struct st_sp_chistics;
00032 struct LEX;
00033 struct TABLE;
00034 struct TABLE_LIST;
00035 typedef struct st_hash HASH;
00036 template <typename T> class SQL_I_List;
00037 
00038 
00039 /* Tells what SP_DEFAULT_ACCESS should be mapped to */
00040 #define SP_DEFAULT_ACCESS_MAPPING SP_CONTAINS_SQL
00041 
00042 // Return codes from sp_create_*, sp_drop_*, and sp_show_*:
00043 #define SP_OK                 0
00044 #define SP_KEY_NOT_FOUND     -1
00045 #define SP_OPEN_TABLE_FAILED -2
00046 #define SP_WRITE_ROW_FAILED  -3
00047 #define SP_DELETE_ROW_FAILED -4
00048 #define SP_GET_FIELD_FAILED  -5
00049 #define SP_PARSE_ERROR       -6
00050 #define SP_INTERNAL_ERROR    -7
00051 #define SP_NO_DB_ERROR       -8
00052 #define SP_BAD_IDENTIFIER    -9
00053 #define SP_BODY_TOO_LONG    -10
00054 #define SP_FLD_STORE_FAILED -11
00055 
00056 /* DB storage of Stored PROCEDUREs and FUNCTIONs */
00057 enum
00058 {
00059   MYSQL_PROC_FIELD_DB = 0,
00060   MYSQL_PROC_FIELD_NAME,
00061   MYSQL_PROC_MYSQL_TYPE,
00062   MYSQL_PROC_FIELD_SPECIFIC_NAME,
00063   MYSQL_PROC_FIELD_LANGUAGE,
00064   MYSQL_PROC_FIELD_ACCESS,
00065   MYSQL_PROC_FIELD_DETERMINISTIC,
00066   MYSQL_PROC_FIELD_SECURITY_TYPE,
00067   MYSQL_PROC_FIELD_PARAM_LIST,
00068   MYSQL_PROC_FIELD_RETURNS,
00069   MYSQL_PROC_FIELD_BODY,
00070   MYSQL_PROC_FIELD_DEFINER,
00071   MYSQL_PROC_FIELD_CREATED,
00072   MYSQL_PROC_FIELD_MODIFIED,
00073   MYSQL_PROC_FIELD_SQL_MODE,
00074   MYSQL_PROC_FIELD_COMMENT,
00075   MYSQL_PROC_FIELD_CHARACTER_SET_CLIENT,
00076   MYSQL_PROC_FIELD_COLLATION_CONNECTION,
00077   MYSQL_PROC_FIELD_DB_COLLATION,
00078   MYSQL_PROC_FIELD_BODY_UTF8,
00079   MYSQL_PROC_FIELD_COUNT
00080 };
00081 
00082 /* Drop all routines in database 'db' */
00083 int sp_drop_db_routines(THD *thd, char *db);
00084 
00095 bool lock_db_routines(THD *thd, char *db);
00096 
00097 sp_head *sp_find_routine(THD *thd, enum_sp_type type, sp_name *name,
00098                          sp_cache **cp, bool cache_only);
00099 
00100 int sp_cache_routine(THD *thd, Sroutine_hash_entry *rt,
00101                      bool lookup_only, sp_head **sp);
00102 
00103 int sp_cache_routine(THD *thd, enum_sp_type type, sp_name *name,
00104                      bool lookup_only, sp_head **sp);
00105 
00106 bool sp_exist_routines(THD *thd, TABLE_LIST *procs, bool is_proc);
00107 
00108 bool sp_show_create_routine(THD *thd, enum_sp_type type, sp_name *name);
00109 
00110 int sp_create_routine(THD *thd, sp_head *sp);
00111 
00112 int sp_update_routine(THD *thd, enum_sp_type type, sp_name *name,
00113                       st_sp_chistics *chistics);
00114 
00115 int sp_drop_routine(THD *thd, enum_sp_type type, sp_name *name);
00116 
00117 
00123 class Sroutine_hash_entry
00124 {
00125 public:
00130   MDL_request mdl_request;
00135   Sroutine_hash_entry *next;
00141   TABLE_LIST *belong_to_view;
00151   ulong m_sp_cache_version;
00152 };
00153 
00154 
00155 /*
00156   Procedures for handling sets of stored routines used by statement or routine.
00157 */
00158 void sp_add_used_routine(Query_tables_list *prelocking_ctx, Query_arena *arena,
00159                          sp_name *rt, enum_sp_type rt_type);
00160 bool sp_add_used_routine(Query_tables_list *prelocking_ctx, Query_arena *arena,
00161                          const MDL_key *key, TABLE_LIST *belong_to_view);
00162 void sp_remove_not_own_routines(Query_tables_list *prelocking_ctx);
00163 void sp_update_stmt_used_routines(THD *thd, Query_tables_list *prelocking_ctx,
00164                                   HASH *src, TABLE_LIST *belong_to_view);
00165 void sp_update_stmt_used_routines(THD *thd, Query_tables_list *prelocking_ctx,
00166                                   SQL_I_List<Sroutine_hash_entry> *src,
00167                                   TABLE_LIST *belong_to_view);
00168 
00169 extern "C" uchar* sp_sroutine_key(const uchar *ptr, size_t *plen,
00170                                   my_bool first);
00171 
00172 /*
00173   Routines which allow open/lock and close mysql.proc table even when
00174   we already have some tables open and locked.
00175 */
00176 TABLE *open_proc_table_for_read(THD *thd, Open_tables_backup *backup);
00177 
00178 sp_head *sp_load_for_information_schema(THD *thd, TABLE *proc_table, String *db,
00179                                         String *name, sql_mode_t sql_mode,
00180                                         enum_sp_type type,
00181                                         const char *returns, const char *params,
00182                                         bool *free_sp_head);
00183 
00184 bool load_charset(MEM_ROOT *mem_root,
00185                   Field *field,
00186                   const CHARSET_INFO *dflt_cs,
00187                   const CHARSET_INFO **cs);
00188 
00189 bool load_collation(MEM_ROOT *mem_root,
00190                     Field *field,
00191                     const CHARSET_INFO *dflt_cl,
00192                     const CHARSET_INFO **cl);
00193 
00195 
00196 sp_head *sp_start_parsing(THD *thd,
00197                           enum_sp_type sp_type,
00198                           sp_name *sp_name);
00199 
00200 void sp_finish_parsing(THD *thd);
00201 
00203 
00204 Item_result sp_map_result_type(enum enum_field_types type);
00205 Item::Type sp_map_item_type(enum enum_field_types type);
00206 uint sp_get_flags_for_command(LEX *lex);
00207 
00208 bool sp_check_name(LEX_STRING *ident);
00209 
00210 TABLE_LIST *sp_add_to_query_tables(THD *thd, LEX *lex,
00211                                    const char *db, const char *name,
00212                                    thr_lock_type locktype,
00213                                    enum_mdl_type mdl_type);
00214 
00215 bool sp_check_show_access(THD *thd, sp_head *sp, bool *full_access);
00216 
00217 Item *sp_prepare_func_item(THD* thd, Item **it_addr);
00218 
00219 bool sp_eval_expr(THD *thd, Field *result_field, Item **expr_item_ptr);
00220 
00221 String *sp_get_item_value(THD *thd, Item *item, String *str);
00222 
00224 
00225 #endif /* _SP_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines