1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
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.
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.
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
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).
27
@TODO Name this file better. "priv" could mean private, privileged, privileges.
30
#ifndef DRIZZLED_SERVER_INCLUDES_H
31
#define DRIZZLED_SERVER_INCLUDES_H
33
/* Cross-platform portability code and standard includes */
34
#include <drizzled/global.h>
35
/* Contains system-wide constants and #defines */
36
#include <drizzled/definitions.h>
37
/* System-wide common data structures */
38
#include <drizzled/structs.h>
39
/* Defines for the storage engine handler -- i.e. HA_XXX defines */
40
/* Needed by field.h */
41
#include <drizzled/base.h>
43
/* Lots of system-wide struct definitions like IO_CACHE,
44
prototypes for all my_* functions */
45
#include <mysys/my_sys.h>
46
/* Custom C string functions */
47
#include <mystrings/m_string.h>
49
/* The <strong>INTERNAL</strong> plugin API - not the external, or public, server plugin API */
50
#include <drizzled/sql_plugin.h>
51
/* Range optimization API/library */
52
#include <drizzled/opt_range.h>
53
/* Simple error injection (crash) module */
54
#include <drizzled/error_injection.h>
55
/* Routines for dropping, repairing, checking schema tables */
56
#include <drizzled/sql_table.h>
58
/* Routines for printing error messages */
59
#include <drizzled/errmsg_print.h>
66
extern const CHARSET_INFO *system_charset_info, *files_charset_info ;
67
extern const CHARSET_INFO *national_charset_info, *table_alias_charset;
69
typedef class st_select_lex SELECT_LEX;
70
typedef struct st_mysql_lock DRIZZLE_LOCK;
71
typedef struct st_ha_create_information HA_CREATE_INFO;
73
/* information schema */
74
static const std::string INFORMATION_SCHEMA_NAME("information_schema");
79
void refresh_status(Session *session);
80
bool drizzle_rm_tmp_tables(void);
81
void handle_connection_in_main_thread(Session *session);
82
void create_thread_to_handle_connection(Session *session);
83
void unlink_session(Session *session);
84
bool one_thread_per_connection_end(Session *session, bool put_in_cache);
85
void flush_thread_cache();
88
extern bool check_reserved_words(LEX_STRING *name);
89
extern enum_field_types agg_field_type(Item **items, uint32_t nitems);
92
uint64_t find_set(TYPELIB *lib, const char *x, uint32_t length, const CHARSET_INFO * const cs,
93
char **err_pos, uint32_t *err_len, bool *set_warning);
94
uint32_t find_type(const TYPELIB *lib, const char *find, uint32_t length,
96
uint32_t find_type2(const TYPELIB *lib, const char *find, uint32_t length,
97
const CHARSET_INFO *cs);
98
void unhex_type2(TYPELIB *lib);
99
uint32_t check_word(TYPELIB *lib, const char *val, const char *end,
100
const char **end_of_word);
101
int find_string_in_array(LEX_STRING * const haystack, LEX_STRING * const needle,
102
const CHARSET_INFO * const cs);
105
bool is_keyword(const char *name, uint32_t len);
111
extern char *drizzle_tmpdir;
112
extern const LEX_STRING command_name[];
113
extern const char *first_keyword, *my_localhost, *delayed_user, *binary_keyword;
114
extern const char *myisam_recover_options_str;
115
extern const char *in_left_expr_name, *in_additional_cond, *in_having_cond;
116
extern const char * const TRG_EXT;
117
extern const char * const TRN_EXT;
118
extern char language[FN_REFLEN];
119
extern char glob_hostname[FN_REFLEN], drizzle_home[FN_REFLEN];
120
extern char pidfile_name[FN_REFLEN], system_time_zone[30], *opt_init_file;
121
extern char *opt_tc_log_file;
122
extern const double log_10[309];
123
extern uint64_t log_10_int[20];
124
extern uint64_t keybuff_size;
125
extern uint64_t session_startup_options;
126
extern ulong thread_id;
127
extern uint64_t binlog_cache_use;
128
extern uint64_t binlog_cache_disk_use;
129
extern uint64_t aborted_threads;
130
extern uint64_t aborted_connects;
131
extern uint64_t slave_open_temp_tables;
132
extern uint64_t slow_launch_threads;
133
extern uint64_t slow_launch_time;
134
extern uint64_t table_cache_size;
135
extern uint64_t table_def_size;
136
extern uint64_t max_connections;
137
extern uint64_t max_connect_errors;
138
extern uint64_t connect_timeout;
139
extern bool slave_allow_batching;
140
extern uint64_t slave_net_timeout;
141
extern uint64_t slave_trans_retries;
142
extern uint32_t max_user_connections;
143
extern ulong what_to_log;
144
extern uint64_t binlog_cache_size;
145
extern uint64_t max_binlog_cache_size;
146
extern uint64_t open_files_limit;
147
extern uint64_t max_binlog_size;
148
extern uint64_t max_relay_log_size;
149
extern uint64_t opt_binlog_rows_event_max_size;
150
extern uint64_t thread_pool_size;
151
extern uint32_t back_log;
152
extern pid_t current_pid;
153
extern uint64_t expire_logs_days;
154
extern uint64_t sync_binlog_period;
155
extern uint64_t tc_log_max_pages_used;
156
extern uint64_t tc_log_page_size;
157
extern uint64_t opt_tc_log_size;
158
extern uint64_t tc_log_page_waits;
159
extern bool relay_log_purge;
160
extern bool opt_innodb_safe_binlog, opt_innodb;
161
extern uint32_t test_flags,select_errors,ha_open_options;
162
extern uint32_t protocol_version, drizzled_port, dropping_tables;
163
extern uint32_t delay_key_write_options;
164
extern bool opt_endinfo, using_udf_functions;
165
extern bool locked_in_memory;
166
extern bool opt_using_transactions;
167
extern bool using_update_log, server_id_supplied;
168
extern bool opt_update_log, opt_bin_log;
170
extern bool opt_slow_log;
171
extern ulong log_output_options;
172
extern bool opt_character_set_client_handshake;
173
extern bool volatile abort_loop, shutdown_in_progress;
174
extern uint32_t volatile thread_count, thread_running, global_read_lock;
175
extern uint32_t connection_count;
176
extern bool opt_sql_bin_update;
177
extern bool opt_safe_user_create;
178
extern bool opt_no_mix_types;
179
extern bool opt_safe_show_db, opt_myisam_use_mmap;
180
extern bool opt_local_infile;
181
extern bool opt_slave_compressed_protocol;
182
extern bool use_temp_pool;
183
extern ulong slave_exec_mode_options;
184
extern bool opt_readonly;
185
extern char* opt_secure_file_priv;
186
extern bool opt_noacl;
187
extern bool opt_old_style_user_limits;
188
extern uint32_t opt_crash_binlog_innodb;
189
extern char *default_tz_name;
190
extern char *opt_logname, *opt_slow_logname;
191
extern const char *log_output_str;
193
extern TableList general_log, slow_log;
194
extern FILE *stderror_file;
195
extern pthread_mutex_t LOCK_drizzle_create_db,LOCK_open, LOCK_lock_db,
196
LOCK_thread_count,LOCK_user_locks, LOCK_status,
198
LOCK_crypt, LOCK_timezone,
199
LOCK_slave_list, LOCK_active_mi, LOCK_global_read_lock,
200
LOCK_global_system_variables, LOCK_user_conn,
201
LOCK_bytes_sent, LOCK_bytes_received, LOCK_connection_count;
202
extern pthread_mutex_t LOCK_server_started;
203
extern pthread_rwlock_t LOCK_sys_init_connect;
204
extern pthread_rwlock_t LOCK_sys_init_slave;
205
extern pthread_rwlock_t LOCK_system_variables_hash;
206
extern pthread_cond_t COND_refresh, COND_thread_count, COND_manager;
207
extern pthread_cond_t COND_global_read_lock;
208
extern pthread_attr_t connection_attrib;
209
extern I_List<Session> threads;
210
extern MY_BITMAP temp_pool;
211
extern String my_empty_string;
212
extern const String my_null_string;
213
extern SHOW_VAR status_vars[];
214
extern struct system_variables max_system_variables;
215
extern struct system_status_var global_status_var;
216
extern struct rand_struct sql_rand;
218
extern const char *opt_date_time_formats[];
219
extern KNOWN_DATE_TIME_FORMAT known_date_time_formats[];
221
extern Table *unused_tables;
222
extern const char* any_db;
223
extern struct my_option my_long_options[];
224
extern const LEX_STRING view_type;
225
extern TYPELIB thread_handling_typelib;
226
extern uint8_t uc_update_queries[SQLCOM_END+1];
227
extern std::bitset<5> sql_command_flags[];
228
extern TYPELIB log_output_typelib;
230
/* optional things, have_* variables */
231
extern SHOW_COMP_OPTION have_community_features;
233
extern handlerton *myisam_hton;
234
extern handlerton *heap_hton;
236
extern SHOW_COMP_OPTION have_symlink;
238
extern pthread_t signal_thread;
242
TABLE_SHARE *alloc_table_share(TableList *table_list, char *key,
243
uint32_t key_length);
244
void init_tmp_table_share(Session *session, TABLE_SHARE *share, const char *key,
246
const char *table_name, const char *path);
247
void free_table_share(TABLE_SHARE *share);
248
int open_table_def(Session *session, TABLE_SHARE *share, uint32_t db_flags);
249
void open_table_error(TABLE_SHARE *share, int error, int db_errno, int errarg);
250
int open_table_from_share(Session *session, TABLE_SHARE *share, const char *alias,
251
uint32_t db_stat, uint32_t prgflag, uint32_t ha_open_flags,
252
Table *outparam, open_table_mode open_mode);
253
int readfrm(const char *name, unsigned char **data, size_t *length);
254
int writefrm(const char* name, const unsigned char* data, size_t len);
255
int read_string(File file, unsigned char* *to, size_t length);
256
void free_blobs(Table *table);
257
int set_zone(int nr,int min_zone,int max_zone);
258
uint32_t convert_period_to_month(uint32_t period);
259
uint32_t convert_month_to_period(uint32_t month);
260
void get_date_from_daynr(long daynr,uint32_t *year, uint32_t *month,
262
time_t TIME_to_timestamp(Session *session, const DRIZZLE_TIME *t, bool *not_exist);
263
bool str_to_time_with_warn(const char *str,uint32_t length,DRIZZLE_TIME *l_time);
264
enum enum_drizzle_timestamp_type str_to_datetime_with_warn(const char *str, uint32_t length,
265
DRIZZLE_TIME *l_time, uint32_t flags);
266
void localtime_to_TIME(DRIZZLE_TIME *to, struct tm *from);
267
void calc_time_from_sec(DRIZZLE_TIME *to, long seconds, long microseconds);
269
void make_truncated_value_warning(Session *session, DRIZZLE_ERROR::enum_warning_level level,
271
uint32_t str_length, enum enum_drizzle_timestamp_type time_type,
272
const char *field_name);
274
bool date_add_interval(DRIZZLE_TIME *ltime, interval_type int_type, INTERVAL interval);
275
bool calc_time_diff(DRIZZLE_TIME *l_time1, DRIZZLE_TIME *l_time2, int l_sign,
276
int64_t *seconds_out, long *microseconds_out);
278
extern LEX_STRING interval_type_to_name[];
280
extern DATE_TIME_FORMAT *date_time_format_make(enum enum_drizzle_timestamp_type format_type,
281
const char *format_str,
282
uint32_t format_length);
283
extern DATE_TIME_FORMAT *date_time_format_copy(Session *session,
284
DATE_TIME_FORMAT *format);
285
const char *get_date_time_format_str(KNOWN_DATE_TIME_FORMAT *format,
286
enum enum_drizzle_timestamp_type type);
287
void make_datetime(const DATE_TIME_FORMAT *format, const DRIZZLE_TIME *l_time,
289
void make_date(const DATE_TIME_FORMAT *format, const DRIZZLE_TIME *l_time,
291
void make_time(const DATE_TIME_FORMAT *format, const DRIZZLE_TIME *l_time,
293
int my_time_compare(DRIZZLE_TIME *a, DRIZZLE_TIME *b);
294
uint64_t get_datetime_value(Session *session, Item ***item_arg, Item **cache_arg,
295
Item *warn_item, bool *is_null);
297
int test_if_number(char *str,int *res,bool allow_wildcards);
298
void change_byte(unsigned char *,uint,char,char);
299
void init_read_record(READ_RECORD *info, Session *session, Table *reg_form,
301
int use_record_cache, bool print_errors);
302
void init_read_record_idx(READ_RECORD *info, Session *session, Table *table,
303
bool print_error, uint32_t idx);
304
void end_read_record(READ_RECORD *info);
305
ha_rows filesort(Session *session, Table *form,struct st_sort_field *sortorder,
306
uint32_t s_length, SQL_SELECT *select,
307
ha_rows max_rows, bool sort_positions,
308
ha_rows *examined_rows);
309
void filesort_free_buffers(Table *table, bool full);
310
void change_double_for_sort(double nr,unsigned char *to);
311
double my_double_round(double value, int64_t dec, bool dec_unsigned,
313
int get_quick_record(SQL_SELECT *select);
315
int calc_weekday(long daynr,bool sunday_first_day_of_week);
316
uint32_t calc_week(DRIZZLE_TIME *l_time, uint32_t week_behaviour, uint32_t *year);
317
void find_date(char *pos,uint32_t *vek,uint32_t flag);
318
TYPELIB *convert_strings_to_array_type(char * *typelibs, char * *end);
319
TYPELIB *typelib(MEM_ROOT *mem_root, List<String> &strings);
320
ulong get_form_pos(File file, unsigned char *head, TYPELIB *save_names);
321
ulong make_new_entry(File file,unsigned char *fileinfo,TYPELIB *formnames,
322
const char *newname);
323
ulong next_io_size(ulong pos);
324
void append_unescaped(String *res, const char *pos, uint32_t length);
325
int create_frm(Session *session, const char *name, const char *db, const char *table,
326
uint32_t reclength, unsigned char *fileinfo,
327
HA_CREATE_INFO *create_info, uint32_t keys, KEY *key_info);
328
int rename_table_proto_file(const char *from, const char* to);
329
int delete_table_proto_file(char *file_name);
330
int rename_file_ext(const char * from,const char * to,const char * ext);
331
bool check_db_name(LEX_STRING *db);
332
bool check_column_name(const char *name);
333
bool check_table_name(const char *name, uint32_t length);
334
char *get_field(MEM_ROOT *mem, Field *field);
335
bool get_field(MEM_ROOT *mem, Field *field, class String *res);
336
char *fn_rext(char *name);
338
/* Conversion functions */
339
uint32_t build_table_filename(char *buff, size_t bufflen, const char *db,
340
const char *table, const char *ext, uint32_t flags);
342
#define MYSQL50_TABLE_NAME_PREFIX "#mysql50#"
343
#define MYSQL50_TABLE_NAME_PREFIX_LENGTH sizeof(MYSQL50_TABLE_NAME_PREFIX)
345
/* Flags for conversion functions. */
346
#define FN_FROM_IS_TMP (1 << 0)
347
#define FN_TO_IS_TMP (1 << 1)
348
#define FN_IS_TMP (FN_FROM_IS_TMP | FN_TO_IS_TMP)
349
#define NO_FRM_RENAME (1 << 2)
352
inline ulong sql_rnd()
354
ulong tmp= (ulong) (rand() * 0xffffffff); /* make all bits random */
362
convert a hex digit into number.
365
inline int hexchar_to_int(char c)
367
if (c <= '9' && c >= '0')
370
if (c <= 'f' && c >= 'a')
376
#endif /* DRIZZLE_SERVER_SERVER_INCLUDES_H */