~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzle.cc

Renamed namespace slot to namespace service.

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 "server_detect.h"
41
 
#include "get_password.h"
42
 
 
43
 
#include <boost/date_time/posix_time/posix_time.hpp>
44
 
 
45
 
#include <cerrno>
 
36
#include "client_priv.h"
46
37
#include <string>
47
 
#include <drizzled/gettext.h>
48
 
#include <iostream>
49
 
#include <fstream>
50
 
#include <map>
51
38
#include <algorithm>
52
 
#include <limits.h>
53
 
#include <cassert>
 
39
#include <mystrings/m_ctype.h>
54
40
#include <stdarg.h>
55
 
#include <math.h>
56
 
#include <memory>
57
 
#include <client/linebuffer.h>
 
41
#include "client/linebuffer.h"
58
42
#include <signal.h>
59
43
#include <sys/ioctl.h>
60
44
#include <drizzled/configmake.h>
61
 
#include <drizzled/utf8/utf8.h>
62
 
#include <cstdlib>
63
45
 
64
46
#if defined(HAVE_CURSES_H) && defined(HAVE_TERM_H)
65
47
#include <curses.h>
117
99
    /* no history */
118
100
#endif /* HAVE_READLINE_HISTORY */
119
101
 
 
102
#define DRIZZLE_DEFAULT_INPUT_LINE 65536
 
103
 
120
104
/**
121
105
 Make the old readline interface look like the new one.
122
106
*/
123
 
#ifndef HAVE_RL_COMPLETION
124
 
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;
125
110
#define rl_completion_matches(str, func) \
126
111
  completion_matches((char *)str, (CPFunction *)func)
127
112
#endif
128
113
 
129
 
#ifdef HAVE_RL_COMPENTRY
130
 
# ifdef HAVE_WORKING_RL_COMPENTRY
131
 
typedef rl_compentry_func_t drizzle_compentry_func_t;
132
 
# else
133
 
/* Snow Leopard ships an rl_compentry which cannot be assigned to
134
 
 * rl_completion_entry_function. We must undo the complete and total
135
 
 * ass-bagery.
136
 
 */
137
 
typedef Function drizzle_compentry_func_t;
138
 
# endif
139
 
#else
140
 
typedef Function drizzle_compentry_func_t;
141
 
#endif
142
 
 
143
114
#if defined(HAVE_LOCALE_H)
144
115
#include <locale.h>
145
116
#endif
146
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);
147
123
 
148
124
 
149
125
#if !defined(HAVE_VIDATTR)
150
126
#undef vidattr
151
127
#define vidattr(A) {}      // Can't get this to work
152
128
#endif
153
 
#include <boost/program_options.hpp>
154
 
#include <boost/scoped_ptr.hpp>
155
 
#include <drizzled/program_options/config_file.h>
 
129
 
 
130
#include <iostream>
 
131
#include <map>
156
132
 
157
133
using namespace std;
158
 
namespace po=boost::program_options;
159
 
namespace dpo=drizzled::program_options;
160
134
 
 
135
const string VER("14.14");
161
136
/* Don't try to make a nice table if the data is too big */
162
137
const uint32_t MAX_COLUMN_LENGTH= 1024;
163
138
 
165
140
const int MAX_SERVER_VERSION_LENGTH= 128;
166
141
 
167
142
#define PROMPT_CHAR '\\'
 
143
#define DEFAULT_DELIMITER ";"
168
144
 
169
 
class Status
 
145
typedef struct st_status
170
146
{
171
 
public:
172
 
 
173
 
  Status(int in_exit_status, 
174
 
         uint32_t in_query_start_line,
175
 
         char *in_file_name,
176
 
         LineBuffer *in_line_buff,
177
 
         bool in_batch,
178
 
         bool in_add_to_history)
179
 
    :
180
 
    exit_status(in_exit_status),
181
 
    query_start_line(in_query_start_line),
182
 
    file_name(in_file_name),
183
 
    line_buff(in_line_buff),
184
 
    batch(in_batch),
185
 
    add_to_history(in_add_to_history)
186
 
    {}
187
 
 
188
 
  Status() :
189
 
    exit_status(0),
190
 
    query_start_line(0),
191
 
    file_name(NULL),
192
 
    line_buff(NULL),
193
 
    batch(false),        
194
 
    add_to_history(false)
195
 
  {}
196
 
  
197
 
  int getExitStatus() const
198
 
  {
199
 
    return exit_status;
200
 
  }
201
 
 
202
 
  uint32_t getQueryStartLine() const
203
 
  {
204
 
    return query_start_line;
205
 
  }
206
 
 
207
 
  const char *getFileName() const
208
 
  {
209
 
    return file_name;
210
 
  }
211
 
 
212
 
  LineBuffer *getLineBuff() const
213
 
  {
214
 
    return line_buff;
215
 
  }
216
 
 
217
 
  bool getBatch() const
218
 
  {
219
 
    return batch;
220
 
  }
221
 
 
222
 
  bool getAddToHistory() const
223
 
  {
224
 
    return add_to_history;
225
 
  }
226
 
 
227
 
  void setExitStatus(int in_exit_status)
228
 
  {
229
 
    exit_status= in_exit_status;
230
 
  }
231
 
 
232
 
  void setQueryStartLine(uint32_t in_query_start_line)
233
 
  {
234
 
    query_start_line= in_query_start_line;
235
 
  }
236
 
 
237
 
  void setFileName(char *in_file_name)
238
 
  {
239
 
    file_name= in_file_name;
240
 
  }
241
 
 
242
 
  void setLineBuff(int max_size, FILE *file=NULL)
243
 
  {
244
 
    line_buff= new(std::nothrow) LineBuffer(max_size, file);
245
 
  }
246
 
 
247
 
  void setLineBuff(LineBuffer *in_line_buff)
248
 
  {
249
 
    line_buff= in_line_buff;
250
 
  }
251
 
 
252
 
  void setBatch(bool in_batch)
253
 
  {
254
 
    batch= in_batch;
255
 
  }
256
 
 
257
 
  void setAddToHistory(bool in_add_to_history)
258
 
  {
259
 
    add_to_history= in_add_to_history;
260
 
  }
261
 
 
262
 
private:
263
147
  int exit_status;
264
148
  uint32_t query_start_line;
265
149
  char *file_name;
266
150
  LineBuffer *line_buff;
267
151
  bool batch,add_to_history;
268
 
}; 
 
152
} STATUS;
 
153
 
269
154
 
270
155
static map<string, string>::iterator completion_iter;
271
156
static map<string, string>::iterator completion_end;
272
157
static map<string, string> completion_map;
273
158
static string completion_string;
274
159
 
 
160
static char **defaults_argv;
275
161
 
276
162
enum enum_info_type { INFO_INFO,INFO_ERROR,INFO_RESULT};
277
163
typedef enum enum_info_type INFO_TYPE;
282
168
  connected= false, opt_raw_data= false, unbuffered= false,
283
169
  output_tables= false, opt_rehash= true, skip_updates= false,
284
170
  safe_updates= false, one_database= false,
285
 
  opt_shutdown= false, opt_ping= false,
 
171
  opt_compress= false, opt_shutdown= false, opt_ping= false,
286
172
  vertical= false, line_numbers= true, column_names= true,
287
173
  opt_nopager= true, opt_outfile= false, named_cmds= false,
288
 
  opt_nobeep= false, opt_reconnect= true,
289
 
  opt_secure_auth= false,
 
174
  tty_password= false, opt_nobeep= false, opt_reconnect= true,
 
175
  default_charset_used= false, opt_secure_auth= false,
290
176
  default_pager_set= false, opt_sigint_ignore= false,
291
177
  auto_vertical_output= false,
292
 
  show_warnings= false, executing_query= false, interrupted_query= false,
293
 
  use_drizzle_protocol= false, opt_local_infile;
294
 
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;
295
181
static bool column_types_flag;
296
182
static bool preserve_comments= false;
297
 
static uint32_t opt_max_input_line;
298
 
static uint32_t opt_drizzle_port= 0;
299
 
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;
300
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;
301
190
static char *histfile;
302
191
static char *histfile_tmp;
303
192
static string *glob_buffer;
304
193
static string *processed_prompt= NULL;
305
194
static char *default_prompt= NULL;
306
195
static char *full_username= NULL,*part_username= NULL;
307
 
static Status status;
 
196
static STATUS status;
308
197
static uint32_t select_limit;
309
198
static uint32_t max_join_size;
310
199
static uint32_t opt_connect_timeout= 0;
311
 
static ServerDetect::server_type server_type= ServerDetect::SERVER_UNKNOWN_FOUND;
312
 
std::string current_db,
313
 
  delimiter_str,  
314
 
  current_host,
315
 
  current_prompt,
316
 
  current_user,
317
 
  opt_verbose,
318
 
  current_password,
319
 
  opt_password,
320
 
  opt_protocol;
321
 
 
322
 
static const char* get_day_name(int day_of_week)
323
 
{
324
 
  switch(day_of_week)
325
 
  {
326
 
  case 0:
327
 
    return _("Sun");
328
 
  case 1:
329
 
    return _("Mon");
330
 
  case 2:
331
 
    return _("Tue");
332
 
  case 3:
333
 
    return _("Wed");
334
 
  case 4:
335
 
    return _("Thu");
336
 
  case 5:
337
 
    return _("Fri");
338
 
  case 6:
339
 
    return _("Sat");
340
 
  }
341
 
 
342
 
  return NULL;
343
 
}
344
 
 
345
 
static const char* get_month_name(int month)
346
 
{
347
 
  switch(month)
348
 
  {
349
 
  case 0:
350
 
    return _("Jan");
351
 
  case 1:
352
 
    return _("Feb");
353
 
  case 2:
354
 
    return _("Mar");
355
 
  case 3:
356
 
    return _("Apr");
357
 
  case 4:
358
 
    return _("May");
359
 
  case 5:
360
 
    return _("Jun");
361
 
  case 6:
362
 
    return _("Jul");
363
 
  case 7:
364
 
    return _("Aug");
365
 
  case 8:
366
 
    return _("Sep");
367
 
  case 9:
368
 
    return _("Oct");
369
 
  case 10:
370
 
    return _("Nov");
371
 
  case 11:
372
 
    return _("Dec");
373
 
  }
374
 
 
375
 
  return NULL;
376
 
}
377
 
 
378
 
/* @TODO: Remove this */
379
 
#define FN_REFLEN 512
380
 
 
381
 
static string default_pager("");
382
 
static string pager("");
383
 
static string outfile("");
 
200
// TODO: Need to i18n these
 
201
static const char *day_names[]= {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
 
202
static const char *month_names[]= {"Jan","Feb","Mar","Apr","May","Jun","Jul",
 
203
                                  "Aug","Sep","Oct","Nov","Dec"};
 
204
static char default_pager[FN_REFLEN];
 
205
static char pager[FN_REFLEN], outfile[FN_REFLEN];
384
206
static FILE *PAGER, *OUTFILE;
385
207
static uint32_t prompt_counter;
386
 
static char *delimiter= NULL;
 
208
static char delimiter[16]= DEFAULT_DELIMITER;
387
209
static uint32_t delimiter_length= 1;
388
210
unsigned short terminal_width= 80;
389
211
 
390
 
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,
391
215
                                      drizzle_result_st *result,
392
216
                                      uint32_t *error_code);
393
217
int drizzleclient_store_result_for_lazy(drizzle_result_st *result);
399
223
void tee_putc(int c, FILE *file);
400
224
static void tee_print_sized_data(const char *, unsigned int, unsigned int, bool);
401
225
/* The names of functions that actually do the manipulation. */
402
 
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);
403
229
static int com_quit(string *str,const char*),
404
230
  com_go(string *str,const char*), com_ego(string *str,const char*),
405
231
  com_print(string *str,const char*),
406
232
  com_help(string *str,const char*), com_clear(string *str,const char*),
407
233
  com_connect(string *str,const char*), com_status(string *str,const char*),
408
234
  com_use(string *str,const char*), com_source(string *str, const char*),
409
 
  com_shutdown(string *str,const char*),
410
235
  com_rehash(string *str, const char*), com_tee(string *str, const char*),
411
236
  com_notee(string *str, const char*),
412
237
  com_prompt(string *str, const char*), com_delimiter(string *str, const char*),
414
239
  com_nopager(string *str, const char*), com_pager(string *str, const char*);
415
240
 
416
241
static int read_and_execute(bool interactive);
417
 
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,
 
243
                       uint32_t silent);
418
244
static const char *server_version_string(drizzle_con_st *con);
419
245
static int put_info(const char *str,INFO_TYPE info,uint32_t error,
420
246
                    const char *sql_state);
430
256
static void add_int_to_prompt(int toadd);
431
257
static int get_result_width(drizzle_result_st *res);
432
258
static int get_field_disp_length(drizzle_column_st * field);
433
 
static const char * strcont(const char *str, const char *set);
 
259
static const char * strcont(register const char *str, register const char *set);
434
260
 
435
 
/* A class which contains information on the commands this program
 
261
/* A structure which contains information on the commands this program
436
262
   can understand. */
437
 
class Commands
438
 
