~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/server_includes.h

pandora-build v0.100 - Fixes several bugs found by cb1kenobi. Add several thoughts from folks at LCA.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000-2003 MySQL AB
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
 
 
16
 
/**
17
 
  @file
18
 
 
19
 
  @details
20
 
  Mostly this file is used in the server. But a little part of it is used in
21
 
  mysqlbinlog too (definition of SELECT_DISTINCT and others).
22
 
  The consequence is that 90% of the file is wrapped in \#ifndef DRIZZLE_CLIENT,
23
 
  except the part which must be in the server and in the client.
24
 
 
25
 
  @TODO Name this file better. "priv" could mean private, privileged, privileges.
26
 
 
27
 
  @TODO Get rid of the DRIZZLE_CLIENT and DRIZZLE_SERVER conditionals
28
 
*/
29
 
 
30
 
#ifndef DRIZZLE_SERVER_SERVER_INCLUDES_H
31
 
#define DRIZZLE_SERVER_SERVER_INCLUDES_H
32
 
 
33
 
/* Some forward declarations just for the server */
34
 
 
35
 
class Comp_creator;
36
 
typedef Comp_creator* (*chooser_compare_func_creator)(bool invert);
37
 
 
38
 
/**
39
 
 * Contains all headers, definitions, and declarations common to 
40
 
 * the server and the plugin infrastructure, and not the client 
41
 
 */
42
 
#include <drizzled/common_includes.h>       
43
 
/* Range optimization API/library */
44
 
#include <drizzled/opt_range.h>
45
 
/* Simple error injection (crash) module */
46
 
#include <drizzled/error_injection.h>
47
 
/* API for connecting, logging in to a drizzled server */
48
 
#include <drizzled/connect.h>
49
 
/* Routines for dropping, repairing, checking schema tables */
50
 
#include <drizzled/sql_table.h>
51
 
 
52
 
/* sql_db.cc */
53
 
int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create, bool silent);
54
 
bool mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create);
55
 
bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent);
56
 
bool mysql_change_db(THD *thd, const LEX_STRING *new_db_name,
57
 
                     bool force_switch);
58
 
bool mysql_opt_change_db(THD *thd,
59
 
                         const LEX_STRING *new_db_name,
60
 
                         LEX_STRING *saved_db_name,
61
 
                         bool force_switch,
62
 
                         bool *cur_db_changed);
63
 
 
64
 
/* sql_repl.cc */
65
 
void write_bin_log(THD *thd, bool clear_error,
66
 
                   char const *query, ulong query_length);
67
 
void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos, ushort flags);
68
 
void mysql_client_binlog_statement(THD *thd);
69
 
 
70
 
/* sql_rename.cc */
71
 
bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list, bool silent);
72
 
bool do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db,
73
 
                      char *new_table_name, char *new_table_alias,
74
 
                      bool skip_error);
75
 
 
76
 
/* sql_parse.cc */
77
 
void mysql_parse(THD *thd, const char *inBuf, uint length,
78
 
                 const char ** semicolon);
79
 
 
80
 
bool mysql_test_parse_for_slave(THD *thd,char *inBuf,uint length);
81
 
 
82
 
 
83
 
bool is_update_query(enum enum_sql_command command);
84
 
 
85
 
bool alloc_query(THD *thd, const char *packet, uint packet_length);
86
 
 
87
 
void mysql_reset_thd_for_next_command(THD *thd);
88
 
 
89
 
void create_select_for_variable(const char *var_name);
90
 
 
91
 
void mysql_init_multi_delete(LEX *lex);
92
 
 
93
 
bool multi_delete_set_locks_and_link_aux_tables(LEX *lex);
94
 
 
95
 
void init_update_queries(void);
96
 
 
97
 
bool do_command(THD *thd);
98
 
 
99
 
bool dispatch_command(enum enum_server_command command, THD *thd,
100
 
                      char* packet, uint packet_length);
101
 
 
102
 
void log_slow_statement(THD *thd);
103
 
 
104
 
bool append_file_to_dir(THD *thd, const char **filename_ptr, 
105
 
                        const char *table_name);
106
 
 
107
 
bool reload_cache(THD *thd, ulong options, TABLE_LIST *tables, bool *write_to_binlog);
108
 
 
109
 
bool check_simple_select();
110
 
 
111
 
/* @TODO <UNUSED> */
112
 
void mysql_init_select(LEX *lex);
113
 
bool mysql_new_select(LEX *lex, bool move_down);
114
 
void init_max_user_conn(void);
115
 
void free_max_user_conn(void);
116
 
pthread_handler_t handle_bootstrap(void *arg);
117
 
int mysql_execute_command(THD *thd);
118
 
bool check_dup(const char *db, const char *name, TABLE_LIST *tables);
119
 
bool check_table_access(THD *thd, ulong want_access, TABLE_LIST *tables,
120
 
                        bool no_errors,
121
 
                        bool any_combination_of_privileges_will_do,
122
 
                        uint number);
123
 
/*
124
 
  General routine to change field->ptr of a NULL-terminated array of Field
125
 
  objects. Useful when needed to call val_int, val_str or similar and the
126
 
  field data is not in table->record[0] but in some other structure.
127
 
  set_key_field_ptr changes all fields of an index using a key_info object.
128
 
  All methods presume that there is at least one field to change.
129
 
*/
130
 
void set_field_ptr(Field **ptr, const uchar *new_buf, const uchar *old_buf);
131
 
void set_key_field_ptr(KEY *key_info, const uchar *new_buf,
132
 
                       const uchar *old_buf);
133
 
/* </UNUSED> */
134
 
 
135
 
/* sql_update.cc */
136
 
bool compare_record(TABLE *table);
137
 
 
138
 
/* sql_base.cc */
139
 
void table_cache_free(void);
140
 
bool table_cache_init(void);
141
 
bool table_def_init(void);
142
 
void table_def_free(void);
143
 
void assign_new_table_id(TABLE_SHARE *share);
144
 
uint cached_open_tables(void);
145
 
uint cached_table_definitions(void);
146
 
 
147
 
/* drizzled.cc */
148
 
void kill_mysql(void);
149
 
void close_connection(THD *thd, uint errcode, bool lock);
150
 
 
151
 
/* sql_select.cc */
152
 
TABLE *create_virtual_tmp_table(THD *thd, List<Create_field> &field_list);
153
 
 
154
 
/* handler.cc */
155
 
bool mysql_xa_recover(THD *thd);
156
 
 
157
 
SORT_FIELD * make_unireg_sortorder(ORDER *order, uint *length,
158
 
                                  SORT_FIELD *sortorder);
159
 
int setup_order(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
160
 
                List<Item> &fields, List <Item> &all_fields, ORDER *order);
161
 
int setup_group(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
162
 
                List<Item> &fields, List<Item> &all_fields, ORDER *order,
163
 
                bool *hidden_group_fields);
164
 
bool fix_inner_refs(THD *thd, List<Item> &all_fields, SELECT_LEX *select,
165
 
                   Item **ref_pointer_array);
166
 
 
167
 
bool handle_select(THD *thd, LEX *lex, select_result *result,
168
 
                   ulong setup_tables_done_option);
169
 
bool mysql_select(THD *thd, Item ***rref_pointer_array,
170
 
                  TABLE_LIST *tables, uint wild_num,  List<Item> &list,
171
 
                  COND *conds, uint og_num, ORDER *order, ORDER *group,
172
 
                  Item *having, ORDER *proc_param, uint64_t select_type, 
173
 
                  select_result *result, SELECT_LEX_UNIT *unit, 
174
 
                  SELECT_LEX *select_lex);
175
 
void free_underlaid_joins(THD *thd, SELECT_LEX *select);
176
 
bool mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit,
177
 
                         select_result *result);
178
 
int mysql_explain_select(THD *thd, SELECT_LEX *sl, char const *type,
179
 
                         select_result *result);
