~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzle.cc

  • Committer: Monty Taylor
  • Date: 2009-03-02 23:14:32 UTC
  • mto: This revision was merged to the branch mainline in revision 910.
  • Revision ID: mordred@inaugust.com-20090302231432-i35xehp7uzo6hjjw
Updated build system to use new version numbering. Just remember to run ./config/autorun.sh before running make distcheck for release and all should be peachy.

Show diffs side-by-side

added added

removed removed

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