MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sql_parse.h
1 /* Copyright (c) 2006, 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 SQL_PARSE_INCLUDED
17 #define SQL_PARSE_INCLUDED
18 
19 #include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */
20 #include "sql_acl.h" /* GLOBAL_ACLS */
21 
22 class Comp_creator;
23 class Item;
25 class Parser_state;
26 struct TABLE_LIST;
27 class THD;
28 class Table_ident;
29 struct LEX;
30 
31 enum enum_mysql_completiontype {
32  ROLLBACK_RELEASE=-2, ROLLBACK=1, ROLLBACK_AND_CHAIN=7,
33  COMMIT_RELEASE=-1, COMMIT=0, COMMIT_AND_CHAIN=6
34 };
35 
36 extern "C" int test_if_data_home_dir(const char *dir);
37 
38 bool stmt_causes_implicit_commit(const THD *thd, uint mask);
39 
40 bool select_precheck(THD *thd, LEX *lex, TABLE_LIST *tables,
41  TABLE_LIST *first_table);
42 bool multi_update_precheck(THD *thd, TABLE_LIST *tables);
43 bool multi_delete_precheck(THD *thd, TABLE_LIST *tables);
44 int mysql_multi_update_prepare(THD *thd);
45 int mysql_multi_delete_prepare(THD *thd, uint *table_count);
46 bool mysql_insert_select_prepare(THD *thd);
47 bool update_precheck(THD *thd, TABLE_LIST *tables);
48 bool delete_precheck(THD *thd, TABLE_LIST *tables);
49 bool insert_precheck(THD *thd, TABLE_LIST *tables);
50 bool create_table_precheck(THD *thd, TABLE_LIST *tables,
52 
53 bool parse_sql(THD *thd,
54  Parser_state *parser_state,
55  Object_creation_ctx *creation_ctx);
56 
57 uint kill_one_thread(THD *thd, ulong id, bool only_kill_query);
58 
59 void free_items(Item *item);
60 void cleanup_items(Item *item);
61 
62 Comp_creator *comp_eq_creator(bool invert);
63 Comp_creator *comp_ge_creator(bool invert);
64 Comp_creator *comp_gt_creator(bool invert);
65 Comp_creator *comp_le_creator(bool invert);
66 Comp_creator *comp_lt_creator(bool invert);
67 Comp_creator *comp_ne_creator(bool invert);
68 
69 int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident,
70  enum enum_schema_tables schema_table_idx);
71 void get_default_definer(THD *thd, LEX_USER *definer);
73 LEX_USER *create_definer(THD *thd, LEX_STRING *user_name, LEX_STRING *host_name);
74 LEX_USER *get_current_user(THD *thd, LEX_USER *user);
75 bool check_string_byte_length(LEX_STRING *str, const char *err_msg,
76  uint max_byte_length);
77 bool check_string_char_length(LEX_STRING *str, const char *err_msg,
78  uint max_char_length, const CHARSET_INFO *cs,
79  bool no_error);
80 const CHARSET_INFO* merge_charset_and_collation(const CHARSET_INFO *cs,
81  const CHARSET_INFO *cl);
82 bool check_host_name(LEX_STRING *str);
83 bool check_identifier_name(LEX_STRING *str, uint max_char_length,
84  uint err_code, const char *param_for_err_msg);
85 bool mysql_test_parse_for_slave(THD *thd,char *inBuf,uint length);
86 bool is_update_query(enum enum_sql_command command);
87 bool is_explainable_query(enum enum_sql_command command);
88 bool is_log_table_write_query(enum enum_sql_command command);
89 bool alloc_query(THD *thd, const char *packet, uint packet_length);
90 void mysql_init_select(LEX *lex);
91 void mysql_parse(THD *thd, char *rawbuf, uint length,
92  Parser_state *parser_state);
94 bool mysql_new_select(LEX *lex, bool move_down);
95 void create_select_for_variable(const char *var_name);
97 void mysql_init_multi_delete(LEX *lex);
100 pthread_handler_t handle_bootstrap(void *arg);
101 int mysql_execute_command(THD *thd);
102 bool do_command(THD *thd);
103 void do_handle_bootstrap(THD *thd);
104 bool dispatch_command(enum enum_server_command command, THD *thd,
105  char* packet, uint packet_length);
106 void log_slow_statement(THD *thd);
107 bool log_slow_applicable(THD *thd);
108 void log_slow_do(THD *thd);
109 bool append_file_to_dir(THD *thd, const char **filename_ptr,
110  const char *table_name);
111 bool append_file_to_dir(THD *thd, const char **filename_ptr,
112  const char *table_name);
113 void execute_init_command(THD *thd, LEX_STRING *init_command,
114  mysql_rwlock_t *var_lock);
115 bool add_field_to_list(THD *thd, LEX_STRING *field_name, enum enum_field_types type,
116  char *length, char *decimal,
117  uint type_modifier,
118  Item *default_value, Item *on_update_value,
119  LEX_STRING *comment,
120  char *change, List<String> *interval_list,
121  const CHARSET_INFO *cs,
122  uint uint_geom_type);
123 bool add_to_list(THD *thd, SQL_I_List<ORDER> &list, Item *group, bool asc);
124 void add_join_on(TABLE_LIST *b,Item *expr);
125 void add_join_natural(TABLE_LIST *a,TABLE_LIST *b,List<String> *using_fields,
126  SELECT_LEX *lex);
127 bool push_new_name_resolution_context(THD *thd,
128  TABLE_LIST *left_op,
129  TABLE_LIST *right_op);
130 void store_position_for_column(const char *name);
131 void init_update_queries(void);
132 bool check_simple_select();
133 Item *negate_expression(THD *thd, Item *expr);
134 bool check_stack_overrun(THD *thd, long margin, uchar *dummy);
135 
136 /* Variables */
137 
138 extern const char* any_db;
139 extern uint sql_command_flags[];
140 extern uint server_command_flags[];
141 extern const LEX_STRING command_name[];
142 extern uint server_command_flags[];
143 
144 /* Inline functions */
145 inline bool check_identifier_name(LEX_STRING *str, uint err_code)
146 {
147  return check_identifier_name(str, NAME_CHAR_LEN, err_code, "");
148 }
149 
150 inline bool check_identifier_name(LEX_STRING *str)
151 {
152  return check_identifier_name(str, NAME_CHAR_LEN, 0, "");
153 }
154 
155 #ifndef NO_EMBEDDED_ACCESS_CHECKS
156 bool check_one_table_access(THD *thd, ulong privilege, TABLE_LIST *tables);
157 bool check_single_table_access(THD *thd, ulong privilege,
158  TABLE_LIST *tables, bool no_errors);
159 bool check_routine_access(THD *thd,ulong want_access,char *db,char *name,
160  bool is_proc, bool no_errors);
161 bool check_some_access(THD *thd, ulong want_access, TABLE_LIST *table);
162 bool check_some_routine_access(THD *thd, const char *db, const char *name, bool is_proc);
163 bool check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv,
164  GRANT_INTERNAL_INFO *grant_internal_info,
165  bool dont_check_global_grants, bool no_errors);
166 bool check_table_access(THD *thd, ulong requirements,TABLE_LIST *tables,
167  bool any_combination_of_privileges_will_do,
168  uint number,
169  bool no_errors);
170 #else
171 inline bool check_one_table_access(THD *thd, ulong privilege, TABLE_LIST *tables)
172 { return false; }
173 inline bool check_single_table_access(THD *thd, ulong privilege,
174  TABLE_LIST *tables, bool no_errors)
175 { return false; }
176 inline bool check_routine_access(THD *thd,ulong want_access,char *db,
177  char *name, bool is_proc, bool no_errors)
178 { return false; }
179 inline bool check_some_access(THD *thd, ulong want_access, TABLE_LIST *table)
180 {
181  table->grant.privilege= want_access;
182  return false;
183 }
184 inline bool check_some_routine_access(THD *thd, const char *db,
185  const char *name, bool is_proc)
186 { return false; }
187 inline bool check_access(THD *, ulong, const char *, ulong *save_priv,
188  GRANT_INTERNAL_INFO *, bool, bool)
189 {
190  if (save_priv)
191  *save_priv= GLOBAL_ACLS;
192  return false;
193 }
194 inline bool
195 check_table_access(THD *thd, ulong requirements,TABLE_LIST *tables,
196  bool any_combination_of_privileges_will_do,
197  uint number,
198  bool no_errors)
199 { return false; }
200 #endif /*NO_EMBEDDED_ACCESS_CHECKS*/
201 
202 /* These were under the INNODB_COMPATIBILITY_HOOKS */
203 
204 bool check_global_access(THD *thd, ulong want_access);
205 
206 inline bool is_supported_parser_charset(const CHARSET_INFO *cs)
207 {
208  return (cs->mbminlen == 1);
209 }
210 
211 extern "C" bool sqlcom_can_generate_row_events(const THD *thd);
212 
213 
214 #endif /* SQL_PARSE_INCLUDED */