180
 
bool mysql_union(THD *thd, LEX *lex, select_result *result,
181
 
                 SELECT_LEX_UNIT *unit, ulong setup_tables_done_option);
182
 
bool mysql_handle_derived(LEX *lex, bool (*processor)(THD *thd,
183
 
                                                      LEX *lex,
184
 
                                                      TABLE_LIST *table));
185
 
bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *t);
186
 
bool mysql_derived_filling(THD *thd, LEX *lex, TABLE_LIST *t);
187
 
Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
188
 
                        Item ***copy_func, Field **from_field,
189
 
                        Field **def_field,
190
 
                        bool group, bool modify_item,
191
 
                        bool table_cant_handle_bit_fields,
192
 
                        bool make_copy_field,
193
 
                        uint convert_blob_length);
194
 
void sp_prepare_create_field(THD *thd, Create_field *sql_field);
195
 
int prepare_create_field(Create_field *sql_field, 
196
 
                         uint *blob_columns, 
197
 
                         int *timestamps, int *timestamps_with_niladic,
198
 
                         int64_t table_flags);
199
 
bool mysql_create_table(THD *thd,const char *db, const char *table_name,
200
 
                        HA_CREATE_INFO *create_info,
201
 
                        Alter_info *alter_info,
202
 
                        bool tmp_table, uint select_field_count);
203
 
bool mysql_create_table_no_lock(THD *thd, const char *db,
204
 
                                const char *table_name,
205
 
                                HA_CREATE_INFO *create_info,
206
 
                                Alter_info *alter_info,
207
 
                                bool tmp_table, uint select_field_count);
208
 
 
209
 
bool mysql_alter_table(THD *thd, char *new_db, char *new_name,
210
 
                       HA_CREATE_INFO *create_info,
211
 
                       TABLE_LIST *table_list,
212
 
                       Alter_info *alter_info,
213
 
                       uint order_num, ORDER *order, bool ignore);
214
 
bool mysql_recreate_table(THD *thd, TABLE_LIST *table_list);
215
 
bool mysql_create_like_table(THD *thd, TABLE_LIST *table,
216
 
                             TABLE_LIST *src_table,
217
 
                             HA_CREATE_INFO *create_info);
218
 
bool mysql_rename_table(handlerton *base, const char *old_db,
219
 
                        const char * old_name, const char *new_db,
220
 
                        const char * new_name, uint flags);
221
 
bool mysql_prepare_update(THD *thd, TABLE_LIST *table_list,
222
 
                          Item **conds, uint order_num, ORDER *order);
223
 
int mysql_update(THD *thd,TABLE_LIST *tables,List<Item> &fields,
224
 
                 List<Item> &values,COND *conds,
225
 
                 uint order_num, ORDER *order, ha_rows limit,
226
 
                 enum enum_duplicates handle_duplicates, bool ignore);
227
 
bool mysql_multi_update(THD *thd, TABLE_LIST *table_list,
228
 
                        List<Item> *fields, List<Item> *values,
229
 
                        COND *conds, uint64_t options,
230
 
                        enum enum_duplicates handle_duplicates, bool ignore,
231
 
                        SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex);
232
 
bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list, TABLE *table,
233
 
                          List<Item> &fields, List_item *values,
234
 
                          List<Item> &update_fields,
235
 
                          List<Item> &update_values, enum_duplicates duplic,
236
 
                          COND **where, bool select_insert,
237
 
                          bool check_fields, bool abort_on_warning);
238
 
bool mysql_insert(THD *thd,TABLE_LIST *table,List<Item> &fields,
239
 
                  List<List_item> &values, List<Item> &update_fields,
240
 
                  List<Item> &update_values, enum_duplicates flag,
241
 
                  bool ignore);
242
 
int check_that_all_fields_are_given_values(THD *thd, TABLE *entry,
243
 
                                           TABLE_LIST *table_list);
244
 
void prepare_triggers_for_insert_stmt(TABLE *table);
245
 
int mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds);
246
 
bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
247
 
                  SQL_LIST *order, ha_rows rows, uint64_t options,
248
 
                  bool reset_auto_increment);
249
 
bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok);
250
 
uint create_table_def_key(THD *thd, char *key, TABLE_LIST *table_list,
251
 
                          bool tmp_table);
252
 
TABLE_SHARE *get_table_share(THD *thd, TABLE_LIST *table_list, char *key,
253
 
                             uint key_length, uint db_flags, int *error);
254
 
void release_table_share(TABLE_SHARE *share, enum release_type type);
255
 
TABLE_SHARE *get_cached_table_share(const char *db, const char *table_name);
256
 
TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type update,
257
 
                   uint lock_flags);
258
 
TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT* mem,
259
 
                  bool *refresh, uint flags);
260
 
bool name_lock_locked_table(THD *thd, TABLE_LIST *tables);
261
 
bool reopen_name_locked_table(THD* thd, TABLE_LIST* table_list, bool link_in);
262
 
TABLE *table_cache_insert_placeholder(THD *thd, const char *key,
263
 
                                      uint key_length);
264
 
bool lock_table_name_if_not_cached(THD *thd, const char *db,
265
 
                                   const char *table_name, TABLE **table);
266
 
TABLE *find_locked_table(THD *thd, const char *db,const char *table_name);
267
 
void detach_merge_children(TABLE *table, bool clear_refs);
268
 
bool fix_merge_after_open(TABLE_LIST *old_child_list, TABLE_LIST **old_last,
269
 
                          TABLE_LIST *new_child_list, TABLE_LIST **new_last);
270
 
bool reopen_table(TABLE *table);
271
 
bool reopen_tables(THD *thd,bool get_locks,bool in_refresh);
272
 
void close_data_files_and_morph_locks(THD *thd, const char *db,
273
 
                                      const char *table_name);
274
 
void close_handle_and_leave_table_as_lock(TABLE *table);
275
 
bool open_new_frm(THD *thd, TABLE_SHARE *share, const char *alias,
276
 
                  uint db_stat, uint prgflag,
277
 
                  uint ha_open_flags, TABLE *outparam,
278
 
                  TABLE_LIST *table_desc, MEM_ROOT *mem_root);
279
 
bool wait_for_tables(THD *thd);
280
 
bool table_is_used(TABLE *table, bool wait_for_name_lock);
281
 
TABLE *drop_locked_tables(THD *thd,const char *db, const char *table_name);
282
 
void abort_locked_tables(THD *thd,const char *db, const char *table_name);
283
 
void execute_init_command(THD *thd, sys_var_str *init_command_var,
284
 
                          rw_lock_t *var_mutex);
285
 
extern Field *not_found_field;
286
 
extern Field *view_ref_found;
287
 
 
288
 
enum find_item_error_report_type {REPORT_ALL_ERRORS, REPORT_EXCEPT_NOT_FOUND,
289
 
                                  IGNORE_ERRORS, REPORT_EXCEPT_NON_UNIQUE,
290
 
                                  IGNORE_EXCEPT_NON_UNIQUE};
291
 
Field *
292
 
find_field_in_tables(THD *thd, Item_ident *item,
293
 
                     TABLE_LIST *first_table, TABLE_LIST *last_table,
294
 
                     Item **ref, find_item_error_report_type report_error,
295
 
                     bool check_privileges, bool register_tree_change);
296
 
Field *
297
 
find_field_in_table_ref(THD *thd, TABLE_LIST *table_list,
298
 
                        const char *name, uint length,
299
 
                        const char *item_name, const char *db_name,
300
 
                        const char *table_name, Item **ref,
301
 
                        bool check_privileges, bool allow_rowid,
302
 
                        uint *cached_field_index_ptr,
303
 
                        bool register_tree_change, TABLE_LIST **actual_table);
304
 
Field *
305
 
find_field_in_table(THD *thd, TABLE *table, const char *name, uint length,
306
 
                    bool allow_rowid, uint *cached_field_index_ptr);
