~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzle.cc

  • Committer: Stewart Smith
  • Date: 2009-06-05 12:04:43 UTC
  • mto: This revision was merged to the branch mainline in revision 1053.
  • Revision ID: stewart@flamingspork.com-20090605120443-dn9ttgy0f1942cr8
Add code coverage for ALTER DATABASE

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2010 Vijay Samuel
5
4
 *  Copyright (C) 2008 MySQL
6
5
 *
7
6
 *  This program is free software; you can redistribute it and/or modify
34
33
 *
35
34
 **/
36
35
 
37
 
#include "config.h"
38
 
#include <libdrizzle/drizzle_client.h>
39
 
 
40
 
#include "client/get_password.h"
41
 
 
42
 
#if TIME_WITH_SYS_TIME
43
 
# include <sys/time.h>
44
 
# include <time.h>
45
 
#else
46
 
# if HAVE_SYS_TIME_H
47
 
#  include <sys/time.h>
48
 
# else
49
 
#  include <time.h>
50
 
# endif
51
 
#endif
52
 
 
53
 
#include <cerrno>
 
36
#include "client_priv.h"
54
37
#include <string>
55
 
#include <drizzled/gettext.h>
56
 
#include <iostream>
57
 
#include <fstream>
58
 
#include <map>
59
38
#include <algorithm>
60
 
#include <limits.h>
61
 
#include <cassert>
 
39
#include <mystrings/m_ctype.h>
62
40
#include <stdarg.h>
63
 
#include <math.h>
64
 
#include <memory>
65
 
#include "client/linebuffer.h"
 
41
#include "client/my_readline.h"
66
42
#include <signal.h>
67
43
#include <sys/ioctl.h>
68
44
#include <drizzled/configmake.h>
69
 
#include "drizzled/utf8/utf8.h"
70
 
#include <cstdlib>
71
45
 
72
46
#if defined(HAVE_CURSES_H) && defined(HAVE_TERM_H)
73
47
#include <curses.h>
125
99
    /* no history */
126
100
#endif /* HAVE_READLINE_HISTORY */
127
101
 
 
102
#define DRIZZLE_DEFAULT_INPUT_LINE 65536
 
103
 
128
104
/**
129
105
 Make the old readline interface look like the new one.
130
106
*/
131
 
#ifndef HAVE_RL_COMPLETION
132
 
typedef char **rl_completion_func_t(const char *, int, int);
 
107
#ifndef USE_NEW_READLINE_INTERFACE
 
108
typedef CPPFunction rl_completion_func_t;
 
109
typedef Function rl_compentry_func_t;
133
110
#define rl_completion_matches(str, func) \
134
111
  completion_matches((char *)str, (CPFunction *)func)
135
112
#endif
136
113
 
137
 
#ifdef HAVE_RL_COMPENTRY
138
 
# ifdef HAVE_WORKING_RL_COMPENTRY
139
 
typedef rl_compentry_func_t drizzle_compentry_func_t;
140
 
# else
141
 
/* Snow Leopard ships an rl_compentry which cannot be assigned to
142
 
 * rl_completion_entry_function. We must undo the complete and total
143
 
 * ass-bagery.
144
 
 */
145
 
typedef Function drizzle_compentry_func_t;
146
 
# endif
147
 
#else
148
 
typedef Function drizzle_compentry_func_t;
149
 
#endif
150
 
 
151
114
#if defined(HAVE_LOCALE_H)
152
115
#include <locale.h>
153
116
#endif
154
117
 
 
118
#include <drizzled/gettext.h>
 
119
 
 
120
 
 
121
void* sql_alloc(unsigned size);       // Don't use drizzled alloc for these
 
122
void sql_element_free(void *ptr);
155
123
 
156
124
 
157
125
#if !defined(HAVE_VIDATTR)
158
126
#undef vidattr
159
127
#define vidattr(A) {}      // Can't get this to work
160
128
#endif
161
 
#include <boost/program_options.hpp>
162
 
#include <boost/scoped_ptr.hpp>
163
 
#include "drizzled/program_options/config_file.h"
 
129
 
 
130
#include <iostream>
 
131
#include <map>
164
132
 
165
133
using namespace std;
166
 
namespace po=boost::program_options;
167
 
namespace dpo=drizzled::program_options;
168
134
 
 
135
const string VER("14.14");
169
136
/* Don't try to make a nice table if the data is too big */
170
137
const uint32_t MAX_COLUMN_LENGTH= 1024;
171
138
 
173
140
const int MAX_SERVER_VERSION_LENGTH= 128;
174
141
 
175
142
#define PROMPT_CHAR '\\'
 
143
#define DEFAULT_DELIMITER ";"
176
144
 
177
 
class Status
 
145
typedef struct st_status
178
146
{
179
 
public:
180
 
 
181
 
  Status(int in_exit_status, 
182
 
         uint32_t in_query_start_line,
183
 
         char *in_file_name,
184
 
         LineBuffer *in_line_buff,
185
 
         bool in_batch,
186
 
         bool in_add_to_history)
187
 
    :
188
 
    exit_status(in_exit_status),
189
 
    query_start_line(in_query_start_line),
190
 
    file_name(in_file_name),
191
 
    line_buff(in_line_buff),
192
 
    batch(in_batch),
193
 
    add_to_history(in_add_to_history)
194
 
    {}
195
 
 
196
 
  Status() :
197
 
    exit_status(0),
198
 
    query_start_line(0),
199
 
    file_name(NULL),
200
 
    line_buff(NULL),
201
 
    batch(false),        
202
 
    add_to_history(false)
203
 
  {}
204
 
  
205
 
  int getExitStatus() const
206
 
  {
207
 
    return exit_status;
208
 
  }
209
 
 
210
 
  uint32_t getQueryStartLine() const
211
 
  {
212
 
    return query_start_line;
213
 
  }
214
 
 
215
 
  const char *getFileName() const
216
 
  {
217
 
    return file_name;
218
 
  }
219
 
 
220
 
  LineBuffer *getLineBuff() const
221
 
  {
222
 
    return line_buff;
223
 
  }
224
 
 
225
 
  bool getBatch() const
226
 
  {
227
 
    return batch;
228
 
  }
229
 
 
230
 
  bool getAddToHistory() const
231
 
  {
232
 
    return add_to_history;
233
 
  }
234
 
 
235
 
  void setExitStatus(int in_exit_status)
236
 
  {
237
 
    exit_status= in_exit_status;
238
 
  }
239
 
 
240
 
  void setQueryStartLine(uint32_t in_query_start_line)
241
 
  {
242
 
    query_start_line= in_query_start_line;
243
 
  }
244
 
 
245
 
  void setFileName(char *in_file_name)
246
 
  {
247
 
    file_name= in_file_name;
248
 
  }
249
 
 
250
 
  void setLineBuff(int max_size, FILE *file=NULL)
251
 
  {
252
 
    line_buff= new(std::nothrow) LineBuffer(max_size, file);
253
 
  }
254
 
 
255
 
  void setLineBuff(LineBuffer *in_line_buff)
256
 
  {
257
 
    line_buff= in_line_buff;
258
 
  }
259
 
 
260
 
  void setBatch(bool in_batch)
261
 
  {
262
 
    batch= in_batch;
263
 
  }
264
 
 
265
 
  void setAddToHistory(bool in_add_to_history)
266
 
  {
267
 
    add_to_history= in_add_to_history;
268
 
  }
269
 
 
270
 
private:
271
147
  int exit_status;
272
148
  uint32_t query_start_line;
273
149
  char *file_name;
274
 
  LineBuffer *line_buff;
 
150
  LINE_BUFFER *line_buff;
275
151
  bool batch,add_to_history;
276
 
}; 
 
152
} STATUS;
 
153
 
277
154
 
278
155
static map<string, string>::iterator completion_iter;
279
156
static map<string, string>::iterator completion_end;
280
157
static map<string, string> completion_map;
281
158
static string completion_string;
282
159
 
 
160
static char **defaults_argv;
283
161
 
284
162
enum enum_info_type { INFO_INFO,INFO_ERROR,INFO_RESULT};
285
163
typedef enum enum_info_type INFO_TYPE;
290
168
  connected= false, opt_raw_data= false, unbuffered= false,
291
169
  output_tables= false, opt_rehash= true, skip_updates= false,
292
170
  safe_updates= false, one_database= false,
293
 
  opt_shutdown= false, opt_ping= false,
 
171
  opt_compress= false, opt_shutdown= false, opt_ping= false,
294
172
  vertical= false, line_numbers= true, column_names= true,
295
173
  opt_nopager= true, opt_outfile= false, named_cmds= false,
296
 
  opt_nobeep= false, opt_reconnect= true,
297
 
  opt_secure_auth= false,
 
174
  tty_password= false, opt_nobeep= false, opt_reconnect= true,
 
175
  default_charset_used= false, opt_secure_auth= false,
298
176
  default_pager_set= false, opt_sigint_ignore= false,
299
177
  auto_vertical_output= false,
300
 
  show_warnings= false, executing_query= false, interrupted_query= false,
301
 
  use_drizzle_protocol= false, opt_local_infile;
302
 
static uint32_t show_progress_size= 0;
 
178
  show_warnings= false, executing_query= false, interrupted_query= false;
 
179
static uint32_t  show_progress_size= 0;
 
180
static bool debug_info_flag, debug_check_flag;
303
181
static bool column_types_flag;
304
182
static bool preserve_comments= false;
305
 
static uint32_t opt_max_input_line;
306
 
static uint32_t opt_drizzle_port= 0;
307
 
static int  opt_silent, verbose= 0;
 
183
static uint32_t opt_max_input_line, opt_drizzle_port= 0;
 
184
static int verbose= 0, opt_silent= 0, opt_local_infile= 0;
 
185
static uint32_t my_end_arg;
 
186
static char * opt_drizzle_unix_port= NULL;
308
187
static drizzle_capabilities_t connect_flag= DRIZZLE_CAPABILITIES_NONE;
 
188
static char *current_host, *current_db, *current_user= NULL,
 
189
  *opt_password= NULL, *delimiter_str= NULL, *current_prompt= NULL;
309
190
static char *histfile;
310
191
static char *histfile_tmp;
311
192
static string *glob_buffer;
312
193
static string *processed_prompt= NULL;
313
194
static char *default_prompt= NULL;
314
195
static char *full_username= NULL,*part_username= NULL;
315
 
static Status status;
 
196
static STATUS status;
316
197
static uint32_t select_limit;
317
198
static uint32_t max_join_size;
318
199
static uint32_t opt_connect_timeout= 0;
319
 
std::string current_db,
320
 
  delimiter_str,  
321
 
  current_host,
322
 
  current_prompt,
323
 
  current_user,
324
 
  opt_verbose,
325
 
  current_password,
326
 
  opt_password,
327
 
  opt_protocol;
