~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/server_includes.h

  • Committer: Monty Taylor
  • Date: 2008-10-10 23:04:21 UTC
  • mto: (509.1.1 codestyle)
  • mto: This revision was merged to the branch mainline in revision 511.
  • Revision ID: monty@inaugust.com-20081010230421-zohe1eppxievpw8d
RemovedĀ O_NOFOLLOW

Show diffs side-by-side

added added

removed removed

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