307
 
Field *
308
 
find_field_in_table_sef(TABLE *table, const char *name);
309
 
 
310
 
/* sql_do.cc */
311
 
bool mysql_do(THD *thd, List<Item> &values);
312
 
 
313
 
/* sql_analyse.h */
314
 
bool append_escaped(String *to_str, String *from_str);
315
 
 
316
 
#include <drizzled/show.h>
317
 
 
318
 
/* information schema */
319
 
extern LEX_STRING INFORMATION_SCHEMA_NAME;
320
 
/* log tables */
321
 
extern LEX_STRING DRIZZLE_SCHEMA_NAME;
322
 
extern LEX_STRING GENERAL_LOG_NAME;
323
 
extern LEX_STRING SLOW_LOG_NAME;
324
 
 
325
 
extern const LEX_STRING partition_keywords[];
326
 
ST_SCHEMA_TABLE *find_schema_table(THD *thd, const char* table_name);
327
 
ST_SCHEMA_TABLE *get_schema_table(enum enum_schema_tables schema_table_idx);
328
 
int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident,
329
 
                         enum enum_schema_tables schema_table_idx);
330
 
int make_schema_select(THD *thd,  SELECT_LEX *sel,
331
 
                       enum enum_schema_tables schema_table_idx);
332
 
int mysql_schema_table(THD *thd, LEX *lex, TABLE_LIST *table_list);
333
 
bool get_schema_tables_result(JOIN *join,
334
 
                              enum enum_schema_table_state executed_place);
335
 
enum enum_schema_tables get_schema_table_idx(ST_SCHEMA_TABLE *schema_table);
336
 
 
337
 
#define is_schema_db(X) \
338
 
  !my_strcasecmp(system_charset_info, INFORMATION_SCHEMA_NAME.str, (X))
339
 
 
340
 
/* sql_handler.cc */
341
 
bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen);
342
 
bool mysql_ha_close(THD *thd, TABLE_LIST *tables);
343
 
bool mysql_ha_read(THD *, TABLE_LIST *,enum enum_ha_read_modes,char *,
344
 
                   List<Item> *,enum ha_rkey_function,Item *,ha_rows,ha_rows);
345
 
void mysql_ha_flush(THD *thd);
346
 
void mysql_ha_rm_tables(THD *thd, TABLE_LIST *tables, bool is_locked);
347
 
void mysql_ha_cleanup(THD *thd);
348
 
 
349
 
/* sql_base.cc */
350
 
#define TMP_TABLE_KEY_EXTRA 8
351
 
void set_item_name(Item *item,char *pos,uint length);
352
 
bool add_field_to_list(THD *thd, LEX_STRING *field_name, enum enum_field_types type,
353
 
                       char *length, char *decimal,
354
 
                       uint type_modifier,
355
 
                       enum column_format_type column_format,
356
 
                       Item *default_value, Item *on_update_value,
357
 
                       LEX_STRING *comment,
358
 
                       char *change, List<String> *interval_list,
359
 
                       const CHARSET_INFO * const cs);
360
 
Create_field * new_create_field(THD *thd, char *field_name, enum_field_types type,
361
 
                                char *length, char *decimals,
362
 
                                uint type_modifier, 
363
 
                                Item *default_value, Item *on_update_value,
364
 
                                LEX_STRING *comment, char *change, 
365
 
                                List<String> *interval_list, CHARSET_INFO *cs);
366
 
void store_position_for_column(const char *name);
367
 
bool add_to_list(THD *thd, SQL_LIST &list,Item *group,bool asc);
368
 
bool push_new_name_resolution_context(THD *thd,
369
 
                                      TABLE_LIST *left_op,
370
 
                                      TABLE_LIST *right_op);
371
 
void add_join_on(TABLE_LIST *b,Item *expr);
372
 
void add_join_natural(TABLE_LIST *a,TABLE_LIST *b,List<String> *using_fields,
373
 
                      SELECT_LEX *lex);
374
 
bool add_proc_to_list(THD *thd, Item *item);
375
 
void unlink_open_table(THD *thd, TABLE *find, bool unlock);
376
 
void drop_open_table(THD *thd, TABLE *table, const char *db_name,
377
 
                     const char *table_name);
378
 
void update_non_unique_table_error(TABLE_LIST *update,
379
 
                                   const char *operation,
380
 
                                   TABLE_LIST *duplicate);
381
 
 
382
 
SQL_SELECT *make_select(TABLE *head, table_map const_tables,
383
 
                        table_map read_tables, COND *conds,
384
 
                        bool allow_null_cond,  int *error);
385
 
extern Item **not_found_item;
386
 
 
387
 
/*
388
 
  A set of constants used for checking non aggregated fields and sum
389
 
  functions mixture in the ONLY_FULL_GROUP_BY_MODE.
390
 
*/
391
 
#define NON_AGG_FIELD_USED  1
392
 
#define SUM_FUNC_USED       2
393
 
 
394
 
/*
395
 
  This enumeration type is used only by the function find_item_in_list
396
 
  to return the info on how an item has been resolved against a list
397
 
  of possibly aliased items.
398
 
  The item can be resolved: 
399
 
   - against an alias name of the list's element (RESOLVED_AGAINST_ALIAS)
400
 
   - against non-aliased field name of the list  (RESOLVED_WITH_NO_ALIAS)
401
 
   - against an aliased field name of the list   (RESOLVED_BEHIND_ALIAS)
402
 
   - ignoring the alias name in cases when SQL requires to ignore aliases
403
 
     (e.g. when the resolved field reference contains a table name or
404
 
     when the resolved item is an expression)   (RESOLVED_IGNORING_ALIAS)    
405
 
*/
406
 
enum enum_resolution_type {
407
 
  NOT_RESOLVED=0,
408
 
  RESOLVED_IGNORING_ALIAS,
409
 
  RESOLVED_BEHIND_ALIAS,
410
 
  RESOLVED_WITH_NO_ALIAS,
411
 
  RESOLVED_AGAINST_ALIAS
412
 
};
413
 
Item ** find_item_in_list(Item *item, List<Item> &items, uint *counter,
414
 
                          find_item_error_report_type report_error,
415
 
                          enum_resolution_type *resolution);
416
 
bool get_key_map_from_key_list(key_map *map, TABLE *table,
417
 
                               List<String> *index_list);
418
 
bool insert_fields(THD *thd, Name_resolution_context *context,
419
 
                   const char *db_name, const char *table_name,
420
 
                   List_iterator<Item> *it, bool any_privileges);
421
 
bool setup_tables(THD *thd, Name_resolution_context *context,
422
 
                  List<TABLE_LIST> *from_clause, TABLE_LIST *tables,
423
 
                  TABLE_LIST **leaves, bool select_insert);
424
 
bool setup_tables_and_check_access(THD *thd, 
425
 
                                   Name_resolution_context *context,
426
 
                                   List<TABLE_LIST> *from_clause, 
427
 
                                   TABLE_LIST *tables, 
428
 
                                   TABLE_LIST **leaves, 
429
 
                                   bool select_insert);
430
 
int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields,
431
 
               List<Item> *sum_func_list, uint wild_num);
432
 
bool setup_fields(THD *thd, Item** ref_pointer_array,
433
 
                  List<Item> &item, enum_mark_columns mark_used_columns,
434
 
                  List<Item> *sum_func_list, bool allow_sum_func);
435
 
inline bool setup_fields_with_no_wrap(THD *thd, Item **ref_pointer_array,
436
 
                                      List<Item> &item,
437
 
                                      enum_mark_columns mark_used_columns,
438
 
                                      List<Item> *sum_func_list,
439
 
                                      bool allow_sum_func)
440
 
{
441
 
  bool res;
442
 
  res= setup_fields(thd, ref_pointer_array, item, mark_used_columns, sum_func_list,
443
 
                    allow_sum_func);
444
 
  return res;
445
 
}
446
 