{
439
 
private:
 
263
typedef struct {
440
264
  const char *name;        /* User printable name of the function. */
441
265
  char cmd_char;        /* msql command character */
442
 
public:
443
 
Commands(const char *in_name,
444
 
         char in_cmd_char,
445
 
         int (*in_func)(string *str,const char *name),
446
 
         bool in_takes_params,
447
 
         const char *in_doc)
448
 
  :
449
 
  name(in_name),
450
 
  cmd_char(in_cmd_char),
451
 
  func(in_func),
452
 
  takes_params(in_takes_params),
453
 
  doc(in_doc)
454
 
  {}
455
 
 
456
 
  Commands()
457
 
  :
458
 
  name(),
459
 
  cmd_char(),
460
 
  func(NULL),
461
 
  takes_params(false),
462
 
  doc()
463
 
  {}
464
 
 
465
 
  int (*func)(string *str,const char *);/* Function to call to do the job. */
466
 
 
467
 
  const char *getName() const
468
 
  {
469
 
    return name;
470
 
  }
471
 
 
472
 
  char getCmdChar() const
473
 
  {
474
 
    return cmd_char;
475
 
  }
476
 
 
477
 
  bool getTakesParams() const
478
 
  {
479
 
    return takes_params;
480
 
  }
481
 
 
482
 
  const char *getDoc() const
483
 
  {
484
 
    return doc;
485
 
  }
486
 
 
487
 
  void setName(const char *in_name)
488
 
  {
489
 
     name= in_name;
490
 
  }
491
 
 
492
 
  void setCmdChar(char in_cmd_char)
493
 
  {
494
 
    cmd_char= in_cmd_char;
495
 
  }
496
 
 
497
 
  void setTakesParams(bool in_takes_params)
498
 
  {
499
 
    takes_params= in_takes_params;
500
 
  }
501
 
 
502
 
  void setDoc(const char *in_doc)
503
 
  {
504
 
    doc= in_doc;
505
 
  }
506
 
 
507
 
private:
 
266
  int (*func)(string *str,const char *); /* Function to call to do the job. */
508
267
  bool takes_params;        /* Max parameters for command */
509
268
  const char *doc;        /* Documentation for this function.  */
510
 
}; 
511
 
 
512
 
 
513
 
static Commands commands[] = {
514
 
  Commands( "?",      '?', com_help,   0, N_("Synonym for `help'.") ),
515
 
  Commands( "clear",  'c', com_clear,  0, N_("Clear command.")),
516
 
  Commands( "connect",'r', com_connect,1,
517
 
    N_("Reconnect to the server. Optional arguments are db and host.")),
518
 
  Commands( "delimiter", 'd', com_delimiter,    1,
519
 
    N_("Set statement delimiter. NOTE: Takes the rest of the line as new delimiter.") ),
520
 
  Commands( "ego",    'G', com_ego,    0,
521
 
    N_("Send command to drizzle server, display result vertically.")),
522
 
  Commands( "exit",   'q', com_quit,   0, N_("Exit drizzle. Same as quit.")),
523
 
  Commands( "go",     'g', com_go,     0, N_("Send command to drizzle server.") ),
524
 
  Commands( "help",   'h', com_help,   0, N_("Display this help.") ),
525
 
  Commands( "nopager",'n', com_nopager,0, N_("Disable pager, print to stdout.") ),
526
 
  Commands( "notee",  't', com_notee,  0, N_("Don't write into outfile.") ),
527
 
  Commands( "pager",  'P', com_pager,  1,
528
 
    N_("Set PAGER [to_pager]. Print the query results via PAGER.") ),
529
 
  Commands( "print",  'p', com_print,  0, N_("Print current command.") ),
530
 
  Commands( "prompt", 'R', com_prompt, 1, N_("Change your drizzle prompt.")),
531
 
  Commands( "quit",   'q', com_quit,   0, N_("Quit drizzle.") ),
532
 
  Commands( "rehash", '#', com_rehash, 0, N_("Rebuild completion hash.") ),
533
 
  Commands( "source", '.', com_source, 1,
534
 
    N_("Execute an SQL script file. Takes a file name as an argument.")),
535
 
  Commands( "status", 's', com_status, 0, N_("Get status information from the server.")),
536
 
  Commands( "tee",    'T', com_tee,    1,
537
 
    N_("Set outfile [to_outfile]. Append everything into given outfile.") ),
538
 
  Commands( "use",    'u', com_use,    1,
539
 
    N_("Use another schema. Takes schema name as argument.") ),
540
 
  Commands( "shutdown",    'u', com_shutdown,    1,
541
 
    N_("Shutdown the instance you are connected too.") ),
542
 
  Commands( "warnings", 'W', com_warnings,  0,
543
 
    N_("Show warnings after every statement.") ),
544
 
  Commands( "nowarning", 'w', com_nowarnings, 0,
545
 
    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.") },
546
303
  /* Get bash-like expansion for some commands */
547
 
  Commands( "create table",     0, 0, 0, ""),
548
 
  Commands( "create database",  0, 0, 0, ""),
549
 
  Commands( "show databases",   0, 0, 0, ""),
550
 
  Commands( "show fields from", 0, 0, 0, ""),
551
 
  Commands( "show keys from",   0, 0, 0, ""),
552
 
  Commands( "show tables",      0, 0, 0, ""),
553
 
  Commands( "load data from",   0, 0, 0, ""),
554
 
  Commands( "alter table",      0, 0, 0, ""),
555
 
  Commands( "set option",       0, 0, 0, ""),
556
 
  Commands( "lock tables",      0, 0, 0, ""),
557
 
  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, ""},
558
315
  /* generated 2006-12-28.  Refresh occasionally from lexer. */
559
 
  Commands( "ACTION", 0, 0, 0, ""),
560
 
  Commands( "ADD", 0, 0, 0, ""),
561
 
  Commands( "AFTER", 0, 0, 0, ""),
562
 
  Commands( "AGAINST", 0, 0, 0, ""),
563
 
  Commands( "AGGREGATE", 0, 0, 0, ""),
564
 
  Commands( "ALL", 0, 0, 0, ""),
565
 
  Commands( "ALGORITHM", 0, 0, 0, ""),
566
 
  Commands( "ALTER", 0, 0, 0, ""),
567
 
  Commands( "ANALYZE", 0, 0, 0, ""),
568
 
  Commands( "AND", 0, 0, 0, ""),
569
 
  Commands( "ANY", 0, 0, 0, ""),
570
 
  Commands( "AS", 0, 0, 0, ""),
571
 
  Commands( "ASC", 0, 0, 0, ""),
572
 
  Commands( "ASCII", 0, 0, 0, ""),
573
 
  Commands( "ASENSITIVE", 0, 0, 0, ""),
574
 
  Commands( "AUTO_INCREMENT", 0, 0, 0, ""),
575
 
  Commands( "AVG", 0, 0, 0, ""),
576
 
  Commands( "AVG_ROW_LENGTH", 0, 0, 0, ""),
577
 
  Commands( "BEFORE", 0, 0, 0, ""),
578
 
  Commands( "BEGIN", 0, 0, 0, ""),
579
 
  Commands( "BETWEEN", 0, 0, 0, ""),
580
 
  Commands( "BIGINT", 0, 0, 0, ""),
581
 
  Commands( "BINARY", 0, 0, 0, ""),
582
 
  Commands( "BIT", 0, 0, 0, ""),
583
 
  Commands( "BLOB", 0, 0, 0, ""),
584
 
  Commands( "BOOL", 0, 0, 0, ""),
585
 
  Commands( "BOOLEAN", 0, 0, 0, ""),
586
 
  Commands( "BOTH", 0, 0, 0, ""),
587
 
  Commands( "BTREE", 0, 0, 0, ""),
588
 
  Commands( "BY", 0, 0, 0, ""),
589
 
  Commands( "BYTE", 0, 0, 0, ""),
590
 
  Commands( "CACHE", 0, 0, 0, ""),
591
 
  Commands( "CALL", 0, 0, 0, ""),
592
 
  Commands( "CASCADE", 0, 0, 0, ""),
593
 
  Commands( "CASCADED", 0, 0, 0, ""),
594
 
  Commands( "CASE", 0, 0, 0, ""),
595
 
  Commands( "CHAIN", 0, 0, 0, ""),
596
 
  Commands( "CHANGE", 0, 0, 0, ""),
597
 
  Commands( "CHANGED", 0, 0, 0, ""),
598
 
  Commands( "CHAR", 0, 0, 0, ""),
599
 
  Commands( "CHARACTER", 0, 0, 0, ""),
600
 
  Commands( "CHECK", 0, 0, 0, ""),
601
 
  Commands( "CHECKSUM", 0, 0, 0, ""),
602
 
  Commands( "CLIENT", 0, 0, 0, ""),
603
 
  Commands( "CLOSE", 0, 0, 0, ""),
604
 
  Commands( "COLLATE", 0, 0, 0, ""),
605
 
  Commands( "COLLATION", 0, 0, 0, ""),
606
 
  Commands( "COLUMN", 0, 0, 0, ""),
607
 
  Commands( "COLUMNS", 0, 0, 0, ""),
608
 
  Commands( "COMMENT", 0, 0, 0, ""),
609
 
  Commands( "COMMIT", 0, 0, 0, ""),
610
 
  Commands( "COMMITTED", 0, 0, 0, ""),
611
 
  Commands( "COMPACT", 0, 0, 0, ""),
612
 
  Commands( "COMPRESSED", 0, 0, 0, ""),
613
 
  Commands( "CONCURRENT", 0, 0, 0, ""),
614
 
  Commands( "CONDITION", 0, 0, 0, ""),
615
 
  Commands( "CONNECTION", 0, 0, 0, ""),
616
 
  Commands( "CONSISTENT", 0, 0, 0, ""),
617
 
  Commands( "CONSTRAINT", 0, 0, 0, ""),
618
 
  Commands( "CONTAINS", 0, 0, 0, ""),
619
 
  Commands( "CONTINUE", 0, 0, 0, ""),
620
 
  Commands( "CONVERT", 0, 0, 0, ""),
621
 
  Commands( "CREATE", 0, 0, 0, ""),
622
 
  Commands( "CROSS", 0, 0, 0, ""),
623
 
  Commands( "CUBE", 0, 0, 0, ""),
624
 
  Commands( "CURRENT_DATE", 0, 0, 0, ""),
625
 
  Commands( "CURRENT_TIMESTAMP", 0, 0, 0, ""),
626
 
  Commands( "CURRENT_USER", 0, 0, 0, ""),
627
 
  Commands( "CURSOR", 0, 0, 0, ""),
628
 
  Commands( "DATA", 0, 0, 0, ""),
629
 
  Commands( "DATABASE", 0, 0, 0, ""),
630
 
  Commands( "DATABASES", 0, 0, 0, ""),
631
 
  Commands( "DATE", 0, 0, 0, ""),
632
 
  Commands( "DATETIME", 0, 0, 0, ""),
633
 
  Commands( "DAY", 0, 0, 0, ""),
634
 
  Commands( "DAY_HOUR", 0, 0, 0, ""),
635
 
  Commands( "DAY_MICROSECOND", 0, 0, 0, ""),
636
 
  Commands( "DAY_MINUTE", 0, 0, 0, ""),
637
 
  Commands( "DAY_SECOND", 0, 0, 0, ""),
638
 
  Commands( "DEALLOCATE", 0, 0, 0, ""),
639
 
  Commands( "DEC", 0, 0, 0, ""),
640
 
  Commands( "DECIMAL", 0, 0, 0, ""),
641
 
  Commands( "DECLARE", 0, 0, 0, ""),
642
 
  Commands( "DEFAULT", 0, 0, 0, ""),
643
 
  Commands( "DEFINER", 0, 0, 0, ""),
644
 
  Commands( "DELAYED", 0, 0, 0, ""),
645
 
  Commands( "DELETE", 0, 0, 0, ""),
646
 
  Commands( "DESC", 0, 0, 0, ""),
647
 
  Commands( "DESCRIBE", 0, 0, 0, ""),
648
 
  Commands( "DETERMINISTIC", 0, 0, 0, ""),
649
 
  Commands( "DISABLE", 0, 0, 0, ""),
650
 
  Commands( "DISCARD", 0, 0, 0, ""),
651
 
  Commands( "DISTINCT", 0, 0, 0, ""),
652
 
  Commands( "DISTINCTROW", 0, 0, 0, ""),
653
 
  Commands( "DIV", 0, 0, 0, ""),
654
 
  Commands( "DOUBLE", 0, 0, 0, ""),
655
 
  Commands( "DROP", 0, 0, 0, ""),
656
 
  Commands( "DUMPFILE", 0, 0, 0, ""),
657
 
  Commands( "DUPLICATE", 0, 0, 0, ""),
658
 
  Commands( "DYNAMIC", 0, 0, 0, ""),
659
 
  Commands( "EACH", 0, 0, 0, ""),
660
 
  Commands( "ELSE", 0, 0, 0, ""),
661
 
  Commands( "ELSEIF", 0, 0, 0, ""),
662
 
  Commands( "ENABLE", 0, 0, 0, ""),
663
 
  Commands( "ENCLOSED", 0, 0, 0, ""),
664
 
  Commands( "END", 0, 0, 0, ""),
665
 
  Commands( "ENGINE", 0, 0, 0, ""),
666
 
  Commands( "ENGINES", 0, 0, 0, ""),
667
 
  Commands( "ENUM", 0, 0, 0, ""),
668
 
  Commands( "ERRORS", 0, 0, 0, ""),
669
 
  Commands( "ESCAPE", 0, 0, 0, ""),
670
 
  Commands( "ESCAPED", 0, 0, 0, ""),
671
 
  Commands( "EXISTS", 0, 0, 0, ""),
672
 
  Commands( "EXIT", 0, 0, 0, ""),
673
 
  Commands( "EXPLAIN", 0, 0, 0, ""),
674
 
  Commands( "EXTENDED", 0, 0, 0, ""),
675
 
  Commands( "FALSE", 0, 0, 0, ""),
676
 
  Commands( "FAST", 0, 0, 0, ""),
677
 
  Commands( "FETCH", 0, 0, 0, ""),
678
 
  Commands( "FIELDS", 0, 0, 0, ""),
679
 
  Commands( "FILE", 0, 0, 0, ""),
680
 
  Commands( "FIRST", 0, 0, 0, ""),
681
 
  Commands( "FIXED", 0, 0, 0, ""),
682
 
  Commands( "FLOAT", 0, 0, 0, ""),
683
 
  Commands( "FLOAT4", 0, 0, 0, ""),
684
 
  Commands( "FLOAT8", 0, 0, 0, ""),
685
 
  Commands( "FLUSH", 0, 0, 0, ""),
686
 
  Commands( "FOR", 0, 0, 0, ""),
687
 
  Commands( "FORCE", 0, 0, 0, ""),
688
 
  Commands( "FOREIGN", 0, 0, 0, ""),
689
 
  Commands( "FOUND", 0, 0, 0, ""),
690
 
  Commands( "FRAC_SECOND", 0, 0, 0, ""),
691
 
  Commands( "FROM", 0, 0, 0, ""),
692
 
  Commands( "FULL", 0, 0, 0, ""),
693
 
  Commands( "FUNCTION", 0, 0, 0, ""),
694
 
  Commands( "GLOBAL", 0, 0, 0, ""),
695
 
  Commands( "GRANT", 0, 0, 0, ""),
696
 
  Commands( "GRANTS", 0, 0, 0, ""),
697
 
  Commands( "GROUP", 0, 0, 0, ""),
698
 
  Commands( "HANDLER", 0, 0, 0, ""),
699
 
  Commands( "HASH", 0, 0, 0, ""),
700
 
  Commands( "HAVING", 0, 0, 0, ""),
701
 
  Commands( "HELP", 0, 0, 0, ""),
702
 
  Commands( "HIGH_PRIORITY", 0, 0, 0, ""),
703
 
  Commands( "HOSTS", 0, 0, 0, ""),
704
 
  Commands( "HOUR", 0, 0, 0, ""),
705
 
  Commands( "HOUR_MICROSECOND", 0, 0, 0, ""),
706
 
  Commands( "HOUR_MINUTE", 0, 0, 0, ""),
707
 
  Commands( "HOUR_SECOND", 0, 0, 0, ""),
708
 
  Commands( "IDENTIFIED", 0, 0, 0, ""),
709
 
  Commands( "IF", 0, 0, 0, ""),
710
 
  Commands( "IGNORE", 0, 0, 0, ""),
711
 
  Commands( "IMPORT", 0, 0, 0, ""),
712
 
  Commands( "IN", 0, 0, 0, ""),
713
 
  Commands( "INDEX", 0, 0, 0, ""),
714
 
  Commands( "INDEXES", 0, 0, 0, ""),
715
 
  Commands( "INFILE", 0, 0, 0, ""),
716
 
  Commands( "INNER", 0, 0, 0, ""),
717
 
  Commands( "INNOBASE", 0, 0, 0, ""),
718
 
  Commands( "INNODB", 0, 0, 0, ""),
719
 
  Commands( "INOUT", 0, 0, 0, ""),
720
 
  Commands( "INSENSITIVE", 0, 0, 0, ""),
721
 
  Commands( "INSERT", 0, 0, 0, ""),
722
 
  Commands( "INSERT_METHOD", 0, 0, 0, ""),
723
 
  Commands( "INT", 0, 0, 0, ""),
724
 
  Commands( "INT1", 0, 0, 0, ""),
725
 
  Commands( "INT2", 0, 0, 0, ""),
726
 
  Commands( "INT3", 0, 0, 0, ""),
727
 
  Commands( "INT4", 0, 0, 0, ""),
728
 
  Commands( "INT8", 0, 0, 0, ""),
729
 
  Commands( "INTEGER", 0, 0, 0, ""),
730
 
  Commands( "INTERVAL", 0, 0, 0, ""),
731
 
  Commands( "INTO", 0, 0, 0, ""),
732
 
  Commands( "IO_THREAD", 0, 0, 0, ""),
733
 
  Commands( "IS", 0, 0, 0, ""),
734
 
  Commands( "ISOLATION", 0, 0, 0, ""),
735
 
  Commands( "ISSUER", 0, 0, 0, ""),
736
 
  Commands( "ITERATE", 0, 0, 0, ""),
737
 
  Commands( "INVOKER", 0, 0, 0, ""),
738
 
  Commands( "JOIN", 0, 0, 0, ""),
739
 
  Commands( "KEY", 0, 0, 0, ""),
740
 
  Commands( "KEYS", 0, 0, 0, ""),
741
 
  Commands( "KILL", 0, 0, 0, ""),
742
 
  Commands( "LANGUAGE", 0, 0, 0, ""),
743
 
  Commands( "LAST", 0, 0, 0, ""),
744
 
  Commands( "LEADING", 0, 0, 0, ""),
745
 
  Commands( "LEAVE", 0, 0, 0, ""),
746
 
  Commands( "LEAVES", 0, 0, 0, ""),
747
 
  Commands( "LEFT", 0, 0, 0, ""),
748
 
  Commands( "LEVEL", 0, 0, 0, ""),
749
 
  Commands( "LIKE", 0, 0, 0, ""),
750
 
  Commands( "LIMIT", 0, 0, 0, ""),
751
 
  Commands( "LINES", 0, 0, 0, ""),
752
 
  Commands( "LINESTRING", 0, 0, 0, ""),
753
 
  Commands( "LOAD", 0, 0, 0, ""),
754
 
  Commands( "LOCAL", 0, 0, 0, ""),
755
 
  Commands( "LOCALTIMESTAMP", 0, 0, 0, ""),
756
 
  Commands( "LOCK", 0, 0, 0, ""),
757
 
  Commands( "LOCKS", 0, 0, 0, ""),
758
 
  Commands( "LOGS", 0, 0, 0, ""),
759
 
  Commands( "LONG", 0, 0, 0, ""),
760
 
  Commands( "LOOP", 0, 0, 0, ""),
761
 
  Commands( "MATCH", 0, 0, 0, ""),
762
 
  Commands( "MAX_CONNECTIONS_PER_HOUR", 0, 0, 0, ""),
763
 
  Commands( "MAX_QUERIES_PER_HOUR", 0, 0, 0, ""),
764
 
  Commands( "MAX_ROWS", 0, 0, 0, ""),
765
 
  Commands( "MAX_UPDATES_PER_HOUR", 0, 0, 0, ""),
766
 
  Commands( "MAX_USER_CONNECTIONS", 0, 0, 0, ""),
767
 
  Commands( "MEDIUM", 0, 0, 0, ""),
768
 
  Commands( "MERGE", 0, 0, 0, ""),
769
 
  Commands( "MICROSECOND", 0, 0, 0, ""),
770
 
  Commands( "MIGRATE", 0, 0, 0, ""),
771
 
  Commands( "MINUTE", 0, 0, 0, ""),
772
 
  Commands( "MINUTE_MICROSECOND", 0, 0, 0, ""),
773
 
  Commands( "MINUTE_SECOND", 0, 0, 0, ""),
774
 
  Commands( "MIN_ROWS", 0, 0, 0, ""),
775
 
  Commands( "MOD", 0, 0, 0, ""),
776
 
  Commands( "MODE", 0, 0, 0, ""),
777
 
  Commands( "MODIFIES", 0, 0, 0, ""),
778
 
  Commands( "MODIFY", 0, 0, 0, ""),
779
 
  Commands( "MONTH", 0, 0, 0, ""),
780
 
  Commands( "MULTILINESTRING", 0, 0, 0, ""),
781
 
  Commands( "MULTIPOINT", 0, 0, 0, ""),
782
 
  Commands( "MULTIPOLYGON", 0, 0, 0, ""),
783
 
  Commands( "MUTEX", 0, 0, 0, ""),
784
 
  Commands( "NAME", 0, 0, 0, ""),
785
 
  Commands( "NAMES", 0, 0, 0, ""),
786
 
  Commands( "NATIONAL", 0, 0, 0, ""),
787
 
  Commands( "NATURAL", 0, 0, 0, ""),
788
 
  Commands( "NCHAR", 0, 0, 0, ""),
789
 
  Commands( "NEW", 0, 0, 0, ""),
790
 
  Commands( "NEXT", 0, 0, 0, ""),
791
 
  Commands( "NO", 0, 0, 0, ""),
792
 
  Commands( "NONE", 0, 0, 0, ""),
793
 
  Commands( "NOT", 0, 0, 0, ""),
794
 
  Commands( "NULL", 0, 0, 0, ""),
795
 
  Commands( "NUMERIC", 0, 0, 0, ""),
796
 
  Commands( "NVARCHAR", 0, 0, 0, ""),
797
 
  Commands( "OFFSET", 0, 0, 0, ""),
798
 
  Commands( "ON", 0, 0, 0, ""),
799
 
  Commands( "ONE", 0, 0, 0, ""),
800
 
  Commands( "ONE_SHOT", 0, 0, 0, ""),
801
 
  Commands( "OPEN", 0, 0, 0, ""),
802
 
  Commands( "OPTIMIZE", 0, 0, 0, ""),
803
 
  Commands( "OPTION", 0, 0, 0, ""),
804
 
  Commands( "OPTIONALLY", 0, 0, 0, ""),
805
 
  Commands( "OR", 0, 0, 0, ""),
806
 
  Commands( "ORDER", 0, 0, 0, ""),
807
 
  Commands( "OUT", 0, 0, 0, ""),
808
 
  Commands( "OUTER", 0, 0, 0, ""),
809
 
  Commands( "OUTFILE", 0, 0, 0, ""),
810
 
  Commands( "PACK_KEYS", 0, 0, 0, ""),
811
 
  Commands( "PARTIAL", 0, 0, 0, ""),
812
 
  Commands( "PASSWORD", 0, 0, 0, ""),
813
 
  Commands( "PHASE", 0, 0, 0, ""),
814
 
  Commands( "PRECISION", 0, 0, 0, ""),
815
 
  Commands( "PREPARE", 0, 0, 0, ""),
816
 
  Commands( "PREV", 0, 0, 0, ""),
817
 
  Commands( "PRIMARY", 0, 0, 0, ""),
818
 
  Commands( "PRIVILEGES", 0, 0, 0, ""),
819
 
  Commands( "PROCEDURE", 0, 0, 0, ""),
820
 
  Commands( "PROCESS", 0, 0, 0, ""),
821
 
  Commands( "PROCESSLIST", 0, 0, 0, ""),
822
 
  Commands( "PURGE", 0, 0, 0, ""),
823
 
  Commands( "QUARTER", 0, 0, 0, ""),
824
 
  Commands( "QUERY", 0, 0, 0, ""),
825
 
  Commands( "QUICK", 0, 0, 0, ""),
826
 
  Commands( "READ", 0, 0, 0, ""),
827
 
  Commands( "READS", 0, 0, 0, ""),
828
 
  Commands( "REAL", 0, 0, 0, ""),
829
 
  Commands( "RECOVER", 0, 0, 0, ""),
830
 
  Commands( "REDUNDANT", 0, 0, 0, ""),
831
 
  Commands( "REFERENCES", 0, 0, 0, ""),
832
 
  Commands( "REGEXP", 0, 0, 0, ""),
833
 
  Commands( "RELEASE", 0, 0, 0, ""),
834
 
  Commands( "RELOAD", 0, 0, 0, ""),
835
 
  Commands( "RENAME", 0, 0, 0, ""),
836
 
  Commands( "REPAIR", 0, 0, 0, ""),
837
 
  Commands( "REPEATABLE", 0, 0, 0, ""),
838
 
  Commands( "REPLACE", 0, 0, 0, ""),
839
 
  Commands( "REPEAT", 0, 0, 0, ""),
840
 
  Commands( "REQUIRE", 0, 0, 0, ""),
841
 
  Commands( "RESET", 0, 0, 0, ""),
842
 
  Commands( "RESTORE", 0, 0, 0, ""),
843
 
  Commands( "RESTRICT", 0, 0, 0, ""),
844
 
  Commands( "RESUME", 0, 0, 0, ""),
845
 
  Commands( "RETURN", 0, 0, 0, ""),
846
 
  Commands( "RETURNS", 0, 0, 0, ""),
847
 
  Commands( "REVOKE", 0, 0, 0, ""),
848
 
  Commands( "RIGHT", 0, 0, 0, ""),
849
 
  Commands( "RLIKE", 0, 0, 0, ""),
850
 
  Commands( "ROLLBACK", 0, 0, 0, ""),
851
 
  Commands( "ROLLUP", 0, 0, 0, ""),
852
 
  Commands( "ROUTINE", 0, 0, 0, ""),
853
 
  Commands( "ROW", 0, 0, 0, ""),
854
 
  Commands( "ROWS", 0, 0, 0, ""),
855
 
  Commands( "ROW_FORMAT", 0, 0, 0, ""),
856
 
  Commands( "RTREE", 0, 0, 0, ""),
857
 
  Commands( "SAVEPOINT", 0, 0, 0, ""),
858
 
  Commands( "SCHEMA", 0, 0, 0, ""),
859
 
  Commands( "SCHEMAS", 0, 0, 0, ""),
860
 
  Commands( "SECOND", 0, 0, 0, ""),
861
 
  Commands( "SECOND_MICROSECOND", 0, 0, 0, ""),
862
 
  Commands( "SECURITY", 0, 0, 0, ""),
863
 
  Commands( "SELECT", 0, 0, 0, ""),
864
 
  Commands( "SENSITIVE", 0, 0, 0, ""),
865
 
  Commands( "SEPARATOR", 0, 0, 0, ""),
866
 
  Commands( "SERIAL", 0, 0, 0, ""),
867
 
  Commands( "SERIALIZABLE", 0, 0, 0, ""),
868
 
  Commands( "SESSION", 0, 0, 0, ""),
869
 
  Commands( "SET", 0, 0, 0, ""),
870
 
  Commands( "SHARE", 0, 0, 0, ""),
871
 
  Commands( "SHOW", 0, 0, 0, ""),
872
 
  Commands( "SHUTDOWN", 0, 0, 0, ""),
873
 
  Commands( "SIGNED", 0, 0, 0, ""),
874
 
  Commands( "SIMPLE", 0, 0, 0, ""),
875
 
  Commands( "SLAVE", 0, 0, 0, ""),
876
 
  Commands( "SNAPSHOT", 0, 0, 0, ""),
877
 
  Commands( "SOME", 0, 0, 0, ""),
878
 
  Commands( "SONAME", 0, 0, 0, ""),
879
 
  Commands( "SOUNDS", 0, 0, 0, ""),
880
 
  Commands( "SPATIAL", 0, 0, 0, ""),
881
 
  Commands( "SPECIFIC", 0, 0, 0, ""),
882
 
  Commands( "SQL", 0, 0, 0, ""),
883
 
  Commands( "SQLEXCEPTION", 0, 0, 0, ""),
884
 
  Commands( "SQLSTATE", 0, 0, 0, ""),
885
 
  Commands( "SQLWARNING", 0, 0, 0, ""),
886
 
  Commands( "SQL_BIG_RESULT", 0, 0, 0, ""),
887
 
  Commands( "SQL_BUFFER_RESULT", 0, 0, 0, ""),
888
 
  Commands( "SQL_CACHE", 0, 0, 0, ""),
889
 
  Commands( "SQL_CALC_FOUND_ROWS", 0, 0, 0, ""),
890
 
  Commands( "SQL_NO_CACHE", 0, 0, 0, ""),
891
 
  Commands( "SQL_SMALL_RESULT", 0, 0, 0, ""),
892
 
  Commands( "SQL_THREAD", 0, 0, 0, ""),
893
 
  Commands( "SQL_TSI_FRAC_SECOND", 0, 0, 0, ""),
894
 
  Commands( "SQL_TSI_SECOND", 0, 0, 0, ""),
895
 
  Commands( "SQL_TSI_MINUTE", 0, 0, 0, ""),
896
 
  Commands( "SQL_TSI_HOUR", 0, 0, 0, ""),
897
 
  Commands( "SQL_TSI_DAY", 0, 0, 0, ""),
898
 
  Commands( "SQL_TSI_WEEK", 0, 0, 0, ""),
899
 
  Commands( "SQL_TSI_MONTH", 0, 0, 0, ""),
900
 
  Commands( "SQL_TSI_QUARTER", 0, 0, 0, ""),
901
 
  Commands( "SQL_TSI_YEAR", 0, 0, 0, ""),
902
 
  Commands( "SSL", 0, 0, 0, ""),
903
 
  Commands( "START", 0, 0, 0, ""),
904
 
  Commands( "STARTING", 0, 0, 0, ""),
905
 
  Commands( "STATUS", 0, 0, 0, ""),
906
 
  Commands( "STOP", 0, 0, 0, ""),
907
 
  Commands( "STORAGE", 0, 0, 0, ""),
908
 
  Commands( "STRAIGHT_JOIN", 0, 0, 0, ""),
909
 
  Commands( "STRING", 0, 0, 0, ""),
910
 
  Commands( "STRIPED", 0, 0, 0, ""),
911
 
  Commands( "SUBJECT", 0, 0, 0, ""),
912
 
  Commands( "SUPER", 0, 0, 0, ""),
913
 
  Commands( "SUSPEND", 0, 0, 0, ""),
914
 
  Commands( "TABLE", 0, 0, 0, ""),
915
 
  Commands( "TABLES", 0, 0, 0, ""),
916
 
  Commands( "TABLESPACE", 0, 0, 0, ""),
917
 
  Commands( "TEMPORARY", 0, 0, 0, ""),
918
 
  Commands( "TEMPTABLE", 0, 0, 0, ""),
919
 
  Commands( "TERMINATED", 0, 0, 0, ""),
920
 
  Commands( "TEXT", 0, 0, 0, ""),
921
 
  Commands( "THEN", 0, 0, 0, ""),
922
 
  Commands( "TIMESTAMP", 0, 0, 0, ""),
923
 
  Commands( "TIMESTAMPADD", 0, 0, 0, ""),
924
 
  Commands( "TIMESTAMPDIFF", 0, 0, 0, ""),
925
 
  Commands( "TO", 0, 0, 0, ""),
926
 
  Commands( "TRAILING", 0, 0, 0, ""),
927
 
  Commands( "TRANSACTION", 0, 0, 0, ""),
928
 
  Commands( "TRUE", 0, 0, 0, ""),
929
 
  Commands( "TRUNCATE", 0, 0, 0, ""),
930
 
  Commands( "TYPE", 0, 0, 0, ""),
931
 
  Commands( "TYPES", 0, 0, 0, ""),
932
 
  Commands( "UNCOMMITTED", 0, 0, 0, ""),
933
 
  Commands( "UNDEFINED", 0, 0, 0, ""),
934
 
  Commands( "UNDO", 0, 0, 0, ""),
935
 
  Commands( "UNICODE", 0, 0, 0, ""),
936
 
  Commands( "UNION", 0, 0, 0, ""),
937
 
  Commands( "UNIQUE", 0, 0, 0, ""),
938
 
  Commands( "UNKNOWN", 0, 0, 0, ""),
939
 
  Commands( "UNLOCK", 0, 0, 0, ""),
940
 
  Commands( "UNTIL", 0, 0, 0, ""),
941
 
  Commands( "UPDATE", 0, 0, 0, ""),
942
 
  Commands( "UPGRADE", 0, 0, 0, ""),
943
 
  Commands( "USAGE", 0, 0, 0, ""),
944
 
  Commands( "USE", 0, 0, 0, ""),
945
 
  Commands( "USER", 0, 0, 0, ""),
946
 
  Commands( "USER_RESOURCES", 0, 0, 0, ""),
947
 
  Commands( "USING", 0, 0, 0, ""),
948
 
  Commands( "UTC_DATE", 0, 0, 0, ""),
949
 
  Commands( "UTC_TIMESTAMP", 0, 0, 0, ""),
950
 
  Commands( "VALUE", 0, 0, 0, ""),
951
 
  Commands( "VALUES", 0, 0, 0, ""),
952
 
  Commands( "VARBINARY", 0, 0, 0, ""),
953
 
  Commands( "VARCHAR", 0, 0, 0, ""),
954
 
  Commands( "VARCHARACTER", 0, 0, 0, ""),
955
 
  Commands( "VARIABLES", 0, 0, 0, ""),
956
 
  Commands( "VARYING", 0, 0, 0, ""),
957
 
  Commands( "WARNINGS", 0, 0, 0, ""),
958
 
  Commands( "WEEK", 0, 0, 0, ""),
959
 
  Commands( "WHEN", 0, 0, 0, ""),
960
 
  Commands( "WHERE", 0, 0, 0, ""),
961
 
  Commands( "WHILE", 0, 0, 0, ""),
962
 
  Commands( "VIEW", 0, 0, 0, ""),
963
 
  Commands( "WITH", 0, 0, 0, ""),
964
 
  Commands( "WORK", 0, 0, 0, ""),
965
 
  Commands( "WRITE", 0, 0, 0, ""),
966
 
  Commands( "XOR", 0, 0, 0, ""),
967
 
  Commands( "XA", 0, 0, 0, ""),
968
 
  Commands( "YEAR", 0, 0, 0, ""),
969
 
  Commands( "YEAR_MONTH", 0, 0, 0, ""),
970
 
  Commands( "ZEROFILL", 0, 0, 0, ""),
971
 
  Commands( "ABS", 0, 0, 0, ""),
972
 
  Commands( "ACOS", 0, 0, 0, ""),
973
 
  Commands( "ADDDATE", 0, 0, 0, ""),
974
 
  Commands( "AREA", 0, 0, 0, ""),
975
 
  Commands( "ASIN", 0, 0, 0, ""),
976
 
  Commands( "ASBINARY", 0, 0, 0, ""),
977
 
  Commands( "ASTEXT", 0, 0, 0, ""),
978
 
  Commands( "ATAN", 0, 0, 0, ""),
979
 
  Commands( "ATAN2", 0, 0, 0, ""),
980
 
  Commands( "BENCHMARK", 0, 0, 0, ""),
981
 
  Commands( "BIN", 0, 0, 0, ""),
982
 
  Commands( "BIT_OR", 0, 0, 0, ""),
983
 
  Commands( "BIT_AND", 0, 0, 0, ""),
984
 
  Commands( "BIT_XOR", 0, 0, 0, ""),
985
 
  Commands( "CAST", 0, 0, 0, ""),
986
 
  Commands( "CEIL", 0, 0, 0, ""),
987
 
  Commands( "CEILING", 0, 0, 0, ""),
988
 
  Commands( "CENTROID", 0, 0, 0, ""),
989
 
  Commands( "CHAR_LENGTH", 0, 0, 0, ""),
990
 
  Commands( "CHARACTER_LENGTH", 0, 0, 0, ""),
991
 
  Commands( "COALESCE", 0, 0, 0, ""),
992
 
  Commands( "COERCIBILITY", 0, 0, 0, ""),
993
 
  Commands( "COMPRESS", 0, 0, 0, ""),
994
 
  Commands( "CONCAT", 0, 0, 0, ""),
995
 
  Commands( "CONCAT_WS", 0, 0, 0, ""),
996
 
  Commands( "CONNECTION_ID", 0, 0, 0, ""),
997
 
  Commands( "CONV", 0, 0, 0, ""),
998
 
  Commands( "CONVERT_TZ", 0, 0, 0, ""),
999
 
  Commands( "COUNT", 0, 0, 0, ""),
1000
 
  Commands( "COS", 0, 0, 0, ""),
1001
 
  Commands( "COT", 0, 0, 0, ""),
1002
 
  Commands( "CRC32", 0, 0, 0, ""),
1003
 
  Commands( "CROSSES", 0, 0, 0, ""),
1004
 
  Commands( "CURDATE", 0, 0, 0, ""),
1005
 
  Commands( "DATE_ADD", 0, 0, 0, ""),
1006
 
  Commands( "DATEDIFF", 0, 0, 0, ""),
1007
 
  Commands( "DATE_FORMAT", 0, 0, 0, ""),
1008
 
  Commands( "DATE_SUB", 0, 0, 0, ""),
1009
 
  Commands( "DAYNAME", 0, 0, 0, ""),
1010
 
  Commands( "DAYOFMONTH", 0, 0, 0, ""),
1011
 
  Commands( "DAYOFWEEK", 0, 0, 0, ""),
1012
 
  Commands( "DAYOFYEAR", 0, 0, 0, ""),
1013
 
  Commands( "DECODE", 0, 0, 0, ""),
1014
 
  Commands( "DEGREES", 0, 0, 0, ""),
1015
 
  Commands( "DES_ENCRYPT", 0, 0, 0, ""),
1016
 
  Commands( "DES_DECRYPT", 0, 0, 0, ""),
1017
 
  Commands( "DIMENSION", 0, 0, 0, ""),
1018
 
  Commands( "DISJOINT", 0, 0, 0, ""),
1019
 
  Commands( "ELT", 0, 0, 0, ""),
1020
 
  Commands( "ENCODE", 0, 0, 0, ""),
1021
 
  Commands( "ENCRYPT", 0, 0, 0, ""),
1022
 
  Commands( "ENDPOINT", 0, 0, 0, ""),
1023
 
  Commands( "ENVELOPE", 0, 0, 0, ""),
1024
 
  Commands( "EQUALS", 0, 0, 0, ""),
1025
 
  Commands( "EXTERIORRING", 0, 0, 0, ""),
1026
 
  Commands( "EXTRACT", 0, 0, 0, ""),
1027
 
  Commands( "EXP", 0, 0, 0, ""),
1028
 
  Commands( "EXPORT_SET", 0, 0, 0, ""),
1029
 
  Commands( "FIELD", 0, 0, 0, ""),
1030
 
  Commands( "FIND_IN_SET", 0, 0, 0, ""),
1031
 
  Commands( "FLOOR", 0, 0, 0, ""),
1032
 
  Commands( "FORMAT", 0, 0, 0, ""),
1033
 
  Commands( "FOUND_ROWS", 0, 0, 0, ""),
1034
 
  Commands( "FROM_DAYS", 0, 0, 0, ""),
1035
 
  Commands( "FROM_UNIXTIME", 0, 0, 0, ""),
1036
 
  Commands( "GET_LOCK", 0, 0, 0, ""),
1037
 
  Commands( "GLENGTH", 0, 0, 0, ""),
1038
 
  Commands( "GREATEST", 0, 0, 0, ""),
1039
 
  Commands( "GROUP_CONCAT", 0, 0, 0, ""),
1040
 
  Commands( "GROUP_UNIQUE_USERS", 0, 0, 0, ""),
1041
 
  Commands( "HEX", 0, 0, 0, ""),
1042
 
  Commands( "IFNULL", 0, 0, 0, ""),
1043
 
  Commands( "INSTR", 0, 0, 0, ""),
1044
 
  Commands( "INTERIORRINGN", 0, 0, 0, ""),
1045
 
  Commands( "INTERSECTS", 0, 0, 0, ""),
1046
 
  Commands( "ISCLOSED", 0, 0, 0, ""),
1047
 
  Commands( "ISEMPTY", 0, 0, 0, ""),
1048
 
  Commands( "ISNULL", 0, 0, 0, ""),
1049
 
  Commands( "IS_FREE_LOCK", 0, 0, 0, ""),
1050
 
  Commands( "IS_USED_LOCK", 0, 0, 0, ""),
1051
 
  Commands( "LAST_INSERT_ID", 0, 0, 0, ""),
1052
 
  Commands( "ISSIMPLE", 0, 0, 0, ""),
1053
 
  Commands( "LAST_DAY", 0, 0, 0, ""),
1054
 
  Commands( "LCASE", 0, 0, 0, ""),
1055
 
  Commands( "LEAST", 0, 0, 0, ""),
1056
 
  Commands( "LENGTH", 0, 0, 0, ""),
1057
 
  Commands( "LN", 0, 0, 0, ""),
1058
 
  Commands( "LOAD_FILE", 0, 0, 0, ""),
1059
 
  Commands( "LOCATE", 0, 0, 0, ""),
1060
 
  Commands( "LOG", 0, 0, 0, ""),
1061
 
  Commands( "LOG2", 0, 0, 0, ""),
1062
 
  Commands( "LOG10", 0, 0, 0, ""),
1063
 
  Commands( "LOWER", 0, 0, 0, ""),
1064
 
  Commands( "LPAD", 0, 0, 0, ""),
1065
 
  Commands( "LTRIM", 0, 0, 0, ""),
1066
 
  Commands( "MAKE_SET", 0, 0, 0, ""),
1067
 
  Commands( "MAKEDATE", 0, 0, 0, ""),
1068
 
  Commands( "MASTER_POS_WAIT", 0, 0, 0, ""),
1069
 
  Commands( "MAX", 0, 0, 0, ""),
1070
 
  Commands( "MBRCONTAINS", 0, 0, 0, ""),
1071
 
  Commands( "MBRDISJOINT", 0, 0, 0, ""),
1072
 
  Commands( "MBREQUAL", 0, 0, 0, ""),
1073
 
  Commands( "MBRINTERSECTS", 0, 0, 0, ""),
1074
 
  Commands( "MBROVERLAPS", 0, 0, 0, ""),
1075
 
  Commands( "MBRTOUCHES", 0, 0, 0, ""),
1076
 
  Commands( "MBRWITHIN", 0, 0, 0, ""),
1077
 
  Commands( "MD5", 0, 0, 0, ""),
1078
 
  Commands( "MID", 0, 0, 0, ""),
1079
 
  Commands( "MIN", 0, 0, 0, ""),
1080
 
  Commands( "MONTHNAME", 0, 0, 0, ""),
1081
 
  Commands( "NAME_CONST", 0, 0, 0, ""),
1082
 
  Commands( "NOW", 0, 0, 0, ""),
1083
 
  Commands( "NULLIF", 0, 0, 0, ""),
1084
 
  Commands( "NUMPOINTS", 0, 0, 0, ""),
1085
 
  Commands( "OCTET_LENGTH", 0, 0, 0, ""),
1086
 
  Commands( "OCT", 0, 0, 0, ""),
1087
 
  Commands( "ORD", 0, 0, 0, ""),
1088
 
  Commands( "OVERLAPS", 0, 0, 0, ""),
1089
 
  Commands( "PERIOD_ADD", 0, 0, 0, ""),
1090
 
  Commands( "PERIOD_DIFF", 0, 0, 0, ""),
1091
 
  Commands( "PI", 0, 0, 0, ""),
1092
 
  Commands( "POINTN", 0, 0, 0, ""),
1093
 
  Commands( "POSITION", 0, 0, 0, ""),
1094
 
  Commands( "POW", 0, 0, 0, ""),
1095
 
  Commands( "POWER", 0, 0, 0, ""),
1096
 
  Commands( "QUOTE", 0, 0, 0, ""),
1097
 
  Commands( "RADIANS", 0, 0, 0, ""),
1098
 
  Commands( "RAND", 0, 0, 0, ""),
1099
 
  Commands( "RELEASE_LOCK", 0, 0, 0, ""),
1100
 
  Commands( "REVERSE", 0, 0, 0, ""),
1101
 
  Commands( "ROUND", 0, 0, 0, ""),
1102
 
  Commands( "ROW_COUNT", 0, 0, 0, ""),
1103
 
  Commands( "RPAD", 0, 0, 0, ""),
1104
 
  Commands( "RTRIM", 0, 0, 0, ""),
1105
 
  Commands( "SESSION_USER", 0, 0, 0, ""),
1106
 
  Commands( "SUBDATE", 0, 0, 0, ""),
1107
 
  Commands( "SIGN", 0, 0, 0, ""),
1108
 
  Commands( "SIN", 0, 0, 0, ""),
1109
 
  Commands( "SHA", 0, 0, 0, ""),
1110
 
  Commands( "SHA1", 0, 0, 0, ""),
1111
 
  Commands( "SLEEP", 0, 0, 0, ""),
1112
 
  Commands( "SOUNDEX", 0, 0, 0, ""),
1113
 
  Commands( "SPACE", 0, 0, 0, ""),
1114
 
  Commands( "SQRT", 0, 0, 0, ""),
1115
 
  Commands( "SRID", 0, 0, 0, ""),
1116
 
  Commands( "STARTPOINT", 0, 0, 0, ""),
1117
 
  Commands( "STD", 0, 0, 0, ""),
1118
 
  Commands( "STDDEV", 0, 0, 0, ""),
1119
 
  Commands( "STDDEV_POP", 0, 0, 0, ""),
1120
 
  Commands( "STDDEV_SAMP", 0, 0, 0, ""),
1121
 
  Commands( "STR_TO_DATE", 0, 0, 0, ""),
1122
 
  Commands( "STRCMP", 0, 0, 0, ""),
1123
 
  Commands( "SUBSTR", 0, 0, 0, ""),
1124
 
  Commands( "SUBSTRING", 0, 0, 0, ""),
1125
 
  Commands( "SUBSTRING_INDEX", 0, 0, 0, ""),
1126
 
  Commands( "SUM", 0, 0, 0, ""),
1127
 
  Commands( "SYSDATE", 0, 0, 0, ""),
1128
 
  Commands( "SYSTEM_USER", 0, 0, 0, ""),
1129
 
  Commands( "TAN", 0, 0, 0, ""),
1130
 
  Commands( "TIME_FORMAT", 0, 0, 0, ""),
1131
 
  Commands( "TO_DAYS", 0, 0, 0, ""),
1132
 
  Commands( "TOUCHES", 0, 0, 0, ""),
1133
 
  Commands( "TRIM", 0, 0, 0, ""),
1134
 
  Commands( "UCASE", 0, 0, 0, ""),
1135
 
  Commands( "UNCOMPRESS", 0, 0, 0, ""),
1136
 
  Commands( "UNCOMPRESSED_LENGTH", 0, 0, 0, ""),
1137
 
  Commands( "UNHEX", 0, 0, 0, ""),
1138
 
  Commands( "UNIQUE_USERS", 0, 0, 0, ""),
1139
 
  Commands( "UNIX_TIMESTAMP", 0, 0, 0, ""),
1140
 
  Commands( "UPPER", 0, 0, 0, ""),
1141
 
  Commands( "UUID", 0, 0, 0, ""),
1142
 
  Commands( "VARIANCE", 0, 0, 0, ""),
1143
 
  Commands( "VAR_POP", 0, 0, 0, ""),
1144
 
  Commands( "VAR_SAMP", 0, 0, 0, ""),
1145
 
  Commands( "VERSION", 0, 0, 0, ""),
1146
 
  Commands( "WEEKDAY", 0, 0, 0, ""),
1147
 
  Commands( "WEEKOFYEAR", 0, 0, 0, ""),
1148
 
  Commands( "WITHIN", 0, 0, 0, ""),
1149
 
  Commands( "X", 0, 0, 0, ""),
1150
 
  Commands( "Y", 0, 0, 0, ""),
1151
 
  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, ""},
1152
991
  /* end sentinel */
1153
 
  Commands((char *)NULL,       0, 0, 0, "")
 
992
  { (char *)NULL,       0, 0, 0, ""}
1154
993
};
1155
994
 
 
995
static const char *load_default_groups[]= { "drizzle","client",0 };
1156
996
 
