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