~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzle.cc

  • Committer: Brian Aker
  • Date: 2010-05-27 01:25:56 UTC
  • mfrom: (1567.1.4 new-staging)
  • Revision ID: brian@gaz-20100527012556-5zgkirkl7swbigd6
Merge of Brian, Paul. PBXT compile issue, and test framework cleanup. 

Show diffs side-by-side

added added

removed removed

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