| 1 | /* Copyright (c) 2006, 2011, 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 SQL_PARSE_INCLUDED |
| 17 | #define SQL_PARSE_INCLUDED |
| 18 | |
| 19 | #include "sql_acl.h" /* GLOBAL_ACLS */ |
| 20 | |
| 21 | class Comp_creator; |
| 22 | class Item; |
| 23 | class Object_creation_ctx; |
| 24 | class Parser_state; |
| 25 | struct TABLE_LIST; |
| 26 | class THD; |
| 27 | class Table_ident; |
| 28 | struct LEX; |
| 29 | |
| 30 | enum enum_mysql_completiontype { |
| 31 | ROLLBACK_RELEASE=-2, ROLLBACK=1, ROLLBACK_AND_CHAIN=7, |
| 32 | COMMIT_RELEASE=-1, COMMIT=0, COMMIT_AND_CHAIN=6 |
| 33 | }; |
| 34 | |
| 35 | extern "C" int path_starts_from_data_home_dir(const char *dir); |
| 36 | int test_if_data_home_dir(const char *dir); |
| 37 | int error_if_data_home_dir(const char *path, const char *what); |
| 38 | my_bool net_allocate_new_packet(NET *net, void *thd, uint my_flags); |
| 39 | |
| 40 | bool multi_update_precheck(THD *thd, TABLE_LIST *tables); |
| 41 | bool multi_delete_precheck(THD *thd, TABLE_LIST *tables); |
| 42 | int mysql_multi_update_prepare(THD *thd); |
| 43 | int mysql_multi_delete_prepare(THD *thd); |
| 44 | bool mysql_insert_select_prepare(THD *thd); |
| 45 | bool update_precheck(THD *thd, TABLE_LIST *tables); |
| 46 | bool delete_precheck(THD *thd, TABLE_LIST *tables); |
| 47 | bool insert_precheck(THD *thd, TABLE_LIST *tables); |
| 48 | bool create_table_precheck(THD *thd, TABLE_LIST *tables, |
| 49 | TABLE_LIST *create_table); |
| 50 | bool check_fk_parent_table_access(THD *thd, |
| 51 | HA_CREATE_INFO *create_info, |
| 52 | Alter_info *alter_info, |
| 53 | const char* create_db); |
| 54 | |
| 55 | bool parse_sql(THD *thd, Parser_state *parser_state, |
| 56 | Object_creation_ctx *creation_ctx, bool do_pfs_digest=false); |
| 57 | |
| 58 | void free_items(Item *item); |
| 59 | void cleanup_items(Item *item); |
| 60 | |
| 61 | Comp_creator *comp_eq_creator(bool invert); |
| 62 | Comp_creator *comp_ge_creator(bool invert); |
| 63 | Comp_creator *comp_gt_creator(bool invert); |
| 64 | Comp_creator *comp_le_creator(bool invert); |
| 65 | Comp_creator *comp_lt_creator(bool invert); |
| 66 | Comp_creator *comp_ne_creator(bool invert); |
| 67 | |
| 68 | int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident, |
| 69 | enum enum_schema_tables schema_table_idx); |
| 70 | void get_default_definer(THD *thd, LEX_USER *definer, bool role); |
| 71 | LEX_USER *create_default_definer(THD *thd, bool role); |
| 72 | LEX_USER *create_definer(THD *thd, LEX_CSTRING *user_name, LEX_CSTRING *host_name); |
| 73 | LEX_USER *get_current_user(THD *thd, LEX_USER *user, bool lock=true); |
| 74 | bool sp_process_definer(THD *thd); |
| 75 | bool check_string_byte_length(const LEX_CSTRING *str, uint err_msg, |
| 76 | size_t max_byte_length); |
| 77 | bool check_string_char_length(const LEX_CSTRING *str, uint err_msg, |
| 78 | size_t max_char_length, CHARSET_INFO *cs, |
| 79 | bool no_error); |
| 80 | bool check_ident_length(const LEX_CSTRING *ident); |
| 81 | CHARSET_INFO* merge_charset_and_collation(CHARSET_INFO *cs, CHARSET_INFO *cl); |
| 82 | CHARSET_INFO *find_bin_collation(CHARSET_INFO *cs); |
| 83 | bool check_host_name(LEX_CSTRING *str); |
| 84 | bool check_identifier_name(LEX_CSTRING *str, uint max_char_length, |
| 85 | uint err_code, const char *param_for_err_msg); |
| 86 | bool mysql_test_parse_for_slave(THD *thd,char *inBuf,uint length); |
| 87 | bool sqlcom_can_generate_row_events(const THD *thd); |
| 88 | bool stmt_causes_implicit_commit(THD *thd, uint mask); |
| 89 | bool is_update_query(enum enum_sql_command command); |
| 90 | bool is_log_table_write_query(enum enum_sql_command command); |
| 91 | bool alloc_query(THD *thd, const char *packet, size_t packet_length); |
| 92 | void mysql_init_select(LEX *lex); |
| 93 | void mysql_parse(THD *thd, char *rawbuf, uint length, |
| 94 | Parser_state *parser_state, bool is_com_multi, |
| 95 | bool is_next_command); |
| 96 | bool mysql_new_select(LEX *lex, bool move_down, SELECT_LEX *sel); |
| 97 | void create_select_for_variable(THD *thd, LEX_CSTRING *var_name); |
| 98 | void create_table_set_open_action_and_adjust_tables(LEX *lex); |
| 99 | void mysql_init_multi_delete(LEX *lex); |
| 100 | bool multi_delete_set_locks_and_link_aux_tables(LEX *lex); |
| 101 | void create_table_set_open_action_and_adjust_tables(LEX *lex); |
| 102 | pthread_handler_t handle_bootstrap(void *arg); |
| 103 | int mysql_execute_command(THD *thd); |
| 104 | bool do_command(THD *thd); |
| 105 | void do_handle_bootstrap(THD *thd); |
| 106 | bool dispatch_command(enum enum_server_command command, THD *thd, |
| 107 | char* packet, uint packet_length, |
| 108 | bool is_com_multi, bool is_next_command); |
| 109 | void log_slow_statement(THD *thd); |
| 110 | bool append_file_to_dir(THD *thd, const char **filename_ptr, |
| 111 | const LEX_CSTRING *table_name); |
| 112 | void execute_init_command(THD *thd, LEX_STRING *init_command, |
| 113 | mysql_rwlock_t *var_lock); |
| 114 | bool add_to_list(THD *thd, SQL_I_List<ORDER> &list, Item *group, bool asc); |
| 115 | void add_join_on(THD *thd, TABLE_LIST *b, Item *expr); |
| 116 | void add_join_natural(TABLE_LIST *a,TABLE_LIST *b,List<String> *using_fields, |
| 117 | SELECT_LEX *lex); |
| 118 | bool add_proc_to_list(THD *thd, Item *item); |
| 119 | bool push_new_name_resolution_context(THD *thd, |
| 120 | TABLE_LIST *left_op, |
| 121 | TABLE_LIST *right_op); |
| 122 | void init_update_queries(void); |
| 123 | Item *normalize_cond(THD *thd, Item *cond); |
| 124 | Item *negate_expression(THD *thd, Item *expr); |
| 125 | bool check_stack_overrun(THD *thd, long margin, uchar *dummy); |
| 126 | |
| 127 | /* Variables */ |
| 128 | |
| 129 | extern const char* any_db; |
| 130 | extern uint sql_command_flags[]; |
| 131 | extern uint server_command_flags[]; |
| 132 | extern const LEX_CSTRING command_name[]; |
| 133 | extern uint server_command_flags[]; |
| 134 | |
| 135 | /* Inline functions */ |
| 136 | inline bool check_identifier_name(LEX_CSTRING *str, uint err_code) |
| 137 | { |
| 138 | return check_identifier_name(str, NAME_CHAR_LEN, err_code, "" ); |
| 139 | } |
| 140 | |
| 141 | inline bool check_identifier_name(LEX_CSTRING *str) |
| 142 | { |
| 143 | return check_identifier_name(str, NAME_CHAR_LEN, 0, "" ); |
| 144 | } |
| 145 | |
| 146 | #ifndef NO_EMBEDDED_ACCESS_CHECKS |
| 147 | bool check_one_table_access(THD *thd, ulong privilege, TABLE_LIST *tables); |
| 148 | bool check_single_table_access(THD *thd, ulong privilege, |
| 149 | TABLE_LIST *tables, bool no_errors); |
| 150 | bool check_routine_access(THD *thd,ulong want_access, |
| 151 | const LEX_CSTRING *db, |
| 152 | const LEX_CSTRING *name, |
| 153 | const Sp_handler *sph, bool no_errors); |
| 154 | bool check_some_access(THD *thd, ulong want_access, TABLE_LIST *table); |
| 155 | bool check_some_routine_access(THD *thd, const char *db, const char *name, |
| 156 | const Sp_handler *sph); |
| 157 | bool check_table_access(THD *thd, ulong requirements,TABLE_LIST *tables, |
| 158 | bool any_combination_of_privileges_will_do, |
| 159 | uint number, |
| 160 | bool no_errors); |
| 161 | #else |
| 162 | inline bool check_one_table_access(THD *thd, ulong privilege, TABLE_LIST *tables) |
| 163 | { return false; } |
| 164 | inline bool check_single_table_access(THD *thd, ulong privilege, |
| 165 | TABLE_LIST *tables, bool no_errors) |
| 166 | { return false; } |
| 167 | inline bool check_routine_access(THD *thd,ulong want_access, |
| 168 | const LEX_CSTRING *db, |
| 169 | const LEX_CSTRING *name, |
| 170 | const Sp_handler *sph, bool no_errors) |
| 171 | { return false; } |
| 172 | inline bool check_some_access(THD *thd, ulong want_access, TABLE_LIST *table) |
| 173 | { |
| 174 | table->grant.privilege= want_access; |
| 175 | return false; |
| 176 | } |
| 177 | inline bool check_some_routine_access(THD *thd, const char *db, |
| 178 | const char *name, |
| 179 | const Sp_handler *sph) |
| 180 | { return false; } |
| 181 | inline bool |
| 182 | check_table_access(THD *thd, ulong requirements,TABLE_LIST *tables, |
| 183 | bool any_combination_of_privileges_will_do, |
| 184 | uint number, |
| 185 | bool no_errors) |
| 186 | { return false; } |
| 187 | #endif /*NO_EMBEDDED_ACCESS_CHECKS*/ |
| 188 | |
| 189 | #endif /* SQL_PARSE_INCLUDED */ |
| 190 | |