int setup_conds(THD *thd, TABLE_LIST *tables, TABLE_LIST *leaves,
447
 
                COND **conds);
448
 
int setup_ftfuncs(SELECT_LEX* select);
449
 
int init_ftfuncs(THD *thd, SELECT_LEX* select, bool no_order);
450
 
void wait_for_condition(THD *thd, pthread_mutex_t *mutex,
451
 
                        pthread_cond_t *cond);
452
 
int open_tables(THD *thd, TABLE_LIST **tables, uint *counter, uint flags);
453
 
/* open_and_lock_tables with optional derived handling */
454
 
int open_and_lock_tables_derived(THD *thd, TABLE_LIST *tables, bool derived);
455
 
/* simple open_and_lock_tables without derived handling */
456
 
inline int simple_open_n_lock_tables(THD *thd, TABLE_LIST *tables)
457
 
{
458
 
  return open_and_lock_tables_derived(thd, tables, false);
459
 
}
460
 
/* open_and_lock_tables with derived handling */
461
 
inline int open_and_lock_tables(THD *thd, TABLE_LIST *tables)
462
 
{
463
 
  return open_and_lock_tables_derived(thd, tables, true);
464
 
}
465
 
/* simple open_and_lock_tables without derived handling for single table */
466
 
TABLE *open_n_lock_single_table(THD *thd, TABLE_LIST *table_l,
467
 
                                thr_lock_type lock_type);
468
 
bool open_normal_and_derived_tables(THD *thd, TABLE_LIST *tables, uint flags);
469
 
int lock_tables(THD *thd, TABLE_LIST *tables, uint counter, bool *need_reopen);
470
 
int decide_logging_format(THD *thd, TABLE_LIST *tables);
471
 
TABLE *open_temporary_table(THD *thd, const char *path, const char *db,
472
 
                            const char *table_name, bool link_in_list,
473
 
                            open_table_mode open_mode);
474
 
bool rm_temporary_table(handlerton *base, char *path, bool frm_only);
475
 
void free_io_cache(TABLE *entry);
476
 
void intern_close_table(TABLE *entry);
477
 
bool close_thread_table(THD *thd, TABLE **table_ptr);
478
 
void close_temporary_tables(THD *thd);
479
 
void close_tables_for_reopen(THD *thd, TABLE_LIST **tables);
480
 
TABLE_LIST *find_table_in_list(TABLE_LIST *table,
481
 
                               TABLE_LIST *TABLE_LIST::*link,
482
 
                               const char *db_name,
483
 
                               const char *table_name);
484
 
TABLE_LIST *unique_table(THD *thd, TABLE_LIST *table, TABLE_LIST *table_list,
485
 
                         bool check_alias);
486
 
TABLE *find_temporary_table(THD *thd, const char *db, const char *table_name);
487
 
TABLE *find_temporary_table(THD *thd, TABLE_LIST *table_list);
488
 
int drop_temporary_table(THD *thd, TABLE_LIST *table_list);
489
 
void close_temporary_table(THD *thd, TABLE *table, bool free_share,
490
 
                           bool delete_table);
491
 
void close_temporary(TABLE *table, bool free_share, bool delete_table);
492
 
bool rename_temporary_table(THD* thd, TABLE *table, const char *new_db,
493
 
                            const char *table_name);
494
 
void remove_db_from_cache(const char *db);
495
 
void flush_tables();
496
 
bool is_equal(const LEX_STRING *a, const LEX_STRING *b);
497
 
char *make_default_log_name(char *buff,const char* log_ext);
498
 
 
499
 
/* bits for last argument to remove_table_from_cache() */
500
 
#define RTFC_NO_FLAG                0x0000
501
 
#define RTFC_OWNED_BY_THD_FLAG      0x0001
502
 
#define RTFC_WAIT_OTHER_THREAD_FLAG 0x0002
503
 
#define RTFC_CHECK_KILLED_FLAG      0x0004
504
 
bool remove_table_from_cache(THD *thd, const char *db, const char *table,
505
 
                             uint flags);
506
 
 
507
 
#define NORMAL_PART_NAME 0
508
 
#define TEMP_PART_NAME 1
509
 
#define RENAMED_PART_NAME 2
510
 
 
511
 
void mem_alloc_error(size_t size);
512
 
 
513
 
#define WFRM_WRITE_SHADOW 1
514
 
#define WFRM_INSTALL_SHADOW 2
515
 
#define WFRM_PACK_FRM 4
516
 
#define WFRM_KEEP_SHARE 8
517
 
 
518
 
bool close_cached_tables(THD *thd, TABLE_LIST *tables, bool have_lock,
519
 
                         bool wait_for_refresh, bool wait_for_placeholders);
520
 
bool close_cached_connection_tables(THD *thd, bool wait_for_refresh,
521
 
                                    LEX_STRING *connect_string,
522
 
                                    bool have_lock= false);
523
 
void copy_field_from_tmp_record(Field *field,int offset);
524
 
bool fill_record(THD * thd, List<Item> &fields, List<Item> &values, bool ignore_errors);
525
 
bool fill_record(THD *thd, Field **field, List<Item> &values, bool ignore_errors);
526
 
OPEN_TABLE_LIST *list_open_tables(THD *thd, const char *db, const char *wild);
527
 
 
528
 
inline TABLE_LIST *find_table_in_global_list(TABLE_LIST *table,
529
 
                                             const char *db_name,
530
 
                                             const char *table_name)
531
 
{
532
 
  return find_table_in_list(table, &TABLE_LIST::next_global,
533
 
                            db_name, table_name);
534
 
}
535
 
 
536
 
inline TABLE_LIST *find_table_in_local_list(TABLE_LIST *table,
537
 
                                            const char *db_name,
538
 
                                            const char *table_name)
539
 
{
540
 
  return find_table_in_list(table, &TABLE_LIST::next_local,
541
 
                            db_name, table_name);
542
 
}
543
 
 
544
 
 
545
 
/* sql_calc.cc */
546
 
bool eval_const_cond(COND *cond);
547
 
 
548
 
/* sql_load.cc */
549
 
int mysql_load(THD *thd, sql_exchange *ex, TABLE_LIST *table_list,
550
 
                List<Item> &fields_vars, List<Item> &set_fields,
551
 
                List<Item> &set_values_list,
552
 
                enum enum_duplicates handle_duplicates, bool ignore,
553
 
                bool local_file);
554
 
int write_record(THD *thd, TABLE *table, COPY_INFO *info);
555
 
 
556
 
 
557
 
/* sql_test.cc */
558
 
void print_where(COND *cond,const char *info, enum_query_type query_type);
559
 
void print_cached_tables(void);
560
 
void TEST_filesort(SORT_FIELD *sortorder,uint s_length);
561
 
void print_plan(JOIN* join,uint idx, double record_count, double read_time,
562
 
                double current_read_time, const char *info);
563
 
void print_keyuse_array(DYNAMIC_ARRAY *keyuse_array);
564
 
void dump_TABLE_LIST_graph(SELECT_LEX *select_lex, TABLE_LIST* tl);
565
 
void mysql_print_status();
566
 
 
567
 
/* key.cc */
568
 
int find_ref_key(KEY *key, uint key_count, uchar *record, Field *field,
569
 
                 uint *key_length, uint *keypart);
570
 
void key_copy(uchar *to_key, uchar *from_record, KEY *key_info, uint key_length);
571
 
void key_restore(uchar *to_record, uchar *from_key, KEY *key_info,
572
 
                 uint16_t key_length);
573
 
void key_zero_nulls(uchar *tuple, KEY *key_info);
574
 
bool key_cmp_if_same(TABLE *form,const uchar *key,uint index,uint key_length);
575
 
void key_unpack(String *to,TABLE *form,uint index);
576
 
bool is_key_used(TABLE *table, uint idx, const MY_BITMAP *fields);
577
 
