~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/server_includes.h

  • Committer: Jay Pipes
  • Date: 2008-12-18 15:55:03 UTC
  • mto: This revision was merged to the branch mainline in revision 717.
  • Revision ID: jpipes@serialcoder-20081218155503-u45ygyunrdyyvquq
Fix for Bug#308457.  Gave UTF8 enclosure and escape character on LOAD DATA INFILE and changed the error message to be more descriptive

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 DRIZZLED_SERVER_INCLUDES_H
 
31
#define DRIZZLED_SERVER_INCLUDES_H
 
32
 
 
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>
 
42
 
 
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>
 
48
 
 
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>
 
57
#include <drizzled/log.h>
 
58
 
 
59
#include <string>
 
60
#include <sstream>
 
61
#include <bitset>
 
62
 
 
63
 
 
64
extern const CHARSET_INFO *system_charset_info, *files_charset_info ;
 
65
extern const CHARSET_INFO *national_charset_info, *table_alias_charset;
 
66
 
 
67
typedef class st_select_lex SELECT_LEX;
 
68
typedef struct st_mysql_lock DRIZZLE_LOCK;
 
69
typedef struct st_ha_create_information HA_CREATE_INFO;
 
70
 
 
71
/* information schema */
 
72
static const std::string INFORMATION_SCHEMA_NAME("information_schema");
 
73
 
 
74
 
 
75
 
 
76
/* mysqld.cc */
 
77
void refresh_status(Session *session);
 
78
bool drizzle_rm_tmp_tables(void);
 
79
void handle_connection_in_main_thread(Session *session);
 
80
void create_thread_to_handle_connection(Session *session);
 
81
void unlink_session(Session *session);
 
82
bool one_thread_per_connection_end(Session *session, bool put_in_cache);
 
83
void flush_thread_cache();
 
84
 
 
85
/* item_func.cc */
 
86
extern bool check_reserved_words(LEX_STRING *name);
 
87
extern enum_field_types agg_field_type(Item **items, uint32_t nitems);
 
88
 
 
89
/* strfunc.cc */
 
90
uint64_t find_set(TYPELIB *lib, const char *x, uint32_t length, const CHARSET_INFO * const cs,
 
91
                   char **err_pos, uint32_t *err_len, bool *set_warning);
 
92
uint32_t find_type(const TYPELIB *lib, const char *find, uint32_t length,
 
93
               bool part_match);
 
94
uint32_t find_type2(const TYPELIB *lib, const char *find, uint32_t length,
 
95
                const CHARSET_INFO *cs);
 
96
void unhex_type2(TYPELIB *lib);
 
97
uint32_t check_word(TYPELIB *lib, const char *val, const char *end,
 
98
                const char **end_of_word);
 
99
int find_string_in_array(LEX_STRING * const haystack, LEX_STRING * const needle,
 
100
                         const CHARSET_INFO * const cs);
 
101
 
 
102
 
 
103
bool is_keyword(const char *name, uint32_t len);
 
104
 
 
105
/*
 
106
  External variables
 
107
*/
 
108
 
 
109
extern char *drizzle_tmpdir;
 
110
extern const LEX_STRING command_name[];
 
111
extern const char *first_keyword, *my_localhost, *delayed_user, *binary_keyword;
 
112
extern const char *myisam_recover_options_str;
 
113
extern const char *in_left_expr_name, *in_additional_cond, *in_having_cond;
 
114
extern const char * const TRG_EXT;
 
115
extern const char * const TRN_EXT;
 
116
extern char language[FN_REFLEN];
 
117
extern char glob_hostname[FN_REFLEN], drizzle_home[FN_REFLEN];
 
118
extern char pidfile_name[FN_REFLEN], system_time_zone[30], *opt_init_file;
 
119
extern char log_error_file[FN_REFLEN], *opt_tc_log_file;
 
120
extern const double log_10[309];
 
121
extern uint64_t log_10_int[20];
 
122
extern uint64_t keybuff_size;
 
123
extern uint64_t session_startup_options;
 
124
extern ulong thread_id;
 
125
extern uint64_t binlog_cache_use;
 
126
extern uint64_t binlog_cache_disk_use;
 
127
extern uint64_t aborted_threads;
 