328
200
// TODO: Need to i18n these
329
201
static const char *day_names[]= {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
330
202
static const char *month_names[]= {"Jan","Feb","Mar","Apr","May","Jun","Jul",
331
203
                                  "Aug","Sep","Oct","Nov","Dec"};
332
 
/* @TODO: Remove this */
333
 
#define FN_REFLEN 512
334
 
 
335
 
static string default_pager("");
336
 
static string pager("");
337
 
static string outfile("");
 
204
static char default_pager[FN_REFLEN];
 
205
static char pager[FN_REFLEN], outfile[FN_REFLEN];
338
206
static FILE *PAGER, *OUTFILE;
339
207
static uint32_t prompt_counter;
340
 
static char *delimiter= NULL;
 
208
static char delimiter[16]= DEFAULT_DELIMITER;
341
209
static uint32_t delimiter_length= 1;
342
210
unsigned short terminal_width= 80;
343
211
 
344
 
int drizzleclient_real_query_for_lazy(const char *buf, size_t length,
 
212
static const CHARSET_INFO *charset_info= &my_charset_utf8_general_ci;
 
213
 
 
214
int drizzleclient_real_query_for_lazy(const char *buf, int length,
345
215
                                      drizzle_result_st *result,
346
216
                                      uint32_t *error_code);
347
217
int drizzleclient_store_result_for_lazy(drizzle_result_st *result);
353
223
void tee_putc(int c, FILE *file);
354
224
static void tee_print_sized_data(const char *, unsigned int, unsigned int, bool);
355
225
/* The names of functions that actually do the manipulation. */
356
 
static int process_options(void);
 
226
static int get_options(int argc,char **argv);
 
227
extern "C" bool get_one_option(int optid, const struct my_option *opt,
 
228
                               char *argument);
357
229
static int com_quit(string *str,const char*),
358
230
  com_go(string *str,const char*), com_ego(string *str,const char*),
359
231
  com_print(string *str,const char*),
360
232
  com_help(string *str,const char*), com_clear(string *str,const char*),
361
233
  com_connect(string *str,const char*), com_status(string *str,const char*),
362
234
  com_use(string *str,const char*), com_source(string *str, const char*),
363
 
  com_shutdown(string *str,const char*),
364
235
  com_rehash(string *str, const char*), com_tee(string *str, const char*),
365
236
  com_notee(string *str, const char*),
366
237
  com_prompt(string *str, const char*), com_delimiter(string *str, const char*),
368
239
  com_nopager(string *str, const char*), com_pager(string *str, const char*);
369
240
 
370
241
static int read_and_execute(bool interactive);
371
 
static int sql_connect(const string &host, const string &database, const string &user, const string &password,
 
242
static int sql_connect(char *host,char *database,char *user,char *password,
372
243
                       uint32_t silent);
373
244
static const char *server_version_string(drizzle_con_st *con);
374
245
static int put_info(const char *str,INFO_TYPE info,uint32_t error,
387
258
static int get_field_disp_length(drizzle_column_st * field);
388
259
static const char * strcont(register const char *str, register const char *set);
389
260
 
390
 
/* A class which contains information on the commands this program
 
261
/* A structure which contains information on the commands this program
391
262
   can understand. */
392
 
class Commands
393
 
{
394
 
private:
 
263
typedef struct {
395
264
  const char *name;        /* User printable name of the function. */
396
265
  char cmd_char;        /* msql command character */
397
 
public:
398
 
Commands(const char *in_name,
399
 
         char in_cmd_char,
400
 
         int (*in_func)(string *str,const char *name),
401
 
         bool in_takes_params,
402
 
         const char *in_doc)
403
 
  :
404
 
  name(in_name),
405
 
  cmd_char(in_cmd_char),
406
 
  func(in_func),
407
 
  takes_params(in_takes_params),
408
 
  doc(in_doc)
409
 
  {}
410
 
 
411
 
  Commands()
412
 
  :
413
 
  name(),
414
 
  cmd_char(),
415
 
  func(NULL),
416
 
  takes_params(false),
417
 
  doc()
418
 
  {}
419
 
 
420
 
  int (*func)(string *str,const char *);/* Function to call to do the job. */
421
 
 
422
 
  const char *getName() const
423
 
  {
424
 
    return name;
425
 
  }
426
 
 
427
 
  char getCmdChar() const
428
 
  {
429
 
    return cmd_char;
430
 
  }
431
 
 
432
 
  bool getTakesParams() const
433
 
  {
434
 
    return takes_params;
435
 
  }
436
 
 
437
 
  const char *getDoc() const
438
 
  {
439
 
    return doc;
440
 
  }
441
 
 
442
 
  void setName(const char *in_name)
443
 
  {
444
 
     name= in_name;
445
 
  }
446
 
 
447
 
  void setCmdChar(char in_cmd_char)
448
 
  {
449
 
    cmd_char= in_cmd_char;
450
 
  }
451
 
 
452
 
  void setTakesParams(bool in_takes_params)
453
 
  {
454
 
    takes_params= in_takes_params;
455
 
  }
456
 
 
457
 
  void setDoc(const char *in_doc)
458
 
  {
459
 
    doc= in_doc;
460
 
  }
461
 
 
462
 
private:
 
266
  int (*func)(string *str,const char *); /* Function to call to do the job. */
463
267
  bool takes_params;        /* Max parameters for command */
464
268
  const char *doc;        /* Documentation for this function.  */
465
 
}; 
466
 
 
467
 
 
468
 
static Commands commands[] = {
469
 
  Commands( "?",      '?', com_help,   0, N_("Synonym for `help'.") ),
470
 
  Commands( "clear",  'c', com_clear,  0, N_("Clear command.")),
471
 
  Commands( "connect",'r', com_connect,1,
472
 
    N_("Reconnect to the server. Optional arguments are db and host.")),
473
 
  Commands( "delimiter", 'd', com_delimiter,    1,
474
 
    N_("Set statement delimiter. NOTE: Takes the rest of the line as new delimiter.") ),
475
 
  Commands( "ego",    'G', com_ego,    0,
476
 
    N_("Send command to drizzle server, display result vertically.")),
477
 
  Commands( "exit",   'q', com_quit,   0, N_("Exit drizzle. Same as quit.")),
478
 
  Commands( "go",     'g', com_go,     0, N_("Send command to drizzle server.") ),
479
 
  Commands( "help",   'h', com_help,   0, N_("Display this help.") ),
480
 
  Commands( "nopager",'n', com_nopager,0, N_("Disable pager, print to stdout.") ),
481
 
  Commands( "notee",  't', com_notee,  0, N_("Don't write into outfile.") ),
482
 
  Commands( "pager",  'P', com_pager,  1,
483
 
    N_("Set PAGER [to_pager]. Print the query results via PAGER.") ),
484
 
  Commands( "print",  'p', com_print,  0, N_("Print current command.") ),
485
 
  Commands( "prompt", 'R', com_prompt, 1, N_("Change your drizzle prompt.")),
486
 
  Commands( "quit",   'q', com_quit,   0, N_("Quit drizzle.") ),
487
 
  Commands( "rehash", '#', com_rehash, 0, N_("Rebuild completion hash.") ),
488
 
  Commands( "source", '.', com_source, 1,
489
 
    N_("Execute an SQL script file. Takes a file name as an argument.")),
490
 
  Commands( "status", 's', com_status, 0, N_("Get status information from the server.")),
491
 
  Commands( "tee",    'T', com_tee,    1,
492
 
    N_("Set outfile [to_outfile]. Append everything into given outfile.") ),
493
 
  Commands( "use",    'u', com_use,    1,
494
 
    N_("Use another database. Takes database name as argument.") ),
495
 
  Commands( "shutdown",    'u', com_shutdown,    1,
496
 
    N_("Shutdown the instance you are connected too.") ),
497
 
  Commands( "warnings", 'W', com_warnings,  0,
498
 
    N_("Show warnings after every statement.") ),
499
 
  Commands( "nowarning", 'w', com_nowarnings, 0,
500
 
    N_("Don't show warnings after every statement.") ),
 
269
} COMMANDS;
 
270
 
 
271
 
 
272
static COMMANDS commands[] = {
 
273
  { "?",      '?', com_help,   0, N_("Synonym for `help'.") },
 
274
  { "clear",  'c', com_clear,  0, N_("Clear command.")},
 
275
  { "connect",'r', com_connect,1,
 
276
    N_("Reconnect to the server. Optional arguments are db and host." }),
 
277
  { "delimiter", 'd', com_delimiter,    1,
 
278
    N_("Set statement delimiter. NOTE: Takes the rest of the line as new delimiter.") },
 
279
  { "ego",    'G', com_ego,    0,
 
280
    N_("Send command to drizzle server, display result vertically.")},
 
281
  { "exit",   'q', com_quit,   0, N_("Exit drizzle. Same as quit.")},
 
282
  { "go",     'g', com_go,     0, N_("Send command to drizzle server.") },
 
283
  { "help",   'h', com_help,   0, N_("Display this help.") },
 
284
  { "nopager",'n', com_nopager,0, N_("Disable pager, print to stdout.") },
 
285
  { "notee",  't', com_notee,  0, N_("Don't write into outfile.") },
 
286
  { "pager",  'P', com_pager,  1,
 
287
    N_("Set PAGER [to_pager]. Print the query results via PAGER.") },
 
288
  { "print",  'p', com_print,  0, N_("Print current command.") },
 
289
  { "prompt", 'R', com_prompt, 1, N_("Change your drizzle prompt.")},
 
290
  { "quit",   'q', com_quit,   0, N_("Quit drizzle.") },
 
291
  { "rehash", '#', com_rehash, 0, N_("Rebuild completion hash.") },
 
292
  { "source", '.', com_source, 1,
 
293
    N_("Execute an SQL script file. Takes a file name as an argument.")},
 
294
  { "status", 's', com_status, 0, N_("Get status information from the server.")},
 
295
  { "tee",    'T', com_tee,    1,
 
296
    N_("Set outfile [to_outfile]. Append everything into given outfile.") },
 
297
  { "use",    'u', com_use,    1,
 
298
    N_("Use another database. Takes database name as argument.") },
 
299
  { "warnings", 'W', com_warnings,  0,
 
300
    N_("Show warnings after every statement.") },
 
301
  { "nowarning", 'w', com_nowarnings, 0,
 
302
    N_("Don't show warnings after every statement.") },
501
303
  /* Get bash-like expansion for some commands */
502
 
  Commands( "create table",     0, 0, 0, ""),
503
 
  Commands( "create database",  0, 0, 0, ""),
504
 
  Commands( "show databases",   0, 0, 0, ""),
505
 
  Commands( "show fields from", 0, 0, 0, ""),
506
 
  Commands( "show keys from",   0, 0, 0, ""),
507
 
  Commands( "show tables",      0, 0, 0, ""),
508
 
  Commands( "load data from",   0, 0, 0, ""),
509
 
  Commands( "alter table",      0, 0, 0, ""),
510
 
  Commands( "set option",       0, 0, 0, ""),
511
 
  Commands( "lock tables",      0, 0, 0, ""),
512
 
  Commands( "unlock tables",    0, 0, 0, ""),
 
304
  { "create table",     0, 0, 0, ""},
 
305
  { "create database",  0, 0, 0, ""},
 
306
  { "show databases",   0, 0, 0, ""},
 
307
  { "show fields from", 0, 0, 0, ""},
 
308
  { "show keys from",   0, 0, 0, ""},
 
309
  { "show tables",      0, 0, 0, ""},
 
310
  { "load data from",   0, 0, 0, ""},
 
311
  { "alter table",      0, 0, 0, ""},
 
312
  { "set option",       0, 0, 0, ""},
 
313
  { "lock tables",      0, 0, 0, ""},
 
314
  { "unlock tables",    0, 0, 0, ""},
513
315
  /* generated 2006-12-28.  Refresh occasionally from lexer. */
514
 
  Commands( "ACTION", 0, 0, 0, ""),
515
 
  Commands( "ADD", 0, 0, 0, ""),
516
 
  Commands( "AFTER", 0, 0, 0, ""),
517
 
  Commands( "AGAINST", 0, 0, 0, ""),
518
 
  Commands( "AGGREGATE", 0, 0, 0, ""),
519
 
  Commands( "ALL", 0, 0, 0, ""),
520
 
  Commands( "ALGORITHM", 0, 0, 0, ""),
521
 
  Commands( "ALTER", 0, 0, 0, ""),
522
 
  Commands( "ANALYZE", 0, 0, 0, ""),
523
 
  Commands( "AND", 0, 0, 0, ""),
524
 
  Commands( "ANY", 0, 0, 0, ""),
525
 
  Commands( "AS", 0, 0, 0, ""),
526
 
  Commands( "ASC", 0, 0, 0, ""),
527
 
  Commands( "ASCII", 0, 0, 0, ""),
528
 
  Commands( "ASENSITIVE", 0, 0, 0, ""),
529
 
  Commands( "AUTO_INCREMENT", 0, 0, 0, ""),
530
 
  Commands( "AVG", 0, 0, 0, ""),
531
 
  Commands( "AVG_ROW_LENGTH", 0, 0, 0, ""),
532
 
  Commands( "BEFORE", 0, 0, 0, ""),
533
 
  Commands( "BEGIN", 0, 0, 0, ""),
534
 
  Commands( "BETWEEN", 0, 0, 0, ""),
535
 
  Commands( "BIGINT", 0, 0, 0, ""),
536
 
  Commands( "BINARY", 0, 0, 0, ""),
537
 
  Commands( "BIT", 0, 0, 0, ""),
538
 
  Commands( "BLOB", 0, 0, 0, ""),
539
 
  Commands( "BOOL", 0, 0, 0, ""),
540
 
  Commands( "BOOLEAN", 0, 0, 0, ""),
541
 
  Commands( "BOTH", 0, 0, 0, ""),
542
 
  Commands( "BTREE", 0, 0, 0, ""),
543
 
  Commands( "BY", 0, 0, 0, ""),
544
 
  Commands( "BYTE", 0, 0, 0, ""),
545
 
  Commands( "CACHE", 0, 0, 0, ""),
546
 
  Commands( "CALL", 0, 0, 0, ""),
547
 
  Commands( "CASCADE", 0, 0, 0, ""),
548
 
  Commands( "CASCADED", 0, 0, 0, ""),
549
 
  Commands( "CASE", 0, 0, 0, ""),
550
 
  Commands( "CHAIN", 0, 0, 0, ""),
551
 
  Commands( "CHANGE", 0, 0, 0, ""),
552
 
  Commands( "CHANGED", 0, 0, 0, ""),
553
 
  Commands( "CHAR", 0, 0, 0, ""),
554
 
  Commands( "CHARACTER", 0, 0, 0, ""),
555
 
  Commands( "CHECK", 0, 0, 0, ""),
556
 
  Commands( "CHECKSUM", 0, 0, 0, ""),
557
 
  Commands( "CLIENT", 0, 0, 0, ""),
558
 
  Commands( "CLOSE", 0, 0, 0, ""),
559
 
  Commands( "COLLATE", 0, 0, 0, ""),
560
 
  Commands( "COLLATION", 0, 0, 0, ""),
561
 
  Commands( "COLUMN", 0, 0, 0, ""),
562
 
  Commands( "COLUMNS", 0, 0, 0, ""),
563
 
  Commands( "COMMENT", 0, 0, 0, ""),
564
 
  Commands( "COMMIT", 0, 0, 0, ""),
565
 
  Commands( "COMMITTED", 0, 0, 0, ""),
566
 
  Commands( "COMPACT", 0, 0, 0, ""),
567
 
  Commands( "COMPRESSED", 0, 0, 0, ""),
568
 
  Commands( "CONCURRENT", 0, 0, 0, ""),
569
 
  Commands( "CONDITION", 0, 0, 0, ""),
570
 
  Commands( "CONNECTION", 0, 0, 0, ""),
571
 
  Commands( "CONSISTENT", 0, 0, 0, ""),
572
 
  Commands( "CONSTRAINT", 0, 0, 0, ""),
573
 
  Commands( "CONTAINS", 0, 0, 0, ""),
574
 
  Commands( "CONTINUE", 0, 0, 0, ""),
575
 
  Commands( "CONVERT", 0, 0, 0, ""),
576
 
  Commands( "CREATE", 0, 0, 0, ""),
577
 
  Commands( "CROSS", 0, 0, 0, ""),
578
 
  Commands( "CUBE", 0, 0, 0, ""),
579
 
  Commands( "CURRENT_DATE", 0, 0, 0, ""),
580
 
  Commands( "CURRENT_TIMESTAMP", 0, 0, 0, ""),
581
 
  Commands( "CURRENT_USER", 0, 0, 0, ""),
582
 
  Commands( "CURSOR", 0, 0, 0, ""),
583
 
  Commands( "DATA", 0, 0, 0, ""),
584
 
  Commands( "DATABASE", 0, 0, 0, ""),
585
 
  Commands( "DATABASES", 0, 0, 0, ""),
586
 
  Commands( "DATE", 0, 0, 0, ""),
587
 
  Commands( "DATETIME", 0, 0, 0, ""),
588
 
  Commands( "DAY", 0, 0, 0, ""),
589
 
  Commands( "DAY_HOUR", 0, 0, 0, ""),
590
 
  Commands( "DAY_MICROSECOND", 0, 0, 0, ""),
591
 
  Commands( "DAY_MINUTE", 0, 0, 0, ""),
592
 
  Commands( "DAY_SECOND", 0, 0, 0, ""),
593
 
  Commands( "DEALLOCATE", 0, 0, 0, ""),
594
 
  Commands( "DEC", 0, 0, 0, ""),
595
 
  Commands( "DECIMAL", 0, 0, 0, ""),
596
 
  Commands( "DECLARE", 0, 0, 0, ""),
597
 
  Commands( "DEFAULT", 0, 0, 0, ""),
598
 
  Commands( "DEFINER", 0, 0, 0, ""),
599
 
  Commands( "DELAYED", 0, 0, 0, ""),
600
 
  Commands( "DELETE", 0, 0, 0, ""),
601
 
  Commands( "DESC", 0, 0, 0, ""),
602
 
  Commands( "DESCRIBE", 0, 0, 0, ""),
603
 
  Commands( "DETERMINISTIC", 0, 0, 0, ""),
604
 
  Commands( "DISABLE", 0, 0, 0, ""),
605
 
  Commands( "DISCARD", 0, 0, 0, ""),
606
 
  Commands( "DISTINCT", 0, 0, 0, ""),
607
 
  Commands( "DISTINCTROW", 0, 0, 0, ""),
608
 
  Commands( "DIV", 0, 0, 0, ""),
609
 
  Commands( "DOUBLE", 0, 0, 0, ""),
610
 
  Commands( "DROP", 0, 0, 0, ""),
611
 
  Commands( "DUMPFILE", 0, 0, 0, ""),
612
 
  Commands( "DUPLICATE", 0, 0, 0, ""),
613
 
  Commands( "DYNAMIC", 0, 0, 0, ""),
614
 
  Commands( "EACH", 0, 0, 0, ""),
615
 
  Commands( "ELSE", 0, 0, 0, ""),
616
 
  Commands( "ELSEIF", 0, 0, 0, ""),
617
 
  Commands( "ENABLE", 0, 0, 0, ""),
618
 
  Commands( "ENCLOSED", 0, 0, 0, ""),
619
 
  Commands( "END", 0, 0, 0, ""),
620
 
  Commands( "ENGINE", 0, 0, 0, ""),
621
 
  Commands( "ENGINES", 0, 0, 0, ""),
622
 
  Commands( "ENUM", 0, 0, 0, ""),
623
 
  Commands( "ERRORS", 0, 0, 0, ""),
624
 
  Commands( "ESCAPE", 0, 0, 0, ""),
625
 
  Commands( "ESCAPED", 0, 0, 0, ""),
626
 
  Commands( "EXISTS", 0, 0, 0, ""),
627
 
  Commands( "EXIT", 0, 0, 0, ""),
628
 
  Commands( "EXPLAIN", 0, 0, 0, ""),
629
 
  Commands( "EXTENDED", 0, 0, 0, ""),
630
 
  Commands( "FALSE", 0, 0, 0, ""),
631
 
  Commands( "FAST", 0, 0, 0, ""),
632
 
  Commands( "FETCH", 0, 0, 0, ""),
633
 
  Commands( "FIELDS", 0, 0, 0, ""),
634
 
  Commands( "FILE", 0, 0, 0, ""),
635
 
  Commands( "FIRST", 0, 0, 0, ""),
636
 
  Commands( "FIXED", 0, 0, 0, ""),
637
 
  Commands( "FLOAT", 0, 0, 0, ""),
638
 
  Commands( "FLOAT4", 0, 0, 0, ""),
639
 
  Commands( "FLOAT8", 0, 0, 0, ""),
640
 
  Commands( "FLUSH", 0, 0, 0, ""),
641
 
  Commands( "FOR", 0, 0, 0, ""),
642
 
  Commands( "FORCE", 0, 0, 0, ""),
643
 
  Commands( "FOREIGN", 0, 0, 0, ""),
644
 
  Commands( "FOUND", 0, 0, 0, ""),
645
 
  Commands( "FRAC_SECOND", 0, 0, 0, ""),
646
 
  Commands( "FROM", 0, 0, 0, ""),
647
 
  Commands( "FULL", 0, 0, 0, ""),
648
 
  Commands( "FUNCTION", 0, 0, 0, ""),
649
 
  Commands( "GLOBAL", 0, 0, 0, ""),
650
 
  Commands( "GRANT", 0, 0, 0, ""),
651
 
  Commands( "GRANTS", 0, 0, 0, ""),
652
 
  Commands( "GROUP", 0, 0, 0, ""),
653
 
  Commands( "HANDLER", 0, 0, 0, ""),
654
 
  Commands( "HASH", 0, 0, 0, ""),
655
 
  Commands( "HAVING", 0, 0, 0, ""),
656
 
  Commands( "HELP", 0, 0, 0, ""),
657
 
  Commands( "HIGH_PRIORITY", 0, 0, 0, ""),
658
 
  Commands( "HOSTS", 0, 0, 0, ""),
659
 
  Commands( "HOUR", 0, 0, 0, ""),
660
 
  Commands( "HOUR_MICROSECOND", 0, 0, 0, ""),
661
 
  Commands( "HOUR_MINUTE", 0, 0, 0, ""),
662
 
  Commands( "HOUR_SECOND", 0, 0, 0, ""),
663
 
  Commands( "IDENTIFIED", 0, 0, 0, ""),
664
 
  Commands( "IF", 0, 0, 0, ""),
665
 
  Commands( "IGNORE", 0, 0, 0, ""),
666
 
  Commands( "IMPORT", 0, 0, 0, ""),
667
 
  Commands( "IN", 0, 0, 0, ""),
668
 
  Commands( "INDEX", 0, 0, 0, ""),
669
 
  Commands( "INDEXES", 0, 0, 0, ""),
670
 
  Commands( "INFILE", 0, 0, 0, ""),
671
 
  Commands( "INNER", 0, 0, 0, ""),
672
 
  Commands( "INNOBASE", 0, 0, 0, ""),
673
 
  Commands( "INNODB", 0, 0, 0, ""),
674
 
  Commands( "INOUT", 0, 0, 0, ""),
675
 
  Commands( "INSENSITIVE", 0, 0, 0, ""),
676
 
  Commands( "INSERT", 0, 0, 0, ""),
677
 
  Commands( "INSERT_METHOD", 0, 0, 0, ""),
678
 
  Commands( "INT", 0, 0, 0, ""),
679
 
  Commands( "INT1", 0, 0, 0, ""),
680
 
  Commands( "INT2", 0, 0, 0, ""),
681
 
  Commands( "INT3", 0, 0, 0, ""),
682
 
  Commands( "INT4", 0, 0, 0, ""),
683
 
  Commands( "INT8", 0, 0, 0, ""),
684
 
  Commands( "INTEGER", 0, 0, 0, ""),
685
 
  Commands( "INTERVAL", 0, 0, 0, ""),
686
 
  Commands( "INTO", 0, 0, 0, ""),
687
 
  Commands( "IO_THREAD", 0, 0, 0, ""),
688
 
  Commands( "IS", 0, 0, 0, ""),
689
 
  Commands( "ISOLATION", 0, 0, 0, ""),
690
 
  Commands( "ISSUER", 0, 0, 0, ""),
691
 
  Commands( "ITERATE", 0, 0, 0, ""),
692
 
  Commands( "INVOKER", 0, 0, 0, ""),
693
 
  Commands( "JOIN", 0, 0, 0, ""),
694
 
  Commands( "KEY", 0, 0, 0, ""),
695
 
  Commands( "KEYS", 0, 0, 0, ""),
696
 
  Commands( "KILL", 0, 0, 0, ""),
697
 
  Commands( "LANGUAGE", 0, 0, 0, ""),
698
 
  Commands( "LAST", 0, 0, 0, ""),
699
 
  Commands( "LEADING", 0, 0, 0, ""),
700
 
  Commands( "LEAVE", 0, 0, 0, ""),
701
 
  Commands( "LEAVES", 0, 0, 0, ""),
702
 
  Commands( "LEFT", 0, 0, 0, ""),
703
 
  Commands( "LEVEL", 0, 0, 0, ""),
704
 
  Commands( "LIKE", 0, 0, 0, ""),
705
 
  Commands( "LIMIT", 0, 0, 0, ""),
706
 
  Commands( "LINES", 0, 0, 0, ""),
707
 
  Commands( "LINESTRING", 0, 0, 0, ""),
708
 
  Commands( "LOAD", 0, 0, 0, ""),
709
 
  Commands( "LOCAL", 0, 0, 0, ""),
710
 
  Commands( "LOCALTIMESTAMP", 0, 0, 0, ""),
711
 
  Commands( "LOCK", 0, 0, 0, ""),
712
 
  Commands( "LOCKS", 0, 0, 0, ""),
713
 
  Commands( "LOGS", 0, 0, 0, ""),
714
 
  Commands( "LONG", 0, 0, 0, ""),
715
 
  Commands( "LOOP", 0, 0, 0, ""),
716
 
  Commands( "MATCH", 0, 0, 0, ""),
717
 
  Commands( "MAX_CONNECTIONS_PER_HOUR", 0, 0, 0, ""),
718
 
  Commands( "MAX_QUERIES_PER_HOUR", 0, 0, 0, ""),
719
 
  Commands( "MAX_ROWS", 0, 0, 0, ""),
720
 
  Commands( "MAX_UPDATES_PER_HOUR", 0, 0, 0, ""),
721
 
  Commands( "MAX_USER_CONNECTIONS", 0, 0, 0, ""),
722
 
  Commands( "MEDIUM", 0, 0, 0, ""),
723
 
  Commands( "MERGE", 0, 0, 0, ""),
724
 
  Commands( "MICROSECOND", 0, 0, 0, ""),
725
 
  Commands( "MIGRATE", 0, 0, 0, ""),
726
 
  Commands( "MINUTE", 0, 0, 0, ""),
727
 
  Commands( "MINUTE_MICROSECOND", 0, 0, 0, ""),
728
 
  Commands( "MINUTE_SECOND", 0, 0, 0, ""),
729
 
  Commands( "MIN_ROWS", 0, 0, 0, ""),
730
 
  Commands( "MOD", 0, 0, 0, ""),
731
 
  Commands( "MODE", 0, 0, 0, ""),
732
 
  Commands( "MODIFIES", 0, 0, 0, ""),
733
 
  Commands( "MODIFY", 0, 0, 0, ""),
734
 
  Commands( "MONTH", 0, 0, 0, ""),
735
 
  Commands( "MULTILINESTRING", 0, 0, 0, ""),
736
 
  Commands( "MULTIPOINT", 0, 0, 0, ""),
737
 
  Commands( "MULTIPOLYGON", 0, 0, 0, ""),
738
 
  Commands( "MUTEX", 0, 0, 0, ""),
739
 
  Commands( "NAME", 0, 0, 0, ""),
740
 
  Commands( "NAMES", 0, 0, 0, ""),
741
 
  Commands( "NATIONAL", 0, 0, 0, ""),
742
 
  Commands( "NATURAL", 0, 0, 0, ""),
743
 
  Commands( "NCHAR", 0, 0, 0, ""),
744
 
  Commands( "NEW", 0, 0, 0, ""),
745
 
  Commands( "NEXT", 0, 0, 0, ""),
746
 
  Commands( "NO", 0, 0, 0, ""),
747
 
  Commands( "NONE", 0, 0, 0, ""),
748
 
  Commands( "NOT", 0, 0, 0, ""),
749
 
  Commands( "NULL", 0, 0, 0, ""),
750
 
  Commands( "NUMERIC", 0, 0, 0, ""),
751
 
  Commands( "NVARCHAR", 0, 0, 0, ""),
752
 
  Commands( "OFFSET", 0, 0, 0, ""),
753
 
  Commands( "ON", 0, 0, 0, ""),
754
 
  Commands( "ONE", 0, 0, 0, ""),
755
 
  Commands( "ONE_SHOT", 0, 0, 0, ""),
756
 
  Commands( "OPEN", 0, 0, 0, ""),
757
 
  Commands( "OPTIMIZE", 0, 0, 0, ""),
758
 
  Commands( "OPTION", 0, 0, 0, ""),
759
 
  Commands( "OPTIONALLY", 0, 0, 0, ""),
760
 
  Commands( "OR", 0, 0, 0, ""),
761
 
  Commands( "ORDER", 0, 0, 0, ""),
762
 
  Commands( "OUT", 0, 0, 0, ""),
763
 
  Commands( "OUTER", 0, 0, 0, ""),
764
 
  Commands( "OUTFILE", 0, 0, 0, ""),
765
 
  Commands( "PACK_KEYS", 0, 0, 0, ""),
766
 
  Commands( "PARTIAL", 0, 0, 0, ""),
767
 
  Commands( "PASSWORD", 0, 0, 0, ""),
768
 
  Commands( "PHASE", 0, 0, 0, ""),
769
 
  Commands( "PRECISION", 0, 0, 0, ""),
770
 
  Commands( "PREPARE", 0, 0, 0, ""),
771
 
  Commands( "PREV", 0, 0, 0, ""),
772
 
  Commands( "PRIMARY", 0, 0, 0, ""),
773
 
  Commands( "PRIVILEGES", 0, 0, 0, ""),
774
 
  Commands( "PROCEDURE", 0, 0, 0, ""),
775
 
  Commands( "PROCESS", 0, 0, 0, ""),
776
 
  Commands( "PROCESSLIST", 0, 0, 0, ""),
777
 
  Commands( "PURGE", 0, 0, 0, ""),
778
 
  Commands( "QUARTER", 0, 0, 0, ""),
779
 
  Commands( "QUERY", 0, 0, 0, ""),
780
 
  Commands( "QUICK", 0, 0, 0, ""),
781
 
  Commands( "READ", 0, 0, 0, ""),
782
 
  Commands( "READS", 0, 0, 0, ""),
783
 
  Commands( "REAL", 0, 0, 0, ""),
784
 
  Commands( "RECOVER", 0, 0, 0, ""),
785
 
  Commands( "REDUNDANT", 0, 0, 0, ""),
786
 
  Commands( "REFERENCES", 0, 0, 0, ""),
787
 
  Commands( "REGEXP", 0, 0, 0, ""),
788
 
  Commands( "RELEASE", 0, 0, 0, ""),
789
 
  Commands( "RELOAD", 0, 0, 0, ""),
790
 
  Commands( "RENAME", 0, 0, 0, ""),
791
 
  Commands( "REPAIR", 0, 0, 0, ""),
792
 
  Commands( "REPEATABLE", 0, 0, 0, ""),
793
 
  Commands( "REPLACE", 0, 0, 0, ""),
794
 
  Commands( "REPEAT", 0, 0, 0, ""),
795
 
  Commands( "REQUIRE", 0, 0, 0, ""),
796
 
  Commands( "RESET", 0, 0, 0, ""),
797
 
  Commands( "RESTORE", 0, 0, 0, ""),
798
 
  Commands( "RESTRICT", 0, 0, 0, ""),
799
 
  Commands( "RESUME", 0, 0, 0, ""),
800
 
  Commands( "RETURN", 0, 0, 0, ""),
801
 
  Commands( "RETURNS", 0, 0, 0, ""),
802
 
  Commands( "REVOKE", 0, 0, 0, ""),
803
 
  Commands( "RIGHT", 0, 0, 0, ""),
804
 
  Commands( "RLIKE", 0, 0, 0, ""),
805
 
  Commands( "ROLLBACK", 0, 0, 0, ""),
806
 
  Commands( "ROLLUP", 0, 0, 0, ""),
807
 
  Commands( "ROUTINE", 0, 0, 0, ""),
808
 
  Commands( "ROW", 0, 0, 0, ""),
809
 
  Commands( "ROWS", 0, 0, 0, ""),
810
 
  Commands( "ROW_FORMAT", 0, 0, 0, ""),
811
 
  Commands( "RTREE", 0, 0, 0, ""),
812
 
  Commands( "SAVEPOINT", 0, 0, 0, ""),
813
 
  Commands( "SCHEMA", 0, 0, 0, ""),
814
 
  Commands( "SCHEMAS", 0, 0, 0, ""),
815
 
  Commands( "SECOND", 0, 0, 0, ""),
816
 
  Commands( "SECOND_MICROSECOND", 0, 0, 0, ""),
817
 
  Commands( "SECURITY", 0, 0, 0, ""),
818
 
  Commands( "SELECT", 0, 0, 0, ""),
819
 
  Commands( "SENSITIVE", 0, 0, 0, ""),
820
 
  Commands( "SEPARATOR", 0, 0, 0, ""),
821
 
  Commands( "SERIAL", 0, 0, 0, ""),
822
 
  Commands( "SERIALIZABLE", 0, 0, 0, ""),
823
 
  Commands( "SESSION", 0, 0, 0, ""),
824
 
  Commands( "SET", 0, 0, 0, ""),
825
 
  Commands( "SHARE", 0, 0, 0, ""),
826
 
  Commands( "SHOW", 0, 0, 0, ""),
827
 
  Commands( "SHUTDOWN", 0, 0, 0, ""),
828
 
  Commands( "SIGNED", 0, 0, 0, ""),
829
 
  Commands( "SIMPLE", 0, 0, 0, ""),
830
 
  Commands( "SLAVE", 0, 0, 0, ""),
831
 
  Commands( "SNAPSHOT", 0, 0, 0, ""),
832
 
  Commands( "SOME", 0, 0, 0, ""),
833
 
  Commands( "SONAME", 0, 0, 0, ""),
834
 
  Commands( "SOUNDS", 0, 0, 0, ""),
835
 
  Commands( "SPATIAL", 0, 0, 0, ""),
836
 
  Commands( "SPECIFIC", 0, 0, 0, ""),
837
 
  Commands( "SQL", 0, 0, 0, ""),
838
 
  Commands( "SQLEXCEPTION", 0, 0, 0, ""),
839
 
  Commands( "SQLSTATE", 0, 0, 0, ""),
840
 
  Commands( "SQLWARNING", 0, 0, 0, ""),
841
 
  Commands( "SQL_BIG_RESULT", 0, 0, 0, ""),
842
 
  Commands( "SQL_BUFFER_RESULT", 0, 0, 0, ""),
843
 
  Commands( "SQL_CACHE", 0, 0, 0, ""),
844
 
  Commands( "SQL_CALC_FOUND_ROWS", 0, 0, 0, ""),
845
 
  Commands( "SQL_NO_CACHE", 0, 0, 0, ""),
846
 
  Commands( "SQL_SMALL_RESULT", 0, 0, 0, ""),
847
 
  Commands( "SQL_THREAD", 0, 0, 0, ""),
848
 
  Commands( "SQL_TSI_FRAC_SECOND", 0, 0, 0, ""),
849
 
  Commands( "SQL_TSI_SECOND", 0, 0, 0, ""),
850
 
  Commands( "SQL_TSI_MINUTE", 0, 0, 0, ""),
851
 
  Commands( "SQL_TSI_HOUR", 0, 0, 0, ""),
852
 
  Commands( "SQL_TSI_DAY", 0, 0, 0, ""),
853
 
  Commands( "SQL_TSI_WEEK", 0, 0, 0, ""),
854
 
  Commands( "SQL_TSI_MONTH", 0, 0, 0, ""),
855
 
  Commands( "SQL_TSI_QUARTER", 0, 0, 0, ""),
856
 
  Commands( "SQL_TSI_YEAR", 0, 0, 0, ""),
857
 
  Commands( "SSL", 0, 0, 0, ""),
858
 
  Commands( "START", 0, 0, 0, ""),
859
 
  Commands( "STARTING", 0, 0, 0, ""),
860
 
  Commands( "STATUS", 0, 0, 0, ""),
861
 
  Commands( "STOP", 0, 0, 0, ""),
862
 
  Commands( "STORAGE", 0, 0, 0, ""),
863
 
  Commands( "STRAIGHT_JOIN", 0, 0, 0, ""),
864
 
  Commands( "STRING", 0, 0, 0, ""),
865
 
  Commands( "STRIPED", 0, 0, 0, ""),
866
 
  Commands( "SUBJECT", 0, 0, 0, ""),
867
 
  Commands( "SUPER", 0, 0, 0, ""),
868
 
  Commands( "SUSPEND", 0, 0, 0, ""),
869
 
  Commands( "TABLE", 0, 0, 0, ""),
870
 
  Commands( "TABLES", 0, 0, 0, ""),
871
 
  Commands( "TABLESPACE", 0, 0, 0, ""),
872
 
  Commands( "TEMPORARY", 0, 0, 0, ""),
873
 
  Commands( "TEMPTABLE", 0, 0, 0, ""),
874
 
  Commands( "TERMINATED", 0, 0, 0, ""),
875
 
  Commands( "TEXT", 0, 0, 0, ""),
876
 
  Commands( "THEN", 0, 0, 0, ""),
877
 
  Commands( "TIMESTAMP", 0, 0, 0, ""),
878
 
  Commands( "TIMESTAMPADD", 0, 0, 0, ""),
879
 
  Commands( "TIMESTAMPDIFF", 0, 0, 0, ""),
880
 
  Commands( "TO", 0, 0, 0, ""),
881
 
  Commands( "TRAILING", 0, 0, 0, ""),
882
 
  Commands( "TRANSACTION", 0, 0, 0, ""),
883
 
  Commands( "TRUE", 0, 0, 0, ""),
884
 
  Commands( "TRUNCATE", 0, 0, 0, ""),
885
 
  Commands( "TYPE", 0, 0, 0, ""),
886
 
  Commands( "TYPES", 0, 0, 0, ""),
887
 
  Commands( "UNCOMMITTED", 0, 0, 0, ""),
888
 
  Commands( "UNDEFINED", 0, 0, 0, ""),
889
 
  Commands( "UNDO", 0, 0, 0, ""),
890
 
  Commands( "UNICODE", 0, 0, 0, ""),
891
 
  Commands( "UNION", 0, 0, 0, ""),
892
 
  Commands( "UNIQUE", 0, 0, 0, ""),
893
 
  Commands( "UNKNOWN", 0, 0, 0, ""),
894
 
  Commands( "UNLOCK", 0, 0, 0, ""),
895
 
  Commands( "UNTIL", 0, 0, 0, ""),
896
 
  Commands( "UPDATE", 0, 0, 0, ""),
897
 
  Commands( "UPGRADE", 0, 0, 0, ""),
898
 
  Commands( "USAGE", 0, 0, 0, ""),
899
 
  Commands( "USE", 0, 0, 0, ""),
900
 
  Commands( "USER", 0, 0, 0, ""),
901
 
  Commands( "USER_RESOURCES", 0, 0, 0, ""),
902
 
  Commands( "USING", 0, 0, 0, ""),
903
 
  Commands( "UTC_DATE", 0, 0, 0, ""),
904
 
  Commands( "UTC_TIMESTAMP", 0, 0, 0, ""),
905
 
  Commands( "VALUE", 0, 0, 0, ""),
906
 
  Commands( "VALUES", 0, 0, 0, ""),
907
 
  Commands( "VARBINARY", 0, 0, 0, ""),
908
 
  Commands( "VARCHAR", 0, 0, 0, ""),
909
 
  Commands( "VARCHARACTER", 0, 0, 0, ""),
910
 
  Commands( "VARIABLES", 0, 0, 0, ""),
911
 
  Commands( "VARYING", 0, 0, 0, ""),
912
 
  Commands( "WARNINGS", 0, 0, 0, ""),
913
 
  Commands( "WEEK", 0, 0, 0, ""),
914
 
  Commands( "WHEN", 0, 0, 0, ""),
915
 
  Commands( "WHERE", 0, 0, 0, ""),
916
 
  Commands( "WHILE", 0, 0, 0, ""),
917
 
  Commands( "VIEW", 0, 0, 0, ""),
918
 
  Commands( "WITH", 0, 0, 0, ""),
919
 
  Commands( "WORK", 0, 0, 0, ""),
920
 
  Commands( "WRITE", 0, 0, 0, ""),
921
 
  Commands( "XOR", 0, 0, 0, ""),
922
 
  Commands( "XA", 0, 0, 0, ""),
923
 
  Commands( "YEAR", 0, 0, 0, ""),
924
 
  Commands( "YEAR_MONTH", 0, 0, 0, ""),
925
 
  Commands( "ZEROFILL", 0, 0, 0, ""),
926
 
  Commands( "ABS", 0, 0, 0, ""),
927
 
  Commands( "ACOS", 0, 0, 0, ""),
928
 
  Commands( "ADDDATE", 0, 0, 0, ""),
929
 
  Commands( "AREA", 0, 0, 0, ""),
930
 
  Commands( "ASIN", 0, 0, 0, ""),
931
 
  Commands( "ASBINARY", 0, 0, 0, ""),
932
 
  Commands( "ASTEXT", 0, 0, 0, ""),
933
 
  Commands( "ATAN", 0, 0, 0, ""),
934
 
  Commands( "ATAN2", 0, 0, 0, ""),
935
 
  Commands( "BENCHMARK", 0, 0, 0, ""),
936
 
  Commands( "BIN", 0, 0, 0, ""),
937
 
  Commands( "BIT_OR", 0, 0, 0, ""),
938
 
  Commands( "BIT_AND", 0, 0, 0, ""),
939
 
  Commands( "BIT_XOR", 0, 0, 0, ""),
940
 
  Commands( "CAST", 0, 0, 0, ""),
941
 
  Commands( "CEIL", 0, 0, 0, ""),
942
 
  Commands( "CEILING", 0, 0, 0, ""),
943
 
  Commands( "CENTROID", 0, 0, 0, ""),
944
 
  Commands( "CHAR_LENGTH", 0, 0, 0, ""),
945
 
  Commands( "CHARACTER_LENGTH", 0, 0, 0, ""),
946
 
  Commands( "COALESCE", 0, 0, 0, ""),
947
 
  Commands( "COERCIBILITY", 0, 0, 0, ""),
948
 
  Commands( "COMPRESS", 0, 0, 0, ""),
949
 
  Commands( "CONCAT", 0, 0, 0, ""),
950
 
  Commands( "CONCAT_WS", 0, 0, 0, ""),
951
 
  Commands( "CONNECTION_ID", 0, 0, 0, ""),
952
 
  Commands( "CONV", 0, 0, 0, ""),
953
 
  Commands( "CONVERT_TZ", 0, 0, 0, ""),
954
 
  Commands( "COUNT", 0, 0, 0, ""),
955
 
  Commands( "COS", 0, 0, 0, ""),
956
 
  Commands( "COT", 0, 0, 0, ""),
957
 
  Commands( "CRC32", 0, 0, 0, ""),
958
 
  Commands( "CROSSES", 0, 0, 0, ""),
959
 
  Commands( "CURDATE", 0, 0, 0, ""),
960
 
  Commands( "DATE_ADD", 0, 0, 0, ""),
961
 
  Commands( "DATEDIFF", 0, 0, 0, ""),
962
 
  Commands( "DATE_FORMAT", 0, 0, 0, ""),
963
 
  Commands( "DATE_SUB", 0, 0, 0, ""),
964
 
  Commands( "DAYNAME", 0, 0, 0, ""),
965
 
  Commands( "DAYOFMONTH", 0, 0, 0, ""),
966
 
  Commands( "DAYOFWEEK", 0, 0, 0, ""),
967
 
  Commands( "DAYOFYEAR", 0, 0, 0, ""),
968
 
  Commands( "DECODE", 0, 0, 0, ""),
969
 
  Commands( "DEGREES", 0, 0, 0, ""),
970
 
  Commands( "DES_ENCRYPT", 0, 0, 0, ""),
971
 
  Commands( "DES_DECRYPT", 0, 0, 0, ""),
972
 
  Commands( "DIMENSION", 0, 0, 0, ""),
973
 
  Commands( "DISJOINT", 0, 0, 0, ""),
974
 
  Commands( "ELT", 0, 0, 0, ""),
975
 
  Commands( "ENCODE", 0, 0, 0, ""),
976
 
  Commands( "ENCRYPT", 0, 0, 0, ""),
977
 
  Commands( "ENDPOINT", 0, 0, 0, ""),
978
 
  Commands( "ENVELOPE", 0, 0, 0, ""),
979
 
  Commands( "EQUALS", 0, 0, 0, ""),
980
 
  Commands( "EXTERIORRING", 0, 0, 0, ""),
981
 
  Commands( "EXTRACT", 0, 0, 0, ""),
982
 
  Commands( "EXP", 0, 0, 0, ""),
983
 
  Commands( "EXPORT_SET", 0, 0, 0, ""),
984
 
  Commands( "FIELD", 0, 0, 0, ""),
985
 
  Commands( "FIND_IN_SET", 0, 0, 0, ""),
986
 
  Commands( "FLOOR", 0, 0, 0, ""),
987
 
  Commands( "FORMAT", 0, 0, 0, ""),
988
 
  Commands( "FOUND_ROWS", 0, 0, 0, ""),
989
 
  Commands( "FROM_DAYS", 0, 0, 0, ""),
990
 
  Commands( "FROM_UNIXTIME", 0, 0, 0, ""),
991
 
  Commands( "GET_LOCK", 0, 0, 0, ""),
992
 
  Commands( "GLENGTH", 0, 0, 0, ""),
993
 
  Commands( "GREATEST", 0, 0, 0, ""),
994
 
  Commands( "GROUP_CONCAT", 0, 0, 0, ""),
995
 
  Commands( "GROUP_UNIQUE_USERS", 0, 0, 0, ""),
996
 
  Commands( "HEX", 0, 0, 0, ""),
997
 
  Commands( "IFNULL", 0, 0, 0, ""),
998
 
  Commands( "INSTR", 0, 0, 0, ""),
999
 
  Commands( "INTERIORRINGN", 0, 0, 0, ""),
1000
 
  Commands( "INTERSECTS", 0, 0, 0, ""),
1001
 
  Commands( "ISCLOSED", 0, 0, 0, ""),
1002
 
  Commands( "ISEMPTY", 0, 0, 0, ""),
1003
 
  Commands( "ISNULL", 0, 0, 0, ""),
1004
 
  Commands( "IS_FREE_LOCK", 0, 0, 0, ""),
1005
 
  Commands( "IS_USED_LOCK", 0, 0, 0, ""),
1006
 
  Commands( "LAST_INSERT_ID", 0, 0, 0, ""),
1007
 
  Commands( "ISSIMPLE", 0, 0, 0, ""),
1008
 
  Commands( "LAST_DAY", 0, 0, 0, ""),
1009
 
  Commands( "LCASE", 0, 0, 0, ""),
1010
 
  Commands( "LEAST", 0, 0, 0, ""),
1011
 
  Commands( "LENGTH", 0, 0, 0, ""),
1012
 
  Commands( "LN", 0, 0, 0, ""),
1013
 
  Commands( "LOAD_FILE", 0, 0, 0, ""),
1014
 
  Commands( "LOCATE", 0, 0, 0, ""),
1015
 
  Commands( "LOG", 0, 0, 0, ""),
1016
 
  Commands( "LOG2", 0, 0, 0, ""),
1017
 
  Commands( "LOG10", 0, 0, 0, ""),
1018
 
  Commands( "LOWER", 0, 0, 0, ""),
1019
 
  Commands( "LPAD", 0, 0, 0, ""),
1020
 
  Commands( "LTRIM", 0, 0, 0, ""),
1021
 
  Commands( "MAKE_SET", 0, 0, 0, ""),
1022
 
  Commands( "MAKEDATE", 0, 0, 0, ""),
1023
 
  Commands( "MASTER_POS_WAIT", 0, 0, 0, ""),
1024
 
  Commands( "MAX", 0, 0, 0, ""),
1025
 
  Commands( "MBRCONTAINS", 0, 0, 0, ""),
1026
 
  Commands( "MBRDISJOINT", 0, 0, 0, ""),
1027
 
  Commands( "MBREQUAL", 0, 0, 0, ""),
1028
 
  Commands( "MBRINTERSECTS", 0, 0, 0, ""),
1029
 
  Commands( "MBROVERLAPS", 0, 0, 0, ""),
1030
 
  Commands( "MBRTOUCHES", 0, 0, 0, ""),
1031
 
  Commands( "MBRWITHIN", 0, 0, 0, ""),
1032
 
  Commands( "MD5", 0, 0, 0, ""),
1033
 
  Commands( "MID", 0, 0, 0, ""),
1034
 
  Commands( "MIN", 0, 0, 0, ""),
1035
 
  Commands( "MONTHNAME", 0, 0, 0, ""),
1036
 
  Commands( "NAME_CONST", 0, 0, 0, ""),
1037
 
  Commands( "NOW", 0, 0, 0, ""),
1038
 
  Commands( "NULLIF", 0, 0, 0, ""),
1039
 
  Commands( "NUMPOINTS", 0, 0, 0, ""),
1040
 
  Commands( "OCTET_LENGTH", 0, 0, 0, ""),
1041
 
  Commands( "OCT", 0, 0, 0, ""),
1042
 
  Commands( "ORD", 0, 0, 0, ""),
1043
 
  Commands( "OVERLAPS", 0, 0, 0, ""),
1044
 
  Commands( "PERIOD_ADD", 0, 0, 0, ""),
1045
 
  Commands( "PERIOD_DIFF", 0, 0, 0, ""),
1046
 
  Commands( "PI", 0, 0, 0, ""),
1047
 
  Commands( "POINTN", 0, 0, 0, ""),
1048
 
  Commands( "POSITION", 0, 0, 0, ""),
1049
 
  Commands( "POW", 0, 0, 0, ""),
1050
 
  Commands( "POWER", 0, 0, 0, ""),
1051
 
  Commands( "QUOTE", 0, 0, 0, ""),
1052
 
  Commands( "RADIANS", 0, 0, 0, ""),
1053
 
  Commands( "RAND", 0, 0, 0, ""),
1054
 
  Commands( "RELEASE_LOCK", 0, 0, 0, ""),
1055
 
  Commands( "REVERSE", 0, 0, 0, ""),
1056
 
  Commands( "ROUND", 0, 0, 0, ""),
1057
 
  Commands( "ROW_COUNT", 0, 0, 0, ""),
1058
 
  Commands( "RPAD", 0, 0, 0, ""),
1059
 
  Commands( "RTRIM", 0, 0, 0, ""),
1060
 
  Commands( "SESSION_USER", 0, 0, 0, ""),
1061
 
  Commands( "SUBDATE", 0, 0, 0, ""),
1062
 
  Commands( "SIGN", 0, 0, 0, ""),
1063
 
  Commands( "SIN", 0, 0, 0, ""),
1064
 
  Commands( "SHA", 0, 0, 0, ""),
1065
 
  Commands( "SHA1", 0, 0, 0, ""),
1066
 
  Commands( "SLEEP", 0, 0, 0, ""),
1067
 
  Commands( "SOUNDEX", 0, 0, 0, ""),
1068
 
  Commands( "SPACE", 0, 0, 0, ""),
1069
 
  Commands( "SQRT", 0, 0, 0, ""),
1070
 
  Commands( "SRID", 0, 0, 0, ""),
1071
 
  Commands( "STARTPOINT", 0, 0, 0, ""),
1072
 
  Commands( "STD", 0, 0, 0, ""),
1073
 
  Commands( "STDDEV", 0, 0, 0, ""),
1074
 
  Commands( "STDDEV_POP", 0, 0, 0, ""),
1075
 
  Commands( "STDDEV_SAMP", 0, 0, 0, ""),
1076
 
  Commands( "STR_TO_DATE", 0, 0, 0, ""),
1077
 
  Commands( "STRCMP", 0, 0, 0, ""),
1078
 
  Commands( "SUBSTR", 0, 0, 0, ""),
1079
 
  Commands( "SUBSTRING", 0, 0, 0, ""),
1080
 
  Commands( "SUBSTRING_INDEX", 0, 0, 0, ""),
1081
 
  Commands( "SUM", 0, 0, 0, ""),
1082
 
  Commands( "SYSDATE", 0, 0, 0, ""),
1083
 
  Commands( "SYSTEM_USER", 0, 0, 0, ""),
1084
 
  Commands( "TAN", 0, 0, 0, ""),
1085
 
  Commands( "TIME_FORMAT", 0, 0, 0, ""),
1086
 
  Commands( "TO_DAYS", 0, 0, 0, ""),
1087
 
  Commands( "TOUCHES", 0, 0, 0, ""),
1088
 
  Commands( "TRIM", 0, 0, 0, ""),
1089
 
  Commands( "UCASE", 0, 0, 0, ""),
1090
 
  Commands( "UNCOMPRESS", 0, 0, 0, ""),
1091
 
  Commands( "UNCOMPRESSED_LENGTH", 0, 0, 0, ""),
1092
 
  Commands( "UNHEX", 0, 0, 0, ""),
1093
 
  Commands( "UNIQUE_USERS", 0, 0, 0, ""),
1094
 
  Commands( "UNIX_TIMESTAMP", 0, 0, 0, ""),
1095
 
  Commands( "UPPER", 0, 0, 0, ""),
1096
 
  Commands( "UUID", 0, 0, 0, ""),
1097
 
  Commands( "VARIANCE", 0, 0, 0, ""),
1098
 
  Commands( "VAR_POP", 0, 0, 0, ""),
1099
 
  Commands( "VAR_SAMP", 0, 0, 0, ""),
1100
 
  Commands( "VERSION", 0, 0, 0, ""),
1101
 
  Commands( "WEEKDAY", 0, 0, 0, ""),
1102
 
  Commands( "WEEKOFYEAR", 0, 0, 0, ""),
1103
 
  Commands( "WITHIN", 0, 0, 0, ""),
1104
 
  Commands( "X", 0, 0, 0, ""),
1105
 
  Commands( "Y", 0, 0, 0, ""),
1106
 
  Commands( "YEARWEEK", 0, 0, 0, ""),
 
316
  { "ACTION", 0, 0, 0, ""},
 
317
  { "ADD", 0, 0, 0, ""},
 
318
  { "AFTER", 0, 0, 0, ""},
 
319
  { "AGAINST", 0, 0, 0, ""},
 
320
  { "AGGREGATE", 0, 0, 0, ""},
 
321
  { "ALL", 0, 0, 0, ""},
 
322
  { "ALGORITHM", 0, 0, 0, ""},
 
323
  { "ALTER", 0, 0, 0, ""},
 
324
  { "ANALYZE", 0, 0, 0, ""},
 
325
  { "AND", 0, 0, 0, ""},
 
326
  { "ANY", 0, 0, 0, ""},
 
327
  { "AS", 0, 0, 0, ""},
 
328
  { "ASC", 0, 0, 0, ""},
 
329
  { "ASCII", 0, 0, 0, ""},
 
330
  { "ASENSITIVE", 0, 0, 0, ""},
 
331
  { "AUTO_INCREMENT", 0, 0, 0, ""},
 
332
  { "AVG", 0, 0, 0, ""},
 
333
  { "AVG_ROW_LENGTH", 0, 0, 0, ""},
 
334
  { "BACKUP", 0, 0, 0, ""},
 
335
  { "BDB", 0, 0, 0, ""},
 
336
  { "BEFORE", 0, 0, 0, ""},
 
337
  { "BEGIN", 0, 0, 0, ""},
 
338
  { "BERKELEYDB", 0, 0, 0, ""},
 
339
  { "BETWEEN", 0, 0, 0, ""},
 
340
  { "BIGINT", 0, 0, 0, ""},
 
341
  { "BINARY", 0, 0, 0, ""},
 
342
  { "BINLOG", 0, 0, 0, ""},
 
343
  { "BIT", 0, 0, 0, ""},
 
344
  { "BLOB", 0, 0, 0, ""},
 
345
  { "BOOL", 0, 0, 0, ""},
 
346
  { "BOOLEAN", 0, 0, 0, ""},
 
347
  { "BOTH", 0, 0, 0, ""},
 
348
  { "BTREE", 0, 0, 0, ""},
 
349
  { "BY", 0, 0, 0, ""},
 
350
  { "BYTE", 0, 0, 0, ""},
 
351
  { "CACHE", 0, 0, 0, ""},
 
352
  { "CALL", 0, 0, 0, ""},
 
353
  { "CASCADE", 0, 0, 0, ""},
 
354
  { "CASCADED", 0, 0, 0, ""},
 
355
  { "CASE", 0, 0, 0, ""},
 
356
  { "CHAIN", 0, 0, 0, ""},
 
357
  { "CHANGE", 0, 0, 0, ""},
 
358
  { "CHANGED", 0, 0, 0, ""},
 
359
  { "CHAR", 0, 0, 0, ""},
 
360
  { "CHARACTER", 0, 0, 0, ""},
 
361
  { "CHARSET", 0, 0, 0, ""},
 
362
  { "CHECK", 0, 0, 0, ""},
 
363
  { "CHECKSUM", 0, 0, 0, ""},
 
364
  { "CIPHER", 0, 0, 0, ""},
 
365
  { "CLIENT", 0, 0, 0, ""},
 
366
  { "CLOSE", 0, 0, 0, ""},
 
367
  { "CODE", 0, 0, 0, ""},
 
368
  { "COLLATE", 0, 0, 0, ""},
 
369
  { "COLLATION", 0, 0, 0, ""},
 
370
  { "COLUMN", 0, 0, 0, ""},
 
371
  { "COLUMNS", 0, 0, 0, ""},
 
372
  { "COMMENT", 0, 0, 0, ""},
 
373
  { "COMMIT", 0, 0, 0, ""},
 
374
  { "COMMITTED", 0, 0, 0, ""},
 
375
  { "COMPACT", 0, 0, 0, ""},
 
376
  { "COMPRESSED", 0, 0, 0, ""},
 
377
  { "CONCURRENT", 0, 0, 0, ""},
 
378
  { "CONDITION", 0, 0, 0, ""},
 
379
  { "CONNECTION", 0, 0, 0, ""},
 
380
  { "CONSISTENT", 0, 0, 0, ""},
 
381
  { "CONSTRAINT", 0, 0, 0, ""},
 
382
  { "CONTAINS", 0, 0, 0, ""},
 
383
  { "CONTINUE", 0, 0, 0, ""},
 
384
  { "CONVERT", 0, 0, 0, ""},
 
385
  { "CREATE", 0, 0, 0, ""},
 
386
  { "CROSS", 0, 0, 0, ""},
 
387
  { "CUBE", 0, 0, 0, ""},
 
388
  { "CURRENT_DATE", 0, 0, 0, ""},
 
389
  { "CURRENT_TIMESTAMP", 0, 0, 0, ""},
 
390
  { "CURRENT_USER", 0, 0, 0, ""},
 
391
  { "CURSOR", 0, 0, 0, ""},
 
392
  { "DATA", 0, 0, 0, ""},
 
393
  { "DATABASE", 0, 0, 0, ""},
 
394
  { "DATABASES", 0, 0, 0, ""},
 
395
  { "DATE", 0, 0, 0, ""},
 
396
  { "DATETIME", 0, 0, 0, ""},
 
397
  { "DAY", 0, 0, 0, ""},
 
398
  { "DAY_HOUR", 0, 0, 0, ""},
 
399
  { "DAY_MICROSECOND", 0, 0, 0, ""},
 
400
  { "DAY_MINUTE", 0, 0, 0, ""},
 
401
  { "DAY_SECOND", 0, 0, 0, ""},
 
402
  { "DEALLOCATE", 0, 0, 0, ""},
 
403
  { "DEC", 0, 0, 0, ""},
 
404
  { "DECIMAL", 0, 0, 0, ""},
 
405
  { "DECLARE", 0, 0, 0, ""},
 
406
  { "DEFAULT", 0, 0, 0, ""},
 
407
  { "DEFINER", 0, 0, 0, ""},
 
408
  { "DELAYED", 0, 0, 0, ""},
 
409
  { "DELAY_KEY_WRITE", 0, 0, 0, ""},
 
410
  { "DELETE", 0, 0, 0, ""},
 
411
  { "DESC", 0, 0, 0, ""},
 
412
  { "DESCRIBE", 0, 0, 0, ""},
 
413
  { "DES_KEY_FILE", 0, 0, 0, ""},
 
414
  { "DETERMINISTIC", 0, 0, 0, ""},
 
415
  { "DIRECTORY", 0, 0, 0, ""},
 
416
  { "DISABLE", 0, 0, 0, ""},
 
417
  { "DISCARD", 0, 0, 0, ""},
 
418
  { "DISTINCT", 0, 0, 0, ""},
 
419
  { "DISTINCTROW", 0, 0, 0, ""},
 
420
  { "DIV", 0, 0, 0, ""},
 
421
  { "DO", 0, 0, 0, ""},
 
422
  { "DOUBLE", 0, 0, 0, ""},
 
423
  { "DROP", 0, 0, 0, ""},
 
424
  { "DUAL", 0, 0, 0, ""},
 
425
  { "DUMPFILE", 0, 0, 0, ""},
 
426
  { "DUPLICATE", 0, 0, 0, ""},
 
427
  { "DYNAMIC", 0, 0, 0, ""},
 
428
  { "EACH", 0, 0, 0, ""},
 
429
  { "ELSE", 0, 0, 0, ""},
 
430
  { "ELSEIF", 0, 0, 0, ""},
 
431
  { "ENABLE", 0, 0, 0, ""},
 
432
  { "ENCLOSED", 0, 0, 0, ""},
 
433
  { "END", 0, 0, 0, ""},
 
434
  { "ENGINE", 0, 0, 0, ""},
 
435
  { "ENGINES", 0, 0, 0, ""},
 
436
  { "ENUM", 0, 0, 0, ""},
 
437
  { "ERRORS", 0, 0, 0, ""},
 
438
  { "ESCAPE", 0, 0, 0, ""},
 
439
  { "ESCAPED", 0, 0, 0, ""},
 
440
  { "EVENTS", 0, 0, 0, ""},
 
441
  { "EXECUTE", 0, 0, 0, ""},
 
442
  { "EXISTS", 0, 0, 0, ""},
 
443
  { "EXIT", 0, 0, 0, ""},
 
444
  { "EXPANSION", 0, 0, 0, ""},
 
445
  { "EXPLAIN", 0, 0, 0, ""},
 
446
  { "EXTENDED", 0, 0, 0, ""},
 
447
  { "FALSE", 0, 0, 0, ""},
 
448
  { "FAST", 0, 0, 0, ""},
 
449
  { "FETCH", 0, 0, 0, ""},
 
450
  { "FIELDS", 0, 0, 0, ""},
 
451
  { "FILE", 0, 0, 0, ""},
 
452
  { "FIRST", 0, 0, 0, ""},
 
453
  { "FIXED", 0, 0, 0, ""},
 
454
  { "FLOAT", 0, 0, 0, ""},
 
455
  { "FLOAT4", 0, 0, 0, ""},
 
456
  { "FLOAT8", 0, 0, 0, ""},
 
457
  { "FLUSH", 0, 0, 0, ""},
 
458
  { "FOR", 0, 0, 0, ""},
 
459
  { "FORCE", 0, 0, 0, ""},
 
460
  { "FOREIGN", 0, 0, 0, ""},
 
461
  { "FOUND", 0, 0, 0, ""},
 
462
  { "FRAC_SECOND", 0, 0, 0, ""},
 
463
  { "FROM", 0, 0, 0, ""},
 
464
  { "FULL", 0, 0, 0, ""},
 
465
  { "FULLTEXT", 0, 0, 0, ""},
 
466
  { "FUNCTION", 0, 0, 0, ""},
 
467
  { "GLOBAL", 0, 0, 0, ""},
 
468
  { "GRANT", 0, 0, 0, ""},
 
469
  { "GRANTS", 0, 0, 0, ""},
 
470
  { "GROUP", 0, 0, 0, ""},
 
471
  { "HANDLER", 0, 0, 0, ""},
 
472
  { "HASH", 0, 0, 0, ""},
 
473
  { "HAVING", 0, 0, 0, ""},
 
474
  { "HELP", 0, 0, 0, ""},
 
475
  { "HIGH_PRIORITY", 0, 0, 0, ""},
 
476
  { "HOSTS", 0, 0, 0, ""},
 
477
  { "HOUR", 0, 0, 0, ""},
 
478
  { "HOUR_MICROSECOND", 0, 0, 0, ""},
 
479
  { "HOUR_MINUTE", 0, 0, 0, ""},
 
480
  { "HOUR_SECOND", 0, 0, 0, ""},
 
481
  { "IDENTIFIED", 0, 0, 0, ""},
 
482
  { "IF", 0, 0, 0, ""},
 
483
  { "IGNORE", 0, 0, 0, ""},
 
484
  { "IMPORT", 0, 0, 0, ""},
 
485
  { "IN", 0, 0, 0, ""},
 
486
  { "INDEX", 0, 0, 0, ""},
 
487
  { "INDEXES", 0, 0, 0, ""},
 
488
  { "INFILE", 0, 0, 0, ""},
 
489
  { "INNER", 0, 0, 0, ""},
 
490
  { "INNOBASE", 0, 0, 0, ""},
 
491
  { "INNODB", 0, 0, 0, ""},
 
492
  { "INOUT", 0, 0, 0, ""},
 
493
  { "INSENSITIVE", 0, 0, 0, ""},
 
494
  { "INSERT", 0, 0, 0, ""},
 
495
  { "INSERT_METHOD", 0, 0, 0, ""},
 
496
  { "INT", 0, 0, 0, ""},
 
497
  { "INT1", 0, 0, 0, ""},
 
498
  { "INT2", 0, 0, 0, ""},
 
499
  { "INT3", 0, 0, 0, ""},
 
500
  { "INT4", 0, 0, 0, ""},
 
501
  { "INT8", 0, 0, 0, ""},
 
502
  { "INTEGER", 0, 0, 0, ""},
 
503
  { "INTERVAL", 0, 0, 0, ""},
 
504
  { "INTO", 0, 0, 0, ""},
 
505
  { "IO_THREAD", 0, 0, 0, ""},
 
506
  { "IS", 0, 0, 0, ""},
 
507
  { "ISOLATION", 0, 0, 0, ""},
 
508
  { "ISSUER", 0, 0, 0, ""},
 
509
  { "ITERATE", 0, 0, 0, ""},
 
510
  { "INVOKER", 0, 0, 0, ""},
 
511
  { "JOIN", 0, 0, 0, ""},
 
512
  { "KEY", 0, 0, 0, ""},
 
513
  { "KEYS", 0, 0, 0, ""},
 
514
  { "KILL", 0, 0, 0, ""},
 
515
  { "LANGUAGE", 0, 0, 0, ""},
 
516
  { "LAST", 0, 0, 0, ""},
 
517
  { "LEADING", 0, 0, 0, ""},
 
518
  { "LEAVE", 0, 0, 0, ""},
 
519
  { "LEAVES", 0, 0, 0, ""},
 
520
  { "LEFT", 0, 0, 0, ""},
 
521
  { "LEVEL", 0, 0, 0, ""},
 
522
  { "LIKE", 0, 0, 0, ""},
 
523
  { "LIMIT", 0, 0, 0, ""},
 
524
  { "LINES", 0, 0, 0, ""},
 
525
  { "LINESTRING", 0, 0, 0, ""},
 
526
  { "LOAD", 0, 0, 0, ""},
 
527
  { "LOCAL", 0, 0, 0, ""},
 
528
  { "LOCALTIMESTAMP", 0, 0, 0, ""},
 
529
  { "LOCK", 0, 0, 0, ""},
 
530
  { "LOCKS", 0, 0, 0, ""},
 
531
  { "LOGS", 0, 0, 0, ""},
 
532
  { "LONG", 0, 0, 0, ""},
 
533
  { "LONGTEXT", 0, 0, 0, ""},
 
534
  { "LOOP", 0, 0, 0, ""},
 
535
  { "LOW_PRIORITY", 0, 0, 0, ""},
 
536
  { "MASTER", 0, 0, 0, ""},
 
537
  { "MASTER_CONNECT_RETRY", 0, 0, 0, ""},
 
538
  { "MASTER_HOST", 0, 0, 0, ""},
 
539
  { "MASTER_LOG_FILE", 0, 0, 0, ""},
 
540
  { "MASTER_LOG_POS", 0, 0, 0, ""},
 
541
  { "MASTER_PASSWORD", 0, 0, 0, ""},
 
542
  { "MASTER_PORT", 0, 0, 0, ""},
 
543
  { "MASTER_SERVER_ID", 0, 0, 0, ""},
 
544
  { "MASTER_SSL", 0, 0, 0, ""},
 
545
  { "MASTER_SSL_CA", 0, 0, 0, ""},
 
546
  { "MASTER_SSL_CAPATH", 0, 0, 0, ""},
 
547
  { "MASTER_SSL_CERT", 0, 0, 0, ""},
 
548
  { "MASTER_SSL_CIPHER", 0, 0, 0, ""},
 
549
  { "MASTER_SSL_KEY", 0, 0, 0, ""},
 
550
  { "MASTER_USER", 0, 0, 0, ""},
 
551
  { "MATCH", 0, 0, 0, ""},
 
552
  { "MAX_CONNECTIONS_PER_HOUR", 0, 0, 0, ""},
 
553
  { "MAX_QUERIES_PER_HOUR", 0, 0, 0, ""},
 
554
  { "MAX_ROWS", 0, 0, 0, ""},
 
555
  { "MAX_UPDATES_PER_HOUR", 0, 0, 0, ""},
 
556
  { "MAX_USER_CONNECTIONS", 0, 0, 0, ""},
 
557
  { "MEDIUM", 0, 0, 0, ""},
 
558
  { "MEDIUMTEXT", 0, 0, 0, ""},
 
559
  { "MERGE", 0, 0, 0, ""},
 
560
  { "MICROSECOND", 0, 0, 0, ""},
 
561
  { "MIDDLEINT", 0, 0, 0, ""},
 
562
  { "MIGRATE", 0, 0, 0, ""},
 
563
  { "MINUTE", 0, 0, 0, ""},
 
564
  { "MINUTE_MICROSECOND", 0, 0, 0, ""},
 
565
  { "MINUTE_SECOND", 0, 0, 0, ""},
 
566
  { "MIN_ROWS", 0, 0, 0, ""},
 
567
  { "MOD", 0, 0, 0, ""},
 
568
  { "MODE", 0, 0, 0, ""},
 
569
  { "MODIFIES", 0, 0, 0, ""},
 
570
  { "MODIFY", 0, 0, 0, ""},
 
571
  { "MONTH", 0, 0, 0, ""},
 
572
  { "MULTILINESTRING", 0, 0, 0, ""},
 
573
  { "MULTIPOINT", 0, 0, 0, ""},
 
574
  { "MULTIPOLYGON", 0, 0, 0, ""},
 
575
  { "MUTEX", 0, 0, 0, ""},
 
576
  { "NAME", 0, 0, 0, ""},
 
577
  { "NAMES", 0, 0, 0, ""},
 
578
  { "NATIONAL", 0, 0, 0, ""},
 
579
  { "NATURAL", 0, 0, 0, ""},
 
580
  { "NDB", 0, 0, 0, ""},
 
581
  { "NDBCLUSTER", 0, 0, 0, ""},
 
582
  { "NCHAR", 0, 0, 0, ""},
 
583
  { "NEW", 0, 0, 0, ""},
 
584
  { "NEXT", 0, 0, 0, ""},
 
585
  { "NO", 0, 0, 0, ""},
 
586
  { "NONE", 0, 0, 0, ""},
 
587
  { "NOT", 0, 0, 0, ""},
 
588
  { "NO_WRITE_TO_BINLOG", 0, 0, 0, ""},
 
589
  { "NULL", 0, 0, 0, ""},
 
590
  { "NUMERIC", 0, 0, 0, ""},
 
591
  { "NVARCHAR", 0, 0, 0, ""},
 
592
  { "OFFSET", 0, 0, 0, ""},
 
593
  { "OLD_PASSWORD", 0, 0, 0, ""},
 
594
  { "ON", 0, 0, 0, ""},
 
595
  { "ONE", 0, 0, 0, ""},
 
596
  { "ONE_SHOT", 0, 0, 0, ""},
 
597
  { "OPEN", 0, 0, 0, ""},
 
598
  { "OPTIMIZE", 0, 0, 0, ""},
 
599
  { "OPTION", 0, 0, 0, ""},
 
600
  { "OPTIONALLY", 0, 0, 0, ""},
 
601
  { "OR", 0, 0, 0, ""},
 
602
  { "ORDER", 0, 0, 0, ""},
 
603
  { "OUT", 0, 0, 0, ""},
 
604
  { "OUTER", 0, 0, 0, ""},
 
605
  { "OUTFILE", 0, 0, 0, ""},
 
606
  { "PACK_KEYS", 0, 0, 0, ""},
 
607
  { "PARTIAL", 0, 0, 0, ""},
 
608
  { "PASSWORD", 0, 0, 0, ""},
 
609
  { "PHASE", 0, 0, 0, ""},
 
610
  { "POINT", 0, 0, 0, ""},
 
611
  { "POLYGON", 0, 0, 0, ""},
 
612
  { "PRECISION", 0, 0, 0, ""},
 
613
  { "PREPARE", 0, 0, 0, ""},
 
614
  { "PREV", 0, 0, 0, ""},
 
615
  { "PRIMARY", 0, 0, 0, ""},
 
616
  { "PRIVILEGES", 0, 0, 0, ""},
 
617
  { "PROCEDURE", 0, 0, 0, ""},
 
618
  { "PROCESS", 0, 0, 0, ""},
 
619
  { "PROCESSLIST", 0, 0, 0, ""},
 
620
  { "PURGE", 0, 0, 0, ""},
 
621
  { "QUARTER", 0, 0, 0, ""},
 
622
  { "QUERY", 0, 0, 0, ""},
 
623
  { "QUICK", 0, 0, 0, ""},
 
624
  { "READ", 0, 0, 0, ""},
 
625
  { "READS", 0, 0, 0, ""},
 
626
  { "REAL", 0, 0, 0, ""},
 
627
  { "RECOVER", 0, 0, 0, ""},
 
628
  { "REDUNDANT", 0, 0, 0, ""},
 
629
  { "REFERENCES", 0, 0, 0, ""},
 
630
  { "REGEXP", 0, 0, 0, ""},
 
631
  { "RELAY_LOG_FILE", 0, 0, 0, ""},
 
632
  { "RELAY_LOG_POS", 0, 0, 0, ""},
 
633
  { "RELAY_THREAD", 0, 0, 0, ""},
 
634
  { "RELEASE", 0, 0, 0, ""},
 
635
  { "RELOAD", 0, 0, 0, ""},
 
636
  { "RENAME", 0, 0, 0, ""},
 
637
  { "REPAIR", 0, 0, 0, ""},
 
638
  { "REPEATABLE", 0, 0, 0, ""},
 
639
  { "REPLACE", 0, 0, 0, ""},
 
640
  { "REPLICATION", 0, 0, 0, ""},
 
641
  { "REPEAT", 0, 0, 0, ""},
 
642
  { "REQUIRE", 0, 0, 0, ""},
 
643
  { "RESET", 0, 0, 0, ""},
 
644
  { "RESTORE", 0, 0, 0, ""},
 
645
  { "RESTRICT", 0, 0, 0, ""},
 
646
  { "RESUME", 0, 0, 0, ""},
 
647
  { "RETURN", 0, 0, 0, ""},
 
648
  { "RETURNS", 0, 0, 0, ""},
 
649
  { "REVOKE", 0, 0, 0, ""},
 
650
  { "RIGHT", 0, 0, 0, ""},
 
651
  { "RLIKE", 0, 0, 0, ""},
 
652
  { "ROLLBACK", 0, 0, 0, ""},
 
653
  { "ROLLUP", 0, 0, 0, ""},
 
654
  { "ROUTINE", 0, 0, 0, ""},
 
655
  { "ROW", 0, 0, 0, ""},
 
656
  { "ROWS", 0, 0, 0, ""},
 
657
  { "ROW_FORMAT", 0, 0, 0, ""},
 
658
  { "RTREE", 0, 0, 0, ""},
 
659
  { "SAVEPOINT", 0, 0, 0, ""},
 
660
  { "SCHEMA", 0, 0, 0, ""},
 
661
  { "SCHEMAS", 0, 0, 0, ""},
 
662
  { "SECOND", 0, 0, 0, ""},
 
663
  { "SECOND_MICROSECOND", 0, 0, 0, ""},
 
664
  { "SECURITY", 0, 0, 0, ""},
 
665
  { "SELECT", 0, 0, 0, ""},
 
666
  { "SENSITIVE", 0, 0, 0, ""},
 
667
  { "SEPARATOR", 0, 0, 0, ""},
 
668
  { "SERIAL", 0, 0, 0, ""},
 
669
  { "SERIALIZABLE", 0, 0, 0, ""},
 
670
  { "SESSION", 0, 0, 0, ""},
 
671
  { "SET", 0, 0, 0, ""},
 
672
  { "SHARE", 0, 0, 0, ""},
 
673
  { "SHOW", 0, 0, 0, ""},
 
674
  { "SHUTDOWN", 0, 0, 0, ""},
 
675
  { "SIGNED", 0, 0, 0, ""},
 
676
  { "SIMPLE", 0, 0, 0, ""},
 
677
  { "SLAVE", 0, 0, 0, ""},
 
678
  { "SNAPSHOT", 0, 0, 0, ""},
 
679
  { "SMALLINT", 0, 0, 0, ""},
 
680
  { "SOME", 0, 0, 0, ""},
 
681
  { "SONAME", 0, 0, 0, ""},
 
682
  { "SOUNDS", 0, 0, 0, ""},
 
683
  { "SPATIAL", 0, 0, 0, ""},
 
684
  { "SPECIFIC", 0, 0, 0, ""},
 
685
  { "SQL", 0, 0, 0, ""},
 
686
  { "SQLEXCEPTION", 0, 0, 0, ""},
 
687
  { "SQLSTATE", 0, 0, 0, ""},
 
688
  { "SQLWARNING", 0, 0, 0, ""},
 
689
  { "SQL_BIG_RESULT", 0, 0, 0, ""},
 
690
  { "SQL_BUFFER_RESULT", 0, 0, 0, ""},
 
691
  { "SQL_CACHE", 0, 0, 0, ""},
 
692
  { "SQL_CALC_FOUND_ROWS", 0, 0, 0, ""},
 
693
  { "SQL_NO_CACHE", 0, 0, 0, ""},
 
694
  { "SQL_SMALL_RESULT", 0, 0, 0, ""},
 
695
  { "SQL_THREAD", 0, 0, 0, ""},
 
696
  { "SQL_TSI_FRAC_SECOND", 0, 0, 0, ""},
 
697
  { "SQL_TSI_SECOND", 0, 0, 0, ""},
 
698
  { "SQL_TSI_MINUTE", 0, 0, 0, ""},
 
699
  { "SQL_TSI_HOUR", 0, 0, 0, ""},
 
700
  { "SQL_TSI_DAY", 0, 0, 0, ""},
 
701
  { "SQL_TSI_WEEK", 0, 0, 0, ""},
 
702
  { "SQL_TSI_MONTH", 0, 0, 0, ""},
 
703
  { "SQL_TSI_QUARTER", 0, 0, 0, ""},
 
704
  { "SQL_TSI_YEAR", 0, 0, 0, ""},
 
705
  { "SSL", 0, 0, 0, ""},
 
706
  { "START", 0, 0, 0, ""},
 
707
  { "STARTING", 0, 0, 0, ""},
 
708
  { "STATUS", 0, 0, 0, ""},
 
709
  { "STOP", 0, 0, 0, ""},
 
710
  { "STORAGE", 0, 0, 0, ""},
 
711
  { "STRAIGHT_JOIN", 0, 0, 0, ""},
 
712
  { "STRING", 0, 0, 0, ""},
 
713
  { "STRIPED", 0, 0, 0, ""},
 
714
  { "SUBJECT", 0, 0, 0, ""},
 
715
  { "SUPER", 0, 0, 0, ""},
 
716
  { "SUSPEND", 0, 0, 0, ""},
 
717
  { "TABLE", 0, 0, 0, ""},
 
718
  { "TABLES", 0, 0, 0, ""},
 
719
  { "TABLESPACE", 0, 0, 0, ""},
 
720
  { "TEMPORARY", 0, 0, 0, ""},
 
721
  { "TEMPTABLE", 0, 0, 0, ""},
 
722
  { "TERMINATED", 0, 0, 0, ""},
 
723
  { "TEXT", 0, 0, 0, ""},
 
724
  { "THEN", 0, 0, 0, ""},
 
725
  { "TIMESTAMP", 0, 0, 0, ""},
 
726
  { "TIMESTAMPADD", 0, 0, 0, ""},
 
727
  { "TIMESTAMPDIFF", 0, 0, 0, ""},
 
728
  { "TINYINT", 0, 0, 0, ""},
 
729
  { "TINYTEXT", 0, 0, 0, ""},
 
730
  { "TO", 0, 0, 0, ""},
 
731
  { "TRAILING", 0, 0, 0, ""},
 
732
  { "TRANSACTION", 0, 0, 0, ""},
 
733
  { "TRIGGER", 0, 0, 0, ""},
 
734
  { "TRIGGERS", 0, 0, 0, ""},
 
735
  { "TRUE", 0, 0, 0, ""},
 
736
  { "TRUNCATE", 0, 0, 0, ""},
 
737
  { "TYPE", 0, 0, 0, ""},
 
738
  { "TYPES", 0, 0, 0, ""},
 
739
  { "UNCOMMITTED", 0, 0, 0, ""},
 
740
  { "UNDEFINED", 0, 0, 0, ""},
 
741
  { "UNDO", 0, 0, 0, ""},
 
742
  { "UNICODE", 0, 0, 0, ""},
 
743
  { "UNION", 0, 0, 0, ""},
 
744
  { "UNIQUE", 0, 0, 0, ""},
 
745
  { "UNKNOWN", 0, 0, 0, ""},
 
746
  { "UNLOCK", 0, 0, 0, ""},
 
747
  { "UNSIGNED", 0, 0, 0, ""},
 
748
  { "UNTIL", 0, 0, 0, ""},
 
749
  { "UPDATE", 0, 0, 0, ""},
 
750
  { "UPGRADE", 0, 0, 0, ""},
 
751
  { "USAGE", 0, 0, 0, ""},
 
752
  { "USE", 0, 0, 0, ""},
 
753
  { "USER", 0, 0, 0, ""},
 
754
  { "USER_RESOURCES", 0, 0, 0, ""},
 
755
  { "USE_FRM", 0, 0, 0, ""},
 
756
  { "USING", 0, 0, 0, ""},
 
757
  { "UTC_DATE", 0, 0, 0, ""},
 
758
  { "UTC_TIMESTAMP", 0, 0, 0, ""},
 
759
  { "VALUE", 0, 0, 0, ""},
 
760
  { "VALUES", 0, 0, 0, ""},
 
761
  { "VARBINARY", 0, 0, 0, ""},
 
762
  { "VARCHAR", 0, 0, 0, ""},
 
763
  { "VARCHARACTER", 0, 0, 0, ""},
 
764
  { "VARIABLES", 0, 0, 0, ""},
 
765
  { "VARYING", 0, 0, 0, ""},
 
766
  { "WARNINGS", 0, 0, 0, ""},
 
767
  { "WEEK", 0, 0, 0, ""},
 
768
  { "WHEN", 0, 0, 0, ""},
 
769
  { "WHERE", 0, 0, 0, ""},
 
770
  { "WHILE", 0, 0, 0, ""},
 
771
  { "VIEW", 0, 0, 0, ""},
 
772
  { "WITH", 0, 0, 0, ""},
 
773
  { "WORK", 0, 0, 0, ""},
 
774
  { "WRITE", 0, 0, 0, ""},
 
775
  { "X509", 0, 0, 0, ""},
 
776
  { "XOR", 0, 0, 0, ""},
 
777
  { "XA", 0, 0, 0, ""},
 
778
  { "YEAR", 0, 0, 0, ""},
 
779
  { "YEAR_MONTH", 0, 0, 0, ""},
 
780
  { "ZEROFILL", 0, 0, 0, ""},
 
781
  { "ABS", 0, 0, 0, ""},
 
782
  { "ACOS", 0, 0, 0, ""},
 
783
  { "ADDDATE", 0, 0, 0, ""},
 
784
  { "AES_ENCRYPT", 0, 0, 0, ""},
 
785
  { "AES_DECRYPT", 0, 0, 0, ""},
 
786
  { "AREA", 0, 0, 0, ""},
 
787
  { "ASIN", 0, 0, 0, ""},
 
788
  { "ASBINARY", 0, 0, 0, ""},
 
789
  { "ASTEXT", 0, 0, 0, ""},
 
790
  { "ASWKB", 0, 0, 0, ""},
 
791
  { "ASWKT", 0, 0, 0, ""},
 
792
  { "ATAN", 0, 0, 0, ""},
 
793
  { "ATAN2", 0, 0, 0, ""},
 
794
  { "BENCHMARK", 0, 0, 0, ""},
 
795
  { "BIN", 0, 0, 0, ""},
 
796
  { "BIT_OR", 0, 0, 0, ""},
 
797
  { "BIT_AND", 0, 0, 0, ""},
 
798
  { "BIT_XOR", 0, 0, 0, ""},
 
799
  { "CAST", 0, 0, 0, ""},
 
800
  { "CEIL", 0, 0, 0, ""},
 
801
  { "CEILING", 0, 0, 0, ""},
 
802
  { "CENTROID", 0, 0, 0, ""},
 
803
  { "CHAR_LENGTH", 0, 0, 0, ""},
 
804
  { "CHARACTER_LENGTH", 0, 0, 0, ""},
 
805
  { "COALESCE", 0, 0, 0, ""},
 
806
  { "COERCIBILITY", 0, 0, 0, ""},
 
807
  { "COMPRESS", 0, 0, 0, ""},
 
808
  { "CONCAT", 0, 0, 0, ""},
 
809
  { "CONCAT_WS", 0, 0, 0, ""},
 
810
  { "CONNECTION_ID", 0, 0, 0, ""},
 
811
  { "CONV", 0, 0, 0, ""},
 
812
  { "CONVERT_TZ", 0, 0, 0, ""},
 
813
  { "COUNT", 0, 0, 0, ""},
 
814
  { "COS", 0, 0, 0, ""},
 
815
  { "COT", 0, 0, 0, ""},
 
816
  { "CRC32", 0, 0, 0, ""},
 
817
  { "CROSSES", 0, 0, 0, ""},
 
818
  { "CURDATE", 0, 0, 0, ""},
 
819
  { "DATE_ADD", 0, 0, 0, ""},
 
820
  { "DATEDIFF", 0, 0, 0, ""},
 
821
  { "DATE_FORMAT", 0, 0, 0, ""},
 
822
  { "DATE_SUB", 0, 0, 0, ""},
 
823
  { "DAYNAME", 0, 0, 0, ""},
 
824
  { "DAYOFMONTH", 0, 0, 0, ""},
 
825
  { "DAYOFWEEK", 0, 0, 0, ""},
 
826
  { "DAYOFYEAR", 0, 0, 0, ""},
 
827
  { "DECODE", 0, 0, 0, ""},
 
828
  { "DEGREES", 0, 0, 0, ""},
 
829
  { "DES_ENCRYPT", 0, 0, 0, ""},
 
830
  { "DES_DECRYPT", 0, 0, 0, ""},
 
831
  { "DIMENSION", 0, 0, 0, ""},
 
832
  { "DISJOINT", 0, 0, 0, ""},
 
833
  { "ELT", 0, 0, 0, ""},
 
834
  { "ENCODE", 0, 0, 0, ""},
 
835
  { "ENCRYPT", 0, 0, 0, ""},
 
836
  { "ENDPOINT", 0, 0, 0, ""},
 
837
  { "ENVELOPE", 0, 0, 0, ""},
 
838
  { "EQUALS", 0, 0, 0, ""},
 
839
  { "EXTERIORRING", 0, 0, 0, ""},
 
840
  { "EXTRACT", 0, 0, 0, ""},
 
841
  { "EXP", 0, 0, 0, ""},
 
842
  { "EXPORT_SET", 0, 0, 0, ""},
 
843
  { "FIELD", 0, 0, 0, ""},
 
844
  { "FIND_IN_SET", 0, 0, 0, ""},
 
845
  { "FLOOR", 0, 0, 0, ""},
 
846
  { "FORMAT", 0, 0, 0, ""},
 
847
  { "FOUND_ROWS", 0, 0, 0, ""},
 
848
  { "FROM_DAYS", 0, 0, 0, ""},
 
849
  { "FROM_UNIXTIME", 0, 0, 0, ""},
 
850
  { "GET_LOCK", 0, 0, 0, ""},
 
851
  { "GLENGTH", 0, 0, 0, ""},
 
852
  { "GREATEST", 0, 0, 0, ""},
 
853
  { "GROUP_CONCAT", 0, 0, 0, ""},
 
854
  { "GROUP_UNIQUE_USERS", 0, 0, 0, ""},
 
855
  { "HEX", 0, 0, 0, ""},
 
856
  { "IFNULL", 0, 0, 0, ""},
 
857
  { "INET_ATON", 0, 0, 0, ""},
 
858
  { "INET_NTOA", 0, 0, 0, ""},
 
859
  { "INSTR", 0, 0, 0, ""},
 
860
  { "INTERIORRINGN", 0, 0, 0, ""},
 
861
  { "INTERSECTS", 0, 0, 0, ""},
 
862
  { "ISCLOSED", 0, 0, 0, ""},
 
863
  { "ISEMPTY", 0, 0, 0, ""},
 
864
  { "ISNULL", 0, 0, 0, ""},
 
865
  { "IS_FREE_LOCK", 0, 0, 0, ""},
 
866
  { "IS_USED_LOCK", 0, 0, 0, ""},
 
867
  { "LAST_INSERT_ID", 0, 0, 0, ""},
 
868
  { "ISSIMPLE", 0, 0, 0, ""},
 
869
  { "LAST_DAY", 0, 0, 0, ""},
 
870
  { "LCASE", 0, 0, 0, ""},
 
871
  { "LEAST", 0, 0, 0, ""},
 
872
  { "LENGTH", 0, 0, 0, ""},
 
873
  { "LN", 0, 0, 0, ""},
 
874
  { "LINEFROMTEXT", 0, 0, 0, ""},
 
875
  { "LINEFROMWKB", 0, 0, 0, ""},
 
876
  { "LINESTRINGFROMTEXT", 0, 0, 0, ""},
 
877
  { "LINESTRINGFROMWKB", 0, 0, 0, ""},
 
878
  { "LOAD_FILE", 0, 0, 0, ""},
 
879
  { "LOCATE", 0, 0, 0, ""},
 
880
  { "LOG", 0, 0, 0, ""},
 
881
  { "LOG2", 0, 0, 0, ""},
 
882
  { "LOG10", 0, 0, 0, ""},
 
883
  { "LOWER", 0, 0, 0, ""},
 
884
  { "LPAD", 0, 0, 0, ""},
 
885
  { "LTRIM", 0, 0, 0, ""},
 
886
  { "MAKE_SET", 0, 0, 0, ""},
 
887
  { "MAKEDATE", 0, 0, 0, ""},
 
888
  { "MASTER_POS_WAIT", 0, 0, 0, ""},
 
889
  { "MAX", 0, 0, 0, ""},
 
890
  { "MBRCONTAINS", 0, 0, 0, ""},
 
891
  { "MBRDISJOINT", 0, 0, 0, ""},
 
892
  { "MBREQUAL", 0, 0, 0, ""},
 
893
  { "MBRINTERSECTS", 0, 0, 0, ""},
 
894
  { "MBROVERLAPS", 0, 0, 0, ""},
 
895
  { "MBRTOUCHES", 0, 0, 0, ""},
 
896
  { "MBRWITHIN", 0, 0, 0, ""},
 
897
  { "MD5", 0, 0, 0, ""},
 
898
  { "MID", 0, 0, 0, ""},
 
899
  { "MIN", 0, 0, 0, ""},
 
900
  { "MLINEFROMTEXT", 0, 0, 0, ""},
 
901
  { "MLINEFROMWKB", 0, 0, 0, ""},
 
902
  { "MPOINTFROMTEXT", 0, 0, 0, ""},
 
903
  { "MPOINTFROMWKB", 0, 0, 0, ""},
 
904
  { "MPOLYFROMTEXT", 0, 0, 0, ""},
 
905
  { "MPOLYFROMWKB", 0, 0, 0, ""},
 
906
  { "MONTHNAME", 0, 0, 0, ""},
 
907
  { "MULTILINESTRINGFROMTEXT", 0, 0, 0, ""},
 
908
  { "MULTILINESTRINGFROMWKB", 0, 0, 0, ""},
 
909
  { "MULTIPOINTFROMTEXT", 0, 0, 0, ""},
 
910
  { "MULTIPOINTFROMWKB", 0, 0, 0, ""},
 
911
  { "MULTIPOLYGONFROMTEXT", 0, 0, 0, ""},
 
912
  { "MULTIPOLYGONFROMWKB", 0, 0, 0, ""},
 
913
  { "NAME_CONST", 0, 0, 0, ""},
 
914
  { "NOW", 0, 0, 0, ""},
 
915
  { "NULLIF", 0, 0, 0, ""},
 
916
  { "NUMINTERIORRINGS", 0, 0, 0, ""},
 
917
  { "NUMPOINTS", 0, 0, 0, ""},
 
918
  { "OCTET_LENGTH", 0, 0, 0, ""},
 
919
  { "OCT", 0, 0, 0, ""},
 
920
  { "ORD", 0, 0, 0, ""},
 
921
  { "OVERLAPS", 0, 0, 0, ""},
 
922
  { "PERIOD_ADD", 0, 0, 0, ""},
 
923
  { "PERIOD_DIFF", 0, 0, 0, ""},
 
924
  { "PI", 0, 0, 0, ""},
 
925
  { "POINTFROMTEXT", 0, 0, 0, ""},
 
926
  { "POINTFROMWKB", 0, 0, 0, ""},
 
927
  { "POINTN", 0, 0, 0, ""},
 
928
  { "POLYFROMTEXT", 0, 0, 0, ""},
 
929
  { "POLYFROMWKB", 0, 0, 0, ""},
 
930
  { "POLYGONFROMTEXT", 0, 0, 0, ""},
 
931
  { "POLYGONFROMWKB", 0, 0, 0, ""},
 
932
  { "POSITION", 0, 0, 0, ""},
 
933
  { "POW", 0, 0, 0, ""},
 
934
  { "POWER", 0, 0, 0, ""},
 
935
  { "QUOTE", 0, 0, 0, ""},
 
936
  { "RADIANS", 0, 0, 0, ""},
 
937
  { "RAND", 0, 0, 0, ""},
 
938
  { "RELEASE_LOCK", 0, 0, 0, ""},
 
939
  { "REVERSE", 0, 0, 0, ""},
 
940
  { "ROUND", 0, 0, 0, ""},
 
941
  { "ROW_COUNT", 0, 0, 0, ""},
 
942
  { "RPAD", 0, 0, 0, ""},
 
943
  { "RTRIM", 0, 0, 0, ""},
 
944
  { "SESSION_USER", 0, 0, 0, ""},
 
945
  { "SUBDATE", 0, 0, 0, ""},
 
946
  { "SIGN", 0, 0, 0, ""},
 
947
  { "SIN", 0, 0, 0, ""},
 
948
  { "SHA", 0, 0, 0, ""},
 
949
  { "SHA1", 0, 0, 0, ""},
 
950
  { "SLEEP", 0, 0, 0, ""},
 
951
  { "SOUNDEX", 0, 0, 0, ""},
 
952
  { "SPACE", 0, 0, 0, ""},
 
953
  { "SQRT", 0, 0, 0, ""},
 
954
  { "SRID", 0, 0, 0, ""},
 
955
  { "STARTPOINT", 0, 0, 0, ""},
 
956
  { "STD", 0, 0, 0, ""},
 
957
  { "STDDEV", 0, 0, 0, ""},
 
958
  { "STDDEV_POP", 0, 0, 0, ""},
 
959
  { "STDDEV_SAMP", 0, 0, 0, ""},
 
960
  { "STR_TO_DATE", 0, 0, 0, ""},
 
961
  { "STRCMP", 0, 0, 0, ""},
 
962
  { "SUBSTR", 0, 0, 0, ""},
 
963
  { "SUBSTRING", 0, 0, 0, ""},
 
964
  { "SUBSTRING_INDEX", 0, 0, 0, ""},
 
965
  { "SUM", 0, 0, 0, ""},
 
966
  { "SYSDATE", 0, 0, 0, ""},
 
967
  { "SYSTEM_USER", 0, 0, 0, ""},
 
968
  { "TAN", 0, 0, 0, ""},
 
969
  { "TIME_FORMAT", 0, 0, 0, ""},
 
970
  { "TO_DAYS", 0, 0, 0, ""},
 
971
  { "TOUCHES", 0, 0, 0, ""},
 
972
  { "TRIM", 0, 0, 0, ""},
 
973
  { "UCASE", 0, 0, 0, ""},
 
974
  { "UNCOMPRESS", 0, 0, 0, ""},
 
975
  { "UNCOMPRESSED_LENGTH", 0, 0, 0, ""},
 
976
  { "UNHEX", 0, 0, 0, ""},
 
977
  { "UNIQUE_USERS", 0, 0, 0, ""},
 
978
  { "UNIX_TIMESTAMP", 0, 0, 0, ""},
 
979
  { "UPPER", 0, 0, 0, ""},
 
980
  { "UUID", 0, 0, 0, ""},
 
981
  { "VARIANCE", 0, 0, 0, ""},
 
982
  { "VAR_POP", 0, 0, 0, ""},
 
983
  { "VAR_SAMP", 0, 0, 0, ""},
 
984
  { "VERSION", 0, 0, 0, ""},
 
985
  { "WEEKDAY", 0, 0, 0, ""},
 
986
  { "WEEKOFYEAR", 0, 0, 0, ""},
 
987
  { "WITHIN", 0, 0, 0, ""},
 
988
  { "X", 0, 0, 0, ""},
 
989
  { "Y", 0, 0, 0, ""},
 
990
  { "YEARWEEK", 0, 0, 0, ""},
1107
991
  /* end sentinel */
1108
 
  Commands((char *)NULL,       0, 0, 0, "")
 
992
  { (char *)NULL,       0, 0, 0, ""}
1109
993
};
1110
994
 
 
995
static const char *load_default_groups[]= { "drizzle","client",0 };
1111
996
 
1112
997
int history_length;
1113
998
static int not_in_history(const char *line);
1114
999
static void initialize_readline (char *name);
1115
1000
static void fix_history(string *final_command);
1116
1001
 
1117
 
static Commands *find_command(const char *name,char cmd_name);
 
1002
static COMMANDS *find_command(const char *name,char cmd_name);
1118
1003
static bool add_line(string *buffer,char *line,char *in_string,
1119
1004
                     bool *ml_comment);
1120
1005
static void remove_cntrl(string *buffer);
1132
1017
static void window_resize(int sig);
1133
1018
#endif
1134
1019
 
 
1020
static inline int is_prefix(const char *s, const char *t)
 
1021
{
 
1022
  while (*t)
 
1023
    if (*s++ != *t++) return 0;
 
1024
  return 1;                                     /* WRONG */
 
1025
}
 
1026
 
1135
1027
/**
1136
1028
  Shutdown the server that we are currently connected to.
1137
1029
 
1147
1039
 
1148
1040
  if (verbose)
1149
1041
  {
1150
 
    printf(_("shutting down drizzled"));
 
1042
    printf("shutting down drizzled");
1151
1043
    if (opt_drizzle_port > 0)
1152
 
      printf(_(" on port %d"), opt_drizzle_port);
 
1044
      printf(" on port %d", opt_drizzle_port);
1153
1045
    printf("... ");
1154
1046
  }
1155
1047
 
1158
1050
  {
1159
1051
    if (ret == DRIZZLE_RETURN_ERROR_CODE)
1160
1052
    {
1161
 
      fprintf(stderr, _("shutdown failed; error: '%s'"),
 
1053
      fprintf(stderr, "shutdown failed; error: '%s'",
1162
1054
              drizzle_result_error(&result));
1163
1055
      drizzle_result_free(&result);
1164
1056
    }
1165
1057
    else
1166
1058
    {
1167
 
      fprintf(stderr, _("shutdown failed; error: '%s'"),
 
1059
      fprintf(stderr, "shutdown failed; error: '%s'",
1168
1060
              drizzle_con_error(&con));
1169
1061
    }
1170
1062
    return false;
1173
1065
  drizzle_result_free(&result);
1174
1066
 
1175
1067
  if (verbose)
1176
 
    printf(_("done\n"));
 
1068
    printf("done\n");
1177
1069
 
1178
1070
  return true;
1179
1071
}
1194
1086
  if (drizzle_ping(&con, &result, &ret) != NULL && ret == DRIZZLE_RETURN_OK)
1195
1087
  {
1196
1088
    if (opt_silent < 2)
1197
 
      printf(_("drizzled is alive\n"));
 
1089
      printf("drizzled is alive\n");
1198
1090
  }
1199
1091
  else
1200
1092
  {
1201
1093
    if (ret == DRIZZLE_RETURN_ERROR_CODE)
1202
1094
    {
1203
 
      fprintf(stderr, _("ping failed; error: '%s'"),
 
1095
      fprintf(stderr, "ping failed; error: '%s'",
1204
1096
              drizzle_result_error(&result));
1205
1097
      drizzle_result_free(&result);
1206
1098
    }
1207
1099
    else
1208
1100
    {
1209
 
      fprintf(stderr, _("drizzled won't answer to ping, error: '%s'"),
 
1101
      fprintf(stderr, "drizzled won't answer to ping, error: '%s'",
1210
1102
              drizzle_con_error(&con));
1211
1103
    }
1212
1104
    return false;
1250
1142
  return executed;
1251
1143
}
1252
1144
 
1253
 
static void check_timeout_value(uint32_t in_connect_timeout)
1254
 
{
1255
 
  opt_connect_timeout= 0;
1256
 
  if (in_connect_timeout > 3600*12)
1257
 
  {
1258
 
    cout << _("Error: Invalid Value for connect_timeout"); 
1259
 
    exit(-1);
1260
 
  }
1261
 
  opt_connect_timeout= in_connect_timeout;
1262
 
}
1263
 
 
1264
 
static void check_max_input_line(uint32_t in_max_input_line)
1265
 
{
1266
 
  opt_max_input_line= 0;
1267
 
  if (in_max_input_line < 4096 || in_max_input_line > (int64_t)2*1024L*1024L*1024L)
1268
 
  {
1269
 
    cout << _("Error: Invalid Value for max_input_line");
1270
 
    exit(-1);
1271
 
  }
1272
 
  opt_max_input_line= in_max_input_line - (in_max_input_line % 1024);
1273
 
}
1274
 
 
1275
1145
int main(int argc,char *argv[])
1276
1146
{
1277
 
try
1278
 
{
 
1147
  char buff[80];
1279
1148
 
1280
1149
#if defined(ENABLE_NLS)
1281
1150
# if defined(HAVE_LOCALE_H)
1285
1154
  textdomain("drizzle");
1286
1155
#endif
1287
1156
 
1288
 
  po::options_description commandline_options(N_("Options used only in command line"));
1289
 
  commandline_options.add_options()
1290
 
  ("help,?",N_("Displays this help and exit."))
1291
 
  ("batch,B",N_("Don't use history file. Disable interactive behavior. (Enables --silent)"))
1292
 
  ("column-type-info", po::value<bool>(&column_types_flag)->default_value(false)->zero_tokens(),
1293
 
  N_("Display column type information."))
1294
 
  ("comments,c", po::value<bool>(&preserve_comments)->default_value(false)->zero_tokens(),
1295
 
  N_("Preserve comments. Send comments to the server. The default is --skip-comments (discard comments), enable with --comments"))
1296
 
  ("vertical,E", po::value<bool>(&vertical)->default_value(false)->zero_tokens(),
1297
 
  N_("Print the output of a query (rows) vertically."))
1298
 
  ("force,f", po::value<bool>(&ignore_errors)->default_value(false)->zero_tokens(),
1299
 
  N_("Continue even if we get an sql error."))
1300
 
  ("named-commands,G", po::value<bool>(&named_cmds)->default_value(false)->zero_tokens(),
1301
 
  N_("Enable named commands. Named commands mean this program's internal commands; see drizzle> help . When enabled, the named commands can be used from any line of the query, otherwise only from the first line, before an enter."))
1302
 
  ("no-beep,b", po::value<bool>(&opt_nobeep)->default_value(false)->zero_tokens(),
1303
 
  N_("Turn off beep on error."))
1304
 
  ("disable-line-numbers", N_("Do not write line numbers for errors."))
1305
 
  ("disable-column-names", N_("Do not write column names in results."))
1306
 
  ("skip-column-names,N", 
1307
 
  N_("Don't write column names in results. WARNING: -N is deprecated, use long version of this options instead."))
1308
 
  ("set-variable,O", po::value<string>(),
1309
 
  N_("Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value."))
1310
 
  ("table,t", po::value<bool>(&output_tables)->default_value(false)->zero_tokens(),
1311
 
  N_("Output in table format.")) 
1312
 
  ("safe-updates,U", po::value<bool>(&safe_updates)->default_value(false)->zero_tokens(),
1313
 
  N_("Only allow UPDATE and DELETE that uses keys."))
1314
 
  ("i-am-a-dummy,U", po::value<bool>(&safe_updates)->default_value(false)->zero_tokens(),
1315
 
  N_("Synonym for option --safe-updates, -U."))
1316
 
  ("verbose,v", po::value<string>(&opt_verbose)->default_value(""),
1317
 
  N_("-v vvv implies that verbose= 3, Used to specify verbose"))
1318
 
  ("version,V", N_("Output version information and exit."))
1319
 
  ("secure-auth", po::value<bool>(&opt_secure_auth)->default_value(false)->zero_tokens(),
1320
 
  N_("Refuse client connecting to server if it uses old (pre-4.1.1) protocol"))
1321
 
  ("show-warnings", po::value<bool>(&show_warnings)->default_value(false)->zero_tokens(),
1322
 
  N_("Show warnings after every statement."))
1323
 
  ("show-progress-size", po::value<uint32_t>(&show_progress_size)->default_value(0),
1324
 
  N_("Number of lines before each import progress report."))
1325
 
  ("ping", po::value<bool>(&opt_ping)->default_value(false)->zero_tokens(),
1326
 
  N_("Ping the server to check if it's alive."))
1327
 
  ("no-defaults", po::value<bool>()->default_value(false)->zero_tokens(),
1328
 
  N_("Configuration file defaults are not used if no-defaults is set"))
1329
 
  ;
1330
 
 
1331
 
  po::options_description drizzle_options(N_("Options specific to the drizzle client"));
1332
 
  drizzle_options.add_options()
1333
 
  ("disable-auto-rehash,A",
1334
 
  N_("Disable automatic rehashing. One doesn't need to use 'rehash' to get table and field completion, but startup and reconnecting may take a longer time."))
1335
 
  ("auto-vertical-output", po::value<bool>(&auto_vertical_output)->default_value(false)->zero_tokens(),
1336
 
  N_("Automatically switch to vertical output mode if the result is wider than the terminal width."))
1337
 
  ("database,D", po::value<string>(&current_db)->default_value(""),
1338
 
  N_("Database to use."))
1339
 
  ("default-character-set",po::value<string>(),
1340
 
  N_("(not used)"))
1341
 
  ("delimiter", po::value<string>(&delimiter_str)->default_value(";"),
1342
 
  N_("Delimiter to be used."))
1343
 
  ("execute,e", po::value<string>(),
1344
 
  N_("Execute command and quit. (Disables --force and history file)"))
1345
 
  ("local-infile", po::value<bool>(&opt_local_infile)->default_value(false)->zero_tokens(),
1346
 
  N_("Enable LOAD DATA LOCAL INFILE."))
1347
 
  ("unbuffered,n", po::value<bool>(&unbuffered)->default_value(false)->zero_tokens(),
1348
 
  N_("Flush buffer after each query."))
1349
 
  ("sigint-ignore", po::value<bool>(&opt_sigint_ignore)->default_value(false)->zero_tokens(),
1350
 
  N_("Ignore SIGINT (CTRL-C)"))
1351
 
  ("one-database,o", po::value<bool>(&one_database)->default_value(false)->zero_tokens(),
1352
 
  N_("Only update the default database. This is useful for skipping updates to other database in the update log."))
1353
 
  ("pager", po::value<string>(),
1354
 
  N_("Pager to use to display results. If you don't supply an option the default pager is taken from your ENV variable PAGER. Valid pagers are less, more, cat [> filename], etc. See interactive help (\\h) also. This option does not work in batch mode. Disable with --disable-pager. This option is disabled by default."))
1355
 
  ("disable-pager", po::value<bool>(&opt_nopager)->default_value(false)->zero_tokens(),
1356
 
  N_("Disable pager and print to stdout. See interactive help (\\h) also."))
1357
 
  ("prompt", po::value<string>(&current_prompt)->default_value(""),  
1358
 
  N_("Set the drizzle prompt to this value."))
1359
 
  ("quick,q", po::value<bool>(&quick)->default_value(false)->zero_tokens(),
1360
 
  N_("Don't cache result, print it row by row. This may slow down the server if the output is suspended. Doesn't use history file."))
1361
 
  ("raw,r", po::value<bool>(&opt_raw_data)->default_value(false)->zero_tokens(),
1362
 
  N_("Write fields without conversion. Used with --batch.")) 
1363
 
  ("disable-reconnect", N_("Do not reconnect if the connection is lost."))
1364
 
  ("shutdown", po::value<bool>()->zero_tokens(),
1365
 
  N_("Shutdown the server"))
1366
 
  ("silent,s", N_("Be more silent. Print results with a tab as separator, each row on new line."))
1367
 
  ("tee", po::value<string>(),
1368
 
  N_("Append everything into outfile. See interactive help (\\h) also. Does not work in batch mode. Disable with --disable-tee. This option is disabled by default."))
1369
 
  ("disable-tee", po::value<bool>()->default_value(false)->zero_tokens(), 
1370
 
  N_("Disable outfile. See interactive help (\\h) also."))
1371
 
  ("connect-timeout", po::value<uint32_t>(&opt_connect_timeout)->default_value(0)->notifier(&check_timeout_value),
1372
 
  N_("Number of seconds before connection timeout."))
1373
 
  ("max-input-line", po::value<uint32_t>(&opt_max_input_line)->default_value(16*1024L*1024L)->notifier(&check_max_input_line),
1374
 
  N_("Max length of input line"))
1375
 
  ("select-limit", po::value<uint32_t>(&select_limit)->default_value(1000L),
1376
 
  N_("Automatic limit for SELECT when using --safe-updates"))
1377
 
  ("max-join-size", po::value<uint32_t>(&max_join_size)->default_value(1000000L),
1378
 
  N_("Automatic limit for rows in a join when using --safe-updates"))
1379
 
  ;
1380
 
 
1381
 
  po::options_description client_options(N_("Options specific to the client"));
1382
 
  client_options.add_options()
1383
 
  ("host,h", po::value<string>(&current_host)->default_value("localhost"),
1384
 
  N_("Connect to host"))
1385
 
  ("password,P", po::value<string>(&current_password)->default_value(PASSWORD_SENTINEL),
1386
 
  N_("Password to use when connecting to server. If password is not given it's asked from the tty."))
1387
 
  ("port,p", po::value<uint32_t>()->default_value(0),
1388
 
  N_("Port number to use for connection or 0 for default to, in order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, built-in default"))
1389
 
#ifdef DRIZZLE_ADMIN_TOOL
1390
 
  ("user,u", po::value<string>(&current_user)->default_value("root"),
1391
 
#else
1392
 
  ("user,u", po::value<string>(&current_user)->default_value(""),
1393
 
#endif
1394
 
  N_("User for login if not current user."))
1395
 
  ("protocol",po::value<string>(&opt_protocol)->default_value("mysql"),
1396
 
  N_("The protocol of connection (mysql or drizzle)."))
1397
 
  ;
1398
 
 
1399
 
  po::options_description long_options(N_("Allowed Options"));
1400
 
  long_options.add(commandline_options).add(drizzle_options).add(client_options);
1401
 
 
1402
 
  std::string system_config_dir_drizzle(SYSCONFDIR); 
1403
 
  system_config_dir_drizzle.append("/drizzle/drizzle.cnf");
1404
 
 
1405
 
  std::string system_config_dir_client(SYSCONFDIR); 
1406
 
  system_config_dir_client.append("/drizzle/client.cnf");
1407
 
 
1408
 
  std::string user_config_dir((getenv("XDG_CONFIG_HOME")? getenv("XDG_CONFIG_HOME"):"~/.config"));
1409
 
 
1410
 
  if (user_config_dir.compare(0, 2, "~/") == 0)
1411
 
  {
1412
 
    char *homedir;
1413
 
    homedir= getenv("HOME");
1414
 
    if (homedir != NULL)
1415
 
      user_config_dir.replace(0, 1, homedir);
1416
 
  }
1417
 
 
1418
 
  po::variables_map vm;
1419
 
 
1420
 
  po::positional_options_description p;
1421
 
  p.add("database", 1);
1422
 
 
1423
 
  // Disable allow_guessing
1424
 
  int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing;
1425
 
 
1426
 
  po::store(po::command_line_parser(argc, argv).options(long_options).
1427
 
            style(style).positional(p).extra_parser(parse_password_arg).run(),
1428
 
            vm);
1429
 
 
1430
 
  if (! vm["no-defaults"].as<bool>())
1431
 
  {
1432
 
    std::string user_config_dir_drizzle(user_config_dir);
1433
 
    user_config_dir_drizzle.append("/drizzle/drizzle.cnf"); 
1434
 
 
1435
 
    std::string user_config_dir_client(user_config_dir);
1436
 
    user_config_dir_client.append("/drizzle/client.cnf");
1437
 
 
1438
 
    ifstream user_drizzle_ifs(user_config_dir_drizzle.c_str());
1439
 
    po::store(dpo::parse_config_file(user_drizzle_ifs, drizzle_options), vm);
1440
 
 
1441
 
    ifstream user_client_ifs(user_config_dir_client.c_str());
1442
 
    po::store(dpo::parse_config_file(user_client_ifs, client_options), vm);
1443
 
 
1444
 
    ifstream system_drizzle_ifs(system_config_dir_drizzle.c_str());
1445
 
    store(dpo::parse_config_file(system_drizzle_ifs, drizzle_options), vm);
1446
 
 
1447
 
    ifstream system_client_ifs(system_config_dir_client.c_str());
1448
 
    po::store(dpo::parse_config_file(system_client_ifs, client_options), vm);
1449
 
  }
1450
 
 
1451
 
  po::notify(vm);
1452
 
 
1453
 
#ifdef DRIZZLE_ADMIN_TOOL
1454
 
  default_prompt= strdup(getenv("DRIZZLE_PS1") ?
1455
 
                         getenv("DRIZZLE_PS1") :
1456
 
                         "drizzleadmin> ");
1457
 
#else
 
1157
  MY_INIT(argv[0]);
 
1158
  delimiter_str= delimiter;
1458
1159
  default_prompt= strdup(getenv("DRIZZLE_PS1") ?
1459
1160
                         getenv("DRIZZLE_PS1") :
1460
1161
                         "drizzle> ");
1461
 
#endif
 
1162
  
1462
1163
  if (default_prompt == NULL)
1463
1164
  {
1464
1165
    fprintf(stderr, _("Memory allocation error while constructing initial "
1466
1167
    exit(ENOMEM);
1467
1168
  }
1468
1169
  current_prompt= strdup(default_prompt);
1469
 
  if (current_prompt.empty())
 
1170
  if (current_prompt == NULL)
1470
1171
  {
1471
1172
    fprintf(stderr, _("Memory allocation error while constructing initial "
1472
1173
                      "prompt. Aborting.\n"));
1477
1178
 
1478
1179
  prompt_counter=0;
1479
1180
 
1480
 
  outfile.clear();      // no (default) outfile
1481
 
  pager.assign("stdout");  // the default, if --pager wasn't given
 
1181
  outfile[0]=0;      // no (default) outfile
 
1182
  strcpy(pager, "stdout");  // the default, if --pager wasn't given
1482
1183
  {
1483
 
    const char *tmp= getenv("PAGER");
 
1184
    char *tmp=getenv("PAGER");
1484
1185
    if (tmp && strlen(tmp))
1485
1186
    {
1486
1187
      default_pager_set= 1;
1487
 
      default_pager.assign(tmp);
 
1188
      strcpy(default_pager, tmp);
1488
1189
    }
1489
1190
  }
1490
 
  if (! isatty(0) || ! isatty(1))
 
1191
  if (!isatty(0) || !isatty(1))
1491
1192
  {
1492
 
    status.setBatch(1); opt_silent=1;
 
1193
    status.batch=1; opt_silent=1;
1493
1194
    ignore_errors=0;
1494
1195
  }
1495
1196
  else
1496
 
    status.setAddToHistory(1);
1497
 
  status.setExitStatus(1);
 
1197
    status.add_to_history=1;
 
1198
  status.exit_status=1;
1498
1199
 
1499
1200
  {
1500
1201
    /*
1510
1211
      close(stdout_fileno_copy);             /* Clean up dup(). */
1511
1212
  }
1512
1213
 
1513
 
  /* Inverted Booleans */
1514
 
 
1515
 
  line_numbers= (vm.count("disable-line-numbers")) ? false : true;
1516
 
  column_names= (vm.count("disable-column-names")) ? false : true;
1517
 
  opt_rehash= (vm.count("disable-auto-rehash")) ? false : true;
1518
 
  opt_reconnect= (vm.count("disable-reconnect")) ? false : true;
1519
 
 
1520
 
  /* Don't rehash with --shutdown */
1521
 
  if (vm.count("shutdown"))
1522
 
  {
1523
 
    opt_rehash= false;
1524
 
    opt_shutdown= true;
1525
 
  }
1526
 
 
1527
 
  if (vm.count("delimiter"))
1528
 
  {
1529
 
    /* Check that delimiter does not contain a backslash */
1530
 
    if (! strstr(delimiter_str.c_str(), "\\"))
1531
 
    {
1532
 
      delimiter= (char *)delimiter_str.c_str();  
1533
 
    }
1534
 
    else
1535
 
    {
1536
 
      put_info(_("DELIMITER cannot contain a backslash character"),
1537
 
      INFO_ERROR,0,0);
1538
 
      exit(-1);
1539
 
    }
1540
 
   
1541
 
    delimiter_length= (uint32_t)strlen(delimiter);
1542
 
  }
1543
 
  if (vm.count("tee"))
1544
 
  { 
1545
 
    if (vm["tee"].as<string>().empty())
1546
 
    {
1547
 
      if (opt_outfile)
1548
 
        end_tee();
1549
 
    }
1550
 
    else
1551
 
      init_tee(vm["tee"].as<string>().c_str());
1552
 
  }
1553
 
  if (vm["disable-tee"].as<bool>() == true)
1554
 
  {
1555
 
    if (opt_outfile)
1556
 
      end_tee();
1557
 
  }
1558
 
  if (vm.count("pager"))
1559
 
  {
1560
 
    if (vm["pager"].as<string>().empty())
1561
 
      opt_nopager= 1;
1562
 
    else
1563
 
    {
1564
 
      opt_nopager= 0;
1565
 
      if (vm[pager].as<string>().length())
1566
 
      {
1567
 
        default_pager_set= 1;
1568
 
        pager.assign(vm["pager"].as<string>());
1569
 
        default_pager.assign(pager);
1570
 
      }
1571
 
      else if (default_pager_set)
1572
 
        pager.assign(default_pager);
1573
 
      else
1574
 
        opt_nopager= 1;
1575
 
    }
1576
 
  }
1577
 
  if (vm.count("disable-pager"))
1578
 
  {
1579
 
    opt_nopager= 1;
1580
 
  }
1581
 
 
1582
 
  if (vm.count("no-auto-rehash"))
1583
 
    opt_rehash= 0;
1584
 
 
1585
 
  if (vm.count("skip-column-names"))
1586
 
    column_names= 0;
1587
 
    
1588
 
  if (vm.count("execute"))
1589
 
  {  
1590
 
    status.setBatch(1);
1591
 
    status.setAddToHistory(1);
1592
 
    if (status.getLineBuff() == NULL)
1593
 
      status.setLineBuff(opt_max_input_line,NULL);
1594
 
    if (status.getLineBuff() == NULL)
1595
 
    {
1596
 
      exit(1);
1597
 
    }
1598
 
    status.getLineBuff()->addString(vm["execute"].as<string>().c_str());
1599
 
  }
1600
 
 
1601
 
  if (one_database)
1602
 
    skip_updates= true;
1603
 
 
1604
 
  if (vm.count("protocol"))
1605
 
  {
1606
 
    std::transform(opt_protocol.begin(), opt_protocol.end(), 
1607
 
      opt_protocol.begin(), ::tolower);
1608
 
 
1609
 
    if (not opt_protocol.compare("mysql"))
1610
 
      use_drizzle_protocol=false;
1611
 
    else if (not opt_protocol.compare("drizzle"))
1612
 
      use_drizzle_protocol=true;
1613
 
    else
1614
 
    {
1615
 
      cout << _("Error: Unknown protocol") << " '" << opt_protocol << "'" << endl;
1616
 
      exit(-1);
1617
 
    }
1618
 
  }
1619
 
 
1620
 
  if (vm.count("port"))
1621
 
  {
1622
 
    opt_drizzle_port= vm["port"].as<uint32_t>();
1623
 
 
1624
 
    /* If the port number is > 65535 it is not a valid port
1625
 
       This also helps with potential data loss casting unsigned long to a
1626
 
       uint32_t. */
1627
 
    if (opt_drizzle_port > 65535)
1628
 
    {
1629
 
      printf(_("Error: Value of %" PRIu32 " supplied for port is not valid.\n"), opt_drizzle_port);
1630
 
      exit(-1);
1631
 
    }
1632
 
  }
1633
 
 
1634
 
  if (vm.count("password"))
1635
 
  {
1636
 
    if (!opt_password.empty())
1637
 
      opt_password.erase();
1638
 
    if (current_password == PASSWORD_SENTINEL)
1639
 
    {
1640
 
      opt_password= "";
1641
 
    }
1642
 
    else
1643
 
    {
1644
 
      opt_password= current_password;
1645
 
      tty_password= false;
1646
 
    }
1647
 
  }
1648
 
  else
1649
 
  {
1650
 
      tty_password= true;
1651
 
  }
1652
 
  
1653
 
 
1654
 
  if (!opt_verbose.empty())
1655
 
  {
1656
 
    verbose= opt_verbose.length();
1657
 
  }
1658
 
 
1659
 
  if (vm.count("batch"))
1660
 
  {
1661
 
    status.setBatch(1);
1662
 
    status.setAddToHistory(0);
1663
 
    if (opt_silent < 1)
1664
 
    {
1665
 
      opt_silent= 1;
1666
 
    }
1667
 
  }
1668
 
  if (vm.count("silent"))
1669
 
  {
1670
 
    opt_silent++;
1671
 
  }
1672
 
  
1673
 
  if (vm.count("help") || vm.count("version"))
1674
 
  {
1675
 
    printf(_("Drizzle client %s build %s, for %s-%s (%s) using readline %s\n"),
1676
 
           drizzle_version(), VERSION,
1677
 
           HOST_VENDOR, HOST_OS, HOST_CPU,
1678
 
           rl_library_version);
1679
 
    if (vm.count("version"))
1680
 
      exit(0);
1681
 
    printf(_("Copyright (C) 2008 Sun Microsystems\n"
1682
 
           "This software comes with ABSOLUTELY NO WARRANTY. "
1683
 
           "This is free software,\n"
1684
 
           "and you are welcome to modify and redistribute it "
1685
 
           "under the GPL license\n"));
1686
 
    printf(_("Usage: drizzle [OPTIONS] [database]\n"));
1687
 
    cout << long_options;
1688
 
    exit(0);
1689
 
  }
1690
 
 
1691
 
 
1692
 
  if (process_options())
1693
 
  {
 
1214
  load_defaults("drizzle",load_default_groups,&argc,&argv);
 
1215
  defaults_argv=argv;
 
1216
  if (get_options(argc, (char **) argv))
 
1217
  {
 
1218
    free_defaults(defaults_argv);
 
1219
    my_end(0);
1694
1220
    exit(1);
1695
1221
  }
1696
1222
 
1697
1223
  memset(&drizzle, 0, sizeof(drizzle));
1698
 
  if (sql_connect(current_host, current_db, current_user, opt_password,opt_silent))
 
1224
  if (sql_connect(current_host,current_db,current_user,opt_password,
 
1225
                  opt_silent))
1699
1226
  {
1700
1227
    quick= 1;          // Avoid history
1701
 
    status.setExitStatus(1);
 
1228
    status.exit_status= 1;
1702
1229
    drizzle_end(-1);
1703
1230
  }
1704
1231
 
1706
1233
  if (execute_commands(&command_error) != false)
1707
1234
  {
1708
1235
    /* we've executed a command so exit before we go into readline mode */
 
1236
    free_defaults(defaults_argv);
 
1237
    my_end(0);
1709
1238
    exit(command_error);
1710
1239
  }
1711
1240
 
1712
 
  if (status.getBatch() && !status.getLineBuff())
 
1241
  if (status.batch && !status.line_buff)
1713
1242
  {
1714
 
    status.setLineBuff(opt_max_input_line, stdin);
1715
 
    if (status.getLineBuff() == NULL)
 
1243
    status.line_buff =batch_readline_init(opt_max_input_line+512, stdin);
 
1244
    if (status.line_buff == NULL)
1716
1245
    {
 
1246
      free_defaults(defaults_argv);
 
1247
      my_end(0);
1717
1248
      exit(1);
1718
1249
    }
1719
1250
  }
1720
1251
 
1721
 
  if (!status.getBatch())
 
1252
  if (!status.batch)
1722
1253
    ignore_errors=1;        // Don't abort monitor
1723
1254
 
1724
1255
  if (opt_sigint_ignore)
1733
1264
  /* call the SIGWINCH handler to get the default term width */
1734
1265
  window_resize(0);
1735
1266
#endif
1736
 
  std::vector<char> output_buff;
1737
 
  output_buff.resize(512);
1738
 
 
1739
 
  snprintf(&output_buff[0], output_buff.size(), 
1740
 
           _("Welcome to the Drizzle client..  Commands end with %s or \\g."), 
1741
 
           delimiter);
1742
 
 
1743
 
  put_info(&output_buff[0], INFO_INFO, 0, 0);
 
1267
 
 
1268
  put_info(_("Welcome to the Drizzle client..  Commands end with ; or \\g."),
 
1269
           INFO_INFO,0,0);
1744
1270
 
1745
1271
  glob_buffer= new string();
1746
1272
  glob_buffer->reserve(512);
1747
1273
 
1748
 
  snprintf(&output_buff[0], output_buff.size(),
1749
 
          _("Your Drizzle connection id is %u\nConnection protocol: %s\nServer version: %s\n"),
 
1274
  char * output_buff= (char *)malloc(512);
 
1275
  memset(output_buff, '\0', 512);
 
1276
 
 
1277
  sprintf(output_buff,
 
1278
          _("Your Drizzle connection id is %u\nServer version: %s\n"),
1750
1279
          drizzle_con_thread_id(&con),
1751
 
          opt_protocol.c_str(),
1752
1280
          server_version_string(&con));
1753
 
  put_info(&output_buff[0], INFO_INFO, 0, 0);
1754
 
 
1755
 
 
1756
 
  initialize_readline((char *)current_prompt.c_str());
1757
 
  if (!status.getBatch() && !quick)
 
1281
  put_info(output_buff, INFO_INFO, 0, 0);
 
1282
 
 
1283
  initialize_readline(current_prompt);
 
1284
  if (!status.batch && !quick)
1758
1285
  {
1759
1286
    /* read-history from file, default ~/.drizzle_history*/
1760
1287
    if (getenv("DRIZZLE_HISTFILE"))
1765
1292
      if (histfile)
1766
1293
        sprintf(histfile,"%s/.drizzle_history",getenv("HOME"));
1767
1294
      char link_name[FN_REFLEN];
1768
 
      ssize_t sym_link_size= readlink(histfile,link_name,FN_REFLEN-1);
1769
 
      if (sym_link_size >= 0)
 
1295
      if (my_readlink(link_name, histfile, 0) == 0 &&
 
1296
          strncmp(link_name, "/dev/null", 10) == 0)
1770
1297
      {
1771
 
        link_name[sym_link_size]= '\0';
1772
 
        if (strncmp(link_name, "/dev/null", 10) == 0)
1773
 
        {
1774
 
          /* The .drizzle_history file is a symlink to /dev/null, don't use it */
1775
 
          free(histfile);
1776
 
          histfile= 0;
1777
 
        }
 
1298
        /* The .drizzle_history file is a symlink to /dev/null, don't use it */
 
1299
        free(histfile);
 
1300
        histfile= 0;
1778
1301
      }
1779
1302
    }
1780
1303
    if (histfile)
1790
1313
      sprintf(histfile_tmp, "%s.TMP", histfile);
1791
1314
    }
1792
1315
  }
 
1316
  sprintf(buff, "%s",
 
1317
          _("Type 'help;' or '\\h' for help. Type '\\c' to clear the buffer.\n"));
1793
1318
 
1794
 
  put_info(_("Type 'help;' or '\\h' for help. "
1795
 
             "Type '\\c' to clear the buffer.\n"),INFO_INFO,0,0);
1796
 
  status.setExitStatus(read_and_execute(!status.getBatch()));
 
1319
  put_info(buff,INFO_INFO,0,0);
 
1320
  status.exit_status= read_and_execute(!status.batch);
1797
1321
  if (opt_outfile)
1798
1322
    end_tee();
1799
1323
  drizzle_end(0);
1800
 
}
1801
1324
 
1802
 
  catch(exception &err)
1803
 
  {
1804
 
    cerr << _("Error:") << err.what() << endl;
1805
 
  }
1806
1325
  return(0);        // Keep compiler happy
1807
1326
}
1808
1327
 
1810
1329
{
1811
1330
  drizzle_con_free(&con);
1812
1331
  drizzle_free(&drizzle);
1813
 
  if (!status.getBatch() && !quick && histfile)
 
1332
  if (!status.batch && !quick && histfile)
1814
1333
  {
1815
1334
    /* write-history */
1816
1335
    if (verbose)
1817
1336
      tee_fprintf(stdout, _("Writing history-file %s\n"),histfile);
1818
1337
    if (!write_history(histfile_tmp))
1819
 
      rename(histfile_tmp, histfile);
 
1338
      my_rename(histfile_tmp, histfile, MYF(MY_WME));
1820
1339
  }
1821
 
  delete status.getLineBuff();
1822
 
  status.setLineBuff(0);
 
1340
  batch_readline_end(status.line_buff);
1823
1341
 
1824
1342
  if (sig >= 0)
1825
1343
    put_info(sig ? _("Aborted") : _("Bye"), INFO_RESULT,0,0);
1826
 
  delete glob_buffer;
1827
 
  delete processed_prompt;
1828
 
  opt_password.erase();
 
1344
  if (glob_buffer)
 
1345
    delete glob_buffer;
 
1346
  if (processed_prompt)
 
1347
    delete processed_prompt;
 
1348
  free(opt_password);
 
1349
  free(opt_drizzle_unix_port);
1829
1350
  free(histfile);
1830
1351
  free(histfile_tmp);
1831
 
  current_db.erase();
1832
 
  current_host.erase();
1833
 
  current_user.erase();
 
1352
  free(current_db);
 
1353
  free(current_host);
 
1354
  free(current_user);
1834
1355
  free(full_username);
1835
1356
  free(part_username);
1836
1357
  free(default_prompt);
1837
 
  current_prompt.erase();
1838
 
  exit(status.getExitStatus());
 
1358
  free(current_prompt);
 
1359
  free_defaults(defaults_argv);
 
1360
  my_end(my_end_arg);
 
1361
  exit(status.exit_status);
1839
1362
}
1840
1363
 
1841
1364
 
1848
1371
void handle_sigint(int sig)
1849
1372
{
1850
1373
  char kill_buffer[40];
1851
 
  boost::scoped_ptr<drizzle_con_st> kill_drizzle(new drizzle_con_st);
 
1374
  drizzle_con_st kill_drizzle;
1852
1375
  drizzle_result_st res;
1853
1376
  drizzle_return_t ret;
1854
1377
 
1857
1380
    goto err;
1858
1381
  }
1859
1382
 
1860
 
  if (drizzle_con_add_tcp(&drizzle, kill_drizzle.get(), current_host.c_str(),
1861
 
    opt_drizzle_port, current_user.c_str(), opt_password.c_str(), NULL,
1862
 
    use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL) == NULL)
 
1383
  if (drizzle_con_add_tcp(&drizzle, &kill_drizzle, current_host,
 
1384
                          opt_drizzle_port, current_user, opt_password, NULL,
 
1385
                          DRIZZLE_CON_NONE) == NULL)
1863
1386
  {
1864
1387
    goto err;
1865
1388
  }
1868
1391
  sprintf(kill_buffer, "KILL /*!50000 QUERY */ %u",
1869
1392
          drizzle_con_thread_id(&con));
1870
1393
 
1871
 
  if (drizzle_query_str(kill_drizzle.get(), &res, kill_buffer, &ret) != NULL)
 
1394
  if (drizzle_query_str(&kill_drizzle, &res, kill_buffer, &ret) != NULL)
1872
1395
    drizzle_result_free(&res);
1873
1396
 
1874
 
  drizzle_con_free(kill_drizzle.get());
 
1397
  drizzle_con_free(&kill_drizzle);
1875
1398
  tee_fprintf(stdout, _("Query aborted by Ctrl+C\n"));
1876
1399
 
1877
1400
  interrupted_query= 1;
1893
1416
}
1894
1417
#endif
1895
1418
 
1896
 
 
1897
 
 
1898
 
static int process_options(void)
 
1419
static struct my_option my_long_options[] =
 
1420
{
 
1421
  {"help", '?', N_("Display this help and exit."), 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
 
1422
   0, 0, 0, 0, 0},
 
1423
  {"help", 'I', N_("Synonym for -?"), 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
 
1424
   0, 0, 0, 0, 0},
 
1425
  {"auto-rehash", OPT_AUTO_REHASH,
 
1426
   N_("Enable automatic rehashing. One doesn't need to use 'rehash' to get table and field completion, but startup and reconnecting may take a longer time. Disable with --disable-auto-rehash."),
 
1427
   (char**) &opt_rehash, (char**) &opt_rehash, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0,
 
1428
   0, 0},
 
1429
  {"no-auto-rehash", 'A',
 
1430
   N_("No automatic rehashing. One has to use 'rehash' to get table and field completion. This gives a quicker start of drizzle_st and disables rehashing on reconnect. WARNING: options deprecated; use --disable-auto-rehash instead."),
 
1431
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1432
  {"auto-vertical-output", OPT_AUTO_VERTICAL_OUTPUT,
 
1433
   N_("Automatically switch to vertical output mode if the result is wider than the terminal width."),
 
1434
   (char**) &auto_vertical_output, (char**) &auto_vertical_output, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1435
  {"batch", 'B',
 
1436
   N_("Don't use history file. Disable interactive behavior. (Enables --silent)"), 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1437
  {"column-type-info", OPT_COLUMN_TYPES, N_("Display column type information."),
 
1438
   (char**) &column_types_flag, (char**) &column_types_flag,
 
1439
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1440
  {"comments", 'c', N_("Preserve comments. Send comments to the server. The default is --skip-comments (discard comments), enable with --comments"),
 
1441
   (char**) &preserve_comments, (char**) &preserve_comments,
 
1442
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1443
  {"compress", 'C', N_("Use compression in server/client protocol."),
 
1444
   (char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
 
1445
   0, 0, 0},
 
1446
  {"debug-check", OPT_DEBUG_CHECK, N_("Check memory and open file usage at exit ."),
 
1447
   (char**) &debug_check_flag, (char**) &debug_check_flag, 0,
 
1448
   GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1449
  {"debug-info", 'T', N_("Print some debug info at exit."), (char**) &debug_info_flag,
 
1450
   (char**) &debug_info_flag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1451
  {"database", 'D', N_("Database to use."), (char**) &current_db,
 
1452
   (char**) &current_db, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1453
  {"default-character-set", OPT_DEFAULT_CHARSET,
 
1454
   N_("(not used)"), 0,
 
1455
   0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1456
  {"delimiter", OPT_DELIMITER, N_("Delimiter to be used."), (char**) &delimiter_str,
 
1457
   (char**) &delimiter_str, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1458
  {"execute", 'e', N_("Execute command and quit. (Disables --force and history file)"), 0,
 
1459
   0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1460
  {"vertical", 'E', N_("Print the output of a query (rows) vertically."),
 
1461
   (char**) &vertical, (char**) &vertical, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
 
1462
   0},
 
1463
  {"force", 'f', N_("Continue even if we get an sql error."),
 
1464
   (char**) &ignore_errors, (char**) &ignore_errors, 0, GET_BOOL, NO_ARG, 0, 0,
 
1465
   0, 0, 0, 0},
 
1466
  {"named-commands", 'G',
 
1467
   N_("Enable named commands. Named commands mean this program's internal commands; see drizzle> help . When enabled, the named commands can be used from any line of the query, otherwise only from the first line, before an enter. Disable with --disable-named-commands. This option is disabled by default."),
 
1468
   (char**) &named_cmds, (char**) &named_cmds, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
 
1469
   0, 0},
 
1470
  {"no-named-commands", 'g',
 
1471
   N_("Named commands are disabled. Use \\* form only, or use named commands only in the beginning of a line ending with a semicolon (;) Since version 10.9 the client now starts with this option ENABLED by default! Disable with '-G'. Long format commands still work from the first line. WARNING: option deprecated; use --disable-named-commands instead."),
 
1472
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1473
  {"ignore-spaces", 'i', N_("Ignore space after function names."), 0, 0, 0,
 
1474
   GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1475
  {"local-infile", OPT_LOCAL_INFILE, N_("Enable/disable LOAD DATA LOCAL INFILE."),
 
1476
   (char**) &opt_local_infile,
 
1477
   (char**) &opt_local_infile, 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
1478
  {"no-beep", 'b', N_("Turn off beep on error."), (char**) &opt_nobeep,
 
1479
   (char**) &opt_nobeep, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1480
  {"host", 'h', N_("Connect to host."), (char**) &current_host,
 
1481
   (char**) &current_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1482
  {"line-numbers", OPT_LINE_NUMBERS, N_("Write line numbers for errors."),
 
1483
   (char**) &line_numbers, (char**) &line_numbers, 0, GET_BOOL,
 
1484
   NO_ARG, 1, 0, 0, 0, 0, 0},
 
1485
  {"skip-line-numbers", 'L', N_("Don't write line number for errors. WARNING: -L is deprecated, use long version of this option instead."), 0, 0, 0, GET_NO_ARG,
 
1486
   NO_ARG, 0, 0, 0, 0, 0, 0},
 
1487
  {"unbuffered", 'n', N_("Flush buffer after each query."), (char**) &unbuffered,
 
1488
   (char**) &unbuffered, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1489
  {"column-names", OPT_COLUMN_NAMES, N_("Write column names in results."),
 
1490
   (char**) &column_names, (char**) &column_names, 0, GET_BOOL,
 
1491
   NO_ARG, 1, 0, 0, 0, 0, 0},
 
1492
  {"skip-column-names", 'N',
 
1493
   N_("Don't write column names in results. WARNING: -N is deprecated, use long version of this options instead."),
 
1494
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1495
  {"set-variable", 'O',
 
1496
   N_("Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value."),
 
1497
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1498
  {"sigint-ignore", OPT_SIGINT_IGNORE, N_("Ignore SIGINT (CTRL-C)"),
 
1499
   (char**) &opt_sigint_ignore,  (char**) &opt_sigint_ignore, 0, GET_BOOL,
 
1500
   NO_ARG, 0, 0, 0, 0, 0, 0},
 
1501
  {"one-database", 'o',
 
1502
   N_("Only update the default database. This is useful for skipping updates to other database in the update log."),
 
1503
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1504
  {"pager", OPT_PAGER,
 
1505
   N_("Pager to use to display results. If you don't supply an option the default pager is taken from your ENV variable PAGER. Valid pagers are less, more, cat [> filename], etc. See interactive help (\\h) also. This option does not work in batch mode. Disable with --disable-pager. This option is disabled by default."),
 
1506
   0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
1507
  {"no-pager", OPT_NOPAGER,
 
1508
   N_("Disable pager and print to stdout. See interactive help (\\h) also. WARNING: option deprecated; use --disable-pager instead."),
 
1509
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1510
  {"password", 'P',
 
1511
   N_("Password to use when connecting to server. If password is not given it's asked from the tty."),
 
1512
   0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
1513
  {"port", 'p', N_("Port number to use for connection or 0 for default to, in order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, ")
 
1514
   N_("built-in default") " (" STRINGIFY_ARG(DRIZZLE_PORT) ").",
 
1515
   0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1516
  {"prompt", OPT_PROMPT, N_("Set the drizzle prompt to this value."),
 
1517
   (char**) &current_prompt, (char**) &current_prompt, 0, GET_STR_ALLOC,
 
1518
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1519
  {"quick", 'q',
 
1520
   N_("Don't cache result, print it row by row. This may slow down the server if the output is suspended. Doesn't use history file."),
 
1521
   (char**) &quick, (char**) &quick, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1522
  {"raw", 'r', N_("Write fields without conversion. Used with --batch."),
 
1523
   (char**) &opt_raw_data, (char**) &opt_raw_data, 0, GET_BOOL, NO_ARG, 0, 0, 0,
 
1524
   0, 0, 0},
 
1525
  {"reconnect", OPT_RECONNECT, N_("Reconnect if the connection is lost. Disable with --disable-reconnect. This option is enabled by default."),
 
1526
   (char**) &opt_reconnect, (char**) &opt_reconnect, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
 
1527
  {"shutdown", OPT_SHUTDOWN, N_("Shutdown the server."),
 
1528
   (char**) &opt_shutdown, (char**) &opt_shutdown, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1529
  {"silent", 's', N_("Be more silent. Print results with a tab as separator, each row on new line."), 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0,
 
1530
   0, 0},
 
1531
  {"socket", 'S', N_("Socket file to use for connection."),
 
1532
   (char**) &opt_drizzle_unix_port, (char**) &opt_drizzle_unix_port, 0, GET_STR_ALLOC,
 
1533
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1534
  {"table", 't', N_("Output in table format."), (char**) &output_tables,
 
1535
   (char**) &output_tables, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1536
  {"tee", OPT_TEE,
 
1537
   N_("Append everything into outfile. See interactive help (\\h) also. Does not work in batch mode. Disable with --disable-tee. This option is disabled by default."),
 
1538
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1539
  {"no-tee", OPT_NOTEE, N_("Disable outfile. See interactive help (\\h) also. WARNING: option deprecated; use --disable-tee instead"), 0, 0, 0, GET_NO_ARG,
 
1540
   NO_ARG, 0, 0, 0, 0, 0, 0},
 
1541
#ifndef DONT_ALLOW_USER_CHANGE
 
1542
  {"user", 'u', N_("User for login if not current user."), (char**) &current_user,
 
1543
   (char**) &current_user, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1544
#endif
 
1545
  {"safe-updates", 'U', N_("Only allow UPDATE and DELETE that uses keys."),
 
1546
   (char**) &safe_updates, (char**) &safe_updates, 0, GET_BOOL, NO_ARG, 0, 0,
 
1547
   0, 0, 0, 0},
 
1548
  {"i-am-a-dummy", 'U', N_("Synonym for option --safe-updates, -U."),
 
1549
   (char**) &safe_updates, (char**) &safe_updates, 0, GET_BOOL, NO_ARG, 0, 0,
 
1550
   0, 0, 0, 0},
 
1551
  {"verbose", 'v', N_("Write more. (-v -v -v gives the table output format)."), 0,
 
1552
   0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1553
  {"version", 'V', N_("Output version information and exit."), 0, 0, 0,
 
1554
   GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1555
  {"wait", 'w', N_("Wait and retry if connection is down."), 0, 0, 0, GET_NO_ARG,
 
1556
   NO_ARG, 0, 0, 0, 0, 0, 0},
 
1557
  {"connect_timeout", OPT_CONNECT_TIMEOUT,
 
1558
   N_("Number of seconds before connection timeout."),
 
1559
   (char**) &opt_connect_timeout,
 
1560
   (char**) &opt_connect_timeout, 0, GET_UINT32, REQUIRED_ARG, 0, 0, 3600*12, 0,
 
1561
   0, 0},
 
1562
  {"max_input_line", OPT_MAX_INPUT_LINE,
 
1563
   N_("Max length of input line"),
 
1564
   (char**) &opt_max_input_line, (char**) &opt_max_input_line, 0,
 
1565
   GET_UINT32, REQUIRED_ARG, 16 *1024L*1024L, 4096,
 
1566
   (int64_t) 2*1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
 
1567
  {"select_limit", OPT_SELECT_LIMIT,
 
1568
   N_("Automatic limit for SELECT when using --safe-updates"),
 
1569
   (char**) &select_limit,
 
1570
   (char**) &select_limit, 0, GET_UINT32, REQUIRED_ARG, 1000L, 1, ULONG_MAX,
 
1571
   0, 1, 0},
 
1572
  {"max_join_size", OPT_MAX_JOIN_SIZE,
 
1573
   N_("Automatic limit for rows in a join when using --safe-updates"),
 
1574
   (char**) &max_join_size,
 
1575
   (char**) &max_join_size, 0, GET_UINT32, REQUIRED_ARG, 1000000L, 1, ULONG_MAX,
 
1576
   0, 1, 0},
 
1577
  {"secure-auth", OPT_SECURE_AUTH, N_("Refuse client connecting to server if it uses old (pre-4.1.1) protocol"), (char**) &opt_secure_auth,
 
1578
   (char**) &opt_secure_auth, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1579
  {"show-warnings", OPT_SHOW_WARNINGS, N_("Show warnings after every statement."),
 
1580
   (char**) &show_warnings, (char**) &show_warnings, 0, GET_BOOL, NO_ARG,
 
1581
   0, 0, 0, 0, 0, 0},
 
1582
  {"show-progress-size", OPT_SHOW_PROGRESS_SIZE, N_("Number of lines before each import progress report."),
 
1583
   (char**) &show_progress_size, (char**) &show_progress_size, 0, GET_UINT32, REQUIRED_ARG,
 
1584
   0, 0, 0, 0, 0, 0},
 
1585
  {"ping", OPT_PING, N_("Ping the server to check if it's alive."),
 
1586
   (char**) &opt_ping, (char**) &opt_ping, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1587
  { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
 
1588
};
 
1589
 
 
1590
 
 
1591
static void usage(int version)
 
1592
{
 
1593
  const char* readline= "readline";
 
1594
 
 
1595
  printf(_("%s  Ver %s Distrib %s, for %s (%s) using %s %s\n"),
 
1596
         my_progname, VER.c_str(), drizzle_version(),
 
1597
         SYSTEM_TYPE, MACHINE_TYPE,
 
1598
         readline, rl_library_version);
 
1599
 
 
1600
  if (version)
 
1601
    return;
 
1602
  printf(_("Copyright (C) 2008 Sun Microsystems\n"
 
1603
           "This software comes with ABSOLUTELY NO WARRANTY. "
 
1604
           "This is free software,\n"
 
1605
           "and you are welcome to modify and redistribute it "
 
1606
           "under the GPL license\n"));
 
1607
  printf(_("Usage: %s [OPTIONS] [database]\n"), my_progname);
 
1608
  my_print_help(my_long_options);
 
1609
  print_defaults("drizzle", load_default_groups);
 
1610
  my_print_variables(my_long_options);
 
1611
}
 
1612
 
 
1613
 
 
1614
extern "C" bool
 
1615
get_one_option(int optid, const struct my_option *, char *argument)
 
1616
{
 
1617
  char *endchar= NULL;
 
1618
  uint64_t temp_drizzle_port= 0;
 
1619
 
 
1620
  switch(optid) {
 
1621
  case  OPT_DEFAULT_CHARSET:
 
1622
    default_charset_used= 1;
 
1623
    break;
 
1624
  case OPT_DELIMITER:
 
1625
    if (argument == disabled_my_option)
 
1626
    {
 
1627
      strcpy(delimiter, DEFAULT_DELIMITER);
 
1628
    }
 
1629
    else
 
1630
    {
 
1631
      /* Check that delimiter does not contain a backslash */
 
1632
      if (!strstr(argument, "\\"))
 
1633
      {
 
1634
        strncpy(delimiter, argument, sizeof(delimiter) - 1);
 
1635
      }
 
1636
      else
 
1637
      {
 
1638
        put_info(_("DELIMITER cannot contain a backslash character"),
 
1639
                 INFO_ERROR,0,0);
 
1640
        return false;
 
1641
      }
 
1642
    }
 
1643
    delimiter_length= (uint32_t)strlen(delimiter);
 
1644
    delimiter_str= delimiter;
 
1645
    break;
 
1646
  case OPT_TEE:
 
1647
    if (argument == disabled_my_option)
 
1648
    {
 
1649
      if (opt_outfile)
 
1650
        end_tee();
 
1651
    }
 
1652
    else
 
1653
      init_tee(argument);
 
1654
    break;
 
1655
  case OPT_NOTEE:
 
1656
    printf(_("WARNING: option deprecated; use --disable-tee instead.\n"));
 
1657
    if (opt_outfile)
 
1658
      end_tee();
 
1659
    break;
 
1660
  case OPT_PAGER:
 
1661
    if (argument == disabled_my_option)
 
1662
      opt_nopager= 1;
 
1663
    else
 
1664
    {
 
1665
      opt_nopager= 0;
 
1666
      if (argument && strlen(argument))
 
1667
      {
 
1668
        default_pager_set= 1;
 
1669
        strncpy(pager, argument, sizeof(pager) - 1);
 
1670
        strcpy(default_pager, pager);
 
1671
      }
 
1672
      else if (default_pager_set)
 
1673
        strcpy(pager, default_pager);
 
1674
      else
 
1675
        opt_nopager= 1;
 
1676
    }
 
1677
    break;
 
1678
  case OPT_NOPAGER:
 
1679
    printf(_("WARNING: option deprecated; use --disable-pager instead.\n"));
 
1680
    opt_nopager= 1;
 
1681
    break;
 
1682
  case OPT_SERVER_ARG:
 
1683
    printf(_("WARNING: --server-arg option not supported in this configuration.\n"));
 
1684
    break;
 
1685
  case 'A':
 
1686
    opt_rehash= 0;
 
1687
    break;
 
1688
  case 'N':
 
1689
    column_names= 0;
 
1690
    break;
 
1691
  case 'e':
 
1692
    status.batch= 1;
 
1693
    status.add_to_history= 0;
 
1694
    if (!status.line_buff)
 
1695
      ignore_errors= 0;                         // do it for the first -e only
 
1696
    if (!(status.line_buff= batch_readline_command(status.line_buff, argument)))
 
1697
      return 1;
 
1698
    break;
 
1699
  case 'o':
 
1700
    if (argument == disabled_my_option)
 
1701
      one_database= 0;
 
1702
    else
 
1703
      one_database= skip_updates= 1;
 
1704
    break;
 
1705
  case 'p':
 
1706
    temp_drizzle_port= (uint64_t) strtoul(argument, &endchar, 10);
 
1707
    /* if there is an alpha character this is not a valid port */
 
1708
    if (strlen(endchar) != 0)
 
1709
    {
 
1710
      put_info(_("Non-integer value supplied for port.  If you are trying to enter a password please use --password instead."), INFO_ERROR, 0, 0);
 
1711
      return false;
 
1712
    }
 
1713
    /* If the port number is > 65535 it is not a valid port
 
1714
       This also helps with potential data loss casting unsigned long to a
 
1715
       uint32_t. */
 
1716
    if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
 
1717
    {
 
1718
      put_info(_("Value supplied for port is not valid."), INFO_ERROR, 0, 0);
 
1719
      return false;
 
1720
    }
 
1721
    else
 
1722
    {
 
1723
      opt_drizzle_port= (uint32_t) temp_drizzle_port;
 
1724
    }
 
1725
    break;
 
1726
  case 'P':
 
1727
    /* Don't require password */
 
1728
    if (argument == disabled_my_option)
 
1729
    {
 
1730
      argument= (char*) "";
 
1731
    }
 
1732
    if (argument)
 
1733
    {
 
1734
      char *start= argument;
 
1735
      free(opt_password);
 
1736
      opt_password= strdup(argument);
 
1737
      while (*argument)
 
1738
      {
 
1739
        /* Overwriting password with 'x' */
 
1740
        *argument++= 'x';
 
1741
      }
 
1742
      if (*start)
 
1743
      {
 
1744
        start[1]= 0;
 
1745
      }
 
1746
      tty_password= 0;
 
1747
    }
 
1748
    else
 
1749
    {
 
1750
      tty_password= 1;
 
1751
    }
 
1752
    break;
 
1753
  case 's':
 
1754
    if (argument == disabled_my_option)
 
1755
      opt_silent= 0;
 
1756
    else
 
1757
      opt_silent++;
 
1758
    break;
 
1759
  case 'v':
 
1760
    if (argument == disabled_my_option)
 
1761
      verbose= 0;
 
1762
    else
 
1763
      verbose++;
 
1764
    break;
 
1765
  case 'B':
 
1766
    status.batch= 1;
 
1767
    status.add_to_history= 0;
 
1768
    set_if_bigger(opt_silent,1);                         // more silent
 
1769
    break;
 
1770
  case 'V':
 
1771
    usage(1);
 
1772
    exit(0);
 
1773
  case 'I':
 
1774
  case '?':
 
1775
    usage(0);
 
1776
    exit(0);
 
1777
  }
 
1778
  return 0;
 
1779
}
 
1780
 
 
1781
 
 
1782
static int get_options(int argc, char **argv)
1899
1783
{
1900
1784
  char *tmp, *pagpoint;
1901
 
  
 
1785
  int ho_error;
1902
1786
 
1903
1787
  tmp= (char *) getenv("DRIZZLE_HOST");
1904
1788
  if (tmp)
1905
 
    current_host.assign(tmp);
 
1789
    current_host= strdup(tmp);
1906
1790
 
1907
1791
  pagpoint= getenv("PAGER");
1908
1792
  if (!((char*) (pagpoint)))
1909
1793
  {
1910
 
    pager.assign("stdout");
 
1794
    strcpy(pager, "stdout");
1911
1795
    opt_nopager= 1;
1912
1796
  }
1913
1797
  else
1914
 
  {
1915
 
    pager.assign(pagpoint);
1916
 
  }
1917
 
  default_pager.assign(pager);
1918
 
 
1919
 
  //
1920
 
 
1921
 
  if (status.getBatch()) /* disable pager and outfile in this case */
1922
 
  {
1923
 
    default_pager.assign("stdout");
1924
 
    pager.assign("stdout");
 
1798
    strcpy(pager, pagpoint);
 
1799
  strcpy(default_pager, pager);
 
1800
 
 
1801
  if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
 
1802
    exit(ho_error);
 
1803
 
 
1804
  if (status.batch) /* disable pager and outfile in this case */
 
1805
  {
 
1806
    strcpy(default_pager, "stdout");
 
1807
    strcpy(pager, "stdout");
1925
1808
    opt_nopager= 1;
1926
1809
    default_pager_set= 0;
1927
1810
    opt_outfile= 0;
1929
1812
    connect_flag= DRIZZLE_CAPABILITIES_NONE; /* Not in interactive mode */
1930
1813
  }
1931
1814
 
 
1815
  if (argc > 1)
 
1816
  {
 
1817
    usage(0);
 
1818
    exit(1);
 
1819
  }
 
1820
  if (argc == 1)
 
1821
  {
 
1822
    skip_updates= 0;
 
1823
    free(current_db);
 
1824
    current_db= strdup(*argv);
 
1825
  }
1932
1826
  if (tty_password)
1933
1827
    opt_password= client_get_tty_password(NULL);
 
1828
  if (debug_info_flag)
 
1829
    my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
 
1830
  if (debug_check_flag)
 
1831
    my_end_arg= MY_CHECK_ERROR;
1934
1832
  return(0);
1935
1833
}
1936
1834
 
1940
1838
  char in_string=0;
1941
1839
  uint32_t line_number=0;
1942
1840
  bool ml_comment= 0;
1943
 
  Commands *com;
1944
 
  status.setExitStatus(1);
 
1841
  COMMANDS *com;
 
1842
  status.exit_status=1;
1945
1843
 
1946
1844
  for (;;)
1947
1845
  {
1948
1846
    if (!interactive)
1949
1847
    {
1950
 
      if (status.getLineBuff())
1951
 
        line= status.getLineBuff()->readline();
1952
 
      else
1953
 
        line= 0;
1954
 
 
 
1848
      line=batch_readline(status.line_buff);
 
1849
      /*
 
1850
        Skip UTF8 Byte Order Marker (BOM) 0xEFBBBF.
 
1851
        Editors like "notepad" put this marker in
 
1852
        the very beginning of a text file when
 
1853
        you save the file using "Unicode UTF-8" format.
 
1854
      */
 
1855
      if (!line_number &&
 
1856
          (unsigned char) line[0] == 0xEF &&
 
1857
          (unsigned char) line[1] == 0xBB &&
 
1858
          (unsigned char) line[2] == 0xBF)
 
1859
        line+= 3;
1955
1860
      line_number++;
1956
1861
      if (show_progress_size > 0)
1957
1862
      {
1959
1864
          fprintf(stderr, _("Processing line: %"PRIu32"\n"), line_number);
1960
1865
      }
1961
1866
      if (!glob_buffer->empty())
1962
 
        status.setQueryStartLine(line_number);
 
1867
        status.query_start_line=line_number;
1963
1868
    }
1964
1869
    else
1965
1870
    {
1966
 
      string prompt(ml_comment
1967
 
                      ? "   /*> " 
1968
 
                      : glob_buffer->empty()
1969
 
                        ? construct_prompt()
1970
 
                        : not in_string
1971
 
                          ? "    -> "
1972
 
                          : in_string == '\''
1973
 
                            ? "    '> "
1974
 
                            : in_string == '`'
1975
 
                              ? "    `> "
1976
 
                              : "    \"> ");
 
1871
      const char *prompt= (const char*) (ml_comment ? "   /*> " :
 
1872
                                         (glob_buffer->empty())
 
1873
                                         ?  construct_prompt()
 
1874
                                         : !in_string ? "    -> " :
 
1875
                                         in_string == '\'' ?
 
1876
                                         "    '> " : (in_string == '`' ?
 
1877
                                                      "    `> " :
 
1878
                                                      "    \"> "));
1977
1879
      if (opt_outfile && glob_buffer->empty())
1978
1880
        fflush(OUTFILE);
1979
1881
 
1980
1882
      if (opt_outfile)
1981
 
        fputs(prompt.c_str(), OUTFILE);
1982
 
      line= readline(prompt.c_str());
 
1883
        fputs(prompt, OUTFILE);
 
1884
      line= readline(prompt);
1983
1885
      /*
1984
1886
        When Ctrl+d or Ctrl+z is pressed, the line may be NULL on some OS
1985
1887
        which may cause coredump.
1990
1892
    // End of file
1991
1893
    if (!line)
1992
1894
    {
1993
 
      status.setExitStatus(0);
 
1895
      status.exit_status=0;
1994
1896
      break;
1995
1897
    }
1996
1898
 
2006
1908
      // If buffer was emptied
2007
1909
      if (glob_buffer->empty())
2008
1910
        in_string=0;
2009
 
      if (interactive && status.getAddToHistory() && not_in_history(line))
 
1911
      if (interactive && status.add_to_history && not_in_history(line))
2010
1912
        add_history(line);
2011
1913
      continue;
2012
1914
    }
2015
1917
  }
2016
1918
  /* if in batch mode, send last query even if it doesn't end with \g or go */
2017
1919
 
2018
 
  if (!interactive && !status.getExitStatus())
 
1920
  if (!interactive && !status.exit_status)
2019
1921
  {
2020
1922
    remove_cntrl(glob_buffer);
2021
1923
    if (!glob_buffer->empty())
2022
1924
    {
2023
 
      status.setExitStatus(1);
 
1925
      status.exit_status=1;
2024
1926
      if (com_go(glob_buffer,line) <= 0)
2025
 
        status.setExitStatus(0);
 
1927
        status.exit_status=0;
2026
1928
    }
2027
1929
  }
2028
1930
 
2029
 
  return status.getExitStatus();
 
1931
  return status.exit_status;
2030
1932
}
2031
1933
 
2032
1934
 
2033
 
static Commands *find_command(const char *name,char cmd_char)
 
1935
static COMMANDS *find_command(const char *name,char cmd_char)
2034
1936
{
2035
1937
  uint32_t len;
2036
1938
  const char *end;
2042
1944
  }
2043
1945
  else
2044
1946
  {
2045
 
    while (isspace(*name))
 
1947
    while (my_isspace(charset_info,*name))
2046
1948
      name++;
2047
1949
    /*
2048
1950
      If there is an \\g in the row or if the row has a delimiter but
2051
1953
    */
2052
1954
    if (strstr(name, "\\g") || (strstr(name, delimiter) &&
2053
1955
                                !(strlen(name) >= 9 &&
2054
 
                                  !strcmp(name, "delimiter"))))
2055
 
      return(NULL);
 
1956
                                  !my_strnncoll(charset_info,
 
1957
                                                (unsigned char*) name, 9,
 
1958
                                                (const unsigned char*) "delimiter",
 
1959
                                                9))))
 
1960
      return((COMMANDS *) 0);
2056
1961
    if ((end=strcont(name," \t")))
2057
1962
    {
2058
1963
      len=(uint32_t) (end - name);
2059
 
      while (isspace(*end))
 
1964
      while (my_isspace(charset_info,*end))
2060
1965
        end++;
2061
1966
      if (!*end)
2062
1967
        end=0;          // no arguments to function
2065
1970
      len=(uint32_t) strlen(name);
2066
1971
  }
2067
1972
 
2068
 
  for (uint32_t i= 0; commands[i].getName(); i++)
 
1973
  for (uint32_t i= 0; commands[i].name; i++)
2069
1974
  {
2070
1975
    if (commands[i].func &&
2071
 
        ((name && !strncmp(name, commands[i].getName(), len)
2072
 
          && !commands[i].getName()[len] && (!end || (end && commands[i].getTakesParams()))) || (!name && commands[i].getCmdChar() == cmd_char)))
 
1976
        ((name && !my_strnncoll(charset_info,(const unsigned char*)name,len, (const unsigned char*)commands[i].name,len) && !commands[i].name[len] && (!end || (end && commands[i].takes_params))) || (!name && commands[i].cmd_char == cmd_char)))
2073
1977
    {
2074
1978
      return(&commands[i]);
2075
1979
    }
2076
1980
  }
2077
 
  return(NULL);
 
1981
  return((COMMANDS *) 0);
2078
1982
}
2079
1983
 
2080
1984
 
2082
1986
                        bool *ml_comment)
2083
1987
{
2084
1988
  unsigned char inchar;
2085
 
  char *pos, *out;
2086
 
  Commands *com;
 
1989
  char buff[80], *pos, *out;
 
1990
  COMMANDS *com;
2087
1991
  bool need_space= 0;
2088
1992
  bool ss_comment= 0;
2089
1993
 
2090
1994
 
2091
1995
  if (!line[0] && (buffer->empty()))
2092
1996
    return(0);
2093
 
  if (status.getAddToHistory() && line[0] && not_in_history(line))
 
1997
  if (status.add_to_history && line[0] && not_in_history(line))
2094
1998
    add_history(line);
2095
1999
  char *end_of_line=line+(uint32_t) strlen(line);
2096
2000
 
2099
2003
    if (!preserve_comments)
2100
2004
    {
2101
2005
      // Skip spaces at the beggining of a statement
2102
 
      if (isspace(inchar) && (out == line) &&
 
2006
      if (my_isspace(charset_info,inchar) && (out == line) &&
2103
2007
          (buffer->empty()))
2104
2008
        continue;
2105
2009
    }
2106
2010
 
 
2011
#ifdef USE_MB
2107
2012
    // Accept multi-byte characters as-is
2108
 
    if (not drizzled::utf8::is_single(*pos))
 
2013
    int length;
 
2014
    if (use_mb(charset_info) &&
 
2015
        (length= my_ismbchar(charset_info, pos, end_of_line)))
2109
2016
    {
2110
 
      int length;
2111
 
      if ((length= drizzled::utf8::sequence_length(*pos)))
 
2017
      if (!*ml_comment || preserve_comments)
2112
2018
      {
2113
 
        if (!*ml_comment || preserve_comments)
2114
 
        {
2115
 
          while (length--)
2116
 
            *out++ = *pos++;
2117
 
          pos--;
2118
 
        }
2119
 
        else
2120
 
          pos+= length - 1;
2121
 
        continue;
 
2019
        while (length--)
 
2020
          *out++ = *pos++;
 
2021
        pos--;
2122
2022
      }
 
2023
      else
 
2024
        pos+= length - 1;
 
2025
      continue;
2123
2026
    }
2124
 
    if (!*ml_comment && inchar == '\\' &&
2125
 
        !(*in_string && (drizzle_con_status(&con) & DRIZZLE_CON_STATUS_NO_BACKSLASH_ESCAPES)))
 
2027
#endif
 
2028
        if (!*ml_comment && inchar == '\\' &&
 
2029
            !(*in_string && (drizzle_con_status(&con) & DRIZZLE_CON_STATUS_NO_BACKSLASH_ESCAPES)))
2126
2030
    {
2127
2031
      // Found possbile one character command like \c
2128
2032
 
2145
2049
 
2146
2050
        if ((*com->func)(buffer,pos-1) > 0)
2147
2051
          return(1);                       // Quit
2148
 
        if (com->getTakesParams())
 
2052
        if (com->takes_params)
2149
2053
        {
2150
2054
          if (ss_comment)
2151
2055
          {
2174
2078
      }
2175
2079
      else
2176
2080
      {
2177
 
        string buff(_("Unknown command: "));
2178
 
        buff.push_back('\'');
2179
 
        buff.push_back(inchar);
2180
 
        buff.push_back('\'');
2181
 
        buff.push_back('.');
2182
 
        if (put_info(buff.c_str(),INFO_ERROR,0,0) > 0)
 
2081
        sprintf(buff,_("Unknown command '\\%c'."),inchar);
 
2082
        if (put_info(buff,INFO_ERROR,0,0) > 0)
2183
2083
          return(1);
2184
2084
        *out++='\\';
2185
2085
        *out++=(char) inchar;
2188
2088
    }
2189
2089
    else if (!*ml_comment && !*in_string &&
2190
2090
             (end_of_line - pos) >= 10 &&
2191
 
             !strncmp(pos, "delimiter ", 10))
 
2091
             !my_strnncoll(charset_info, (unsigned char*) pos, 10,
 
2092
                           (const unsigned char*) "delimiter ", 10))
2192
2093
    {
2193
2094
      // Flush previously accepted characters
2194
2095
      if (out != line)
2225
2126
 
2226
2127
      if (preserve_comments)
2227
2128
      {
2228
 
        while (isspace(*pos))
 
2129
        while (my_isspace(charset_info, *pos))
2229
2130
          *out++= *pos++;
2230
2131
      }
2231
2132
      // Flush previously accepted characters
2238
2139
      if (preserve_comments && ((*pos == '#') ||
2239
2140
                                ((*pos == '-') &&
2240
2141
                                 (pos[1] == '-') &&
2241
 
                                 isspace(pos[2]))))
 
2142
                                 my_isspace(charset_info, pos[2]))))
2242
2143
      {
2243
2144
        // Add trailing single line comments to this statement
2244
2145
        buffer->append(pos);
2265
2166
                 && (inchar == '#'
2266
2167
                     || (inchar == '-'
2267
2168
                         && pos[1] == '-'
2268
 
                         && isspace(pos[2])))))
 
2169
                         && my_isspace(charset_info,pos[2])))))
2269
2170
    {
2270
2171
      // Flush previously accepted characters
2271
2172
      if (out != line)
2331
2232
        *in_string= (char) inchar;
2332
2233
      if (!*ml_comment || preserve_comments)
2333
2234
      {
2334
 
        if (need_space && !isspace((char)inchar))
 
2235
        if (need_space && !my_isspace(charset_info, (char)inchar))
2335
2236
          *out++= ' ';
2336
2237
        need_space= 0;
2337
2238
        *out++= (char) inchar;
2342
2243
  {
2343
2244
    *out++='\n';
2344
2245
    uint32_t length=(uint32_t) (out-line);
2345
 
    if ((buffer->length() + length) > opt_max_input_line)
2346
 
    {
2347
 
      status.setExitStatus(1);
2348
 
      put_info(_("Not found a delimiter within max_input_line of input"), INFO_ERROR, 0, 0);
2349
 
      return 1;
2350
 
    }
2351
2246
    if ((!*ml_comment || preserve_comments))
2352
2247
      buffer->append(line, length);
2353
2248
  }
2452
2347
 
2453
2348
  /* Tell the completer that we want a crack first. */
2454
2349
  rl_attempted_completion_function= (rl_completion_func_t*)&mysql_completion;
2455
 
  rl_completion_entry_function= (drizzle_compentry_func_t*)&no_completion;
 
2350
  rl_completion_entry_function= (rl_compentry_func_t*)&no_completion;
2456
2351
}
2457
2352
 
2458
2353
 
2464
2359
*/
2465
2360
char **mysql_completion (const char *text, int, int)
2466
2361
{
2467
 
  if (!status.getBatch() && !quick)
 
2362
  if (!status.batch && !quick)
2468
2363
    return rl_completion_matches(text, new_command_generator);
2469
2364
  else
2470
2365
    return (char**) 0;
2533
2428
 
2534
2429
static void build_completion_hash(bool rehash, bool write_info)
2535
2430
{
2536
 
  Commands *cmd=commands;
 
2431
  COMMANDS *cmd=commands;
2537
2432
  drizzle_return_t ret;
2538
2433
  drizzle_result_st databases,tables,fields;
2539
2434
  drizzle_row_t database_row,table_row;
2540
2435
  drizzle_column_st *sql_field;
2541
2436
  string tmp_str, tmp_str_lower;
2542
2437
 
2543
 
  if (status.getBatch() || quick || current_db.empty())
 
2438
  if (status.batch || quick || !current_db)
2544
2439
    return;      // We don't need completion in batches
2545
2440
  if (!rehash)
2546
2441
    return;
2548
2443
  completion_map.clear();
2549
2444
 
2550
2445
  /* hash this file's known subset of SQL commands */
2551
 
  while (cmd->getName()) {
2552
 
    tmp_str= cmd->getName();
 
2446
  while (cmd->name) {
 
2447
    tmp_str= cmd->name;
2553
2448
    tmp_str_lower= lower_string(tmp_str);
2554
2449
    completion_map[tmp_str_lower]= tmp_str;
2555
2450
    cmd++;
2593
2488
    {
2594
2489
      if (drizzle_result_row_count(&tables) > 0 && !opt_silent && write_info)
2595
2490
      {
2596
 
        tee_fprintf(stdout,
2597
 
                    _("Reading table information for completion of "
2598
 
                      "table and column names\n"
2599
 
                      "You can turn off this feature to get a quicker "
2600
 
                      "startup with -A\n\n"));
 
2491
        tee_fprintf(stdout, _("\
 
2492
Reading table information for completion of table and column names\n    \
 
2493
You can turn off this feature to get a quicker startup with -A\n\n"));
2601
2494
      }
2602
2495
      while ((table_row=drizzle_row_next(&tables)))
2603
2496
      {
2623
2516
  {
2624
2517
    string query;
2625
2518
 
2626
 
    query.append("show fields in `");
 
2519
    query.append("show fields in '");
2627
2520
    query.append(table_row[0]);
2628
 
    query.append("`");
 
2521
    query.append("'");
2629
2522
    
2630
2523
    if (drizzle_query(&con, &fields, query.c_str(), query.length(),
2631
2524
                      &ret) != NULL)
2655
2548
 
2656
2549
/* for gnu readline */
2657
2550
 
 
2551
#ifndef HAVE_INDEX
 
2552
extern "C" {
 
2553
  extern char *index(const char *,int c),*rindex(const char *,int);
 
2554
 
 
2555
  char *index(const char *s,int c)
 
2556
  {
 
2557
    for (;;)
 
2558
    {
 
2559
      if (*s == (char) c) return (char*) s;
 
2560
      if (!*s++) return NULL;
 
2561
    }
 
2562
  }
 
2563
 
 
2564
  char *rindex(const char *s,int c)
 
2565
  {
 
2566
    register char *t;
 
2567
 
 
2568
    t = NULL;
 
2569
    do if (*s == (char) c) t = (char*) s; while (*s++);
 
2570
    return (char*) t;
 
2571
  }
 
2572
}
 
2573
#endif
 
2574
 
2658
2575
 
2659
2576
static int reconnect(void)
2660
2577
{
 
2578
  /* purecov: begin tested */
2661
2579
  if (opt_reconnect)
2662
2580
  {
2663
2581
    put_info(_("No connection. Trying to reconnect..."),INFO_INFO,0,0);
2664
2582
    (void) com_connect((string *)0, 0);
2665
 
    if (opt_rehash && connected)
 
2583
    if (opt_rehash)
2666
2584
      com_rehash(NULL, NULL);
2667
2585
  }
2668
 
  if (! connected)
 
2586
  if (!connected)
2669
2587
    return put_info(_("Can't connect to the server\n"),INFO_ERROR,0,0);
 
2588
  /* purecov: end */
2670
2589
  return 0;
2671
2590
}
2672
2591
 
2675
2594
  drizzle_return_t ret;
2676
2595
  drizzle_result_st res;
2677
2596
 
2678
 
  current_db.erase();
2679
 
  current_db= "";
 
2597
  free(current_db);
 
2598
  current_db= NULL;
2680
2599
  /* In case of error below current_db will be NULL */
2681
2600
  if (drizzle_query_str(&con, &res, "SELECT DATABASE()", &ret) != NULL)
2682
2601
  {
2685
2604
    {
2686
2605
      drizzle_row_t row= drizzle_row_next(&res);
2687
2606
      if (row[0])
2688
 
        current_db.assign(row[0]);
2689
 
      drizzle_result_free(&res);
 
2607
        current_db= strdup(row[0]);
2690
2608
    }
 
2609
    drizzle_result_free(&res);
2691
2610
  }
2692
2611
}
2693
2612
 
2695
2614
 The different commands
2696
2615
***************************************************************************/
2697
2616
 
2698
 
int drizzleclient_real_query_for_lazy(const char *buf, size_t length,
 
2617
int drizzleclient_real_query_for_lazy(const char *buf, int length,
2699
2618
                                      drizzle_result_st *result,
2700
2619
                                      uint32_t *error_code)
2701
2620
{
2734
2653
    return 0;
2735
2654
 
2736
2655
  if (drizzle_con_error(&con)[0])
2737
 
  {
2738
 
    int ret= put_error(&con, result);
2739
 
    drizzle_result_free(result);
2740
 
    return ret;
2741
 
  }
 
2656
    return put_error(&con, result);
2742
2657
  return 0;
2743
2658
}
2744
2659
 
2747
2662
{
2748
2663
  register int i, j;
2749
2664
  char buff[32], *end;
2750
 
  std::vector<char> output_buff;
2751
 
  output_buff.resize(512);
2752
2665
 
2753
2666
  put_info(_("List of all Drizzle commands:"), INFO_INFO,0,0);
2754
2667
  if (!named_cmds)
2755
 
  {
2756
 
    snprintf(&output_buff[0], output_buff.size(),
2757
 
             _("Note that all text commands must be first on line and end with '%s' or \\g"),
2758
 
             delimiter);
2759
 
    put_info(&output_buff[0], INFO_INFO, 0, 0);
2760
 
  }
2761
 
  for (i = 0; commands[i].getName(); i++)
2762
 
  {
2763
 
    end= strcpy(buff, commands[i].getName());
2764
 
    end+= strlen(commands[i].getName());
2765
 
    for (j= (int)strlen(commands[i].getName()); j < 10; j++)
 
2668
    put_info(_("Note that all text commands must be first on line and end with ';'"),INFO_INFO,0,0);
 
2669
  for (i = 0; commands[i].name; i++)
 
2670
  {
 
2671
    end= strcpy(buff, commands[i].name);
 
2672
    end+= strlen(commands[i].name);
 
2673
    for (j= (int)strlen(commands[i].name); j < 10; j++)
2766
2674
      end= strcpy(end, " ")+1;
2767
2675
    if (commands[i].func)
2768
2676
      tee_fprintf(stdout, "%s(\\%c) %s\n", buff,
2769
 
                  commands[i].getCmdChar(), _(commands[i].getDoc()));
 
2677
                  commands[i].cmd_char, _(commands[i].doc));
2770
2678
  }
2771
2679
  tee_fprintf(stdout, "\n");
2772
2680
  buffer->clear();
2777
2685
static int
2778
2686
com_clear(string *buffer, const char *)
2779
2687
{
2780
 
  if (status.getAddToHistory())
 
2688
  if (status.add_to_history)
2781
2689
    fix_history(buffer);
2782
2690
  buffer->clear();
2783
2691
  return 0;
2810
2718
  if (buffer->empty())
2811
2719
  {
2812
2720
    // Ignore empty quries
2813
 
    if (status.getBatch())
 
2721
    if (status.batch)
2814
2722
      return 0;
2815
2723
    return put_info(_("No query specified\n"),INFO_ERROR,0,0);
2816
2724
 
2835
2743
  executing_query= 1;
2836
2744
  error= drizzleclient_real_query_for_lazy(buffer->c_str(),buffer->length(),&result, &error_code);
2837
2745
 
2838
 
  if (status.getAddToHistory())
 
2746
  if (status.add_to_history)
2839
2747
  {
2840
2748
    buffer->append(vertical ? "\\G" : delimiter);
2841
2749
    /* Append final command onto history */
2956
2864
  if (show_warnings == 1 && (warnings >= 1 || error))
2957
2865
    print_warnings(error_code);
2958
2866
 
2959
 
  if (!error && !status.getBatch() &&
 
2867
  if (!error && !status.batch &&
2960
2868
      drizzle_con_status(&con) & DRIZZLE_CON_STATUS_DB_DROPPED)
2961
2869
  {
2962
2870
    get_current_db();
2971
2879
{
2972
2880
  if (!opt_nopager)
2973
2881
  {
2974
 
    if (!(PAGER= popen(pager.c_str(), "w")))
 
2882
    if (!(PAGER= popen(pager, "w")))
2975
2883
    {
2976
 
      tee_fprintf(stdout,_( "popen() failed! defaulting PAGER to stdout!\n"));
 
2884
      tee_fprintf(stdout, "popen() failed! defaulting PAGER to stdout!\n");
2977
2885
      PAGER= stdout;
2978
2886
    }
2979
2887
  }
2995
2903
    end_tee();
2996
2904
  if (!(new_outfile= fopen(file_name, "a")))
2997
2905
  {
2998
 
    tee_fprintf(stdout, _("Error logging to file '%s'\n"), file_name);
 
2906
    tee_fprintf(stdout, "Error logging to file '%s'\n", file_name);
2999
2907
    return;
3000
2908
  }
3001
2909
  OUTFILE = new_outfile;
3002
 
  outfile.assign(file_name);
3003
 
  tee_fprintf(stdout, _("Logging to file '%s'\n"), file_name);
 
2910
  strncpy(outfile, file_name, FN_REFLEN-1);
 
2911
  tee_fprintf(stdout, "Logging to file '%s'\n", file_name);
3004
2912
  opt_outfile= 1;
3005
2913
 
3006
2914
  return;
3041
2949
    case DRIZZLE_COLUMN_TYPE_LONGLONG:    return "LONGLONG";
3042
2950
    case DRIZZLE_COLUMN_TYPE_NULL:        return "NULL";
3043
2951
    case DRIZZLE_COLUMN_TYPE_TIMESTAMP:   return "TIMESTAMP";
 
2952
    case DRIZZLE_COLUMN_TYPE_TINY:        return "TINY";
 
2953
    case DRIZZLE_COLUMN_TYPE_VIRTUAL:     return "VIRTUAL";
3044
2954
    default:                     return "?-unknown-?";
3045
2955
  }
3046
2956
}
3084
2994
 
3085
2995
  while ((field = drizzle_column_next(result)))
3086
2996
  {
3087
 
    tee_fprintf(PAGER, _("Field %3u:  `%s`\n"
 
2997
    tee_fprintf(PAGER, "Field %3u:  `%s`\n"
3088
2998
                "Catalog:    `%s`\n"
3089
2999
                "Database:   `%s`\n"
3090
3000
                "Table:      `%s`\n"
3091
3001
                "Org_table:  `%s`\n"
3092
 
                "Type:       UTF-8\n"
 
3002
                "Type:       %s\n"
3093
3003
                "Collation:  %s (%u)\n"
3094
3004
                "Length:     %lu\n"
3095
3005
                "Max_length: %lu\n"
3096
3006
                "Decimals:   %u\n"
3097
 
                "Flags:      %s\n\n"),
 
3007
                "Flags:      %s\n\n",
3098
3008
                ++i,
3099
3009
                drizzle_column_name(field), drizzle_column_catalog(field),
3100
3010
                drizzle_column_db(field), drizzle_column_table(field),
3101
3011
                drizzle_column_orig_table(field),
3102
3012
                fieldtype2str(drizzle_column_type(field)),
 
3013
                get_charset_name(drizzle_column_charset(field)),
3103
3014
                drizzle_column_charset(field), drizzle_column_size(field),
3104
3015
                drizzle_column_max_size(field), drizzle_column_decimals(field),
3105
3016
                fieldflags2str(drizzle_column_flags(field)));
3107
3018
  tee_puts("", PAGER);
3108
3019
}
3109
3020
 
 
3021
 
3110
3022
static void
3111
3023
print_table_data(drizzle_result_st *result)
3112
3024
{
3113
3025
  drizzle_row_t cur;
3114
3026
  drizzle_return_t ret;
3115
3027
  drizzle_column_st *field;
3116
 
  std::vector<bool> num_flag;
 
3028
  bool *num_flag;
3117
3029
  string separator;
3118
3030
 
3119
3031
  separator.reserve(256);
3120
3032
 
3121
 
  num_flag.resize(drizzle_result_column_count(result));
 
3033
  num_flag=(bool*) malloc(sizeof(bool)*drizzle_result_column_count(result));
3122
3034
  if (column_types_flag)
3123
3035
  {
3124
3036
    print_field_types(result);
3138
3050
      /* Check if the max_byte value is really the maximum in terms
3139
3051
         of visual length since multibyte characters can affect the
3140
3052
         length of the separator. */
3141
 
      length= drizzled::utf8::char_length(drizzle_column_name(field));
 
3053
      length= charset_info->cset->numcells(charset_info,
 
3054
                                           drizzle_column_name(field),
 
3055
                                           drizzle_column_name(field) +
 
3056
                                           name_length);
3142
3057
 
3143
3058
      if (name_length == drizzle_column_max_size(field))
3144
3059
      {
3176
3091
    for (uint32_t off=0; (field = drizzle_column_next(result)) ; off++)
3177
3092
    {
3178
3093
      uint32_t name_length= (uint32_t) strlen(drizzle_column_name(field));
3179
 
      uint32_t numcells= drizzled::utf8::char_length(drizzle_column_name(field));
 
3094
      uint32_t numcells= charset_info->cset->numcells(charset_info,
 
3095
                                                  drizzle_column_name(field),
 
3096
                                                  drizzle_column_name(field) +
 
3097
                                                  name_length);
3180
3098
      uint32_t display_length= drizzle_column_max_size(field) + name_length -
3181
3099
                               numcells;
3182
3100
      tee_fprintf(PAGER, " %-*s |",(int) min(display_length,
3239
3157
        We need to find how much screen real-estate we will occupy to know how
3240
3158
        many extra padding-characters we should send with the printing function.
3241
3159
      */
3242
 
      visible_length= drizzled::utf8::char_length(buffer);
 
3160
      visible_length= charset_info->cset->numcells(charset_info, buffer, buffer + data_length);
3243
3161
      extra_padding= data_length - visible_length;
3244
3162
 
3245
3163
      if (field_max_length > MAX_COLUMN_LENGTH)
3246
 
        tee_print_sized_data(buffer, data_length, MAX_COLUMN_LENGTH+extra_padding, false);
 
3164
        tee_print_sized_data(buffer, data_length, MAX_COLUMN_LENGTH+extra_padding, FALSE);
3247
3165
      else
3248
3166
      {
3249
3167
        if (num_flag[off] != 0) /* if it is numeric, we right-justify it */
3250
 
          tee_print_sized_data(buffer, data_length, field_max_length+extra_padding, true);
 
3168
          tee_print_sized_data(buffer, data_length, field_max_length+extra_padding, TRUE);
3251
3169
        else
3252
3170
          tee_print_sized_data(buffer, data_length,
3253
 
                               field_max_length+extra_padding, false);
 
3171
                               field_max_length+extra_padding, FALSE);
3254
3172
      }
3255
3173
      tee_fputs(" | ", PAGER);
3256
3174
    }
3259
3177
      drizzle_row_free(result, cur);
3260
3178
  }
3261
3179
  tee_puts(separator.c_str(), PAGER);
 
3180
  free(num_flag);
3262
3181
}
3263
3182
 
3264
3183
/**
3406
3325
  drizzle_row_t cur;
3407
3326
  uint64_t num_rows;
3408
3327
  uint32_t new_code= 0;
3409
 
  FILE *out;
3410
3328
 
3411
3329
  /* Get the warnings */
3412
3330
  query= "show warnings";
3432
3350
  }
3433
3351
 
3434
3352
  /* Print the warnings */
3435
 
  if (status.getBatch()) 
3436
 
  {
3437
 
    out= stderr;
3438
 
  } 
3439
 
  else 
3440
 
  {
3441
 
    init_pager();
3442
 
    out= PAGER;
3443
 
  }
 
3353
  init_pager();
3444
3354
  do
3445
3355
  {
3446
 
    tee_fprintf(out, "%s (Code %s): %s\n", cur[0], cur[1], cur[2]);
 
3356
    tee_fprintf(PAGER, "%s (Code %s): %s\n", cur[0], cur[1], cur[2]);
3447
3357
  } while ((cur= drizzle_row_next(&result)));
3448
 
 
3449
 
  if (not status.getBatch())
3450
 
    end_pager();
 
3358
  end_pager();
3451
3359
 
3452
3360
end:
3453
3361
  drizzle_result_free(&result);
3464
3372
    if (opt_raw_data)
3465
3373
      tee_fputs(pos, PAGER);
3466
3374
    else for (const char *end=pos+length ; pos != end ; pos++)
3467
 
    {
3468
 
      int l;
3469
 
      if ((l = drizzled::utf8::sequence_length(*pos)))
3470
 
      {
3471
 
        while (l--)
3472
 
          tee_putc(*pos++, PAGER);
3473
 
        pos--;
3474
 
        continue;
3475
 
      }
3476
 
      if (!*pos)
3477
 
        tee_fputs("\\0", PAGER); // This makes everything hard
3478
 
      else if (*pos == '\t')
3479
 
        tee_fputs("\\t", PAGER); // This would destroy tab format
3480
 
      else if (*pos == '\n')
3481
 
        tee_fputs("\\n", PAGER); // This too
3482
 
      else if (*pos == '\\')
3483
 
        tee_fputs("\\\\", PAGER);
3484
 
      else
3485
 
        tee_putc(*pos, PAGER);
3486
 
    }
 
3375
         {
 
3376
#ifdef USE_MB
 
3377
           int l;
 
3378
           if (use_mb(charset_info) &&
 
3379
               (l = my_ismbchar(charset_info, pos, end)))
 
3380
           {
 
3381
             while (l--)
 
3382
               tee_putc(*pos++, PAGER);
 
3383
             pos--;
 
3384
             continue;
 
3385
           }
 
3386
#endif
 
3387
           if (!*pos)
 
3388
             tee_fputs("\\0", PAGER); // This makes everything hard
 
3389
           else if (*pos == '\t')
 
3390
             tee_fputs("\\t", PAGER); // This would destroy tab format
 
3391
           else if (*pos == '\n')
 
3392
             tee_fputs("\\n", PAGER); // This too
 
3393
           else if (*pos == '\\')
 
3394
             tee_fputs("\\\\", PAGER);
 
3395
           else
 
3396
             tee_putc(*pos, PAGER);
 
3397
         }
3487
3398
  }
3488
3399
}
3489
3400
 
3543
3454
  char file_name[FN_REFLEN], *end;
3544
3455
  const char *param;
3545
3456
 
3546
 
  if (status.getBatch())
 
3457
  if (status.batch)
3547
3458
    return 0;
3548
 
  while (isspace(*line))
 
3459
  while (my_isspace(charset_info,*line))
3549
3460
    line++;
3550
 
  if (!(param =strchr(line, ' '))) // if outfile wasn't given, use the default
 
3461
  if (!(param = strchr(line, ' '))) // if outfile wasn't given, use the default
3551
3462
  {
3552
 
    if (outfile.empty())
 
3463
    if (!strlen(outfile))
3553
3464
    {
3554
 
      printf(_("No previous outfile available, you must give a filename!\n"));
 
3465
      printf("No previous outfile available, you must give a filename!\n");
3555
3466
      return 0;
3556
3467
    }
3557
3468
    else if (opt_outfile)
3558
3469
    {
3559
 
      tee_fprintf(stdout, _("Currently logging to file '%s'\n"), outfile.c_str());
 
3470
      tee_fprintf(stdout, "Currently logging to file '%s'\n", outfile);
3560
3471
      return 0;
3561
3472
    }
3562
3473
    else
3563
 
      param= outfile.c_str();      //resume using the old outfile
 
3474
      param = outfile;      //resume using the old outfile
3564
3475
  }
3565
3476
 
3566
 
  /* @TODO: Replace this with string methods */
3567
3477
  /* eliminate the spaces before the parameters */
3568
 
  while (isspace(*param))
 
3478
  while (my_isspace(charset_info,*param))
3569
3479
    param++;
3570
3480
  strncpy(file_name, param, sizeof(file_name) - 1);
3571
3481
  end= file_name + strlen(file_name);
3572
3482
  /* remove end space from command line */
3573
 
  while (end > file_name && (isspace(end[-1]) ||
3574
 
                             iscntrl(end[-1])))
 
3483
  while (end > file_name && (my_isspace(charset_info,end[-1]) ||
 
3484
                             my_iscntrl(charset_info,end[-1])))
3575
3485
    end--;
3576
3486
  end[0]= 0;
3577
3487
  if (end == file_name)
3578
3488
  {
3579
 
    printf(_("No outfile specified!\n"));
 
3489
    printf("No outfile specified!\n");
3580
3490
    return 0;
3581
3491
  }
3582
3492
  init_tee(file_name);
3589
3499
{
3590
3500
  if (opt_outfile)
3591
3501
    end_tee();
3592
 
  tee_fprintf(stdout, _("Outfile disabled.\n"));
 
3502
  tee_fprintf(stdout, "Outfile disabled.\n");
3593
3503
  return 0;
3594
3504
}
3595
3505
 
3600
3510
static int
3601
3511
com_pager(string *, const char *line)
3602
3512
{
 
3513
  char pager_name[FN_REFLEN], *end;
3603
3514
  const char *param;
3604
3515
 
3605
 
  if (status.getBatch())
 
3516
  if (status.batch)
3606
3517
    return 0;
3607
3518
  /* Skip spaces in front of the pager command */
3608
 
  while (isspace(*line))
 
3519
  while (my_isspace(charset_info, *line))
3609
3520
    line++;
3610
3521
  /* Skip the pager command */
3611
3522
  param= strchr(line, ' ');
3612
3523
  /* Skip the spaces between the command and the argument */
3613
 
  while (param && isspace(*param))
 
3524
  while (param && my_isspace(charset_info, *param))
3614
3525
    param++;
3615
 
  if (!param || (*param == '\0')) // if pager was not given, use the default
 
3526
  if (!param || !strlen(param)) // if pager was not given, use the default
3616
3527
  {
3617
3528
    if (!default_pager_set)
3618
3529
    {
3619
 
      tee_fprintf(stdout, _("Default pager wasn't set, using stdout.\n"));
 
3530
      tee_fprintf(stdout, "Default pager wasn't set, using stdout.\n");
3620
3531
      opt_nopager=1;
3621
 
      pager.assign("stdout");
 
3532
      strcpy(pager, "stdout");
3622
3533
      PAGER= stdout;
3623
3534
      return 0;
3624
3535
    }
3625
 
    pager.assign(default_pager);
 
3536
    strcpy(pager, default_pager);
3626
3537
  }
3627
3538
  else
3628
3539
  {
3629
 
    string pager_name(param);
3630
 
    string::iterator end= pager_name.end();
3631
 
    while (end > pager_name.begin() &&
3632
 
           (isspace(*(end-1)) || iscntrl(*(end-1))))
3633
 
      --end;
3634
 
    pager_name.erase(end, pager_name.end());
3635
 
    pager.assign(pager_name);
3636
 
    default_pager.assign(pager_name);
 
3540
    end= strncpy(pager_name, param, sizeof(pager_name)-1);
 
3541
    end+= strlen(pager_name);
 
3542
    while (end > pager_name && (my_isspace(charset_info,end[-1]) ||
 
3543
                                my_iscntrl(charset_info,end[-1])))
 
3544
      end--;
 
3545
    end[0]=0;
 
3546
    strcpy(pager, pager_name);
 
3547
    strcpy(default_pager, pager_name);
3637
3548
  }
3638
3549
  opt_nopager=0;
3639
 
  tee_fprintf(stdout, _("PAGER set to '%s'\n"), pager.c_str());
 
3550
  tee_fprintf(stdout, "PAGER set to '%s'\n", pager);
3640
3551
  return 0;
3641
3552
}
3642
3553
 
3644
3555
static int
3645
3556
com_nopager(string *, const char *)
3646
3557
{
3647
 
  pager.assign("stdout");
 
3558
  strcpy(pager, "stdout");
3648
3559
  opt_nopager=1;
3649
3560
  PAGER= stdout;
3650
 
  tee_fprintf(stdout, _("PAGER set to stdout\n"));
 
3561
  tee_fprintf(stdout, "PAGER set to stdout\n");
3651
3562
  return 0;
3652
3563
}
3653
3564
 
3657
3568
com_quit(string *, const char *)
3658
3569
{
3659
3570
  /* let the screen auto close on a normal shutdown */
3660
 
  status.setExitStatus(0);
 
3571
  status.exit_status=0;
3661
3572
  return 1;
3662
3573
}
3663
3574
 
3705
3616
    tmp= get_arg(buff, 0);
3706
3617
    if (tmp && *tmp)
3707
3618
    {
3708
 
      current_db.erase();
3709
 
      current_db.assign(tmp);
 
3619
      free(current_db);
 
3620
      current_db= strdup(tmp);
3710
3621
      tmp= get_arg(buff, 1);
3711
3622
      if (tmp)
3712
3623
      {
3713
 
        current_host.erase();
 
3624
        free(current_host);
3714
3625
        current_host=strdup(tmp);
3715
3626
      }
3716
3627
    }
3717
3628
    else
3718
3629
    {
3719
3630
      /* Quick re-connect */
3720
 
      opt_rehash= 0;
 
3631
      opt_rehash= 0;                            /* purecov: tested */
3721
3632
    }
3722
3633
    // command used
3723
3634
    assert(buffer!=NULL);
3725
3636
  }
3726
3637
  else
3727
3638
    opt_rehash= 0;
3728
 
  error=sql_connect(current_host, current_db, current_user, opt_password,0);
 
3639
  error=sql_connect(current_host,current_db,current_user,opt_password,0);
3729
3640
  opt_rehash= save_rehash;
3730
3641
 
3731
3642
  if (connected)
3732
3643
  {
3733
 
    sprintf(buff, _("Connection id:    %u"), drizzle_con_thread_id(&con));
 
3644
    sprintf(buff,"Connection id:    %u",drizzle_con_thread_id(&con));
3734
3645
    put_info(buff,INFO_INFO,0,0);
3735
 
    sprintf(buff, _("Current database: %.128s\n"),
3736
 
            !current_db.empty() ? current_db.c_str() : _("*** NONE ***"));
 
3646
    sprintf(buff,"Current database: %.128s\n",
 
3647
            current_db ? current_db : "*** NONE ***");
3737
3648
    put_info(buff,INFO_INFO,0,0);
3738
3649
  }
3739
3650
  return error;
3744
3655
{
3745
3656
  char source_name[FN_REFLEN], *end;
3746
3657
  const char *param;
3747
 
  LineBuffer *line_buff;
 
3658
  LINE_BUFFER *line_buff;
3748
3659
  int error;
3749
 
  Status old_status;
 
3660
  STATUS old_status;
3750
3661
  FILE *sql_file;
3751
3662
 
3752
3663
  /* Skip space from file name */
3753
 
  while (isspace(*line))
 
3664
  while (my_isspace(charset_info,*line))
3754
3665
    line++;
3755
3666
  if (!(param = strchr(line, ' ')))    // Skip command name
3756
 
    return put_info(_("Usage: \\. <filename> | source <filename>"),
 
3667
    return put_info("Usage: \\. <filename> | source <filename>",
3757
3668
                    INFO_ERROR, 0,0);
3758
 
  while (isspace(*param))
 
3669
  while (my_isspace(charset_info,*param))
3759
3670
    param++;
3760
3671
  end= strncpy(source_name,param,sizeof(source_name)-1);
3761
3672
  end+= strlen(source_name);
3762
 
  while (end > source_name && (isspace(end[-1]) ||
3763
 
                               iscntrl(end[-1])))
 
3673
  while (end > source_name && (my_isspace(charset_info,end[-1]) ||
 
3674
                               my_iscntrl(charset_info,end[-1])))
3764
3675
    end--;
3765
3676
  end[0]=0;
3766
 
 
 
3677
  unpack_filename(source_name,source_name);
3767
3678
  /* open file name */
3768
3679
  if (!(sql_file = fopen(source_name, "r")))
3769
3680
  {
3770
3681
    char buff[FN_REFLEN+60];
3771
 
    sprintf(buff, _("Failed to open file '%s', error: %d"), source_name,errno);
 
3682
    sprintf(buff,"Failed to open file '%s', error: %d", source_name,errno);
3772
3683
    return put_info(buff, INFO_ERROR, 0 ,0);
3773
3684
  }
3774
3685
 
3775
 
  line_buff= new(std::nothrow) LineBuffer(opt_max_input_line,sql_file);
3776
 
  if (line_buff == NULL)
 
3686
  if (!(line_buff=batch_readline_init(opt_max_input_line+512,sql_file)))
3777
3687
  {
3778
3688
    fclose(sql_file);
3779
 
    return put_info(_("Can't initialize LineBuffer"), INFO_ERROR, 0, 0);
 
3689
    return put_info("Can't initialize batch_readline", INFO_ERROR, 0 ,0);
3780
3690
  }
3781
3691
 
3782
3692
  /* Save old status */
3784
3694
  memset(&status, 0, sizeof(status));
3785
3695
 
3786
3696
  // Run in batch mode
3787
 
  status.setBatch(old_status.getBatch());
3788
 
  status.setLineBuff(line_buff);
3789
 
  status.setFileName(source_name);
 
3697
  status.batch=old_status.batch;
 
3698
  status.line_buff=line_buff;
 
3699
  status.file_name=source_name;
3790
3700
  // Empty command buffer
3791
3701
  assert(glob_buffer!=NULL);
3792
3702
  glob_buffer->clear();
3794
3704
  // Continue as before
3795
3705
  status=old_status;
3796
3706
  fclose(sql_file);
3797
 
  delete status.getLineBuff();
3798
 
  line_buff=0;
3799
 
  status.setLineBuff(0);
 
3707
  batch_readline_end(line_buff);
3800
3708
  return error;
3801
3709
}
3802
3710
 
3812
3720
 
3813
3721
  if (!tmp || !*tmp)
3814
3722
  {
3815
 
    put_info(_("DELIMITER must be followed by a 'delimiter' character or string"),
 
3723
    put_info("DELIMITER must be followed by a 'delimiter' character or string",
3816
3724
             INFO_ERROR, 0, 0);
3817
3725
    return 0;
3818
3726
  }
3820
3728
  {
3821
3729
    if (strstr(tmp, "\\"))
3822
3730
    {
3823
 
      put_info(_("DELIMITER cannot contain a backslash character"),
 
3731
      put_info("DELIMITER cannot contain a backslash character",
3824
3732
               INFO_ERROR, 0, 0);
3825
3733
      return 0;
3826
3734
    }
3845
3753
  tmp= get_arg(buff, 0);
3846
3754
  if (!tmp || !*tmp)
3847
3755
  {
3848
 
    put_info(_("USE must be followed by a database name"), INFO_ERROR, 0, 0);
 
3756
    put_info("USE must be followed by a database name", INFO_ERROR, 0, 0);
3849
3757
    return 0;
3850
3758
  }
3851
3759
  /*
3855
3763
  */
3856
3764
  get_current_db();
3857
3765
 
3858
 
  if (current_db.empty() || strcmp(current_db.c_str(),tmp))
 
3766
  if (!current_db || strcmp(current_db,tmp))
3859
3767
  {
3860
3768
    if (one_database)
3861
3769
    {
3907
3815
      else
3908
3816
        drizzle_result_free(&result);
3909
3817
    }
3910
 
    current_db.erase();
3911
 
    current_db.assign(tmp);
 
3818
    free(current_db);
 
3819
    current_db= strdup(tmp);
3912
3820
    if (select_db > 1)
3913
3821
      build_completion_hash(opt_rehash, 1);
3914
3822
  }
3915
3823
 
3916
 
  put_info(_("Database changed"),INFO_INFO, 0, 0);
 
3824
  put_info("Database changed",INFO_INFO, 0, 0);
3917
3825
  return 0;
3918
3826
}
3919
3827
 
3920
 
static int com_shutdown(string *, const char *)
3921
 
{
3922
 
  drizzle_result_st result;
3923
 
  drizzle_return_t ret;
3924
 
 
3925
 
  if (verbose)
3926
 
  {
3927
 
    printf(_("shutting down drizzled"));
3928
 
    if (opt_drizzle_port > 0)
3929
 
      printf(_(" on port %d"), opt_drizzle_port);
3930
 
    printf("... ");
3931
 
  }
3932
 
 
3933
 
  if (drizzle_shutdown(&con, &result, DRIZZLE_SHUTDOWN_DEFAULT,
3934
 
                       &ret) == NULL || ret != DRIZZLE_RETURN_OK)
3935
 
  {
3936
 
    if (ret == DRIZZLE_RETURN_ERROR_CODE)
3937
 
    {
3938
 
      fprintf(stderr, _("shutdown failed; error: '%s'"),
3939
 
              drizzle_result_error(&result));
3940
 
      drizzle_result_free(&result);
3941
 
    }
3942
 
    else
3943
 
    {
3944
 
      fprintf(stderr, _("shutdown failed; error: '%s'"),
3945
 
              drizzle_con_error(&con));
3946
 
    }
3947
 
    return false;
3948
 
  }
3949
 
 
3950
 
  drizzle_result_free(&result);
3951
 
 
3952
 
  if (verbose)
3953
 
    printf(_("done\n"));
3954
 
 
3955
 
  return false;
3956
 
}
3957
 
 
3958
3828
static int
3959
3829
com_warnings(string *, const char *)
3960
3830
{
3961
3831
  show_warnings = 1;
3962
 
  put_info(_("Show warnings enabled."),INFO_INFO, 0, 0);
 
3832
  put_info("Show warnings enabled.",INFO_INFO, 0, 0);
3963
3833
  return 0;
3964
3834
}
3965
3835
 
3967
3837
com_nowarnings(string *, const char *)
3968
3838
{
3969
3839
  show_warnings = 0;
3970
 
  put_info(_("Show warnings disabled."),INFO_INFO, 0, 0);
 
3840
  put_info("Show warnings disabled.",INFO_INFO, 0, 0);
3971
3841
  return 0;
3972
3842
}
3973
3843
 
3997
3867
  else
3998
3868
  {
3999
3869
    /* skip leading white spaces */
4000
 
    while (isspace(*ptr))
 
3870
    while (my_isspace(charset_info, *ptr))
4001
3871
      ptr++;
4002
3872
    if (*ptr == '\\') // short command was used
4003
3873
      ptr+= 2;
4004
3874
    else
4005
 
      while (*ptr &&!isspace(*ptr)) // skip command
 
3875
      while (*ptr &&!my_isspace(charset_info, *ptr)) // skip command
4006
3876
        ptr++;
4007
3877
  }
4008
3878
  if (!*ptr)
4009
3879
    return NULL;
4010
 
  while (isspace(*ptr))
 
3880
  while (my_isspace(charset_info, *ptr))
4011
3881
    ptr++;
4012
3882
  if (*ptr == '\'' || *ptr == '\"' || *ptr == '`')
4013
3883
  {
4034
3904
 
4035
3905
 
4036
3906
static int
4037
 
sql_connect(const string &host, const string &database, const string &user, const string &password,
 
3907
sql_connect(char *host,char *database,char *user,char *password,
4038
3908
                 uint32_t silent)
4039
3909
{
4040
3910
  drizzle_return_t ret;
 
3911
 
4041
3912
  if (connected)
4042
3913
  {
4043
3914
    connected= 0;
4045
3916
    drizzle_free(&drizzle);
4046
3917
  }
4047
3918
  drizzle_create(&drizzle);
4048
 
 
4049
 
#ifdef DRIZZLE_ADMIN_TOOL
4050
 
  drizzle_con_options_t options= (drizzle_con_options_t) (DRIZZLE_CON_ADMIN | (use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL));
4051
 
#else
4052
 
  drizzle_con_options_t options= (drizzle_con_options_t) (use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL);
4053
 
#endif
4054
 
 
4055
 
  if (drizzle_con_add_tcp(&drizzle, &con, (char *)host.c_str(),
4056
 
    opt_drizzle_port, (char *)user.c_str(),
4057
 
    (char *)password.c_str(), (char *)database.c_str(),
4058
 
    options) == NULL)
 
3919
  if (drizzle_con_add_tcp(&drizzle, &con, host, opt_drizzle_port, user,
 
3920
                          password, database, DRIZZLE_CON_NONE) == NULL)
4059
3921
  {
4060
3922
    (void) put_error(&con, NULL);
4061
3923
    (void) fflush(stdout);
4094
3956
    return -1;          // Retryable
4095
3957
  }
4096
3958
  connected=1;
4097
 
 
 
3959
/* XXX hmm?
 
3960
  drizzle.reconnect= debug_info_flag; // We want to know if this happens
 
3961
*/
4098
3962
  build_completion_hash(opt_rehash, 1);
4099
3963
  return 0;
4100
3964
}
4111
3975
  drizzle_return_t ret;
4112
3976
 
4113
3977
  tee_puts("--------------", stdout);
4114
 
  printf(_("Drizzle client %s build %s, for %s-%s (%s) using readline %s\n"),
4115
 
         drizzle_version(), VERSION,
4116
 
         HOST_VENDOR, HOST_OS, HOST_CPU,
4117
 
         rl_library_version);
4118
 
 
 
3978
  usage(1);          /* Print version */
4119
3979
  if (connected)
4120
3980
  {
4121
 
    tee_fprintf(stdout, _("\nConnection id:\t\t%lu\n"),drizzle_con_thread_id(&con));
 
3981
    tee_fprintf(stdout, "\nConnection id:\t\t%lu\n",drizzle_con_thread_id(&con));
4122
3982
    /*
4123
3983
      Don't remove "limit 1",
4124
3984
      it is protection againts SQL_SELECT_LIMIT=0
4130
3990
      drizzle_row_t cur=drizzle_row_next(&result);
4131
3991
      if (cur)
4132
3992
      {
4133
 
        tee_fprintf(stdout, _("Current database:\t%s\n"), cur[0] ? cur[0] : "");
4134
 
        tee_fprintf(stdout, _("Current user:\t\t%s\n"), cur[1]);
 
3993
        tee_fprintf(stdout, "Current database:\t%s\n", cur[0] ? cur[0] : "");
 
3994
        tee_fprintf(stdout, "Current user:\t\t%s\n", cur[1]);
4135
3995
      }
4136
3996
      drizzle_result_free(&result);
4137
3997
    }
4138
3998
    else if (ret == DRIZZLE_RETURN_ERROR_CODE)
4139
3999
      drizzle_result_free(&result);
4140
 
    tee_puts(_("SSL:\t\t\tNot in use"), stdout);
 
4000
    tee_puts("SSL:\t\t\tNot in use", stdout);
4141
4001
  }
4142
4002
  else
4143
4003
  {
4144
4004
    vidattr(A_BOLD);
4145
 
    tee_fprintf(stdout, _("\nNo connection\n"));
 
4005
    tee_fprintf(stdout, "\nNo connection\n");
4146
4006
    vidattr(A_NORMAL);
4147
4007
    return 0;
4148
4008
  }
4149
4009
  if (skip_updates)
4150
4010
  {
4151
4011
    vidattr(A_BOLD);
4152
 
    tee_fprintf(stdout, _("\nAll updates ignored to this database\n"));
 
4012
    tee_fprintf(stdout, "\nAll updates ignored to this database\n");
4153
4013
    vidattr(A_NORMAL);
4154
4014
  }
4155
 
  tee_fprintf(stdout, _("Current pager:\t\t%s\n"), pager.c_str());
4156
 
  tee_fprintf(stdout, _("Using outfile:\t\t'%s'\n"), opt_outfile ? outfile.c_str() : "");
4157
 
  tee_fprintf(stdout, _("Using delimiter:\t%s\n"), delimiter);
4158
 
  tee_fprintf(stdout, _("Server version:\t\t%s\n"), server_version_string(&con));
4159
 
  tee_fprintf(stdout, _("Protocol:\t\t%s\n"), opt_protocol.c_str());
4160
 
  tee_fprintf(stdout, _("Protocol version:\t%d\n"), drizzle_con_protocol_version(&con));
4161
 
  tee_fprintf(stdout, _("Connection:\t\t%s\n"), drizzle_con_host(&con));
 
4015
  tee_fprintf(stdout, "Current pager:\t\t%s\n", pager);
 
4016
  tee_fprintf(stdout, "Using outfile:\t\t'%s'\n", opt_outfile ? outfile : "");
 
4017
  tee_fprintf(stdout, "Using delimiter:\t%s\n", delimiter);
 
4018
  tee_fprintf(stdout, "Server version:\t\t%s\n", server_version_string(&con));
 
4019
  tee_fprintf(stdout, "Protocol version:\t%d\n", drizzle_con_protocol_version(&con));
 
4020
  tee_fprintf(stdout, "Connection:\t\t%s\n", drizzle_con_host(&con));
4162
4021
/* XXX need to save this from result
4163
4022
  if ((id= drizzleclient_insert_id(&drizzle)))
4164
 
    tee_fprintf(stdout, "Insert id:\t\t%s\n", internal::llstr(id, buff));
 
4023
    tee_fprintf(stdout, "Insert id:\t\t%s\n", llstr(id, buff));
4165
4024
*/
4166
4025
 
4167
 
  if (drizzle_con_uds(&con))
4168
 
    tee_fprintf(stdout, _("UNIX socket:\t\t%s\n"), drizzle_con_uds(&con));
 
4026
  if (strcmp(drizzle_con_uds(&con), ""))
 
4027
    tee_fprintf(stdout, "UNIX socket:\t\t%s\n", drizzle_con_uds(&con));
4169
4028
  else
4170
 
    tee_fprintf(stdout, _("TCP port:\t\t%d\n"), drizzle_con_port(&con));
 
4029
    tee_fprintf(stdout, "TCP port:\t\t%d\n", drizzle_con_port(&con));
4171
4030
 
4172
4031
  if (safe_updates)
4173
4032
  {
4174
4033
    vidattr(A_BOLD);
4175
 
    tee_fprintf(stdout, _("\nNote that you are running in safe_update_mode:\n"));
 
4034
    tee_fprintf(stdout, "\nNote that you are running in safe_update_mode:\n");
4176
4035
    vidattr(A_NORMAL);
4177
 
    tee_fprintf(stdout, _("\
 
4036
    tee_fprintf(stdout, "\
4178
4037
UPDATEs and DELETEs that don't use a key in the WHERE clause are not allowed.\n\
4179
4038
(One can force an UPDATE/DELETE by adding LIMIT # at the end of the command.)\n \
4180
4039
SELECT has an automatic 'LIMIT %lu' if LIMIT is not used.\n             \
4181
 
Max number of examined row combination in a join is set to: %lu\n\n"),
 
4040
Max number of examined row combination in a join is set to: %lu\n\n",
4182
4041
                select_limit, max_join_size);
4183
4042
  }
4184
4043
  tee_puts("--------------\n", stdout);
4231
4090
  FILE *file= (info_type == INFO_ERROR ? stderr : stdout);
4232
4091
  static int inited=0;
4233
4092
 
4234
 
  if (status.getBatch())
 
4093
  if (status.batch)
4235
4094
  {
4236
4095
    if (info_type == INFO_ERROR)
4237
4096
    {
4238
4097
      (void) fflush(file);
4239
 
      fprintf(file,_("ERROR"));
 
4098
      fprintf(file,"ERROR");
4240
4099
      if (error)
4241
4100
      {
4242
4101
        if (sqlstate)
4244
4103
        else
4245
4104
          (void) fprintf(file," %d",error);
4246
4105
      }
4247
 
      if (status.getQueryStartLine() && line_numbers)
 
4106
      if (status.query_start_line && line_numbers)
4248
4107
      {
4249
 
        (void) fprintf(file," at line %"PRIu32,status.getQueryStartLine());
4250
 
        if (status.getFileName())
4251
 
          (void) fprintf(file," in file: '%s'", status.getFileName());
 
4108
        (void) fprintf(file," at line %"PRIu32,status.query_start_line);
 
4109
        if (status.file_name)
 
4110
          (void) fprintf(file," in file: '%s'", status.file_name);
4252
4111
      }
4253
4112
      (void) fprintf(file,": %s\n",str);
4254
4113
      (void) fflush(file);
4279
4138
      if (error)
4280
4139
      {
4281
4140
        if (sqlstate)
4282
 
          (void) tee_fprintf(file, _("ERROR %d (%s): "), error, sqlstate);
 
4141
          (void) tee_fprintf(file, "ERROR %d (%s): ", error, sqlstate);
4283
4142
        else
4284
 
          (void) tee_fprintf(file, _("ERROR %d: "), error);
 
4143
          (void) tee_fprintf(file, "ERROR %d: ", error);
4285
4144
      }
4286
4145
      else
4287
 
        tee_puts(_("ERROR: "), file);
 
4146
        tee_puts("ERROR: ", file);
4288
4147
    }
4289
4148
    else
4290
4149
      vidattr(A_BOLD);
4323
4182
{
4324
4183
  const char *start=  buffer->c_str();
4325
4184
  const char *end= start + (buffer->length());
4326
 
  while (start < end && !isgraph(end[-1]))
 
4185
  while (start < end && !my_isgraph(charset_info,end[-1]))
4327
4186
    end--;
4328
4187
  uint32_t pos_to_truncate= (end-start);
4329
4188
  if (buffer->length() > pos_to_truncate)
4417
4276
    tmp_buff_str << tmp;
4418
4277
 
4419
4278
    if (tmp > 1)
4420
 
      tmp_buff_str << _(" hours ");
 
4279
      tmp_buff_str << " hours ";
4421
4280
    else
4422
 
      tmp_buff_str << _(" hour ");
 
4281
      tmp_buff_str << " hour ";
4423
4282
  }
4424
4283
  if (sec >= 60.0)
4425
4284
  {
4426
4285
    tmp=(uint32_t) floor(sec/60.0);
4427
4286
    sec-=60.0*tmp;
4428
 
    tmp_buff_str << tmp << _(" min ");
 
4287
    tmp_buff_str << tmp << " min ";
4429
4288
  }
4430
4289
  if (part_second)
4431
4290
    tmp_buff_str.precision(2);
4432
4291
  else
4433
4292
    tmp_buff_str.precision(0);
4434
 
  tmp_buff_str << sec << _(" sec");
 
4293
  tmp_buff_str << sec << " sec";
4435
4294
  strcpy(buff, tmp_buff_str.str().c_str());
4436
4295
}
4437
4296
 
4462
4321
  struct tm *t = localtime(&lclock);
4463
4322
 
4464
4323
  /* parse thru the settings for the prompt */
4465
 
  string::iterator c= current_prompt.begin();
4466
 
  while (c != current_prompt.end())
 
4324
  for (char *c= current_prompt; *c; (void)*c++)
4467
4325
  {
4468
4326
    if (*c != PROMPT_CHAR)
4469
4327
    {
4470
 
      processed_prompt->push_back(*c);
 
4328
      processed_prompt->append(c, 1);
4471
4329
    }
4472
4330
    else
4473
4331
    {
4478
4336
      switch (*++c) {
4479
4337
      case '\0':
4480
4338
        // stop it from going beyond if ends with %
4481
 
        --c;
 
4339
        c--;
4482
4340
        break;
4483
4341
      case 'c':
4484
4342
        add_int_to_prompt(++prompt_counter);
4490
4348
          processed_prompt->append("not_connected");
4491
4349
        break;
4492
4350
      case 'd':
4493
 
        processed_prompt->append(not current_db.empty() ? current_db : "(none)");
 
4351
        processed_prompt->append(current_db ? current_db : "(none)");
4494
4352
        break;
4495
4353
      case 'h':
4496
4354
      {
4497
 
        const char *prompt= connected ? drizzle_con_host(&con) : "not_connected";
 
4355
        const char *prompt;
 
4356
        prompt= connected ? drizzle_con_host(&con) : "not_connected";
4498
4357
        if (strstr(prompt, "Localhost"))
4499
4358
          processed_prompt->append("localhost");
4500
4359
        else
4513
4372
          break;
4514
4373
        }
4515
4374
 
4516
 
        if (drizzle_con_uds(&con))
 
4375
        if (strcmp(drizzle_con_uds(&con), ""))
4517
4376
        {
4518
4377
          const char *pos=strrchr(drizzle_con_uds(&con),'/');
4519
4378
          processed_prompt->append(pos ? pos+1 : drizzle_con_uds(&con));
4526
4385
        if (!full_username)
4527
4386
          init_username();
4528
4387
        processed_prompt->append(full_username ? full_username :
4529
 
                                 (!current_user.empty() ?  current_user : "(unknown)"));
 
4388
                                 (current_user ?  current_user : "(unknown)"));
4530
4389
        break;
4531
4390
      case 'u':
4532
4391
        if (!full_username)
4533
4392
          init_username();
4534
4393
        processed_prompt->append(part_username ? part_username :
4535
 
                                 (!current_user.empty() ?  current_user : _("(unknown)")));
 
4394
                                 (current_user ?  current_user : "(unknown)"));
4536
4395
        break;
4537
4396
      case PROMPT_CHAR:
4538
4397
        {
4614
4473
        processed_prompt->append(delimiter_str);
4615
4474
        break;
4616
4475
      default:
4617
 
        processed_prompt->push_back(*c);
 
4476
        processed_prompt->append(c, 1);
4618
4477
      }
4619
4478
    }
4620
 
    ++c;
4621
4479
  }
4622
4480
  return processed_prompt->c_str();
4623
4481
}
4652
4510
{
4653
4511
  const char *ptr=strchr(line, ' ');
4654
4512
  if (ptr == NULL)
4655
 
    tee_fprintf(stdout, _("Returning to default PROMPT of %s\n"),
 
4513
    tee_fprintf(stdout, "Returning to default PROMPT of %s\n",
4656
4514
                default_prompt);
4657
4515
  prompt_counter = 0;
4658
4516
  char * tmpptr= strdup(ptr ? ptr+1 : default_prompt);
4659
4517
  if (tmpptr == NULL)
4660
 
    tee_fprintf(stdout, _("Memory allocation error. Not changing prompt\n"));
 
4518
    tee_fprintf(stdout, "Memory allocation error. Not changing prompt\n");
4661
4519
  else
4662
4520
  {
4663
 
    current_prompt.erase();
 
4521
    free(current_prompt);
4664
4522
    current_prompt= tmpptr;
4665
 
    tee_fprintf(stdout, _("PROMPT set to '%s'\n"), current_prompt.c_str());
 
4523
    tee_fprintf(stdout, "PROMPT set to '%s'\n", current_prompt);
4666
4524
  }
4667
4525
  return 0;
4668
4526
}