int key_cmp(KEY_PART_INFO *key_part, const uchar *key, uint key_length);
578
 
extern "C" int key_rec_cmp(void *key_info, uchar *a, uchar *b);
579
 
 
580
 
bool init_errmessage(void);
581
 
File open_binlog(IO_CACHE *log, const char *log_file_name,
582
 
                 const char **errmsg);
583
 
 
584
 
/* mysqld.cc */
585
 
extern void MYSQLerror(const char*);
586
 
void refresh_status(THD *thd);
587
 
bool mysql_rm_tmp_tables(void);
588
 
void handle_connection_in_main_thread(THD *thd);
589
 
void create_thread_to_handle_connection(THD *thd);
590
 
void unlink_thd(THD *thd);
591
 
bool one_thread_per_connection_end(THD *thd, bool put_in_cache);
592
 
void flush_thread_cache();
593
 
 
594
 
/* item_func.cc */
595
 
extern bool check_reserved_words(LEX_STRING *name);
596
 
extern enum_field_types agg_field_type(Item **items, uint nitems);
597
 
 
598
 
/* strfunc.cc */
599
 
uint64_t find_set(TYPELIB *lib, const char *x, uint length, const CHARSET_INFO * const cs,
600
 
                   char **err_pos, uint *err_len, bool *set_warning);
601
 
uint find_type(const TYPELIB *lib, const char *find, uint length,
602
 
               bool part_match);
603
 
uint find_type2(const TYPELIB *lib, const char *find, uint length,
604
 
                const CHARSET_INFO *cs);
605
 
void unhex_type2(TYPELIB *lib);
606
 
uint check_word(TYPELIB *lib, const char *val, const char *end,
607
 
                const char **end_of_word);
608
 
int find_string_in_array(LEX_STRING * const haystack, LEX_STRING * const needle,
609
 
                         const CHARSET_INFO * const cs);
610
 
 
611
 
 
612
 
bool is_keyword(const char *name, uint len);
613
 
 
614
 
#define MY_DB_OPT_FILE "db.opt"
615
 
bool my_database_names_init(void);
616
 
void my_database_names_free(void);
617
 
bool check_db_dir_existence(const char *db_name);
618
 
bool load_db_opt(THD *thd, const char *path, HA_CREATE_INFO *create);
619
 
bool load_db_opt_by_name(THD *thd, const char *db_name,
620
 
                         HA_CREATE_INFO *db_create_info);
621
 
const CHARSET_INFO *get_default_db_collation(THD *thd, const char *db_name);
622
 
bool my_dbopt_init(void);
623
 
void my_dbopt_cleanup(void);
624
 
extern int creating_database; // How many database locks are made
625
 
extern int creating_table;    // How many mysql_create_table() are running
626
 
 
627
 
/*
628
 
  External variables
629
 
*/
630
 
 
631
 
extern time_t server_start_time, flush_status_time;
632
 
extern char *opt_mysql_tmpdir, mysql_charsets_dir[];
633
 
            
634
 
#define mysql_tmpdir (my_tmpdir(&mysql_tmpdir_list))
635
 
extern MY_TMPDIR mysql_tmpdir_list;
636
 
extern const LEX_STRING command_name[];
637
 
extern const char *first_keyword, *my_localhost, *delayed_user, *binary_keyword;
638
 
extern const char *myisam_recover_options_str;
639
 
extern const char *in_left_expr_name, *in_additional_cond, *in_having_cond;
640
 
extern const char * const TRG_EXT;
641
 
extern const char * const TRN_EXT;
642
 
extern Eq_creator eq_creator;
643
 
extern Ne_creator ne_creator;
644
 
extern Gt_creator gt_creator;
645
 
extern Lt_creator lt_creator;
646
 
extern Ge_creator ge_creator;
647
 
extern Le_creator le_creator;
648
 
extern char language[FN_REFLEN];
649
 
extern char glob_hostname[FN_REFLEN], mysql_home[FN_REFLEN];
650
 
extern char pidfile_name[FN_REFLEN], system_time_zone[30], *opt_init_file;
651
 
extern char log_error_file[FN_REFLEN], *opt_tc_log_file;
652
 
extern const double log_10[309];
653
 
extern uint64_t log_10_int[20];
654
 
extern uint64_t keybuff_size;
655
 
extern uint64_t thd_startup_options;
656
 
extern ulong thread_id;
657
 
extern ulong binlog_cache_use, binlog_cache_disk_use;
658
 
extern ulong aborted_threads,aborted_connects;
659
 
extern ulong slave_open_temp_tables;
660
 
extern ulong slow_launch_threads, slow_launch_time;
661
 
extern ulong table_cache_size, table_def_size;
662
 
extern ulong max_connections,max_connect_errors, connect_timeout;
663
 
extern bool slave_allow_batching;
664
 
extern ulong slave_net_timeout, slave_trans_retries;
665
 
extern uint max_user_connections;
666
 
extern ulong what_to_log,flush_time;
667
 
extern ulong query_buff_size;
668
 
extern ulong binlog_cache_size, max_binlog_cache_size, open_files_limit;
669
 
extern ulong max_binlog_size, max_relay_log_size;
670
 
extern ulong opt_binlog_rows_event_max_size;
671
 
extern ulong rpl_recovery_rank, thread_cache_size, thread_pool_size;
672
 
extern ulong back_log;
673
 
extern ulong current_pid;
674
 
extern ulong expire_logs_days, sync_binlog_period, sync_binlog_counter;
675
 
extern ulong opt_tc_log_size, tc_log_max_pages_used, tc_log_page_size;
676
 
extern ulong tc_log_page_waits;
677
 
extern bool relay_log_purge;
678
 
extern bool opt_innodb_safe_binlog, opt_innodb;
679
 
extern uint test_flags,select_errors,ha_open_options;
680
 
extern uint protocol_version, mysqld_port, dropping_tables;
681
 
extern uint delay_key_write_options;
682
 
extern bool opt_endinfo, using_udf_functions;
683
 
extern bool locked_in_memory;
684
 
extern bool opt_using_transactions;
685
 
extern bool using_update_log, server_id_supplied;
686
 
extern bool opt_update_log, opt_bin_log, opt_error_log;
687
 
extern bool opt_log; 
688
 
extern bool opt_slow_log;
689
 
extern ulong log_output_options;
690
 
extern bool opt_log_queries_not_using_indexes;
691
 
extern bool opt_character_set_client_handshake;
692
 
extern bool volatile abort_loop, shutdown_in_progress;
693
 
extern uint volatile thread_count, thread_running, global_read_lock;
694
 
extern uint connection_count;
695
 
extern bool opt_sql_bin_update;
696
 
extern bool opt_safe_user_create;
697
 
extern bool opt_no_mix_types;
698
 
extern bool opt_safe_show_db, opt_myisam_use_mmap;
699
 
extern bool opt_local_infile;
700
 
extern bool opt_slave_compressed_protocol;
701
 
extern bool use_temp_pool;
702
 
extern ulong slave_exec_mode_options;
703
 
extern bool opt_readonly;
704
 
extern bool opt_sync_frm;
705
 
extern bool opt_secure_auth;
706
 
extern char* opt_secure_file_priv;
707
 
extern bool opt_log_slow_admin_statements;
708
 
extern bool opt_log_slow_slave_statements;
709
 
extern bool opt_noacl;
710
 
extern bool opt_old_style_user_limits;
711
 
extern uint opt_crash_binlog_innodb;
712
 
extern char *default_tz_name;
713
 
extern char *opt_logname, *opt_slow_logname;
714
 
extern const char *log_output_str;
715
 
 
716
 
extern DRIZZLE_BIN_LOG mysql_bin_log;
717
 
extern LOGGER logger;
718
 
extern TABLE_LIST general_log, slow_log;
719
 
extern FILE *stderror_file;
720
 
