~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzle.cc

  • Committer: Brian Aker
  • Date: 2010-11-11 04:16:59 UTC
  • mto: (1932.2.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 1930.
  • Revision ID: brian@tangent.org-20101111041659-5xb7ymjrasq1520p
Adding in support for EXECUTE to have WITH NO RETURN.

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
4
5
 *  Copyright (C) 2008 MySQL
5
6
 *
6
7
 *  This program is free software; you can redistribute it and/or modify
33
34
 *
34
35
 **/
35
36
 
36
 
#include "client_priv.h"
 
37
#include "config.h"
 
38
#include <libdrizzle/drizzle_client.h>
 
39
 
 
40
#include "client/get_password.h"
 
41
 
 
42
#if TIME_WITH_SYS_TIME
 
43
# include <sys/time.h>
 
44
# include <time.h>
 
45
#else
 
46
# if HAVE_SYS_TIME_H
 
47
#  include <sys/time.h>
 
48
# else
 
49
#  include <time.h>
 
50
# endif
 
51
#endif
 
52
 
 
53
#include <cerrno>
37
54
#include <string>
38
55
#include <drizzled/gettext.h>
39
56
#include <iostream>
 
57
#include <fstream>
40
58
#include <map>
41
59
#include <algorithm>
42
60
#include <limits.h>
43
61
#include <cassert>
44
 
#include "drizzled/charset_info.h"
45
62
#include <stdarg.h>
46
63
#include <math.h>
47
64
#include "client/linebuffer.h"
48
65
#include <signal.h>
49
66
#include <sys/ioctl.h>
50
67
#include <drizzled/configmake.h>
51
 
#include "drizzled/charset.h"
 
68
#include "drizzled/utf8/utf8.h"
 
69
#include <cstdlib>
52
70
 
53
71
#if defined(HAVE_CURSES_H) && defined(HAVE_TERM_H)
54
72
#include <curses.h>
89
107
#  endif /* !defined(HAVE_READLINE_H) */
90
108
char *cmdline = NULL;
91
109
#else /* !defined(HAVE_READLINE_READLINE_H) */
92
 
/* no readline */
 
110
  /* no readline */
93
111
#  error Readline Required
94
112
#endif /* HAVE_LIBREADLINE */
95
113
 
103
121
extern int write_history ();
104
122
extern int read_history ();
105
123
#  endif /* defined(HAVE_READLINE_HISTORY_H) */
106
 
/* no history */
 
124
    /* no history */
107
125
#endif /* HAVE_READLINE_HISTORY */
108
126
 
109
127
/**
110
 
  Make the old readline interface look like the new one.
 
128
 Make the old readline interface look like the new one.
111
129
*/
112
130
#ifndef HAVE_RL_COMPLETION
113
131
typedef char **rl_completion_func_t(const char *, int, int);
139
157
#undef vidattr
140
158
#define vidattr(A) {}      // Can't get this to work
141
159
#endif
 
160
#include <boost/program_options.hpp>
 
161
#include "drizzled/program_options/config_file.h"
142
162
 
143
 
using namespace drizzled;
144
163
using namespace std;
 
164
namespace po=boost::program_options;
 
165
namespace dpo=drizzled::program_options;
145
166
 
146
 
const string VER("14.14");
147
167
/* Don't try to make a nice table if the data is too big */
148
168
const uint32_t MAX_COLUMN_LENGTH= 1024;
149
169
 
151
171
const int MAX_SERVER_VERSION_LENGTH= 128;
152
172
 
153
173
#define PROMPT_CHAR '\\'
154
 
#define DEFAULT_DELIMITER ";"
155
174
 
156
 
typedef struct st_status
 
175
class Status
157
176
{
 
177
public:
 
178
 
 
179
  Status(int in_exit_status, 
 
180
         uint32_t in_query_start_line,
 
181
         char *in_file_name,
 
182
         LineBuffer *in_line_buff,
 
183
         bool in_batch,
 
184
         bool in_add_to_history)
 
185
    :
 
186
    exit_status(in_exit_status),
 
187
    query_start_line(in_query_start_line),
 
188
    file_name(in_file_name),
 
189
    line_buff(in_line_buff),
 
190
    batch(in_batch),
 
191
    add_to_history(in_add_to_history)
 
192
    {}
 
193
 
 
194
  Status() :
 
195
    exit_status(0),
 
196
    query_start_line(0),
 
197
    file_name(NULL),
 
198
    line_buff(NULL),
 
199
    batch(false),        
 
200
    add_to_history(false)
 
201
  {}
 
202
  
 
203
  int getExitStatus() const
 
204
  {
 
205
    return exit_status;
 
206
  }
 
207
 
 
208
  uint32_t getQueryStartLine() const
 
209
  {
 
210
    return query_start_line;
 
211
  }
 
212
 
 
213
  const char *getFileName() const
 
214
  {
 
215
    return file_name;
 
216
  }
 
217
 
 
218
  LineBuffer *getLineBuff() const
 
219
  {
 
220
    return line_buff;
 
221
  }
 
222
 
 
223
  bool getBatch() const
 
224
  {
 
225
    return batch;
 
226
  }
 
227
 
 
228
  bool getAddToHistory() const
 
229
  {
 
230
    return add_to_history;
 
231
  }
 
232
 
 
233
  void setExitStatus(int in_exit_status)
 
234
  {
 
235
    exit_status= in_exit_status;
 
236
  }
 
237
 
 
238
  void setQueryStartLine(uint32_t in_query_start_line)
 
239
  {
 
240
    query_start_line= in_query_start_line;
 
241
  }
 
242
 
 
243
  void setFileName(char *in_file_name)
 
244
  {
 
245
    file_name= in_file_name;
 
246
  }
 
247
 
 
248
  void setLineBuff(int max_size, FILE *file=NULL)
 
249
  {
 
250
    line_buff= new(std::nothrow) LineBuffer(max_size, file);
 
251
  }
 
252
 
 
253
  void setLineBuff(LineBuffer *in_line_buff)
 
254
  {
 
255
    line_buff= in_line_buff;
 
256
  }
 
257
 
 
258
  void setBatch(bool in_batch)
 
259
  {
 
260
    batch= in_batch;
 
261
  }
 
262
 
 
263
  void setAddToHistory(bool in_add_to_history)
 
264
  {
 
265
    add_to_history= in_add_to_history;
 
266
  }
 
267
 
 
268
private:
158
269
  int exit_status;
159
270
  uint32_t query_start_line;
160
271
  char *file_name;
161
272
  LineBuffer *line_buff;
162
273
  bool batch,add_to_history;
163
 
} STATUS;
164
 
 
 
274
}; 
165
275
 
166
276
static map<string, string>::iterator completion_iter;
167
277
static map<string, string>::iterator completion_end;
168
278
static map<string, string> completion_map;
169
279
static string completion_string;
170
280
 
171
 
static char **defaults_argv;
172
281
 
173
282
enum enum_info_type { INFO_INFO,INFO_ERROR,INFO_RESULT};
174
283
typedef enum enum_info_type INFO_TYPE;
176
285
static drizzle_st drizzle;      /* The library handle */
177
286
static drizzle_con_st con;      /* The connection */
178
287
static bool ignore_errors= false, quick= false,
179
 
            connected= false, opt_raw_data= false, unbuffered= false,
180
 
            output_tables= false, opt_rehash= true, skip_updates= false,
181
 
            safe_updates= false, one_database= false,
182
 
            opt_compress= false, opt_shutdown= false, opt_ping= false,
183
 
            vertical= false, line_numbers= true, column_names= true,
184
 
            opt_nopager= true, opt_outfile= false, named_cmds= false,
185
 
            tty_password= false, opt_nobeep= false, opt_reconnect= true,
186
 
            default_charset_used= false, opt_secure_auth= false,
187
 
            default_pager_set= false, opt_sigint_ignore= false,
188
 
            auto_vertical_output= false,
189
 
            show_warnings= false, executing_query= false, interrupted_query= false,
190
 
            opt_mysql= false;
191
 
static uint32_t  show_progress_size= 0;
 
288
  connected= false, opt_raw_data= false, unbuffered= false,
 
289
  output_tables= false, opt_rehash= true, skip_updates= false,
 
290
  safe_updates= false, one_database= false,
 
291
  opt_shutdown= false, opt_ping= false,
 
292
  vertical= false, line_numbers= true, column_names= true,
 
293
  opt_nopager= true, opt_outfile= false, named_cmds= false,
 
294
  opt_nobeep= false, opt_reconnect= true,
 
295
  opt_secure_auth= false,
 
296
  default_pager_set= false, opt_sigint_ignore= false,
 
297
  auto_vertical_output= false,
 
298
  show_warnings= false, executing_query= false, interrupted_query= false,
 
299
  use_drizzle_protocol= false, opt_local_infile;
 
300
static uint32_t show_progress_size= 0;
192
301
static bool column_types_flag;
193
302
static bool preserve_comments= false;
194
 
static uint32_t opt_max_input_line, opt_drizzle_port= 0;
195
 
static int verbose= 0, opt_silent= 0, opt_local_infile= 0;
 
303
static uint32_t opt_max_input_line;
 
304
static uint32_t opt_drizzle_port= 0;
 
305
static int  opt_silent, verbose= 0;
196
306
static drizzle_capabilities_t connect_flag= DRIZZLE_CAPABILITIES_NONE;
197
 
static char *current_host, *current_db, *current_user= NULL,
198
 
            *opt_password= NULL, *delimiter_str= NULL, *current_prompt= NULL;
199
307
static char *histfile;
200
308
static char *histfile_tmp;
201
309
static string *glob_buffer;
202
310
static string *processed_prompt= NULL;
203
311
static char *default_prompt= NULL;
204
312
static char *full_username= NULL,*part_username= NULL;
205
 
static STATUS status;
 
313
static Status status;
206
314
static uint32_t select_limit;
207
315
static uint32_t max_join_size;
208
316
static uint32_t opt_connect_timeout= 0;
 
317
std::string current_db,
 
318
  delimiter_str,  
 
319
  current_host,
 
320
  current_prompt,
 
321
  current_user,
 
322
  opt_verbose,
 
323
  current_password,
 
324
  opt_password,
 
325
  opt_protocol;
209
326
// TODO: Need to i18n these
210
327
static const char *day_names[]= {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
211
328
static const char *month_names[]= {"Jan","Feb","Mar","Apr","May","Jun","Jul",
212
 
  "Aug","Sep","Oct","Nov","Dec"};
213
 
static char default_pager[FN_REFLEN];
214
 
static char pager[FN_REFLEN], outfile[FN_REFLEN];
 
329
                                  "Aug","Sep","Oct","Nov","Dec"};
 
330
/* @TODO: Remove this */
 
331
#define FN_REFLEN 512
 
332
 
 
333
static string default_pager("");
 
334
static string pager("");
 
335
static string outfile("");
215
336
static FILE *PAGER, *OUTFILE;
216
337
static uint32_t prompt_counter;
217
 
static char delimiter[16]= DEFAULT_DELIMITER;
 
338
static char *delimiter= NULL;
218
339
static uint32_t delimiter_length= 1;
219
340
unsigned short terminal_width= 80;
220
341
 
221
 
static const CHARSET_INFO *charset_info= &my_charset_utf8_general_ci;
222
 
 
223
 