1157
997
int history_length;
1158
998
static int not_in_history(const char *line);
1159
999
static void initialize_readline (char *name);
1160
1000
static void fix_history(string *final_command);
1161
1001
 
1162
 
static Commands *find_command(const char *name,char cmd_name);
 
1002
static COMMANDS *find_command(const char *name,char cmd_name);
1163
1003
static bool add_line(string *buffer,char *line,char *in_string,
1164
1004
                     bool *ml_comment);
1165
1005
static void remove_cntrl(string *buffer);
1167
1007
static void print_tab_data(drizzle_result_st *result);
1168
1008
static void print_table_data_vertically(drizzle_result_st *result);
1169
1009
static void print_warnings(uint32_t error_code);
1170
 
static boost::posix_time::ptime start_timer(void);
1171
 
static void end_timer(boost::posix_time::ptime, string &buff);
1172
 
static void drizzle_end_timer(boost::posix_time::ptime, string &buff);
1173
 
static void nice_time(boost::posix_time::time_duration duration, string &buff);
 
1010
static uint32_t start_timer(void);
 
1011
static void end_timer(uint32_t start_time,char *buff);
 
1012
static void drizzle_end_timer(uint32_t start_time,char *buff);
 
1013
static void nice_time(double sec,char *buff,bool part_second);
1174
1014
extern "C" void drizzle_end(int sig);
1175
1015
extern "C" void handle_sigint(int sig);
1176
1016
#if defined(HAVE_TERMIOS_H) && defined(GWINSZ_IN_SYS_IOCTL)
1177
1017
static void window_resize(int sig);
1178
1018
#endif
1179
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
 