extern pthread_key(MEM_ROOT**,THR_MALLOC);
721
 
extern pthread_mutex_t LOCK_mysql_create_db,LOCK_open, LOCK_lock_db,
722
 
       LOCK_thread_count,LOCK_mapped_file,LOCK_user_locks, LOCK_status,
723
 
       LOCK_error_log, LOCK_uuid_generator,
724
 
       LOCK_crypt, LOCK_timezone,
725
 
       LOCK_slave_list, LOCK_active_mi, LOCK_global_read_lock,
726
 
       LOCK_global_system_variables, LOCK_user_conn,
727
 
       LOCK_bytes_sent, LOCK_bytes_received, LOCK_connection_count;
728
 
extern pthread_mutex_t LOCK_server_started;
729
 
extern rw_lock_t LOCK_sys_init_connect, LOCK_sys_init_slave;
730
 
extern rw_lock_t LOCK_system_variables_hash;
731
 
extern pthread_cond_t COND_refresh, COND_thread_count, COND_manager;
732
 
extern pthread_cond_t COND_global_read_lock;
733
 
extern pthread_attr_t connection_attrib;
734
 
extern I_List<THD> threads;
735
 
extern I_List<NAMED_LIST> key_caches;
736
 
extern MY_BITMAP temp_pool;
737
 
extern String my_empty_string;
738
 
extern const String my_null_string;
739
 
extern SHOW_VAR status_vars[];
740
 
extern struct system_variables max_system_variables;
741
 
extern struct system_status_var global_status_var;
742
 
extern struct rand_struct sql_rand;
743
 
 
744
 
extern const char *opt_date_time_formats[];
745
 
extern KNOWN_DATE_TIME_FORMAT known_date_time_formats[];
746
 
 
747
 
extern String null_string;
748
 
extern HASH open_cache, lock_db_cache;
749
 
extern TABLE *unused_tables;
750
 
extern const char* any_db;
751
 
extern struct my_option my_long_options[];
752
 
extern const LEX_STRING view_type;
753
 
extern scheduler_functions thread_scheduler;
754
 
extern TYPELIB thread_handling_typelib;
755
 
extern uint8_t uc_update_queries[SQLCOM_END+1];
756
 
extern uint sql_command_flags[];
757
 
extern TYPELIB log_output_typelib;
758
 
 
759
 
/* optional things, have_* variables */
760
 
extern SHOW_COMP_OPTION have_community_features;
761
 
 
762
 
extern handlerton *myisam_hton;
763
 
extern handlerton *heap_hton;
764
 
 
765
 
extern SHOW_COMP_OPTION have_symlink;
766
 
extern SHOW_COMP_OPTION have_compress;
767
 
 
768
 
 
769
 
extern pthread_t signal_thread;
770
 
 
771
 
DRIZZLE_LOCK *mysql_lock_tables(THD *thd, TABLE **table, uint count,
772
 
                              uint flags, bool *need_reopen);
773
 
/* mysql_lock_tables() and open_table() flags bits */
774
 
#define DRIZZLE_LOCK_IGNORE_GLOBAL_READ_LOCK      0x0001
775
 
#define DRIZZLE_LOCK_IGNORE_FLUSH                 0x0002
776
 
#define DRIZZLE_LOCK_NOTIFY_IF_NEED_REOPEN        0x0004
777
 
#define DRIZZLE_OPEN_TEMPORARY_ONLY               0x0008
778
 
#define DRIZZLE_LOCK_IGNORE_GLOBAL_READ_ONLY      0x0010
779
 
#define DRIZZLE_LOCK_PERF_SCHEMA                  0x0020
780
 
 
781
 
void mysql_unlock_tables(THD *thd, DRIZZLE_LOCK *sql_lock);
782
 
void mysql_unlock_read_tables(THD *thd, DRIZZLE_LOCK *sql_lock);
783
 
void mysql_unlock_some_tables(THD *thd, TABLE **table,uint count);
784
 
void mysql_lock_remove(THD *thd, DRIZZLE_LOCK *locked,TABLE *table,
785
 
                       bool always_unlock);
786
 
void mysql_lock_abort(THD *thd, TABLE *table, bool upgrade_lock);
787
 
void mysql_lock_downgrade_write(THD *thd, TABLE *table,
788
 
                                thr_lock_type new_lock_type);
789
 
bool mysql_lock_abort_for_thread(THD *thd, TABLE *table);
790
 
DRIZZLE_LOCK *mysql_lock_merge(DRIZZLE_LOCK *a,DRIZZLE_LOCK *b);
791
 
TABLE_LIST *mysql_lock_have_duplicate(THD *thd, TABLE_LIST *needle,
792
 
                                      TABLE_LIST *haystack);
793
 
bool lock_global_read_lock(THD *thd);
794
 
void unlock_global_read_lock(THD *thd);
795
 
bool wait_if_global_read_lock(THD *thd, bool abort_on_refresh,
796
 
                              bool is_not_commit);
797
 
void start_waiting_global_read_lock(THD *thd);
798
 
bool make_global_read_lock_block_commit(THD *thd);
799
 
bool set_protect_against_global_read_lock(void);
800
 
void unset_protect_against_global_read_lock(void);
801
 
void broadcast_refresh(void);
802
 
int try_transactional_lock(THD *thd, TABLE_LIST *table_list);
803
 
int check_transactional_lock(THD *thd, TABLE_LIST *table_list);
804
 
int set_handler_table_locks(THD *thd, TABLE_LIST *table_list,
805
 
                            bool transactional);
806
 
 
807
 
/* Lock based on name */
808
 
int lock_and_wait_for_table_name(THD *thd, TABLE_LIST *table_list);
809
 
int lock_table_name(THD *thd, TABLE_LIST *table_list, bool check_in_use);
810
 
void unlock_table_name(THD *thd, TABLE_LIST *table_list);
811
 
bool wait_for_locked_table_names(THD *thd, TABLE_LIST *table_list);
812
 
bool lock_table_names(THD *thd, TABLE_LIST *table_list);
813
 
void unlock_table_names(THD *thd, TABLE_LIST *table_list,
814
 
                        TABLE_LIST *last_table);
815
 
bool lock_table_names_exclusively(THD *thd, TABLE_LIST *table_list);
816
 
bool is_table_name_exclusively_locked_by_this_thread(THD *thd, 
817
 
                                                     TABLE_LIST *table_list);
818
 
bool is_table_name_exclusively_locked_by_this_thread(THD *thd, uchar *key,
819
 
                                                     int key_length);
820
 
 
821
 
 
822
 
/* old unireg functions */
823
 
 
824
 
void unireg_init(ulong options);
825
 
void unireg_end(void) __attribute__((noreturn));
826
 
bool mysql_create_frm(THD *thd, const char *file_name,
827
 
                      const char *db, const char *table,
828
 
                      HA_CREATE_INFO *create_info,
829
 
                      List<Create_field> &create_field,
830
 
                      uint key_count,KEY *key_info,handler *db_type);
831
 
int rea_create_table(THD *thd, const char *path,
832
 
                     const char *db, const char *table_name,
833
 
                     HA_CREATE_INFO *create_info,
834
 
                     List<Create_field> &create_field,
835
 
                     uint key_count,KEY *key_info,
836
 
                     handler *file);
837
 
int format_number(uint inputflag,uint max_length,char * pos,uint length,
838
 
                  char * *errpos);
839
 
 
840
 
/* table.cc */
841
 
TABLE_SHARE *alloc_table_share(TABLE_LIST *table_list, char *key,
842
 
                               uint key_length);
843
 
void init_tmp_table_share(THD *thd, TABLE_SHARE *share, const char *key,
844
 
                          uint key_length,
845
 
                          const char *table_name, const char *path);
846
 
void free_table_share(TABLE_SHARE *share);
847
 
int open_table_def(THD *thd, TABLE_SHARE *share, uint db_flags);
848
 