128
extern uint64_t aborted_connects;
 
129
extern uint64_t slave_open_temp_tables;
 
130
extern uint64_t slow_launch_threads;
 
131
extern uint64_t slow_launch_time;
 
132
extern uint64_t table_cache_size;
 
133
extern uint64_t table_def_size;
 
134
extern uint64_t max_connections;
 
135
extern uint64_t max_connect_errors;
 
136
extern uint64_t connect_timeout;
 
137
extern bool slave_allow_batching;
 
138
extern uint64_t slave_net_timeout;
 
139
extern uint64_t slave_trans_retries;
 
140
extern uint32_t max_user_connections;
 
141
extern ulong what_to_log;
 
142
extern uint64_t binlog_cache_size;
 
143
extern uint64_t max_binlog_cache_size;
 
144
extern uint64_t open_files_limit;
 
145
extern uint64_t max_binlog_size;
 
146
extern uint64_t max_relay_log_size;
 
147
extern uint64_t opt_binlog_rows_event_max_size;
 
148
extern uint64_t thread_pool_size;
 
149
extern uint32_t back_log;
 
150
extern pid_t current_pid;
 
151
extern uint64_t expire_logs_days;
 
152
extern uint64_t sync_binlog_period;
 
153
extern uint64_t tc_log_max_pages_used;
 
154
extern uint64_t tc_log_page_size;
 
155
extern uint64_t opt_tc_log_size;
 
156
extern uint64_t tc_log_page_waits;
 
157
extern bool relay_log_purge;
 
158
extern bool opt_innodb_safe_binlog, opt_innodb;
 
159
extern uint32_t test_flags,select_errors,ha_open_options;
 
160
extern uint32_t protocol_version, drizzled_port, dropping_tables;
 
161
extern uint32_t delay_key_write_options;
 
162
extern bool opt_endinfo, using_udf_functions;
 
163
extern bool locked_in_memory;
 
164
extern bool opt_using_transactions;
 
165
extern bool using_update_log, server_id_supplied;
 
166
extern bool opt_update_log, opt_bin_log, opt_error_log;
 
167
extern bool opt_log;
 
168
extern bool opt_slow_log;
 
169
extern ulong log_output_options;
 
170
extern bool opt_log_queries_not_using_indexes;
 
171
extern bool opt_character_set_client_handshake;
 
172
extern bool volatile abort_loop, shutdown_in_progress;
 
173
extern uint32_t volatile thread_count, thread_running, global_read_lock;
 
174
extern uint32_t connection_count;
 
175
extern bool opt_sql_bin_update;
 
176
extern bool opt_safe_user_create;
 
177
extern bool opt_no_mix_types;
 
178
extern bool opt_safe_show_db, opt_myisam_use_mmap;
 
179
extern bool opt_local_infile;
 
180
extern bool opt_slave_compressed_protocol;
 
181
extern bool use_temp_pool;
 
182
extern ulong slave_exec_mode_options;
 
183
extern bool opt_readonly;
 
184
extern char* opt_secure_file_priv;
 
185
extern bool opt_noacl;
 
186
extern bool opt_old_style_user_limits;
 
187
extern uint32_t opt_crash_binlog_innodb;
 
188
extern char *default_tz_name;
 
189
extern char *opt_logname, *opt_slow_logname;
 
190
extern const char *log_output_str;
 
191
 
 
192
extern DRIZZLE_BIN_LOG drizzle_bin_log;
 
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,
 
197
       LOCK_error_log, LOCK_uuid_generator,
 
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;
 
217
 
 
218
extern const char *opt_date_time_formats[];
 
219
extern KNOWN_DATE_TIME_FORMAT known_date_time_formats[];
 
220
 
 
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;
 
229
 
 
230
/* optional things, have_* variables */
 
231
extern SHOW_COMP_OPTION have_community_features;
 
232
 
 
233
extern handlerton *myisam_hton;
 
234
extern handlerton *heap_hton;
 
235
 
 
236
extern SHOW_COMP_OPTION have_symlink;
 
237
extern SHOW_COMP_OPTION have_compress;
 
238
 
 
239
 
 
240
extern pthread_t signal_thread;
 
241
 
 
242
 
 
243
/* table.cc */
 