1180
1027
/**
1181
1028
  Shutdown the server that we are currently connected to.
1182
1029
 
1192
1039
 
1193
1040
  if (verbose)
1194
1041
  {
1195
 
    printf(_("shutting down drizzled"));
 
1042
    printf("shutting down drizzled");
1196
1043
    if (opt_drizzle_port > 0)
1197
 
      printf(_(" on port %d"), opt_drizzle_port);
 
1044
      printf(" on port %d", opt_drizzle_port);
1198
1045
    printf("... ");
1199
1046
  }
1200
1047
 
1203
1050
  {
1204
1051
    if (ret == DRIZZLE_RETURN_ERROR_CODE)
1205
1052
    {
1206
 
      fprintf(stderr, _("shutdown failed; error: '%s'"),
 
1053
      fprintf(stderr, "shutdown failed; error: '%s'",
1207
1054
              drizzle_result_error(&result));
1208
1055
      drizzle_result_free(&result);
1209
1056
    }
1210
1057
    else
1211
1058
    {
1212
 
      fprintf(stderr, _("shutdown failed; error: '%s'"),
 
1059
      fprintf(stderr, "shutdown failed; error: '%s'",
1213
1060
              drizzle_con_error(&con));
1214
1061
    }
1215
1062
    return false;
1218
1065
  drizzle_result_free(&result);
1219
1066
 
1220
1067
  if (verbose)
1221
 
    printf(_("done\n"));
 
1068
    printf("done\n");
1222
1069
 
1223
1070
  return true;
1224
1071
}
1239
1086
  if (drizzle_ping(&con, &result, &ret) != NULL && ret == DRIZZLE_RETURN_OK)
1240
1087
  {
1241
1088
    if (opt_silent < 2)
1242
 
      printf(_("drizzled is alive\n"));
 
1089
      printf("drizzled is alive\n");
1243
1090
  }
1244
1091
  else
1245
1092
  {
1246
1093
    if (ret == DRIZZLE_RETURN_ERROR_CODE)
1247
1094
    {
1248
 
      fprintf(stderr, _("ping failed; error: '%s'"),
 
1095
      fprintf(stderr, "ping failed; error: '%s'",
1249
1096
              drizzle_result_error(&result));
1250
1097
      drizzle_result_free(&result);
1251
1098
    }
1252
1099
    else
1253
1100
    {
1254
 
      fprintf(stderr, _("drizzled won't answer to ping, error: '%s'"),
 
1101
      fprintf(stderr, "drizzled won't answer to ping, error: '%s'",
1255
1102
              drizzle_con_error(&con));
1256
1103
    }
1257
1104
    return false;
1295
1142
  return executed;
1296
1143
}
1297
1144
 
1298
 
static void check_timeout_value(uint32_t in_connect_timeout)
1299
 
{
1300
 
  opt_connect_timeout= 0;
1301
 
  if (in_connect_timeout > 3600*12)
1302
 
  {
1303
 
    cout << _("Error: Invalid Value for connect_timeout"); 
1304
 
    exit(-1);
1305
 
  }
1306
 
  opt_connect_timeout= in_connect_timeout;
1307
 
}
1308
 
 
1309
 
static void check_max_input_line(uint32_t in_max_input_line)
1310
 
{
1311
 
  opt_max_input_line= 0;
1312
 
  if (in_max_input_line < 4096 || in_max_input_line > (int64_t)2*1024L*1024L*1024L)
1313
 
  {
1314
 
    cout << _("Error: Invalid Value for max_input_line");
1315
 
    exit(-1);
1316
 
  }
1317
 
  opt_max_input_line= in_max_input_line - (in_max_input_line % 1024);
1318
 
}
1319
 
 
1320
1145
int main(int argc,char *argv[])
1321
1146
{
1322
 
try
1323
 
{
1324
 
 
1325
1147
#if defined(ENABLE_NLS)
1326
1148
# if defined(HAVE_LOCALE_H)
1327
1149
  setlocale(LC_ALL, "");
1328
1150
# endif
1329
 
  bindtextdomain("drizzle7", LOCALEDIR);
1330
 
  textdomain("drizzle7");
1331
 
#endif
1332
 
 
1333
 
  po::options_description commandline_options(_("Options used only in command line"));
1334
 
  commandline_options.add_options()
1335
 
  ("help,?",_("Displays this help and exit."))
1336
 
  ("batch,B",_("Don't use history file. Disable interactive behavior. (Enables --silent)"))
1337
 
  ("column-type-info", po::value<bool>(&column_types_flag)->default_value(false)->zero_tokens(),
1338
 
  _("Display column type information."))
1339
 
  ("comments,c", po::value<bool>(&preserve_comments)->default_value(false)->zero_tokens(),
1340
 
  _("Preserve comments. Send comments to the server. The default is --skip-comments (discard comments), enable with --comments"))
1341
 
  ("vertical,E", po::value<bool>(&vertical)->default_value(false)->zero_tokens(),
1342
 
  _("Print the output of a query (rows) vertically."))
1343
 
  ("force,f", po::value<bool>(&ignore_errors)->default_value(false)->zero_tokens(),
1344
 
  _("Continue even if we get an sql error."))
1345
 
  ("named-commands,G", po::value<bool>(&named_cmds)->default_value(false)->zero_tokens(),
1346
 
  _("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."))
1347
 
  ("no-beep,b", po::value<bool>(&opt_nobeep)->default_value(false)->zero_tokens(),
1348
 
  _("Turn off beep on error."))
1349
 
  ("disable-line-numbers", _("Do not write line numbers for errors."))
1350
 
  ("disable-column-names", _("Do not write column names in results."))
1351
 
  ("skip-column-names,N", 
1352
 
  _("Don't write column names in results. WARNING: -N is deprecated, use long version of this options instead."))
1353
 
  ("set-variable,O", po::value<string>(),
1354
 
  _("Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value."))
1355
 
  ("table,t", po::value<bool>(&output_tables)->default_value(false)->zero_tokens(),
1356
 
  _("Output in table format.")) 
1357
 
  ("safe-updates,U", po::value<bool>(&safe_updates)->default_value(false)->zero_tokens(),
1358
 
  _("Only allow UPDATE and DELETE that uses keys."))
1359
 
  ("i-am-a-dummy,U", po::value<bool>(&safe_updates)->default_value(false)->zero_tokens(),
1360
 
  _("Synonym for option --safe-updates, -U."))
1361
 
  ("verbose,v", po::value<string>(&opt_verbose)->default_value(""),
1362
 
  _("-v vvv implies that verbose= 3, Used to specify verbose"))
1363
 
  ("version,V", _("Output version information and exit."))
1364
 
  ("secure-auth", po::value<bool>(&opt_secure_auth)->default_value(false)->zero_tokens(),
1365
 
  _("Refuse client connecting to server if it uses old (pre-4.1.1) protocol"))
1366
 
  ("show-warnings", po::value<bool>(&show_warnings)->default_value(false)->zero_tokens(),
1367
 
  _("Show warnings after every statement."))
1368
 
  ("show-progress-size", po::value<uint32_t>(&show_progress_size)->default_value(0),
1369
 
  _("Number of lines before each import progress report."))
1370
 
  ("ping", po::value<bool>(&opt_ping)->default_value(false)->zero_tokens(),
1371
 
  _("Ping the server to check if it's alive."))
1372
 
  ("no-defaults", po::value<bool>()->default_value(false)->zero_tokens(),
1373
 
  _("Configuration file defaults are not used if no-defaults is set"))
1374
 
  ;
1375
 
 
1376
 
  po::options_description drizzle_options(_("Options specific to the drizzle client"));
1377
 
  drizzle_options.add_options()
1378
 
  ("disable-auto-rehash,A",
1379
 
  _("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."))
1380
 
  ("auto-vertical-output", po::value<bool>(&auto_vertical_output)->default_value(false)->zero_tokens(),
1381
 
  _("Automatically switch to vertical output mode if the result is wider than the terminal width."))
1382
 
  ("database,D", po::value<string>(&current_db)->default_value(""),
1383
 
  _("Database to use."))
1384
 
  ("default-character-set",po::value<string>(),
1385
 
  _("(not used)"))
1386
 
  ("delimiter", po::value<string>(&delimiter_str)->default_value(";"),
1387
 
  _("Delimiter to be used."))
1388
 
  ("execute,e", po::value<string>(),
1389
 
  _("Execute command and quit. (Disables --force and history file)"))
1390
 
  ("local-infile", po::value<bool>(&opt_local_infile)->default_value(false)->zero_tokens(),
1391
 
  _("Enable LOAD DATA LOCAL INFILE."))
1392
 
  ("unbuffered,n", po::value<bool>(&unbuffered)->default_value(false)->zero_tokens(),
1393
 
  _("Flush buffer after each query."))
1394
 
  ("sigint-ignore", po::value<bool>(&opt_sigint_ignore)->default_value(false)->zero_tokens(),
1395
 
  _("Ignore SIGINT (CTRL-C)"))
1396
 
  ("one-database,o", po::value<bool>(&one_database)->default_value(false)->zero_tokens(),
1397
 
  _("Only update the default database. This is useful for skipping updates to other database in the update log."))
1398
 
  ("pager", po::value<string>(),
1399
 
  _("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."))
1400
 
  ("disable-pager", po::value<bool>(&opt_nopager)->default_value(false)->zero_tokens(),
1401
 
  _("Disable pager and print to stdout. See interactive help (\\h) also."))
1402
 
  ("prompt", po::value<string>(&current_prompt)->default_value(""),  
1403
 
  _("Set the drizzle prompt to this value."))
1404
 
  ("quick,q", po::value<bool>(&quick)->default_value(false)->zero_tokens(),
1405
 
  _("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."))
1406
 
  ("raw,r", po::value<bool>(&opt_raw_data)->default_value(false)->zero_tokens(),
1407
 
  _("Write fields without conversion. Used with --batch.")) 
1408
 
  ("disable-reconnect", _("Do not reconnect if the connection is lost."))
1409
 
  ("shutdown", po::value<bool>()->zero_tokens(),
1410
 
  _("Shutdown the server"))
1411
 
  ("silent,s", _("Be more silent. Print results with a tab as separator, each row on new line."))
1412
 
  ("tee", po::value<string>(),
1413
 
  _("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."))
1414
 
  ("disable-tee", po::value<bool>()->default_value(false)->zero_tokens(), 
1415
 
  _("Disable outfile. See interactive help (\\h) also."))
1416
 
  ("connect-timeout", po::value<uint32_t>(&opt_connect_timeout)->default_value(0)->notifier(&check_timeout_value),
1417
 
  _("Number of seconds before connection timeout."))
1418
 
  ("max-input-line", po::value<uint32_t>(&opt_max_input_line)->default_value(16*1024L*1024L)->notifier(&check_max_input_line),
1419
 
  _("Max length of input line"))
1420
 
  ("select-limit", po::value<uint32_t>(&select_limit)->default_value(1000L),
1421
 
  _("Automatic limit for SELECT when using --safe-updates"))
1422
 
  ("max-join-size", po::value<uint32_t>(&max_join_size)->default_value(1000000L),
1423
 
  _("Automatic limit for rows in a join when using --safe-updates"))
1424
 
  ;
1425
 
 
1426
 
  po::options_description client_options(_("Options specific to the client"));
1427
 
  client_options.add_options()
1428
 
  ("host,h", po::value<string>(&current_host)->default_value("localhost"),
1429
 
  _("Connect to host"))
1430
 
  ("password,P", po::value<string>(&current_password)->default_value(PASSWORD_SENTINEL),
1431
 
  _("Password to use when connecting to server. If password is not given it's asked from the tty."))
1432
 
  ("port,p", po::value<uint32_t>()->default_value(0),
1433
 
  _("Port number to use for connection or 0 for default to, in order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, built-in default"))
1434
 
#ifdef DRIZZLE_ADMIN_TOOL
1435
 
  ("user,u", po::value<string>(&current_user)->default_value("root"),
1436
 
#else
1437
 
  ("user,u", po::value<string>(&current_user)->default_value(""),
1438
 
#endif
1439
 
  _("User for login if not current user."))
1440
 
  ("protocol",po::value<string>(&opt_protocol)->default_value("mysql"),
1441
 
  _("The protocol of connection (mysql or drizzle)."))
1442
 
  ;
1443
 
 
1444
 
  po::options_description long_options(_("Allowed Options"));
1445
 
  long_options.add(commandline_options).add(drizzle_options).add(client_options);
1446
 
 
1447
 
  std::string system_config_dir_drizzle(SYSCONFDIR); 
1448
 
  system_config_dir_drizzle.append("/drizzle/drizzle.cnf");
1449
 
 
1450
 
  std::string system_config_dir_client(SYSCONFDIR); 
1451
 
  system_config_dir_client.append("/drizzle/client.cnf");
1452
 
 
1453
 
  std::string user_config_dir((getenv("XDG_CONFIG_HOME")? getenv("XDG_CONFIG_HOME"):"~/.config"));
1454
 
 
1455
 
  if (user_config_dir.compare(0, 2, "~/") == 0)
1456
 
  {
1457
 
    char *homedir;
1458
 
    homedir= getenv("HOME");
1459
 
    if (homedir != NULL)
1460
 
      user_config_dir.replace(0, 1, homedir);
1461
 
  }
1462
 
 
1463
 
  po::variables_map vm;
1464
 
 
1465
 
  po::positional_options_description p;
1466
 
  p.add("database", 1);
1467
 
 
1468
 
  // Disable allow_guessing
1469
 
  int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing;
1470
 
 
1471
 
  po::store(po::command_line_parser(argc, argv).options(long_options).
1472
 
            style(style).positional(p).extra_parser(parse_password_arg).run(),
1473
 
            vm);
1474
 
 
1475
 
  if (! vm["no-defaults"].as<bool>())
1476
 
  {
1477
 
    std::string user_config_dir_drizzle(user_config_dir);
1478
 
    user_config_dir_drizzle.append("/drizzle/drizzle.cnf"); 
1479
 
 
1480
 
    std::string user_config_dir_client(user_config_dir);
1481
 
    user_config_dir_client.append("/drizzle/client.cnf");
1482
 
 
1483
 
    ifstream user_drizzle_ifs(user_config_dir_drizzle.c_str());
1484
 
    po::store(dpo::parse_config_file(user_drizzle_ifs, drizzle_options), vm);
1485
 
 
1486
 
    ifstream user_client_ifs(user_config_dir_client.c_str());
1487
 
    po::store(dpo::parse_config_file(user_client_ifs, client_options), vm);
1488
 
 
1489
 
    ifstream system_drizzle_ifs(system_config_dir_drizzle.c_str());
1490
 
    store(dpo::parse_config_file(system_drizzle_ifs, drizzle_options), vm);
1491
 
 
1492
 
    ifstream system_client_ifs(system_config_dir_client.c_str());
1493
 
    po::store(dpo::parse_config_file(system_client_ifs, client_options), vm);
1494
 
  }
1495
 
 
1496
 
  po::notify(vm);
1497
 
 
1498
 
#ifdef DRIZZLE_ADMIN_TOOL
1499
 
  default_prompt= strdup(getenv("DRIZZLE_PS1") ?
1500
 
                         getenv("DRIZZLE_PS1") :
1501
 
                         "drizzleadmin> ");
1502
 
#else
 
1151
  bindtextdomain("drizzle", LOCALEDIR);
 
1152
  textdomain("drizzle");
 
1153
#endif
 
1154
 
 
1155
  MY_INIT(argv[0]);
 
1156
  delimiter_str= delimiter;
1503
1157
  default_prompt= strdup(getenv("DRIZZLE_PS1") ?
1504
1158
                         getenv("DRIZZLE_PS1") :
1505
1159
                         "drizzle> ");
1506
 
#endif
 
1160
  
1507
1161
  if (default_prompt == NULL)
1508
1162
  {
1509
1163
    fprintf(stderr, _("Memory allocation error while constructing initial "
1510
1164
                      "prompt. Aborting.\n"));
1511
1165
    exit(ENOMEM);
1512
1166
  }
1513
 
 
1514
 
  if (current_prompt.empty())
1515
 
    current_prompt= strdup(default_prompt);
1516
 
 
1517
 
  if (current_prompt.empty())
 
1167
  current_prompt= strdup(default_prompt);
 
1168
  if (current_prompt == NULL)
1518
1169
  {
1519
1170
    fprintf(stderr, _("Memory allocation error while constructing initial "
1520
1171
                      "prompt. Aborting.\n"));
1525
1176
 
1526
1177
  prompt_counter=0;
1527
1178
 
1528
 
  outfile.clear();      // no (default) outfile
1529
 
  pager.assign("stdout");  // the default, if --pager wasn't given
 
1179
  outfile[0]=0;      // no (default) outfile
 
1180
  strcpy(pager, "stdout");  // the default, if --pager wasn't given
1530
1181
  {
1531
 
    const char *tmp= getenv("PAGER");
 
1182
    char *tmp=getenv("PAGER");
1532
1183
    if (tmp && strlen(tmp))
1533
1184
    {
1534
1185
      default_pager_set= 1;
1535
 
      default_pager.assign(tmp);
 
1186
      strcpy(default_pager, tmp);
1536
1187
    }
1537
1188
  }
1538
 
  if (! isatty(0) || ! isatty(1))
 
1189
  if (!isatty(0) || !isatty(1))
1539
1190
  {
1540
 
    status.setBatch(1); opt_silent=1;
 
1191
    status.batch=1; opt_silent=1;
 
1192
    ignore_errors=0;
1541
1193
  }
1542
1194
  else
1543
 
    status.setAddToHistory(1);
1544
 
  status.setExitStatus(1);
 
1195
    status.add_to_history=1;
 
1196
  status.exit_status=1;
1545
1197
 
1546
1198
  {
1547
1199
    /*
1557
1209
      close(stdout_fileno_copy);             /* Clean up dup(). */
1558
1210
  }
1559
1211
 
1560
 
  /* Inverted Booleans */
1561
 
 
1562
 
  line_numbers= (vm.count("disable-line-numbers")) ? false : true;
1563
 
  column_names= (vm.count("disable-column-names")) ? false : true;
1564
 
  opt_rehash= (vm.count("disable-auto-rehash")) ? false : true;
1565
 
  opt_reconnect= (vm.count("disable-reconnect")) ? false : true;
1566
 
 
1567
 
  /* Don't rehash with --shutdown */
1568
 
  if (vm.count("shutdown"))
1569
 
  {
1570
 
    opt_rehash= false;
1571
 
    opt_shutdown= true;
1572
 
  }
1573
 
 
1574
 
  if (vm.count("delimiter"))
1575
 
  {
1576
 
    /* Check that delimiter does not contain a backslash */
1577
 
    if (! strstr(delimiter_str.c_str(), "\\"))
1578
 
    {
1579
 
      delimiter= (char *)delimiter_str.c_str();  
1580
 
    }
1581
 
    else
1582
 
    {
1583
 
      put_info(_("DELIMITER cannot contain a backslash character"),
1584
 
      INFO_ERROR,0,0);
1585
 
      exit(-1);
1586
 
    }
1587
 
   
1588
 
    delimiter_length= (uint32_t)strlen(delimiter);
1589
 
  }
1590
 
  if (vm.count("tee"))
1591
 
  { 
1592
 
    if (vm["tee"].as<string>().empty())
1593
 
    {
1594
 
      if (opt_outfile)
1595
 
        end_tee();
1596
 
    }
1597
 
    else
1598
 
      init_tee(vm["tee"].as<string>().c_str());
1599
 
  }
1600
 
  if (vm["disable-tee"].as<bool>() == true)
1601
 
  {
1602
 
    if (opt_outfile)
1603
 
      end_tee();
1604
 
  }
1605
 
  if (vm.count("pager"))
1606
 
  {
1607
 
    if (vm["pager"].as<string>().empty())
1608
 
      opt_nopager= 1;
1609
 
    else
1610
 
    {
1611
 
      opt_nopager= 0;
1612
 
      if (vm[pager].as<string>().length())
1613
 
      {
1614
 
        default_pager_set= 1;
1615
 
        pager.assign(vm["pager"].as<string>());
1616
 
        default_pager.assign(pager);
1617
 
      }
1618
 
      else if (default_pager_set)
1619
 
        pager.assign(default_pager);
1620
 
      else
1621
 
        opt_nopager= 1;
1622
 
    }
1623
 
  }
1624
 
  if (vm.count("disable-pager"))
1625
 
  {
1626
 
    opt_nopager= 1;
1627
 
  }
1628
 
 
1629
 
  if (vm.count("no-auto-rehash"))
1630
 
    opt_rehash= 0;
1631
 
 
1632
 
  if (vm.count("skip-column-names"))
1633
 
    column_names= 0;
1634
 
    
1635
 
  if (vm.count("execute"))
1636
 
  {  
1637
 
    status.setBatch(1);
1638
 
    status.setAddToHistory(1);
1639
 
    if (status.getLineBuff() == NULL)
1640
 
      status.setLineBuff(opt_max_input_line,NULL);
1641
 
    if (status.getLineBuff() == NULL)
1642
 
    {
1643
 
      exit(1);
1644
 
    }
1645
 
    status.getLineBuff()->addString(vm["execute"].as<string>().c_str());
1646
 
  }
1647
 
 
1648
 
  if (one_database)
1649
 
    skip_updates= true;
1650
 
 
1651
 
  if (vm.count("protocol"))
1652
 
  {
1653
 
    std::transform(opt_protocol.begin(), opt_protocol.end(), 
1654
 
      opt_protocol.begin(), ::tolower);
1655
 
 
1656
 
    if (not opt_protocol.compare("mysql"))
1657
 
      use_drizzle_protocol=false;
1658
 
    else if (not opt_protocol.compare("drizzle"))
1659
 
      use_drizzle_protocol=true;
1660
 
    else
1661
 
    {
1662
 
      cout << _("Error: Unknown protocol") << " '" << opt_protocol << "'" << endl;
1663
 
      exit(-1);
1664
 
    }
1665
 
  }
1666
 
 
1667
 
  if (vm.count("port"))
1668
 
  {
1669
 
    opt_drizzle_port= vm["port"].as<uint32_t>();
1670
 
 
1671
 
    /* If the port number is > 65535 it is not a valid port
1672
 
       This also helps with potential data loss casting unsigned long to a
1673
 
       uint32_t. */
1674
 
    if (opt_drizzle_port > 65535)
1675
 
    {
1676
 
      printf(_("Error: Value of %" PRIu32 " supplied for port is not valid.\n"), opt_drizzle_port);
1677
 
      exit(-1);
1678
 
    }
1679
 
  }
1680
 
 
1681
 
  if (vm.count("password"))
1682
 
  {
1683
 
    if (!opt_password.empty())
1684
 
      opt_password.erase();
1685
 
    if (current_password == PASSWORD_SENTINEL)
1686
 
    {
1687
 
      opt_password= "";
1688
 
    }
1689
 
    else
1690
 
    {
1691
 
      opt_password= current_password;
1692
 
      tty_password= false;
1693
 
    }
1694
 
  }
1695
 
  else
1696
 
  {
1697
 
      tty_password= true;
1698
 
  }
1699
 
  
1700
 
 
1701
 
  if (!opt_verbose.empty())
1702
 
  {
1703
 
    verbose= opt_verbose.length();
1704
 
  }
1705
 
 
1706
 
  if (vm.count("batch"))
1707
 
  {
1708
 
    status.setBatch(1);
1709
 
    status.setAddToHistory(0);
1710
 
    if (opt_silent < 1)
1711
 
    {
1712
 
      opt_silent= 1;
1713
 
    }
1714
 
  }
1715
 
  if (vm.count("silent"))
1716
 
  {
1717
 
    opt_silent= 2;
1718
 
  }
1719
 
  
1720
 
  if (vm.count("help") || vm.count("version"))
1721
 
  {
1722
 
    printf(_("Drizzle client %s build %s, for %s-%s (%s) using readline %s\n"),
1723
 
           drizzle_version(), VERSION,
1724
 
           HOST_VENDOR, HOST_OS, HOST_CPU,
1725
 
           rl_library_version);
1726
 
    if (vm.count("version"))
1727
 
      exit(0);
1728
 
    printf(_("Copyright (C) 2008 Sun Microsystems\n"
1729
 
           "This software comes with ABSOLUTELY NO WARRANTY. "
1730
 
           "This is free software,\n"
1731
 
           "and you are welcome to modify and redistribute it "
1732
 
           "under the GPL license\n"));
1733
 
    printf(_("Usage: drizzle [OPTIONS] [schema]\n"));
1734
 
    cout << long_options;
1735
 
    exit(0);
1736
 
  }
1737
 
 
1738
 
 
1739
 
  if (process_options())
1740
 
  {
 
1212
  load_defaults("drizzle",load_default_groups,&argc,&argv);
 
1213
  defaults_argv=argv;
 
1214
  if (get_options(argc, (char **) argv))
 
1215
  {
 
1216
    free_defaults(defaults_argv);
 
1217
    my_end(0);
1741
1218
    exit(1);
1742
1219
  }
1743
1220
 
1744
1221
  memset(&drizzle, 0, sizeof(drizzle));
1745
 
  if (sql_connect(current_host, current_db, current_user, opt_password))
 
1222
  if (sql_connect(current_host,current_db,current_user,opt_password,
 
1223
                  opt_silent))
1746
1224
  {
1747
1225
    quick= 1;          // Avoid history
1748
 
    status.setExitStatus(1);
 
1226
    status.exit_status= 1;
1749
1227
    drizzle_end(-1);
1750
1228
  }
1751
1229
 
1753
1231
  if (execute_commands(&command_error) != false)
1754
1232
  {
1755
1233
    /* we've executed a command so exit before we go into readline mode */
 
1234
    free_defaults(defaults_argv);
 
1235
    my_end(0);
1756
1236
    exit(command_error);
1757
1237
  }
1758
1238
 
1759
 
  if (status.getBatch() && !status.getLineBuff())
 
1239
  if (status.batch && !status.line_buff)
1760
1240
  {
1761
 
    status.setLineBuff(opt_max_input_line, stdin);
1762
 
    if (status.getLineBuff() == NULL)
 
1241
    status.line_buff= new(std::nothrow) LineBuffer(opt_max_input_line, stdin);
 
1242
    if (status.line_buff == NULL)
1763
1243
    {
 
1244
      free_defaults(defaults_argv);
 
1245
      my_end(0);
1764
1246
      exit(1);
1765
1247
    }
1766
1248
  }
1767
1249
 
1768
 
  if (!status.getBatch())
 
1250
  if (!status.batch)
1769
1251
    ignore_errors=1;        // Don't abort monitor
1770
1252
 
1771
1253
  if (opt_sigint_ignore)
1780
1262
  /* call the SIGWINCH handler to get the default term width */
1781
1263
  window_resize(0);
1782
1264
#endif
1783
 
  std::vector<char> output_buff;
1784
 
  output_buff.resize(512);
1785
 
 
1786
 
  snprintf(&output_buff[0], output_buff.size(), 
1787
 
           _("Welcome to the Drizzle client..  Commands end with %s or \\g."), 
1788
 
           delimiter);
1789
 
 
1790
 
  put_info(&output_buff[0], INFO_INFO, 0, 0);
 
1265
 
 
1266
  put_info(_("Welcome to the Drizzle client..  Commands end with ; or \\g."),
 
1267
           INFO_INFO,0,0);
1791
1268
 
1792
1269
  glob_buffer= new string();
1793
1270
  glob_buffer->reserve(512);
1794
1271
 
1795
 
  snprintf(&output_buff[0], output_buff.size(),
1796
 
          _("Your Drizzle connection id is %u\nConnection protocol: %s\nServer version: %s\n"),
 
1272
  char * output_buff= (char *)malloc(512);
 
1273
  memset(output_buff, '\0', 512);
 
1274
 
 
1275
  sprintf(output_buff,
 
1276
          _("Your Drizzle connection id is %u\nServer version: %s\n"),
1797
1277
          drizzle_con_thread_id(&con),
1798
 
          opt_protocol.c_str(),
1799
1278
          server_version_string(&con));
1800
 
  put_info(&output_buff[0], INFO_INFO, 0, 0);
1801
 
 
1802
 
 
1803
 
  initialize_readline((char *)current_prompt.c_str());
1804
 
  if (!status.getBatch() && !quick)
 
1279
  put_info(output_buff, INFO_INFO, 0, 0);
 
1280
 
 
1281
  initialize_readline(current_prompt);
 
1282
  if (!status.batch && !quick)
1805
1283
  {
1806
1284
    /* read-history from file, default ~/.drizzle_history*/
1807
1285
    if (getenv("DRIZZLE_HISTFILE"))
1840
1318
 
1841
1319
  put_info(_("Type 'help;' or '\\h' for help. "
1842
1320
             "Type '\\c' to clear the buffer.\n"),INFO_INFO,0,0);
1843
 
  status.setExitStatus(read_and_execute(!status.getBatch()));
 
1321
  status.exit_status= read_and_execute(!status.batch);
1844
1322
  if (opt_outfile)
1845
1323
    end_tee();
1846
1324
  drizzle_end(0);
1847
 
}
1848
1325
 
1849
 
  catch(exception &err)
1850
 
  {
1851
 
    cerr << _("Error:") << err.what() << endl;
1852
 
  }
1853
1326
  return(0);        // Keep compiler happy
1854
1327
}
1855
1328
 
1857
1330
{
1858
1331
  drizzle_con_free(&con);
1859
1332
  drizzle_free(&drizzle);
1860
 
  if (!status.getBatch() && !quick && histfile)
 
1333
  if (!status.batch && !quick && histfile)
1861
1334
  {
1862
1335
    /* write-history */
1863
1336
    if (verbose)
1864
1337
      tee_fprintf(stdout, _("Writing history-file %s\n"),histfile);
1865
1338
    if (!write_history(histfile_tmp))
1866
 
      rename(histfile_tmp, histfile);
 
1339
      my_rename(histfile_tmp, histfile, MYF(MY_WME));
1867
1340
  }
1868
 
  delete status.getLineBuff();
1869
 
  status.setLineBuff(0);
 
1341
  delete status.line_buff;
 
1342
  status.line_buff= 0;
1870
1343
 
1871
1344
  if (sig >= 0)
1872
1345
    put_info(sig ? _("Aborted") : _("Bye"), INFO_RESULT,0,0);
1873
 
  delete glob_buffer;
1874
 
  delete processed_prompt;
1875
 
  opt_password.erase();
 
1346
  if (glob_buffer)
 
1347
    delete glob_buffer;
 
1348
  if (processed_prompt)
 
1349
    delete processed_prompt;
 
1350
  free(opt_password);
 
1351
  free(opt_drizzle_unix_port);
1876
1352
  free(histfile);
1877
1353
  free(histfile_tmp);
1878
 
  current_db.erase();
1879
 
  current_host.erase();
1880
 
  current_user.erase();
 
1354
  free(current_db);
 
1355
  free(current_host);
 
1356
  free(current_user);
1881
1357
  free(full_username);
1882
1358
  free(part_username);
1883
1359
  free(default_prompt);
1884
 
  current_prompt.erase();
1885
 
  exit(status.getExitStatus());
 
1360
  free(current_prompt);
 
1361
  free_defaults(defaults_argv);
 
1362
  my_end(my_end_arg);
 
1363
  exit(status.exit_status);
1886
1364
}
1887
1365
 
1888
1366
 
1895
1373
void handle_sigint(int sig)
1896
1374
{
1897
1375
  char kill_buffer[40];
1898
 
  boost::scoped_ptr<drizzle_con_st> kill_drizzle(new drizzle_con_st);
 
1376
  drizzle_con_st kill_drizzle;
1899
1377
  drizzle_result_st res;
1900
1378
  drizzle_return_t ret;
1901
1379
 
1904
1382
    goto err;
1905
1383
  }
1906
1384
 
1907
 
  if (drizzle_con_add_tcp(&drizzle, kill_drizzle.get(), current_host.c_str(),
1908
 
    opt_drizzle_port, current_user.c_str(), opt_password.c_str(), NULL,
1909
 
    use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL) == NULL)
 
1385
  if (drizzle_con_add_tcp(&drizzle, &kill_drizzle, current_host,
 
1386
                          opt_drizzle_port, current_user, opt_password, NULL,
 
1387
                          DRIZZLE_CON_NONE) == NULL)
1910
1388
  {
1911
1389
    goto err;
1912
1390
  }
1915
1393
  sprintf(kill_buffer, "KILL /*!50000 QUERY */ %u",
1916
1394
          drizzle_con_thread_id(&con));
1917
1395
 
1918
 
  if (drizzle_query_str(kill_drizzle.get(), &res, kill_buffer, &ret) != NULL)
 
1396
  if (drizzle_query_str(&kill_drizzle, &res, kill_buffer, &ret) != NULL)
1919
1397
    drizzle_result_free(&res);
1920
1398
 
1921
 
  drizzle_con_free(kill_drizzle.get());
 
1399
  drizzle_con_free(&kill_drizzle);
1922
1400
  tee_fprintf(stdout, _("Query aborted by Ctrl+C\n"));
1923
1401
 
1924
1402
  interrupted_query= 1;
1940
1418
}
1941
1419
#endif
1942
1420
 