void open_table_error(TABLE_SHARE *share, int error, int db_errno, int errarg);
849
 
int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias,
850
 
                          uint db_stat, uint prgflag, uint ha_open_flags,
851
 
                          TABLE *outparam, open_table_mode open_mode);
852
 
int readfrm(const char *name, uchar **data, size_t *length);
853
 
int writefrm(const char* name, const uchar* data, size_t len);
854
 
int closefrm(TABLE *table, bool free_share);
855
 
int read_string(File file, uchar* *to, size_t length);
856
 
void free_blobs(TABLE *table);
857
 
int set_zone(int nr,int min_zone,int max_zone);
858
 
ulong convert_period_to_month(ulong period);
859
 
ulong convert_month_to_period(ulong month);
860
 
void get_date_from_daynr(long daynr,uint *year, uint *month,
861
 
                         uint *day);
862
 
my_time_t TIME_to_timestamp(THD *thd, const DRIZZLE_TIME *t, bool *not_exist);
863
 
bool str_to_time_with_warn(const char *str,uint length,DRIZZLE_TIME *l_time);
864
 
timestamp_type str_to_datetime_with_warn(const char *str, uint length,
865
 
                                         DRIZZLE_TIME *l_time, uint flags);
866
 
void localtime_to_TIME(DRIZZLE_TIME *to, struct tm *from);
867
 
void calc_time_from_sec(DRIZZLE_TIME *to, long seconds, long microseconds);
868
 
 
869
 
void make_truncated_value_warning(THD *thd, DRIZZLE_ERROR::enum_warning_level level,
870
 
                                  const char *str_val,
871
 
                                  uint str_length, timestamp_type time_type,
872
 
                                  const char *field_name);
873
 
 
874
 
bool date_add_interval(DRIZZLE_TIME *ltime, interval_type int_type, INTERVAL interval);
875
 
bool calc_time_diff(DRIZZLE_TIME *l_time1, DRIZZLE_TIME *l_time2, int l_sign,
876
 
                    int64_t *seconds_out, long *microseconds_out);
877
 
 
878
 
extern LEX_STRING interval_type_to_name[];
879
 
 
880
 
extern DATE_TIME_FORMAT *date_time_format_make(timestamp_type format_type,
881
 
                                               const char *format_str,
882
 
                                               uint format_length);
883
 
extern DATE_TIME_FORMAT *date_time_format_copy(THD *thd,
884
 
                                               DATE_TIME_FORMAT *format);
885
 
const char *get_date_time_format_str(KNOWN_DATE_TIME_FORMAT *format,
886
 
                                     timestamp_type type);
887
 
extern bool make_date_time(DATE_TIME_FORMAT *format, DRIZZLE_TIME *l_time,
888
 
                           timestamp_type type, String *str);
889
 
void make_datetime(const DATE_TIME_FORMAT *format, const DRIZZLE_TIME *l_time,
890
 
                   String *str);
891
 
void make_date(const DATE_TIME_FORMAT *format, const DRIZZLE_TIME *l_time,
892
 
               String *str);
893
 
void make_time(const DATE_TIME_FORMAT *format, const DRIZZLE_TIME *l_time,
894
 
               String *str);
895
 
int my_time_compare(DRIZZLE_TIME *a, DRIZZLE_TIME *b);
896
 
uint64_t get_datetime_value(THD *thd, Item ***item_arg, Item **cache_arg,
897
 
                             Item *warn_item, bool *is_null);
898
 
 
899
 
int test_if_number(char *str,int *res,bool allow_wildcards);
900
 
void change_byte(uchar *,uint,char,char);
901
 
void init_read_record(READ_RECORD *info, THD *thd, TABLE *reg_form,
902
 
                      SQL_SELECT *select,
903
 
                      int use_record_cache, bool print_errors);
904
 
void init_read_record_idx(READ_RECORD *info, THD *thd, TABLE *table, 
905
 
                          bool print_error, uint idx);
906
 
void end_read_record(READ_RECORD *info);
907
 
ha_rows filesort(THD *thd, TABLE *form,struct st_sort_field *sortorder,
908
 
                 uint s_length, SQL_SELECT *select,
909
 
                 ha_rows max_rows, bool sort_positions,
910
 
                 ha_rows *examined_rows);
911
 
void filesort_free_buffers(TABLE *table, bool full);
912
 
void change_double_for_sort(double nr,uchar *to);
913
 
double my_double_round(double value, int64_t dec, bool dec_unsigned,
914
 
                       bool truncate);
915
 
int get_quick_record(SQL_SELECT *select);
916
 
 
917
 
int calc_weekday(long daynr,bool sunday_first_day_of_week);
918
 
uint calc_week(DRIZZLE_TIME *l_time, uint week_behaviour, uint *year);
919
 
void find_date(char *pos,uint *vek,uint flag);
920
 
TYPELIB *convert_strings_to_array_type(char * *typelibs, char * *end);
921
 
TYPELIB *typelib(MEM_ROOT *mem_root, List<String> &strings);
922
 
ulong get_form_pos(File file, uchar *head, TYPELIB *save_names);
923
 
ulong make_new_entry(File file,uchar *fileinfo,TYPELIB *formnames,
924
 
                     const char *newname);
925
 
ulong next_io_size(ulong pos);
926
 
void append_unescaped(String *res, const char *pos, uint length);
927
 
int create_frm(THD *thd, const char *name, const char *db, const char *table,
928
 
               uint reclength, uchar *fileinfo,
929
 
               HA_CREATE_INFO *create_info, uint keys, KEY *key_info);
930
 
void update_create_info_from_table(HA_CREATE_INFO *info, TABLE *form);
931
 
int rename_file_ext(const char * from,const char * to,const char * ext);
932
 
bool check_db_name(LEX_STRING *db);
933
 
bool check_column_name(const char *name);
934
 
bool check_table_name(const char *name, uint length);
935
 
char *get_field(MEM_ROOT *mem, Field *field);
936
 
bool get_field(MEM_ROOT *mem, Field *field, class String *res);
937
 
char *fn_rext(char *name);
938
 
 
939
 
/* Conversion functions */
940
 
uint build_table_filename(char *buff, size_t bufflen, const char *db,
941
 
                          const char *table, const char *ext, uint flags);
942
 
 
943
 
#define MYSQL50_TABLE_NAME_PREFIX         "#mysql50#"
944
 
#define MYSQL50_TABLE_NAME_PREFIX_LENGTH  9
945
 
 
946
 
/* Flags for conversion functions. */
947
 
#define FN_FROM_IS_TMP  (1 << 0)
948
 
#define FN_TO_IS_TMP    (1 << 1)
949
 
#define FN_IS_TMP       (FN_FROM_IS_TMP | FN_TO_IS_TMP)
950
 
#define NO_FRM_RENAME   (1 << 2)
951
 
 
952
 
/* item_func.cc */
953
 
Item *get_system_var(THD *thd, enum_var_type var_type, LEX_STRING name,
954
 
                     LEX_STRING component);
955
 
int get_var_with_binlog(THD *thd, enum_sql_command sql_command,
956
 
                        LEX_STRING &name, user_var_entry **out_entry);
957
 
/* log.cc */
958
 
bool flush_error_log(void);
959
 
 
960
 
/* sql_list.cc */
961
 
void free_list(I_List <i_string_pair> *list);
962
 
void free_list(I_List <i_string> *list);
963
 
 
964
 
/* Some inline functions for more speed */
965
 
 
966
 
inline bool add_item_to_list(THD *thd, Item *item)
967
 
{
968
 
  return thd->lex->current_select->add_item_to_list(thd, item);
969
 
}
970
 
 
971
 
inline bool add_value_to_list(THD *thd, Item *value)
972
 
{
973
 
  return thd->lex->value_list.push_back(value);
974
 
}
975
 
 
976
 