int drizzleclient_real_query_for_lazy(const char *buf, int length,
 
342
int drizzleclient_real_query_for_lazy(const char *buf, size_t length,
224
343
                                      drizzle_result_st *result,
225
344
                                      uint32_t *error_code);
226
345
int drizzleclient_store_result_for_lazy(drizzle_result_st *result);
232
351
void tee_putc(int c, FILE *file);
233
352
static void tee_print_sized_data(const char *, unsigned int, unsigned int, bool);
234
353
/* The names of functions that actually do the manipulation. */
235
 
static int get_options(int argc,char **argv);
 
354
static int process_options(void);
236
355
static int com_quit(string *str,const char*),
237
 
           com_go(string *str,const char*), com_ego(string *str,const char*),
238
 
           com_print(string *str,const char*),
239
 
           com_help(string *str,const char*), com_clear(string *str,const char*),
240
 
           com_connect(string *str,const char*), com_status(string *str,const char*),
241
 
           com_use(string *str,const char*), com_source(string *str, const char*),
242
 
           com_rehash(string *str, const char*), com_tee(string *str, const char*),
243
 
           com_notee(string *str, const char*),
244
 
           com_prompt(string *str, const char*), com_delimiter(string *str, const char*),
245
 
           com_warnings(string *str, const char*), com_nowarnings(string *str, const char*),
246
 
           com_nopager(string *str, const char*), com_pager(string *str, const char*);
 
356
  com_go(string *str,const char*), com_ego(string *str,const char*),
 
357
  com_print(string *str,const char*),
 
358
  com_help(string *str,const char*), com_clear(string *str,const char*),
 
359
  com_connect(string *str,const char*), com_status(string *str,const char*),
 
360
  com_use(string *str,const char*), com_source(string *str, const char*),
 
361
  com_rehash(string *str, const char*), com_tee(string *str, const char*),
 
362
  com_notee(string *str, const char*),
 
363
  com_prompt(string *str, const char*), com_delimiter(string *str, const char*),
 
364
  com_warnings(string *str, const char*), com_nowarnings(string *str, const char*),
 
365
  com_nopager(string *str, const char*), com_pager(string *str, const char*);
247
366
 
248
367
static int read_and_execute(bool interactive);
249
 
static int sql_connect(char *host,char *database,char *user,char *password,
 
368
static int sql_connect(const string &host, const string &database, const string &user, const string &password,
250
369
                       uint32_t silent);
251
370
static const char *server_version_string(drizzle_con_st *con);
252
371
static int put_info(const char *str,INFO_TYPE info,uint32_t error,
265
384
static int get_field_disp_length(drizzle_column_st * field);
266
385
static const char * strcont(register const char *str, register const char *set);
267
386
 
268
 
/* A structure which contains information on the commands this program
269
 
  can understand. */
270
 
typedef struct {
 
387
/* A class which contains information on the commands this program
 
388
   can understand. */
 
389
class Commands
 
390
{
 
391
private:
271
392
  const char *name;        /* User printable name of the function. */
272
393
  char cmd_char;        /* msql command character */
273
 
  int (*func)(string *str,const char *); /* Function to call to do the job. */
 
394
public:
 
395
Commands(const char *in_name,
 
396
         char in_cmd_char,
 
397
         int (*in_func)(string *str,const char *name),
 
398
         bool in_takes_params,
 
399
         const char *in_doc)
 
400
  :
 
401
  name(in_name),
 
402
  cmd_char(in_cmd_char),
 
403
  func(in_func),
 
404
  takes_params(in_takes_params),
 
405
  doc(in_doc)
 
406
  {}
 
407
 
 
408
  Commands()
 
409
  :
 
410
  name(),
 
411
  cmd_char(),
 
412
  func(NULL),
 
413
  takes_params(false),
 
414
  doc()
 
415
  {}
 
416
 
 
417
  int (*func)(string *str,const char *);/* Function to call to do the job. */
 
418
 
 
419
  const char *getName() const
 
420
  {
 
421
    return name;
 
422
  }
 
423
 
 
424
  char getCmdChar() const
 
425
  {
 
426
    return cmd_char;
 
427
  }
 
428
 
 
429
  bool getTakesParams() const
 
430
  {
 
431
    return takes_params;
 
432
  }
 
433
 
 
434
  const char *getDoc() const
 
435
  {
 
436
    return doc;
 
437
  }
 
438
 
 
439
  void setName(const char *in_name)
 
440
  {
 
441
     name= in_name;
 
442
  }
 
443
 
 
444
  void setCmdChar(char in_cmd_char)
 
445
  {
 
446
    cmd_char= in_cmd_char;
 
447
  }
 
448
 
 
449
  void setTakesParams(bool in_takes_params)
 
450
  {
 
451
    takes_params= in_takes_params;
 
452
  }
 
453
 
 
454
  void setDoc(const char *in_doc)
 
455
  {
 
456
    doc= in_doc;
 
457
  }
 
458
 
 
459
private:
274
460
  bool takes_params;        /* Max parameters for command */
275
461
  const char *doc;        /* Documentation for this function.  */
276
 
} COMMANDS;
277
 
 
278
 
 
279
 
static COMMANDS commands[] = {
280
 
  { "?",      '?', com_help,   0, N_("Synonym for `help'.") },
281
 
  { "clear",  'c', com_clear,  0, N_("Clear command.")},
282
 
  { "connect",'r', com_connect,1,
283
 
    N_("Reconnect to the server. Optional arguments are db and host.")},
284
 
  { "delimiter", 'd', com_delimiter,    1,
285
 
    N_("Set statement delimiter. NOTE: Takes the rest of the line as new delimiter.") },
286
 
  { "ego",    'G', com_ego,    0,
287
 
    N_("Send command to drizzle server, display result vertically.")},
288
 
  { "exit",   'q', com_quit,   0, N_("Exit drizzle. Same as quit.")},
289
 
  { "go",     'g', com_go,     0, N_("Send command to drizzle server.") },
290
 
  { "help",   'h', com_help,   0, N_("Display this help.") },
291
 
  { "nopager",'n', com_nopager,0, N_("Disable pager, print to stdout.") },
292
 
  { "notee",  't', com_notee,  0, N_("Don't write into outfile.") },
293
 
  { "pager",  'P', com_pager,  1,
294
 
    N_("Set PAGER [to_pager]. Print the query results via PAGER.") },
295
 
  { "print",  'p', com_print,  0, N_("Print current command.") },
296
 
  { "prompt", 'R', com_prompt, 1, N_("Change your drizzle prompt.")},
297
 
  { "quit",   'q', com_quit,   0, N_("Quit drizzle.") },
298
 
  { "rehash", '#', com_rehash, 0, N_("Rebuild completion hash.") },
299
 
  { "source", '.', com_source, 1,
300
 
    N_("Execute an SQL script file. Takes a file name as an argument.")},
301
 
  { "status", 's', com_status, 0, N_("Get status information from the server.")},
302
 
  { "tee",    'T', com_tee,    1,
303
 
    N_("Set outfile [to_outfile]. Append everything into given outfile.") },
304
 
  { "use",    'u', com_use,    1,
305
 
    N_("Use another database. Takes database name as argument.") },
306
 
  { "warnings", 'W', com_warnings,  0,
307
 
    N_("Show warnings after every statement.") },
308
 
  { "nowarning", 'w', com_nowarnings, 0,
309
 
    N_("Don't show warnings after every statement.") },
 
462
}; 
 
463
 
 
464
 
 
465
static Commands commands[] = {
 
466
  Commands( "?",      '?', com_help,   0, N_("Synonym for `help'.") ),
 
467
  Commands( "clear",  'c', com_clear,  0, N_("Clear command.")),
 
468
  Commands( "connect",'r', com_connect,1,
 
469
    N_("Reconnect to the server. Optional arguments are db and host.")),
 
470
  Commands( "delimiter", 'd', com_delimiter,    1,
 
471
    N_("Set statement delimiter. NOTE: Takes the rest of the line as new delimiter.") ),
 
472
  Commands( "ego",    'G', com_ego,    0,
 
473
    N_("Send command to drizzle server, display result vertically.")),
 
474
  Commands( "exit",   'q', com_quit,   0, N_("Exit drizzle. Same as quit.")),
 
475
  Commands( "go",     'g', com_go,     0, N_("Send command to drizzle server.") ),
 
476
  Commands( "help",   'h', com_help,   0, N_("Display this help.") ),
 
477
  Commands( "nopager",'n', com_nopager,0, N_("Disable pager, print to stdout.") ),
 
478
  Commands( "notee",  't', com_notee,  0, N_("Don't write into outfile.") ),
 
479
  Commands( "pager",  'P', com_pager,  1,
 
480
    N_("Set PAGER [to_pager]. Print the query results via PAGER.") ),
 
481
  Commands( "print",  'p', com_print,  0, N_("Print current command.") ),
 
482
  Commands( "prompt", 'R', com_prompt, 1, N_("Change your drizzle prompt.")),
 
483
  Commands( "quit",   'q', com_quit,   0, N_("Quit drizzle.") ),
 
484
  Commands( "rehash", '#', com_rehash, 0, N_("Rebuild completion hash.") ),
 
485
  Commands( "source", '.', com_source, 1,
 
486
    N_("Execute an SQL script file. Takes a file name as an argument.")),
 
487
  Commands( "status", 's', com_status, 0, N_("Get status information from the server.")),
 
488
  Commands( "tee",    'T', com_tee,    1,
 
489
    N_("Set outfile [to_outfile]. Append everything into given outfile.") ),
 
490
  Commands( "use",    'u', com_use,    1,
 
491
    N_("Use another database. Takes database name as argument.") ),
 
492
  Commands( "warnings", 'W', com_warnings,  0,
 
493
    N_("Show warnings after every statement.") ),
 
494
  Commands( "nowarning", 'w', com_nowarnings, 0,
 
495
    N_("Don't show warnings after every statement.") ),
310
496
  /* Get bash-like expansion for some commands */
311
 
  { "create table",     0, 0, 0, ""},
312
 
  { "create database",  0, 0, 0, ""},
313
 
  { "show databases",   0, 0, 0, ""},
314
 
  { "show fields from", 0, 0, 0, ""},
315
 
  { "show keys from",   0, 0, 0, ""},
316
 
  { "show tables",      0, 0, 0, ""},
317
 
  { "load data from",   0, 0, 0, ""},
318
 
  { "alter table",      0, 0, 0, ""},
319
 
  { "set option",       0, 0, 0, ""},
320
 
  { "lock tables",      0, 0, 0, ""},
321
 
  { "unlock tables",    0, 0, 0, ""},
 
497
  Commands( "create table",     0, 0, 0, ""),
 
498
  Commands( "create database",  0, 0, 0, ""),
 
499
  Commands( "show databases",   0, 0, 0, ""),
 
500
  Commands( "show fields from", 0, 0, 0, ""),
 
501
  Commands( "show keys from",   0, 0, 0, ""),
 
502
  Commands( "show tables",      0, 0, 0, ""),
 
503
  Commands( "load data from",   0, 0, 0, ""),
 
504
  Commands( "alter table",      0, 0, 0, ""),
 
505
  Commands( "set option",       0, 0, 0, ""),
 
506
  Commands( "lock tables",      0, 0, 0, ""),
 
507
  Commands( "unlock tables",    0, 0, 0, ""),
322
508
  /* generated 2006-12-28.  Refresh occasionally from lexer. */
323
 
  { "ACTION", 0, 0, 0, ""},
324
 
  { "ADD", 0, 0, 0, ""},
325
 
  { "AFTER", 0, 0, 0, ""},
326
 
  { "AGAINST", 0, 0, 0, ""},
327
 
  { "AGGREGATE", 0, 0, 0, ""},
328
 
  { "ALL", 0, 0, 0, ""},
329
 
  { "ALGORITHM", 0, 0, 0, ""},
330
 
  { "ALTER", 0, 0, 0, ""},
331
 
  { "ANALYZE", 0, 0, 0, ""},
332
 
  { "AND", 0, 0, 0, ""},
333
 
  { "ANY", 0, 0, 0, ""},
334
 
  { "AS", 0, 0, 0, ""},
335
 
  { "ASC", 0, 0, 0, ""},
336
 
  { "ASCII", 0, 0, 0, ""},
337
 
  { "ASENSITIVE", 0, 0, 0, ""},
338
 
  { "AUTO_INCREMENT", 0, 0, 0, ""},
339
 
  { "AVG", 0, 0, 0, ""},
340
 
  { "AVG_ROW_LENGTH", 0, 0, 0, ""},
341
 
  { "BACKUP", 0, 0, 0, ""},
342
 
  { "BDB", 0, 0, 0, ""},
343
 
  { "BEFORE", 0, 0, 0, ""},
344
 
  { "BEGIN", 0, 0, 0, ""},
345
 
  { "BERKELEYDB", 0, 0, 0, ""},
346
 
  { "BETWEEN", 0, 0, 0, ""},
347
 
  { "BIGINT", 0, 0, 0, ""},
348
 
  { "BINARY", 0, 0, 0, ""},
349
 
  { "BINLOG", 0, 0, 0, ""},
350
 
  { "BIT", 0, 0, 0, ""},
351
 
  { "BLOB", 0, 0, 0, ""},
352
 
  { "BOOL", 0, 0, 0, ""},
353
 
  { "BOOLEAN", 0, 0, 0, ""},
354
 
  { "BOTH", 0, 0, 0, ""},
355
 
  { "BTREE", 0, 0, 0, ""},
356
 
  { "BY", 0, 0, 0, ""},
357
 
  { "BYTE", 0, 0, 0, ""},
358
 
  { "CACHE", 0, 0, 0, ""},
359
 
  { "CALL", 0, 0, 0, ""},
360
 
  { "CASCADE", 0, 0, 0, ""},
361
 
  { "CASCADED", 0, 0, 0, ""},
362
 
  { "CASE", 0, 0, 0, ""},
363
 
  { "CHAIN", 0, 0, 0, ""},
364
 
  { "CHANGE", 0, 0, 0, ""},
365
 
  { "CHANGED", 0, 0, 0, ""},
366
 
  { "CHAR", 0, 0, 0, ""},
367
 
  { "CHARACTER", 0, 0, 0, ""},
368
 
  { "CHARSET", 0, 0, 0, ""},
369
 
  { "CHECK", 0, 0, 0, ""},
370
 
  { "CHECKSUM", 0, 0, 0, ""},
371
 
  { "CIPHER", 0, 0, 0, ""},
372
 
  { "CLIENT", 0, 0, 0, ""},
373
 
  { "CLOSE", 0, 0, 0, ""},
374
 
  { "CODE", 0, 0, 0, ""},
375
 
  { "COLLATE", 0, 0, 0, ""},
376
 
  { "COLLATION", 0, 0, 0, ""},
377
 
  { "COLUMN", 0, 0, 0, ""},
378
 
  { "COLUMNS", 0, 0, 0, ""},
379
 
  { "COMMENT", 0, 0, 0, ""},
380
 
  { "COMMIT", 0, 0, 0, ""},
381
 
  { "COMMITTED", 0, 0, 0, ""},
382
 
  { "COMPACT", 0, 0, 0, ""},
383
 
  { "COMPRESSED", 0, 0, 0, ""},
384
 
  { "CONCURRENT", 0, 0, 0, ""},
385
 
  { "CONDITION", 0, 0, 0, ""},
386
 
  { "CONNECTION", 0, 0, 0, ""},
387
 
  { "CONSISTENT", 0, 0, 0, ""},
388
 
  { "CONSTRAINT", 0, 0, 0, ""},
389
 
  { "CONTAINS", 0, 0, 0, ""},
390
 
  { "CONTINUE", 0, 0, 0, ""},
391
 
  { "CONVERT", 0, 0, 0, ""},
392
 
  { "CREATE", 0, 0, 0, ""},
393
 
  { "CROSS", 0, 0, 0, ""},
394
 
  { "CUBE", 0, 0, 0, ""},
395
 
  { "CURRENT_DATE", 0, 0, 0, ""},
396
 
  { "CURRENT_TIMESTAMP", 0, 0, 0, ""},
397
 
  { "CURRENT_USER", 0, 0, 0, ""},
398
 
  { "CURSOR", 0, 0, 0, ""},
399
 
  { "DATA", 0, 0, 0, ""},
400
 
  { "DATABASE", 0, 0, 0, ""},
401
 
  { "DATABASES", 0, 0, 0, ""},
402
 
  { "DATE", 0, 0, 0, ""},
403
 
  { "DATETIME", 0, 0, 0, ""},
404
 
  { "DAY", 0, 0, 0, ""},
405
 
  { "DAY_HOUR", 0, 0, 0, ""},
406
 
  { "DAY_MICROSECOND", 0, 0, 0, ""},
407
 
  { "DAY_MINUTE", 0, 0, 0, ""},
408
 
  { "DAY_SECOND", 0, 0, 0, ""},
409
 
  { "DEALLOCATE", 0, 0, 0, ""},
410
 
  { "DEC", 0, 0, 0, ""},
411
 
  { "DECIMAL", 0, 0, 0, ""},
412
 
  { "DECLARE", 0, 0, 0, ""},
413
 
  { "DEFAULT", 0, 0, 0, ""},
414
 
  { "DEFINER", 0, 0, 0, ""},
415
 
  { "DELAYED", 0, 0, 0, ""},
416
 
  { "DELAY_KEY_WRITE", 0, 0, 0, ""},
417
 
  { "DELETE", 0, 0, 0, ""},
418
 
  { "DESC", 0, 0, 0, ""},
419
 
  { "DESCRIBE", 0, 0, 0, ""},
420
 
  { "DES_KEY_FILE", 0, 0, 0, ""},
421
 
  { "DETERMINISTIC", 0, 0, 0, ""},
422
 
  { "DIRECTORY", 0, 0, 0, ""},
423
 
  { "DISABLE", 0, 0, 0, ""},
424
 
  { "DISCARD", 0, 0, 0, ""},
425
 
  { "DISTINCT", 0, 0, 0, ""},
426
 
  { "DISTINCTROW", 0, 0, 0, ""},
427
 
  { "DIV", 0, 0, 0, ""},
428
 
  { "DO", 0, 0, 0, ""},
429
 
  { "DOUBLE", 0, 0, 0, ""},
430
 
  { "DROP", 0, 0, 0, ""},
431
 
  { "DUAL", 0, 0, 0, ""},
432
 
  { "DUMPFILE", 0, 0, 0, ""},
433
 
  { "DUPLICATE", 0, 0, 0, ""},
434
 
  { "DYNAMIC", 0, 0, 0, ""},
435
 
  { "EACH", 0, 0, 0, ""},
436
 
  { "ELSE", 0, 0, 0, ""},
437
 
  { "ELSEIF", 0, 0, 0, ""},
438
 
  { "ENABLE", 0, 0, 0, ""},
439
 
  { "ENCLOSED", 0, 0, 0, ""},
440
 
  { "END", 0, 0, 0, ""},
441
 
  { "ENGINE", 0, 0, 0, ""},
442
 
  { "ENGINES", 0, 0, 0, ""},
443
 
  { "ENUM", 0, 0, 0, ""},
444
 
  { "ERRORS", 0, 0, 0, ""},
445
 
  { "ESCAPE", 0, 0, 0, ""},
446
 
  { "ESCAPED", 0, 0, 0, ""},
447
 
  { "EVENTS", 0, 0, 0, ""},
448
 
  { "EXECUTE", 0, 0, 0, ""},
449
 
  { "EXISTS", 0, 0, 0, ""},
450
 
  { "EXIT", 0, 0, 0, ""},
451
 
  { "EXPANSION", 0, 0, 0, ""},
452
 
  { "EXPLAIN", 0, 0, 0, ""},
453
 
  { "EXTENDED", 0, 0, 0, ""},
454
 
  { "FALSE", 0, 0, 0, ""},
455
 
  { "FAST", 0, 0, 0, ""},
456
 
  { "FETCH", 0, 0, 0, ""},
457
 
  { "FIELDS", 0, 0, 0, ""},
458
 
  { "FILE", 0, 0, 0, ""},
459
 
  { "FIRST", 0, 0, 0, ""},
460
 
  { "FIXED", 0, 0, 0, ""},
461
 
  { "FLOAT", 0, 0, 0, ""},
462
 
  { "FLOAT4", 0, 0, 0, ""},
463
 
  { "FLOAT8", 0, 0, 0, ""},
464
 
  { "FLUSH", 0, 0, 0, ""},
465
 
  { "FOR", 0, 0, 0, ""},
466
 
  { "FORCE", 0, 0, 0, ""},
467
 
  { "FOREIGN", 0, 0, 0, ""},
468
 
  { "FOUND", 0, 0, 0, ""},
469
 
  { "FRAC_SECOND", 0, 0, 0, ""},
470
 
  { "FROM", 0, 0, 0, ""},
471
 
  { "FULL", 0, 0, 0, ""},
472
 
  { "FULLTEXT", 0, 0, 0, ""},
473
 
  { "FUNCTION", 0, 0, 0, ""},
474
 
  { "GLOBAL", 0, 0, 0, ""},
475
 
  { "GRANT", 0, 0, 0, ""},
476
 
  { "GRANTS", 0, 0, 0, ""},
477
 
  { "GROUP", 0, 0, 0, ""},
478
 
  { "HANDLER", 0, 0, 0, ""},
479
 
  { "HASH", 0, 0, 0, ""},
480
 
  { "HAVING", 0, 0, 0, ""},
481
 
  { "HELP", 0, 0, 0, ""},
482
 
  { "HIGH_PRIORITY", 0, 0, 0, ""},
483
 
  { "HOSTS", 0, 0, 0, ""},
484
 
  { "HOUR", 0, 0, 0, ""},
485
 
  { "HOUR_MICROSECOND", 0, 0, 0, ""},
486
 
  { "HOUR_MINUTE", 0, 0, 0, ""},
487
 
  { "HOUR_SECOND", 0, 0, 0, ""},
488
 
  { "IDENTIFIED", 0, 0, 0, ""},
489
 
  { "IF", 0, 0, 0, ""},
490
 
  { "IGNORE", 0, 0, 0, ""},
491
 
  { "IMPORT", 0, 0, 0, ""},
492
 
  { "IN", 0, 0, 0, ""},
493
 
  { "INDEX", 0, 0, 0, ""},
494
 
  { "INDEXES", 0, 0, 0, ""},
495
 
  { "INFILE", 0, 0, 0, ""},
496
 
  { "INNER", 0, 0, 0, ""},
497
 
  { "INNOBASE", 0, 0, 0, ""},
498
 
  { "INNODB", 0, 0, 0, ""},
499
 
  { "INOUT", 0, 0, 0, ""},
500
 
  { "INSENSITIVE", 0, 0, 0, ""},
501
 
  { "INSERT", 0, 0, 0, ""},
502
 
  { "INSERT_METHOD", 0, 0, 0, ""},
503
 
  { "INT", 0, 0, 0, ""},
504
 
  { "INT1", 0, 0, 0, ""},
505
 
  { "INT2", 0, 0, 0, ""},
506
 
  { "INT3", 0, 0, 0, ""},
507
 
  { "INT4", 0, 0, 0, ""},
508
 
  { "INT8", 0, 0, 0, ""},
509
 
  { "INTEGER", 0, 0, 0, ""},
510
 
  { "INTERVAL", 0, 0, 0, ""},
511
 
  { "INTO", 0, 0, 0, ""},
512
 
  { "IO_THREAD", 0, 0, 0, ""},
513
 
  { "IS", 0, 0, 0, ""},
514
 
  { "ISOLATION", 0, 0, 0, ""},
515
 
  { "ISSUER", 0, 0, 0, ""},
516
 
  { "ITERATE", 0, 0, 0, ""},
517
 
  { "INVOKER", 0, 0, 0, ""},
518
 
  { "JOIN", 0, 0, 0, ""},
519
 
  { "KEY", 0, 0, 0, ""},
520
 
  { "KEYS", 0, 0, 0, ""},
521
 
  { "KILL", 0, 0, 0, ""},
522
 
  { "LANGUAGE", 0, 0, 0, ""},
523
 
  { "LAST", 0, 0, 0, ""},
524
 
  { "LEADING", 0, 0, 0, ""},
525
 
  { "LEAVE", 0, 0, 0, ""},
526
 
  { "LEAVES", 0, 0, 0, ""},
527
 
  { "LEFT", 0, 0, 0, ""},
528
 
  { "LEVEL", 0, 0, 0, ""},
529
 
  { "LIKE", 0, 0, 0, ""},
530
 
  { "LIMIT", 0, 0, 0, ""},
531
 
  { "LINES", 0, 0, 0, ""},
532
 
  { "LINESTRING", 0, 0, 0, ""},
533
 
  { "LOAD", 0, 0, 0, ""},
534
 
  { "LOCAL", 0, 0, 0, ""},
535
 
  { "LOCALTIMESTAMP", 0, 0, 0, ""},
536
 
  { "LOCK", 0, 0, 0, ""},
537
 
  { "LOCKS", 0, 0, 0, ""},
538
 
  { "LOGS", 0, 0, 0, ""},
539
 
  { "LONG", 0, 0, 0, ""},
540
 
  { "LONGTEXT", 0, 0, 0, ""},
541
 
  { "LOOP", 0, 0, 0, ""},
542
 
  { "LOW_PRIORITY", 0, 0, 0, ""},
543
 
  { "MASTER", 0, 0, 0, ""},
544
 
  { "MASTER_CONNECT_RETRY", 0, 0, 0, ""},
545
 
  { "MASTER_HOST", 0, 0, 0, ""},
546
 
  { "MASTER_LOG_FILE", 0, 0, 0, ""},
547
 
  { "MASTER_LOG_POS", 0, 0, 0, ""},
548
 
  { "MASTER_PASSWORD", 0, 0, 0, ""},
549
 
  { "MASTER_PORT", 0, 0, 0, ""},
550
 
  { "MASTER_SERVER_ID", 0, 0, 0, ""},
551
 
  { "MASTER_SSL", 0, 0, 0, ""},
552
 
  { "MASTER_SSL_CA", 0, 0, 0, ""},
553
 
  { "MASTER_SSL_CAPATH", 0, 0, 0, ""},
554
 
  { "MASTER_SSL_CERT", 0, 0, 0, ""},
555
 
  { "MASTER_SSL_CIPHER", 0, 0, 0, ""},
556
 
  { "MASTER_SSL_KEY", 0, 0, 0, ""},
557
 
  { "MASTER_USER", 0, 0, 0, ""},
558
 
  { "MATCH", 0, 0, 0, ""},
559
 
  { "MAX_CONNECTIONS_PER_HOUR", 0, 0, 0, ""},
560
 
  { "MAX_QUERIES_PER_HOUR", 0, 0, 0, ""},
561
 
  { "MAX_ROWS", 0, 0, 0, ""},
562
 
  { "MAX_UPDATES_PER_HOUR", 0, 0, 0, ""},
563
 
  { "MAX_USER_CONNECTIONS", 0, 0, 0, ""},
564
 
  { "MEDIUM", 0, 0, 0, ""},
565
 
  { "MEDIUMTEXT", 0, 0, 0, ""},
566
 
  { "MERGE", 0, 0, 0, ""},
567
 
  { "MICROSECOND", 0, 0, 0, ""},
568
 
  { "MIDDLEINT", 0, 0, 0, ""},
569
 
  { "MIGRATE", 0, 0, 0, ""},
570
 
  { "MINUTE", 0, 0, 0, ""},
571
 
  { "MINUTE_MICROSECOND", 0, 0, 0, ""},
572
 
  { "MINUTE_SECOND", 0, 0, 0, ""},
573
 
  { "MIN_ROWS", 0, 0, 0, ""},
574
 
  { "MOD", 0, 0, 0, ""},
575
 
  { "MODE", 0, 0, 0, ""},
576
 
  { "MODIFIES", 0, 0, 0, ""},
577
 
  { "MODIFY", 0, 0, 0, ""},
578
 
  { "MONTH", 0, 0, 0, ""},
579
 
  { "MULTILINESTRING", 0, 0, 0, ""},
580
 
  { "MULTIPOINT", 0, 0, 0, ""},
581
 
  { "MULTIPOLYGON", 0, 0, 0, ""},
582
 
  { "MUTEX", 0, 0, 0, ""},
583
 
  { "NAME", 0, 0, 0, ""},
584
 
  { "NAMES", 0, 0, 0, ""},
585
 
  { "NATIONAL", 0, 0, 0, ""},
586
 
  { "NATURAL", 0, 0, 0, ""},
587
 
  { "NDB", 0, 0, 0, ""},
588
 
  { "NDBCLUSTER", 0, 0, 0, ""},
589
 
  { "NCHAR", 0, 0, 0, ""},
590
 
  { "NEW", 0, 0, 0, ""},
591
 
  { "NEXT", 0, 0, 0, ""},
592
 
  { "NO", 0, 0, 0, ""},
593
 
  { "NONE", 0, 0, 0, ""},
594
 
  { "NOT", 0, 0, 0, ""},
595
 
  { "NO_WRITE_TO_BINLOG", 0, 0, 0, ""},
596
 
  { "NULL", 0, 0, 0, ""},
597
 
  { "NUMERIC", 0, 0, 0, ""},
598
 
  { "NVARCHAR", 0, 0, 0, ""},
599
 
  { "OFFSET", 0, 0, 0, ""},
600
 
  { "OLD_PASSWORD", 0, 0, 0, ""},
601
 
  { "ON", 0, 0, 0, ""},
602
 
  { "ONE", 0, 0, 0, ""},
603
 
  { "ONE_SHOT", 0, 0, 0, ""},
604
 
  { "OPEN", 0, 0, 0, ""},
605
 
  { "OPTIMIZE", 0, 0, 0, ""},
606
 
  { "OPTION", 0, 0, 0, ""},
607
 
  { "OPTIONALLY", 0, 0, 0, ""},
608
 
  { "OR", 0, 0, 0, ""},
609
 
  { "ORDER", 0, 0, 0, ""},
610
 
  { "OUT", 0, 0, 0, ""},
611
 
  { "OUTER", 0, 0, 0, ""},
612
 
  { "OUTFILE", 0, 0, 0, ""},
613
 
  { "PACK_KEYS", 0, 0, 0, ""},
614
 
  { "PARTIAL", 0, 0, 0, ""},
615
 
  { "PASSWORD", 0, 0, 0, ""},
616
 
  { "PHASE", 0, 0, 0, ""},
617
 
  { "POINT", 0, 0, 0, ""},
618
 
  { "POLYGON", 0, 0, 0, ""},
619
 
  { "PRECISION", 0, 0, 0, ""},
620
 
  { "PREPARE", 0, 0, 0, ""},
621
 
  { "PREV", 0, 0, 0, ""},
622
 
  { "PRIMARY", 0, 0, 0, ""},
623
 
  { "PRIVILEGES", 0, 0, 0, ""},
624
 
  { "PROCEDURE", 0, 0, 0, ""},
625
 
  { "PROCESS", 0, 0, 0, ""},
626
 
  { "PROCESSLIST", 0, 0, 0, ""},
627
 
  { "PURGE", 0, 0, 0, ""},
628
 
  { "QUARTER", 0, 0, 0, ""},
629
 
  { "QUERY", 0, 0, 0, ""},
630
 
  { "QUICK", 0, 0, 0, ""},
631
 
  { "READ", 0, 0, 0, ""},
632
 
  { "READS", 0, 0, 0, ""},
633
 
  { "REAL", 0, 0, 0, ""},
634
 
  { "RECOVER", 0, 0, 0, ""},
635
 
  { "REDUNDANT", 0, 0, 0, ""},
636
 
  { "REFERENCES", 0, 0, 0, ""},
637
 
  { "REGEXP", 0, 0, 0, ""},
638
 
  { "RELAY_LOG_FILE", 0, 0, 0, ""},
639
 
  { "RELAY_LOG_POS", 0, 0, 0, ""},
640
 
  { "RELAY_THREAD", 0, 0, 0, ""},
641
 
  { "RELEASE", 0, 0, 0, ""},
642
 
  { "RELOAD", 0, 0, 0, ""},
643
 
  { "RENAME", 0, 0, 0, ""},
644
 
  { "REPAIR", 0, 0, 0, ""},
645
 
  { "REPEATABLE", 0, 0, 0, ""},
646
 
  { "REPLACE", 0, 0, 0, ""},
647
 
  { "REPLICATION", 0, 0, 0, ""},
648
 
  { "REPEAT", 0, 0, 0, ""},
649
 
  { "REQUIRE", 0, 0, 0, ""},
650
 
  { "RESET", 0, 0, 0, ""},
651
 
  { "RESTORE", 0, 0, 0, ""},
652
 
  { "RESTRICT", 0, 0, 0, ""},
653
 
  { "RESUME", 0, 0, 0, ""},
654
 
  { "RETURN", 0, 0, 0, ""},
655
 
  { "RETURNS", 0, 0, 0, ""},
656
 
  { "REVOKE", 0, 0, 0, ""},
657
 
  { "RIGHT", 0, 0, 0, ""},
658
 
  { "RLIKE", 0, 0, 0, ""},
659
 
  { "ROLLBACK", 0, 0, 0, ""},
660
 
  { "ROLLUP", 0, 0, 0, ""},
661
 
  { "ROUTINE", 0, 0, 0, ""},
662
 
  { "ROW", 0, 0, 0, ""},
663
 
  { "ROWS", 0, 0, 0, ""},
664
 
  { "ROW_FORMAT", 0, 0, 0, ""},
665
 
  { "RTREE", 0, 0, 0, ""},
666
 
  { "SAVEPOINT", 0, 0, 0, ""},
667
 
  { "SCHEMA", 0, 0, 0, ""},
668
 
  { "SCHEMAS", 0, 0, 0, ""},
669
 
  { "SECOND", 0, 0, 0, ""},
670
 
  { "SECOND_MICROSECOND", 0, 0, 0, ""},
671
 
  { "SECURITY", 0, 0, 0, ""},
672
 
  { "SELECT", 0, 0, 0, ""},
673
 
  { "SENSITIVE", 0, 0, 0, ""},
674
 
  { "SEPARATOR", 0, 0, 0, ""},
675
 
  { "SERIAL", 0, 0, 0, ""},
676
 
  { "SERIALIZABLE", 0, 0, 0, ""},
677
 
  { "SESSION", 0, 0, 0, ""},
678
 
  { "SET", 0, 0, 0, ""},
679
 
  { "SHARE", 0, 0, 0, ""},
680
 
  { "SHOW", 0, 0, 0, ""},
681
 
  { "SHUTDOWN", 0, 0, 0, ""},
682
 
  { "SIGNED", 0, 0, 0, ""},
683
 
  { "SIMPLE", 0, 0, 0, ""},
684
 
  { "SLAVE", 0, 0, 0, ""},
685
 
  { "SNAPSHOT", 0, 0, 0, ""},
686
 
  { "SMALLINT", 0, 0, 0, ""},
687
 
  { "SOME", 0, 0, 0, ""},
688
 
  { "SONAME", 0, 0, 0, ""},
689
 
  { "SOUNDS", 0, 0, 0, ""},
690
 
  { "SPATIAL", 0, 0, 0, ""},
691
 
  { "SPECIFIC", 0, 0, 0, ""},
692
 
  { "SQL", 0, 0, 0, ""},
693
 
  { "SQLEXCEPTION", 0, 0, 0, ""},
694
 
  { "SQLSTATE", 0, 0, 0, ""},
695
 
  { "SQLWARNING", 0, 0, 0, ""},
696
 
  { "SQL_BIG_RESULT", 0, 0, 0, ""},
697
 
  { "SQL_BUFFER_RESULT", 0, 0, 0, ""},
698
 
  { "SQL_CACHE", 0, 0, 0, ""},
699
 
  { "SQL_CALC_FOUND_ROWS", 0, 0, 0, ""},
700
 
  { "SQL_NO_CACHE", 0, 0, 0, ""},
701
 
  { "SQL_SMALL_RESULT", 0, 0, 0, ""},
702
 
  { "SQL_THREAD", 0, 0, 0, ""},
703
 
  { "SQL_TSI_FRAC_SECOND", 0, 0, 0, ""},
704
 
  { "SQL_TSI_SECOND", 0, 0, 0, ""},
705
 
  { "SQL_TSI_MINUTE", 0, 0, 0, ""},
706
 
  { "SQL_TSI_HOUR", 0, 0, 0, ""},
707
 
  { "SQL_TSI_DAY", 0, 0, 0, ""},
708
 
  { "SQL_TSI_WEEK", 0, 0, 0, ""},
709
 
  { "SQL_TSI_MONTH", 0, 0, 0, ""},
710
 
  { "SQL_TSI_QUARTER", 0, 0, 0, ""},
711
 
  { "SQL_TSI_YEAR", 0, 0, 0, ""},
712
 
  { "SSL", 0, 0, 0, ""},
713
 
  { "START", 0, 0, 0, ""},
714
 
  { "STARTING", 0, 0, 0, ""},
715
 
  { "STATUS", 0, 0, 0, ""},
716
 
  { "STOP", 0, 0, 0, ""},
717
 
  { "STORAGE", 0, 0, 0, ""},
718
 
  { "STRAIGHT_JOIN", 0, 0, 0, ""},
719
 
  { "STRING", 0, 0, 0, ""},
720
 
  { "STRIPED", 0, 0, 0, ""},
721
 
  { "SUBJECT", 0, 0, 0, ""},
722
 
  { "SUPER", 0, 0, 0, ""},
723
 
  { "SUSPEND", 0, 0, 0, ""},
724
 
  { "TABLE", 0, 0, 0, ""},
725
 
  { "TABLES", 0, 0, 0, ""},
726
 
  { "TABLESPACE", 0, 0, 0, ""},
727
 
  { "TEMPORARY", 0, 0, 0, ""},
728
 
  { "TEMPTABLE", 0, 0, 0, ""},
729
 
  { "TERMINATED", 0, 0, 0, ""},
730
 
  { "TEXT", 0, 0, 0, ""},
731
 
  { "THEN", 0, 0, 0, ""},
732
 
  { "TIMESTAMP", 0, 0, 0, ""},
733
 
  { "TIMESTAMPADD", 0, 0, 0, ""},
734
 
  { "TIMESTAMPDIFF", 0, 0, 0, ""},
735
 
  { "TINYTEXT", 0, 0, 0, ""},
736
 
  { "TO", 0, 0, 0, ""},
737
 
  { "TRAILING", 0, 0, 0, ""},
738
 
  { "TRANSACTION", 0, 0, 0, ""},
739
 
  { "TRIGGER", 0, 0, 0, ""},
740
 
  { "TRIGGERS", 0, 0, 0, ""},
741
 
  { "TRUE", 0, 0, 0, ""},
742
 
  { "TRUNCATE", 0, 0, 0, ""},
743
 
  { "TYPE", 0, 0, 0, ""},
744
 
  { "TYPES", 0, 0, 0, ""},
745
 
  { "UNCOMMITTED", 0, 0, 0, ""},
746
 
  { "UNDEFINED", 0, 0, 0, ""},
747
 
  { "UNDO", 0, 0, 0, ""},
748
 
  { "UNICODE", 0, 0, 0, ""},
749
 
  { "UNION", 0, 0, 0, ""},
750
 
  { "UNIQUE", 0, 0, 0, ""},
751
 
  { "UNKNOWN", 0, 0, 0, ""},
752
 
  { "UNLOCK", 0, 0, 0, ""},
753
 
  { "UNSIGNED", 0, 0, 0, ""},
754
 
  { "UNTIL", 0, 0, 0, ""},
755
 
  { "UPDATE", 0, 0, 0, ""},
756
 
  { "UPGRADE", 0, 0, 0, ""},
757
 
  { "USAGE", 0, 0, 0, ""},
758
 
  { "USE", 0, 0, 0, ""},
759
 
  { "USER", 0, 0, 0, ""},
760
 
  { "USER_RESOURCES", 0, 0, 0, ""},
761
 
  { "USE_FRM", 0, 0, 0, ""},
762
 
  { "USING", 0, 0, 0, ""},
763
 
  { "UTC_DATE", 0, 0, 0, ""},
764
 
  { "UTC_TIMESTAMP", 0, 0, 0, ""},
765
 
  { "VALUE", 0, 0, 0, ""},
766
 
  { "VALUES", 0, 0, 0, ""},
767
 
  { "VARBINARY", 0, 0, 0, ""},
768
 
  { "VARCHAR", 0, 0, 0, ""},
769
 
  { "VARCHARACTER", 0, 0, 0, ""},
770
 
  { "VARIABLES", 0, 0, 0, ""},
771
 
  { "VARYING", 0, 0, 0, ""},
772
 
  { "WARNINGS", 0, 0, 0, ""},
773
 
  { "WEEK", 0, 0, 0, ""},
774
 
  { "WHEN", 0, 0, 0, ""},
775
 
  { "WHERE", 0, 0, 0, ""},
776
 
  { "WHILE", 0, 0, 0, ""},
777
 
  { "VIEW", 0, 0, 0, ""},
778
 
  { "WITH", 0, 0, 0, ""},
779
 
  { "WORK", 0, 0, 0, ""},
780
 
  { "WRITE", 0, 0, 0, ""},
781
 
  { "X509", 0, 0, 0, ""},
782
 
  { "XOR", 0, 0, 0, ""},
783
 
  { "XA", 0, 0, 0, ""},
784
 
  { "YEAR", 0, 0, 0, ""},
785
 
  { "YEAR_MONTH", 0, 0, 0, ""},
786
 
  { "ZEROFILL", 0, 0, 0, ""},
787
 
  { "ABS", 0, 0, 0, ""},
788
 
  { "ACOS", 0, 0, 0, ""},
789
 
  { "ADDDATE", 0, 0, 0, ""},
790
 
  { "AES_ENCRYPT", 0, 0, 0, ""},
791
 
  { "AES_DECRYPT", 0, 0, 0, ""},
792
 
  { "AREA", 0, 0, 0, ""},
793
 
  { "ASIN", 0, 0, 0, ""},
794
 
  { "ASBINARY", 0, 0, 0, ""},
795
 
  { "ASTEXT", 0, 0, 0, ""},
796
 
  { "ASWKB", 0, 0, 0, ""},
797
 
  { "ASWKT", 0, 0, 0, ""},
798
 
  { "ATAN", 0, 0, 0, ""},
799
 
  { "ATAN2", 0, 0, 0, ""},
800
 
  { "BENCHMARK", 0, 0, 0, ""},
801
 
  { "BIN", 0, 0, 0, ""},
802
 
  { "BIT_OR", 0, 0, 0, ""},
803
 
  { "BIT_AND", 0, 0, 0, ""},
804
 
  { "BIT_XOR", 0, 0, 0, ""},
805
 
  { "CAST", 0, 0, 0, ""},
806
 
  { "CEIL", 0, 0, 0, ""},
807
 
  { "CEILING", 0, 0, 0, ""},
808
 
  { "CENTROID", 0, 0, 0, ""},
809
 
  { "CHAR_LENGTH", 0, 0, 0, ""},
810
 
  { "CHARACTER_LENGTH", 0, 0, 0, ""},
811
 
  { "COALESCE", 0, 0, 0, ""},
812
 
  { "COERCIBILITY", 0, 0, 0, ""},
813
 
  { "COMPRESS", 0, 0, 0, ""},
814
 
  { "CONCAT", 0, 0, 0, ""},
815
 
  { "CONCAT_WS", 0, 0, 0, ""},
816
 
  { "CONNECTION_ID", 0, 0, 0, ""},
817
 
  { "CONV", 0, 0, 0, ""},
818
 
  { "CONVERT_TZ", 0, 0, 0, ""},
819
 
  { "COUNT", 0, 0, 0, ""},
820
 
  { "COS", 0, 0, 0, ""},
821
 
  { "COT", 0, 0, 0, ""},
822
 
  { "CRC32", 0, 0, 0, ""},
823
 
  { "CROSSES", 0, 0, 0, ""},
824
 
  { "CURDATE", 0, 0, 0, ""},
825
 
  { "DATE_ADD", 0, 0, 0, ""},
826
 
  { "DATEDIFF", 0, 0, 0, ""},
827
 
  { "DATE_FORMAT", 0, 0, 0, ""},
828
 
  { "DATE_SUB", 0, 0, 0, ""},
829
 
  { "DAYNAME", 0, 0, 0, ""},
830
 
  { "DAYOFMONTH", 0, 0, 0, ""},
831
 
  { "DAYOFWEEK", 0, 0, 0, ""},
832
 
  { "DAYOFYEAR", 0, 0, 0, ""},
833
 
  { "DECODE", 0, 0, 0, ""},
834
 
  { "DEGREES", 0, 0, 0, ""},
835
 
  { "DES_ENCRYPT", 0, 0, 0, ""},
836
 
  { "DES_DECRYPT", 0, 0, 0, ""},
837
 
  { "DIMENSION", 0, 0, 0, ""},
838
 
  { "DISJOINT", 0, 0, 0, ""},
839
 
  { "ELT", 0, 0, 0, ""},
840
 
  { "ENCODE", 0, 0, 0, ""},
841
 
  { "ENCRYPT", 0, 0, 0, ""},
842
 
  { "ENDPOINT", 0, 0, 0, ""},
843
 
  { "ENVELOPE", 0, 0, 0, ""},
844
 
  { "EQUALS", 0, 0, 0, ""},
845
 
  { "EXTERIORRING", 0, 0, 0, ""},
846
 
  { "EXTRACT", 0, 0, 0, ""},
847
 
  { "EXP", 0, 0, 0, ""},
848
 
  { "EXPORT_SET", 0, 0, 0, ""},
849
 
  { "FIELD", 0, 0, 0, ""},
850
 
  { "FIND_IN_SET", 0, 0, 0, ""},
851
 
  { "FLOOR", 0, 0, 0, ""},
852
 
  { "FORMAT", 0, 0, 0, ""},
853
 
  { "FOUND_ROWS", 0, 0, 0, ""},
854
 
  { "FROM_DAYS", 0, 0, 0, ""},
855
 
  { "FROM_UNIXTIME", 0, 0, 0, ""},
856
 
  { "GET_LOCK", 0, 0, 0, ""},
857
 
  { "GLENGTH", 0, 0, 0, ""},
858
 
  { "GREATEST", 0, 0, 0, ""},
859
 
  { "GROUP_CONCAT", 0, 0, 0, ""},
860
 
  { "GROUP_UNIQUE_USERS", 0, 0, 0, ""},
861
 
  { "HEX", 0, 0, 0, ""},
862
 
  { "IFNULL", 0, 0, 0, ""},
863
 
  { "INET_ATON", 0, 0, 0, ""},
864
 
  { "INET_NTOA", 0, 0, 0, ""},
865
 
  { "INSTR", 0, 0, 0, ""},
866
 
  { "INTERIORRINGN", 0, 0, 0, ""},
867
 
  { "INTERSECTS", 0, 0, 0, ""},
868
 
  { "ISCLOSED", 0, 0, 0, ""},
869
 
  { "ISEMPTY", 0, 0, 0, ""},
870
 
  { "ISNULL", 0, 0, 0, ""},
871
 
  { "IS_FREE_LOCK", 0, 0, 0, ""},
872
 
  { "IS_USED_LOCK", 0, 0, 0, ""},
873
 
  { "LAST_INSERT_ID", 0, 0, 0, ""},
874
 
  { "ISSIMPLE", 0, 0, 0, ""},
875
 
  { "LAST_DAY", 0, 0, 0, ""},
876
 
  { "LCASE", 0, 0, 0, ""},
877
 
  { "LEAST", 0, 0, 0, ""},
878
 
  { "LENGTH", 0, 0, 0, ""},
879
 
  { "LN", 0, 0, 0, ""},
880
 
  { "LINEFROMTEXT", 0, 0, 0, ""},
881
 
  { "LINEFROMWKB", 0, 0, 0, ""},
882
 
  { "LINESTRINGFROMTEXT", 0, 0, 0, ""},
883
 
  { "LINESTRINGFROMWKB", 0, 0, 0, ""},
884
 
  { "LOAD_FILE", 0, 0, 0, ""},
885
 
  { "LOCATE", 0, 0, 0, ""},
886
 
  { "LOG", 0, 0, 0, ""},
887
 
  { "LOG2", 0, 0, 0, ""},
888
 
  { "LOG10", 0, 0, 0, ""},
889
 
  { "LOWER", 0, 0, 0, ""},
890
 
  { "LPAD", 0, 0, 0, ""},
891
 
  { "LTRIM", 0, 0, 0, ""},
892
 
  { "MAKE_SET", 0, 0, 0, ""},
893
 
  { "MAKEDATE", 0, 0, 0, ""},
894
 
  { "MASTER_POS_WAIT", 0, 0, 0, ""},
895
 
  { "MAX", 0, 0, 0, ""},
896
 
  { "MBRCONTAINS", 0, 0, 0, ""},
897
 
  { "MBRDISJOINT", 0, 0, 0, ""},
898
 
  { "MBREQUAL", 0, 0, 0, ""},
899
 
  { "MBRINTERSECTS", 0, 0, 0, ""},
900
 
  { "MBROVERLAPS", 0, 0, 0, ""},
901
 
  { "MBRTOUCHES", 0, 0, 0, ""},
902
 
  { "MBRWITHIN", 0, 0, 0, ""},
903
 
  { "MD5", 0, 0, 0, ""},
904
 
  { "MID", 0, 0, 0, ""},
905
 
  { "MIN", 0, 0, 0, ""},
906
 
  { "MLINEFROMTEXT", 0, 0, 0, ""},
907
 
  { "MLINEFROMWKB", 0, 0, 0, ""},
908
 
  { "MPOINTFROMTEXT", 0, 0, 0, ""},
909
 
  { "MPOINTFROMWKB", 0, 0, 0, ""},
910
 
  { "MPOLYFROMTEXT", 0, 0, 0, ""},
911
 
  { "MPOLYFROMWKB", 0, 0, 0, ""},
912
 
  { "MONTHNAME", 0, 0, 0, ""},
913
 
  { "MULTILINESTRINGFROMTEXT", 0, 0, 0, ""},
914
 
  { "MULTILINESTRINGFROMWKB", 0, 0, 0, ""},
915
 
  { "MULTIPOINTFROMTEXT", 0, 0, 0, ""},
916
 
  { "MULTIPOINTFROMWKB", 0, 0, 0, ""},
917
 
  { "MULTIPOLYGONFROMTEXT", 0, 0, 0, ""},
918
 
  { "MULTIPOLYGONFROMWKB", 0, 0, 0, ""},
919
 
  { "NAME_CONST", 0, 0, 0, ""},
920
 
  { "NOW", 0, 0, 0, ""},
921
 
  { "NULLIF", 0, 0, 0, ""},
922
 
  { "NUMINTERIORRINGS", 0, 0, 0, ""},
923
 
  { "NUMPOINTS", 0, 0, 0, ""},
924
 
  { "OCTET_LENGTH", 0, 0, 0, ""},
925
 
  { "OCT", 0, 0, 0, ""},
926
 
  { "ORD", 0, 0, 0, ""},
927
 
  { "OVERLAPS", 0, 0, 0, ""},
928
 
  { "PERIOD_ADD", 0, 0, 0, ""},
929
 
  { "PERIOD_DIFF", 0, 0, 0, ""},
930
 
  { "PI", 0, 0, 0, ""},
931
 
  { "POINTFROMTEXT", 0, 0, 0, ""},
932
 
  { "POINTFROMWKB", 0, 0, 0, ""},
933
 
  { "POINTN", 0, 0, 0, ""},
934
 
  { "POLYFROMTEXT", 0, 0, 0, ""},
935
 
  { "POLYFROMWKB", 0, 0, 0, ""},
936
 
  { "POLYGONFROMTEXT", 0, 0, 0, ""},
937
 
  { "POLYGONFROMWKB", 0, 0, 0, ""},
938
 
  { "POSITION", 0, 0, 0, ""},
939
 
  { "POW", 0, 0, 0, ""},
940
 
  { "POWER", 0, 0, 0, ""},
941
 
  { "QUOTE", 0, 0, 0, ""},
942
 
  { "RADIANS", 0, 0, 0, ""},
943
 
  { "RAND", 0, 0, 0, ""},
944
 
  { "RELEASE_LOCK", 0, 0, 0, ""},
945
 
  { "REVERSE", 0, 0, 0, ""},
946
 
  { "ROUND", 0, 0, 0, ""},
947
 
  { "ROW_COUNT", 0, 0, 0, ""},
948
 
  { "RPAD", 0, 0, 0, ""},
949
 
  { "RTRIM", 0, 0, 0, ""},
950
 
  { "SESSION_USER", 0, 0, 0, ""},
951
 
  { "SUBDATE", 0, 0, 0, ""},
952
 
  { "SIGN", 0, 0, 0, ""},
953
 
  { "SIN", 0, 0, 0, ""},
954
 
  { "SHA", 0, 0, 0, ""},
955
 
  { "SHA1", 0, 0, 0, ""},
956
 
  { "SLEEP", 0, 0, 0, ""},
957
 
  { "SOUNDEX", 0, 0, 0, ""},
958
 
  { "SPACE", 0, 0, 0, ""},
959
 
  { "SQRT", 0, 0, 0, ""},
960
 
  { "SRID", 0, 0, 0, ""},
961
 
  { "STARTPOINT", 0, 0, 0, ""},
962
 
  { "STD", 0, 0, 0, ""},
963
 
  { "STDDEV", 0, 0, 0, ""},
964
 
  { "STDDEV_POP", 0, 0, 0, ""},
965
 
  { "STDDEV_SAMP", 0, 0, 0, ""},
966
 
  { "STR_TO_DATE", 0, 0, 0, ""},
967
 
  { "STRCMP", 0, 0, 0, ""},
968
 
  { "SUBSTR", 0, 0, 0, ""},
969
 
  { "SUBSTRING", 0, 0, 0, ""},
970
 
  { "SUBSTRING_INDEX", 0, 0, 0, ""},
971
 
  { "SUM", 0, 0, 0, ""},
972
 
  { "SYSDATE", 0, 0, 0, ""},
973
 
  { "SYSTEM_USER", 0, 0, 0, ""},
974
 
  { "TAN", 0, 0, 0, ""},
975
 
  { "TIME_FORMAT", 0, 0, 0, ""},
976
 
  { "TO_DAYS", 0, 0, 0, ""},
977
 
  { "TOUCHES", 0, 0, 0, ""},
978
 
  { "TRIM", 0, 0, 0, ""},
979
 
  { "UCASE", 0, 0, 0, ""},
980
 
  { "UNCOMPRESS", 0, 0, 0, ""},
981
 
  { "UNCOMPRESSED_LENGTH", 0, 0, 0, ""},
982
 
  { "UNHEX", 0, 0, 0, ""},
983
 
  { "UNIQUE_USERS", 0, 0, 0, ""},
984
 
  { "UNIX_TIMESTAMP", 0, 0, 0, ""},
985
 
  { "UPPER", 0, 0, 0, ""},
986
 
  { "UUID", 0, 0, 0, ""},
987
 
  { "VARIANCE", 0, 0, 0, ""},
988
 
  { "VAR_POP", 0, 0, 0, ""},
989
 
  { "VAR_SAMP", 0, 0, 0, ""},
990
 
  { "VERSION", 0, 0, 0, ""},
991
 
  { "WEEKDAY", 0, 0, 0, ""},
992
 
  { "WEEKOFYEAR", 0, 0, 0, ""},
993
 
  { "WITHIN", 0, 0, 0, ""},
994
 
  { "X", 0, 0, 0, ""},
995
 
  { "Y", 0, 0, 0, ""},
996
 
  { "YEARWEEK", 0, 0, 0, ""},
 
509
  Commands( "ACTION", 0, 0, 0, ""),
 
510
  Commands( "ADD", 0, 0, 0, ""),
 
511
  Commands( "AFTER", 0, 0, 0, ""),
 
512
  Commands( "AGAINST", 0, 0, 0, ""),
 
513
  Commands( "AGGREGATE", 0, 0, 0, ""),
 
514
  Commands( "ALL", 0, 0, 0, ""),
 
515
  Commands( "ALGORITHM", 0, 0, 0, ""),
 
516
  Commands( "ALTER", 0, 0, 0, ""),
 
517
  Commands( "ANALYZE", 0, 0, 0, ""),
 
518
  Commands( "AND", 0, 0, 0, ""),
 
519
  Commands( "ANY", 0, 0, 0, ""),
 
520
  Commands( "AS", 0, 0, 0, ""),
 
521
  Commands( "ASC", 0, 0, 0, ""),
 
522
  Commands( "ASCII", 0, 0, 0, ""),
 
523
  Commands( "ASENSITIVE", 0, 0, 0, ""),
 
524
  Commands( "AUTO_INCREMENT", 0, 0, 0, ""),
 
525
  Commands( "AVG", 0, 0, 0, ""),
 
526
  Commands( "AVG_ROW_LENGTH", 0, 0, 0, ""),
 
527
  Commands( "BEFORE", 0, 0, 0, ""),
 
528
  Commands( "BEGIN", 0, 0, 0, ""),
 
529
  Commands( "BETWEEN", 0, 0, 0, ""),
 
530
  Commands( "BIGINT", 0, 0, 0, ""),
 
531
  Commands( "BINARY", 0, 0, 0, ""),
 
532
  Commands( "BIT", 0, 0, 0, ""),
 
533
  Commands( "BLOB", 0, 0, 0, ""),
 
534
  Commands( "BOOL", 0, 0, 0, ""),
 
535
  Commands( "BOOLEAN", 0, 0, 0, ""),
 
536
  Commands( "BOTH", 0, 0, 0, ""),
 
537
  Commands( "BTREE", 0, 0, 0, ""),
 
538
  Commands( "BY", 0, 0, 0, ""),
 
539
  Commands( "BYTE", 0, 0, 0, ""),
 
540
  Commands( "CACHE", 0, 0, 0, ""),
 
541
  Commands( "CALL", 0, 0, 0, ""),
 
542
  Commands( "CASCADE", 0, 0, 0, ""),
 
543
  Commands( "CASCADED", 0, 0, 0, ""),
 
544
  Commands( "CASE", 0, 0, 0, ""),
 
545
  Commands( "CHAIN", 0, 0, 0, ""),
 
546
  Commands( "CHANGE", 0, 0, 0, ""),
 
547
  Commands( "CHANGED", 0, 0, 0, ""),
 
548
  Commands( "CHAR", 0, 0, 0, ""),
 
549
  Commands( "CHARACTER", 0, 0, 0, ""),
 
550
  Commands( "CHECK", 0, 0, 0, ""),
 
551
  Commands( "CHECKSUM", 0, 0, 0, ""),
 
552
  Commands( "CLIENT", 0, 0, 0, ""),
 
553
  Commands( "CLOSE", 0, 0, 0, ""),
 
554
  Commands( "COLLATE", 0, 0, 0, ""),
 
555
  Commands( "COLLATION", 0, 0, 0, ""),
 
556
  Commands( "COLUMN", 0, 0, 0, ""),
 
557
  Commands( "COLUMNS", 0, 0, 0, ""),
 
558
  Commands( "COMMENT", 0, 0, 0, ""),
 
559
  Commands( "COMMIT", 0, 0, 0, ""),
 
560
  Commands( "COMMITTED", 0, 0, 0, ""),
 
561
  Commands( "COMPACT", 0, 0, 0, ""),
 
562
  Commands( "COMPRESSED", 0, 0, 0, ""),
 
563
  Commands( "CONCURRENT", 0, 0, 0, ""),
 
564
  Commands( "CONDITION", 0, 0, 0, ""),
 
565
  Commands( "CONNECTION", 0, 0, 0, ""),
 
566
  Commands( "CONSISTENT", 0, 0, 0, ""),
 
567
  Commands( "CONSTRAINT", 0, 0, 0, ""),
 
568
  Commands( "CONTAINS", 0, 0, 0, ""),
 
569
  Commands( "CONTINUE", 0, 0, 0, ""),
 
570
  Commands( "CONVERT", 0, 0, 0, ""),
 
571
  Commands( "CREATE", 0, 0, 0, ""),
 
572
  Commands( "CROSS", 0, 0, 0, ""),
 
573
  Commands( "CUBE", 0, 0, 0, ""),
 
574
  Commands( "CURRENT_DATE", 0, 0, 0, ""),
 
575
  Commands( "CURRENT_TIMESTAMP", 0, 0, 0, ""),
 
576
  Commands( "CURRENT_USER", 0, 0, 0, ""),
 
577
  Commands( "CURSOR", 0, 0, 0, ""),
 
578
  Commands( "DATA", 0, 0, 0, ""),
 
579
  Commands( "DATABASE", 0, 0, 0, ""),
 
580
  Commands( "DATABASES", 0, 0, 0, ""),
 
581
  Commands( "DATE", 0, 0, 0, ""),
 
582
  Commands( "DATETIME", 0, 0, 0, ""),
 
583
  Commands( "DAY", 0, 0, 0, ""),
 
584
  Commands( "DAY_HOUR", 0, 0, 0, ""),
 
585
  Commands( "DAY_MICROSECOND", 0, 0, 0, ""),
 
586
  Commands( "DAY_MINUTE", 0, 0, 0, ""),
 
587
  Commands( "DAY_SECOND", 0, 0, 0, ""),
 
588
  Commands( "DEALLOCATE", 0, 0, 0, ""),
 
589
  Commands( "DEC", 0, 0, 0, ""),
 
590
  Commands( "DECIMAL", 0, 0, 0, ""),
 
591
  Commands( "DECLARE", 0, 0, 0, ""),
 
592
  Commands( "DEFAULT", 0, 0, 0, ""),
 
593
  Commands( "DEFINER", 0, 0, 0, ""),
 
594
  Commands( "DELAYED", 0, 0, 0, ""),
 
595
  Commands( "DELETE", 0, 0, 0, ""),
 
596
  Commands( "DESC", 0, 0, 0, ""),
 
597
  Commands( "DESCRIBE", 0, 0, 0, ""),
 
598
  Commands( "DETERMINISTIC", 0, 0, 0, ""),
 
599
  Commands( "DISABLE", 0, 0, 0, ""),
 
600
  Commands( "DISCARD", 0, 0, 0, ""),
 
601
  Commands( "DISTINCT", 0, 0, 0, ""),
 
602
  Commands( "DISTINCTROW", 0, 0, 0, ""),
 
603
  Commands( "DIV", 0, 0, 0, ""),
 
604
  Commands( "DOUBLE", 0, 0, 0, ""),
 
605
  Commands( "DROP", 0, 0, 0, ""),
 
606
  Commands( "DUMPFILE", 0, 0, 0, ""),
 
607
  Commands( "DUPLICATE", 0, 0, 0, ""),
 
608
  Commands( "DYNAMIC", 0, 0, 0, ""),
 
609
  Commands( "EACH", 0, 0, 0, ""),
 
610
  Commands( "ELSE", 0, 0, 0, ""),
 
611
  Commands( "ELSEIF", 0, 0, 0, ""),
 
612
  Commands( "ENABLE", 0, 0, 0, ""),
 
613
  Commands( "ENCLOSED", 0, 0, 0, ""),
 
614
  Commands( "END", 0, 0, 0, ""),
 
615
  Commands( "ENGINE", 0, 0, 0, ""),
 
616
  Commands( "ENGINES", 0, 0, 0, ""),
 
617
  Commands( "ENUM", 0, 0, 0, ""),
 
618
  Commands( "ERRORS", 0, 0, 0, ""),
 
619
  Commands( "ESCAPE", 0, 0, 0, ""),
 
620
  Commands( "ESCAPED", 0, 0, 0, ""),
 
621
  Commands( "EXISTS", 0, 0, 0, ""),
 
622
  Commands( "EXIT", 0, 0, 0, ""),
 
623
  Commands( "EXPLAIN", 0, 0, 0, ""),
 
624
  Commands( "EXTENDED", 0, 0, 0, ""),
 
625
  Commands( "FALSE", 0, 0, 0, ""),
 
626
  Commands( "FAST", 0, 0, 0, ""),
 
627
  Commands( "FETCH", 0, 0, 0, ""),
 
628
  Commands( "FIELDS", 0, 0, 0, ""),
 
629
  Commands( "FILE", 0, 0, 0, ""),
 
630
  Commands( "FIRST", 0, 0, 0, ""),
 
631
  Commands( "FIXED", 0, 0, 0, ""),
 
632
  Commands( "FLOAT", 0, 0, 0, ""),
 
633
  Commands( "FLOAT4", 0, 0, 0, ""),
 
634
  Commands( "FLOAT8", 0, 0, 0, ""),
 
635
  Commands( "FLUSH", 0, 0, 0, ""),
 
636
  Commands( "FOR", 0, 0, 0, ""),
 
637
  Commands( "FORCE", 0, 0, 0, ""),
 
638
  Commands( "FOREIGN", 0, 0, 0, ""),
 
639
  Commands( "FOUND", 0, 0, 0, ""),
 
640
  Commands( "FRAC_SECOND", 0, 0, 0, ""),
 
641
  Commands( "FROM", 0, 0, 0, ""),
 
642
  Commands( "FULL", 0, 0, 0, ""),
 
643
  Commands( "FUNCTION", 0, 0, 0, ""),
 
644
  Commands( "GLOBAL", 0, 0, 0, ""),
 
645
  Commands( "GRANT", 0, 0, 0, ""),
 
646
  Commands( "GRANTS", 0, 0, 0, ""),
 
647
  Commands( "GROUP", 0, 0, 0, ""),
 
648
  Commands( "HANDLER", 0, 0, 0, ""),
 
649
  Commands( "HASH", 0, 0, 0, ""),
 
650
  Commands( "HAVING", 0, 0, 0, ""),
 
651
  Commands( "HELP", 0, 0, 0, ""),
 
652
  Commands( "HIGH_PRIORITY", 0, 0, 0, ""),
 
653
  Commands( "HOSTS", 0, 0, 0, ""),
 
654
  Commands( "HOUR", 0, 0, 0, ""),
 
655
  Commands( "HOUR_MICROSECOND", 0, 0, 0, ""),
 
656
  Commands( "HOUR_MINUTE", 0, 0, 0, ""),
 
657
  Commands( "HOUR_SECOND", 0, 0, 0, ""),
 
658
  Commands( "IDENTIFIED", 0, 0, 0, ""),
 
659
  Commands( "IF", 0, 0, 0, ""),
 
660
  Commands( "IGNORE", 0, 0, 0, ""),
 
661
  Commands( "IMPORT", 0, 0, 0, ""),
 
662
  Commands( "IN", 0, 0, 0, ""),
 
663
  Commands( "INDEX", 0, 0, 0, ""),
 
664
  Commands( "INDEXES", 0, 0, 0, ""),
 
665
  Commands( "INFILE", 0, 0, 0, ""),
 
666
  Commands( "INNER", 0, 0, 0, ""),
 
667
  Commands( "INNOBASE", 0, 0, 0, ""),
 
668
  Commands( "INNODB", 0, 0, 0, ""),
 
669
  Commands( "INOUT", 0, 0, 0, ""),
 
670
  Commands( "INSENSITIVE", 0, 0, 0, ""),
 
671
  Commands( "INSERT", 0, 0, 0, ""),
 
672
  Commands( "INSERT_METHOD", 0, 0, 0, ""),
 
673
  Commands( "INT", 0, 0, 0, ""),
 
674
  Commands( "INT1", 0, 0, 0, ""),
 
675
  Commands( "INT2", 0, 0, 0, ""),
 
676
  Commands( "INT3", 0, 0, 0, ""),
 
677
  Commands( "INT4", 0, 0, 0, ""),
 
678
  Commands( "INT8", 0, 0, 0, ""),
 
679
  Commands( "INTEGER", 0, 0, 0, ""),
 
680
  Commands( "INTERVAL", 0, 0, 0, ""),
 
681
  Commands( "INTO", 0, 0, 0, ""),
 
682
  Commands( "IO_THREAD", 0, 0, 0, ""),
 
683
  Commands( "IS", 0, 0, 0, ""),
 
684
  Commands( "ISOLATION", 0, 0, 0, ""),
 
685
  Commands( "ISSUER", 0, 0, 0, ""),
 
686
  Commands( "ITERATE", 0, 0, 0, ""),
 
687
  Commands( "INVOKER", 0, 0, 0, ""),
 
688
  Commands( "JOIN", 0, 0, 0, ""),
 
689
  Commands( "KEY", 0, 0, 0, ""),
 
690
  Commands( "KEYS", 0, 0, 0, ""),
 
691
  Commands( "KILL", 0, 0, 0, ""),
 
692
  Commands( "LANGUAGE", 0, 0, 0, ""),
 
693
  Commands( "LAST", 0, 0, 0, ""),
 
694
  Commands( "LEADING", 0, 0, 0, ""),
 
695
  Commands( "LEAVE", 0, 0, 0, ""),
 
696
  Commands( "LEAVES", 0, 0, 0, ""),
 
697
  Commands( "LEFT", 0, 0, 0, ""),
 
698
  Commands( "LEVEL", 0, 0, 0, ""),
 
699
  Commands( "LIKE", 0, 0, 0, ""),
 
700
  Commands( "LIMIT", 0, 0, 0, ""),
 
701
  Commands( "LINES", 0, 0, 0, ""),
 
702
  Commands( "LINESTRING", 0, 0, 0, ""),
 
703
  Commands( "LOAD", 0, 0, 0, ""),
 
704
  Commands( "LOCAL", 0, 0, 0, ""),
 
705
  Commands( "LOCALTIMESTAMP", 0, 0, 0, ""),
 
706
  Commands( "LOCK", 0, 0, 0, ""),
 
707
  Commands( "LOCKS", 0, 0, 0, ""),
 
708
  Commands( "LOGS", 0, 0, 0, ""),
 
709
  Commands( "LONG", 0, 0, 0, ""),
 
710
  Commands( "LOOP", 0, 0, 0, ""),
 
711
  Commands( "MATCH", 0, 0, 0, ""),
 
712
  Commands( "MAX_CONNECTIONS_PER_HOUR", 0, 0, 0, ""),
 
713
  Commands( "MAX_QUERIES_PER_HOUR", 0, 0, 0, ""),
 
714
  Commands( "MAX_ROWS", 0, 0, 0, ""),
 
715
  Commands( "MAX_UPDATES_PER_HOUR", 0, 0, 0, ""),
 
716
  Commands( "MAX_USER_CONNECTIONS", 0, 0, 0, ""),
 
717
  Commands( "MEDIUM", 0, 0, 0, ""),
 
718
  Commands( "MERGE", 0, 0, 0, ""),
 
719
  Commands( "MICROSECOND", 0, 0, 0, ""),
 
720
  Commands( "MIGRATE", 0, 0, 0, ""),
 
721
  Commands( "MINUTE", 0, 0, 0, ""),
 
722
  Commands( "MINUTE_MICROSECOND", 0, 0, 0, ""),
 
723
  Commands( "MINUTE_SECOND", 0, 0, 0, ""),
 
724
  Commands( "MIN_ROWS", 0, 0, 0, ""),
 
725
  Commands( "MOD", 0, 0, 0, ""),
 
726
  Commands( "MODE", 0, 0, 0, ""),
 
727
  Commands( "MODIFIES", 0, 0, 0, ""),
 
728
  Commands( "MODIFY", 0, 0, 0, ""),
 
729
  Commands( "MONTH", 0, 0, 0, ""),
 
730
  Commands( "MULTILINESTRING", 0, 0, 0, ""),
 
731
  Commands( "MULTIPOINT", 0, 0, 0, ""),
 
732
  Commands( "MULTIPOLYGON", 0, 0, 0, ""),
 
733
  Commands( "MUTEX", 0, 0, 0, ""),
 
734
  Commands( "NAME", 0, 0, 0, ""),
 
735
  Commands( "NAMES", 0, 0, 0, ""),
 
736
  Commands( "NATIONAL", 0, 0, 0, ""),
 
737
  Commands( "NATURAL", 0, 0, 0, ""),
 
738
  Commands( "NCHAR", 0, 0, 0, ""),
 
739
  Commands( "NEW", 0, 0, 0, ""),
 
740
  Commands( "NEXT", 0, 0, 0, ""),
 
741
  Commands( "NO", 0, 0, 0, ""),
 
742
  Commands( "NONE", 0, 0, 0, ""),
 
743
  Commands( "NOT", 0, 0, 0, ""),
 
744
  Commands( "NULL", 0, 0, 0, ""),
 
745
  Commands( "NUMERIC", 0, 0, 0, ""),
 
746
  Commands( "NVARCHAR", 0, 0, 0, ""),
 
747
  Commands( "OFFSET", 0, 0, 0, ""),
 
748
  Commands( "ON", 0, 0, 0, ""),
 
749
  Commands( "ONE", 0, 0, 0, ""),
 
750
  Commands( "ONE_SHOT", 0, 0, 0, ""),
 
751
  Commands( "OPEN", 0, 0, 0, ""),
 
752
  Commands( "OPTIMIZE", 0, 0, 0, ""),
 
753
  Commands( "OPTION", 0, 0, 0, ""),
 
754
  Commands( "OPTIONALLY", 0, 0, 0, ""),
 
755
  Commands( "OR", 0, 0, 0, ""),
 
756
  Commands( "ORDER", 0, 0, 0, ""),
 
757
  Commands( "OUT", 0, 0, 0, ""),
 
758
  Commands( "OUTER", 0, 0, 0, ""),
 
759
  Commands( "OUTFILE", 0, 0, 0, ""),
 
760
  Commands( "PACK_KEYS", 0, 0, 0, ""),
 
761
  Commands( "PARTIAL", 0, 0, 0, ""),
 
762
  Commands( "PASSWORD", 0, 0, 0, ""),
 
763
  Commands( "PHASE", 0, 0, 0, ""),
 
764
  Commands( "PRECISION", 0, 0, 0, ""),
 
765
  Commands( "PREPARE", 0, 0, 0, ""),
 
766
  Commands( "PREV", 0, 0, 0, ""),
 
767
  Commands( "PRIMARY", 0, 0, 0, ""),
 
768
  Commands( "PRIVILEGES", 0, 0, 0, ""),
 
769
  Commands( "PROCEDURE", 0, 0, 0, ""),
 
770
  Commands( "PROCESS", 0, 0, 0, ""),
 
771
  Commands( "PROCESSLIST", 0, 0, 0, ""),
 
772
  Commands( "PURGE", 0, 0, 0, ""),
 
773
  Commands( "QUARTER", 0, 0, 0, ""),
 
774
  Commands( "QUERY", 0, 0, 0, ""),
 
775
  Commands( "QUICK", 0, 0, 0, ""),
 
776
  Commands( "READ", 0, 0, 0, ""),
 
777
  Commands( "READS", 0, 0, 0, ""),
 
778
  Commands( "REAL", 0, 0, 0, ""),
 
779
  Commands( "RECOVER", 0, 0, 0, ""),
 
780
  Commands( "REDUNDANT", 0, 0, 0, ""),
 
781
  Commands( "REFERENCES", 0, 0, 0, ""),
 
782
  Commands( "REGEXP", 0, 0, 0, ""),
 
783
  Commands( "RELEASE", 0, 0, 0, ""),
 
784
  Commands( "RELOAD", 0, 0, 0, ""),
 
785
  Commands( "RENAME", 0, 0, 0, ""),
 
786
  Commands( "REPAIR", 0, 0, 0, ""),
 
787
  Commands( "REPEATABLE", 0, 0, 0, ""),
 
788
  Commands( "REPLACE", 0, 0, 0, ""),
 
789
  Commands( "REPEAT", 0, 0, 0, ""),
 
790
  Commands( "REQUIRE", 0, 0, 0, ""),
 
791
  Commands( "RESET", 0, 0, 0, ""),
 
792
  Commands( "RESTORE", 0, 0, 0, ""),
 
793
  Commands( "RESTRICT", 0, 0, 0, ""),
 
794
  Commands( "RESUME", 0, 0, 0, ""),
 
795
  Commands( "RETURN", 0, 0, 0, ""),
 
796
  Commands( "RETURNS", 0, 0, 0, ""),
 
797
  Commands( "REVOKE", 0, 0, 0, ""),
 
798
  Commands( "RIGHT", 0, 0, 0, ""),
 
799
  Commands( "RLIKE", 0, 0, 0, ""),
 
800
  Commands( "ROLLBACK", 0, 0, 0, ""),
 
801
  Commands( "ROLLUP", 0, 0, 0, ""),
 
802
  Commands( "ROUTINE", 0, 0, 0, ""),
 
803
  Commands( "ROW", 0, 0, 0, ""),
 
804
  Commands( "ROWS", 0, 0, 0, ""),
 
805
  Commands( "ROW_FORMAT", 0, 0, 0, ""),
 
806
  Commands( "RTREE", 0, 0, 0, ""),
 
807
  Commands( "SAVEPOINT", 0, 0, 0, ""),
 
808
  Commands( "SCHEMA", 0, 0, 0, ""),
 
809
  Commands( "SCHEMAS", 0, 0, 0, ""),
 
810
  Commands( "SECOND", 0, 0, 0, ""),
 
811
  Commands( "SECOND_MICROSECOND", 0, 0, 0, ""),
 
812
  Commands( "SECURITY", 0, 0, 0, ""),
 
813
  Commands( "SELECT", 0, 0, 0, ""),
 
814
  Commands( "SENSITIVE", 0, 0, 0, ""),
 
815
  Commands( "SEPARATOR", 0, 0, 0, ""),
 
816
  Commands( "SERIAL", 0, 0, 0, ""),
 
817
  Commands( "SERIALIZABLE", 0, 0, 0, ""),
 
818
  Commands( "SESSION", 0, 0, 0, ""),
 
819
  Commands( "SET", 0, 0, 0, ""),
 
820
  Commands( "SHARE", 0, 0, 0, ""),
 
821
  Commands( "SHOW", 0, 0, 0, ""),
 
822
  Commands( "SHUTDOWN", 0, 0, 0, ""),
 
823
  Commands( "SIGNED", 0, 0, 0, ""),
 
824
  Commands( "SIMPLE", 0, 0, 0, ""),
 
825
  Commands( "SLAVE", 0, 0, 0, ""),
 
826
  Commands( "SNAPSHOT", 0, 0, 0, ""),
 
827
  Commands( "SOME", 0, 0, 0, ""),
 
828
  Commands( "SONAME", 0, 0, 0, ""),
 
829
  Commands( "SOUNDS", 0, 0, 0, ""),
 
830
  Commands( "SPATIAL", 0, 0, 0, ""),
 
831
  Commands( "SPECIFIC", 0, 0, 0, ""),
 
832
  Commands( "SQL", 0, 0, 0, ""),
 
833
  Commands( "SQLEXCEPTION", 0, 0, 0, ""),
 
834
  Commands( "SQLSTATE", 0, 0, 0, ""),
 
835
  Commands( "SQLWARNING", 0, 0, 0, ""),
 
836
  Commands( "SQL_BIG_RESULT", 0, 0, 0, ""),
 
837
  Commands( "SQL_BUFFER_RESULT", 0, 0, 0, ""),
 
838
  Commands( "SQL_CACHE", 0, 0, 0, ""),
 
839
  Commands( "SQL_CALC_FOUND_ROWS", 0, 0, 0, ""),
 
840
  Commands( "SQL_NO_CACHE", 0, 0, 0, ""),
 
841
  Commands( "SQL_SMALL_RESULT", 0, 0, 0, ""),
 
842
  Commands( "SQL_THREAD", 0, 0, 0, ""),
 
843
  Commands( "SQL_TSI_FRAC_SECOND", 0, 0, 0, ""),
 
844
  Commands( "SQL_TSI_SECOND", 0, 0, 0, ""),
 
845
  Commands( "SQL_TSI_MINUTE", 0, 0, 0, ""),
 
846
  Commands( "SQL_TSI_HOUR", 0, 0, 0, ""),
 
847
  Commands( "SQL_TSI_DAY", 0, 0, 0, ""),
 
848
  Commands( "SQL_TSI_WEEK", 0, 0, 0, ""),
 
849
  Commands( "SQL_TSI_MONTH", 0, 0, 0, ""),
 
850
  Commands( "SQL_TSI_QUARTER", 0, 0, 0, ""),
 
851
  Commands( "SQL_TSI_YEAR", 0, 0, 0, ""),
 
852
  Commands( "SSL", 0, 0, 0, ""),
 
853
  Commands( "START", 0, 0, 0, ""),
 
854
  Commands( "STARTING", 0, 0, 0, ""),
 
855
  Commands( "STATUS", 0, 0, 0, ""),
 
856
  Commands( "STOP", 0, 0, 0, ""),
 
857
  Commands( "STORAGE", 0, 0, 0, ""),
 
858
  Commands( "STRAIGHT_JOIN", 0, 0, 0, ""),
 
859
  Commands( "STRING", 0, 0, 0, ""),
 
860
  Commands( "STRIPED", 0, 0, 0, ""),
 
861
  Commands( "SUBJECT", 0, 0, 0, ""),
 
862
  Commands( "SUPER", 0, 0, 0, ""),
 
863
  Commands( "SUSPEND", 0, 0, 0, ""),
 
864
  Commands( "TABLE", 0, 0, 0, ""),
 
865
  Commands( "TABLES", 0, 0, 0, ""),
 
866
  Commands( "TABLESPACE", 0, 0, 0, ""),
 
867
  Commands( "TEMPORARY", 0, 0, 0, ""),
 
868
  Commands( "TEMPTABLE", 0, 0, 0, ""),
 
869
  Commands( "TERMINATED", 0, 0, 0, ""),
 
870
  Commands( "TEXT", 0, 0, 0, ""),
 
871
  Commands( "THEN", 0, 0, 0, ""),
 
872
  Commands( "TIMESTAMP", 0, 0, 0, ""),
 
873
  Commands( "TIMESTAMPADD", 0, 0, 0, ""),
 
874
  Commands( "TIMESTAMPDIFF", 0, 0, 0, ""),
 
875
  Commands( "TO", 0, 0, 0, ""),
 
876
  Commands( "TRAILING", 0, 0, 0, ""),
 
877
  Commands( "TRANSACTION", 0, 0, 0, ""),
 
878
  Commands( "TRUE", 0, 0, 0, ""),
 
879
  Commands( "TRUNCATE", 0, 0, 0, ""),
 
880
  Commands( "TYPE", 0, 0, 0, ""),
 
881
  Commands( "TYPES", 0, 0, 0, ""),
 
882
  Commands( "UNCOMMITTED", 0, 0, 0, ""),
 
883
  Commands( "UNDEFINED", 0, 0, 0, ""),
 
884
  Commands( "UNDO", 0, 0, 0, ""),
 
885
  Commands( "UNICODE", 0, 0, 0, ""),
 
886
  Commands( "UNION", 0, 0, 0, ""),
 
887
  Commands( "UNIQUE", 0, 0, 0, ""),
 
888
  Commands( "UNKNOWN", 0, 0, 0, ""),
 
889
  Commands( "UNLOCK", 0, 0, 0, ""),
 
890
  Commands( "UNTIL", 0, 0, 0, ""),
 
891
  Commands( "UPDATE", 0, 0, 0, ""),
 
892
  Commands( "UPGRADE", 0, 0, 0, ""),
 
893
  Commands( "USAGE", 0, 0, 0, ""),
 
894
  Commands( "USE", 0, 0, 0, ""),
 
895
  Commands( "USER", 0, 0, 0, ""),
 
896
  Commands( "USER_RESOURCES", 0, 0, 0, ""),
 
897
  Commands( "USING", 0, 0, 0, ""),
 
898
  Commands( "UTC_DATE", 0, 0, 0, ""),
 
899
  Commands( "UTC_TIMESTAMP", 0, 0, 0, ""),
 
900
  Commands( "VALUE", 0, 0, 0, ""),
 
901
  Commands( "VALUES", 0, 0, 0, ""),
 
902
  Commands( "VARBINARY", 0, 0, 0, ""),
 
903
  Commands( "VARCHAR", 0, 0, 0, ""),
 
904
  Commands( "VARCHARACTER", 0, 0, 0, ""),
 
905
  Commands( "VARIABLES", 0, 0, 0, ""),
 
906
  Commands( "VARYING", 0, 0, 0, ""),
 
907
  Commands( "WARNINGS", 0, 0, 0, ""),
 
908
  Commands( "WEEK", 0, 0, 0, ""),
 
909
  Commands( "WHEN", 0, 0, 0, ""),
 
910
  Commands( "WHERE", 0, 0, 0, ""),
 
911
  Commands( "WHILE", 0, 0, 0, ""),
 
912
  Commands( "VIEW", 0, 0, 0, ""),
 
913
  Commands( "WITH", 0, 0, 0, ""),
 
914
  Commands( "WORK", 0, 0, 0, ""),
 
915
  Commands( "WRITE", 0, 0, 0, ""),
 
916
  Commands( "XOR", 0, 0, 0, ""),
 
917
  Commands( "XA", 0, 0, 0, ""),
 
918
  Commands( "YEAR", 0, 0, 0, ""),
 
919
  Commands( "YEAR_MONTH", 0, 0, 0, ""),
 
920
  Commands( "ZEROFILL", 0, 0, 0, ""),
 
921
  Commands( "ABS", 0, 0, 0, ""),
 
922
  Commands( "ACOS", 0, 0, 0, ""),
 
923
  Commands( "ADDDATE", 0, 0, 0, ""),
 
924
  Commands( "AREA", 0, 0, 0, ""),
 
925
  Commands( "ASIN", 0, 0, 0, ""),
 
926
  Commands( "ASBINARY", 0, 0, 0, ""),
 
927
  Commands( "ASTEXT", 0, 0, 0, ""),
 
928
  Commands( "ATAN", 0, 0, 0, ""),
 
929
  Commands( "ATAN2", 0, 0, 0, ""),
 
930
  Commands( "BENCHMARK", 0, 0, 0, ""),
 
931
  Commands( "BIN", 0, 0, 0, ""),
 
932
  Commands( "BIT_OR", 0, 0, 0, ""),
 
933
  Commands( "BIT_AND", 0, 0, 0, ""),
 
934
  Commands( "BIT_XOR", 0, 0, 0, ""),
 
935
  Commands( "CAST", 0, 0, 0, ""),
 
936
  Commands( "CEIL", 0, 0, 0, ""),
 
937
  Commands( "CEILING", 0, 0, 0, ""),
 
938
  Commands( "CENTROID", 0, 0, 0, ""),
 
939
  Commands( "CHAR_LENGTH", 0, 0, 0, ""),
 
940
  Commands( "CHARACTER_LENGTH", 0, 0, 0, ""),
 
941
  Commands( "COALESCE", 0, 0, 0, ""),
 
942
  Commands( "COERCIBILITY", 0, 0, 0, ""),
 
943
  Commands( "COMPRESS", 0, 0, 0, ""),
 
944
  Commands( "CONCAT", 0, 0, 0, ""),
 
945
  Commands( "CONCAT_WS", 0, 0, 0, ""),
 
946
  Commands( "CONNECTION_ID", 0, 0, 0, ""),
 
947
  Commands( "CONV", 0, 0, 0, ""),
 
948
  Commands( "CONVERT_TZ", 0, 0, 0, ""),
 
949
  Commands( "COUNT", 0, 0, 0, ""),
 
950
  Commands( "COS", 0, 0, 0, ""),
 
951
  Commands( "COT", 0, 0, 0, ""),
 
952
  Commands( "CRC32", 0, 0, 0, ""),
 
953
  Commands( "CROSSES", 0, 0, 0, ""),
 
954
  Commands( "CURDATE", 0, 0, 0, ""),
 
955
  Commands( "DATE_ADD", 0, 0, 0, ""),
 
956
  Commands( "DATEDIFF", 0, 0, 0, ""),
 
957
  Commands( "DATE_FORMAT", 0, 0, 0, ""),
 
958
  Commands( "DATE_SUB", 0, 0, 0, ""),
 
959
  Commands( "DAYNAME", 0, 0, 0, ""),
 
960
  Commands( "DAYOFMONTH", 0, 0, 0, ""),
 
961
  Commands( "DAYOFWEEK", 0, 0, 0, ""),
 
962
  Commands( "DAYOFYEAR", 0, 0, 0, ""),
 
963
  Commands( "DECODE", 0, 0, 0, ""),
 
964
  Commands( "DEGREES", 0, 0, 0, ""),
 
965
  Commands( "DES_ENCRYPT", 0, 0, 0, ""),
 
966
  Commands( "DES_DECRYPT", 0, 0, 0, ""),
 
967
  Commands( "DIMENSION", 0, 0, 0, ""),
 
968
  Commands( "DISJOINT", 0, 0, 0, ""),
 
969
  Commands( "ELT", 0, 0, 0, ""),
 
970
  Commands( "ENCODE", 0, 0, 0, ""),
 
971
  Commands( "ENCRYPT", 0, 0, 0, ""),
 
972
  Commands( "ENDPOINT", 0, 0, 0, ""),
 
973
  Commands( "ENVELOPE", 0, 0, 0, ""),
 
974
  Commands( "EQUALS", 0, 0, 0, ""),
 
975
  Commands( "EXTERIORRING", 0, 0, 0, ""),
 
976
  Commands( "EXTRACT", 0, 0, 0, ""),
 
977
  Commands( "EXP", 0, 0, 0, ""),
 
978
  Commands( "EXPORT_SET", 0, 0, 0, ""),
 
979
  Commands( "FIELD", 0, 0, 0, ""),
 
980
  Commands( "FIND_IN_SET", 0, 0, 0, ""),
 
981
  Commands( "FLOOR", 0, 0, 0, ""),
 
982
  Commands( "FORMAT", 0, 0, 0, ""),
 
983
  Commands( "FOUND_ROWS", 0, 0, 0, ""),
 
984
  Commands( "FROM_DAYS", 0, 0, 0, ""),
 
985
  Commands( "FROM_UNIXTIME", 0, 0, 0, ""),
 
986
  Commands( "GET_LOCK", 0, 0, 0, ""),
 
987
  Commands( "GLENGTH", 0, 0, 0, ""),
 
988
  Commands( "GREATEST", 0, 0, 0, ""),
 
989
  Commands( "GROUP_CONCAT", 0, 0, 0, ""),
 
990
  Commands( "GROUP_UNIQUE_USERS", 0, 0, 0, ""),
 
991
  Commands( "HEX", 0, 0, 0, ""),
 
992
  Commands( "IFNULL", 0, 0, 0, ""),
 
993
  Commands( "INSTR", 0, 0, 0, ""),
 
994
  Commands( "INTERIORRINGN", 0, 0, 0, ""),
 
995
  Commands( "INTERSECTS", 0, 0, 0, ""),
 
996
  Commands( "ISCLOSED", 0, 0, 0, ""),
 
997
  Commands( "ISEMPTY", 0, 0, 0, ""),
 
998
  Commands( "ISNULL", 0, 0, 0, ""),
 
999
  Commands( "IS_FREE_LOCK", 0, 0, 0, ""),
 
1000
  Commands( "IS_USED_LOCK", 0, 0, 0, ""),
 
1001
  Commands( "LAST_INSERT_ID", 0, 0, 0, ""),
 
1002
  Commands( "ISSIMPLE", 0, 0, 0, ""),
 
1003
  Commands( "LAST_DAY", 0, 0, 0, ""),
 
1004
  Commands( "LCASE", 0, 0, 0, ""),
 
1005
  Commands( "LEAST", 0, 0, 0, ""),
 
1006
  Commands( "LENGTH", 0, 0, 0, ""),
 
1007
  Commands( "LN", 0, 0, 0, ""),
 
1008
  Commands( "LOAD_FILE", 0, 0, 0, ""),
 
1009
  Commands( "LOCATE", 0, 0, 0, ""),
 
1010
  Commands( "LOG", 0, 0, 0, ""),
 
1011
  Commands( "LOG2", 0, 0, 0, ""),
 
1012
  Commands( "LOG10", 0, 0, 0, ""),
 
1013
  Commands( "LOWER", 0, 0, 0, ""),
 
1014
  Commands( "LPAD", 0, 0, 0, ""),
 
1015
  Commands( "LTRIM", 0, 0, 0, ""),
 
1016
  Commands( "MAKE_SET", 0, 0, 0, ""),
 
1017
  Commands( "MAKEDATE", 0, 0, 0, ""),
 
1018
  Commands( "MASTER_POS_WAIT", 0, 0, 0, ""),
 
1019
  Commands( "MAX", 0, 0, 0, ""),
 
1020
  Commands( "MBRCONTAINS", 0, 0, 0, ""),
 
1021
  Commands( "MBRDISJOINT", 0, 0, 0, ""),
 
1022
  Commands( "MBREQUAL", 0, 0, 0, ""),
 
1023
  Commands( "MBRINTERSECTS", 0, 0, 0, ""),
 
1024
  Commands( "MBROVERLAPS", 0, 0, 0, ""),
 
1025
  Commands( "MBRTOUCHES", 0, 0, 0, ""),
 
1026
  Commands( "MBRWITHIN", 0, 0, 0, ""),
 
1027
  Commands( "MD5", 0, 0, 0, ""),
 
1028
  Commands( "MID", 0, 0, 0, ""),
 
1029
  Commands( "MIN", 0, 0, 0, ""),
 
1030
  Commands( "MONTHNAME", 0, 0, 0, ""),
 
1031
  Commands( "NAME_CONST", 0, 0, 0, ""),
 
1032
  Commands( "NOW", 0, 0, 0, ""),
 
1033
  Commands( "NULLIF", 0, 0, 0, ""),
 
1034
  Commands( "NUMPOINTS", 0, 0, 0, ""),
 
1035
  Commands( "OCTET_LENGTH", 0, 0, 0, ""),
 
1036
  Commands( "OCT", 0, 0, 0, ""),
 
1037
  Commands( "ORD", 0, 0, 0, ""),
 
1038
  Commands( "OVERLAPS", 0, 0, 0, ""),
 
1039
  Commands( "PERIOD_ADD", 0, 0, 0, ""),
 
1040
  Commands( "PERIOD_DIFF", 0, 0, 0, ""),
 
1041
  Commands( "PI", 0, 0, 0, ""),
 
1042
  Commands( "POINTN", 0, 0, 0, ""),
 
1043
  Commands( "POSITION", 0, 0, 0, ""),
 
1044
  Commands( "POW", 0, 0, 0, ""),
 
1045
  Commands( "POWER", 0, 0, 0, ""),
 
1046
  Commands( "QUOTE", 0, 0, 0, ""),
 
1047
  Commands( "RADIANS", 0, 0, 0, ""),
 
1048
  Commands( "RAND", 0, 0, 0, ""),
 
1049
  Commands( "RELEASE_LOCK", 0, 0, 0, ""),
 
1050
  Commands( "REVERSE", 0, 0, 0, ""),
 
1051
  Commands( "ROUND", 0, 0, 0, ""),
 
1052
  Commands( "ROW_COUNT", 0, 0, 0, ""),
 
1053
  Commands( "RPAD", 0, 0, 0, ""),
 
1054
  Commands( "RTRIM", 0, 0, 0, ""),
 
1055
  Commands( "SESSION_USER", 0, 0, 0, ""),
 
1056
  Commands( "SUBDATE", 0, 0, 0, ""),
 
1057
  Commands( "SIGN", 0, 0, 0, ""),
 
1058
  Commands( "SIN", 0, 0, 0, ""),
 
1059
  Commands( "SHA", 0, 0, 0, ""),
 
1060
  Commands( "SHA1", 0, 0, 0, ""),
 
1061
  Commands( "SLEEP", 0, 0, 0, ""),
 
1062
  Commands( "SOUNDEX", 0, 0, 0, ""),
 
1063
  Commands( "SPACE", 0, 0, 0, ""),
 
1064
  Commands( "SQRT", 0, 0, 0, ""),
 
1065
  Commands( "SRID", 0, 0, 0, ""),
 
1066
  Commands( "STARTPOINT", 0, 0, 0, ""),
 
1067
  Commands( "STD", 0, 0, 0, ""),
 
1068
  Commands( "STDDEV", 0, 0, 0, ""),
 
1069
  Commands( "STDDEV_POP", 0, 0, 0, ""),
 
1070
  Commands( "STDDEV_SAMP", 0, 0, 0, ""),
 
1071
  Commands( "STR_TO_DATE", 0, 0, 0, ""),
 
1072
  Commands( "STRCMP", 0, 0, 0, ""),
 
1073
  Commands( "SUBSTR", 0, 0, 0, ""),
 
1074
  Commands( "SUBSTRING", 0, 0, 0, ""),
 
1075
  Commands( "SUBSTRING_INDEX", 0, 0, 0, ""),
 
1076
  Commands( "SUM", 0, 0, 0, ""),
 
1077
  Commands( "SYSDATE", 0, 0, 0, ""),
 
1078
  Commands( "SYSTEM_USER", 0, 0, 0, ""),
 
1079
  Commands( "TAN", 0, 0, 0, ""),
 
1080
  Commands( "TIME_FORMAT", 0, 0, 0, ""),
 
1081
  Commands( "TO_DAYS", 0, 0, 0, ""),
 
1082
  Commands( "TOUCHES", 0, 0, 0, ""),
 
1083
  Commands( "TRIM", 0, 0, 0, ""),
 
1084
  Commands( "UCASE", 0, 0, 0, ""),
 
1085
  Commands( "UNCOMPRESS", 0, 0, 0, ""),
 
1086
  Commands( "UNCOMPRESSED_LENGTH", 0, 0, 0, ""),
 
1087
  Commands( "UNHEX", 0, 0, 0, ""),
 
1088
  Commands( "UNIQUE_USERS", 0, 0, 0, ""),
 
1089
  Commands( "UNIX_TIMESTAMP", 0, 0, 0, ""),
 
1090
  Commands( "UPPER", 0, 0, 0, ""),
 
1091
  Commands( "UUID", 0, 0, 0, ""),
 
1092
  Commands( "VARIANCE", 0, 0, 0, ""),
 
1093
  Commands( "VAR_POP", 0, 0, 0, ""),
 
1094
  Commands( "VAR_SAMP", 0, 0, 0, ""),
 
1095
  Commands( "VERSION", 0, 0, 0, ""),
 
1096
  Commands( "WEEKDAY", 0, 0, 0, ""),
 
1097
  Commands( "WEEKOFYEAR", 0, 0, 0, ""),
 
1098
  Commands( "WITHIN", 0, 0, 0, ""),
 
1099
  Commands( "X", 0, 0, 0, ""),
 
1100
  Commands( "Y", 0, 0, 0, ""),
 
1101
  Commands( "YEARWEEK", 0, 0, 0, ""),
997
1102
  /* end sentinel */
998
 
  { (char *)NULL,       0, 0, 0, ""}
 
1103
  Commands((char *)NULL,       0, 0, 0, "")
999
1104
};
1000
1105
 
1001
 
static const char *load_default_groups[]= { "drizzle","client",0 };
1002
1106
 
1003
1107
int history_length;
1004
1108
static int not_in_history(const char *line);
1005
1109
static void initialize_readline (char *name);
1006
1110
static void fix_history(string *final_command);
1007
1111
 
1008
 
static COMMANDS *find_command(const char *name,char cmd_name);
 
1112
static Commands *find_command(const char *name,char cmd_name);
1009
1113
static bool add_line(string *buffer,char *line,char *in_string,
1010
1114
                     bool *ml_comment);
1011
1115
static void remove_cntrl(string *buffer);
1027
1131
  Shutdown the server that we are currently connected to.
1028
1132
 
1029
1133
  @retval
1030
 
  true success
 
1134
    true success
1031
1135
  @retval
1032
 
  false failure
 
1136
    false failure
1033
1137
*/
1034
1138
static bool server_shutdown(void)
1035
1139
{
1038
1142
 
1039
1143
  if (verbose)
1040
1144
  {
1041
 
    printf("shutting down drizzled");
 
1145
    printf(_("shutting down drizzled"));
1042
1146
    if (opt_drizzle_port > 0)
1043
 
      printf(" on port %d", opt_drizzle_port);
 
1147
      printf(_(" on port %d"), opt_drizzle_port);
1044
1148
    printf("... ");
1045
1149
  }
1046
1150
 
1049
1153
  {
1050
1154
    if (ret == DRIZZLE_RETURN_ERROR_CODE)
1051
1155
    {
1052
 
      fprintf(stderr, "shutdown failed; error: '%s'",
 
1156
      fprintf(stderr, _("shutdown failed; error: '%s'"),
1053
1157
              drizzle_result_error(&result));
1054
1158
      drizzle_result_free(&result);
1055
1159
    }
1056
1160
    else
1057
1161
    {
1058
 
      fprintf(stderr, "shutdown failed; error: '%s'",
 
1162
      fprintf(stderr, _("shutdown failed; error: '%s'"),
1059
1163
              drizzle_con_error(&con));
1060
1164
    }
1061
1165
    return false;
1064
1168
  drizzle_result_free(&result);
1065
1169
 
1066
1170
  if (verbose)
1067
 
    printf("done\n");
 
1171
    printf(_("done\n"));
1068
1172
 
1069
1173
  return true;
1070
1174
}
1073
1177
  Ping the server that we are currently connected to.
1074
1178
 
1075
1179
  @retval
1076
 
  true success
 
1180
    true success
1077
1181
  @retval
1078
 
  false failure
 
1182
    false failure
1079
1183
*/
1080
1184
static bool server_ping(void)
1081
1185
{
1085
1189
  if (drizzle_ping(&con, &result, &ret) != NULL && ret == DRIZZLE_RETURN_OK)
1086
1190
  {
1087
1191
    if (opt_silent < 2)
1088
 
      printf("drizzled is alive\n");
 
1192
      printf(_("drizzled is alive\n"));
1089
1193
  }
1090
1194
  else
1091
1195
  {
1092
1196
    if (ret == DRIZZLE_RETURN_ERROR_CODE)
1093
1197
    {
1094
 
      fprintf(stderr, "ping failed; error: '%s'",
 
1198
      fprintf(stderr, _("ping failed; error: '%s'"),
1095
1199
              drizzle_result_error(&result));
1096
1200
      drizzle_result_free(&result);
1097
1201
    }
1098
1202
    else
1099
1203
    {
1100
 
      fprintf(stderr, "drizzled won't answer to ping, error: '%s'",
 
1204
      fprintf(stderr, _("drizzled won't answer to ping, error: '%s'"),
1101
1205
              drizzle_con_error(&con));
1102
1206
    }
1103
1207
    return false;
1110
1214
  Execute command(s) specified by the user.
1111
1215
 
1112
1216
  @param error  error status of command execution.
1113
 
  If an error had occurred, this variable will be set
1114
 
  to 1 whereas on success, it shall be set to 0. This
1115
 
  value will be supplied to the exit() function used
1116
 
  by the caller.
 
1217
                If an error had occurred, this variable will be set
 
1218
                to 1 whereas on success, it shall be set to 0. This
 
1219
                value will be supplied to the exit() function used
 
1220
                by the caller.
1117
1221
 
1118
1222
  @retval
1119
 
  false no commands were executed
 
1223
    false no commands were executed
1120
1224
  @retval
1121
 
  true  at least one command was executed
 
1225
    true  at least one command was executed
1122
1226
*/
1123
1227
static bool execute_commands(int *error)
1124
1228
{
1141
1245
  return executed;
1142
1246
}
1143
1247
 
 
1248
static void check_timeout_value(uint32_t in_connect_timeout)
 
1249
{
 
1250
  opt_connect_timeout= 0;
 
1251
  if (in_connect_timeout > 3600*12)
 
1252
  {
 
1253
    cout << _("Error: Invalid Value for connect_timeout"); 
 
1254
    exit(-1);
 
1255
  }
 
1256
  opt_connect_timeout= in_connect_timeout;
 
1257
}
 
1258
 
 
1259
static void check_max_input_line(uint32_t in_max_input_line)
 
1260
{
 
1261
  opt_max_input_line= 0;
 
1262
  if (in_max_input_line < 4096 || in_max_input_line > (int64_t)2*1024L*1024L*1024L)
 
1263
  {
 
1264
    cout << _("Error: Invalid Value for max_input_line");
 
1265
    exit(-1);
 
1266
  }
 
1267
  opt_max_input_line= in_max_input_line - (in_max_input_line % 1024);
 
1268
}
 
1269
 
1144
1270
int main(int argc,char *argv[])
1145
1271
{
 
1272
try
 
1273
{
 
1274
 
1146
1275
#if defined(ENABLE_NLS)
1147
1276
# if defined(HAVE_LOCALE_H)
1148
1277
  setlocale(LC_ALL, "");
1151
1280
  textdomain("drizzle");
1152
1281
#endif
1153
1282
 
1154
 
  MY_INIT(argv[0]);
1155
 
  delimiter_str= delimiter;
 
1283
  po::options_description commandline_options(N_("Options used only in command line"));
 
1284
  commandline_options.add_options()
 
1285
  ("help,?",N_("Displays this help and exit."))
 
1286
  ("batch,B",N_("Don't use history file. Disable interactive behavior. (Enables --silent)"))
 
1287
  ("column-type-info", po::value<bool>(&column_types_flag)->default_value(false)->zero_tokens(),
 
1288
  N_("Display column type information."))
 
1289
  ("comments,c", po::value<bool>(&preserve_comments)->default_value(false)->zero_tokens(),
 
1290
  N_("Preserve comments. Send comments to the server. The default is --skip-comments (discard comments), enable with --comments"))
 
1291
  ("vertical,E", po::value<bool>(&vertical)->default_value(false)->zero_tokens(),
 
1292
  N_("Print the output of a query (rows) vertically."))
 
1293
  ("force,f", po::value<bool>(&ignore_errors)->default_value(false)->zero_tokens(),
 
1294
  N_("Continue even if we get an sql error."))
 
1295
  ("named-commands,G", po::value<bool>(&named_cmds)->default_value(false)->zero_tokens(),
 
1296
  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."))
 
1297
  ("no-beep,b", po::value<bool>(&opt_nobeep)->default_value(false)->zero_tokens(),
 
1298
  N_("Turn off beep on error."))
 
1299
  ("disable-line-numbers", N_("Do not write line numbers for errors."))
 
1300
  ("disable-column-names", N_("Do not write column names in results."))
 
1301
  ("skip-column-names,N", 
 
1302
  N_("Don't write column names in results. WARNING: -N is deprecated, use long version of this options instead."))
 
1303
  ("set-variable,O", po::value<string>(),
 
1304
  N_("Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value."))
 
1305
  ("table,t", po::value<bool>(&output_tables)->default_value(false)->zero_tokens(),
 
1306
  N_("Output in table format.")) 
 
1307
  ("safe-updates,U", po::value<bool>(&safe_updates)->default_value(false)->zero_tokens(),
 
1308
  N_("Only allow UPDATE and DELETE that uses keys."))
 
1309
  ("i-am-a-dummy,U", po::value<bool>(&safe_updates)->default_value(false)->zero_tokens(),
 
1310
  N_("Synonym for option --safe-updates, -U."))
 
1311
  ("verbose,v", po::value<string>(&opt_verbose)->default_value(""),
 
1312
  N_("-v vvv implies that verbose= 3, Used to specify verbose"))
 
1313
  ("version,V", N_("Output version information and exit."))
 
1314
  ("secure-auth", po::value<bool>(&opt_secure_auth)->default_value(false)->zero_tokens(),
 
1315
  N_("Refuse client connecting to server if it uses old (pre-4.1.1) protocol"))
 
1316
  ("show-warnings", po::value<bool>(&show_warnings)->default_value(false)->zero_tokens(),
 
1317
  N_("Show warnings after every statement."))
 
1318
  ("show-progress-size", po::value<uint32_t>(&show_progress_size)->default_value(0),
 
1319
  N_("Number of lines before each import progress report."))
 
1320
  ("ping", po::value<bool>(&opt_ping)->default_value(false)->zero_tokens(),
 
1321
  N_("Ping the server to check if it's alive."))
 
1322
  ("no-defaults", po::value<bool>()->default_value(false)->zero_tokens(),
 
1323
  N_("Configuration file defaults are not used if no-defaults is set"))
 
1324
  ;
 
1325
 
 
1326
  po::options_description drizzle_options(N_("Options specific to the drizzle client"));
 
1327
  drizzle_options.add_options()
 
1328
  ("disable-auto-rehash,A",
 
1329
  N_("Disable automatic rehashing. One doesn't need to use 'rehash' to get table and field completion, but startup and reconnecting may take a longer time."))
 
1330
  ("auto-vertical-output", po::value<bool>(&auto_vertical_output)->default_value(false)->zero_tokens(),
 
1331
  N_("Automatically switch to vertical output mode if the result is wider than the terminal width."))
 
1332
  ("database,D", po::value<string>(&current_db)->default_value(""),
 
1333
  N_("Database to use."))
 
1334
  ("default-character-set",po::value<string>(),
 
1335
  N_("(not used)"))
 
1336
  ("delimiter", po::value<string>(&delimiter_str)->default_value(";"),
 
1337
  N_("Delimiter to be used."))
 
1338
  ("execute,e", po::value<string>(),
 
1339
  N_("Execute command and quit. (Disables --force and history file)"))
 
1340
  ("local-infile", po::value<bool>(&opt_local_infile)->default_value(false)->zero_tokens(),
 
1341
  N_("Enable LOAD DATA LOCAL INFILE."))
 
1342
  ("unbuffered,n", po::value<bool>(&unbuffered)->default_value(false)->zero_tokens(),
 
1343
  N_("Flush buffer after each query."))
 
1344
  ("sigint-ignore", po::value<bool>(&opt_sigint_ignore)->default_value(false)->zero_tokens(),
 
1345
  N_("Ignore SIGINT (CTRL-C)"))
 
1346
  ("one-database,o", po::value<bool>(&one_database)->default_value(false)->zero_tokens(),
 
1347
  N_("Only update the default database. This is useful for skipping updates to other database in the update log."))
 
1348
  ("pager", po::value<string>(),
 
1349
  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."))
 
1350
  ("disable-pager", po::value<bool>(&opt_nopager)->default_value(false)->zero_tokens(),
 
1351
  N_("Disable pager and print to stdout. See interactive help (\\h) also."))
 
1352
  ("prompt", po::value<string>(&current_prompt)->default_value(""),  
 
1353
  N_("Set the drizzle prompt to this value."))
 
1354
  ("quick,q", po::value<bool>(&quick)->default_value(false)->zero_tokens(),
 
1355
  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."))
 
1356
  ("raw,r", po::value<bool>(&opt_raw_data)->default_value(false)->zero_tokens(),
 
1357
  N_("Write fields without conversion. Used with --batch.")) 
 
1358
  ("disable-reconnect", N_("Do not reconnect if the connection is lost."))
 
1359
  ("shutdown", po::value<bool>()->zero_tokens(),
 
1360
  N_("Shutdown the server"))
 
1361
  ("silent,s", N_("Be more silent. Print results with a tab as separator, each row on new line."))
 
1362
  ("tee", po::value<string>(),
 
1363
  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."))
 
1364
  ("disable-tee", po::value<bool>()->default_value(false)->zero_tokens(), 
 
1365
  N_("Disable outfile. See interactive help (\\h) also."))
 
1366
  ("connect_timeout", po::value<uint32_t>(&opt_connect_timeout)->default_value(0)->notifier(&check_timeout_value),
 
1367
  N_("Number of seconds before connection timeout."))
 
1368
  ("max_input_line", po::value<uint32_t>(&opt_max_input_line)->default_value(16*1024L*1024L)->notifier(&check_max_input_line),
 
1369
  N_("Max length of input line"))
 
1370
  ("select_limit", po::value<uint32_t>(&select_limit)->default_value(1000L),
 
1371
  N_("Automatic limit for SELECT when using --safe-updates"))
 
1372
  ("max_join_size", po::value<uint32_t>(&max_join_size)->default_value(1000000L),
 
1373
  N_("Automatic limit for rows in a join when using --safe-updates"))
 
1374
  ;
 
1375
 
 
1376
  po::options_description client_options(N_("Options specific to the client"));
 
1377
  client_options.add_options()
 
1378
  ("host,h", po::value<string>(&current_host)->default_value("localhost"),
 
1379
  N_("Connect to host"))
 
1380
  ("password,P", po::value<string>(&current_password)->default_value(PASSWORD_SENTINEL),
 
1381
  N_("Password to use when connecting to server. If password is not given it's asked from the tty."))
 
1382
  ("port,p", po::value<uint32_t>()->default_value(0),
 
1383
  N_("Port number to use for connection or 0 for default to, in order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, built-in default"))
 
1384
  ("user,u", po::value<string>(&current_user)->default_value(""),
 
1385
  N_("User for login if not current user."))
 
1386
  ("protocol",po::value<string>(&opt_protocol)->default_value("mysql"),
 
1387
  N_("The protocol of connection (mysql or drizzle)."))
 
1388
  ;
 
1389
 
 
1390
  po::options_description long_options(N_("Allowed Options"));
 
1391
  long_options.add(commandline_options).add(drizzle_options).add(client_options);
 
1392
 
 
1393
  std::string system_config_dir_drizzle(SYSCONFDIR); 
 
1394
  system_config_dir_drizzle.append("/drizzle/drizzle.cnf");
 
1395
 
 
1396
  std::string system_config_dir_client(SYSCONFDIR); 
 
1397
  system_config_dir_client.append("/drizzle/client.cnf");
 
1398
 
 
1399
  std::string user_config_dir((getenv("XDG_CONFIG_HOME")? getenv("XDG_CONFIG_HOME"):"~/.config"));
 
1400
  
 
1401
  po::variables_map vm;
 
1402
 
 
1403
  po::positional_options_description p;
 
1404
  p.add("database", 1);
 
1405
 
 
1406
  // Disable allow_guessing
 
1407
  int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing;
 
1408
 
 
1409
  po::store(po::command_line_parser(argc, argv).options(long_options).
 
1410
            style(style).positional(p).extra_parser(parse_password_arg).run(),
 
1411
            vm);
 
1412
 
 
1413
  if (! vm["no-defaults"].as<bool>())
 
1414
  {
 
1415
    std::string user_config_dir_drizzle(user_config_dir);
 
1416
    user_config_dir_drizzle.append("/drizzle/drizzle.cnf"); 
 
1417
 
 
1418
    std::string user_config_dir_client(user_config_dir);
 
1419
    user_config_dir_client.append("/drizzle/client.cnf");
 
1420
 
 
1421
    ifstream user_drizzle_ifs(user_config_dir_drizzle.c_str());
 
1422
    po::store(dpo::parse_config_file(user_drizzle_ifs, drizzle_options), vm);
 
1423
 
 
1424
    ifstream user_client_ifs(user_config_dir_client.c_str());
 
1425
    po::store(dpo::parse_config_file(user_client_ifs, client_options), vm);
 
1426
 
 
1427
    ifstream system_drizzle_ifs(system_config_dir_drizzle.c_str());
 
1428
    store(dpo::parse_config_file(system_drizzle_ifs, drizzle_options), vm);
 
1429
 
 
1430
    ifstream system_client_ifs(system_config_dir_client.c_str());
 
1431
    po::store(dpo::parse_config_file(system_client_ifs, client_options), vm);
 
1432
  }
 
1433
 
 
1434
  po::notify(vm);
 
1435
 
1156
1436
  default_prompt= strdup(getenv("DRIZZLE_PS1") ?
1157
1437
                         getenv("DRIZZLE_PS1") :
1158
1438
                         "drizzle> ");
1159
 
 
1160
1439
  if (default_prompt == NULL)
1161
1440
  {
1162
1441
    fprintf(stderr, _("Memory allocation error while constructing initial "
1164
1443
    exit(ENOMEM);
1165
1444
  }
1166
1445
  current_prompt= strdup(default_prompt);
1167
 
  if (current_prompt == NULL)
 
1446
  if (current_prompt.empty())
1168
1447
  {
1169
1448
    fprintf(stderr, _("Memory allocation error while constructing initial "
1170
1449
                      "prompt. Aborting.\n"));
1175
1454
 
1176
1455
  prompt_counter=0;
1177
1456
 
1178
 
  outfile[0]=0;      // no (default) outfile
1179
 
  strcpy(pager, "stdout");  // the default, if --pager wasn't given
 
1457
  outfile.clear();      // no (default) outfile
 
1458
  pager.assign("stdout");  // the default, if --pager wasn't given
1180
1459
  {
1181
 
    char *tmp=getenv("PAGER");
 
1460
    const char *tmp= getenv("PAGER");
1182
1461
    if (tmp && strlen(tmp))
1183
1462
    {
1184
1463
      default_pager_set= 1;
1185
 
      strcpy(default_pager, tmp);
 
1464
      default_pager.assign(tmp);
1186
1465
    }
1187
1466
  }
1188
 
  if (!isatty(0) || !isatty(1))
 
1467
  if (! isatty(0) || ! isatty(1))
1189
1468
  {
1190
 
    status.batch=1; opt_silent=1;
 
1469
    status.setBatch(1); opt_silent=1;
1191
1470
    ignore_errors=0;
1192
1471
  }
1193
1472
  else
1194
 
    status.add_to_history=1;
1195
 
  status.exit_status=1;
 
1473
    status.setAddToHistory(1);
 
1474
  status.setExitStatus(1);
1196
1475
 
1197
1476
  {
1198
1477
    /*
1208
1487
      close(stdout_fileno_copy);             /* Clean up dup(). */
1209
1488
  }
1210
1489
 
1211
 
  internal::load_defaults("drizzle",load_default_groups,&argc,&argv);
1212
 
  defaults_argv=argv;
1213
 
  if (get_options(argc, (char **) argv))
1214
 
  {
1215
 
    internal::free_defaults(defaults_argv);
1216
 
    internal::my_end();
 
1490
  /* Inverted Booleans */
 
1491
 
 
1492
  line_numbers= (vm.count("disable-line-numbers")) ? false : true;
 
1493
  column_names= (vm.count("disable-column-names")) ? false : true;
 
1494
  opt_rehash= (vm.count("disable-auto-rehash")) ? false : true;
 
1495
  opt_reconnect= (vm.count("disable-reconnect")) ? false : true;
 
1496
 
 
1497
  /* Don't rehash with --shutdown */
 
1498
  if (vm.count("shutdown"))
 
1499
  {
 
1500
    opt_rehash= false;
 
1501
    opt_shutdown= true;
 
1502
  }
 
1503
 
 
1504
  if (vm.count("delimiter"))
 
1505
  {
 
1506
    /* Check that delimiter does not contain a backslash */
 
1507
    if (! strstr(delimiter_str.c_str(), "\\"))
 
1508
    {
 
1509
      delimiter= (char *)delimiter_str.c_str();  
 
1510
    }
 
1511
    else
 
1512
    {
 
1513
      put_info(_("DELIMITER cannot contain a backslash character"),
 
1514
      INFO_ERROR,0,0);
 
1515
      exit(-1);
 
1516
    }
 
1517
   
 
1518
    delimiter_length= (uint32_t)strlen(delimiter);
 
1519
  }
 
1520
  if (vm.count("tee"))
 
1521
  { 
 
1522
    if (vm["tee"].as<string>().empty())
 
1523
    {
 
1524
      if (opt_outfile)
 
1525
        end_tee();
 
1526
    }
 
1527
    else
 
1528
      init_tee(vm["tee"].as<string>().c_str());
 
1529
  }
 
1530
  if (vm["disable-tee"].as<bool>() == true)
 
1531
  {
 
1532
    if (opt_outfile)
 
1533
      end_tee();
 
1534
  }
 
1535
  if (vm.count("pager"))
 
1536
  {
 
1537
    if (vm["pager"].as<string>().empty())
 
1538
      opt_nopager= 1;
 
1539
    else
 
1540
    {
 
1541
      opt_nopager= 0;
 
1542
      if (vm[pager].as<string>().length())
 
1543
      {
 
1544
        default_pager_set= 1;
 
1545
        pager.assign(vm["pager"].as<string>());
 
1546
        default_pager.assign(pager);
 
1547
      }
 
1548
      else if (default_pager_set)
 
1549
        pager.assign(default_pager);
 
1550
      else
 
1551
        opt_nopager= 1;
 
1552
    }
 
1553
  }
 
1554
  if (vm.count("disable-pager"))
 
1555
  {
 
1556
    opt_nopager= 1;
 
1557
  }
 
1558
 
 
1559
  if (vm.count("no-auto-rehash"))
 
1560
    opt_rehash= 0;
 
1561
 
 
1562
  if (vm.count("skip-column-names"))
 
1563
    column_names= 0;
 
1564
    
 
1565
  if (vm.count("execute"))
 
1566
  {  
 
1567
    status.setBatch(1);
 
1568
    status.setAddToHistory(1);
 
1569
    if (status.getLineBuff() == NULL)
 
1570
      status.setLineBuff(opt_max_input_line,NULL);
 
1571
    if (status.getLineBuff() == NULL)
 
1572
    {
 
1573
      exit(1);
 
1574
    }
 
1575
    status.getLineBuff()->addString(vm["execute"].as<string>().c_str());
 
1576
  }
 
1577
 
 
1578
  if (one_database)
 
1579
    skip_updates= true;
 
1580
 
 
1581
  if (vm.count("protocol"))
 
1582
  {
 
1583
    std::transform(opt_protocol.begin(), opt_protocol.end(), 
 
1584
      opt_protocol.begin(), ::tolower);
 
1585
 
 
1586
    if (not opt_protocol.compare("mysql"))
 
1587
      use_drizzle_protocol=false;
 
1588
    else if (not opt_protocol.compare("drizzle"))
 
1589
      use_drizzle_protocol=true;
 
1590
    else
 
1591
    {
 
1592
      cout << _("Error: Unknown protocol") << " '" << opt_protocol << "'" << endl;
 
1593
      exit(-1);
 
1594
    }
 
1595
  }
 
1596
 
 
1597
  if (vm.count("port"))
 
1598
  {
 
1599
    opt_drizzle_port= vm["port"].as<uint32_t>();
 
1600
 
 
1601
    /* If the port number is > 65535 it is not a valid port
 
1602
       This also helps with potential data loss casting unsigned long to a
 
1603
       uint32_t. */
 
1604
    if (opt_drizzle_port > 65535)
 
1605
    {
 
1606
      printf(_("Error: Value of %" PRIu32 " supplied for port is not valid.\n"), opt_drizzle_port);
 
1607
      exit(-1);
 
1608
    }
 
1609
  }
 
1610
 
 
1611
  if (vm.count("password"))
 
1612
  {
 
1613
    if (!opt_password.empty())
 
1614
      opt_password.erase();
 
1615
    if (current_password == PASSWORD_SENTINEL)
 
1616
    {
 
1617
      opt_password= "";
 
1618
    }
 
1619
    else
 
1620
    {
 
1621
      opt_password= current_password;
 
1622
      tty_password= false;
 
1623
    }
 
1624
  }
 
1625
  else
 
1626
  {
 
1627
      tty_password= true;
 
1628
  }
 
1629
  
 
1630
 
 
1631
  if (!opt_verbose.empty())
 
1632
  {
 
1633
    verbose= opt_verbose.length();
 
1634
  }
 
1635
 
 
1636
  if (vm.count("batch"))
 
1637
  {
 
1638
    status.setBatch(1);
 
1639
    status.setAddToHistory(0);
 
1640
    if (opt_silent < 1)
 
1641
    {
 
1642
      opt_silent= 1;
 
1643
    }
 
1644
  }
 
1645
  if (vm.count("silent"))
 
1646
  {
 
1647
    opt_silent++;
 
1648
  }
 
1649
  
 
1650
  if (vm.count("help") || vm.count("version"))
 
1651
  {
 
1652
    printf(_("Drizzle client %s build %s, for %s-%s (%s) using readline %s\n"),
 
1653
           drizzle_version(), VERSION,
 
1654
           HOST_VENDOR, HOST_OS, HOST_CPU,
 
1655
           rl_library_version);
 
1656
    if (vm.count("version"))
 
1657
      exit(0);
 
1658
    printf(_("Copyright (C) 2008 Sun Microsystems\n"
 
1659
           "This software comes with ABSOLUTELY NO WARRANTY. "
 
1660
           "This is free software,\n"
 
1661
           "and you are welcome to modify and redistribute it "
 
1662
           "under the GPL license\n"));
 
1663
    printf(_("Usage: drizzle [OPTIONS] [database]\n"));
 
1664
    cout << long_options;
 
1665
    exit(0);
 
1666
  }
 
1667
 
 
1668
 
 
1669
  if (process_options())
 
1670
  {
1217
1671
    exit(1);
1218
1672
  }
1219
1673
 
1220
1674
  memset(&drizzle, 0, sizeof(drizzle));
1221
 
  if (sql_connect(current_host,current_db,current_user,opt_password,
1222
 
                  opt_silent))
 
1675
  if (sql_connect(current_host, current_db, current_user, opt_password,opt_silent))
1223
1676
  {
1224
1677
    quick= 1;          // Avoid history
1225
 
    status.exit_status= 1;
 
1678
    status.setExitStatus(1);
1226
1679
    drizzle_end(-1);
1227
1680
  }
1228
1681
 
1230
1683
  if (execute_commands(&command_error) != false)
1231
1684
  {
1232
1685
    /* we've executed a command so exit before we go into readline mode */
1233
 
    internal::free_defaults(defaults_argv);
1234
 
    internal::my_end();
1235
1686
    exit(command_error);
1236
1687
  }
1237
1688
 
1238
 
  if (status.batch && !status.line_buff)
 
1689
  if (status.getBatch() && !status.getLineBuff())
1239
1690
  {
1240
 
    status.line_buff= new(std::nothrow) LineBuffer(opt_max_input_line, stdin);
1241
 
    if (status.line_buff == NULL)
 
1691
    status.setLineBuff(opt_max_input_line, stdin);
 
1692
    if (status.getLineBuff() == NULL)
1242
1693
    {
1243
 
      internal::free_defaults(defaults_argv);
1244
 
      internal::my_end();
1245
1694
      exit(1);
1246
1695
    }
1247
1696
  }
1248
1697
 
1249
 
  if (!status.batch)
 
1698
  if (!status.getBatch())
1250
1699
    ignore_errors=1;        // Don't abort monitor
1251
1700
 
1252
1701
  if (opt_sigint_ignore)
1261
1710
  /* call the SIGWINCH handler to get the default term width */
1262
1711
  window_resize(0);
1263
1712
#endif
1264
 
 
1265
 
  put_info(_("Welcome to the Drizzle client..  Commands end with ; or \\g."),
1266
 
           INFO_INFO,0,0);
 
1713
  std::vector<char> output_buff;
 
1714
  output_buff.resize(512);
 
1715
 
 
1716
  snprintf(&output_buff[0], output_buff.size(), 
 
1717
           _("Welcome to the Drizzle client..  Commands end with %s or \\g."), 
 
1718
           delimiter);
 
1719
 
 
1720
  put_info(&output_buff[0], INFO_INFO, 0, 0);
1267
1721
 
1268
1722
  glob_buffer= new string();
1269
1723
  glob_buffer->reserve(512);
1270
1724
 
1271
 
  size_t output_buff_size = 512;
1272
 
  char * output_buff= (char *)malloc(output_buff_size);
1273
 
  memset(output_buff, '\0', output_buff_size);
1274
 
 
1275
 
  snprintf(output_buff, output_buff_size,
1276
 
           _("Your Drizzle connection id is %u\nServer version: %s\n"),
1277
 
           drizzle_con_thread_id(&con),
1278
 
           server_version_string(&con));
1279
 
  put_info(output_buff, INFO_INFO, 0, 0);
1280
 
 
1281
 
  initialize_readline(current_prompt);
1282
 
  if (!status.batch && !quick)
 
1725
  snprintf(&output_buff[0], output_buff.size(),
 
1726
          _("Your Drizzle connection id is %u\nConnection protocol: %s\nServer version: %s\n"),
 
1727
          drizzle_con_thread_id(&con),
 
1728
          opt_protocol.c_str(),
 
1729
          server_version_string(&con));
 
1730
  put_info(&output_buff[0], INFO_INFO, 0, 0);
 
1731
 
 
1732
 
 
1733
  initialize_readline((char *)current_prompt.c_str());
 
1734
  if (!status.getBatch() && !quick)
1283
1735
  {
1284
1736
    /* read-history from file, default ~/.drizzle_history*/
1285
1737
    if (getenv("DRIZZLE_HISTFILE"))
1286
1738
      histfile= strdup(getenv("DRIZZLE_HISTFILE"));
1287
1739
    else if (getenv("HOME"))
1288
1740
    {
1289
 
      size_t histfile_size = strlen(getenv("HOME")) +
1290
 
        strlen("/.drizzle_history") + 2;
1291
 
      histfile=(char*) malloc(histfile_size);
 
1741
      histfile=(char*) malloc(strlen(getenv("HOME")) + strlen("/.drizzle_history") + 2);
1292
1742
      if (histfile)
1293
 
        snprintf(histfile, histfile_size, "%s/.drizzle_history",getenv("HOME"));
 
1743
        sprintf(histfile,"%s/.drizzle_history",getenv("HOME"));
1294
1744
      char link_name[FN_REFLEN];
1295
1745
      ssize_t sym_link_size= readlink(histfile,link_name,FN_REFLEN-1);
1296
1746
      if (sym_link_size >= 0)
1309
1759
      if (verbose)
1310
1760
        tee_fprintf(stdout, _("Reading history-file %s\n"),histfile);
1311
1761
      read_history(histfile);
1312
 
      size_t histfile_tmp_size = strlen(histfile) + 5;
1313
 
      if (!(histfile_tmp= (char*) malloc(histfile_tmp_size)))
 
1762
      if (!(histfile_tmp= (char*) malloc((uint32_t) strlen(histfile) + 5)))
1314
1763
      {
1315
1764
        fprintf(stderr, _("Couldn't allocate memory for temp histfile!\n"));
1316
1765
        exit(1);
1317
1766
      }
1318
 
      snprintf(histfile_tmp, histfile_tmp_size, "%s.TMP", histfile);
 
1767
      sprintf(histfile_tmp, "%s.TMP", histfile);
1319
1768
    }
1320
1769
  }
1321
1770
 
1322
1771
  put_info(_("Type 'help;' or '\\h' for help. "
1323
1772
             "Type '\\c' to clear the buffer.\n"),INFO_INFO,0,0);
1324
 
  status.exit_status= read_and_execute(!status.batch);
 
1773
  status.setExitStatus(read_and_execute(!status.getBatch()));
1325
1774
  if (opt_outfile)
1326
1775
    end_tee();
1327
1776
  drizzle_end(0);
 
1777
}
1328
1778
 
 
1779
  catch(exception &err)
 
1780
  {
 
1781
    cerr << _("Error:") << err.what() << endl;
 
1782
  }
1329
1783
  return(0);        // Keep compiler happy
1330
1784
}
1331
1785
 
1333
1787
{
1334
1788
  drizzle_con_free(&con);
1335
1789
  drizzle_free(&drizzle);
1336
 
  if (!status.batch && !quick && histfile)
 
1790
  if (!status.getBatch() && !quick && histfile)
1337
1791
  {
1338
1792
    /* write-history */
1339
1793
    if (verbose)
1340
1794
      tee_fprintf(stdout, _("Writing history-file %s\n"),histfile);
1341
1795
    if (!write_history(histfile_tmp))
1342
 
      internal::my_rename(histfile_tmp, histfile, MYF(MY_WME));
 
1796
      rename(histfile_tmp, histfile);
1343
1797
  }
1344
 
  delete status.line_buff;
1345
 
  status.line_buff= 0;
 
1798
  delete status.getLineBuff();
 
1799
  status.setLineBuff(0);
1346
1800
 
1347
1801
  if (sig >= 0)
1348
1802
    put_info(sig ? _("Aborted") : _("Bye"), INFO_RESULT,0,0);
1349
 
  if (glob_buffer)
1350
 
    delete glob_buffer;
1351
 
  if (processed_prompt)
1352
 
    delete processed_prompt;
1353
 
  free(opt_password);
 
1803
  delete glob_buffer;
 
1804
  delete processed_prompt;
 
1805
  opt_password.erase();
1354
1806
  free(histfile);
1355
1807
  free(histfile_tmp);
1356
 
  free(current_db);
1357
 
  free(current_host);
1358
 
  free(current_user);
 
1808
  current_db.erase();
 
1809
  current_host.erase();
 
1810
  current_user.erase();
1359
1811
  free(full_username);
1360
1812
  free(part_username);
1361
1813
  free(default_prompt);
1362
 
  free(current_prompt);
1363
 
  internal::free_defaults(defaults_argv);
1364
 
  internal::my_end();
1365
 
  exit(status.exit_status);
 
1814
  current_prompt.erase();
 
1815
  exit(status.getExitStatus());
1366
1816
}
1367
1817
 
1368
1818
 
1384
1834
    goto err;
1385
1835
  }
1386
1836
 
1387
 
  if (drizzle_con_add_tcp(&drizzle, &kill_drizzle, current_host,
1388
 
                          opt_drizzle_port, current_user, opt_password, NULL,
1389
 
                          opt_mysql ? DRIZZLE_CON_MYSQL : DRIZZLE_CON_NONE) == NULL)
 
1837
  if (drizzle_con_add_tcp(&drizzle, &kill_drizzle, current_host.c_str(),
 
1838
    opt_drizzle_port, current_user.c_str(), opt_password.c_str(), NULL,
 
1839
    use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL) == NULL)
1390
1840
  {
1391
1841
    goto err;
1392
1842
  }
1393
1843
 
1394
1844
  /* kill_buffer is always big enough because max length of %lu is 15 */
1395
 
  snprintf(kill_buffer, sizeof(kill_buffer), "KILL /*!50000 QUERY */ %u",
1396
 
           drizzle_con_thread_id(&con));
 
1845
  sprintf(kill_buffer, "KILL /*!50000 QUERY */ %u",
 
1846
          drizzle_con_thread_id(&con));
1397
1847
 
1398
1848
  if (drizzle_query_str(&kill_drizzle, &res, kill_buffer, &ret) != NULL)
1399
1849
    drizzle_result_free(&res);
1420
1870
}
1421
1871
#endif
1422
1872
 
1423
 
static struct my_option my_long_options[] =
1424
 
{
1425
 
  {"help", '?', N_("Display this help and exit."), 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
1426
 
    0, 0, 0, 0, 0},
1427
 
  {"help", 'I', N_("Synonym for -?"), 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
1428
 
    0, 0, 0, 0, 0},
1429
 
  {"auto-rehash", OPT_AUTO_REHASH,
1430
 
    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."),
1431
 
    (char**) &opt_rehash, (char**) &opt_rehash, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0,
1432
 
    0, 0},
1433
 
  {"no-auto-rehash", 'A',
1434
 
    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."),
1435
 
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1436
 
  {"auto-vertical-output", OPT_AUTO_VERTICAL_OUTPUT,
1437
 
    N_("Automatically switch to vertical output mode if the result is wider than the terminal width."),
1438
 
    (char**) &auto_vertical_output, (char**) &auto_vertical_output, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1439
 
  {"batch", 'B',
1440
 
    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},
1441
 
  {"column-type-info", OPT_COLUMN_TYPES, N_("Display column type information."),
1442
 
    (char**) &column_types_flag, (char**) &column_types_flag,
1443
 
    0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1444
 
  {"comments", 'c', N_("Preserve comments. Send comments to the server. The default is --skip-comments (discard comments), enable with --comments"),
1445
 
    (char**) &preserve_comments, (char**) &preserve_comments,
1446
 
    0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1447
 
  {"compress", 'C', N_("Use compression in server/client protocol."),
1448
 
    (char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
1449
 
    0, 0, 0},
1450
 
  {"database", 'D', N_("Database to use."), (char**) &current_db,
1451
 
    (char**) &current_db, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1452
 
  {"default-character-set", OPT_DEFAULT_CHARSET,
1453
 
    N_("(not used)"), 0,
1454
 
    0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1455
 
  {"delimiter", OPT_DELIMITER, N_("Delimiter to be used."), (char**) &delimiter_str,
1456
 
    (char**) &delimiter_str, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1457
 
  {"execute", 'e', N_("Execute command and quit. (Disables --force and history file)"), 0,
1458
 
    0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1459
 
  {"vertical", 'E', N_("Print the output of a query (rows) vertically."),
1460
 
    (char**) &vertical, (char**) &vertical, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
1461
 
    0},
1462
 
  {"force", 'f', N_("Continue even if we get an sql error."),
1463
 
    (char**) &ignore_errors, (char**) &ignore_errors, 0, GET_BOOL, NO_ARG, 0, 0,
1464
 
    0, 0, 0, 0},
1465
 
  {"named-commands", 'G',
1466
 
    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."),
1467
 
    (char**) &named_cmds, (char**) &named_cmds, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
1468
 
    0, 0},
1469
 
  {"no-named-commands", 'g',
1470
 
    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."),
1471
 
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1472
 
  {"ignore-spaces", 'i', N_("Ignore space after function names."), 0, 0, 0,
1473
 
    GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1474
 
  {"local-infile", OPT_LOCAL_INFILE, N_("Enable/disable LOAD DATA LOCAL INFILE."),
1475
 
    (char**) &opt_local_infile,
1476
 
    (char**) &opt_local_infile, 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
1477
 
  {"no-beep", 'b', N_("Turn off beep on error."), (char**) &opt_nobeep,
1478
 
    (char**) &opt_nobeep, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1479
 
  {"host", 'h', N_("Connect to host."), (char**) &current_host,
1480
 
    (char**) &current_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1481
 
  {"line-numbers", OPT_LINE_NUMBERS, N_("Write line numbers for errors."),
1482
 
    (char**) &line_numbers, (char**) &line_numbers, 0, GET_BOOL,
1483
 
    NO_ARG, 1, 0, 0, 0, 0, 0},
1484
 
  {"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,
1485
 
    NO_ARG, 0, 0, 0, 0, 0, 0},
1486
 
  {"unbuffered", 'n', N_("Flush buffer after each query."), (char**) &unbuffered,
1487
 
    (char**) &unbuffered, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1488
 
  {"column-names", OPT_COLUMN_NAMES, N_("Write column names in results."),
1489
 
    (char**) &column_names, (char**) &column_names, 0, GET_BOOL,
1490
 
    NO_ARG, 1, 0, 0, 0, 0, 0},
1491
 
  {"skip-column-names", 'N',
1492
 
    N_("Don't write column names in results. WARNING: -N is deprecated, use long version of this options instead."),
1493
 
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1494
 
  {"set-variable", 'O',
1495
 
    N_("Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value."),
1496
 
    0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1497
 
  {"sigint-ignore", OPT_SIGINT_IGNORE, N_("Ignore SIGINT (CTRL-C)"),
1498
 
    (char**) &opt_sigint_ignore,  (char**) &opt_sigint_ignore, 0, GET_BOOL,
1499
 
    NO_ARG, 0, 0, 0, 0, 0, 0},
1500
 
  {"one-database", 'o',
1501
 
    N_("Only update the default database. This is useful for skipping updates to other database in the update log."),
1502
 
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1503
 
  {"pager", OPT_PAGER,
1504
 
    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."),
1505
 
    0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
1506
 
  {"no-pager", OPT_NOPAGER,
1507
 
    N_("Disable pager and print to stdout. See interactive help (\\h) also. WARNING: option deprecated; use --disable-pager instead."),
1508
 
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1509
 
  {"password", 'P',
1510
 
    N_("Password to use when connecting to server. If password is not given it's asked from the tty."),
1511
 
    0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
1512
 
  {"port", 'p', N_("Port number to use for connection or 0 for default to, in order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, ")
1513
 
    N_("built-in default") " (" STRINGIFY_ARG(DRIZZLE_PORT) ").",
1514
 
    0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1515
 
  {"prompt", OPT_PROMPT, N_("Set the drizzle prompt to this value."),
1516
 
    (char**) &current_prompt, (char**) &current_prompt, 0, GET_STR_ALLOC,
1517
 
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1518
 
  {"quick", 'q',
1519
 
    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."),
1520
 
    (char**) &quick, (char**) &quick, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1521
 
  {"raw", 'r', N_("Write fields without conversion. Used with --batch."),
1522
 
    (char**) &opt_raw_data, (char**) &opt_raw_data, 0, GET_BOOL, NO_ARG, 0, 0, 0,
1523
 
    0, 0, 0},
1524
 
  {"reconnect", OPT_RECONNECT, N_("Reconnect if the connection is lost. Disable with --disable-reconnect. This option is enabled by default."),
1525
 
    (char**) &opt_reconnect, (char**) &opt_reconnect, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
1526
 
  {"shutdown", OPT_SHUTDOWN, N_("Shutdown the server."),
1527
 
    (char**) &opt_shutdown, (char**) &opt_shutdown, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1528
 
  {"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,
1529
 
    0, 0},
1530
 
  {"table", 't', N_("Output in table format."), (char**) &output_tables,
1531
 
    (char**) &output_tables, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1532
 
  {"tee", OPT_TEE,
1533
 
    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."),
1534
 
    0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1535
 
  {"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,
1536
 
    NO_ARG, 0, 0, 0, 0, 0, 0},
1537
 
  {"user", 'u', N_("User for login if not current user."), (char**) &current_user,
1538
 
    (char**) &current_user, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1539
 
  {"safe-updates", 'U', N_("Only allow UPDATE and DELETE that uses keys."),
1540
 
    (char**) &safe_updates, (char**) &safe_updates, 0, GET_BOOL, NO_ARG, 0, 0,
1541
 
    0, 0, 0, 0},
1542
 
  {"i-am-a-dummy", 'U', N_("Synonym for option --safe-updates, -U."),
1543
 
    (char**) &safe_updates, (char**) &safe_updates, 0, GET_BOOL, NO_ARG, 0, 0,
1544
 
    0, 0, 0, 0},
1545
 
  {"verbose", 'v', N_("Write more. (-v -v -v gives the table output format)."), 0,
1546
 
    0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1547
 
  {"version", 'V', N_("Output version information and exit."), 0, 0, 0,
1548
 
    GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1549
 
  {"wait", 'w', N_("Wait and retry if connection is down."), 0, 0, 0, GET_NO_ARG,
1550
 
    NO_ARG, 0, 0, 0, 0, 0, 0},
1551
 
  {"connect_timeout", OPT_CONNECT_TIMEOUT,
1552
 
    N_("Number of seconds before connection timeout."),
1553
 
    (char**) &opt_connect_timeout,
1554
 
    (char**) &opt_connect_timeout, 0, GET_UINT32, REQUIRED_ARG, 0, 0, 3600*12, 0,
1555
 
    0, 0},
1556
 
  {"max_input_line", OPT_MAX_INPUT_LINE,
1557
 
    N_("Max length of input line"),
1558
 
    (char**) &opt_max_input_line, (char**) &opt_max_input_line, 0,
1559
 
    GET_UINT32, REQUIRED_ARG, 16 *1024L*1024L, 4096,
1560
 
    (int64_t) 2*1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
1561
 
  {"select_limit", OPT_SELECT_LIMIT,
1562
 
    N_("Automatic limit for SELECT when using --safe-updates"),
1563
 
    (char**) &select_limit,
1564
 
    (char**) &select_limit, 0, GET_UINT32, REQUIRED_ARG, 1000L, 1, ULONG_MAX,
1565
 
    0, 1, 0},
1566
 
  {"max_join_size", OPT_MAX_JOIN_SIZE,
1567
 
    N_("Automatic limit for rows in a join when using --safe-updates"),
1568
 
    (char**) &max_join_size,
1569
 
    (char**) &max_join_size, 0, GET_UINT32, REQUIRED_ARG, 1000000L, 1, ULONG_MAX,
1570
 
    0, 1, 0},
1571
 
  {"secure-auth", OPT_SECURE_AUTH, N_("Refuse client connecting to server if it uses old (pre-4.1.1) protocol"), (char**) &opt_secure_auth,
1572
 
    (char**) &opt_secure_auth, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1573
 
  {"show-warnings", OPT_SHOW_WARNINGS, N_("Show warnings after every statement."),
1574
 
    (char**) &show_warnings, (char**) &show_warnings, 0, GET_BOOL, NO_ARG,
1575
 
    0, 0, 0, 0, 0, 0},
1576
 
  {"show-progress-size", OPT_SHOW_PROGRESS_SIZE, N_("Number of lines before each import progress report."),
1577
 
    (char**) &show_progress_size, (char**) &show_progress_size, 0, GET_UINT32, REQUIRED_ARG,
1578
 
    0, 0, 0, 0, 0, 0},
1579
 
  {"ping", OPT_PING, N_("Ping the server to check if it's alive."),
1580
 
    (char**) &opt_ping, (char**) &opt_ping, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1581
 
  {"mysql", 'm', N_("Use MySQL Protocol."),
1582
 
    (char**) &opt_mysql, (char**) &opt_mysql, 0, GET_BOOL, NO_ARG, 1, 0, 0,
1583
 
    0, 0, 0},
1584
 
  { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
1585
 
};
1586
 
 
1587
 
 
1588
 
static void usage(int version)
1589
 
{
1590
 
  const char* readline= "readline";
1591
 
 
1592
 
  printf(_("%s  Ver %s Distrib %s, for %s-%s (%s) using %s %s\n"),
1593
 
         internal::my_progname, VER.c_str(), drizzle_version(),
1594
 
         HOST_VENDOR, HOST_OS, HOST_CPU,
1595
 
         readline, rl_library_version);
1596
 
 
1597
 
  if (version)
1598
 
    return;
1599
 
  printf(_("Copyright (C) 2008 Sun Microsystems\n"
1600
 
           "This software comes with ABSOLUTELY NO WARRANTY. "
1601
 
           "This is free software,\n"
1602
 
           "and you are welcome to modify and redistribute it "
1603
 
           "under the GPL license\n"));
1604
 
  printf(_("Usage: %s [OPTIONS] [database]\n"), internal::my_progname);
1605
 
  my_print_help(my_long_options);
1606
 
  internal::print_defaults("drizzle", load_default_groups);
1607
 
  my_print_variables(my_long_options);
1608
 
}
1609
 
 
1610
 
 
1611
 
static int get_one_option(int optid, const struct my_option *, char *argument)
1612
 
{
1613
 
  char *endchar= NULL;
1614
 
  uint64_t temp_drizzle_port= 0;
1615
 
 
1616
 
  switch(optid) {
1617
 
  case  OPT_DEFAULT_CHARSET:
1618
 
    default_charset_used= 1;
1619
 
    break;
1620
 
  case OPT_DELIMITER:
1621
 
    if (argument == disabled_my_option)
1622
 
    {
1623
 
      strcpy(delimiter, DEFAULT_DELIMITER);
1624
 
    }
1625
 
    else
1626
 
    {
1627
 
      /* Check that delimiter does not contain a backslash */
1628
 
      if (!strstr(argument, "\\"))
1629
 
      {
1630
 
        strncpy(delimiter, argument, sizeof(delimiter) - 1);
1631
 
      }
1632
 
      else
1633
 
      {
1634
 
        put_info(_("DELIMITER cannot contain a backslash character"),
1635
 
                 INFO_ERROR,0,0);
1636
 
        return EXIT_ARGUMENT_INVALID;
1637
 
      }
1638
 
    }
1639
 
    delimiter_length= (uint32_t)strlen(delimiter);
1640
 
    delimiter_str= delimiter;
1641
 
    break;
1642
 
  case OPT_TEE:
1643
 
    if (argument == disabled_my_option)
1644
 
    {
1645
 
      if (opt_outfile)
1646
 
        end_tee();
1647
 
    }
1648
 
    else
1649
 
      init_tee(argument);
1650
 
    break;
1651
 
  case OPT_NOTEE:
1652
 
    printf(_("WARNING: option deprecated; use --disable-tee instead.\n"));
1653
 
    if (opt_outfile)
1654
 
      end_tee();
1655
 
    break;
1656
 
  case OPT_PAGER:
1657
 
    if (argument == disabled_my_option)
1658
 
      opt_nopager= 1;
1659
 
    else
1660
 
    {
1661
 
      opt_nopager= 0;
1662
 
      if (argument && strlen(argument))
1663
 
      {
1664
 
        default_pager_set= 1;
1665
 
        strncpy(pager, argument, sizeof(pager) - 1);
1666
 
        strcpy(default_pager, pager);
1667
 
      }
1668
 
      else if (default_pager_set)
1669
 
        strcpy(pager, default_pager);
1670
 
      else
1671
 
        opt_nopager= 1;
1672
 
    }
1673
 
    break;
1674
 
  case OPT_NOPAGER:
1675
 
    printf(_("WARNING: option deprecated; use --disable-pager instead.\n"));
1676
 
    opt_nopager= 1;
1677
 
    break;
1678
 
  case OPT_SERVER_ARG:
1679
 
    printf(_("WARNING: --server-arg option not supported in this configuration.\n"));
1680
 
    break;
1681
 
  case 'A':
1682
 
    opt_rehash= 0;
1683
 
    break;
1684
 
  case 'N':
1685
 
    column_names= 0;
1686
 
    break;
1687
 
  case 'e':
1688
 
    status.batch= 1;
1689
 
    status.add_to_history= 0;
1690
 
    if (status.line_buff == NULL)
1691
 
      status.line_buff= new(std::nothrow) LineBuffer(opt_max_input_line,NULL);
1692
 
    if (status.line_buff == NULL)
1693
 
    {
1694
 
      internal::my_end();
1695
 
      exit(1);
1696
 
    }
1697
 
    status.line_buff->addString(argument);
1698
 
    break;
1699
 
  case 'o':
1700
 
    if (argument == disabled_my_option)
1701
 
      one_database= 0;
1702
 
    else
1703
 
      one_database= skip_updates= 1;
1704
 
    break;
1705
 
  case 'p':
1706
 
    temp_drizzle_port= (uint64_t) strtoul(argument, &endchar, 10);
1707
 
    /* if there is an alpha character this is not a valid port */
1708
 
    if (strlen(endchar) != 0)
1709
 
    {
1710
 
      put_info(_("Non-integer value supplied for port.  If you are trying to enter a password please use --password instead."), INFO_ERROR, 0, 0);
1711
 
      return EXIT_ARGUMENT_INVALID;
1712
 
    }
1713
 
    /* If the port number is > 65535 it is not a valid port
1714
 
      This also helps with potential data loss casting unsigned long to a
1715
 
      uint32_t. */
1716
 
    if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
1717
 
    {
1718
 
      put_info(_("Value supplied for port is not valid."), INFO_ERROR, 0, 0);
1719
 
      return EXIT_ARGUMENT_INVALID;
1720
 
    }
1721
 
    else
1722
 
    {
1723
 
      opt_drizzle_port= (uint32_t) temp_drizzle_port;
1724
 
    }
1725
 
    break;
1726
 
  case 'P':
1727
 
    /* Don't require password */
1728
 
    if (argument == disabled_my_option)
1729
 
    {
1730
 
      argument= (char*) "";
1731
 
    }
1732
 
    if (argument)
1733
 
    {
1734
 
      char *start= argument;
1735
 
      free(opt_password);
1736
 
      opt_password= strdup(argument);
1737
 
      while (*argument)
1738
 
      {
1739
 
        /* Overwriting password with 'x' */
1740
 
        *argument++= 'x';
1741
 
      }
1742
 
      if (*start)
1743
 
      {
1744
 
        start[1]= 0;
1745
 
      }
1746
 
      tty_password= 0;
1747
 
    }
1748
 
    else
1749
 
    {
1750
 
      tty_password= 1;
1751
 
    }
1752
 
    break;
1753
 
  case 's':
1754
 
    if (argument == disabled_my_option)
1755
 
      opt_silent= 0;
1756
 
    else
1757
 
      opt_silent++;
1758
 
    break;
1759
 
  case 'v':
1760
 
    if (argument == disabled_my_option)
1761
 
      verbose= 0;
1762
 
    else
1763
 
      verbose++;
1764
 
    break;
1765
 
  case 'B':
1766
 
    status.batch= 1;
1767
 
    status.add_to_history= 0;
1768
 
    set_if_bigger(opt_silent,1);                         // more silent
1769
 
    break;
1770
 
  case 'V':
1771
 
    usage(1);
1772
 
    exit(0);
1773
 
  case 'I':
1774
 
  case '?':
1775
 
    usage(0);
1776
 
    exit(0);
1777
 
  }
1778
 
  return 0;
1779
 
}
1780
 
 
1781
 
 
1782
 
static int get_options(int argc, char **argv)
 
1873
 
 
1874
 
 
1875
static int process_options(void)
1783
1876
{
1784
1877
  char *tmp, *pagpoint;
1785
 
  int ho_error;
 
1878
  
1786
1879
 
1787
1880
  tmp= (char *) getenv("DRIZZLE_HOST");
1788
1881
  if (tmp)
1789
 
    current_host= strdup(tmp);
 
1882
    current_host.assign(tmp);
1790
1883
 
1791
1884
  pagpoint= getenv("PAGER");
1792
1885
  if (!((char*) (pagpoint)))
1793
1886
  {
1794
 
    strcpy(pager, "stdout");
 
1887
    pager.assign("stdout");
1795
1888
    opt_nopager= 1;
1796
1889
  }
1797
1890
  else
1798
 
    strcpy(pager, pagpoint);
1799
 
  strcpy(default_pager, pager);
1800
 
 
1801
 
  if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
1802
 
    exit(ho_error);
1803
 
 
1804
 
  if (status.batch) /* disable pager and outfile in this case */
1805
 
  {
1806
 
    strcpy(default_pager, "stdout");
1807
 
    strcpy(pager, "stdout");
 
1891
  {
 
1892
    pager.assign(pagpoint);
 
1893
  }
 
1894
  default_pager.assign(pager);
 
1895
 
 
1896
  //
 
1897
 
 
1898
  if (status.getBatch()) /* disable pager and outfile in this case */
 
1899
  {
 
1900
    default_pager.assign("stdout");
 
1901
    pager.assign("stdout");
1808
1902
    opt_nopager= 1;
1809
1903
    default_pager_set= 0;
1810
1904
    opt_outfile= 0;
1812
1906
    connect_flag= DRIZZLE_CAPABILITIES_NONE; /* Not in interactive mode */
1813
1907
  }
1814
1908
 
1815
 
  if (argc > 1)
1816
 
  {
1817
 
    usage(0);
1818
 
    exit(1);
1819
 
  }
1820
 
  if (argc == 1)
1821
 
  {
1822
 
    skip_updates= 0;
1823
 
    free(current_db);
1824
 
    current_db= strdup(*argv);
1825
 
  }
1826
1909
  if (tty_password)
1827
1910
    opt_password= client_get_tty_password(NULL);
1828
 
 
1829
1911
  return(0);
1830
1912
}
1831
1913
 
1835
1917
  char in_string=0;
1836
1918
  uint32_t line_number=0;
1837
1919
  bool ml_comment= 0;
1838
 
  COMMANDS *com;
1839
 
  status.exit_status=1;
 
1920
  Commands *com;
 
1921
  status.setExitStatus(1);
1840
1922
 
1841
1923
  for (;;)
1842
1924
  {
1843
1925
    if (!interactive)
1844
1926
    {
1845
 
      if (status.line_buff)
1846
 
        line= status.line_buff->readline();
 
1927
      if (status.getLineBuff())
 
1928
        line= status.getLineBuff()->readline();
1847
1929
      else
1848
1930
        line= 0;
1849
1931
 
1854
1936
          fprintf(stderr, _("Processing line: %"PRIu32"\n"), line_number);
1855
1937
      }
1856
1938
      if (!glob_buffer->empty())
1857
 
        status.query_start_line= line_number;
 
1939
        status.setQueryStartLine(line_number);
1858
1940
    }
1859
1941
    else
1860
1942
    {
1861
 
      const char *prompt= (const char*) (ml_comment ? "   /*> " :
1862
 
                                         (glob_buffer->empty())
1863
 
                                         ?  construct_prompt()
1864
 
                                         : !in_string ? "    -> " :
1865
 
                                         in_string == '\'' ?
1866
 
                                         "    '> " : (in_string == '`' ?
1867
 
                                                      "    `> " :
1868
 
                                                      "    \"> "));
 
1943
      string prompt(ml_comment
 
1944
                      ? "   /*> " 
 
1945
                      : glob_buffer->empty()
 
1946
                        ? construct_prompt()
 
1947
                        : not in_string
 
1948
                          ? "    -> "
 
1949
                          : in_string == '\''
 
1950
                            ? "    '> "
 
1951
                            : in_string == '`'
 
1952
                              ? "    `> "
 
1953
                              : "    \"> ");
1869
1954
      if (opt_outfile && glob_buffer->empty())
1870
1955
        fflush(OUTFILE);
1871
1956
 
1872
1957
      if (opt_outfile)
1873
 
        fputs(prompt, OUTFILE);
1874
 
      line= readline(prompt);
 
1958
        fputs(prompt.c_str(), OUTFILE);
 
1959
      line= readline(prompt.c_str());
1875
1960
      /*
1876
1961
        When Ctrl+d or Ctrl+z is pressed, the line may be NULL on some OS
1877
1962
        which may cause coredump.
1882
1967
    // End of file
1883
1968
    if (!line)
1884
1969
    {
1885
 
      status.exit_status=0;
 
1970
      status.setExitStatus(0);
1886
1971
      break;
1887
1972
    }
1888
1973
 
1898
1983
      // If buffer was emptied
1899
1984
      if (glob_buffer->empty())
1900
1985
        in_string=0;
1901
 
      if (interactive && status.add_to_history && not_in_history(line))
 
1986
      if (interactive && status.getAddToHistory() && not_in_history(line))
1902
1987
        add_history(line);
1903
1988
      continue;
1904
1989
    }
1907
1992
  }
1908
1993
  /* if in batch mode, send last query even if it doesn't end with \g or go */
1909
1994
 
1910
 
  if (!interactive && !status.exit_status)
 
1995
  if (!interactive && !status.getExitStatus())
1911
1996
  {
1912
1997
    remove_cntrl(glob_buffer);
1913
1998
    if (!glob_buffer->empty())
1914
1999
    {
1915
 
      status.exit_status=1;
 
2000
      status.setExitStatus(1);
1916
2001
      if (com_go(glob_buffer,line) <= 0)
1917
 
        status.exit_status=0;
 
2002
        status.setExitStatus(0);
1918
2003
    }
1919
2004
  }
1920
2005
 
1921
 
  return status.exit_status;
 
2006
  return status.getExitStatus();
1922
2007
}
1923
2008
 
1924
2009
 
1925
 
static COMMANDS *find_command(const char *name,char cmd_char)
 
2010
static Commands *find_command(const char *name,char cmd_char)
1926
2011
{
1927
2012
  uint32_t len;
1928
2013
  const char *end;
1934
2019
  }
1935
2020
  else
1936
2021
  {
1937
 
    while (my_isspace(charset_info,*name))
 
2022
    while (isspace(*name))
1938
2023
      name++;
1939
2024
    /*
1940
2025
      If there is an \\g in the row or if the row has a delimiter but
1943
2028
    */
1944
2029
    if (strstr(name, "\\g") || (strstr(name, delimiter) &&
1945
2030
                                !(strlen(name) >= 9 &&
1946
 
                                  !my_strnncoll(charset_info,
1947
 
                                                (unsigned char*) name, 9,
1948
 
                                                (const unsigned char*) "delimiter",
1949
 
                                                9))))
1950
 
      return((COMMANDS *) 0);
 
2031
                                  !strcmp(name, "delimiter"))))
 
2032
      return(NULL);
1951
2033
    if ((end=strcont(name," \t")))
1952
2034
    {
1953
2035
      len=(uint32_t) (end - name);
1954
 
      while (my_isspace(charset_info,*end))
 
2036
      while (isspace(*end))
1955
2037
        end++;
1956
2038
      if (!*end)
1957
2039
        end=0;          // no arguments to function
1960
2042
      len=(uint32_t) strlen(name);
1961
2043
  }
1962
2044
 
1963
 
  for (uint32_t i= 0; commands[i].name; i++)
 
2045
  for (uint32_t i= 0; commands[i].getName(); i++)
1964
2046
  {
1965
2047
    if (commands[i].func &&
1966
 
        ((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)))
 
2048
        ((name && !strncmp(name, commands[i].getName(), len)
 
2049
          && !commands[i].getName()[len] && (!end || (end && commands[i].getTakesParams()))) || (!name && commands[i].getCmdChar() == cmd_char)))
1967
2050
    {
1968
2051
      return(&commands[i]);
1969
2052
    }
1970
2053
  }
1971
 
  return((COMMANDS *) 0);
 
2054
  return(NULL);
1972
2055
}
1973
2056
 
1974
2057
 
1975
2058
static bool add_line(string *buffer, char *line, char *in_string,
1976
 
                     bool *ml_comment)
 
2059
                        bool *ml_comment)
1977
2060
{
1978
2061
  unsigned char inchar;
1979
2062
  char *pos, *out;
1980
 
  COMMANDS *com;
 
2063
  Commands *com;
1981
2064
  bool need_space= 0;
1982
2065
  bool ss_comment= 0;
1983
2066
 
1984
2067
 
1985
2068
  if (!line[0] && (buffer->empty()))
1986
2069
    return(0);
1987
 
  if (status.add_to_history && line[0] && not_in_history(line))
 
2070
  if (status.getAddToHistory() && line[0] && not_in_history(line))
1988
2071
    add_history(line);
1989
2072
  char *end_of_line=line+(uint32_t) strlen(line);
1990
2073
 
1993
2076
    if (!preserve_comments)
1994
2077
    {
1995
2078
      // Skip spaces at the beggining of a statement
1996
 
      if (my_isspace(charset_info,inchar) && (out == line) &&
 
2079
      if (isspace(inchar) && (out == line) &&
1997
2080
          (buffer->empty()))
1998
2081
        continue;
1999
2082
    }
2000
2083
 
2001
2084
    // Accept multi-byte characters as-is
2002
 
    int length;
2003
 
    if (use_mb(charset_info) &&
2004
 
        (length= my_ismbchar(charset_info, pos, end_of_line)))
 
2085
    if (not drizzled::utf8::is_single(*pos))
2005
2086
    {
2006
 
      if (!*ml_comment || preserve_comments)
 
2087
      int length;
 
2088
      if ((length= drizzled::utf8::sequence_length(*pos)))
2007
2089
      {
2008
 
        while (length--)
2009
 
          *out++ = *pos++;
2010
 
        pos--;
 
2090
        if (!*ml_comment || preserve_comments)
 
2091
        {
 
2092
          while (length--)
 
2093
            *out++ = *pos++;
 
2094
          pos--;
 
2095
        }
 
2096
        else
 
2097
          pos+= length - 1;
 
2098
        continue;
2011
2099
      }
2012
 
      else
2013
 
        pos+= length - 1;
2014
 
      continue;
2015
2100
    }
2016
2101
    if (!*ml_comment && inchar == '\\' &&
2017
2102
        !(*in_string && (drizzle_con_status(&con) & DRIZZLE_CON_STATUS_NO_BACKSLASH_ESCAPES)))
2037
2122
 
2038
2123
        if ((*com->func)(buffer,pos-1) > 0)
2039
2124
          return(1);                       // Quit
2040
 
        if (com->takes_params)
 
2125
        if (com->getTakesParams())
2041
2126
        {
2042
2127
          if (ss_comment)
2043
2128
          {
2080
2165
    }
2081
2166
    else if (!*ml_comment && !*in_string &&
2082
2167
             (end_of_line - pos) >= 10 &&
2083
 
             !my_strnncoll(charset_info, (unsigned char*) pos, 10,
2084
 
                           (const unsigned char*) "delimiter ", 10))
 
2168
             !strncmp(pos, "delimiter ", 10))
2085
2169
    {
2086
2170
      // Flush previously accepted characters
2087
2171
      if (out != line)
2118
2202
 
2119
2203
      if (preserve_comments)
2120
2204
      {
2121
 
        while (my_isspace(charset_info, *pos))
 
2205
        while (isspace(*pos))
2122
2206
          *out++= *pos++;
2123
2207
      }
2124
2208
      // Flush previously accepted characters
2131
2215
      if (preserve_comments && ((*pos == '#') ||
2132
2216
                                ((*pos == '-') &&
2133
2217
                                 (pos[1] == '-') &&
2134
 
                                 my_isspace(charset_info, pos[2]))))
 
2218
                                 isspace(pos[2]))))
2135
2219
      {
2136
2220
        // Add trailing single line comments to this statement
2137
2221
        buffer->append(pos);
2158
2242
                 && (inchar == '#'
2159
2243
                     || (inchar == '-'
2160
2244
                         && pos[1] == '-'
2161
 
                         && my_isspace(charset_info,pos[2])))))
 
2245
                         && isspace(pos[2])))))
2162
2246
    {
2163
2247
      // Flush previously accepted characters
2164
2248
      if (out != line)
2224
2308
        *in_string= (char) inchar;
2225
2309
      if (!*ml_comment || preserve_comments)
2226
2310
      {
2227
 
        if (need_space && !my_isspace(charset_info, (char)inchar))
 
2311
        if (need_space && !isspace((char)inchar))
2228
2312
          *out++= ' ';
2229
2313
        need_space= 0;
2230
2314
        *out++= (char) inchar;
2235
2319
  {
2236
2320
    *out++='\n';
2237
2321
    uint32_t length=(uint32_t) (out-line);
 
2322
    if ((buffer->length() + length) > opt_max_input_line)
 
2323
    {
 
2324
      status.setExitStatus(1);
 
2325
      put_info(_("Not found a delimiter within max_input_line of input"), INFO_ERROR, 0, 0);
 
2326
      return 1;
 
2327
    }
2238
2328
    if ((!*ml_comment || preserve_comments))
2239
2329
      buffer->append(line, length);
2240
2330
  }
2242
2332
}
2243
2333
 
2244
2334
/*****************************************************************
2245
 
  Interface to Readline Completion
2246
 
 ******************************************************************/
 
2335
            Interface to Readline Completion
 
2336
******************************************************************/
2247
2337
 
2248
2338
 
2249
2339
static char **mysql_completion (const char *text, int start, int end);
2351
2441
*/
2352
2442
char **mysql_completion (const char *text, int, int)
2353
2443
{
2354
 
  if (!status.batch && !quick)
 
2444
  if (!status.getBatch() && !quick)
2355
2445
    return rl_completion_matches(text, new_command_generator);
2356
2446
  else
2357
2447
    return (char**) 0;
2420
2510
 
2421
2511
static void build_completion_hash(bool rehash, bool write_info)
2422
2512
{
2423
 
  COMMANDS *cmd=commands;
 
2513
  Commands *cmd=commands;
2424
2514
  drizzle_return_t ret;
2425
2515
  drizzle_result_st databases,tables,fields;
2426
2516
  drizzle_row_t database_row,table_row;
2427
2517
  drizzle_column_st *sql_field;
2428
2518
  string tmp_str, tmp_str_lower;
2429
2519
 
2430
 
  if (status.batch || quick || !current_db)
 
2520
  if (status.getBatch() || quick || current_db.empty())
2431
2521
    return;      // We don't need completion in batches
2432
2522
  if (!rehash)
2433
2523
    return;
2435
2525
  completion_map.clear();
2436
2526
 
2437
2527
  /* hash this file's known subset of SQL commands */
2438
 
  while (cmd->name) {
2439
 
    tmp_str= cmd->name;
 
2528
  while (cmd->getName()) {
 
2529
    tmp_str= cmd->getName();
2440
2530
    tmp_str_lower= lower_string(tmp_str);
2441
2531
    completion_map[tmp_str_lower]= tmp_str;
2442
2532
    cmd++;
2480
2570
    {
2481
2571
      if (drizzle_result_row_count(&tables) > 0 && !opt_silent && write_info)
2482
2572
      {
2483
 
        tee_fprintf(stdout, _("\
2484
 
                              Reading table information for completion of table and column names\n    \
2485
 
                              You can turn off this feature to get a quicker startup with -A\n\n"));
 
2573
        tee_fprintf(stdout,
 
2574
                    _("Reading table information for completion of "
 
2575
                      "table and column names\n"
 
2576
                      "You can turn off this feature to get a quicker "
 
2577
                      "startup with -A\n\n"));
2486
2578
      }
2487
2579
      while ((table_row=drizzle_row_next(&tables)))
2488
2580
      {
2511
2603
    query.append("show fields in '");
2512
2604
    query.append(table_row[0]);
2513
2605
    query.append("'");
2514
 
 
 
2606
    
2515
2607
    if (drizzle_query(&con, &fields, query.c_str(), query.length(),
2516
2608
                      &ret) != NULL)
2517
2609
    {
2560
2652
  drizzle_return_t ret;
2561
2653
  drizzle_result_st res;
2562
2654
 
2563
 
  free(current_db);
2564
 
  current_db= NULL;
 
2655
  current_db.erase();
 
2656
  current_db= "";
2565
2657
  /* In case of error below current_db will be NULL */
2566
2658
  if (drizzle_query_str(&con, &res, "SELECT DATABASE()", &ret) != NULL)
2567
2659
  {
2570
2662
    {
2571
2663
      drizzle_row_t row= drizzle_row_next(&res);
2572
2664
      if (row[0])
2573
 
        current_db= strdup(row[0]);
 
2665
        current_db.assign(row[0]);
2574
2666
      drizzle_result_free(&res);
2575
2667
    }
2576
2668
  }
2577
2669
}
2578
2670
 
2579
2671
/***************************************************************************
2580
 
  The different commands
2581
 
 ***************************************************************************/
 
2672
 The different commands
 
2673
***************************************************************************/
2582
2674
 
2583
 
int drizzleclient_real_query_for_lazy(const char *buf, int length,
 
2675
int drizzleclient_real_query_for_lazy(const char *buf, size_t length,
2584
2676
                                      drizzle_result_st *result,
2585
2677
                                      uint32_t *error_code)
2586
2678
{
2619
2711
    return 0;
2620
2712
 
2621
2713
  if (drizzle_con_error(&con)[0])
2622
 
    return put_error(&con, result);
 
2714
  {
 
2715
    int ret= put_error(&con, result);
 
2716
    drizzle_result_free(result);
 
2717
    return ret;
 
2718
  }
2623
2719
  return 0;
2624
2720
}
2625
2721
 
2628
2724
{
2629
2725
  register int i, j;
2630
2726
  char buff[32], *end;
 
2727
  std::vector<char> output_buff;
 
2728
  output_buff.resize(512);
2631
2729
 
2632
2730
  put_info(_("List of all Drizzle commands:"), INFO_INFO,0,0);
2633
2731
  if (!named_cmds)
2634
 
    put_info(_("Note that all text commands must be first on line and end with ';'"),INFO_INFO,0,0);
2635
 
  for (i = 0; commands[i].name; i++)
2636
 
  {
2637
 
    end= strcpy(buff, commands[i].name);
2638
 
    end+= strlen(commands[i].name);
2639
 
    for (j= (int)strlen(commands[i].name); j < 10; j++)
 
2732
  {
 
2733
    snprintf(&output_buff[0], output_buff.size(),
 
2734
             _("Note that all text commands must be first on line and end with '%s' or \\g"),
 
2735
             delimiter);
 
2736
    put_info(&output_buff[0], INFO_INFO, 0, 0);
 
2737
  }
 
2738
  for (i = 0; commands[i].getName(); i++)
 
2739
  {
 
2740
    end= strcpy(buff, commands[i].getName());
 
2741
    end+= strlen(commands[i].getName());
 
2742
    for (j= (int)strlen(commands[i].getName()); j < 10; j++)
2640
2743
      end= strcpy(end, " ")+1;
2641
2744
    if (commands[i].func)
2642
2745
      tee_fprintf(stdout, "%s(\\%c) %s\n", buff,
2643
 
                  commands[i].cmd_char, _(commands[i].doc));
 
2746
                  commands[i].getCmdChar(), _(commands[i].getDoc()));
2644
2747
  }
2645
2748
  tee_fprintf(stdout, "\n");
2646
2749
  buffer->clear();
2651
2754
static int
2652
2755
com_clear(string *buffer, const char *)
2653
2756
{
2654
 
  if (status.add_to_history)
 
2757
  if (status.getAddToHistory())
2655
2758
    fix_history(buffer);
2656
2759
  buffer->clear();
2657
2760
  return 0;
2660
2763
 
2661
2764
/*
2662
2765
  Execute command
2663
 
Returns: 0  if ok
2664
 
-1 if not fatal error
2665
 
1  if fatal error
 
2766
  Returns: 0  if ok
 
2767
  -1 if not fatal error
 
2768
  1  if fatal error
2666
2769
*/
2667
2770
static int
2668
2771
com_go(string *buffer, const char *)
2684
2787
  if (buffer->empty())
2685
2788
  {
2686
2789
    // Ignore empty quries
2687
 
    if (status.batch)
 
2790
    if (status.getBatch())
2688
2791
      return 0;
2689
2792
    return put_info(_("No query specified\n"),INFO_ERROR,0,0);
2690
2793
 
2709
2812
  executing_query= 1;
2710
2813
  error= drizzleclient_real_query_for_lazy(buffer->c_str(),buffer->length(),&result, &error_code);
2711
2814
 
2712
 
  if (status.add_to_history)
 
2815
  if (status.getAddToHistory())
2713
2816
  {
2714
2817
    buffer->append(vertical ? "\\G" : delimiter);
2715
2818
    /* Append final command onto history */
2763
2866
          print_tab_data(&result);
2764
2867
        else
2765
2868
          print_table_data(&result);
2766
 
        snprintf(buff, sizeof(buff), 
2767
 
                 ngettext("%ld row in set","%ld rows in set",
2768
 
                          (long) drizzle_result_row_count(&result)),
2769
 
                 (long) drizzle_result_row_count(&result));
 
2869
        sprintf(buff,
 
2870
                ngettext("%ld row in set","%ld rows in set",
 
2871
                         (long) drizzle_result_row_count(&result)),
 
2872
                (long) drizzle_result_row_count(&result));
2770
2873
        end_pager();
2771
2874
        if (drizzle_result_error_code(&result))
2772
2875
          error= put_error(&con, &result);
2775
2878
    else if (drizzle_result_affected_rows(&result) == ~(uint64_t) 0)
2776
2879
      strcpy(buff,_("Query OK"));
2777
2880
    else
2778
 
      snprintf(buff, sizeof(buff), ngettext("Query OK, %ld row affected",
2779
 
                                            "Query OK, %ld rows affected",
2780
 
                                            (long) drizzle_result_affected_rows(&result)),
2781
 
               (long) drizzle_result_affected_rows(&result));
 
2881
      sprintf(buff, ngettext("Query OK, %ld row affected",
 
2882
                             "Query OK, %ld rows affected",
 
2883
                             (long) drizzle_result_affected_rows(&result)),
 
2884
              (long) drizzle_result_affected_rows(&result));
2782
2885
 
2783
2886
    pos= strchr(buff, '\0');
2784
2887
    if ((warnings= drizzle_result_warning_count(&result)))
2787
2890
      *pos++= ' ';
2788
2891
      char warnings_buff[20];
2789
2892
      memset(warnings_buff,0,20);
2790
 
      snprintf(warnings_buff, sizeof(warnings_buff), "%d", warnings);
 
2893
      sprintf(warnings_buff, "%d", warnings);
2791
2894
      strcpy(pos, warnings_buff);
2792
2895
      pos+= strlen(warnings_buff);
2793
2896
      pos= strcpy(pos, " warning")+8;
2830
2933
  if (show_warnings == 1 && (warnings >= 1 || error))
2831
2934
    print_warnings(error_code);
2832
2935
 
2833
 
  if (!error && !status.batch &&
 
2936
  if (!error && !status.getBatch() &&
2834
2937
      drizzle_con_status(&con) & DRIZZLE_CON_STATUS_DB_DROPPED)
2835
2938
  {
2836
2939
    get_current_db();
2845
2948
{
2846
2949
  if (!opt_nopager)
2847
2950
  {
2848
 
    if (!(PAGER= popen(pager, "w")))
 
2951
    if (!(PAGER= popen(pager.c_str(), "w")))
2849
2952
    {
2850
 
      tee_fprintf(stdout, "popen() failed! defaulting PAGER to stdout!\n");
 
2953
      tee_fprintf(stdout,_( "popen() failed! defaulting PAGER to stdout!\n"));
2851
2954
      PAGER= stdout;
2852
2955
    }
2853
2956
  }
2869
2972
    end_tee();
2870
2973
  if (!(new_outfile= fopen(file_name, "a")))
2871
2974
  {
2872
 
    tee_fprintf(stdout, "Error logging to file '%s'\n", file_name);
 
2975
    tee_fprintf(stdout, _("Error logging to file '%s'\n"), file_name);
2873
2976
    return;
2874
2977
  }
2875
2978
  OUTFILE = new_outfile;
2876
 
  strncpy(outfile, file_name, FN_REFLEN-1);
2877
 
  tee_fprintf(stdout, "Logging to file '%s'\n", file_name);
 
2979
  outfile.assign(file_name);
 
2980
  tee_fprintf(stdout, _("Logging to file '%s'\n"), file_name);
2878
2981
  opt_outfile= 1;
2879
2982
 
2880
2983
  return;
2905
3008
static const char *fieldtype2str(drizzle_column_type_t type)
2906
3009
{
2907
3010
  switch (type) {
2908
 
  case DRIZZLE_COLUMN_TYPE_BLOB:        return "BLOB";
2909
 
  case DRIZZLE_COLUMN_TYPE_DATE:        return "DATE";
2910
 
  case DRIZZLE_COLUMN_TYPE_DATETIME:    return "DATETIME";
2911
 
  case DRIZZLE_COLUMN_TYPE_NEWDECIMAL:  return "DECIMAL";
2912
 
  case DRIZZLE_COLUMN_TYPE_DOUBLE:      return "DOUBLE";
2913
 
  case DRIZZLE_COLUMN_TYPE_ENUM:        return "ENUM";
2914
 
  case DRIZZLE_COLUMN_TYPE_LONG:        return "LONG";
2915
 
  case DRIZZLE_COLUMN_TYPE_LONGLONG:    return "LONGLONG";
2916
 
  case DRIZZLE_COLUMN_TYPE_NULL:        return "NULL";
2917
 
  case DRIZZLE_COLUMN_TYPE_TIMESTAMP:   return "TIMESTAMP";
2918
 
  default:                     return "?-unknown-?";
 
3011
    case DRIZZLE_COLUMN_TYPE_BLOB:        return "BLOB";
 
3012
    case DRIZZLE_COLUMN_TYPE_DATE:        return "DATE";
 
3013
    case DRIZZLE_COLUMN_TYPE_DATETIME:    return "DATETIME";
 
3014
    case DRIZZLE_COLUMN_TYPE_NEWDECIMAL:  return "DECIMAL";
 
3015
    case DRIZZLE_COLUMN_TYPE_DOUBLE:      return "DOUBLE";
 
3016
    case DRIZZLE_COLUMN_TYPE_ENUM:        return "ENUM";
 
3017
    case DRIZZLE_COLUMN_TYPE_LONG:        return "LONG";
 
3018
    case DRIZZLE_COLUMN_TYPE_LONGLONG:    return "LONGLONG";
 
3019
    case DRIZZLE_COLUMN_TYPE_NULL:        return "NULL";
 
3020
    case DRIZZLE_COLUMN_TYPE_TIMESTAMP:   return "TIMESTAMP";
 
3021
    default:                     return "?-unknown-?";
2919
3022
  }
2920
3023
}
2921
3024
 
2925
3028
  *s=0;
2926
3029
#define ff2s_check_flag(X)                                              \
2927
3030
  if (f & DRIZZLE_COLUMN_FLAGS_ ## X) { s=strcpy(s, # X " ")+strlen(# X " "); \
2928
 
    f &= ~ DRIZZLE_COLUMN_FLAGS_ ## X; }
 
3031
                        f &= ~ DRIZZLE_COLUMN_FLAGS_ ## X; }
2929
3032
  ff2s_check_flag(NOT_NULL);
2930
3033
  ff2s_check_flag(PRI_KEY);
2931
3034
  ff2s_check_flag(UNIQUE_KEY);
2946
3049
  ff2s_check_flag(ON_UPDATE_NOW);
2947
3050
#undef ff2s_check_flag
2948
3051
  if (f)
2949
 
    snprintf(s, sizeof(buf), " unknows=0x%04x", f);
 
3052
    sprintf(s, " unknows=0x%04x", f);
2950
3053
  return buf;
2951
3054
}
2952
3055
 
2958
3061
 
2959
3062
  while ((field = drizzle_column_next(result)))
2960
3063
  {
2961
 
    tee_fprintf(PAGER, "Field %3u:  `%s`\n"
 
3064
    tee_fprintf(PAGER, _("Field %3u:  `%s`\n"
2962
3065
                "Catalog:    `%s`\n"
2963
3066
                "Database:   `%s`\n"
2964
3067
                "Table:      `%s`\n"
2965
3068
                "Org_table:  `%s`\n"
2966
 
                "Type:       %s\n"
 
3069
                "Type:       UTF-8\n"
2967
3070
                "Collation:  %s (%u)\n"
2968
3071
                "Length:     %lu\n"
2969
3072
                "Max_length: %lu\n"
2970
3073
                "Decimals:   %u\n"
2971
 
                "Flags:      %s\n\n",
 
3074
                "Flags:      %s\n\n"),
2972
3075
                ++i,
2973
3076
                drizzle_column_name(field), drizzle_column_catalog(field),
2974
3077
                drizzle_column_db(field), drizzle_column_table(field),
2975
3078
                drizzle_column_orig_table(field),
2976
3079
                fieldtype2str(drizzle_column_type(field)),
2977
 
                get_charset_name(drizzle_column_charset(field)),
2978
3080
                drizzle_column_charset(field), drizzle_column_size(field),
2979
3081
                drizzle_column_max_size(field), drizzle_column_decimals(field),
2980
3082
                fieldflags2str(drizzle_column_flags(field)));
2982
3084
  tee_puts("", PAGER);
2983
3085
}
2984
3086
 
2985
 
 
2986
3087
static void
2987
3088
print_table_data(drizzle_result_st *result)
2988
3089
{
2989
3090
  drizzle_row_t cur;
2990
3091
  drizzle_return_t ret;
2991
3092
  drizzle_column_st *field;
2992
 
  bool *num_flag;
 
3093
  std::vector<bool> num_flag;
2993
3094
  string separator;
2994
3095
 
2995
3096
  separator.reserve(256);
2996
3097
 
2997
 
  num_flag=(bool*) malloc(sizeof(bool)*drizzle_result_column_count(result));
 
3098
  num_flag.resize(drizzle_result_column_count(result));
2998
3099
  if (column_types_flag)
2999
3100
  {
3000
3101
    print_field_types(result);
3012
3113
      uint32_t name_length= strlen(drizzle_column_name(field));
3013
3114
 
3014
3115
      /* Check if the max_byte value is really the maximum in terms
3015
 
        of visual length since multibyte characters can affect the
3016
 
        length of the separator. */
3017
 
      length= charset_info->cset->numcells(charset_info,
3018
 
                                           drizzle_column_name(field),
3019
 
                                           drizzle_column_name(field) +
3020
 
                                           name_length);
 
3116
         of visual length since multibyte characters can affect the
 
3117
         length of the separator. */
 
3118
      length= drizzled::utf8::char_length(drizzle_column_name(field));
3021
3119
 
3022
3120
      if (name_length == drizzle_column_max_size(field))
3023
3121
      {
3029
3127
        length= name_length;
3030
3128
      }
3031
3129
    }
3032
 
 
 
3130
  
3033
3131
    if (quick)
3034
3132
      length=max(length,drizzle_column_size(field));
3035
3133
    else
3055
3153
    for (uint32_t off=0; (field = drizzle_column_next(result)) ; off++)
3056
3154
    {
3057
3155
      uint32_t name_length= (uint32_t) strlen(drizzle_column_name(field));
3058
 
      uint32_t numcells= charset_info->cset->numcells(charset_info,
3059
 
                                                      drizzle_column_name(field),
3060
 
                                                      drizzle_column_name(field) +
3061
 
                                                      name_length);
 
3156
      uint32_t numcells= drizzled::utf8::char_length(drizzle_column_name(field));
3062
3157
      uint32_t display_length= drizzle_column_max_size(field) + name_length -
3063
 
        numcells;
 
3158
                               numcells;
3064
3159
      tee_fprintf(PAGER, " %-*s |",(int) min(display_length,
3065
3160
                                             MAX_COLUMN_LENGTH),
3066
3161
                  drizzle_column_name(field));
3121
3216
        We need to find how much screen real-estate we will occupy to know how
3122
3217
        many extra padding-characters we should send with the printing function.
3123
3218
      */
3124
 
      visible_length= charset_info->cset->numcells(charset_info, buffer, buffer + data_length);
 
3219
      visible_length= drizzled::utf8::char_length(buffer);
3125
3220
      extra_padding= data_length - visible_length;
3126
3221
 
3127
3222
      if (field_max_length > MAX_COLUMN_LENGTH)
3141
3236
      drizzle_row_free(result, cur);
3142
3237
  }
3143
3238
  tee_puts(separator.c_str(), PAGER);
3144
 
  free(num_flag);
3145
3239
}
3146
3240
 
3147
3241
/**
3148
 
  Return the length of a field after it would be rendered into text.
3149
 
 
3150
 
  This doesn't know or care about multibyte characters.  Assume we're
3151
 
  using such a charset.  We can't know that all of the upcoming rows
3152
 
  for this column will have bytes that each render into some fraction
3153
 
  of a character.  It's at least possible that a row has bytes that
3154
 
  all render into one character each, and so the maximum length is
3155
 
  still the number of bytes.  (Assumption 1:  This can't be better
3156
 
  because we can never know the number of characters that the DB is
3157
 
  going to send -- only the number of bytes.  2: Chars <= Bytes.)
3158
 
 
3159
 
  @param  field  Pointer to a field to be inspected
3160
 
 
3161
 
  @returns  number of character positions to be used, at most
 
3242
   Return the length of a field after it would be rendered into text.
 
3243
 
 
3244
   This doesn't know or care about multibyte characters.  Assume we're
 
3245
   using such a charset.  We can't know that all of the upcoming rows
 
3246
   for this column will have bytes that each render into some fraction
 
3247
   of a character.  It's at least possible that a row has bytes that
 
3248
   all render into one character each, and so the maximum length is
 
3249
   still the number of bytes.  (Assumption 1:  This can't be better
 
3250
   because we can never know the number of characters that the DB is
 
3251
   going to send -- only the number of bytes.  2: Chars <= Bytes.)
 
3252
 
 
3253
   @param  field  Pointer to a field to be inspected
 
3254
 
 
3255
   @returns  number of character positions to be used, at most
3162
3256
*/
3163
3257
static int get_field_disp_length(drizzle_column_st *field)
3164
3258
{
3170
3264
    length= max(length, (uint32_t)drizzle_column_max_size(field));
3171
3265
 
3172
3266
  if (length < 4 &&
3173
 
      !(drizzle_column_flags(field) & DRIZZLE_COLUMN_FLAGS_NOT_NULL))
 
3267
    !(drizzle_column_flags(field) & DRIZZLE_COLUMN_FLAGS_NOT_NULL))
3174
3268
  {
3175
3269
    length= 4;        /* Room for "NULL" */
3176
3270
  }
3179
3273
}
3180
3274
 
3181
3275
/**
3182
 
  For a new result, return the max number of characters that any
3183
 
  upcoming row may return.
3184
 
 
3185
 
  @param  result  Pointer to the result to judge
3186
 
 
3187
 
  @returns  The max number of characters in any row of this result
 
3276
   For a new result, return the max number of characters that any
 
3277
   upcoming row may return.
 
3278
 
 
3279
   @param  result  Pointer to the result to judge
 
3280
 
 
3281
   @returns  The max number of characters in any row of this result
3188
3282
*/
3189
3283
static int get_result_width(drizzle_result_st *result)
3190
3284
{
3289
3383
  drizzle_row_t cur;
3290
3384
  uint64_t num_rows;
3291
3385
  uint32_t new_code= 0;
 
3386
  FILE *out;
3292
3387
 
3293
3388
  /* Get the warnings */
3294
3389
  query= "show warnings";
3308
3403
    warning.
3309
3404
  */
3310
3405
  if (!cur || (num_rows == 1 &&
3311
 
               error_code == (uint32_t) strtoul(cur[1], NULL, 10)))
 
3406
      error_code == (uint32_t) strtoul(cur[1], NULL, 10)))
3312
3407
  {
3313
3408
    goto end;
3314
3409
  }
3315
3410
 
3316
3411
  /* Print the warnings */
3317
 
  init_pager();
 
3412
  if (status.getBatch()) 
 
3413
  {
 
3414
    out= stderr;
 
3415
  } 
 
3416
  else 
 
3417
  {
 
3418
    init_pager();
 
3419
    out= PAGER;
 
3420
  }
3318
3421
  do
3319
3422
  {
3320
 
    tee_fprintf(PAGER, "%s (Code %s): %s\n", cur[0], cur[1], cur[2]);
 
3423
    tee_fprintf(out, "%s (Code %s): %s\n", cur[0], cur[1], cur[2]);
3321
3424
  } while ((cur= drizzle_row_next(&result)));
3322
 
  end_pager();
 
3425
 
 
3426
  if (not status.getBatch())
 
3427
    end_pager();
3323
3428
 
3324
3429
end:
3325
3430
  drizzle_result_free(&result);
3338
3443
    else for (const char *end=pos+length ; pos != end ; pos++)
3339
3444
    {
3340
3445
      int l;
3341
 
      if (use_mb(charset_info) &&
3342
 
          (l = my_ismbchar(charset_info, pos, end)))
 
3446
      if ((l = drizzled::utf8::sequence_length(*pos)))
3343
3447
      {
3344
3448
        while (l--)
3345
3449
          tee_putc(*pos++, PAGER);
3416
3520
  char file_name[FN_REFLEN], *end;
3417
3521
  const char *param;
3418
3522
 
3419
 
  if (status.batch)
 
3523
  if (status.getBatch())
3420
3524
    return 0;
3421
 
  while (my_isspace(charset_info,*line))
 
3525
  while (isspace(*line))
3422
3526
    line++;
3423
 
  if (!(param = strchr(line, ' '))) // if outfile wasn't given, use the default
 
3527
  if (!(param =strchr(line, ' '))) // if outfile wasn't given, use the default
3424
3528
  {
3425
 
    if (!strlen(outfile))
 
3529
    if (outfile.empty())
3426
3530
    {
3427
 
      printf("No previous outfile available, you must give a filename!\n");
 
3531
      printf(_("No previous outfile available, you must give a filename!\n"));
3428
3532
      return 0;
3429
3533
    }
3430
3534
    else if (opt_outfile)
3431
3535
    {
3432
 
      tee_fprintf(stdout, "Currently logging to file '%s'\n", outfile);
 
3536
      tee_fprintf(stdout, _("Currently logging to file '%s'\n"), outfile.c_str());
3433
3537
      return 0;
3434
3538
    }
3435
3539
    else
3436
 
      param = outfile;      //resume using the old outfile
 
3540
      param= outfile.c_str();      //resume using the old outfile
3437
3541
  }
3438
3542
 
 
3543
  /* @TODO: Replace this with string methods */
3439
3544
  /* eliminate the spaces before the parameters */
3440
 
  while (my_isspace(charset_info,*param))
 
3545
  while (isspace(*param))
3441
3546
    param++;
3442
3547
  strncpy(file_name, param, sizeof(file_name) - 1);
3443
3548
  end= file_name + strlen(file_name);
3444
3549
  /* remove end space from command line */
3445
 
  while (end > file_name && (my_isspace(charset_info,end[-1]) ||
3446
 
                             my_iscntrl(charset_info,end[-1])))
 
3550
  while (end > file_name && (isspace(end[-1]) ||
 
3551
                             iscntrl(end[-1])))
3447
3552
    end--;
3448
3553
  end[0]= 0;
3449
3554
  if (end == file_name)
3450
3555
  {
3451
 
    printf("No outfile specified!\n");
 
3556
    printf(_("No outfile specified!\n"));
3452
3557
    return 0;
3453
3558
  }
3454
3559
  init_tee(file_name);
3461
3566
{
3462
3567
  if (opt_outfile)
3463
3568
    end_tee();
3464
 
  tee_fprintf(stdout, "Outfile disabled.\n");
 
3569
  tee_fprintf(stdout, _("Outfile disabled.\n"));
3465
3570
  return 0;
3466
3571
}
3467
3572
 
3472
3577
static int
3473
3578
com_pager(string *, const char *line)
3474
3579
{
3475
 
  char pager_name[FN_REFLEN], *end;
3476
3580
  const char *param;
3477
3581
 
3478
 
  if (status.batch)
 
3582
  if (status.getBatch())
3479
3583
    return 0;
3480
3584
  /* Skip spaces in front of the pager command */
3481
 
  while (my_isspace(charset_info, *line))
 
3585
  while (isspace(*line))
3482
3586
    line++;
3483
3587
  /* Skip the pager command */
3484
3588
  param= strchr(line, ' ');
3485
3589
  /* Skip the spaces between the command and the argument */
3486
 
  while (param && my_isspace(charset_info, *param))
 
3590
  while (param && isspace(*param))
3487
3591
    param++;
3488
 
  if (!param || !strlen(param)) // if pager was not given, use the default
 
3592
  if (!param || (*param == '\0')) // if pager was not given, use the default
3489
3593
  {
3490
3594
    if (!default_pager_set)
3491
3595
    {
3492
 
      tee_fprintf(stdout, "Default pager wasn't set, using stdout.\n");
 
3596
      tee_fprintf(stdout, _("Default pager wasn't set, using stdout.\n"));
3493
3597
      opt_nopager=1;
3494
 
      strcpy(pager, "stdout");
 
3598
      pager.assign("stdout");
3495
3599
      PAGER= stdout;
3496
3600
      return 0;
3497
3601
    }
3498
 
    strcpy(pager, default_pager);
 
3602
    pager.assign(default_pager);
3499
3603
  }
3500
3604
  else
3501
3605
  {
3502
 
    end= strncpy(pager_name, param, sizeof(pager_name)-1);
3503
 
    end+= strlen(pager_name);
3504
 
    while (end > pager_name && (my_isspace(charset_info,end[-1]) ||
3505
 
                                my_iscntrl(charset_info,end[-1])))
3506
 
      end--;
3507
 
    end[0]=0;
3508
 
    strcpy(pager, pager_name);
3509
 
    strcpy(default_pager, pager_name);
 
3606
    string pager_name(param);
 
3607
    string::iterator end= pager_name.end();
 
3608
    while (end > pager_name.begin() &&
 
3609
           (isspace(*(end-1)) || iscntrl(*(end-1))))
 
3610
      --end;
 
3611
    pager_name.erase(end, pager_name.end());
 
3612
    pager.assign(pager_name);
 
3613
    default_pager.assign(pager_name);
3510
3614
  }
3511
3615
  opt_nopager=0;
3512
 
  tee_fprintf(stdout, "PAGER set to '%s'\n", pager);
 
3616
  tee_fprintf(stdout, _("PAGER set to '%s'\n"), pager.c_str());
3513
3617
  return 0;
3514
3618
}
3515
3619
 
3517
3621
static int
3518
3622
com_nopager(string *, const char *)
3519
3623
{
3520
 
  strcpy(pager, "stdout");
 
3624
  pager.assign("stdout");
3521
3625
  opt_nopager=1;
3522
3626
  PAGER= stdout;
3523
 
  tee_fprintf(stdout, "PAGER set to stdout\n");
 
3627
  tee_fprintf(stdout, _("PAGER set to stdout\n"));
3524
3628
  return 0;
3525
3629
}
3526
3630
 
3530
3634
com_quit(string *, const char *)
3531
3635
{
3532
3636
  /* let the screen auto close on a normal shutdown */
3533
 
  status.exit_status=0;
 
3637
  status.setExitStatus(0);
3534
3638
  return 1;
3535
3639
}
3536
3640
 
3578
3682
    tmp= get_arg(buff, 0);
3579
3683
    if (tmp && *tmp)
3580
3684
    {
3581
 
      free(current_db);
3582
 
      current_db= strdup(tmp);
 
3685
      current_db.erase();
 
3686
      current_db.assign(tmp);
3583
3687
      tmp= get_arg(buff, 1);
3584
3688
      if (tmp)
3585
3689
      {
3586
 
        free(current_host);
 
3690
        current_host.erase();
3587
3691
        current_host=strdup(tmp);
3588
3692
      }
3589
3693
    }
3598
3702
  }
3599
3703
  else
3600
3704
    opt_rehash= 0;
3601
 
  error=sql_connect(current_host,current_db,current_user,opt_password,0);
 
3705
  error=sql_connect(current_host, current_db, current_user, opt_password,0);
3602
3706
  opt_rehash= save_rehash;
3603
3707
 
3604
3708
  if (connected)
3605
3709
  {
3606
 
    snprintf(buff, sizeof(buff), "Connection id:    %u",drizzle_con_thread_id(&con));
 
3710
    sprintf(buff, _("Connection id:    %u"), drizzle_con_thread_id(&con));
3607
3711
    put_info(buff,INFO_INFO,0,0);
3608
 
    snprintf(buff, sizeof(buff), "Current database: %.128s\n",
3609
 
             current_db ? current_db : "*** NONE ***");
 
3712
    sprintf(buff, _("Current database: %.128s\n"),
 
3713
            !current_db.empty() ? current_db.c_str() : _("*** NONE ***"));
3610
3714
    put_info(buff,INFO_INFO,0,0);
3611
3715
  }
3612
3716
  return error;
3619
3723
  const char *param;
3620
3724
  LineBuffer *line_buff;
3621
3725
  int error;
3622
 
  STATUS old_status;
 
3726
  Status old_status;
3623
3727
  FILE *sql_file;
3624
3728
 
3625
3729
  /* Skip space from file name */
3626
 
  while (my_isspace(charset_info,*line))
 
3730
  while (isspace(*line))
3627
3731
    line++;
3628
3732
  if (!(param = strchr(line, ' ')))    // Skip command name
3629
 
    return put_info("Usage: \\. <filename> | source <filename>",
 
3733
    return put_info(_("Usage: \\. <filename> | source <filename>"),
3630
3734
                    INFO_ERROR, 0,0);
3631
 
  while (my_isspace(charset_info,*param))
 
3735
  while (isspace(*param))
3632
3736
    param++;
3633
3737
  end= strncpy(source_name,param,sizeof(source_name)-1);
3634
3738
  end+= strlen(source_name);
3635
 
  while (end > source_name && (my_isspace(charset_info,end[-1]) ||
3636
 
                               my_iscntrl(charset_info,end[-1])))
 
3739
  while (end > source_name && (isspace(end[-1]) ||
 
3740
                               iscntrl(end[-1])))
3637
3741
    end--;
3638
3742
  end[0]=0;
3639
 
  internal::unpack_filename(source_name,source_name);
 
3743
 
3640
3744
  /* open file name */
3641
3745
  if (!(sql_file = fopen(source_name, "r")))
3642
3746
  {
3643
3747
    char buff[FN_REFLEN+60];
3644
 
    snprintf(buff, sizeof(buff), "Failed to open file '%s', error: %d", source_name,errno);
 
3748
    sprintf(buff, _("Failed to open file '%s', error: %d"), source_name,errno);
3645
3749
    return put_info(buff, INFO_ERROR, 0 ,0);
3646
3750
  }
3647
3751
 
3649
3753
  if (line_buff == NULL)
3650
3754
  {
3651
3755
    fclose(sql_file);
3652
 
    return put_info("Can't initialize LineBuffer", INFO_ERROR, 0, 0);
 
3756
    return put_info(_("Can't initialize LineBuffer"), INFO_ERROR, 0, 0);
3653
3757
  }
3654
3758
 
3655
3759
  /* Save old status */
3657
3761
  memset(&status, 0, sizeof(status));
3658
3762
 
3659
3763
  // Run in batch mode
3660
 
  status.batch=old_status.batch;
3661
 
  status.line_buff=line_buff;
3662
 
  status.file_name=source_name;
 
3764
  status.setBatch(old_status.getBatch());
 
3765
  status.setLineBuff(line_buff);
 
3766
  status.setFileName(source_name);
3663
3767
  // Empty command buffer
3664
3768
  assert(glob_buffer!=NULL);
3665
3769
  glob_buffer->clear();
3667
3771
  // Continue as before
3668
3772
  status=old_status;
3669
3773
  fclose(sql_file);
3670
 
  delete status.line_buff;
3671
 
  line_buff= status.line_buff= 0;
 
3774
  delete status.getLineBuff();
 
3775
  line_buff=0;
 
3776
  status.setLineBuff(0);
3672
3777
  return error;
3673
3778
}
3674
3779
 
3684
3789
 
3685
3790
  if (!tmp || !*tmp)
3686
3791
  {
3687
 
    put_info("DELIMITER must be followed by a 'delimiter' character or string",
 
3792
    put_info(_("DELIMITER must be followed by a 'delimiter' character or string"),
3688
3793
             INFO_ERROR, 0, 0);
3689
3794
    return 0;
3690
3795
  }
3692
3797
  {
3693
3798
    if (strstr(tmp, "\\"))
3694
3799
    {
3695
 
      put_info("DELIMITER cannot contain a backslash character",
 
3800
      put_info(_("DELIMITER cannot contain a backslash character"),
3696
3801
               INFO_ERROR, 0, 0);
3697
3802
      return 0;
3698
3803
    }
3717
3822
  tmp= get_arg(buff, 0);
3718
3823
  if (!tmp || !*tmp)
3719
3824
  {
3720
 
    put_info("USE must be followed by a database name", INFO_ERROR, 0, 0);
 
3825
    put_info(_("USE must be followed by a database name"), INFO_ERROR, 0, 0);
3721
3826
    return 0;
3722
3827
  }
3723
3828
  /*
3727
3832
  */
3728
3833
  get_current_db();
3729
3834
 
3730
 
  if (!current_db || strcmp(current_db,tmp))
 
3835
  if (current_db.empty() || strcmp(current_db.c_str(),tmp))
3731
3836
  {
3732
3837
    if (one_database)
3733
3838
    {
3779
3884
      else
3780
3885
        drizzle_result_free(&result);
3781
3886
    }
3782
 
    free(current_db);
3783
 
    current_db= strdup(tmp);
 
3887
    current_db.erase();
 
3888
    current_db.assign(tmp);
3784
3889
    if (select_db > 1)
3785
3890
      build_completion_hash(opt_rehash, 1);
3786
3891
  }
3787
3892
 
3788
 
  put_info("Database changed",INFO_INFO, 0, 0);
 
3893
  put_info(_("Database changed"),INFO_INFO, 0, 0);
3789
3894
  return 0;
3790
3895
}
3791
3896
 
3793
3898
com_warnings(string *, const char *)
3794
3899
{
3795
3900
  show_warnings = 1;
3796
 
  put_info("Show warnings enabled.",INFO_INFO, 0, 0);
 
3901
  put_info(_("Show warnings enabled."),INFO_INFO, 0, 0);
3797
3902
  return 0;
3798
3903
}
3799
3904
 
3801
3906
com_nowarnings(string *, const char *)
3802
3907
{
3803
3908
  show_warnings = 0;
3804
 
  put_info("Show warnings disabled.",INFO_INFO, 0, 0);
 
3909
  put_info(_("Show warnings disabled."),INFO_INFO, 0, 0);
3805
3910
  return 0;
3806
3911
}
3807
3912
 
3831
3936
  else
3832
3937
  {
3833
3938
    /* skip leading white spaces */
3834
 
    while (my_isspace(charset_info, *ptr))
 
3939
    while (isspace(*ptr))
3835
3940
      ptr++;
3836
3941
    if (*ptr == '\\') // short command was used
3837
3942
      ptr+= 2;
3838
3943
    else
3839
 
      while (*ptr &&!my_isspace(charset_info, *ptr)) // skip command
 
3944
      while (*ptr &&!isspace(*ptr)) // skip command
3840
3945
        ptr++;
3841
3946
  }
3842
3947
  if (!*ptr)
3843
3948
    return NULL;
3844
 
  while (my_isspace(charset_info, *ptr))
 
3949
  while (isspace(*ptr))
3845
3950
    ptr++;
3846
3951
  if (*ptr == '\'' || *ptr == '\"' || *ptr == '`')
3847
3952
  {
3868
3973
 
3869
3974
 
3870
3975
static int
3871
 
sql_connect(char *host,char *database,char *user,char *password,
3872
 
            uint32_t silent)
 
3976
sql_connect(const string &host, const string &database, const string &user, const string &password,
 
3977
                 uint32_t silent)
3873
3978
{
3874
3979
  drizzle_return_t ret;
3875
 
 
3876
3980
  if (connected)
3877
3981
  {
3878
3982
    connected= 0;
3880
3984
    drizzle_free(&drizzle);
3881
3985
  }
3882
3986
  drizzle_create(&drizzle);
3883
 
  if (drizzle_con_add_tcp(&drizzle, &con, host, opt_drizzle_port, user,
3884
 
                          password, database, opt_mysql ? DRIZZLE_CON_MYSQL : DRIZZLE_CON_NONE) == NULL)
 
3987
  if (drizzle_con_add_tcp(&drizzle, &con, (char *)host.c_str(),
 
3988
    opt_drizzle_port, (char *)user.c_str(),
 
3989
    (char *)password.c_str(), (char *)database.c_str(),
 
3990
    use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL) == NULL)
3885
3991
  {
3886
3992
    (void) put_error(&con, NULL);
3887
3993
    (void) fflush(stdout);
3888
3994
    return 1;
3889
3995
  }
3890
3996
 
3891
 
  /* XXX add this back in
3892
 
    if (opt_connect_timeout)
3893
 
    {
 
3997
/* XXX add this back in
 
3998
  if (opt_connect_timeout)
 
3999
  {
3894
4000
    uint32_t timeout=opt_connect_timeout;
3895
4001
    drizzleclient_options(&drizzle,DRIZZLE_OPT_CONNECT_TIMEOUT,
3896
 
    (char*) &timeout);
3897
 
    }
3898
 
  */
 
4002
                  (char*) &timeout);
 
4003
  }
 
4004
*/
3899
4005
 
3900
 
  /* XXX Do we need this?
3901
 
    if (safe_updates)
3902
 
    {
 
4006
/* XXX Do we need this?
 
4007
  if (safe_updates)
 
4008
  {
3903
4009
    char init_command[100];
3904
4010
    sprintf(init_command,
3905
 
    "SET SQL_SAFE_UPDATES=1,SQL_SELECT_LIMIT=%"PRIu32
3906
 
    ",MAX_JOIN_SIZE=%"PRIu32,
3907
 
    select_limit, max_join_size);
 
4011
            "SET SQL_SAFE_UPDATES=1,SQL_SELECT_LIMIT=%"PRIu32
 
4012
            ",MAX_JOIN_SIZE=%"PRIu32,
 
4013
            select_limit, max_join_size);
3908
4014
    drizzleclient_options(&drizzle, DRIZZLE_INIT_COMMAND, init_command);
3909
 
    }
3910
 
  */
 
4015
  }
 
4016
*/
3911
4017
  if ((ret= drizzle_con_connect(&con)) != DRIZZLE_RETURN_OK)
3912
4018
  {
3913
4019
    if (!silent || (ret != DRIZZLE_RETURN_GETADDRINFO &&
3929
4035
static int
3930
4036
com_status(string *, const char *)
3931
4037
{
3932
 
  /*
3933
 
    char buff[40];
3934
 
    uint64_t id;
3935
 
  */
 
4038
/*
 
4039
  char buff[40];
 
4040
  uint64_t id;
 
4041
*/
3936
4042
  drizzle_result_st result;
3937
4043
  drizzle_return_t ret;
3938
4044
 
3939
4045
  tee_puts("--------------", stdout);
3940
 
  usage(1);          /* Print version */
 
4046
  printf(_("Drizzle client %s build %s, for %s-%s (%s) using readline %s\n"),
 
4047
         drizzle_version(), VERSION,
 
4048
         HOST_VENDOR, HOST_OS, HOST_CPU,
 
4049
         rl_library_version);
 
4050
 
3941
4051
  if (connected)
3942
4052
  {
3943
 
    tee_fprintf(stdout, "\nConnection id:\t\t%lu\n",drizzle_con_thread_id(&con));
 
4053
    tee_fprintf(stdout, _("\nConnection id:\t\t%lu\n"),drizzle_con_thread_id(&con));
3944
4054
    /*
3945
4055
      Don't remove "limit 1",
3946
4056
      it is protection againts SQL_SELECT_LIMIT=0
3952
4062
      drizzle_row_t cur=drizzle_row_next(&result);
3953
4063
      if (cur)
3954
4064
      {
3955
 
        tee_fprintf(stdout, "Current database:\t%s\n", cur[0] ? cur[0] : "");
3956
 
        tee_fprintf(stdout, "Current user:\t\t%s\n", cur[1]);
 
4065
        tee_fprintf(stdout, _("Current database:\t%s\n"), cur[0] ? cur[0] : "");
 
4066
        tee_fprintf(stdout, _("Current user:\t\t%s\n"), cur[1]);
3957
4067
      }
3958
4068
      drizzle_result_free(&result);
3959
4069
    }
3960
4070
    else if (ret == DRIZZLE_RETURN_ERROR_CODE)
3961
4071
      drizzle_result_free(&result);
3962
 
    tee_puts("SSL:\t\t\tNot in use", stdout);
 
4072
    tee_puts(_("SSL:\t\t\tNot in use"), stdout);
3963
4073
  }
3964
4074
  else
3965
4075
  {
3966
4076
    vidattr(A_BOLD);
3967
 
    tee_fprintf(stdout, "\nNo connection\n");
 
4077
    tee_fprintf(stdout, _("\nNo connection\n"));
3968
4078
    vidattr(A_NORMAL);
3969
4079
    return 0;
3970
4080
  }
3971
4081
  if (skip_updates)
3972
4082
  {
3973
4083
    vidattr(A_BOLD);
3974
 
    tee_fprintf(stdout, "\nAll updates ignored to this database\n");
 
4084
    tee_fprintf(stdout, _("\nAll updates ignored to this database\n"));
3975
4085
    vidattr(A_NORMAL);
3976
4086
  }
3977
 
  tee_fprintf(stdout, "Current pager:\t\t%s\n", pager);
3978
 
  tee_fprintf(stdout, "Using outfile:\t\t'%s'\n", opt_outfile ? outfile : "");
3979
 
  tee_fprintf(stdout, "Using delimiter:\t%s\n", delimiter);
3980
 
  tee_fprintf(stdout, "Server version:\t\t%s\n", server_version_string(&con));
3981
 
  tee_fprintf(stdout, "Protocol version:\t%d\n", drizzle_con_protocol_version(&con));
3982
 
  tee_fprintf(stdout, "Connection:\t\t%s\n", drizzle_con_host(&con));
3983
 
  /* XXX need to save this from result
3984
 
    if ((id= drizzleclient_insert_id(&drizzle)))
 
4087
  tee_fprintf(stdout, _("Current pager:\t\t%s\n"), pager.c_str());
 
4088
  tee_fprintf(stdout, _("Using outfile:\t\t'%s'\n"), opt_outfile ? outfile.c_str() : "");
 
4089
  tee_fprintf(stdout, _("Using delimiter:\t%s\n"), delimiter);
 
4090
  tee_fprintf(stdout, _("Server version:\t\t%s\n"), server_version_string(&con));
 
4091
  tee_fprintf(stdout, _("Protocol:\t\t%s\n"), opt_protocol.c_str());
 
4092
  tee_fprintf(stdout, _("Protocol version:\t%d\n"), drizzle_con_protocol_version(&con));
 
4093
  tee_fprintf(stdout, _("Connection:\t\t%s\n"), drizzle_con_host(&con));
 
4094
/* XXX need to save this from result
 
4095
  if ((id= drizzleclient_insert_id(&drizzle)))
3985
4096
    tee_fprintf(stdout, "Insert id:\t\t%s\n", internal::llstr(id, buff));
3986
 
  */
 
4097
*/
3987
4098
 
3988
4099
  if (drizzle_con_uds(&con))
3989
 
    tee_fprintf(stdout, "UNIX socket:\t\t%s\n", drizzle_con_uds(&con));
 
4100
    tee_fprintf(stdout, _("UNIX socket:\t\t%s\n"), drizzle_con_uds(&con));
3990
4101
  else
3991
 
    tee_fprintf(stdout, "TCP port:\t\t%d\n", drizzle_con_port(&con));
 
4102
    tee_fprintf(stdout, _("TCP port:\t\t%d\n"), drizzle_con_port(&con));
3992
4103
 
3993
4104
  if (safe_updates)
3994
4105
  {
3995
4106
    vidattr(A_BOLD);
3996
 
    tee_fprintf(stdout, "\nNote that you are running in safe_update_mode:\n");
 
4107
    tee_fprintf(stdout, _("\nNote that you are running in safe_update_mode:\n"));
3997
4108
    vidattr(A_NORMAL);
3998
 
    tee_fprintf(stdout, "\
3999
 
                UPDATEs and DELETEs that don't use a key in the WHERE clause are not allowed.\n\
4000
 
                (One can force an UPDATE/DELETE by adding LIMIT # at the end of the command.)\n \
4001
 
                SELECT has an automatic 'LIMIT %lu' if LIMIT is not used.\n             \
4002
 
                Max number of examined row combination in a join is set to: %lu\n\n",
 
4109
    tee_fprintf(stdout, _("\
 
4110
UPDATEs and DELETEs that don't use a key in the WHERE clause are not allowed.\n\
 
4111
(One can force an UPDATE/DELETE by adding LIMIT # at the end of the command.)\n \
 
4112
SELECT has an automatic 'LIMIT %lu' if LIMIT is not used.\n             \
 
4113
Max number of examined row combination in a join is set to: %lu\n\n"),
4003
4114
                select_limit, max_join_size);
4004
4115
  }
4005
4116
  tee_puts("--------------\n", stdout);
4052
4163
  FILE *file= (info_type == INFO_ERROR ? stderr : stdout);
4053
4164
  static int inited=0;
4054
4165
 
4055
 
  if (status.batch)
 
4166
  if (status.getBatch())
4056
4167
  {
4057
4168
    if (info_type == INFO_ERROR)
4058
4169
    {
4059
4170
      (void) fflush(file);
4060
 
      fprintf(file,"ERROR");
 
4171
      fprintf(file,_("ERROR"));
4061
4172
      if (error)
4062
4173
      {
4063
4174
        if (sqlstate)
4065
4176
        else
4066
4177
          (void) fprintf(file," %d",error);
4067
4178
      }
4068
 
      if (status.query_start_line && line_numbers)
 
4179
      if (status.getQueryStartLine() && line_numbers)
4069
4180
      {
4070
 
        (void) fprintf(file," at line %"PRIu32,status.query_start_line);
4071
 
        if (status.file_name)
4072
 
          (void) fprintf(file," in file: '%s'", status.file_name);
 
4181
        (void) fprintf(file," at line %"PRIu32,status.getQueryStartLine());
 
4182
        if (status.getFileName())
 
4183
          (void) fprintf(file," in file: '%s'", status.getFileName());
4073
4184
      }
4074
4185
      (void) fprintf(file,": %s\n",str);
4075
4186
      (void) fflush(file);
4100
4211
      if (error)
4101
4212
      {
4102
4213
        if (sqlstate)
4103
 
          (void) tee_fprintf(file, "ERROR %d (%s): ", error, sqlstate);
 
4214
          (void) tee_fprintf(file, _("ERROR %d (%s): "), error, sqlstate);
4104
4215
        else
4105
 
          (void) tee_fprintf(file, "ERROR %d: ", error);
 
4216
          (void) tee_fprintf(file, _("ERROR %d: "), error);
4106
4217
      }
4107
4218
      else
4108
 
        tee_puts("ERROR: ", file);
 
4219
        tee_puts(_("ERROR: "), file);
4109
4220
    }
4110
4221
    else
4111
4222
      vidattr(A_BOLD);
4134
4245
 
4135
4246
  return put_info(error, INFO_ERROR,
4136
4247
                  res == NULL ? drizzle_con_error_code(local_con) :
4137
 
                  drizzle_result_error_code(res),
 
4248
                                drizzle_result_error_code(res),
4138
4249
                  res == NULL ? drizzle_con_sqlstate(local_con) :
4139
 
                  drizzle_result_sqlstate(res));
 
4250
                                drizzle_result_sqlstate(res));
4140
4251
}
4141
4252
 
4142
4253
 
4144
4255
{
4145
4256
  const char *start=  buffer->c_str();
4146
4257
  const char *end= start + (buffer->length());
4147
 
  while (start < end && !my_isgraph(charset_info,end[-1]))
 
4258
  while (start < end && !isgraph(end[-1]))
4148
4259
    end--;
4149
4260
  uint32_t pos_to_truncate= (end-start);
4150
4261
  if (buffer->length() > pos_to_truncate)
4209
4320
 
4210
4321
 
4211
4322
/**
4212
 
  Write as many as 52+1 bytes to buff, in the form of a legible
4213
 
  duration of time.
 
4323
   Write as many as 52+1 bytes to buff, in the form of a legible
 
4324
   duration of time.
4214
4325
 
4215
 
  len("4294967296 days, 23 hours, 59 minutes, 60.00 seconds")  ->  52
 
4326
   len("4294967296 days, 23 hours, 59 minutes, 60.00 seconds")  ->  52
4216
4327
*/
4217
4328
static void nice_time(double sec,char *buff,bool part_second)
4218
4329
{
4238
4349
    tmp_buff_str << tmp;
4239
4350
 
4240
4351
    if (tmp > 1)
4241
 
      tmp_buff_str << " hours ";
 
4352
      tmp_buff_str << _(" hours ");
4242
4353
    else
4243
 
      tmp_buff_str << " hour ";
 
4354
      tmp_buff_str << _(" hour ");
4244
4355
  }
4245
4356
  if (sec >= 60.0)
4246
4357
  {
4247
4358
    tmp=(uint32_t) floor(sec/60.0);
4248
4359
    sec-=60.0*tmp;
4249
 
    tmp_buff_str << tmp << " min ";
 
4360
    tmp_buff_str << tmp << _(" min ");
4250
4361
  }
4251
4362
  if (part_second)
4252
4363
    tmp_buff_str.precision(2);
4253
4364
  else
4254
4365
    tmp_buff_str.precision(0);
4255
 
  tmp_buff_str << sec << " sec";
 
4366
  tmp_buff_str << sec << _(" sec");
4256
4367
  strcpy(buff, tmp_buff_str.str().c_str());
4257
4368
}
4258
4369
 
4283
4394
  struct tm *t = localtime(&lclock);
4284
4395
 
4285
4396
  /* parse thru the settings for the prompt */
4286
 
  for (char *c= current_prompt; *c; (void)*c++)
 
4397
  string::iterator c= current_prompt.begin();
 
4398
  while (c != current_prompt.end())
4287
4399
  {
4288
4400
    if (*c != PROMPT_CHAR)
4289
4401
    {
4290
 
      processed_prompt->append(c, 1);
 
4402
      processed_prompt->push_back(*c);
4291
4403
    }
4292
4404
    else
4293
4405
    {
4298
4410
      switch (*++c) {
4299
4411
      case '\0':
4300
4412
        // stop it from going beyond if ends with %
4301
 
        c--;
 
4413
        --c;
4302
4414
        break;
4303
4415
      case 'c':
4304
4416
        add_int_to_prompt(++prompt_counter);
4310
4422
          processed_prompt->append("not_connected");
4311
4423
        break;
4312
4424
      case 'd':
4313
 
        processed_prompt->append(current_db ? current_db : "(none)");
 
4425
        processed_prompt->append(not current_db.empty() ? current_db : "(none)");
4314
4426
        break;
4315
4427
      case 'h':
4316
 
        {
4317
 
          const char *prompt;
4318
 
          prompt= connected ? drizzle_con_host(&con) : "not_connected";
4319
 
          if (strstr(prompt, "Localhost"))
4320
 
            processed_prompt->append("localhost");
4321
 
          else
4322
 
          {
4323
 
            const char *end=strrchr(prompt,' ');
4324
 
            if (end != NULL)
4325
 
              processed_prompt->append(prompt, (end-prompt));
4326
 
          }
 
4428
      {
 
4429
        const char *prompt= connected ? drizzle_con_host(&con) : "not_connected";
 
4430
        if (strstr(prompt, "Localhost"))
 
4431
          processed_prompt->append("localhost");
 
4432
        else
 
4433
        {
 
4434
          const char *end=strrchr(prompt,' ');
 
4435
          if (end != NULL)
 
4436
            processed_prompt->append(prompt, (end-prompt));
 
4437
        }
 
4438
        break;
 
4439
      }
 
4440
      case 'p':
 
4441
      {
 
4442
        if (!connected)
 
4443
        {
 
4444
          processed_prompt->append("not_connected");
4327
4445
          break;
4328
4446
        }
4329
 
      case 'p':
 
4447
 
 
4448
        if (drizzle_con_uds(&con))
4330
4449
        {
4331
 
          if (!connected)
4332
 
          {
4333
 
            processed_prompt->append("not_connected");
4334
 
            break;
4335
 
          }
4336
 
 
4337
 
          if (drizzle_con_uds(&con))
4338
 
          {
4339
 
            const char *pos=strrchr(drizzle_con_uds(&con),'/');
4340
 
            processed_prompt->append(pos ? pos+1 : drizzle_con_uds(&con));
4341
 
          }
4342
 
          else
4343
 
            add_int_to_prompt(drizzle_con_port(&con));
 
4450
          const char *pos=strrchr(drizzle_con_uds(&con),'/');
 
4451
          processed_prompt->append(pos ? pos+1 : drizzle_con_uds(&con));
4344
4452
        }
4345
 
        break;
 
4453
        else
 
4454
          add_int_to_prompt(drizzle_con_port(&con));
 
4455
      }
 
4456
      break;
4346
4457
      case 'U':
4347
4458
        if (!full_username)
4348
4459
          init_username();
4349
4460
        processed_prompt->append(full_username ? full_username :
4350
 
                                 (current_user ?  current_user : "(unknown)"));
 
4461
                                 (!current_user.empty() ?  current_user : "(unknown)"));
4351
4462
        break;
4352
4463
      case 'u':
4353
4464
        if (!full_username)
4354
4465
          init_username();
4355
4466
        processed_prompt->append(part_username ? part_username :
4356
 
                                 (current_user ?  current_user : "(unknown)"));
 
4467
                                 (!current_user.empty() ?  current_user : _("(unknown)")));
4357
4468
        break;
4358
4469
      case PROMPT_CHAR:
4359
4470
        {
4435
4546
        processed_prompt->append(delimiter_str);
4436
4547
        break;
4437
4548
      default:
4438
 
        processed_prompt->append(c, 1);
 
4549
        processed_prompt->push_back(*c);
4439
4550
      }
4440
4551
    }
 
4552
    ++c;
4441
4553
  }
4442
4554
  return processed_prompt->c_str();
4443
4555
}
4452
4564
 
4453
4565
static void init_username()
4454
4566
{
4455
 
  /* XXX need this?
4456
 
    free(full_username);
4457
 
    free(part_username);
 
4567
/* XXX need this?
 
4568
  free(full_username);
 
4569
  free(part_username);
4458
4570
 
4459
 
    drizzle_result_st *result;
4460
 
    if (!drizzleclient_query(&drizzle,"select USER()") &&
4461
 
    (result=drizzleclient_use_result(&drizzle)))
4462
 
    {
 
4571
  drizzle_result_st *result;
 
4572
  if (!drizzleclient_query(&drizzle,"select USER()") &&
 
4573
      (result=drizzleclient_use_result(&drizzle)))
 
4574
  {
4463
4575
    drizzle_row_t cur=drizzleclient_fetch_row(result);
4464
4576
    full_username= strdup(cur[0]);
4465
4577
    part_username= strdup(strtok(cur[0],"@"));
4466
4578
    (void) drizzleclient_fetch_row(result);        // Read eof
4467
 
    }
4468
 
  */
 
4579
  }
 
4580
*/
4469
4581
}
4470
4582
 
4471
4583
static int com_prompt(string *, const char *line)
4472
4584
{
4473
4585
  const char *ptr=strchr(line, ' ');
4474
4586
  if (ptr == NULL)
4475
 
    tee_fprintf(stdout, "Returning to default PROMPT of %s\n",
 
4587
    tee_fprintf(stdout, _("Returning to default PROMPT of %s\n"),
4476
4588
                default_prompt);
4477
4589
  prompt_counter = 0;
4478
4590
  char * tmpptr= strdup(ptr ? ptr+1 : default_prompt);
4479
4591
  if (tmpptr == NULL)
4480
 
    tee_fprintf(stdout, "Memory allocation error. Not changing prompt\n");
 
4592
    tee_fprintf(stdout, _("Memory allocation error. Not changing prompt\n"));
4481
4593
  else
4482
4594
  {
4483
 
    free(current_prompt);
 
4595
    current_prompt.erase();
4484
4596
    current_prompt= tmpptr;
4485
 
    tee_fprintf(stdout, "PROMPT set to '%s'\n", current_prompt);
 
4597
    tee_fprintf(stdout, _("PROMPT set to '%s'\n"), current_prompt.c_str());
4486
4598
  }
4487
4599
  return 0;
4488
4600
}
4489
4601
 
4490
4602
/*
4491
 
  strcont(str, set) if str contanies any character in the string set.
4492
 
  The result is the position of the first found character in str, or NULL
4493
 
  if there isn't anything found.
 
4603
    strcont(str, set) if str contanies any character in the string set.
 
4604
    The result is the position of the first found character in str, or NULL
 
4605
    if there isn't anything found.
4494
4606
*/
4495
4607
 
4496
4608
static const char * strcont(register const char *str, register const char *set)