244
TABLE_SHARE *alloc_table_share(TableList *table_list, char *key,
 
245
                               uint32_t key_length);
 
246
void init_tmp_table_share(Session *session, TABLE_SHARE *share, const char *key,
 
247
                          uint32_t key_length,
 
248
                          const char *table_name, const char *path);
 
249
void free_table_share(TABLE_SHARE *share);
 
250
int open_table_def(Session *session, TABLE_SHARE *share, uint32_t db_flags);
 
251
void open_table_error(TABLE_SHARE *share, int error, int db_errno, int errarg);
 
252
int open_table_from_share(Session *session, TABLE_SHARE *share, const char *alias,
 
253
                          uint32_t db_stat, uint32_t prgflag, uint32_t ha_open_flags,
 
254
                          Table *outparam, open_table_mode open_mode);
 
255
int readfrm(const char *name, unsigned char **data, size_t *length);
 
256
int writefrm(const char* name, const unsigned char* data, size_t len);
 
257
int closefrm(Table *table, bool free_share);
 
258
int read_string(File file, unsigned char* *to, size_t length);
 
259
void free_blobs(Table *table);
 
260
int set_zone(int nr,int min_zone,int max_zone);
 
261
uint32_t convert_period_to_month(uint32_t period);
 
262
uint32_t convert_month_to_period(uint32_t month);
 
263
void get_date_from_daynr(long daynr,uint32_t *year, uint32_t *month,
 
264
                         uint32_t *day);
 
265
my_time_t TIME_to_timestamp(Session *session, const DRIZZLE_TIME *t, bool *not_exist);
 
266
bool str_to_time_with_warn(const char *str,uint32_t length,DRIZZLE_TIME *l_time);
 
267
enum enum_drizzle_timestamp_type str_to_datetime_with_warn(const char *str, uint32_t length,
 
268
                                         DRIZZLE_TIME *l_time, uint32_t flags);
 
269
void localtime_to_TIME(DRIZZLE_TIME *to, struct tm *from);
 
270
void calc_time_from_sec(DRIZZLE_TIME *to, long seconds, long microseconds);
 
271
 
 
272
void make_truncated_value_warning(Session *session, DRIZZLE_ERROR::enum_warning_level level,
 
273
                                  const char *str_val,
 
274
                                  uint32_t str_length, enum enum_drizzle_timestamp_type time_type,
 
275
                                  const char *field_name);
 
276
 
 
277
bool date_add_interval(DRIZZLE_TIME *ltime, interval_type int_type, INTERVAL interval);
 
278
bool calc_time_diff(DRIZZLE_TIME *l_time1, DRIZZLE_TIME *l_time2, int l_sign,
 
279
                    int64_t *seconds_out, long *microseconds_out);
 
280
 
 
281
extern LEX_STRING interval_type_to_name[];
 
282
 
 
283
extern DATE_TIME_FORMAT *date_time_format_make(enum enum_drizzle_timestamp_type format_type,
 
284
                                               const char *format_str,
 
285
                                               uint32_t format_length);
 
286
extern DATE_TIME_FORMAT *date_time_format_copy(Session *session,
 
287
                                               DATE_TIME_FORMAT *format);
 
288
const char *get_date_time_format_str(KNOWN_DATE_TIME_FORMAT *format,
 
289
                                                             enum enum_drizzle_timestamp_type type);
 
290
void make_datetime(const DATE_TIME_FORMAT *format, const DRIZZLE_TIME *l_time,
 
291
                   String *str);
 
292
void make_date(const DATE_TIME_FORMAT *format, const DRIZZLE_TIME *l_time,
 
293
               String *str);
 
294
void make_time(const DATE_TIME_FORMAT *format, const DRIZZLE_TIME *l_time,
 
295
               String *str);
 
296
int my_time_compare(DRIZZLE_TIME *a, DRIZZLE_TIME *b);
 
297
uint64_t get_datetime_value(Session *session, Item ***item_arg, Item **cache_arg,
 
298
                             Item *warn_item, bool *is_null);
 
299
 
 
300
int test_if_number(char *str,int *res,bool allow_wildcards);
 
301
void change_byte(unsigned char *,uint,char,char);
 