inline bool add_order_to_list(THD *thd, Item *item, bool asc)
977
 
{
978
 
  return thd->lex->current_select->add_order_to_list(thd, item, asc);
979
 
}
980
 
 
981
 
inline bool add_group_to_list(THD *thd, Item *item, bool asc)
982
 
{
983
 
  return thd->lex->current_select->add_group_to_list(thd, item, asc);
984
 
}
985
 
 
986
 
inline void mark_as_null_row(TABLE *table)
987
 
{
988
 
  table->null_row=1;
989
 
  table->status|=STATUS_NULL_ROW;
990
 
  memset(table->null_flags, 255, table->s->null_bytes);
991
 
}
992
 
 
993
 
inline void table_case_convert(char * name, uint length)
994
 
{
995
 
  if (lower_case_table_names)
996
 
    files_charset_info->cset->casedn(files_charset_info,
997
 
                                     name, length, name, length);
998
 
}
999
 
 
1000
 
inline const char *table_case_name(HA_CREATE_INFO *info, const char *name)
1001
 
{
1002
 
  return ((lower_case_table_names == 2 && info->alias) ? info->alias : name);
1003
 
}
1004
 
 
1005
 
inline ulong sql_rnd()
1006
 
{
1007
 
  ulong tmp= (ulong) (rand() * 0xffffffff); /* make all bits random */
1008
 
 
1009
 
  return tmp;
1010
 
}
1011
 
 
1012
 
Comp_creator *comp_eq_creator(bool invert);
1013
 
Comp_creator *comp_ge_creator(bool invert);
1014
 
Comp_creator *comp_gt_creator(bool invert);
1015
 
Comp_creator *comp_le_creator(bool invert);
1016
 
Comp_creator *comp_lt_creator(bool invert);
1017
 
Comp_creator *comp_ne_creator(bool invert);
1018
 
 
1019
 
Item * all_any_subquery_creator(Item *left_expr,
1020
 
                                chooser_compare_func_creator cmp,
1021
 
                                bool all,
1022
 
                                SELECT_LEX *select_lex);
1023
 
 
1024
 
/**
1025
 
  clean/setup table fields and map.
1026
 
 
1027
 
  @param table        TABLE structure pointer (which should be setup)
1028
 
  @param table_list   TABLE_LIST structure pointer (owner of TABLE)
1029
 
  @param tablenr     table number
1030
 
*/
1031
 
inline void setup_table_map(TABLE *table, TABLE_LIST *table_list, uint tablenr)
1032
 
{
1033
 
  table->used_fields= 0;
1034
 
  table->const_table= 0;
1035
 
  table->null_row= 0;
1036
 
  table->status= STATUS_NO_RECORD;
1037
 
  table->maybe_null= table_list->outer_join;
1038
 
  TABLE_LIST *embedding= table_list->embedding;
1039
 
  while (!table->maybe_null && embedding)
1040
 
  {
1041
 
    table->maybe_null= embedding->outer_join;
1042
 
    embedding= embedding->embedding;
1043
 
  }
1044
 
  table->tablenr= tablenr;
1045
 
  table->map= (table_map) 1 << tablenr;
1046
 
  table->force_index= table_list->force_index;
1047
 
  table->covering_keys= table->s->keys_for_keyread;
1048
 
  table->merge_keys.clear_all();
1049
 
}
1050
 
 
1051
 
#include <drizzled/item_create.h>         /* Factory API for creating Item_* instances */
1052
 
 
1053
 
/**
1054
 
  convert a hex digit into number.
1055
 
*/
1056
 
 
1057
 
inline int hexchar_to_int(char c)
1058
 
{
1059
 
  if (c <= '9' && c >= '0')
1060
 
    return c-'0';
1061
 
  c|=32;
1062
 
  if (c <= 'f' && c >= 'a')
1063
 
    return c-'a'+10;
1064
 
  return -1;
1065
 
}
1066
 
 
1067
 
/**
1068
 
  return true if the table was created explicitly.
1069
 
*/
1070
 
inline bool is_user_table(TABLE * table)
1071
 
{
1072
 
  const char *name= table->s->table_name.str;
1073
 
  return strncmp(name, tmp_file_prefix, tmp_file_prefix_length);
1074
 
}
1075
 
 
1076
 
 
1077
 
#ifndef HAVE_LOG2
1078
 
/*
1079
 
  This will be slightly slower and perhaps a tiny bit less accurate than
1080
 
  doing it the IEEE754 way but log2() should be available on C99 systems.
1081
 
*/
1082
 
static inline double log2(double x)
1083
 
{
1084
 
  return (log(x) / M_LN2);
1085
 
}
1086
 
#endif
1087
 
 
1088
 
 
1089
 
/*
1090
 
  Some functions that are different in the embedded library and the normal
1091
 
  server
1092
 
*/
1093
 
 
1094
 
extern "C" void unireg_abort(int exit_code) __attribute__((noreturn));
1095
 
void kill_delayed_threads(void);
1096
 
bool check_stack_overrun(THD *thd, long margin, uchar *dummy);
1097
 
 
1098
 
/** 
1099
 
 * Used by handlers to store things in schema tables 
1100
 
 *
1101
 
 * @TODO These should be placed in an information_schema.h header
1102
 
 * file once the new information schema design is finalized.
1103
 
 */
1104
 
#define IS_FILES_FILE_ID              0
1105
 
#define IS_FILES_FILE_NAME            1
1106
 
#define IS_FILES_FILE_TYPE            2
1107
 
#define IS_FILES_TABLESPACE_NAME      3
1108
 
#define IS_FILES_TABLE_CATALOG        4
1109
 
#define IS_FILES_TABLE_SCHEMA         5
1110
 
#define IS_FILES_TABLE_NAME           6
1111
 
#define IS_FILES_LOGFILE_GROUP_NAME   7
1112
 
#define IS_FILES_LOGFILE_GROUP_NUMBER 8
1113
 
#define IS_FILES_ENGINE               9
1114
 
#define IS_FILES_FULLTEXT_KEYS       10
1115
 
#define IS_FILES_DELETED_ROWS        11
1116
 
#define IS_FILES_UPDATE_COUNT        12
1117
 
#define IS_FILES_FREE_EXTENTS        13
1118
 
#define IS_FILES_TOTAL_EXTENTS       14
1119
 
#define IS_FILES_EXTENT_SIZE         15
1120
 
#define IS_FILES_INITIAL_SIZE        16
1121
 
#define IS_FILES_MAXIMUM_SIZE        17
1122
 
#define IS_FILES_AUTOEXTEND_SIZE     18
1123
 
#define IS_FILES_CREATION_TIME       19
1124
 
#define IS_FILES_LAST_UPDATE_TIME    20
1125
 
#define IS_FILES_LAST_ACCESS_TIME    21
1126
 
#define IS_FILES_RECOVER_TIME        22
1127
 
#define IS_FILES_TRANSACTION_COUNTER 23
1128
 
#define IS_FILES_VERSION             24
1129
 
#define IS_FILES_ROW_FORMAT          25
1130
 
#define IS_FILES_TABLE_ROWS          26
1131
 
#define IS_FILES_AVG_ROW_LENGTH      27
1132
 
#define IS_FILES_DATA_LENGTH         28
1133
 
#define IS_FILES_MAX_DATA_LENGTH     29
1134
 
#define IS_FILES_INDEX_LENGTH        30
1135
 
#define IS_FILES_DATA_FREE           31
1136
 
#define IS_FILES_CREATE_TIME         32
1137
 
#define IS_FILES_UPDATE_TIME         33
1138
 
#define IS_FILES_CHECK_TIME          34
1139
 
#define IS_FILES_CHECKSUM            35
1140
 
#define IS_FILES_STATUS              36
1141
 
#define IS_FILES_EXTRA               37
1142
 
 
1143
 
#endif /* DRIZZLE_SERVER_SERVER_INCLUDES_H */