My Project
|
00001 /* Copyright (c) 2006, 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 SQL_PARSE_INCLUDED 00017 #define SQL_PARSE_INCLUDED 00018 00019 #include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */ 00020 #include "sql_acl.h" /* GLOBAL_ACLS */ 00021 00022 class Comp_creator; 00023 class Item; 00024 class Object_creation_ctx; 00025 class Parser_state; 00026 struct TABLE_LIST; 00027 class THD; 00028 class Table_ident; 00029 struct LEX; 00030 00031 enum enum_mysql_completiontype { 00032 ROLLBACK_RELEASE=-2, ROLLBACK=1, ROLLBACK_AND_CHAIN=7, 00033 COMMIT_RELEASE=-1, COMMIT=0, COMMIT_AND_CHAIN=6 00034 }; 00035 00036 extern "C" int test_if_data_home_dir(const char *dir); 00037 00038 bool stmt_causes_implicit_commit(const THD *thd, uint mask); 00039 00040 bool select_precheck(THD *thd, LEX *lex, TABLE_LIST *tables, 00041 TABLE_LIST *first_table); 00042 bool multi_update_precheck(THD *thd, TABLE_LIST *tables); 00043 bool multi_delete_precheck(THD *thd, TABLE_LIST *tables); 00044 int mysql_multi_update_prepare(THD *thd); 00045 int mysql_multi_delete_prepare(THD *thd, uint *table_count); 00046 bool mysql_insert_select_prepare(THD *thd); 00047 bool update_precheck(THD *thd, TABLE_LIST *tables); 00048 bool delete_precheck(THD *thd, TABLE_LIST *tables); 00049 bool insert_precheck(THD *thd, TABLE_LIST *tables); 00050 bool create_table_precheck(THD *thd, TABLE_LIST *tables, 00051 TABLE_LIST *create_table); 00052 bool check_fk_parent_table_access(THD *thd, 00053 HA_CREATE_INFO *create_info, 00054 Alter_info *alter_info); 00055 00056 bool parse_sql(THD *thd, 00057 Parser_state *parser_state, 00058 Object_creation_ctx *creation_ctx); 00059 00060 uint kill_one_thread(THD *thd, ulong id, bool only_kill_query); 00061 00062 void free_items(Item *item); 00063 void cleanup_items(Item *item); 00064 00065 Comp_creator *comp_eq_creator(bool invert); 00066 Comp_creator *comp_ge_creator(bool invert); 00067 Comp_creator *comp_gt_creator(bool invert); 00068 Comp_creator *comp_le_creator(bool invert); 00069 Comp_creator *comp_lt_creator(bool invert); 00070 Comp_creator *comp_ne_creator(bool invert); 00071 00072 int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident, 00073 enum enum_schema_tables schema_table_idx); 00074 void get_default_definer(THD *thd, LEX_USER *definer); 00075 LEX_USER *create_default_definer(THD *thd); 00076 LEX_USER *create_definer(THD *thd, LEX_STRING *user_name, LEX_STRING *host_name); 00077 LEX_USER *get_current_user(THD *thd, LEX_USER *user); 00078 bool check_string_byte_length(LEX_STRING *str, const char *err_msg, 00079 uint max_byte_length); 00080 bool check_string_char_length(LEX_STRING *str, const char *err_msg, 00081 uint max_char_length, const CHARSET_INFO *cs, 00082 bool no_error); 00083 const CHARSET_INFO* merge_charset_and_collation(const CHARSET_INFO *cs, 00084 const CHARSET_INFO *cl); 00085 bool check_host_name(LEX_STRING *str); 00086 bool check_identifier_name(LEX_STRING *str, uint max_char_length, 00087 uint err_code, const char *param_for_err_msg); 00088 bool mysql_test_parse_for_slave(THD *thd,char *inBuf,uint length); 00089 bool is_update_query(enum enum_sql_command command); 00090 bool is_explainable_query(enum enum_sql_command command); 00091 bool is_log_table_write_query(enum enum_sql_command command); 00092 bool alloc_query(THD *thd, const char *packet, uint packet_length); 00093 void mysql_init_select(LEX *lex); 00094 void mysql_parse(THD *thd, char *rawbuf, uint length, 00095 Parser_state *parser_state); 00096 void mysql_reset_thd_for_next_command(THD *thd); 00097 bool mysql_new_select(LEX *lex, bool move_down); 00098 void create_select_for_variable(const char *var_name); 00099 void create_table_set_open_action_and_adjust_tables(LEX *lex); 00100 void mysql_init_multi_delete(LEX *lex); 00101 bool multi_delete_set_locks_and_link_aux_tables(LEX *lex); 00102 void create_table_set_open_action_and_adjust_tables(LEX *lex); 00103 pthread_handler_t handle_bootstrap(void *arg); 00104 int mysql_execute_command(THD *thd); 00105 bool do_command(THD *thd); 00106 void do_handle_bootstrap(THD *thd); 00107 bool dispatch_command(enum enum_server_command command, THD *thd, 00108 char* packet, uint packet_length); 00109 void log_slow_statement(THD *thd); 00110 bool log_slow_applicable(THD *thd); 00111 void log_slow_do(THD *thd); 00112 bool append_file_to_dir(THD *thd, const char **filename_ptr, 00113 const char *table_name); 00114 bool append_file_to_dir(THD *thd, const char **filename_ptr, 00115 const char *table_name); 00116 void execute_init_command(THD *thd, LEX_STRING *init_command, 00117 mysql_rwlock_t *var_lock); 00118 bool add_field_to_list(THD *thd, LEX_STRING *field_name, enum enum_field_types type, 00119 char *length, char *decimal, 00120 uint type_modifier, 00121 Item *default_value, Item *on_update_value, 00122 LEX_STRING *comment, 00123 char *change, List<String> *interval_list, 00124 const CHARSET_INFO *cs, 00125 uint uint_geom_type); 00126 bool add_to_list(THD *thd, SQL_I_List<ORDER> &list, Item *group, bool asc); 00127 void add_join_on(TABLE_LIST *b,Item *expr); 00128 void add_join_natural(TABLE_LIST *a,TABLE_LIST *b,List<String> *using_fields, 00129 SELECT_LEX *lex); 00130 bool push_new_name_resolution_context(THD *thd, 00131 TABLE_LIST *left_op, 00132 TABLE_LIST *right_op); 00133 void store_position_for_column(const char *name); 00134 void init_update_queries(void); 00135 bool check_simple_select(); 00136 Item *negate_expression(THD *thd, Item *expr); 00137 bool check_stack_overrun(THD *thd, long margin, uchar *dummy); 00138 00139 /* Variables */ 00140 00141 extern const char* any_db; 00142 extern uint sql_command_flags[]; 00143 extern uint server_command_flags[]; 00144 extern const LEX_STRING command_name[]; 00145 extern uint server_command_flags[]; 00146 00147 /* Inline functions */ 00148 inline bool check_identifier_name(LEX_STRING *str, uint err_code) 00149 { 00150 return check_identifier_name(str, NAME_CHAR_LEN, err_code, ""); 00151 } 00152 00153 inline bool check_identifier_name(LEX_STRING *str) 00154 { 00155 return check_identifier_name(str, NAME_CHAR_LEN, 0, ""); 00156 } 00157 00158 #ifndef NO_EMBEDDED_ACCESS_CHECKS 00159 bool check_one_table_access(THD *thd, ulong privilege, TABLE_LIST *tables); 00160 bool check_single_table_access(THD *thd, ulong privilege, 00161 TABLE_LIST *tables, bool no_errors); 00162 bool check_routine_access(THD *thd,ulong want_access,char *db,char *name, 00163 bool is_proc, bool no_errors); 00164 bool check_some_access(THD *thd, ulong want_access, TABLE_LIST *table); 00165 bool check_some_routine_access(THD *thd, const char *db, const char *name, bool is_proc); 00166 bool check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, 00167 GRANT_INTERNAL_INFO *grant_internal_info, 00168 bool dont_check_global_grants, bool no_errors); 00169 bool check_table_access(THD *thd, ulong requirements,TABLE_LIST *tables, 00170 bool any_combination_of_privileges_will_do, 00171 uint number, 00172 bool no_errors); 00173 #else 00174 inline bool check_one_table_access(THD *thd, ulong privilege, TABLE_LIST *tables) 00175 { return false; } 00176 inline bool check_single_table_access(THD *thd, ulong privilege, 00177 TABLE_LIST *tables, bool no_errors) 00178 { return false; } 00179 inline bool check_routine_access(THD *thd,ulong want_access,char *db, 00180 char *name, bool is_proc, bool no_errors) 00181 { return false; } 00182 inline bool check_some_access(THD *thd, ulong want_access, TABLE_LIST *table) 00183 { 00184 table->grant.privilege= want_access; 00185 return false; 00186 } 00187 inline bool check_some_routine_access(THD *thd, const char *db, 00188 const char *name, bool is_proc) 00189 { return false; } 00190 inline bool check_access(THD *, ulong, const char *, ulong *save_priv, 00191 GRANT_INTERNAL_INFO *, bool, bool) 00192 { 00193 if (save_priv) 00194 *save_priv= GLOBAL_ACLS; 00195 return false; 00196 } 00197 inline bool 00198 check_table_access(THD *thd, ulong requirements,TABLE_LIST *tables, 00199 bool any_combination_of_privileges_will_do, 00200 uint number, 00201 bool no_errors) 00202 { return false; } 00203 #endif /*NO_EMBEDDED_ACCESS_CHECKS*/ 00204 00205 /* These were under the INNODB_COMPATIBILITY_HOOKS */ 00206 00207 bool check_global_access(THD *thd, ulong want_access); 00208 00209 inline bool is_supported_parser_charset(const CHARSET_INFO *cs) 00210 { 00211 return (cs->mbminlen == 1); 00212 } 00213 00214 extern "C" bool sqlcom_can_generate_row_events(const THD *thd); 00215 00216 00217 #endif /* SQL_PARSE_INCLUDED */