302
void init_read_record(READ_RECORD *info, Session *session, Table *reg_form,
 
303
                      SQL_SELECT *select,
 
304
                      int use_record_cache, bool print_errors);
 
305
void init_read_record_idx(READ_RECORD *info, Session *session, Table *table,
 
306
                          bool print_error, uint32_t idx);
 
307
void end_read_record(READ_RECORD *info);
 
308
ha_rows filesort(Session *session, Table *form,struct st_sort_field *sortorder,
 
309
                 uint32_t s_length, SQL_SELECT *select,
 
310
                 ha_rows max_rows, bool sort_positions,
 
311
                 ha_rows *examined_rows);
 
312
void filesort_free_buffers(Table *table, bool full);
 
313
void change_double_for_sort(double nr,unsigned char *to);
 
314
double my_double_round(double value, int64_t dec, bool dec_unsigned,
 
315
                       bool truncate);
 
316
int get_quick_record(SQL_SELECT *select);
 
317
 
 
318
int calc_weekday(long daynr,bool sunday_first_day_of_week);
 
319
uint32_t calc_week(DRIZZLE_TIME *l_time, uint32_t week_behaviour, uint32_t *year);
 
320
void find_date(char *pos,uint32_t *vek,uint32_t flag);
 
321
TYPELIB *convert_strings_to_array_type(char * *typelibs, char * *end);
 
322
TYPELIB *typelib(MEM_ROOT *mem_root, List<String> &strings);
 
323
ulong get_form_pos(File file, unsigned char *head, TYPELIB *save_names);
 
324
ulong make_new_entry(File file,unsigned char *fileinfo,TYPELIB *formnames,
 
325
                     const char *newname);
 
326
ulong next_io_size(ulong pos);
 
327
void append_unescaped(String *res, const char *pos, uint32_t length);
 
328
int create_frm(Session *session, const char *name, const char *db, const char *table,
 
329
               uint32_t reclength, unsigned char *fileinfo,
 
330
               HA_CREATE_INFO *create_info, uint32_t keys, KEY *key_info);
 
331
int rename_table_proto_file(const char *from, const char* to);
 
332
int delete_table_proto_file(char *file_name);
 
333
int rename_file_ext(const char * from,const char * to,const char * ext);
 
334
bool check_db_name(LEX_STRING *db);
 
335
bool check_column_name(const char *name);
 
336
bool check_table_name(const char *name, uint32_t length);
 
337
char *get_field(MEM_ROOT *mem, Field *field);
 
338
bool get_field(MEM_ROOT *mem, Field *field, class String *res);
 
339
char *fn_rext(char *name);
 
340
 
 
341
/* Conversion functions */
 
342
uint32_t build_table_filename(char *buff, size_t bufflen, const char *db,
 
343
                          const char *table, const char *ext, uint32_t flags);
 
344
 
 
345
#define MYSQL50_TABLE_NAME_PREFIX         "#mysql50#"
 
346
#define MYSQL50_TABLE_NAME_PREFIX_LENGTH  sizeof(MYSQL50_TABLE_NAME_PREFIX)
 
347
 
 
348
/* Flags for conversion functions. */
 
349
#define FN_FROM_IS_TMP  (1 << 0)
 
350
#define FN_TO_IS_TMP    (1 << 1)
 
351
#define FN_IS_TMP       (FN_FROM_IS_TMP | FN_TO_IS_TMP)
 
352
#define NO_FRM_RENAME   (1 << 2)
 
353
 
 
354
 
 
355
inline ulong sql_rnd()
 
356
{
 
357
  ulong tmp= (ulong) (rand() * 0xffffffff); /* make all bits random */
 
358
 
 
359
  return tmp;
 
360
}
 
361
 
 
362
 
 
363
 
 
364
/**
 
365
  convert a hex digit into number.
 
366
*/
 
367
 
 
368
inline int hexchar_to_int(char c)
 
369
{
 
370
  if (c <= '9' && c >= '0')
 
371
    return c-'0';
 
372
  c|=32;
 
373
  if (c <= 'f' && c >= 'a')
 
374
    return c-'a'+10;
 
375
  return -1;
 
376
}
 
377
 
 
378
 
 
379
#endif /* DRIZZLE_SERVER_SERVER_INCLUDES_H */