~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzle.cc

  • Committer: Padraig O'Sullivan
  • Date: 2009-03-21 01:02:23 UTC
  • mto: (960.2.5 mordred)
  • mto: This revision was merged to the branch mainline in revision 961.
  • Revision ID: osullivan.padraig@gmail.com-20090321010223-j8cph7eeyt1u3xol
Fixed function object to ensure it correctly returns a boolean type since
memcmp returns an integer. Added some more comments.

Show diffs side-by-side

added added

removed removed

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