1943
 
 
1944
 
 
1945
 
static int process_options(void)
 
1421
static struct my_option my_long_options[] =
 
1422
{
 
1423
  {"help", '?', N_("Display this help and exit."), 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
 
1424
   0, 0, 0, 0, 0},
 
1425
  {"help", 'I', N_("Synonym for -?"), 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
 
1426
   0, 0, 0, 0, 0},
 
1427
  {"auto-rehash", OPT_AUTO_REHASH,
 
1428
   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."),
 
1429
   (char**) &opt_rehash, (char**) &opt_rehash, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0,
 
1430
   0, 0},
 
1431
  {"no-auto-rehash", 'A',
 
1432
   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."),
 
1433
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1434
  {"auto-vertical-output", OPT_AUTO_VERTICAL_OUTPUT,
 
1435
   N_("Automatically switch to vertical output mode if the result is wider than the terminal width."),
 
1436
   (char**) &auto_vertical_output, (char**) &auto_vertical_output, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1437
  {"batch", 'B',
 
1438
   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},
 
1439
  {"column-type-info", OPT_COLUMN_TYPES, N_("Display column type information."),
 
1440
   (char**) &column_types_flag, (char**) &column_types_flag,
 
1441
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1442
  {"comments", 'c', N_("Preserve comments. Send comments to the server. The default is --skip-comments (discard comments), enable with --comments"),
 
1443
   (char**) &preserve_comments, (char**) &preserve_comments,
 
1444
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1445
  {"compress", 'C', N_("Use compression in server/client protocol."),
 
1446
   (char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
 
1447
   0, 0, 0},
 
1448
  {"debug-check", OPT_DEBUG_CHECK, N_("Check memory and open file usage at exit ."),
 
1449
   (char**) &debug_check_flag, (char**) &debug_check_flag, 0,
 
1450
   GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1451
  {"debug-info", 'T', N_("Print some debug info at exit."), (char**) &debug_info_flag,
 
1452
   (char**) &debug_info_flag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1453
  {"database", 'D', N_("Database to use."), (char**) &current_db,
 
1454
   (char**) &current_db, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1455
  {"default-character-set", OPT_DEFAULT_CHARSET,
 
1456
   N_("(not used)"), 0,
 
1457
   0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1458
  {"delimiter", OPT_DELIMITER, N_("Delimiter to be used."), (char**) &delimiter_str,
 
1459
   (char**) &delimiter_str, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1460
  {"execute", 'e', N_("Execute command and quit. (Disables --force and history file)"), 0,
 
1461
   0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1462
  {"vertical", 'E', N_("Print the output of a query (rows) vertically."),
 
1463
   (char**) &vertical, (char**) &vertical, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
 
1464
   0},
 
1465
  {"force", 'f', N_("Continue even if we get an sql error."),
 
1466
   (char**) &ignore_errors, (char**) &ignore_errors, 0, GET_BOOL, NO_ARG, 0, 0,
 
1467
   0, 0, 0, 0},
 
1468
  {"named-commands", 'G',
 
1469
   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."),
 
1470
   (char**) &named_cmds, (char**) &named_cmds, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
 
1471
   0, 0},
 
1472
  {"no-named-commands", 'g',
 
1473
   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."),
 
1474
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1475
  {"ignore-spaces", 'i', N_("Ignore space after function names."), 0, 0, 0,
 
1476
   GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1477
  {"local-infile", OPT_LOCAL_INFILE, N_("Enable/disable LOAD DATA LOCAL INFILE."),
 
1478
   (char**) &opt_local_infile,
 
1479
   (char**) &opt_local_infile, 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
1480
  {"no-beep", 'b', N_("Turn off beep on error."), (char**) &opt_nobeep,
 
1481
   (char**) &opt_nobeep, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1482
  {"host", 'h', N_("Connect to host."), (char**) &current_host,
 
1483
   (char**) &current_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1484
  {"line-numbers", OPT_LINE_NUMBERS, N_("Write line numbers for errors."),
 
1485
   (char**) &line_numbers, (char**) &line_numbers, 0, GET_BOOL,
 
1486
   NO_ARG, 1, 0, 0, 0, 0, 0},
 
1487
  {"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,
 
1488
   NO_ARG, 0, 0, 0, 0, 0, 0},
 
1489
  {"unbuffered", 'n', N_("Flush buffer after each query."), (char**) &unbuffered,
 
1490
   (char**) &unbuffered, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1491
  {"column-names", OPT_COLUMN_NAMES, N_("Write column names in results."),
 
1492
   (char**) &column_names, (char**) &column_names, 0, GET_BOOL,
 
1493
   NO_ARG, 1, 0, 0, 0, 0, 0},
 
1494
  {"skip-column-names", 'N',
 
1495
   N_("Don't write column names in results. WARNING: -N is deprecated, use long version of this options instead."),
 
1496
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1497
  {"set-variable", 'O',
 
1498
   N_("Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value."),
 
1499
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1500
  {"sigint-ignore", OPT_SIGINT_IGNORE, N_("Ignore SIGINT (CTRL-C)"),
 
1501
   (char**) &opt_sigint_ignore,  (char**) &opt_sigint_ignore, 0, GET_BOOL,
 
1502
   NO_ARG, 0, 0, 0, 0, 0, 0},
 
1503
  {"one-database", 'o',
 
1504
   N_("Only update the default database. This is useful for skipping updates to other database in the update log."),
 
1505
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1506
  {"pager", OPT_PAGER,
 
1507
   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."),
 
1508
   0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
1509
  {"no-pager", OPT_NOPAGER,
 
1510
   N_("Disable pager and print to stdout. See interactive help (\\h) also. WARNING: option deprecated; use --disable-pager instead."),
 
1511
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1512
  {"password", 'P',
 
1513
   N_("Password to use when connecting to server. If password is not given it's asked from the tty."),
 
1514
   0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
1515
  {"port", 'p', N_("Port number to use for connection or 0 for default to, in order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, ")
 
1516
   N_("built-in default") " (" STRINGIFY_ARG(DRIZZLE_PORT) ").",
 
1517
   0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1518
  {"prompt", OPT_PROMPT, N_("Set the drizzle prompt to this value."),
 
1519
   (char**) &current_prompt, (char**) &current_prompt, 0, GET_STR_ALLOC,
 
1520
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1521
  {"quick", 'q',
 
1522
   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."),
 
1523
   (char**) &quick, (char**) &quick, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1524
  {"raw", 'r', N_("Write fields without conversion. Used with --batch."),
 
1525
   (char**) &opt_raw_data, (char**) &opt_raw_data, 0, GET_BOOL, NO_ARG, 0, 0, 0,
 
1526
   0, 0, 0},
 
1527
  {"reconnect", OPT_RECONNECT, N_("Reconnect if the connection is lost. Disable with --disable-reconnect. This option is enabled by default."),
 
1528
   (char**) &opt_reconnect, (char**) &opt_reconnect, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
 
1529
  {"shutdown", OPT_SHUTDOWN, N_("Shutdown the server."),
 
1530
   (char**) &opt_shutdown, (char**) &opt_shutdown, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1531
  {"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,
 
1532
   0, 0},
 
1533
  {"socket", 'S', N_("Socket file to use for connection."),
 
1534
   (char**) &opt_drizzle_unix_port, (char**) &opt_drizzle_unix_port, 0, GET_STR_ALLOC,
 
1535
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1536
  {"table", 't', N_("Output in table format."), (char**) &output_tables,
 
1537
   (char**) &output_tables, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1538
  {"tee", OPT_TEE,
 
1539
   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."),
 
1540
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1541
  {"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,
 
1542
   NO_ARG, 0, 0, 0, 0, 0, 0},
 
1543
  {"user", 'u', N_("User for login if not current user."), (char**) &current_user,
 
1544
   (char**) &current_user, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
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 (%s) using %s %s\n"),
 
1596
         my_progname, VER.c_str(), drizzle_version(),
 
1597
         HOST_VENDOR, HOST_OS, HOST_CPU,
 
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 == NULL)
 
1695
      status.line_buff= new(std::nothrow) LineBuffer(opt_max_input_line,NULL);
 
1696
    if (status.line_buff == NULL)
 
1697
    {
 
1698
      my_end(0);
 
1699
      exit(1);
 
1700
    }
 
1701
    status.line_buff->addString(argument);
 
1702
    break;
 
1703
  case 'o':
 
1704
    if (argument == disabled_my_option)
 
1705
      one_database= 0;
 
1706
    else
 
1707
      one_database= skip_updates= 1;
 
1708
    break;
 
1709
  case 'p':
 
1710
    temp_drizzle_port= (uint64_t) strtoul(argument, &endchar, 10);
 
1711
    /* if there is an alpha character this is not a valid port */
 
1712
    if (strlen(endchar) != 0)
 
1713
    {
 
1714
      put_info(_("Non-integer value supplied for port.  If you are trying to enter a password please use --password instead."), INFO_ERROR, 0, 0);
 
1715
      return false;
 
1716
    }
 
1717
    /* If the port number is > 65535 it is not a valid port
 
1718
       This also helps with potential data loss casting unsigned long to a
 
1719
       uint32_t. */
 
1720
    if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
 
1721
    {
 
1722
      put_info(_("Value supplied for port is not valid."), INFO_ERROR, 0, 0);
 
1723
      return false;
 
1724
    }
 
1725
    else
 
1726
    {
 
1727
      opt_drizzle_port= (uint32_t) temp_drizzle_port;
 
1728
    }
 
1729
    break;
 
1730
  case 'P':
 
1731
    /* Don't require password */
 
1732
    if (argument == disabled_my_option)
 
1733
    {
 
1734
      argument= (char*) "";
 
1735
    }
 
1736
    if (argument)
 
1737
    {
 
1738
      char *start= argument;
 
1739
      free(opt_password);
 
1740
      opt_password= strdup(argument);
 
1741
      while (*argument)
 
1742
      {
 
1743
        /* Overwriting password with 'x' */
 
1744
        *argument++= 'x';
 
1745
      }
 
1746
      if (*start)
 
1747
      {
 
1748
        start[1]= 0;
 
1749
      }
 
1750
      tty_password= 0;
 
1751
    }
 
1752
    else
 
1753
    {
 
1754
      tty_password= 1;
 
1755
    }
 
1756
    break;
 
1757
  case 's':
 
1758
    if (argument == disabled_my_option)
 
1759
      opt_silent= 0;
 
1760
    else
 
1761
      opt_silent++;
 
1762
    break;
 
1763
  case 'v':
 
1764
    if (argument == disabled_my_option)
 
1765
      verbose= 0;
 
1766
    else
 
1767
      verbose++;
 
1768
    break;
 
1769
  case 'B':
 
1770
    status.batch= 1;
 
1771
    status.add_to_history= 0;
 
1772
    set_if_bigger(opt_silent,1);                         // more silent
 
1773
    break;
 
1774
  case 'V':
 
1775
    usage(1);
 
1776
    exit(0);
 
1777
  case 'I':
 
1778
  case '?':
 
1779
    usage(0);
 
1780
    exit(0);
 
1781
  }
 
1782
  return 0;
 
1783
}
 
1784
 
 
1785
 
 
1786
static int get_options(int argc, char **argv)
1946
1787
{
1947
1788
  char *tmp, *pagpoint;
1948
 
  
 
1789
  int ho_error;
1949
1790
 
1950
1791
  tmp= (char *) getenv("DRIZZLE_HOST");
1951
1792
  if (tmp)
1952
 
    current_host.assign(tmp);
 
1793
    current_host= strdup(tmp);
1953
1794
 
1954
1795
  pagpoint= getenv("PAGER");
1955
1796
  if (!((char*) (pagpoint)))
1956
1797
  {
1957
 
    pager.assign("stdout");
 
1798
    strcpy(pager, "stdout");
1958
1799
    opt_nopager= 1;
1959
1800
  }
1960
1801
  else
1961
 
  {
1962
 
    pager.assign(pagpoint);
1963
 
  }
1964
 
  default_pager.assign(pager);
1965
 
 
1966
 
  //
1967
 
 
1968
 
  if (status.getBatch()) /* disable pager and outfile in this case */
1969
 
  {
1970
 
    default_pager.assign("stdout");
1971
 
    pager.assign("stdout");
 
1802
    strcpy(pager, pagpoint);
 
1803
  strcpy(default_pager, pager);
 
1804
 
 
1805
  if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
 
1806
    exit(ho_error);
 
1807
 
 
1808
  if (status.batch) /* disable pager and outfile in this case */
 
1809
  {
 
1810
    strcpy(default_pager, "stdout");
 
1811
    strcpy(pager, "stdout");
1972
1812
    opt_nopager= 1;
1973
1813
    default_pager_set= 0;
1974
1814
    opt_outfile= 0;
1976
1816
    connect_flag= DRIZZLE_CAPABILITIES_NONE; /* Not in interactive mode */
1977
1817
  }
1978
1818
 
 
1819
  if (argc > 1)
 
1820
  {
 
1821
    usage(0);
 
1822
    exit(1);
 
1823
  }
 
1824
  if (argc == 1)
 
1825
  {
 
1826
    skip_updates= 0;
 
1827
    free(current_db);
 
1828
    current_db= strdup(*argv);
 
1829
  }
1979
1830
  if (tty_password)
1980
1831
    opt_password= client_get_tty_password(NULL);
 
1832
  if (debug_info_flag)
 
1833
    my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
 
1834
  if (debug_check_flag)
 
1835
    my_end_arg= MY_CHECK_ERROR;
1981
1836
  return(0);
1982
1837
}
1983
1838
 
1987
1842
  char in_string=0;
1988
1843
  uint32_t line_number=0;
1989
1844
  bool ml_comment= 0;
1990
 
  Commands *com;
1991
 
  status.setExitStatus(1);
 
1845
  COMMANDS *com;
 
1846
  status.exit_status=1;
1992
1847
 
1993
1848
  for (;;)
1994
1849
  {
1995
1850
    if (!interactive)
1996
1851
    {
1997
 
      if (status.getLineBuff())
1998
 
        line= status.getLineBuff()->readline();
 
1852
      if (status.line_buff)
 
1853
        line= status.line_buff->readline();
1999
1854
      else
2000
1855
        line= 0;
2001
1856
 
2006
1861
          fprintf(stderr, _("Processing line: %"PRIu32"\n"), line_number);
2007
1862
      }
2008
1863
      if (!glob_buffer->empty())
2009
 
        status.setQueryStartLine(line_number);
 
1864
        status.query_start_line= line_number;
2010
1865
    }
2011
1866
    else
2012
1867
    {
2013
 
      string prompt(ml_comment
2014
 
                      ? "   /*> " 
2015
 
                      : glob_buffer->empty()
2016
 
                        ? construct_prompt()
2017
 
                        : not in_string
2018
 
                          ? "    -> "
2019
 
                          : in_string == '\''
2020
 
                            ? "    '> "
2021
 
                            : in_string == '`'
2022
 
                              ? "    `> "
2023
 
                              : "    \"> ");
 
1868
      const char *prompt= (const char*) (ml_comment ? "   /*> " :
 
1869
                                         (glob_buffer->empty())
 
1870
                                         ?  construct_prompt()
 
1871
                                         : !in_string ? "    -> " :
 
1872
                                         in_string == '\'' ?
 
1873
                                         "    '> " : (in_string == '`' ?
 
1874
                                                      "    `> " :
 
1875
                                                      "    \"> "));
2024
1876
      if (opt_outfile && glob_buffer->empty())
2025
1877
        fflush(OUTFILE);
2026
1878
 
2027
1879
      if (opt_outfile)
2028
 
        fputs(prompt.c_str(), OUTFILE);
2029
 
      line= readline(prompt.c_str());
 
1880
        fputs(prompt, OUTFILE);
 
1881
      line= readline(prompt);
2030
1882
      /*
2031
1883
        When Ctrl+d or Ctrl+z is pressed, the line may be NULL on some OS
2032
1884
        which may cause coredump.
2037
1889
    // End of file
2038
1890
    if (!line)
2039
1891
    {
2040
 
      status.setExitStatus(0);
 
1892
      status.exit_status=0;
2041
1893
      break;
2042
1894
    }
2043
1895
 
2053
1905
      // If buffer was emptied
2054
1906
      if (glob_buffer->empty())
2055
1907
        in_string=0;
2056
 
      if (interactive && status.getAddToHistory() && not_in_history(line))
 
1908
      if (interactive && status.add_to_history && not_in_history(line))
2057
1909
        add_history(line);
2058
1910
      continue;
2059
1911
    }
2062
1914
  }
2063
1915
  /* if in batch mode, send last query even if it doesn't end with \g or go */
2064
1916
 
2065
 
  if (!interactive && !status.getExitStatus())
 
1917
  if (!interactive && !status.exit_status)
2066
1918
  {
2067
1919
    remove_cntrl(glob_buffer);
2068
1920
    if (!glob_buffer->empty())
2069
1921
    {
2070
 
      status.setExitStatus(1);
 
1922
      status.exit_status=1;
2071
1923
      if (com_go(glob_buffer,line) <= 0)
2072
 
        status.setExitStatus(0);
 
1924
        status.exit_status=0;
2073
1925
    }
2074
1926
  }
2075
1927
 
2076
 
  return status.getExitStatus();
 
1928
  return status.exit_status;
2077
1929
}
2078
1930
 
2079
1931
 
2080
 
static Commands *find_command(const char *name,char cmd_char)
 
1932
static COMMANDS *find_command(const char *name,char cmd_char)
2081
1933
{
2082
1934
  uint32_t len;
2083
1935
  const char *end;
2089
1941
  }
2090
1942
  else
2091
1943
  {
2092
 
    while (isspace(*name))
 
1944
    while (my_isspace(charset_info,*name))
2093
1945
      name++;
2094
1946
    /*
2095
1947
      If there is an \\g in the row or if the row has a delimiter but
2098
1950
    */
2099
1951
    if (strstr(name, "\\g") || (strstr(name, delimiter) &&
2100
1952
                                !(strlen(name) >= 9 &&
2101
 
                                  !strcmp(name, "delimiter"))))
2102
 
      return(NULL);
 
1953
                                  !my_strnncoll(charset_info,
 
1954
                                                (unsigned char*) name, 9,
 
1955
                                                (const unsigned char*) "delimiter",
 
1956
                                                9))))
 
1957
      return((COMMANDS *) 0);
2103
1958
    if ((end=strcont(name," \t")))
2104
1959
    {
2105
1960
      len=(uint32_t) (end - name);
2106
 
      while (isspace(*end))
 
1961
      while (my_isspace(charset_info,*end))
2107
1962
        end++;
2108
1963
      if (!*end)
2109
1964
        end=0;          // no arguments to function
2112
1967
      len=(uint32_t) strlen(name);
2113
1968
  }
2114
1969
 
2115
 
  for (uint32_t i= 0; commands[i].getName(); i++)
 
1970
  for (uint32_t i= 0; commands[i].name; i++)
2116
1971
  {
2117
1972
    if (commands[i].func &&
2118
 
        ((name && !strncmp(name, commands[i].getName(), len)
2119
 
          && !commands[i].getName()[len] && (!end || (end && commands[i].getTakesParams()))) || (!name && commands[i].getCmdChar() == cmd_char)))
 
1973
        ((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)))
2120
1974
    {
2121
1975
      return(&commands[i]);
2122
1976
    }
2123
1977
  }
2124
 
  return(NULL);
 
1978
  return((COMMANDS *) 0);
2125
1979
}
2126
1980
 
2127
1981
 
2130
1984
{
2131
1985
  unsigned char inchar;
2132
1986
  char *pos, *out;
2133
 
  Commands *com;
 
1987
  COMMANDS *com;
2134
1988
  bool need_space= 0;
2135
1989
  bool ss_comment= 0;
2136
1990
 
2137
1991
 
2138
1992
  if (!line[0] && (buffer->empty()))
2139
1993
    return(0);
2140
 
  if (status.getAddToHistory() && line[0] && not_in_history(line))
 
1994
  if (status.add_to_history && line[0] && not_in_history(line))
2141
1995
    add_history(line);
2142
1996
  char *end_of_line=line+(uint32_t) strlen(line);
2143
1997
 
2146
2000
    if (!preserve_comments)
2147
2001
    {
2148
2002
      // Skip spaces at the beggining of a statement
2149
 
      if (isspace(inchar) && (out == line) &&
 
2003
      if (my_isspace(charset_info,inchar) && (out == line) &&
2150
2004
          (buffer->empty()))
2151
2005
        continue;
2152
2006
    }
2153
2007
 
2154
2008
    // Accept multi-byte characters as-is
2155
 
    if (not drizzled::utf8::is_single(*pos))
 
2009
    int length;
 
2010
    if (use_mb(charset_info) &&
 
2011
        (length= my_ismbchar(charset_info, pos, end_of_line)))
2156
2012
    {
2157
 
      int length;
2158
 
      if ((length= drizzled::utf8::sequence_length(*pos)))
 
2013
      if (!*ml_comment || preserve_comments)
2159
2014
      {
2160
 
        if (!*ml_comment || preserve_comments)
2161
 
        {
2162
 
          while (length--)
2163
 
            *out++ = *pos++;
2164
 
          pos--;
2165
 
        }
2166
 
        else
2167
 
          pos+= length - 1;
2168
 
        continue;
 
2015
        while (length--)
 
2016
          *out++ = *pos++;
 
2017
        pos--;
2169
2018
      }
 
2019
      else
 
2020
        pos+= length - 1;
 
2021
      continue;
2170
2022
    }
2171
2023
    if (!*ml_comment && inchar == '\\' &&
2172
2024
        !(*in_string && (drizzle_con_status(&con) & DRIZZLE_CON_STATUS_NO_BACKSLASH_ESCAPES)))
2192
2044
 
2193
2045
        if ((*com->func)(buffer,pos-1) > 0)
2194
2046
          return(1);                       // Quit
2195
 
        if (com->getTakesParams())
 
2047
        if (com->takes_params)
2196
2048
        {
2197
2049
          if (ss_comment)
2198
2050
          {
2235
2087
    }
2236
2088
    else if (!*ml_comment && !*in_string &&
2237
2089
             (end_of_line - pos) >= 10 &&
2238
 
             !strncmp(pos, "delimiter ", 10))
 
2090
             !my_strnncoll(charset_info, (unsigned char*) pos, 10,
 
2091
                           (const unsigned char*) "delimiter ", 10))
2239
2092
    {
2240
2093
      // Flush previously accepted characters
2241
2094
      if (out != line)
2272
2125
 
2273
2126
      if (preserve_comments)
2274
2127
      {
2275
 
        while (isspace(*pos))
 
2128
        while (my_isspace(charset_info, *pos))
2276
2129
          *out++= *pos++;
2277
2130
      }
2278
2131
      // Flush previously accepted characters
2285
2138
      if (preserve_comments && ((*pos == '#') ||
2286
2139
                                ((*pos == '-') &&
2287
2140
                                 (pos[1] == '-') &&
2288
 
                                 isspace(pos[2]))))
 
2141
                                 my_isspace(charset_info, pos[2]))))
2289
2142
      {
2290
2143
        // Add trailing single line comments to this statement
2291
2144
        buffer->append(pos);
2312
2165
                 && (inchar == '#'
2313
2166
                     || (inchar == '-'
2314
2167
                         && pos[1] == '-'
2315
 
                         && isspace(pos[2])))))
 
2168
                         && my_isspace(charset_info,pos[2])))))
2316
2169
    {
2317
2170
      // Flush previously accepted characters
2318
2171
      if (out != line)
2378
2231
        *in_string= (char) inchar;
2379
2232
      if (!*ml_comment || preserve_comments)
2380
2233
      {
2381
 
        if (need_space && !isspace((char)inchar))
 
2234
        if (need_space && !my_isspace(charset_info, (char)inchar))
2382
2235
          *out++= ' ';
2383
2236
        need_space= 0;
2384
2237
        *out++= (char) inchar;
2389
2242
  {
2390
2243
    *out++='\n';
2391
2244
    uint32_t length=(uint32_t) (out-line);
2392
 
    if ((buffer->length() + length) > opt_max_input_line)
2393
 
    {
2394
 
      status.setExitStatus(1);
2395
 
      put_info(_("Not found a delimiter within max_input_line of input"), INFO_ERROR, 0, 0);
2396
 
      return 1;
2397
 
    }
2398
2245
    if ((!*ml_comment || preserve_comments))
2399
2246
      buffer->append(line, length);
2400
2247
  }
2499
2346
 
2500
2347
  /* Tell the completer that we want a crack first. */
2501
2348
  rl_attempted_completion_function= (rl_completion_func_t*)&mysql_completion;
2502
 
  rl_completion_entry_function= (drizzle_compentry_func_t*)&no_completion;
 
2349
  rl_completion_entry_function= (rl_compentry_func_t*)&no_completion;
2503
2350
}
2504
2351
 
2505
2352
 
2511
2358
*/
2512
2359
char **mysql_completion (const char *text, int, int)
2513
2360
{
2514
 
  if (!status.getBatch() && !quick)
 
2361
  if (!status.batch && !quick)
2515
2362
    return rl_completion_matches(text, new_command_generator);
2516
2363
  else
2517
2364
    return (char**) 0;
2580
2427
 
2581
2428
static void build_completion_hash(bool rehash, bool write_info)
2582
2429
{
2583
 
  Commands *cmd=commands;
 
2430
  COMMANDS *cmd=commands;
2584
2431
  drizzle_return_t ret;
2585
2432
  drizzle_result_st databases,tables,fields;
2586
2433
  drizzle_row_t database_row,table_row;
 
2434
  drizzle_column_st *sql_field;
2587
2435
  string tmp_str, tmp_str_lower;
2588
 
  std::string query;
2589
2436
 
2590
 
  if (status.getBatch() || quick || current_db.empty())
 
2437
  if (status.batch || quick || !current_db)
2591
2438
    return;      // We don't need completion in batches
2592
2439
  if (!rehash)
2593
2440
    return;
2595
2442
  completion_map.clear();
2596
2443
 
2597
2444
  /* hash this file's known subset of SQL commands */
2598
 
  while (cmd->getName()) {
2599
 
    tmp_str= cmd->getName();
 
2445
  while (cmd->name) {
 
2446
    tmp_str= cmd->name;
2600
2447
    tmp_str_lower= lower_string(tmp_str);
2601
2448
    completion_map[tmp_str_lower]= tmp_str;
2602
2449
    cmd++;
2605
2452
  /* hash Drizzle functions (to be implemented) */
2606
2453
 
2607
2454
  /* hash all database names */
2608
 
  if (drizzle_query_str(&con, &databases, "select schema_name from information_schema.schemata", &ret) != NULL)
 
2455
  if (drizzle_query_str(&con, &databases, "show databases", &ret) != NULL)
2609
2456
  {
2610
2457
    if (ret == DRIZZLE_RETURN_OK)
2611
2458
    {
2625
2472
    drizzle_result_free(&databases);
2626
2473
  }
2627
2474
 
2628
 
  query= "select table_name, column_name from information_schema.columns where table_schema='";
2629
 
  query.append(current_db);
2630
 
  query.append("' order by table_name");
2631
 
  
2632
 
  if (drizzle_query(&con, &fields, query.c_str(), query.length(),
2633
 
                    &ret) != NULL)
 
2475
  /* hash all table names */
 
2476
  if (drizzle_query_str(&con, &tables, "show tables", &ret) != NULL)
2634
2477
  {
2635
 
    if (ret == DRIZZLE_RETURN_OK &&
2636
 
        drizzle_result_buffer(&fields) == DRIZZLE_RETURN_OK)
 
2478
    if (ret != DRIZZLE_RETURN_OK)
 
2479
    {
 
2480
      drizzle_result_free(&tables);
 
2481
      return;
 
2482
    }
 
2483
 
 
2484
    if (drizzle_result_buffer(&tables) != DRIZZLE_RETURN_OK)
 
2485
      put_info(drizzle_error(&drizzle),INFO_INFO,0,0);
 
2486
    else
2637
2487
    {
2638
2488
      if (drizzle_result_row_count(&tables) > 0 && !opt_silent && write_info)
2639
2489
      {
2640
 
        tee_fprintf(stdout,
2641
 
                    _("Reading table information for completion of "
2642
 
                      "table and column names\n"
2643
 
                      "You can turn off this feature to get a quicker "
2644
 
                      "startup with -A\n\n"));
 
2490
        tee_fprintf(stdout, _("\
 
2491
Reading table information for completion of table and column names\n    \
 
2492
You can turn off this feature to get a quicker startup with -A\n\n"));
2645
2493
      }
2646
 
 
2647
 
      std::string table_name;
2648
 
      while ((table_row=drizzle_row_next(&fields)))
 
2494
      while ((table_row=drizzle_row_next(&tables)))
2649
2495
      {
2650
 
        if (table_name.compare(table_row[0]) != 0)
2651
 
        {
2652
 
          tmp_str= table_row[0];
2653
 
          tmp_str_lower= lower_string(tmp_str);
2654
 
          completion_map[tmp_str_lower]= tmp_str;
2655
 
          table_name= table_row[0];
2656
 
        }
2657
2496
        tmp_str= table_row[0];
2658
 
        tmp_str.append(".");
2659
 
        tmp_str.append(table_row[1]);
2660
 
        tmp_str_lower= lower_string(tmp_str);
2661
 
        completion_map[tmp_str_lower]= tmp_str;
2662
 
 
2663
 
        tmp_str= table_row[1];
2664
 
        tmp_str_lower= lower_string(tmp_str);
2665
 
        completion_map[tmp_str_lower]= tmp_str;
2666
 
      }
2667
 
    }
2668
 
  }
2669
 
  drizzle_result_free(&fields);
 
2497
        tmp_str_lower= lower_string(tmp_str);
 
2498
        completion_map[tmp_str_lower]= tmp_str;
 
2499
      }
 
2500
    }
 
2501
  }
 
2502
  else
 
2503
    return;
 
2504
 
 
2505
  /* hash all field names, both with the table prefix and without it */
 
2506
  if (drizzle_result_row_count(&tables) == 0)
 
2507
  {
 
2508
    drizzle_result_free(&tables);
 
2509
    return;
 
2510
  }
 
2511
 
 
2512
  drizzle_row_seek(&tables, 0);
 
2513
 
 
2514
  while ((table_row=drizzle_row_next(&tables)))
 
2515
  {
 
2516
    string query;
 
2517
 
 
2518
    query.append("show fields in '");
 
2519
    query.append(table_row[0]);
 
2520
    query.append("'");
 
2521
    
 
2522
    if (drizzle_query(&con, &fields, query.c_str(), query.length(),
 
2523
                      &ret) != NULL)
 
2524
    {
 
2525
      if (ret == DRIZZLE_RETURN_OK &&
 
2526
          drizzle_result_buffer(&fields) == DRIZZLE_RETURN_OK)
 
2527
      {
 
2528
        while ((sql_field=drizzle_column_next(&fields)))
 
2529
        {
 
2530
          tmp_str=table_row[0];
 
2531
          tmp_str.append(".");
 
2532
          tmp_str.append(drizzle_column_name(sql_field));
 
2533
          tmp_str_lower= lower_string(tmp_str);
 
2534
          completion_map[tmp_str_lower]= tmp_str;
 
2535
 
 
2536
          tmp_str=drizzle_column_name(sql_field);
 
2537
          tmp_str_lower= lower_string(tmp_str);
 
2538
          completion_map[tmp_str_lower]= tmp_str;
 
2539
        }
 
2540
      }
 
2541
      drizzle_result_free(&fields);
 
2542
    }
 
2543
  }
 
2544
  drizzle_result_free(&tables);
2670
2545
  completion_iter= completion_map.begin();
2671
2546
}
2672
2547
 
2673
2548
/* for gnu readline */
2674
2549
 
 
2550
#ifndef HAVE_INDEX
 
2551
extern "C" {
 
2552
  extern char *index(const char *,int c),*rindex(const char *,int);
 
2553
 
 
2554
  char *index(const char *s,int c)
 
2555
  {
 
2556
    for (;;)
 
2557
    {
 
2558
      if (*s == (char) c) return (char*) s;
 
2559
      if (!*s++) return NULL;
 
2560
    }
 
2561
  }
 
2562
 
 
2563
  char *rindex(const char *s,int c)
 
2564
  {
 
2565
    register char *t;
 
2566
 
 
2567
    t = NULL;
 
2568
    do if (*s == (char) c) t = (char*) s; while (*s++);
 
2569
    return (char*) t;
 
2570
  }
 
2571
}
 
2572
#endif
 
2573
 
2675
2574
 
2676
2575
static int reconnect(void)
2677
2576
{
2679
2578
  {
2680
2579
    put_info(_("No connection. Trying to reconnect..."),INFO_INFO,0,0);
2681
2580
    (void) com_connect((string *)0, 0);
2682
 
    if (opt_rehash && connected)
 
2581
    if (opt_rehash)
2683
2582
      com_rehash(NULL, NULL);
2684
2583
  }
2685
 
  if (! connected)
 
2584
  if (!connected)
2686
2585
    return put_info(_("Can't connect to the server\n"),INFO_ERROR,0,0);
2687
2586
  return 0;
2688
2587
}
2692
2591
  drizzle_return_t ret;
2693
2592
  drizzle_result_st res;
2694
2593
 
2695
 
  current_db.erase();
2696
 
  current_db= "";
 
2594
  free(current_db);
 
2595
  current_db= NULL;
2697
2596
  /* In case of error below current_db will be NULL */
2698
2597
  if (drizzle_query_str(&con, &res, "SELECT DATABASE()", &ret) != NULL)
2699
2598
  {
2702
2601
    {
2703
2602
      drizzle_row_t row= drizzle_row_next(&res);
2704
2603
      if (row[0])
2705
 
        current_db.assign(row[0]);
2706
 
      drizzle_result_free(&res);
 
2604
        current_db= strdup(row[0]);
2707
2605
    }
 
2606
    drizzle_result_free(&res);
2708
2607
  }
2709
2608
}
2710
2609
 
2712
2611
 The different commands
2713
2612
***************************************************************************/
2714
2613
 
2715
 
int drizzleclient_real_query_for_lazy(const char *buf, size_t length,
 
2614
int drizzleclient_real_query_for_lazy(const char *buf, int length,
2716
2615
                                      drizzle_result_st *result,
2717
2616
                                      uint32_t *error_code)
2718
2617
{
2751
2650
    return 0;
2752
2651
 
2753
2652
  if (drizzle_con_error(&con)[0])
2754
 
  {
2755
 
    int ret= put_error(&con, result);
2756
 
    drizzle_result_free(result);
2757
 
    return ret;
2758
 
  }
 
2653
    return put_error(&con, result);
2759
2654
  return 0;
2760
2655
}
2761
2656
 
2762
2657
static int
2763
2658
com_help(string *buffer, const char *)
2764
2659
{
2765
 
  int i, j;
 
2660
  register int i, j;
2766
2661
  char buff[32], *end;
2767
 
  std::vector<char> output_buff;
2768
 
  output_buff.resize(512);
2769
2662
 
2770
2663
  put_info(_("List of all Drizzle commands:"), INFO_INFO,0,0);
2771
2664
  if (!named_cmds)
2772
 
  {
2773
 
    snprintf(&output_buff[0], output_buff.size(),
2774
 
             _("Note that all text commands must be first on line and end with '%s' or \\g"),
2775
 
             delimiter);
2776
 
    put_info(&output_buff[0], INFO_INFO, 0, 0);
2777
 
  }
2778
 
  for (i = 0; commands[i].getName(); i++)
2779
 
  {
2780
 
    end= strcpy(buff, commands[i].getName());
2781
 
    end+= strlen(commands[i].getName());
2782
 
    for (j= (int)strlen(commands[i].getName()); j < 10; j++)
 
2665
    put_info(_("Note that all text commands must be first on line and end with ';'"),INFO_INFO,0,0);
 
2666
  for (i = 0; commands[i].name; i++)
 
2667
  {
 
2668
    end= strcpy(buff, commands[i].name);
 
2669
    end+= strlen(commands[i].name);
 
2670
    for (j= (int)strlen(commands[i].name); j < 10; j++)
2783
2671
      end= strcpy(end, " ")+1;
2784
2672
    if (commands[i].func)
2785
2673
      tee_fprintf(stdout, "%s(\\%c) %s\n", buff,
2786
 
                  commands[i].getCmdChar(), _(commands[i].getDoc()));
 
2674
                  commands[i].cmd_char, _(commands[i].doc));
2787
2675
  }
2788
2676
  tee_fprintf(stdout, "\n");
2789
2677
  buffer->clear();
2794
2682
static int
2795
2683
com_clear(string *buffer, const char *)
2796
2684
{
2797
 
  if (status.getAddToHistory())
 
2685
  if (status.add_to_history)
2798
2686
    fix_history(buffer);
2799
2687
  buffer->clear();
2800
2688
  return 0;
2811
2699
com_go(string *buffer, const char *)
2812
2700
{
2813
2701
  char          buff[200]; /* about 110 chars used so far */
 
2702
  char          time_buff[52+3+1]; /* time max + space&parens + NUL */
2814
2703
  drizzle_result_st result;
2815
2704
  drizzle_return_t ret;
2816
 
  uint32_t      warnings= 0;
2817
 
  boost::posix_time::ptime timer;
 
2705
  uint32_t      timer, warnings= 0;
2818
2706
  uint32_t      error= 0;
2819
2707
  uint32_t      error_code= 0;
2820
2708
  int           err= 0;
2827
2715
  if (buffer->empty())
2828
2716
  {
2829
2717
    // Ignore empty quries
2830
 
    if (status.getBatch())
 
2718
    if (status.batch)
2831
2719
      return 0;
2832
2720
    return put_info(_("No query specified\n"),INFO_ERROR,0,0);
2833
2721
 
2852
2740
  executing_query= 1;
2853
2741
  error= drizzleclient_real_query_for_lazy(buffer->c_str(),buffer->length(),&result, &error_code);
2854
2742
 
2855
 
  if (status.getAddToHistory())
 
2743
  if (status.add_to_history)
2856
2744
  {
2857
2745
    buffer->append(vertical ? "\\G" : delimiter);
2858
2746
    /* Append final command onto history */
2883
2771
        goto end;
2884
2772
    }
2885
2773
 
2886
 
    string time_buff("");
2887
2774
    if (verbose >= 3 || !opt_silent)
2888
2775
      drizzle_end_timer(timer,time_buff);
 
2776
    else
 
2777
      time_buff[0]= '\0';
2889
2778
 
2890
2779
    /* Every branch must truncate  buff . */
2891
2780
    if (drizzle_result_column_count(&result) > 0)
2936
2825
      if (warnings != 1)
2937
2826
        *pos++= 's';
2938
2827
    }
2939
 
    strcpy(pos, time_buff.c_str());
 
2828
    strcpy(pos, time_buff);
2940
2829
    put_info(buff,INFO_RESULT,0,0);
2941
2830
    if (strcmp(drizzle_result_info(&result), ""))
2942
2831
      put_info(drizzle_result_info(&result),INFO_RESULT,0,0);
2972
2861
  if (show_warnings == 1 && (warnings >= 1 || error))
2973
2862
    print_warnings(error_code);
2974
2863
 
2975
 
  if (!error && !status.getBatch() &&
 
2864
  if (!error && !status.batch &&
2976
2865
      drizzle_con_status(&con) & DRIZZLE_CON_STATUS_DB_DROPPED)
2977
2866
  {
2978
2867
    get_current_db();
2987
2876
{
2988
2877
  if (!opt_nopager)
2989
2878
  {
2990
 
    if (!(PAGER= popen(pager.c_str(), "w")))
 
2879
    if (!(PAGER= popen(pager, "w")))
2991
2880
    {
2992
 
      tee_fprintf(stdout,_( "popen() failed! defaulting PAGER to stdout!\n"));
 
2881
      tee_fprintf(stdout, "popen() failed! defaulting PAGER to stdout!\n");
2993
2882
      PAGER= stdout;
2994
2883
    }
2995
2884
  }
3011
2900
    end_tee();
3012
2901
  if (!(new_outfile= fopen(file_name, "a")))
3013
2902
  {
3014
 
    tee_fprintf(stdout, _("Error logging to file '%s'\n"), file_name);
 
2903
    tee_fprintf(stdout, "Error logging to file '%s'\n", file_name);
3015
2904
    return;
3016
2905
  }
3017
2906
  OUTFILE = new_outfile;
3018
 
  outfile.assign(file_name);
3019
 
  tee_fprintf(stdout, _("Logging to file '%s'\n"), file_name);
 
2907
  strncpy(outfile, file_name, FN_REFLEN-1);
 
2908
  tee_fprintf(stdout, "Logging to file '%s'\n", file_name);
3020
2909
  opt_outfile= 1;
3021
2910
 
3022
2911
  return;
3057
2946
    case DRIZZLE_COLUMN_TYPE_LONGLONG:    return "LONGLONG";
3058
2947
    case DRIZZLE_COLUMN_TYPE_NULL:        return "NULL";
3059
2948
    case DRIZZLE_COLUMN_TYPE_TIMESTAMP:   return "TIMESTAMP";
 
2949
    case DRIZZLE_COLUMN_TYPE_TINY:        return "TINY";
 
2950
    case DRIZZLE_COLUMN_TYPE_VIRTUAL:     return "VIRTUAL";
3060
2951
    default:                     return "?-unknown-?";
3061
2952
  }
3062
2953
}
3100
2991
 
3101
2992
  while ((field = drizzle_column_next(result)))
3102
2993
  {
3103
 
    tee_fprintf(PAGER, _("Field %3u:  `%s`\n"
 
2994
    tee_fprintf(PAGER, "Field %3u:  `%s`\n"
3104
2995
                "Catalog:    `%s`\n"
3105
 
                "Schema:     `%s`\n"
 
2996
                "Database:   `%s`\n"
3106
2997
                "Table:      `%s`\n"
3107
2998
                "Org_table:  `%s`\n"
3108
 
                "Type:       UTF-8\n"
 
2999
                "Type:       %s\n"
3109
3000
                "Collation:  %s (%u)\n"
3110
3001
                "Length:     %lu\n"
3111
3002
                "Max_length: %lu\n"
3112
3003
                "Decimals:   %u\n"
3113
 
                "Flags:      %s\n\n"),
 
3004
                "Flags:      %s\n\n",
3114
3005
                ++i,
3115
3006
                drizzle_column_name(field), drizzle_column_catalog(field),
3116
3007
                drizzle_column_db(field), drizzle_column_table(field),
3117
3008
                drizzle_column_orig_table(field),
3118
3009
                fieldtype2str(drizzle_column_type(field)),
 
3010
                get_charset_name(drizzle_column_charset(field)),
3119
3011
                drizzle_column_charset(field), drizzle_column_size(field),
3120
3012
                drizzle_column_max_size(field), drizzle_column_decimals(field),
3121
3013
                fieldflags2str(drizzle_column_flags(field)));
3123
3015
  tee_puts("", PAGER);
3124
3016
}
3125
3017
 
 
3018
 
3126
3019
static void
3127
3020
print_table_data(drizzle_result_st *result)
3128
3021
{
3129
3022
  drizzle_row_t cur;
3130
3023
  drizzle_return_t ret;
3131
3024
  drizzle_column_st *field;
3132
 
  std::vector<bool> num_flag;
3133
 
  std::vector<bool> boolean_flag;
3134
 
  std::vector<bool> ansi_boolean_flag;
 
3025
  bool *num_flag;
3135
3026
  string separator;
3136
3027
 
3137
3028
  separator.reserve(256);
3138
3029
 
3139
 
  num_flag.resize(drizzle_result_column_count(result));
3140
 
  boolean_flag.resize(drizzle_result_column_count(result));
3141
 
  ansi_boolean_flag.resize(drizzle_result_column_count(result));
 
3030
  num_flag=(bool*) malloc(sizeof(bool)*drizzle_result_column_count(result));
3142
3031
  if (column_types_flag)
3143
3032
  {
3144
3033
    print_field_types(result);
3158
3047
      /* Check if the max_byte value is really the maximum in terms
3159
3048
         of visual length since multibyte characters can affect the
3160
3049
         length of the separator. */
3161
 
      length= drizzled::utf8::char_length(drizzle_column_name(field));
 
3050
      length= charset_info->cset->numcells(charset_info,
 
3051
                                           drizzle_column_name(field),
 
3052
                                           drizzle_column_name(field) +
 
3053
                                           name_length);
3162
3054
 
3163
3055
      if (name_length == drizzle_column_max_size(field))
3164
3056
      {
3181
3073
      // Room for "NULL"
3182
3074
      length=4;
3183
3075
    }
3184
 
    if ((length < 5) and 
3185
 
      (server_type == ServerDetect::SERVER_DRIZZLE_FOUND) and
3186
 
      (drizzle_column_type(field) == DRIZZLE_COLUMN_TYPE_TINY) and
3187
 
      (drizzle_column_type(field) & DRIZZLE_COLUMN_FLAGS_UNSIGNED))
3188
 
    {
3189
 
      // Room for "FALSE"
3190
 
      length= 5;
3191
 
    }
3192
3076
    drizzle_column_set_max_size(field, length);
3193
3077
 
3194
3078
    for (x=0; x< (length+2); x++)
3204
3088
    for (uint32_t off=0; (field = drizzle_column_next(result)) ; off++)
3205
3089
    {
3206
3090
      uint32_t name_length= (uint32_t) strlen(drizzle_column_name(field));
3207
 
      uint32_t numcells= drizzled::utf8::char_length(drizzle_column_name(field));
 
3091
      uint32_t numcells= charset_info->cset->numcells(charset_info,
 
3092
                                                  drizzle_column_name(field),
 
3093
                                                  drizzle_column_name(field) +
 
3094
                                                  name_length);
3208
3095
      uint32_t display_length= drizzle_column_max_size(field) + name_length -
3209
3096
                               numcells;
3210
3097
      tee_fprintf(PAGER, " %-*s |",(int) min(display_length,
3212
3099
                  drizzle_column_name(field));
3213
3100
      num_flag[off]= ((drizzle_column_type(field) <= DRIZZLE_COLUMN_TYPE_LONGLONG) ||
3214
3101
                      (drizzle_column_type(field) == DRIZZLE_COLUMN_TYPE_NEWDECIMAL));
3215
 
      if ((server_type == ServerDetect::SERVER_DRIZZLE_FOUND) and
3216
 
        (drizzle_column_type(field) == DRIZZLE_COLUMN_TYPE_TINY))
3217
 
      {
3218
 
        if ((drizzle_column_flags(field) & DRIZZLE_COLUMN_FLAGS_UNSIGNED))
3219
 
        {
3220
 
          ansi_boolean_flag[off]= true;
3221
 
        }
3222
 
        else
3223
 
        {
3224
 
          ansi_boolean_flag[off]= false;
3225
 
        }
3226
 
        boolean_flag[off]= true;
3227
 
        num_flag[off]= false;
3228
 
      }
3229
 
      else
3230
 
      {
3231
 
        boolean_flag[off]= false;
3232
 
      }
3233
3102
    }
3234
3103
    (void) tee_fputs("\n", PAGER);
3235
3104
    tee_puts((char*) separator.c_str(), PAGER);
3268
3137
        buffer= "NULL";
3269
3138
        data_length= 4;
3270
3139
      }
3271
 
      else if (boolean_flag[off])
3272
 
      {
3273
 
        if (strncmp(cur[off],"1", 1) == 0)
3274
 
        {
3275
 
          if (ansi_boolean_flag[off])
3276
 
          {
3277
 
            buffer= "YES";
3278
 
            data_length= 3;
3279
 
          }
3280
 
          else
3281
 
          {
3282
 
            buffer= "TRUE";
3283
 
            data_length= 4;
3284
 
          }
3285
 
        }
3286
 
        else
3287
 
        {
3288
 
          if (ansi_boolean_flag[off])
3289
 
          {
3290
 
            buffer= "NO";
3291
 
            data_length= 2;
3292
 
          }
3293
 
          else
3294
 
          {
3295
 
            buffer= "FALSE";
3296
 
            data_length= 5;
3297
 
          }
3298
 
        }
3299
 
      }
3300
3140
      else
3301
3141
      {
3302
3142
        buffer= cur[off];
3314
3154
        We need to find how much screen real-estate we will occupy to know how
3315
3155
        many extra padding-characters we should send with the printing function.
3316
3156
      */
3317
 
      visible_length= drizzled::utf8::char_length(buffer);
 
3157
      visible_length= charset_info->cset->numcells(charset_info, buffer, buffer + data_length);
3318
3158
      extra_padding= data_length - visible_length;
3319
3159
 
3320
3160
      if (field_max_length > MAX_COLUMN_LENGTH)
3334
3174
      drizzle_row_free(result, cur);
3335
3175
  }
3336
3176
  tee_puts(separator.c_str(), PAGER);
 
3177
  free(num_flag);
3337
3178
}
3338
3179
 
3339
3180
/**
3481
3322
  drizzle_row_t cur;
3482
3323
  uint64_t num_rows;
3483
3324
  uint32_t new_code= 0;
3484
 
  FILE *out;
3485
3325
 
3486
3326
  /* Get the warnings */
3487
3327
  query= "show warnings";
3507
3347
  }
3508
3348
 
3509
3349
  /* Print the warnings */
3510
 
  if (status.getBatch()) 
3511
 
  {
3512
 
    out= stderr;
3513
 
  } 
3514
 
  else 
3515
 
  {
3516
 
    init_pager();
3517
 
    out= PAGER;
3518
 
  }
 
3350
  init_pager();
3519
3351
  do
3520
3352
  {
3521
 
    tee_fprintf(out, "%s (Code %s): %s\n", cur[0], cur[1], cur[2]);
 
3353
    tee_fprintf(PAGER, "%s (Code %s): %s\n", cur[0], cur[1], cur[2]);
3522
3354
  } while ((cur= drizzle_row_next(&result)));
3523
 
 
3524
 
  if (not status.getBatch())
3525
 
    end_pager();
 
3355
  end_pager();
3526
3356
 
3527
3357
end:
3528
3358
  drizzle_result_free(&result);
3541
3371
    else for (const char *end=pos+length ; pos != end ; pos++)
3542
3372
    {
3543
3373
      int l;
3544
 
      if ((l = drizzled::utf8::sequence_length(*pos)))
 
3374
      if (use_mb(charset_info) &&
 
3375
          (l = my_ismbchar(charset_info, pos, end)))
3545
3376
      {
3546
3377
        while (l--)
3547
3378
          tee_putc(*pos++, PAGER);
3570
3401
  drizzle_return_t ret;
3571
3402
  drizzle_column_st *field;
3572
3403
  size_t *lengths;
3573
 
  std::vector<bool> boolean_flag;
3574
 
  std::vector<bool> ansi_boolean_flag;
3575
 
 
3576
 
  boolean_flag.resize(drizzle_result_column_count(result));
3577
 
  ansi_boolean_flag.resize(drizzle_result_column_count(result));
3578
 
 
3579
 
  int first=0;
3580
 
  for (uint32_t off= 0; (field = drizzle_column_next(result)); off++)
 
3404
 
 
3405
  if (opt_silent < 2 && column_names)
3581
3406
  {
3582
 
    if (opt_silent < 2 && column_names)
 
3407
    int first=0;
 
3408
    while ((field = drizzle_column_next(result)))
3583
3409
    {
3584
3410
      if (first++)
3585
3411
        (void) tee_fputs("\t", PAGER);
3586
3412
      (void) tee_fputs(drizzle_column_name(field), PAGER);
3587
3413
    }
3588
 
    if ((server_type == ServerDetect::SERVER_DRIZZLE_FOUND) and
3589
 
      (drizzle_column_type(field) == DRIZZLE_COLUMN_TYPE_TINY))
3590
 
    {
3591
 
      if ((drizzle_column_flags(field) & DRIZZLE_COLUMN_FLAGS_UNSIGNED))
3592
 
      {
3593
 
        ansi_boolean_flag[off]= true;
3594
 
      }
3595
 
      else
3596
 
      {
3597
 
        ansi_boolean_flag[off]= false;
3598
 
      }
3599
 
      boolean_flag[off]= true;
3600
 
    }
3601
 
    else
3602
 
    {
3603
 
      boolean_flag[off]= false;
3604
 
    }
3605
 
  }
3606
 
  if (opt_silent < 2 && column_names)
3607
 
  {
3608
3414
    (void) tee_fputs("\n", PAGER);
3609
3415
  }
3610
3416
  while (1)
3625
3431
      break;
3626
3432
 
3627
3433
    lengths= drizzle_row_field_sizes(result);
3628
 
    drizzle_column_seek(result, 0);
3629
 
    for (uint32_t off=0 ; off < drizzle_result_column_count(result); off++)
 
3434
    safe_put_field(cur[0],lengths[0]);
 
3435
    for (uint32_t off=1 ; off < drizzle_result_column_count(result); off++)
3630
3436
    {
3631
 
      if (off != 0)
3632
 
        (void) tee_fputs("\t", PAGER);
3633
 
      if (boolean_flag[off])
3634
 
      {
3635
 
        if (strncmp(cur[off],"1", 1) == 0)
3636
 
        {
3637
 
          if (ansi_boolean_flag[off])
3638
 
          {
3639
 
            safe_put_field("YES", 3);
3640
 
          }
3641
 
          else
3642
 
          {
3643
 
            safe_put_field("TRUE", 4);
3644
 
          }
3645
 
        }
3646
 
        else
3647
 
        {
3648
 
          if (ansi_boolean_flag[off])
3649
 
          {
3650
 
            safe_put_field("NO", 2);
3651
 
          }
3652
 
          else
3653
 
          {
3654
 
            safe_put_field("FALSE", 5);
3655
 
          }
3656
 
        }
3657
 
      }
3658
 
      else
3659
 
      {
3660
 
        safe_put_field(cur[off], lengths[off]);
3661
 
      }
 
3437
      (void) tee_fputs("\t", PAGER);
 
3438
      safe_put_field(cur[off], lengths[off]);
3662
3439
    }
3663
3440
    (void) tee_fputs("\n", PAGER);
3664
3441
    if (quick)
3672
3449
  char file_name[FN_REFLEN], *end;
3673
3450
  const char *param;
3674
3451
 
3675
 
  if (status.getBatch())
 
3452
  if (status.batch)
3676
3453
    return 0;
3677
 
  while (isspace(*line))
 
3454
  while (my_isspace(charset_info,*line))
3678
3455
    line++;
3679
 
  if (!(param =strchr(line, ' '))) // if outfile wasn't given, use the default
 
3456
  if (!(param = strchr(line, ' '))) // if outfile wasn't given, use the default
3680
3457
  {
3681
 
    if (outfile.empty())
 
3458
    if (!strlen(outfile))
3682
3459
    {
3683
 
      printf(_("No previous outfile available, you must give a filename!\n"));
 
3460
      printf("No previous outfile available, you must give a filename!\n");
3684
3461
      return 0;
3685
3462
    }
3686
3463
    else if (opt_outfile)
3687
3464
    {
3688
 
      tee_fprintf(stdout, _("Currently logging to file '%s'\n"), outfile.c_str());
 
3465
      tee_fprintf(stdout, "Currently logging to file '%s'\n", outfile);
3689
3466
      return 0;
3690
3467
    }
3691
3468
    else
3692
 
      param= outfile.c_str();      //resume using the old outfile
 
3469
      param = outfile;      //resume using the old outfile
3693
3470
  }
3694
3471
 
3695
 
  /* @TODO: Replace this with string methods */
3696
3472
  /* eliminate the spaces before the parameters */
3697
 
  while (isspace(*param))
 
3473
  while (my_isspace(charset_info,*param))
3698
3474
    param++;
3699
3475
  strncpy(file_name, param, sizeof(file_name) - 1);
3700
3476
  end= file_name + strlen(file_name);
3701
3477
  /* remove end space from command line */
3702
 
  while (end > file_name && (isspace(end[-1]) ||
3703
 
                             iscntrl(end[-1])))
 
3478
  while (end > file_name && (my_isspace(charset_info,end[-1]) ||
 
3479
                             my_iscntrl(charset_info,end[-1])))
3704
3480
    end--;
3705
3481
  end[0]= 0;
3706
3482
  if (end == file_name)
3707
3483
  {
3708
 
    printf(_("No outfile specified!\n"));
 
3484
    printf("No outfile specified!\n");
3709
3485
    return 0;
3710
3486
  }
3711
3487
  init_tee(file_name);
3718
3494
{
3719
3495
  if (opt_outfile)
3720
3496
    end_tee();
3721
 
  tee_fprintf(stdout, _("Outfile disabled.\n"));
 
3497
  tee_fprintf(stdout, "Outfile disabled.\n");
3722
3498
  return 0;
3723
3499
}
3724
3500
 
3729
3505
static int
3730
3506
com_pager(string *, const char *line)
3731
3507
{
 
3508
  char pager_name[FN_REFLEN], *end;
3732
3509
  const char *param;
3733
3510
 
3734
 
  if (status.getBatch())
 
3511
  if (status.batch)
3735
3512
    return 0;
3736
3513
  /* Skip spaces in front of the pager command */
3737
 
  while (isspace(*line))
 
3514
  while (my_isspace(charset_info, *line))
3738
3515
    line++;
3739
3516
  /* Skip the pager command */
3740
3517
  param= strchr(line, ' ');
3741
3518
  /* Skip the spaces between the command and the argument */
3742
 
  while (param && isspace(*param))
 
3519
  while (param && my_isspace(charset_info, *param))
3743
3520
    param++;
3744
 
  if (!param || (*param == '\0')) // if pager was not given, use the default
 
3521
  if (!param || !strlen(param)) // if pager was not given, use the default
3745
3522
  {
3746
3523
    if (!default_pager_set)
3747
3524
    {
3748
 
      tee_fprintf(stdout, _("Default pager wasn't set, using stdout.\n"));
 
3525
      tee_fprintf(stdout, "Default pager wasn't set, using stdout.\n");
3749
3526
      opt_nopager=1;
3750
 
      pager.assign("stdout");
 
3527
      strcpy(pager, "stdout");
3751
3528
      PAGER= stdout;
3752
3529
      return 0;
3753
3530
    }
3754
 
    pager.assign(default_pager);
 
3531
    strcpy(pager, default_pager);
3755
3532
  }
3756
3533
  else
3757
3534
  {
3758
 
    string pager_name(param);
3759
 
    string::iterator end= pager_name.end();
3760
 
    while (end > pager_name.begin() &&
3761
 
           (isspace(*(end-1)) || iscntrl(*(end-1))))
3762
 
      --end;
3763
 
    pager_name.erase(end, pager_name.end());
3764
 
    pager.assign(pager_name);
3765
 
    default_pager.assign(pager_name);
 
3535
    end= strncpy(pager_name, param, sizeof(pager_name)-1);
 
3536
    end+= strlen(pager_name);
 
3537
    while (end > pager_name && (my_isspace(charset_info,end[-1]) ||
 
3538
                                my_iscntrl(charset_info,end[-1])))
 
3539
      end--;
 
3540
    end[0]=0;
 
3541
    strcpy(pager, pager_name);
 
3542
    strcpy(default_pager, pager_name);
3766
3543
  }
3767
3544
  opt_nopager=0;
3768
 
  tee_fprintf(stdout, _("PAGER set to '%s'\n"), pager.c_str());
 
3545
  tee_fprintf(stdout, "PAGER set to '%s'\n", pager);
3769
3546
  return 0;
3770
3547
}
3771
3548
 
3773
3550
static int
3774
3551
com_nopager(string *, const char *)
3775
3552
{
3776
 
  pager.assign("stdout");
 
3553
  strcpy(pager, "stdout");
3777
3554
  opt_nopager=1;
3778
3555
  PAGER= stdout;
3779
 
  tee_fprintf(stdout, _("PAGER set to stdout\n"));
 
3556
  tee_fprintf(stdout, "PAGER set to stdout\n");
3780
3557
  return 0;
3781
3558
}
3782
3559
 
3786
3563
com_quit(string *, const char *)
3787
3564
{
3788
3565
  /* let the screen auto close on a normal shutdown */
3789
 
  status.setExitStatus(0);
 
3566
  status.exit_status=0;
3790
3567
  return 1;
3791
3568
}
3792
3569
 
3834
3611
    tmp= get_arg(buff, 0);
3835
3612
    if (tmp && *tmp)
3836
3613
    {
3837
 
      current_db.erase();
3838
 
      current_db.assign(tmp);
 
3614
      free(current_db);
 
3615
      current_db= strdup(tmp);
3839
3616
      tmp= get_arg(buff, 1);
3840
3617
      if (tmp)
3841
3618
      {
3842
 
        current_host.erase();
 
3619
        free(current_host);
3843
3620
        current_host=strdup(tmp);
3844
3621
      }
3845
3622
    }
3854
3631
  }
3855
3632
  else
3856
3633
    opt_rehash= 0;
3857
 
  error=sql_connect(current_host, current_db, current_user, opt_password);
 
3634
  error=sql_connect(current_host,current_db,current_user,opt_password,0);
3858
3635
  opt_rehash= save_rehash;
3859
3636
 
3860
3637
  if (connected)
3861
3638
  {
3862
 
    sprintf(buff, _("Connection id:    %u"), drizzle_con_thread_id(&con));
 
3639
    sprintf(buff,"Connection id:    %u",drizzle_con_thread_id(&con));
3863
3640
    put_info(buff,INFO_INFO,0,0);
3864
 
    sprintf(buff, _("Current schema: %.128s\n"),
3865
 
            !current_db.empty() ? current_db.c_str() : _("*** NONE ***"));
 
3641
    sprintf(buff,"Current database: %.128s\n",
 
3642
            current_db ? current_db : "*** NONE ***");
3866
3643
    put_info(buff,INFO_INFO,0,0);
3867
3644
  }
3868
3645
  return error;
3875
3652
  const char *param;
3876
3653
  LineBuffer *line_buff;
3877
3654
  int error;
3878
 
  Status old_status;
 
3655
  STATUS old_status;
3879
3656
  FILE *sql_file;
3880
3657
 
3881
3658
  /* Skip space from file name */
3882
 
  while (isspace(*line))
 
3659
  while (my_isspace(charset_info,*line))
3883
3660
    line++;
3884
3661
  if (!(param = strchr(line, ' ')))    // Skip command name
3885
 
    return put_info(_("Usage: \\. <filename> | source <filename>"),
 
3662
    return put_info("Usage: \\. <filename> | source <filename>",
3886
3663
                    INFO_ERROR, 0,0);
3887
 
  while (isspace(*param))
 
3664
  while (my_isspace(charset_info,*param))
3888
3665
    param++;
3889
3666
  end= strncpy(source_name,param,sizeof(source_name)-1);
3890
3667
  end+= strlen(source_name);
3891
 
  while (end > source_name && (isspace(end[-1]) ||
3892
 
                               iscntrl(end[-1])))
 
3668
  while (end > source_name && (my_isspace(charset_info,end[-1]) ||
 
3669
                               my_iscntrl(charset_info,end[-1])))
3893
3670
    end--;
3894
3671
  end[0]=0;
3895
 
 
 
3672
  unpack_filename(source_name,source_name);
3896
3673
  /* open file name */
3897
3674
  if (!(sql_file = fopen(source_name, "r")))
3898
3675
  {
3899
3676
    char buff[FN_REFLEN+60];
3900
 
    sprintf(buff, _("Failed to open file '%s', error: %d"), source_name,errno);
 
3677
    sprintf(buff,"Failed to open file '%s', error: %d", source_name,errno);
3901
3678
    return put_info(buff, INFO_ERROR, 0 ,0);
3902
3679
  }
3903
3680
 
3905
3682
  if (line_buff == NULL)
3906
3683
  {
3907
3684
    fclose(sql_file);
3908
 
    return put_info(_("Can't initialize LineBuffer"), INFO_ERROR, 0, 0);
 
3685
    return put_info("Can't initialize LineBuffer", INFO_ERROR, 0, 0);
3909
3686
  }
3910
3687
 
3911
3688
  /* Save old status */
3913
3690
  memset(&status, 0, sizeof(status));
3914
3691
 
3915
3692
  // Run in batch mode
3916
 
  status.setBatch(old_status.getBatch());
3917
 
  status.setLineBuff(line_buff);
3918
 
  status.setFileName(source_name);
 
3693
  status.batch=old_status.batch;
 
3694
  status.line_buff=line_buff;
 
3695
  status.file_name=source_name;
3919
3696
  // Empty command buffer
3920
3697
  assert(glob_buffer!=NULL);
3921
3698
  glob_buffer->clear();
3923
3700
  // Continue as before
3924
3701
  status=old_status;
3925
3702
  fclose(sql_file);
3926
 
  delete status.getLineBuff();
3927
 
  line_buff=0;
3928
 
  status.setLineBuff(0);
 
3703
  delete status.line_buff;
 
3704
  line_buff= status.line_buff= 0;
3929
3705
  return error;
3930
3706
}
3931
3707
 
3941
3717
 
3942
3718
  if (!tmp || !*tmp)
3943
3719
  {
3944
 
    put_info(_("DELIMITER must be followed by a 'delimiter' character or string"),
 
3720
    put_info("DELIMITER must be followed by a 'delimiter' character or string",
3945
3721
             INFO_ERROR, 0, 0);
3946
3722
    return 0;
3947
3723
  }
3949
3725
  {
3950
3726
    if (strstr(tmp, "\\"))
3951
3727
    {
3952
 
      put_info(_("DELIMITER cannot contain a backslash character"),
 
3728
      put_info("DELIMITER cannot contain a backslash character",
3953
3729
               INFO_ERROR, 0, 0);
3954
3730
      return 0;
3955
3731
    }
3974
3750
  tmp= get_arg(buff, 0);
3975
3751
  if (!tmp || !*tmp)
3976
3752
  {
3977
 
    put_info(_("USE must be followed by a schema name"), INFO_ERROR, 0, 0);
 
3753
    put_info("USE must be followed by a database name", INFO_ERROR, 0, 0);
3978
3754
    return 0;
3979
3755
  }
3980
3756
  /*
3984
3760
  */
3985
3761
  get_current_db();
3986
3762
 
3987
 
  if (current_db.empty() || strcmp(current_db.c_str(),tmp))
 
3763
  if (!current_db || strcmp(current_db,tmp))
3988
3764
  {
3989
3765
    if (one_database)
3990
3766
    {
4036
3812
      else
4037
3813
        drizzle_result_free(&result);
4038
3814
    }
4039
 
    current_db.erase();
4040
 
    current_db.assign(tmp);
 
3815
    free(current_db);
 
3816
    current_db= strdup(tmp);
4041
3817
    if (select_db > 1)
4042
3818
      build_completion_hash(opt_rehash, 1);
4043
3819
  }
4044
3820
 
4045
 
  put_info(_("Schema changed"),INFO_INFO, 0, 0);
 
3821
  put_info("Database changed",INFO_INFO, 0, 0);
4046
3822
  return 0;
4047
3823
}
4048
3824
 
4049
 
static int com_shutdown(string *, const char *)
4050
 
{
4051
 
  drizzle_result_st result;
4052
 
  drizzle_return_t ret;
4053
 
 
4054
 
  if (verbose)
4055
 
  {
4056
 
    printf(_("shutting down drizzled"));
4057
 
    if (opt_drizzle_port > 0)
4058
 
      printf(_(" on port %d"), opt_drizzle_port);
4059
 
    printf("... ");
4060
 
  }
4061
 
 
4062
 
  if (drizzle_shutdown(&con, &result, DRIZZLE_SHUTDOWN_DEFAULT,
4063
 
                       &ret) == NULL || ret != DRIZZLE_RETURN_OK)
4064
 
  {
4065
 
    if (ret == DRIZZLE_RETURN_ERROR_CODE)
4066
 
    {
4067
 
      fprintf(stderr, _("shutdown failed; error: '%s'"),
4068
 
              drizzle_result_error(&result));
4069
 
      drizzle_result_free(&result);
4070
 
    }
4071
 
    else
4072
 
    {
4073
 
      fprintf(stderr, _("shutdown failed; error: '%s'"),
4074
 
              drizzle_con_error(&con));
4075
 
    }
4076
 
    return false;
4077
 
  }
4078
 
 
4079
 
  drizzle_result_free(&result);
4080
 
 
4081
 
  if (verbose)
4082
 
    printf(_("done\n"));
4083
 
 
4084
 
  return false;
4085
 
}
4086
 
 
4087
3825
static int
4088
3826
com_warnings(string *, const char *)
4089
3827
{
4090
3828
  show_warnings = 1;
4091
 
  put_info(_("Show warnings enabled."),INFO_INFO, 0, 0);
 
3829
  put_info("Show warnings enabled.",INFO_INFO, 0, 0);
4092
3830
  return 0;
4093
3831
}
4094
3832
 
4096
3834
com_nowarnings(string *, const char *)
4097
3835
{
4098
3836
  show_warnings = 0;
4099
 
  put_info(_("Show warnings disabled."),INFO_INFO, 0, 0);
 
3837
  put_info("Show warnings disabled.",INFO_INFO, 0, 0);
4100
3838
  return 0;
4101
3839
}
4102
3840
 
4126
3864
  else
4127
3865
  {
4128
3866
    /* skip leading white spaces */
4129
 
    while (isspace(*ptr))
 
3867
    while (my_isspace(charset_info, *ptr))
4130
3868
      ptr++;
4131
3869
    if (*ptr == '\\') // short command was used
4132
3870
      ptr+= 2;
4133
3871
    else
4134
 
      while (*ptr &&!isspace(*ptr)) // skip command
 
3872
      while (*ptr &&!my_isspace(charset_info, *ptr)) // skip command
4135
3873
        ptr++;
4136
3874
  }
4137
3875
  if (!*ptr)
4138
3876
    return NULL;
4139
 
  while (isspace(*ptr))
 
3877
  while (my_isspace(charset_info, *ptr))
4140
3878
    ptr++;
4141
3879
  if (*ptr == '\'' || *ptr == '\"' || *ptr == '`')
4142
3880
  {
4163
3901
 
4164
3902
 
4165
3903
static int
4166
 
sql_connect(const string &host, const string &database, const string &user, const string &password)
 
3904
sql_connect(char *host,char *database,char *user,char *password,
 
3905
                 uint32_t silent)
4167
3906
{
4168
3907
  drizzle_return_t ret;
 
3908
 
4169
3909
  if (connected)
4170
3910
  {
4171
3911
    connected= 0;
4173
3913
    drizzle_free(&drizzle);
4174
3914
  }
4175
3915
  drizzle_create(&drizzle);
4176
 
 
4177
 
#ifdef DRIZZLE_ADMIN_TOOL
4178
 
  drizzle_con_options_t options= (drizzle_con_options_t) (DRIZZLE_CON_ADMIN | (use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL));
4179
 
#else
4180
 
  drizzle_con_options_t options= (drizzle_con_options_t) (use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL);
4181
 
#endif
4182
 
 
4183
 
  if (drizzle_con_add_tcp(&drizzle, &con, (char *)host.c_str(),
4184
 
    opt_drizzle_port, (char *)user.c_str(),
4185
 
    (char *)password.c_str(), (char *)database.c_str(),
4186
 
    options) == NULL)
 
3916
  if (drizzle_con_add_tcp(&drizzle, &con, host, opt_drizzle_port, user,
 
3917
                          password, database, DRIZZLE_CON_NONE) == NULL)
4187
3918
  {
4188
3919
    (void) put_error(&con, NULL);
4189
3920
    (void) fflush(stdout);
4212
3943
*/
4213
3944
  if ((ret= drizzle_con_connect(&con)) != DRIZZLE_RETURN_OK)
4214
3945
  {
4215
 
 
4216
 
    if (opt_silent < 2)
 
3946
    if (!silent || (ret != DRIZZLE_RETURN_GETADDRINFO &&
 
3947
                    ret != DRIZZLE_RETURN_COULD_NOT_CONNECT))
4217
3948
    {
4218
3949
      (void) put_error(&con, NULL);
4219
3950
      (void) fflush(stdout);
4222
3953
    return -1;          // Retryable
4223
3954
  }
4224
3955
  connected=1;
4225
 
 
4226
 
  ServerDetect server_detect(&con);
4227
 
  server_type= server_detect.getServerType();
4228
 
 
 
3956
/* XXX hmm?
 
3957
  drizzle.reconnect= debug_info_flag; // We want to know if this happens
 
3958
*/
4229
3959
  build_completion_hash(opt_rehash, 1);
4230
3960
  return 0;
4231
3961
}
4242
3972
  drizzle_return_t ret;
4243
3973
 
4244
3974
  tee_puts("--------------", stdout);
4245
 
  printf(_("Drizzle client %s build %s, for %s-%s (%s) using readline %s\n"),
4246
 
         drizzle_version(), VERSION,
4247
 
         HOST_VENDOR, HOST_OS, HOST_CPU,
4248
 
         rl_library_version);
4249
 
 
 
3975
  usage(1);          /* Print version */
4250
3976
  if (connected)
4251
3977
  {
4252
 
    tee_fprintf(stdout, _("\nConnection id:\t\t%lu\n"),drizzle_con_thread_id(&con));
 
3978
    tee_fprintf(stdout, "\nConnection id:\t\t%lu\n",drizzle_con_thread_id(&con));
4253
3979
    /*
4254
3980
      Don't remove "limit 1",
4255
3981
      it is protection againts SQL_SELECT_LIMIT=0
4261
3987
      drizzle_row_t cur=drizzle_row_next(&result);
4262
3988
      if (cur)
4263
3989
      {
4264
 
        tee_fprintf(stdout, _("Current schema:\t%s\n"), cur[0] ? cur[0] : "");
4265
 
        tee_fprintf(stdout, _("Current user:\t\t%s\n"), cur[1]);
 
3990
        tee_fprintf(stdout, "Current database:\t%s\n", cur[0] ? cur[0] : "");
 
3991
        tee_fprintf(stdout, "Current user:\t\t%s\n", cur[1]);
4266
3992
      }
4267
3993
      drizzle_result_free(&result);
4268
3994
    }
4269
3995
    else if (ret == DRIZZLE_RETURN_ERROR_CODE)
4270
3996
      drizzle_result_free(&result);
4271
 
    tee_puts(_("SSL:\t\t\tNot in use"), stdout);
 
3997
    tee_puts("SSL:\t\t\tNot in use", stdout);
4272
3998
  }
4273
3999
  else
4274
4000
  {
4275
4001
    vidattr(A_BOLD);
4276
 
    tee_fprintf(stdout, _("\nNo connection\n"));
 
4002
    tee_fprintf(stdout, "\nNo connection\n");
4277
4003
    vidattr(A_NORMAL);
4278
4004
    return 0;
4279
4005
  }
4280
4006
  if (skip_updates)
4281
4007
  {
4282
4008
    vidattr(A_BOLD);
4283
 
    tee_fprintf(stdout, _("\nAll updates ignored to this schema\n"));
 
4009
    tee_fprintf(stdout, "\nAll updates ignored to this database\n");
4284
4010
    vidattr(A_NORMAL);
4285
4011
  }
4286
 
  tee_fprintf(stdout, _("Current pager:\t\t%s\n"), pager.c_str());
4287
 
  tee_fprintf(stdout, _("Using outfile:\t\t'%s'\n"), opt_outfile ? outfile.c_str() : "");
4288
 
  tee_fprintf(stdout, _("Using delimiter:\t%s\n"), delimiter);
4289
 
  tee_fprintf(stdout, _("Server version:\t\t%s\n"), server_version_string(&con));
4290
 
  tee_fprintf(stdout, _("Protocol:\t\t%s\n"), opt_protocol.c_str());
4291
 
  tee_fprintf(stdout, _("Protocol version:\t%d\n"), drizzle_con_protocol_version(&con));
4292
 
  tee_fprintf(stdout, _("Connection:\t\t%s\n"), drizzle_con_host(&con));
 
4012
  tee_fprintf(stdout, "Current pager:\t\t%s\n", pager);
 
4013
  tee_fprintf(stdout, "Using outfile:\t\t'%s'\n", opt_outfile ? outfile : "");
 
4014
  tee_fprintf(stdout, "Using delimiter:\t%s\n", delimiter);
 
4015
  tee_fprintf(stdout, "Server version:\t\t%s\n", server_version_string(&con));
 
4016
  tee_fprintf(stdout, "Protocol version:\t%d\n", drizzle_con_protocol_version(&con));
 
4017
  tee_fprintf(stdout, "Connection:\t\t%s\n", drizzle_con_host(&con));
4293
4018
/* XXX need to save this from result
4294
4019
  if ((id= drizzleclient_insert_id(&drizzle)))
4295
 
    tee_fprintf(stdout, "Insert id:\t\t%s\n", internal::llstr(id, buff));
 
4020
    tee_fprintf(stdout, "Insert id:\t\t%s\n", llstr(id, buff));
4296
4021
*/
4297
4022
 
4298
 
  if (drizzle_con_uds(&con))
4299
 
    tee_fprintf(stdout, _("UNIX socket:\t\t%s\n"), drizzle_con_uds(&con));
 
4023
  if (strcmp(drizzle_con_uds(&con), ""))
 
4024
    tee_fprintf(stdout, "UNIX socket:\t\t%s\n", drizzle_con_uds(&con));
4300
4025
  else
4301
 
    tee_fprintf(stdout, _("TCP port:\t\t%d\n"), drizzle_con_port(&con));
 
4026
    tee_fprintf(stdout, "TCP port:\t\t%d\n", drizzle_con_port(&con));
4302
4027
 
4303
4028
  if (safe_updates)
4304
4029
  {
4305
4030
    vidattr(A_BOLD);
4306
 
    tee_fprintf(stdout, _("\nNote that you are running in safe_update_mode:\n"));
 
4031
    tee_fprintf(stdout, "\nNote that you are running in safe_update_mode:\n");
4307
4032
    vidattr(A_NORMAL);
4308
 
    tee_fprintf(stdout, _("\
 
4033
    tee_fprintf(stdout, "\
4309
4034
UPDATEs and DELETEs that don't use a key in the WHERE clause are not allowed.\n\
4310
4035
(One can force an UPDATE/DELETE by adding LIMIT # at the end of the command.)\n \
4311
4036
SELECT has an automatic 'LIMIT %lu' if LIMIT is not used.\n             \
4312
 
Max number of examined row combination in a join is set to: %lu\n\n"),
 
4037
Max number of examined row combination in a join is set to: %lu\n\n",
4313
4038
                select_limit, max_join_size);
4314
4039
  }
4315
4040
  tee_puts("--------------\n", stdout);
4362
4087
  FILE *file= (info_type == INFO_ERROR ? stderr : stdout);
4363
4088
  static int inited=0;
4364
4089
 
4365
 
  if (status.getBatch())
 
4090
  if (status.batch)
4366
4091
  {
4367
4092
    if (info_type == INFO_ERROR)
4368
4093
    {
4369
4094
      (void) fflush(file);
4370
 
      fprintf(file,_("ERROR"));
 
4095
      fprintf(file,"ERROR");
4371
4096
      if (error)
4372
4097
      {
4373
4098
        if (sqlstate)
4375
4100
        else
4376
4101
          (void) fprintf(file," %d",error);
4377
4102
      }
4378
 
      if (status.getQueryStartLine() && line_numbers)
 
4103
      if (status.query_start_line && line_numbers)
4379
4104
      {
4380
 
        (void) fprintf(file," at line %"PRIu32,status.getQueryStartLine());
4381
 
        if (status.getFileName())
4382
 
          (void) fprintf(file," in file: '%s'", status.getFileName());
 
4105
        (void) fprintf(file," at line %"PRIu32,status.query_start_line);
 
4106
        if (status.file_name)
 
4107
          (void) fprintf(file," in file: '%s'", status.file_name);
4383
4108
      }
4384
4109
      (void) fprintf(file,": %s\n",str);
4385
4110
      (void) fflush(file);
4410
4135
      if (error)
4411
4136
      {
4412
4137
        if (sqlstate)
4413
 
          (void) tee_fprintf(file, _("ERROR %d (%s): "), error, sqlstate);
 
4138
          (void) tee_fprintf(file, "ERROR %d (%s): ", error, sqlstate);
4414
4139
        else
4415
 
          (void) tee_fprintf(file, _("ERROR %d: "), error);
 
4140
          (void) tee_fprintf(file, "ERROR %d: ", error);
4416
4141
      }
4417
4142
      else
4418
 
        tee_puts(_("ERROR: "), file);
 
4143
        tee_puts("ERROR: ", file);
4419
4144
    }
4420
4145
    else
4421
4146
      vidattr(A_BOLD);
4454
4179
{
4455
4180
  const char *start=  buffer->c_str();
4456
4181
  const char *end= start + (buffer->length());
4457
 
  while (start < end && !isgraph(end[-1]))
 
4182
  while (start < end && !my_isgraph(charset_info,end[-1]))
4458
4183
    end--;
4459
4184
  uint32_t pos_to_truncate= (end-start);
4460
4185
  if (buffer->length() > pos_to_truncate)
4506
4231
}
4507
4232
 
4508
4233
#include <sys/times.h>
 
4234
#ifdef _SC_CLK_TCK        // For mit-pthreads
 
4235
#undef CLOCKS_PER_SEC
 
4236
#define CLOCKS_PER_SEC (sysconf(_SC_CLK_TCK))
 
4237
#endif
4509
4238
 
4510
 
static boost::posix_time::ptime start_timer(void)
 
4239
static uint32_t start_timer(void)
4511
4240
{
4512
 
  return boost::posix_time::microsec_clock::universal_time();
 
4241
  struct tms tms_tmp;
 
4242
  return times(&tms_tmp);
4513
4243
}
4514
4244
 
4515
 
static void nice_time(boost::posix_time::time_duration duration, string &buff)
 
4245
 
 
4246
/**
 
4247
   Write as many as 52+1 bytes to buff, in the form of a legible
 
4248
   duration of time.
 
4249
 
 
4250
   len("4294967296 days, 23 hours, 59 minutes, 60.00 seconds")  ->  52
 
4251
*/
 
4252
static void nice_time(double sec,char *buff,bool part_second)
4516
4253
{
 
4254
  uint32_t tmp;
4517
4255
  ostringstream tmp_buff_str;
4518
4256
 
4519
 
  if (duration.hours() > 0)
4520
 
  {
4521
 
    tmp_buff_str << duration.hours();
4522
 
    if (duration.hours() > 1)
4523
 
      tmp_buff_str << _(" hours ");
4524
 
    else
4525
 
      tmp_buff_str << _(" hour ");
4526
 
  }
4527
 
  if (duration.hours() > 0 || duration.minutes() > 0)
4528
 
  {
4529
 
    tmp_buff_str << duration.minutes() << _(" min ");
4530
 
  }
4531
 
 
4532
 
  tmp_buff_str.precision(duration.num_fractional_digits());
4533
 
 
4534
 
  double seconds= duration.fractional_seconds();
4535
 
 
4536
 
  seconds/= pow(10.0,duration.num_fractional_digits());
4537
 
 
4538
 
  seconds+= duration.seconds();
4539
 
  tmp_buff_str << seconds << _(" sec");
4540
 
 
4541
 
  buff.append(tmp_buff_str.str());
4542
 
}
4543
 
 
4544
 
static void end_timer(boost::posix_time::ptime start_time, string &buff)
4545
 
{
4546
 
  boost::posix_time::ptime end_time= start_timer();
4547
 
  boost::posix_time::time_period duration(start_time, end_time);
4548
 
 
4549
 
  nice_time(duration.length(), buff);
4550
 
}
4551
 
 
4552
 
 
4553
 
static void drizzle_end_timer(boost::posix_time::ptime start_time, string &buff)
4554
 
{
4555
 
  buff.append(" (");
4556
 
  end_timer(start_time,buff);
4557
 
  buff.append(")");
 
4257
  if (sec >= 3600.0*24)
 
4258
  {
 
4259
    tmp=(uint32_t) floor(sec/(3600.0*24));
 
4260
    sec-= 3600.0*24*tmp;
 
4261
    tmp_buff_str << tmp;
 
4262
 
 
4263
    if (tmp > 1)
 
4264
      tmp_buff_str << " days ";
 
4265
    else
 
4266
      tmp_buff_str << " day ";
 
4267
 
 
4268
  }
 
4269
  if (sec >= 3600.0)
 
4270
  {
 
4271
    tmp=(uint32_t) floor(sec/3600.0);
 
4272
    sec-=3600.0*tmp;
 
4273
    tmp_buff_str << tmp;
 
4274
 
 
4275
    if (tmp > 1)
 
4276
      tmp_buff_str << " hours ";
 
4277
    else
 
4278
      tmp_buff_str << " hour ";
 
4279
  }
 
4280
  if (sec >= 60.0)
 
4281
  {
 
4282
    tmp=(uint32_t) floor(sec/60.0);
 
4283
    sec-=60.0*tmp;
 
4284
    tmp_buff_str << tmp << " min ";
 
4285
  }
 
4286
  if (part_second)
 
4287
    tmp_buff_str.precision(2);
 
4288
  else
 
4289
    tmp_buff_str.precision(0);
 
4290
  tmp_buff_str << sec << " sec";
 
4291
  strcpy(buff, tmp_buff_str.str().c_str());
 
4292
}
 
4293
 
 
4294
 
 
4295
static void end_timer(uint32_t start_time,char *buff)
 
4296
{
 
4297
  nice_time((double) (start_timer() - start_time) /
 
4298
            CLOCKS_PER_SEC,buff,1);
 
4299
}
 
4300
 
 
4301
 
 
4302
static void drizzle_end_timer(uint32_t start_time,char *buff)
 
4303
{
 
4304
  buff[0]=' ';
 
4305
  buff[1]='(';
 
4306
  end_timer(start_time,buff+2);
 
4307
  strcpy(strchr(buff, '\0'),")");
4558
4308
}
4559
4309
 
4560
4310
static const char * construct_prompt()
4568
4318
  struct tm *t = localtime(&lclock);
4569
4319
 
4570
4320
  /* parse thru the settings for the prompt */
4571
 
  string::iterator c= current_prompt.begin();
4572
 
  while (c != current_prompt.end())
 
4321
  for (char *c= current_prompt; *c; (void)*c++)
4573
4322
  {
4574
4323
    if (*c != PROMPT_CHAR)
4575
4324
    {
4576
 
      processed_prompt->push_back(*c);
 
4325
      processed_prompt->append(c, 1);
4577
4326
    }
4578
4327
    else
4579
4328
    {
4584
4333
      switch (*++c) {
4585
4334
      case '\0':
4586
4335
        // stop it from going beyond if ends with %
4587
 
        --c;
 
4336
        c--;
4588
4337
        break;
4589
4338
      case 'c':
4590
4339
        add_int_to_prompt(++prompt_counter);
4596
4345
          processed_prompt->append("not_connected");
4597
4346
        break;
4598
4347
      case 'd':
4599
 
        processed_prompt->append(not current_db.empty() ? current_db : "(none)");
 
4348
        processed_prompt->append(current_db ? current_db : "(none)");
4600
4349
        break;
4601
4350
      case 'h':
4602
4351
      {
4603
 
        const char *prompt= connected ? drizzle_con_host(&con) : "not_connected";
 
4352
        const char *prompt;
 
4353
        prompt= connected ? drizzle_con_host(&con) : "not_connected";
4604
4354
        if (strstr(prompt, "Localhost"))
4605
4355
          processed_prompt->append("localhost");
4606
4356
        else
4619
4369
          break;
4620
4370
        }
4621
4371
 
4622
 
        if (drizzle_con_uds(&con))
 
4372
        if (strcmp(drizzle_con_uds(&con), ""))
4623
4373
        {
4624
4374
          const char *pos=strrchr(drizzle_con_uds(&con),'/');
4625
4375
          processed_prompt->append(pos ? pos+1 : drizzle_con_uds(&con));
4632
4382
        if (!full_username)
4633
4383
          init_username();
4634
4384
        processed_prompt->append(full_username ? full_username :
4635
 
                                 (!current_user.empty() ?  current_user : "(unknown)"));
 
4385
                                 (current_user ?  current_user : "(unknown)"));
4636
4386
        break;
4637
4387
      case 'u':
4638
4388
        if (!full_username)
4639
4389
          init_username();
4640
4390
        processed_prompt->append(part_username ? part_username :
4641
 
                                 (!current_user.empty() ?  current_user : _("(unknown)")));
 
4391
                                 (current_user ?  current_user : "(unknown)"));
4642
4392
        break;
4643
4393
      case PROMPT_CHAR:
4644
4394
        {
4693
4443
        add_int_to_prompt(t->tm_sec);
4694
4444
        break;
4695
4445
      case 'w':
4696
 
        processed_prompt->append(get_day_name(t->tm_wday));
 
4446
        processed_prompt->append(day_names[t->tm_wday]);
4697
4447
        break;
4698
4448
      case 'P':
4699
4449
        processed_prompt->append(t->tm_hour < 12 ? "am" : "pm");
4702
4452
        add_int_to_prompt(t->tm_mon+1);
4703
4453
        break;
4704
4454
      case 'O':
4705
 
        processed_prompt->append(get_month_name(t->tm_mon));
 
4455
        processed_prompt->append(month_names[t->tm_mon]);
4706
4456
        break;
4707
4457
      case '\'':
4708
4458
        processed_prompt->append("'");
4720
4470
        processed_prompt->append(delimiter_str);
4721
4471
        break;
4722
4472
      default:
4723
 
        processed_prompt->push_back(*c);
 
4473
        processed_prompt->append(c, 1);
4724
4474
      }
4725
4475
    }
4726
 
    ++c;
4727
4476
  }
4728
4477
  return processed_prompt->c_str();
4729
4478
}
4758
4507
{
4759
4508
  const char *ptr=strchr(line, ' ');
4760
4509
  if (ptr == NULL)
4761
 
    tee_fprintf(stdout, _("Returning to default PROMPT of %s\n"),
 
4510
    tee_fprintf(stdout, "Returning to default PROMPT of %s\n",
4762
4511
                default_prompt);
4763
4512
  prompt_counter = 0;
4764
4513
  char * tmpptr= strdup(ptr ? ptr+1 : default_prompt);
4765
4514
  if (tmpptr == NULL)
4766
 
    tee_fprintf(stdout, _("Memory allocation error. Not changing prompt\n"));
 
4515
    tee_fprintf(stdout, "Memory allocation error. Not changing prompt\n");
4767
4516
  else
4768
4517
  {
4769
 
    current_prompt.erase();
 
4518
    free(current_prompt);
4770
4519
    current_prompt= tmpptr;
4771
 
    tee_fprintf(stdout, _("PROMPT set to '%s'\n"), current_prompt.c_str());
 
4520
    tee_fprintf(stdout, "PROMPT set to '%s'\n", current_prompt);
4772
4521
  }
4773
4522
  return 0;
4774
4523
}
4779
4528
    if there isn't anything found.
4780
4529
*/
4781
4530
 
4782
 
static const char * strcont(const char *str, const char *set)
 
4531
static const char * strcont(register const char *str, register const char *set)
4783
4532
{
4784
 
  const char * start = (const char *) set;
 
4533
  register const char * start = (const char *) set;
4785
4534
 
4786
4535
  while (*str)
4787
4536
  {