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
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>
38
/* Lots of system-wide struct definitions like IO_CACHE,
39
prototypes for all my_* functions */
40
#include <mysys/my_sys.h>
41
/* Custom C string functions */
42
#include <mystrings/m_string.h>
44
/* The <strong>INTERNAL</strong> plugin API - not the external, or public, server plugin API */
45
#include <drizzled/sql_plugin.h>
46
/* Range optimization API/library */
47
#include <drizzled/opt_range.h>
48
/* Simple error injection (crash) module */
49
#include <drizzled/error_injection.h>
50
/* Routines for dropping, repairing, checking schema tables */
51
#include <drizzled/sql_table.h>
53
/* Routines for printing error messages */
54
#include <drizzled/errmsg_print.h>
61
extern const CHARSET_INFO *system_charset_info, *files_charset_info ;
62
extern const CHARSET_INFO *national_charset_info, *table_alias_charset;
64
typedef struct drizzled_lock_st DRIZZLE_LOCK;
65
typedef struct st_ha_create_information HA_CREATE_INFO;
67
/* information schema */
68
static const std::string INFORMATION_SCHEMA_NAME("information_schema");
73
void refresh_status(Session *session);
74
bool drizzle_rm_tmp_tables(void);
75
void handle_connection_in_main_thread(Session *session);
76
void create_thread_to_handle_connection(Session *session);
77
void unlink_session(Session *session);
78
bool one_thread_per_connection_end(Session *session, bool put_in_cache);
79
void flush_thread_cache();
82
extern bool check_reserved_words(LEX_STRING *name);
83
extern enum_field_types agg_field_type(Item **items, uint32_t nitems);
86
uint64_t find_set(TYPELIB *lib, const char *x, uint32_t length, const CHARSET_INFO * const cs,
87
char **err_pos, uint32_t *err_len, bool *set_warning);
88
uint32_t find_type(const TYPELIB *lib, const char *find, uint32_t length,
90
uint32_t find_type2(const TYPELIB *lib, const char *find, uint32_t length,
91
const CHARSET_INFO *cs);
92
void unhex_type2(TYPELIB *lib);
93
uint32_t check_word(TYPELIB *lib, const char *val, const char *end,
94
const char **end_of_word);
95
int find_string_in_array(LEX_STRING * const haystack, LEX_STRING * const needle,
96
const CHARSET_INFO * const cs);
103
extern char *drizzle_tmpdir;
104
extern const LEX_STRING command_name[];
105
extern const char *first_keyword, *my_localhost, *delayed_user, *binary_keyword;
106
extern const char *myisam_recover_options_str;
107
extern const char *in_left_expr_name, *in_additional_cond, *in_having_cond;
108
extern const char * const TRG_EXT;
109
extern const char * const TRN_EXT;
110
extern char language[FN_REFLEN];
111
extern char glob_hostname[FN_REFLEN], drizzle_home[FN_REFLEN];
112
extern char pidfile_name[FN_REFLEN], system_time_zone[30], *opt_init_file;
113
extern char *opt_tc_log_file;
114
extern const double log_10[309];
115
extern uint64_t log_10_int[20];
116
extern uint64_t keybuff_size;
117
extern uint64_t session_startup_options;
118
extern ulong thread_id;
119
extern uint64_t aborted_threads;
120
extern uint64_t aborted_connects;
121
extern uint64_t slow_launch_threads;
122
extern uint64_t slow_launch_time;
123
extern uint64_t table_cache_size;
124
extern uint64_t table_def_size;
125
extern uint64_t max_connect_errors;
126
extern uint64_t connect_timeout;
127
extern uint32_t back_log;
128
extern pid_t current_pid;
129
extern uint64_t expire_logs_days;
130
extern uint64_t tc_log_max_pages_used;
131
extern uint64_t tc_log_page_size;
132
extern uint64_t opt_tc_log_size;
133
extern uint64_t tc_log_page_waits;
134
extern bool opt_innodb;
135
extern uint32_t test_flags,select_errors,ha_open_options;
136
extern uint32_t protocol_version, drizzled_port, dropping_tables;
137
extern uint32_t delay_key_write_options;
138
extern bool opt_endinfo, using_udf_functions;
139
extern bool locked_in_memory;
140
extern bool opt_using_transactions;
141
extern bool using_update_log, server_id_supplied;
142
extern bool opt_update_log, opt_bin_log;
144
extern ulong log_output_options;
145
extern bool opt_character_set_client_handshake;
146
extern bool volatile abort_loop, shutdown_in_progress;
147
extern uint32_t volatile thread_count, thread_running, global_read_lock;
148
extern uint32_t connection_count;
149
extern bool opt_sql_bin_update;
150
extern bool opt_safe_user_create;
151
extern bool opt_no_mix_types;
152
extern bool opt_safe_show_db, opt_myisam_use_mmap;
153
extern bool opt_local_infile;
154
extern bool use_temp_pool;
155
extern bool opt_readonly;
156
extern char* opt_secure_file_priv;
157
extern bool opt_noacl;
158
extern bool opt_old_style_user_limits;
159
extern char *default_tz_name;
160
extern char *opt_logname, *opt_slow_logname;
161
extern const char *log_output_str;
163
extern TableList general_log, slow_log;
164
extern FILE *stderror_file;
165
extern pthread_mutex_t LOCK_drizzleclient_create_db,LOCK_open, LOCK_lock_db,
166
LOCK_thread_count,LOCK_user_locks, LOCK_status,
168
LOCK_global_read_lock,
169
LOCK_global_system_variables, LOCK_user_conn,
170
LOCK_bytes_sent, LOCK_bytes_received, LOCK_connection_count;
171
extern pthread_mutex_t LOCK_server_started;
172
extern pthread_rwlock_t LOCK_sys_init_connect;
173
extern pthread_rwlock_t LOCK_system_variables_hash;
174
extern pthread_cond_t COND_refresh, COND_thread_count, COND_manager;
175
extern pthread_cond_t COND_global_read_lock;
176
extern pthread_attr_t connection_attrib;
177
extern I_List<Session> threads;
178
extern MY_BITMAP temp_pool;
179
extern String my_empty_string;
180
extern const String my_null_string;
181
extern SHOW_VAR status_vars[];
182
extern struct system_variables max_system_variables;
183
extern struct system_status_var global_status_var;
184
extern struct rand_struct sql_rand;
186
extern const char *opt_date_time_formats[];
187
extern KNOWN_DATE_TIME_FORMAT known_date_time_formats[];
189
extern Table *unused_tables;
190
extern const char* any_db;
191
extern struct my_option my_long_options[];
192
extern const LEX_STRING view_type;
193
extern TYPELIB thread_handling_typelib;
194
extern uint8_t uc_update_queries[SQLCOM_END+1];
195
extern std::bitset<5> sql_command_flags[];
196
extern TYPELIB log_output_typelib;
198
/* optional things, have_* variables */
199
extern SHOW_COMP_OPTION have_community_features;
201
extern handlerton *myisam_hton;
202
extern handlerton *heap_hton;
204
extern SHOW_COMP_OPTION have_symlink;
206
extern pthread_t signal_thread;
210
TABLE_SHARE *alloc_table_share(TableList *table_list, char *key,
211
uint32_t key_length);
212
void init_tmp_table_share(Session *session, TABLE_SHARE *share, const char *key,
214
const char *table_name, const char *path);
215
void free_table_share(TABLE_SHARE *share);
216
int open_table_def(Session *session, TABLE_SHARE *share, uint32_t db_flags);
217
void open_table_error(TABLE_SHARE *share, int error, int db_errno, int errarg);
218
int open_table_from_share(Session *session, TABLE_SHARE *share, const char *alias,
219
uint32_t db_stat, uint32_t prgflag, uint32_t ha_open_flags,
220
Table *outparam, open_table_mode open_mode);
221
int readfrm(const char *name, unsigned char **data, size_t *length);
222
int writefrm(const char* name, const unsigned char* data, size_t len);
223
int read_string(File file, unsigned char* *to, size_t length);
224
void free_blobs(Table *table);
225
int set_zone(int nr,int min_zone,int max_zone);
226
uint32_t convert_period_to_month(uint32_t period);
227
uint32_t convert_month_to_period(uint32_t month);
228
void get_date_from_daynr(long daynr,uint32_t *year, uint32_t *month,
230
time_t TIME_to_timestamp(Session *session, const DRIZZLE_TIME *t, bool *not_exist);
231
bool str_to_time_with_warn(const char *str,uint32_t length,DRIZZLE_TIME *l_time);
232
enum enum_drizzle_timestamp_type str_to_datetime_with_warn(const char *str, uint32_t length,
233
DRIZZLE_TIME *l_time, uint32_t flags);
234
void localtime_to_TIME(DRIZZLE_TIME *to, struct tm *from);
235
void calc_time_from_sec(DRIZZLE_TIME *to, long seconds, long microseconds);
237
void make_truncated_value_warning(Session *session, DRIZZLE_ERROR::enum_warning_level level,
239
uint32_t str_length, enum enum_drizzle_timestamp_type time_type,
240
const char *field_name);
242
bool date_add_interval(DRIZZLE_TIME *ltime, interval_type int_type, INTERVAL interval);
243
bool calc_time_diff(DRIZZLE_TIME *l_time1, DRIZZLE_TIME *l_time2, int l_sign,
244
int64_t *seconds_out, long *microseconds_out);
246
extern LEX_STRING interval_type_to_name[];
248
extern DATE_TIME_FORMAT *date_time_format_make(enum enum_drizzle_timestamp_type format_type,
249
const char *format_str,
250
uint32_t format_length);
251
extern DATE_TIME_FORMAT *date_time_format_copy(Session *session,
252
DATE_TIME_FORMAT *format);
253
const char *get_date_time_format_str(KNOWN_DATE_TIME_FORMAT *format,
254
enum enum_drizzle_timestamp_type type);
255
void make_datetime(const DATE_TIME_FORMAT *format, const DRIZZLE_TIME *l_time,
257
void make_date(const DATE_TIME_FORMAT *format, const DRIZZLE_TIME *l_time,
259
void make_time(const DATE_TIME_FORMAT *format, const DRIZZLE_TIME *l_time,
261
int my_time_compare(DRIZZLE_TIME *a, DRIZZLE_TIME *b);
262
uint64_t get_datetime_value(Session *session, Item ***item_arg, Item **cache_arg,
263
Item *warn_item, bool *is_null);
265
int test_if_number(char *str,int *res,bool allow_wildcards);
266
void change_byte(unsigned char *,uint,char,char);
267
void init_read_record(READ_RECORD *info, Session *session, Table *reg_form,
269
int use_record_cache, bool print_errors);
270
void init_read_record_idx(READ_RECORD *info, Session *session, Table *table,
271
bool print_error, uint32_t idx);
272
void end_read_record(READ_RECORD *info);
273
ha_rows filesort(Session *session, Table *form,struct st_sort_field *sortorder,
274
uint32_t s_length, SQL_SELECT *select,
275
ha_rows max_rows, bool sort_positions,
276
ha_rows *examined_rows);
277
void filesort_free_buffers(Table *table, bool full);
278
void change_double_for_sort(double nr,unsigned char *to);
279
double my_double_round(double value, int64_t dec, bool dec_unsigned,
281
int get_quick_record(SQL_SELECT *select);
283
int calc_weekday(long daynr,bool sunday_first_day_of_week);
284
uint32_t calc_week(DRIZZLE_TIME *l_time, uint32_t week_behaviour, uint32_t *year);
285
void find_date(char *pos,uint32_t *vek,uint32_t flag);
286
TYPELIB *convert_strings_to_array_type(char * *typelibs, char * *end);
287
TYPELIB *typelib(MEM_ROOT *mem_root, List<String> &strings);
288
ulong get_form_pos(File file, unsigned char *head, TYPELIB *save_names);
289
ulong make_new_entry(File file,unsigned char *fileinfo,TYPELIB *formnames,
290
const char *newname);
291
ulong next_io_size(ulong pos);
292
void append_unescaped(String *res, const char *pos, uint32_t length);
293
int create_frm(Session *session, const char *name, const char *db, const char *table,
294
uint32_t reclength, unsigned char *fileinfo,
295
HA_CREATE_INFO *create_info, uint32_t keys, KEY *key_info);
296
int rename_table_proto_file(const char *from, const char* to);
297
int delete_table_proto_file(const char *file_name);
298
int rename_file_ext(const char * from,const char * to,const char * ext);
299
bool check_db_name(LEX_STRING *db);
300
bool check_column_name(const char *name);
301
bool check_table_name(const char *name, uint32_t length);
302
char *get_field(MEM_ROOT *mem, Field *field);
303
bool get_field(MEM_ROOT *mem, Field *field, class String *res);
304
char *fn_rext(char *name);
306
/* Conversion functions */
307
uint32_t build_table_filename(char *buff, size_t bufflen, const char *db,
308
const char *table, const char *ext, uint32_t flags);
310
#define MYSQL50_TABLE_NAME_PREFIX "#mysql50#"
311
#define MYSQL50_TABLE_NAME_PREFIX_LENGTH sizeof(MYSQL50_TABLE_NAME_PREFIX)
313
/* Flags for conversion functions. */
314
#define FN_FROM_IS_TMP (1 << 0)
315
#define FN_TO_IS_TMP (1 << 1)
316
#define FN_IS_TMP (FN_FROM_IS_TMP | FN_TO_IS_TMP)
317
#define NO_FRM_RENAME (1 << 2)
320
inline ulong sql_rnd()
322
ulong tmp= (ulong) (rand() * 0xffffffff); /* make all bits random */
330
convert a hex digit into number.
333
inline int hexchar_to_int(char c)
335
if (c <= '9' && c >= '0')
338
if (c <= 'f' && c >= 'a')
344
#endif /* DRIZZLE_SERVER_SERVER_INCLUDES_H */