~drizzle-trunk/drizzle/development

77.3.7 by Monty Taylor
Made mysql into a pure-C program.
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2008 MySQL
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; either version 2 of the License, or
9
 *  (at your option) any later version.
10
 *
11
 *  This program is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *  GNU General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU General Public License
17
 *  along with this program; if not, write to the Free Software
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 */
1 by brian
clean slate
20
206.3.1 by Patrick Galbraith
Most everything working with client rename
21
/* drizzle command tool
1 by brian
clean slate
22
 * Commands compatible with mSQL by David J. Hughes
23
 *
24
 * Written by:
25
 *   Michael 'Monty' Widenius
26
 *   Andi Gutmans  <andi@zend.com>
27
 *   Zeev Suraski  <zeev@zend.com>
202.1.25 by Monty Taylor
Fixed change of mysql.com -> drizzle.com.
28
 *   Jani Tolonen  <jani@mysql.com>
29
 *   Matt Wagner   <matt@mysql.com>
30
 *   Jeremy Cole   <jcole@mysql.com>
31
 *   Tonu Samuel   <tonu@mysql.com>
32
 *   Harrison Fisk <harrison@mysql.com>
1 by brian
clean slate
33
 *
34
 **/
35
612.2.4 by Monty Taylor
Moved some defines to config.h. Stopped including config.h directly anywhere.
36
#include "client_priv.h"
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
37
#include <string>
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
38
#include <drizzled/gettext.h>
39
#include <iostream>
40
#include <map>
713.1.4 by Monty Taylor
Fixed max() problem for solaris
41
#include <algorithm>
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
42
#include <limits.h>
43
#include <cassert>
1241.9.61 by Monty Taylor
No more mystrings in drizzled/
44
#include "drizzled/charset_info.h"
1 by brian
clean slate
45
#include <stdarg.h>
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
46
#include <math.h>
1095.2.1 by Robert Klahn
Replace typedef struct LINE_BUFFER with class LineBuffer, encapsulating current logic
47
#include "client/linebuffer.h"
1 by brian
clean slate
48
#include <signal.h>
212.5.30 by Monty Taylor
Removed my_net.h. Pointless.
49
#include <sys/ioctl.h>
722.1.4 by Monty Taylor
Removed all the setting of DEFS everywhere. Use configmake.h to get the values
50
#include <drizzled/configmake.h>
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
51
#include "drizzled/charset.h"
212.5.30 by Monty Taylor
Removed my_net.h. Pointless.
52
1 by brian
clean slate
53
#if defined(HAVE_CURSES_H) && defined(HAVE_TERM_H)
54
#include <curses.h>
139.1.15 by Trond Norbye
curses.h defines clear and erase as macros causing problems calling the std::string members
55
#ifdef __sun
56
#undef clear
57
#undef erase
58
#endif
1 by brian
clean slate
59
#include <term.h>
60
#else
61
#if defined(HAVE_TERMIOS_H)
62
#include <termios.h>
63
#include <unistd.h>
64
#elif defined(HAVE_TERMBITS_H)
65
#include <termbits.h>
66
#elif defined(HAVE_ASM_TERMBITS_H) && (!defined __GLIBC__ || !(__GLIBC__ > 2 || __GLIBC__ == 2 && __GLIBC_MINOR__ > 0))
206.3.1 by Patrick Galbraith
Most everything working with client rename
67
#include <asm/termbits.h>    // Standard linux
1 by brian
clean slate
68
#endif
69
#if defined(HAVE_TERMCAP_H)
70
#include <termcap.h>
71
#else
72
#ifdef HAVE_CURSES_H
73
#include <curses.h>
74
#endif
206.3.1 by Patrick Galbraith
Most everything working with client rename
75
#undef SYSV        // hack to avoid syntax error
1 by brian
clean slate
76
#ifdef HAVE_TERM_H
77
#include <term.h>
78
#endif
79
#endif
80
#endif
81
779.2.4 by Monty Taylor
Updated some more build stuff.
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) */
1441.3.1 by Vijay Samuel
all required updations have been made
92
  /* no readline */
779.2.4 by Monty Taylor
Updated some more build stuff.
93
#  error Readline Required
94
#endif /* HAVE_LIBREADLINE */
95
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) */
1441.3.1 by Vijay Samuel
all required updations have been made
106
    /* no history */
779.2.4 by Monty Taylor
Updated some more build stuff.
107
#endif /* HAVE_READLINE_HISTORY */
108
779.2.14 by Monty Taylor
Fixed a coupla oopses on the Mac.
109
/**
1441.3.1 by Vijay Samuel
all required updations have been made
110
 Make the old readline interface look like the new one.
779.2.14 by Monty Taylor
Fixed a coupla oopses on the Mac.
111
*/
1149.2.1 by Monty Taylor
Workaround for half-present new-interface on Snow Leopard, combined
112
#ifndef HAVE_RL_COMPLETION
113
typedef char **rl_completion_func_t(const char *, int, int);
779.2.14 by Monty Taylor
Fixed a coupla oopses on the Mac.
114
#define rl_completion_matches(str, func) \
115
  completion_matches((char *)str, (CPFunction *)func)
116
#endif
779.2.4 by Monty Taylor
Updated some more build stuff.
117
1149.2.1 by Monty Taylor
Workaround for half-present new-interface on Snow Leopard, combined
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
1149.2.2 by Monty Taylor
Fixed bad assumption about non-Snow Leopard.
129
typedef Function drizzle_compentry_func_t;
1149.2.1 by Monty Taylor
Workaround for half-present new-interface on Snow Leopard, combined
130
#endif
131
779.2.4 by Monty Taylor
Updated some more build stuff.
132
#if defined(HAVE_LOCALE_H)
133
#include <locale.h>
134
#endif
135
136
137
1 by brian
clean slate
138
#if !defined(HAVE_VIDATTR)
139
#undef vidattr
206.3.1 by Patrick Galbraith
Most everything working with client rename
140
#define vidattr(A) {}      // Can't get this to work
1 by brian
clean slate
141
#endif
142
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
143
using namespace drizzled;
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
144
using namespace std;
145
919.2.11 by Monty Taylor
Removed C99 isnan() usage, which allows us to remove the util/math.{cc,h} workarounds. Yay for standards!
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
1 by brian
clean slate
153
#define PROMPT_CHAR '\\'
154
#define DEFAULT_DELIMITER ";"
155
1441.3.1 by Vijay Samuel
all required updations have been made
156
class Status
1 by brian
clean slate
157
{
1441.3.1 by Vijay Samuel
all required updations have been made
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:
1 by brian
clean slate
251
  int exit_status;
77.1.107 by Monty Taylor
Fixed build warnings.
252
  uint32_t query_start_line;
1 by brian
clean slate
253
  char *file_name;
1095.2.1 by Robert Klahn
Replace typedef struct LINE_BUFFER with class LineBuffer, encapsulating current logic
254
  LineBuffer *line_buff;
1 by brian
clean slate
255
  bool batch,add_to_history;
1441.3.1 by Vijay Samuel
all required updations have been made
256
}; 
1 by brian
clean slate
257
923.2.6 by Monty Taylor
Removing hand-done completion hash functions.
258
static map<string, string>::iterator completion_iter;
923.2.7 by Monty Taylor
Finished replacing custom HashMap with std::map. We use a map and not a set
259
static map<string, string>::iterator completion_end;
923.2.6 by Monty Taylor
Removing hand-done completion hash functions.
260
static map<string, string> completion_map;
923.2.7 by Monty Taylor
Finished replacing custom HashMap with std::map. We use a map and not a set
261
static string completion_string;
262
1 by brian
clean slate
263
static char **defaults_argv;
264
265
enum enum_info_type { INFO_INFO,INFO_ERROR,INFO_RESULT};
266
typedef enum enum_info_type INFO_TYPE;
267
928.1.1 by Eric Day
Started client changes.
268
static drizzle_st drizzle;      /* The library handle */
269
static drizzle_con_st con;      /* The connection */
673.5.2 by Andrew Hutchings
Code cleanups
270
static bool ignore_errors= false, quick= false,
1441.3.1 by Vijay Samuel
all required updations have been made
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;
672.1.1 by Andrew Hutchings
Improve client progress patch
283
static uint32_t  show_progress_size= 0;
143 by Brian Aker
Bool cleanup.
284
static bool column_types_flag;
673.5.2 by Andrew Hutchings
Code cleanups
285
static bool preserve_comments= false;
928.1.4 by Eric Day
Fixed a few bugs, more progress on conversion.
286
static uint32_t opt_max_input_line, opt_drizzle_port= 0;
673.5.6 by Andrew Hutchings
Fix long to uint32_t type casting problem
287
static int verbose= 0, opt_silent= 0, opt_local_infile= 0;
928.1.5 by Eric Day
Merged trunk.
288
static drizzle_capabilities_t connect_flag= DRIZZLE_CAPABILITIES_NONE;
673.5.2 by Andrew Hutchings
Code cleanups
289
static char *current_host, *current_db, *current_user= NULL,
1441.3.1 by Vijay Samuel
all required updations have been made
290
  *opt_password= NULL, *delimiter_str= NULL, *current_prompt= NULL;
1 by brian
clean slate
291
static char *histfile;
292
static char *histfile_tmp;
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
293
static string *glob_buffer;
294
static string *processed_prompt= NULL;
182.1.2 by Jim Winstead
Various fixes to enable compilation on Mac OS X, and remove the glib dependency.
295
static char *default_prompt= NULL;
673.5.2 by Andrew Hutchings
Code cleanups
296
static char *full_username= NULL,*part_username= NULL;
1441.3.1 by Vijay Samuel
all required updations have been made
297
static Status status;
164 by Brian Aker
Commit cleanup of export types.
298
static uint32_t select_limit;
77.1.107 by Monty Taylor
Fixed build warnings.
299
static uint32_t max_join_size;
288 by Brian Aker
ulong cleanp in client apps
300
static uint32_t opt_connect_timeout= 0;
202.3.2 by Monty Taylor
Added gettext calls in to my_getopt.c and drizzle.c
301
// TODO: Need to i18n these
673.5.1 by Andrew Hutchings
Minor coding standards cleanup
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",
1441.3.1 by Vijay Samuel
all required updations have been made
304
                                  "Aug","Sep","Oct","Nov","Dec"};
1 by brian
clean slate
305
static char default_pager[FN_REFLEN];
306
static char pager[FN_REFLEN], outfile[FN_REFLEN];
307
static FILE *PAGER, *OUTFILE;
893 by Brian Aker
First pass of stripping uint
308
static uint32_t prompt_counter;
1 by brian
clean slate
309
static char delimiter[16]= DEFAULT_DELIMITER;
893 by Brian Aker
First pass of stripping uint
310
static uint32_t delimiter_length= 1;
1 by brian
clean slate
311
unsigned short terminal_width= 80;
312
383.1.12 by Brian Aker
Much closer toward UTF8 being around all the time...
313
static const CHARSET_INFO *charset_info= &my_charset_utf8_general_ci;
1 by brian
clean slate
314
928.1.1 by Eric Day
Started client changes.
315
int drizzleclient_real_query_for_lazy(const char *buf, int length,
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
316
                                      drizzle_result_st *result,
317
                                      uint32_t *error_code);
928.1.4 by Eric Day
Fixed a few bugs, more progress on conversion.
318
int drizzleclient_store_result_for_lazy(drizzle_result_st *result);
77.3.7 by Monty Taylor
Made mysql into a pure-C program.
319
1 by brian
clean slate
320
321
void tee_fprintf(FILE *file, const char *fmt, ...);
322
void tee_fputs(const char *s, FILE *file);
323
void tee_puts(const char *s, FILE *file);
324
void tee_putc(int c, FILE *file);
325
static void tee_print_sized_data(const char *, unsigned int, unsigned int, bool);
326
/* The names of functions that actually do the manipulation. */
327
static int get_options(int argc,char **argv);
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
328
static int com_quit(string *str,const char*),
1441.3.1 by Vijay Samuel
all required updations have been made
329
  com_go(string *str,const char*), com_ego(string *str,const char*),
330
  com_print(string *str,const char*),
331
  com_help(string *str,const char*), com_clear(string *str,const char*),
332
  com_connect(string *str,const char*), com_status(string *str,const char*),
333
  com_use(string *str,const char*), com_source(string *str, const char*),
334
  com_rehash(string *str, const char*), com_tee(string *str, const char*),
335
  com_notee(string *str, const char*),
336
  com_prompt(string *str, const char*), com_delimiter(string *str, const char*),
337
  com_warnings(string *str, const char*), com_nowarnings(string *str, const char*),
338
  com_nopager(string *str, const char*), com_pager(string *str, const char*);
1 by brian
clean slate
339
340
static int read_and_execute(bool interactive);
341
static int sql_connect(char *host,char *database,char *user,char *password,
893 by Brian Aker
First pass of stripping uint
342
                       uint32_t silent);
928.1.1 by Eric Day
Started client changes.
343
static const char *server_version_string(drizzle_con_st *con);
893 by Brian Aker
First pass of stripping uint
344
static int put_info(const char *str,INFO_TYPE info,uint32_t error,
77.3.7 by Monty Taylor
Made mysql into a pure-C program.
345
                    const char *sql_state);
928.1.1 by Eric Day
Started client changes.
346
static int put_error(drizzle_con_st *con, drizzle_result_st *res);
288 by Brian Aker
ulong cleanp in client apps
347
static void safe_put_field(const char *pos,uint32_t length);
77.3.7 by Monty Taylor
Made mysql into a pure-C program.
348
static void init_pager(void);
349
static void end_pager(void);
1 by brian
clean slate
350
static void init_tee(const char *);
77.3.7 by Monty Taylor
Made mysql into a pure-C program.
351
static void end_tee(void);
352
static const char* construct_prompt(void);
143 by Brian Aker
Bool cleanup.
353
static char *get_arg(char *line, bool get_next_arg);
77.3.7 by Monty Taylor
Made mysql into a pure-C program.
354
static void init_username(void);
1 by brian
clean slate
355
static void add_int_to_prompt(int toadd);
928.1.1 by Eric Day
Started client changes.
356
static int get_result_width(drizzle_result_st *res);
357
static int get_field_disp_length(drizzle_column_st * field);
266.6.1 by Andy Lester
merging from main
358
static const char * strcont(register const char *str, register const char *set);
1 by brian
clean slate
359
1441.3.1 by Vijay Samuel
all required updations have been made
360
/* A class which contains information on the commands this program
361
   can understand. */
362
class Commands
363
{
364
private:
202.1.25 by Monty Taylor
Fixed change of mysql.com -> drizzle.com.
365
  const char *name;        /* User printable name of the function. */
366
  char cmd_char;        /* msql command character */
1441.3.1 by Vijay Samuel
all required updations have been made
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:
202.1.25 by Monty Taylor
Fixed change of mysql.com -> drizzle.com.
433
  bool takes_params;        /* Max parameters for command */
434
  const char *doc;        /* Documentation for this function.  */
1441.3.1 by Vijay Samuel
all required updations have been made
435
}; 
436
437
438
static Commands commands[] = {
1441.3.3 by Vijay Samuel
Changes made to the struct conversion
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.") ),
1 by brian
clean slate
469
  /* Get bash-like expansion for some commands */
1441.3.3 by Vijay Samuel
Changes made to the struct conversion
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, ""),
1 by brian
clean slate
481
  /* generated 2006-12-28.  Refresh occasionally from lexer. */
1441.3.3 by Vijay Samuel
Changes made to the struct conversion
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, ""),
1 by brian
clean slate
1156
  /* end sentinel */
1441.3.3 by Vijay Samuel
Changes made to the struct conversion
1157
  Commands((char *)NULL,       0, 0, 0, "")
1 by brian
clean slate
1158
};
1159
206.3.1 by Patrick Galbraith
Most everything working with client rename
1160
static const char *load_default_groups[]= { "drizzle","client",0 };
1 by brian
clean slate
1161
77.3.18 by Monty Taylor
Merged in codestyle.
1162
int history_length;
1 by brian
clean slate
1163
static int not_in_history(const char *line);
319 by Brian Aker
Fix (yuck!) for OSX/Google bug.
1164
static void initialize_readline (char *name);
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
1165
static void fix_history(string *final_command);
1 by brian
clean slate
1166
1441.3.1 by Vijay Samuel
all required updations have been made
1167
static Commands *find_command(const char *name,char cmd_name);
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
1168
static bool add_line(string *buffer,char *line,char *in_string,
1 by brian
clean slate
1169
                     bool *ml_comment);
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
1170
static void remove_cntrl(string *buffer);
928.1.1 by Eric Day
Started client changes.
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);
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
1174
static void print_warnings(uint32_t error_code);
288 by Brian Aker
ulong cleanp in client apps
1175
static uint32_t start_timer(void);
1176
static void end_timer(uint32_t start_time,char *buff);
1177
static void drizzle_end_timer(uint32_t start_time,char *buff);
1 by brian
clean slate
1178
static void nice_time(double sec,char *buff,bool part_second);
779.2.11 by Monty Taylor
General build cleanup - removed cruft, removed depreated checks.
1179
extern "C" void drizzle_end(int sig);
1180
extern "C" void handle_sigint(int sig);
1 by brian
clean slate
1181
#if defined(HAVE_TERMIOS_H) && defined(GWINSZ_IN_SYS_IOCTL)
779.2.11 by Monty Taylor
General build cleanup - removed cruft, removed depreated checks.
1182
static void window_resize(int sig);
1 by brian
clean slate
1183
#endif
1184
973.1.2 by Toru Maesaka
Cosmetic fixes pointed out by Jay and added comments for doxygen
1185
/**
1186
  Shutdown the server that we are currently connected to.
1187
1188
  @retval
1441.3.1 by Vijay Samuel
all required updations have been made
1189
    true success
973.1.2 by Toru Maesaka
Cosmetic fixes pointed out by Jay and added comments for doxygen
1190
  @retval
1441.3.1 by Vijay Samuel
all required updations have been made
1191
    false failure
973.1.2 by Toru Maesaka
Cosmetic fixes pointed out by Jay and added comments for doxygen
1192
*/
973.1.1 by Toru Maesaka
Added server shutdown and ping functionalities to the drizzle client app
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);
973.1.2 by Toru Maesaka
Cosmetic fixes pointed out by Jay and added comments for doxygen
1203
    printf("... ");
973.1.1 by Toru Maesaka
Added server shutdown and ping functionalities to the drizzle client app
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
973.1.2 by Toru Maesaka
Cosmetic fixes pointed out by Jay and added comments for doxygen
1231
/**
1232
  Ping the server that we are currently connected to.
1233
1234
  @retval
1441.3.1 by Vijay Samuel
all required updations have been made
1235
    true success
973.1.2 by Toru Maesaka
Cosmetic fixes pointed out by Jay and added comments for doxygen
1236
  @retval
1441.3.1 by Vijay Samuel
all required updations have been made
1237
    false failure
973.1.2 by Toru Maesaka
Cosmetic fixes pointed out by Jay and added comments for doxygen
1238
*/
973.1.1 by Toru Maesaka
Added server shutdown and ping functionalities to the drizzle client app
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
973.1.2 by Toru Maesaka
Cosmetic fixes pointed out by Jay and added comments for doxygen
1268
/**
1269
  Execute command(s) specified by the user.
1270
1271
  @param error  error status of command execution.
1441.3.1 by Vijay Samuel
all required updations have been made
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.
973.1.2 by Toru Maesaka
Cosmetic fixes pointed out by Jay and added comments for doxygen
1276
1277
  @retval
1441.3.1 by Vijay Samuel
all required updations have been made
1278
    false no commands were executed
973.1.2 by Toru Maesaka
Cosmetic fixes pointed out by Jay and added comments for doxygen
1279
  @retval
1441.3.1 by Vijay Samuel
all required updations have been made
1280
    true  at least one command was executed
973.1.2 by Toru Maesaka
Cosmetic fixes pointed out by Jay and added comments for doxygen
1281
*/
973.1.1 by Toru Maesaka
Added server shutdown and ping functionalities to the drizzle client app
1282
static bool execute_commands(int *error)
1283
{
1284
  bool executed= false;
1285
  *error= 0;
1286
1287
  if (opt_ping)
1288
  {
973.1.2 by Toru Maesaka
Cosmetic fixes pointed out by Jay and added comments for doxygen
1289
    if (server_ping() == false)
973.1.1 by Toru Maesaka
Added server shutdown and ping functionalities to the drizzle client app
1290
      *error= 1;
1291
    executed= true;
1292
  }
1293
1294
  if (opt_shutdown)
1295
  {
973.1.2 by Toru Maesaka
Cosmetic fixes pointed out by Jay and added comments for doxygen
1296
    if (server_shutdown() == false)
973.1.1 by Toru Maesaka
Added server shutdown and ping functionalities to the drizzle client app
1297
      *error= 1;
1298
    executed= true;
1299
  }
1300
  return executed;
1301
}
1302
1 by brian
clean slate
1303
int main(int argc,char *argv[])
1304
{
236.1.60 by Monty Taylor
Another stab at protecting NLS stuff.
1305
#if defined(ENABLE_NLS)
1306
# if defined(HAVE_LOCALE_H)
202.3.2 by Monty Taylor
Added gettext calls in to my_getopt.c and drizzle.c
1307
  setlocale(LC_ALL, "");
236.1.60 by Monty Taylor
Another stab at protecting NLS stuff.
1308
# endif
202.3.2 by Monty Taylor
Added gettext calls in to my_getopt.c and drizzle.c
1309
  bindtextdomain("drizzle", LOCALEDIR);
1310
  textdomain("drizzle");
236.1.60 by Monty Taylor
Another stab at protecting NLS stuff.
1311
#endif
202.3.2 by Monty Taylor
Added gettext calls in to my_getopt.c and drizzle.c
1312
1 by brian
clean slate
1313
  MY_INIT(argv[0]);
1314
  delimiter_str= delimiter;
656.1.20 by Monty Taylor
Removed my_strdup, my_malloc, my_realloc from client/
1315
  default_prompt= strdup(getenv("DRIZZLE_PS1") ?
1316
                         getenv("DRIZZLE_PS1") :
1317
                         "drizzle> ");
1441.3.1 by Vijay Samuel
all required updations have been made
1318
  
656.1.51 by Monty Taylor
Fixed strdup return checking in client/
1319
  if (default_prompt == NULL)
1320
  {
1321
    fprintf(stderr, _("Memory allocation error while constructing initial "
1322
                      "prompt. Aborting.\n"));
1323
    exit(ENOMEM);
1324
  }
656.1.20 by Monty Taylor
Removed my_strdup, my_malloc, my_realloc from client/
1325
  current_prompt= strdup(default_prompt);
656.1.51 by Monty Taylor
Fixed strdup return checking in client/
1326
  if (current_prompt == NULL)
1327
  {
1328
    fprintf(stderr, _("Memory allocation error while constructing initial "
1329
                      "prompt. Aborting.\n"));
1330
    exit(ENOMEM);
1331
  }
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
1332
  processed_prompt= new string();
287.3.22 by Monty Taylor
Fixed typo.
1333
  processed_prompt->reserve(32);
182.1.2 by Jim Winstead
Various fixes to enable compilation on Mac OS X, and remove the glib dependency.
1334
1 by brian
clean slate
1335
  prompt_counter=0;
1336
206.3.1 by Patrick Galbraith
Most everything working with client rename
1337
  outfile[0]=0;      // no (default) outfile
641.4.1 by Toru Maesaka
First pass of replacing MySQL's my_stpcpy() with appropriate libc calls
1338
  strcpy(pager, "stdout");  // the default, if --pager wasn't given
1 by brian
clean slate
1339
  {
1340
    char *tmp=getenv("PAGER");
1341
    if (tmp && strlen(tmp))
1342
    {
1343
      default_pager_set= 1;
641.4.1 by Toru Maesaka
First pass of replacing MySQL's my_stpcpy() with appropriate libc calls
1344
      strcpy(default_pager, tmp);
1 by brian
clean slate
1345
    }
1346
  }
1347
  if (!isatty(0) || !isatty(1))
1348
  {
1441.3.1 by Vijay Samuel
all required updations have been made
1349
    status.setBatch(1); opt_silent=1;
1 by brian
clean slate
1350
    ignore_errors=0;
1351
  }
1352
  else
1441.3.1 by Vijay Samuel
all required updations have been made
1353
    status.setAddToHistory(1);
1354
  status.setExitStatus(1);
1 by brian
clean slate
1355
1356
  {
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
1357
    /*
1358
      The file descriptor-layer may be out-of-sync with the file-number layer,
1359
      so we make sure that "stdout" is really open.  If its file is closed then
1360
      explicitly close the FD layer.
1 by brian
clean slate
1361
    */
1362
    int stdout_fileno_copy;
1363
    stdout_fileno_copy= dup(fileno(stdout)); /* Okay if fileno fails. */
1364
    if (stdout_fileno_copy == -1)
1365
      fclose(stdout);
1366
    else
1367
      close(stdout_fileno_copy);             /* Clean up dup(). */
1368
  }
1369
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1370
  internal::load_defaults("drizzle",load_default_groups,&argc,&argv);
1 by brian
clean slate
1371
  defaults_argv=argv;
1372
  if (get_options(argc, (char **) argv))
1373
  {
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1374
    internal::free_defaults(defaults_argv);
1375
    internal::my_end();
1 by brian
clean slate
1376
    exit(1);
1377
  }
973.1.1 by Toru Maesaka
Added server shutdown and ping functionalities to the drizzle client app
1378
212.6.10 by Mats Kindahl
Removing redundant use of casts in client/ for memcmp(), memcpy(), memset(), and memmove().
1379
  memset(&drizzle, 0, sizeof(drizzle));
1 by brian
clean slate
1380
  if (sql_connect(current_host,current_db,current_user,opt_password,
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
1381
                  opt_silent))
1 by brian
clean slate
1382
  {
206.3.1 by Patrick Galbraith
Most everything working with client rename
1383
    quick= 1;          // Avoid history
1441.3.1 by Vijay Samuel
all required updations have been made
1384
    status.setExitStatus(1);
206.3.1 by Patrick Galbraith
Most everything working with client rename
1385
    drizzle_end(-1);
1 by brian
clean slate
1386
  }
973.1.1 by Toru Maesaka
Added server shutdown and ping functionalities to the drizzle client app
1387
1388
  int command_error;
973.1.2 by Toru Maesaka
Cosmetic fixes pointed out by Jay and added comments for doxygen
1389
  if (execute_commands(&command_error) != false)
973.1.1 by Toru Maesaka
Added server shutdown and ping functionalities to the drizzle client app
1390
  {
1391
    /* we've executed a command so exit before we go into readline mode */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1392
    internal::free_defaults(defaults_argv);
1393
    internal::my_end();
973.1.1 by Toru Maesaka
Added server shutdown and ping functionalities to the drizzle client app
1394
    exit(command_error);
1395
  }
1396
1441.3.1 by Vijay Samuel
all required updations have been made
1397
  if (status.getBatch() && !status.getLineBuff())
973.1.1 by Toru Maesaka
Added server shutdown and ping functionalities to the drizzle client app
1398
  {
1441.3.1 by Vijay Samuel
all required updations have been made
1399
    status.setLineBuff(opt_max_input_line, stdin);
1400
    if (status.getLineBuff() == NULL)
973.1.2 by Toru Maesaka
Cosmetic fixes pointed out by Jay and added comments for doxygen
1401
    {
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1402
      internal::free_defaults(defaults_argv);
1403
      internal::my_end();
973.1.2 by Toru Maesaka
Cosmetic fixes pointed out by Jay and added comments for doxygen
1404
      exit(1);
1405
    }
973.1.1 by Toru Maesaka
Added server shutdown and ping functionalities to the drizzle client app
1406
  }
973.1.2 by Toru Maesaka
Cosmetic fixes pointed out by Jay and added comments for doxygen
1407
1441.3.1 by Vijay Samuel
all required updations have been made
1408
  if (!status.getBatch())
206.3.1 by Patrick Galbraith
Most everything working with client rename
1409
    ignore_errors=1;        // Don't abort monitor
1 by brian
clean slate
1410
1411
  if (opt_sigint_ignore)
1412
    signal(SIGINT, SIG_IGN);
1413
  else
1414
    signal(SIGINT, handle_sigint);              // Catch SIGINT to clean up
206.3.1 by Patrick Galbraith
Most everything working with client rename
1415
  signal(SIGQUIT, drizzle_end);      // Catch SIGQUIT to clean up
1 by brian
clean slate
1416
1417
#if defined(HAVE_TERMIOS_H) && defined(GWINSZ_IN_SYS_IOCTL)
1418
  /* Readline will call this if it installs a handler */
1419
  signal(SIGWINCH, window_resize);
1420
  /* call the SIGWINCH handler to get the default term width */
1421
  window_resize(0);
1422
#endif
1423
202.3.13 by Monty Taylor
Changed gettext() to _() in drizzle.c.
1424
  put_info(_("Welcome to the Drizzle client..  Commands end with ; or \\g."),
77.3.7 by Monty Taylor
Made mysql into a pure-C program.
1425
           INFO_INFO,0,0);
182.1.2 by Jim Winstead
Various fixes to enable compilation on Mac OS X, and remove the glib dependency.
1426
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
1427
  glob_buffer= new string();
287.3.19 by Monty Taylor
Added string.reserve() calls.
1428
  glob_buffer->reserve(512);
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1429
1441.3.1 by Vijay Samuel
all required updations have been made
1430
  char * output_buff= (char *)malloc(512);
1431
  memset(output_buff, '\0', 512);
1432
1433
  sprintf(output_buff,
1434
          _("Your Drizzle connection id is %u\nServer version: %s\n"),
1435
          drizzle_con_thread_id(&con),
1436
          server_version_string(&con));
1437
  put_info(output_buff, INFO_INFO, 0, 0);
1 by brian
clean slate
1438
319 by Brian Aker
Fix (yuck!) for OSX/Google bug.
1439
  initialize_readline(current_prompt);
1441.3.1 by Vijay Samuel
all required updations have been made
1440
  if (!status.getBatch() && !quick)
1 by brian
clean slate
1441
  {
206.3.1 by Patrick Galbraith
Most everything working with client rename
1442
    /* read-history from file, default ~/.drizzle_history*/
266.2.3 by Jim Winstead
Use DRIZZLE_* environment variables instead of MYSQL_*
1443
    if (getenv("DRIZZLE_HISTFILE"))
1444
      histfile= strdup(getenv("DRIZZLE_HISTFILE"));
1 by brian
clean slate
1445
    else if (getenv("HOME"))
1446
    {
1441.3.1 by Vijay Samuel
all required updations have been made
1447
      histfile=(char*) malloc(strlen(getenv("HOME")) + strlen("/.drizzle_history") + 2);
1 by brian
clean slate
1448
      if (histfile)
1441.3.1 by Vijay Samuel
all required updations have been made
1449
        sprintf(histfile,"%s/.drizzle_history",getenv("HOME"));
1 by brian
clean slate
1450
      char link_name[FN_REFLEN];
1060.2.1 by Eric Lambert
-replace calls to my_readlink with readlink
1451
      ssize_t sym_link_size= readlink(histfile,link_name,FN_REFLEN-1);
1452
      if (sym_link_size >= 0)
1 by brian
clean slate
1453
      {
1060.2.1 by Eric Lambert
-replace calls to my_readlink with readlink
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
        }
1 by brian
clean slate
1461
      }
1462
    }
1463
    if (histfile)
1464
    {
1465
      if (verbose)
202.3.13 by Monty Taylor
Changed gettext() to _() in drizzle.c.
1466
        tee_fprintf(stdout, _("Reading history-file %s\n"),histfile);
1 by brian
clean slate
1467
      read_history(histfile);
1441.3.1 by Vijay Samuel
all required updations have been made
1468
      if (!(histfile_tmp= (char*) malloc((uint32_t) strlen(histfile) + 5)))
1 by brian
clean slate
1469
      {
202.3.13 by Monty Taylor
Changed gettext() to _() in drizzle.c.
1470
        fprintf(stderr, _("Couldn't allocate memory for temp histfile!\n"));
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
1471
        exit(1);
1 by brian
clean slate
1472
      }
1441.3.1 by Vijay Samuel
all required updations have been made
1473
      sprintf(histfile_tmp, "%s.TMP", histfile);
1 by brian
clean slate
1474
    }
1475
  }
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
1476
1126.4.1 by Monty Taylor
Fixed a buffer overrun that was causing some translated message output to suck.
1477
  put_info(_("Type 'help;' or '\\h' for help. "
1478
             "Type '\\c' to clear the buffer.\n"),INFO_INFO,0,0);
1441.3.1 by Vijay Samuel
all required updations have been made
1479
  status.setExitStatus(read_and_execute(!status.getBatch()));
1 by brian
clean slate
1480
  if (opt_outfile)
1481
    end_tee();
206.3.1 by Patrick Galbraith
Most everything working with client rename
1482
  drizzle_end(0);
319 by Brian Aker
Fix (yuck!) for OSX/Google bug.
1483
206.3.1 by Patrick Galbraith
Most everything working with client rename
1484
  return(0);        // Keep compiler happy
1 by brian
clean slate
1485
}
1486
779.2.11 by Monty Taylor
General build cleanup - removed cruft, removed depreated checks.
1487
void drizzle_end(int sig)
1 by brian
clean slate
1488
{
928.1.1 by Eric Day
Started client changes.
1489
  drizzle_con_free(&con);
1490
  drizzle_free(&drizzle);
1441.3.1 by Vijay Samuel
all required updations have been made
1491
  if (!status.getBatch() && !quick && histfile)
1 by brian
clean slate
1492
  {
1493
    /* write-history */
1494
    if (verbose)
202.3.13 by Monty Taylor
Changed gettext() to _() in drizzle.c.
1495
      tee_fprintf(stdout, _("Writing history-file %s\n"),histfile);
1 by brian
clean slate
1496
    if (!write_history(histfile_tmp))
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1497
      internal::my_rename(histfile_tmp, histfile, MYF(MY_WME));
1 by brian
clean slate
1498
  }
1441.3.1 by Vijay Samuel
all required updations have been made
1499
  delete status.getLineBuff();
1500
  status.setLineBuff(0);
1 by brian
clean slate
1501
1502
  if (sig >= 0)
202.3.13 by Monty Taylor
Changed gettext() to _() in drizzle.c.
1503
    put_info(sig ? _("Aborted") : _("Bye"), INFO_RESULT,0,0);
182.1.2 by Jim Winstead
Various fixes to enable compilation on Mac OS X, and remove the glib dependency.
1504
  if (glob_buffer)
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
1505
    delete glob_buffer;
182.1.2 by Jim Winstead
Various fixes to enable compilation on Mac OS X, and remove the glib dependency.
1506
  if (processed_prompt)
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
1507
    delete processed_prompt;
477 by Monty Taylor
Removed my_free(). It turns out that it had been def'd to ignore the flags passed to it in the second arg anyway. Gotta love that.
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);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1518
  internal::free_defaults(defaults_argv);
1519
  internal::my_end();
1441.3.1 by Vijay Samuel
all required updations have been made
1520
  exit(status.getExitStatus());
1 by brian
clean slate
1521
}
1522
1523
1524
/*
1525
  This function handles sigint calls
1526
  If query is in process, kill query
1527
  no query in process, terminate like previous behavior
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
1528
*/
520.4.43 by mordred
A set of Solaris fixes.
1529
extern "C"
779.2.11 by Monty Taylor
General build cleanup - removed cruft, removed depreated checks.
1530
void handle_sigint(int sig)
1 by brian
clean slate
1531
{
1532
  char kill_buffer[40];
928.1.1 by Eric Day
Started client changes.
1533
  drizzle_con_st kill_drizzle;
1534
  drizzle_result_st res;
1535
  drizzle_return_t ret;
1 by brian
clean slate
1536
1537
  /* terminate if no query being executed, or we already tried interrupting */
77.3.3 by Monty Taylor
Last change to migrate to glib from sql_string.
1538
  if (!executing_query || interrupted_query) {
1 by brian
clean slate
1539
    goto err;
77.3.3 by Monty Taylor
Last change to migrate to glib from sql_string.
1540
  }
1 by brian
clean slate
1541
928.1.1 by Eric Day
Started client changes.
1542
  if (drizzle_con_add_tcp(&drizzle, &kill_drizzle, current_host,
1543
                          opt_drizzle_port, current_user, opt_password, NULL,
971.8.4 by Eric Day
Added --mysql option flags to client utilities. Also removed the socket option since that is no used anymoe (requested from mailing list).
1544
                          opt_mysql ? DRIZZLE_CON_MYSQL : DRIZZLE_CON_NONE) == NULL)
77.3.3 by Monty Taylor
Last change to migrate to glib from sql_string.
1545
  {
1 by brian
clean slate
1546
    goto err;
77.3.3 by Monty Taylor
Last change to migrate to glib from sql_string.
1547
  }
1 by brian
clean slate
1548
1549
  /* kill_buffer is always big enough because max length of %lu is 15 */
1441.3.1 by Vijay Samuel
all required updations have been made
1550
  sprintf(kill_buffer, "KILL /*!50000 QUERY */ %u",
1551
          drizzle_con_thread_id(&con));
928.1.1 by Eric Day
Started client changes.
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);
202.3.13 by Monty Taylor
Changed gettext() to _() in drizzle.c.
1557
  tee_fprintf(stdout, _("Query aborted by Ctrl+C\n"));
1 by brian
clean slate
1558
1559
  interrupted_query= 1;
1560
1561
  return;
1562
1563
err:
206.3.1 by Patrick Galbraith
Most everything working with client rename
1564
  drizzle_end(sig);
1 by brian
clean slate
1565
}
1566
1567
1568
#if defined(HAVE_TERMIOS_H) && defined(GWINSZ_IN_SYS_IOCTL)
779.2.11 by Monty Taylor
General build cleanup - removed cruft, removed depreated checks.
1569
void window_resize(int)
1 by brian
clean slate
1570
{
1571
  struct winsize window_size;
1572
1573
  if (ioctl(fileno(stdin), TIOCGWINSZ, &window_size) == 0)
1574
    terminal_width= window_size.ws_col;
1575
}
1576
#endif
1577
1410.3.4 by Djellel E. Difallah
update references to old my_'s
1578
static struct option my_long_options[] =
1 by brian
clean slate
1579
{
261.3.5 by Monty Taylor
Changed gettext_noop() to N_()
1580
  {"help", '?', N_("Display this help and exit."), 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
1441.3.1 by Vijay Samuel
all required updations have been made
1581
   0, 0, 0, 0, 0},
261.3.5 by Monty Taylor
Changed gettext_noop() to N_()
1582
  {"help", 'I', N_("Synonym for -?"), 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
1441.3.1 by Vijay Samuel
all required updations have been made
1583
   0, 0, 0, 0, 0},
1 by brian
clean slate
1584
  {"auto-rehash", OPT_AUTO_REHASH,
1441.3.1 by Vijay Samuel
all required updations have been made
1585
   N_("Enable automatic rehashing. One doesn't need to use 'rehash' to get table and field completion, but startup and reconnecting may take a longer time. Disable with --disable-auto-rehash."),
1586
   (char**) &opt_rehash, (char**) &opt_rehash, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0,
1587
   0, 0},
1 by brian
clean slate
1588
  {"no-auto-rehash", 'A',
1441.3.1 by Vijay Samuel
all required updations have been made
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."),
1590
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
1591
  {"auto-vertical-output", OPT_AUTO_VERTICAL_OUTPUT,
1441.3.1 by Vijay Samuel
all required updations have been made
1592
   N_("Automatically switch to vertical output mode if the result is wider than the terminal width."),
1593
   (char**) &auto_vertical_output, (char**) &auto_vertical_output, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1 by brian
clean slate
1594
  {"batch", 'B',
1441.3.1 by Vijay Samuel
all required updations have been made
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},
261.3.5 by Monty Taylor
Changed gettext_noop() to N_()
1596
  {"column-type-info", OPT_COLUMN_TYPES, N_("Display column type information."),
1441.3.1 by Vijay Samuel
all required updations have been made
1597
   (char**) &column_types_flag, (char**) &column_types_flag,
1598
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
261.3.5 by Monty Taylor
Changed gettext_noop() to N_()
1599
  {"comments", 'c', N_("Preserve comments. Send comments to the server. The default is --skip-comments (discard comments), enable with --comments"),
1441.3.1 by Vijay Samuel
all required updations have been made
1600
   (char**) &preserve_comments, (char**) &preserve_comments,
1601
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
261.3.5 by Monty Taylor
Changed gettext_noop() to N_()
1602
  {"compress", 'C', N_("Use compression in server/client protocol."),
1441.3.1 by Vijay Samuel
all required updations have been made
1603
   (char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
1604
   0, 0, 0},
261.3.5 by Monty Taylor
Changed gettext_noop() to N_()
1605
  {"database", 'D', N_("Database to use."), (char**) &current_db,
1441.3.1 by Vijay Samuel
all required updations have been made
1606
   (char**) &current_db, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1 by brian
clean slate
1607
  {"default-character-set", OPT_DEFAULT_CHARSET,
1441.3.1 by Vijay Samuel
all required updations have been made
1608
   N_("(not used)"), 0,
1609
   0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
261.3.5 by Monty Taylor
Changed gettext_noop() to N_()
1610
  {"delimiter", OPT_DELIMITER, N_("Delimiter to be used."), (char**) &delimiter_str,
1441.3.1 by Vijay Samuel
all required updations have been made
1611
   (char**) &delimiter_str, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
261.3.5 by Monty Taylor
Changed gettext_noop() to N_()
1612
  {"execute", 'e', N_("Execute command and quit. (Disables --force and history file)"), 0,
1441.3.1 by Vijay Samuel
all required updations have been made
1613
   0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
261.3.5 by Monty Taylor
Changed gettext_noop() to N_()
1614
  {"vertical", 'E', N_("Print the output of a query (rows) vertically."),
1441.3.1 by Vijay Samuel
all required updations have been made
1615
   (char**) &vertical, (char**) &vertical, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
1616
   0},
261.3.5 by Monty Taylor
Changed gettext_noop() to N_()
1617
  {"force", 'f', N_("Continue even if we get an sql error."),
1441.3.1 by Vijay Samuel
all required updations have been made
1618
   (char**) &ignore_errors, (char**) &ignore_errors, 0, GET_BOOL, NO_ARG, 0, 0,
1619
   0, 0, 0, 0},
1 by brian
clean slate
1620
  {"named-commands", 'G',
1441.3.1 by Vijay Samuel
all required updations have been made
1621
   N_("Enable named commands. Named commands mean this program's internal commands; see drizzle> help . When enabled, the named commands can be used from any line of the query, otherwise only from the first line, before an enter. Disable with --disable-named-commands. This option is disabled by default."),
1622
   (char**) &named_cmds, (char**) &named_cmds, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
1623
   0, 0},
1 by brian
clean slate
1624
  {"no-named-commands", 'g',
1441.3.1 by Vijay Samuel
all required updations have been made
1625
   N_("Named commands are disabled. Use \\* form only, or use named commands only in the beginning of a line ending with a semicolon (;) Since version 10.9 the client now starts with this option ENABLED by default! Disable with '-G'. Long format commands still work from the first line. WARNING: option deprecated; use --disable-named-commands instead."),
1626
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
261.3.5 by Monty Taylor
Changed gettext_noop() to N_()
1627
  {"ignore-spaces", 'i', N_("Ignore space after function names."), 0, 0, 0,
1441.3.1 by Vijay Samuel
all required updations have been made
1628
   GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
261.3.5 by Monty Taylor
Changed gettext_noop() to N_()
1629
  {"local-infile", OPT_LOCAL_INFILE, N_("Enable/disable LOAD DATA LOCAL INFILE."),
1441.3.1 by Vijay Samuel
all required updations have been made
1630
   (char**) &opt_local_infile,
1631
   (char**) &opt_local_infile, 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
261.3.5 by Monty Taylor
Changed gettext_noop() to N_()
1632
  {"no-beep", 'b', N_("Turn off beep on error."), (char**) &opt_nobeep,
1441.3.1 by Vijay Samuel
all required updations have been made
1633
   (char**) &opt_nobeep, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
261.3.5 by Monty Taylor
Changed gettext_noop() to N_()
1634
  {"host", 'h', N_("Connect to host."), (char**) &current_host,
1441.3.1 by Vijay Samuel
all required updations have been made
1635
   (char**) &current_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
261.3.5 by Monty Taylor
Changed gettext_noop() to N_()
1636
  {"line-numbers", OPT_LINE_NUMBERS, N_("Write line numbers for errors."),
1441.3.1 by Vijay Samuel
all required updations have been made
1637
   (char**) &line_numbers, (char**) &line_numbers, 0, GET_BOOL,
1638
   NO_ARG, 1, 0, 0, 0, 0, 0},
261.3.5 by Monty Taylor
Changed gettext_noop() to N_()
1639
  {"skip-line-numbers", 'L', N_("Don't write line number for errors. WARNING: -L is deprecated, use long version of this option instead."), 0, 0, 0, GET_NO_ARG,
1441.3.1 by Vijay Samuel
all required updations have been made
1640
   NO_ARG, 0, 0, 0, 0, 0, 0},
261.3.5 by Monty Taylor
Changed gettext_noop() to N_()
1641
  {"unbuffered", 'n', N_("Flush buffer after each query."), (char**) &unbuffered,
1441.3.1 by Vijay Samuel
all required updations have been made
1642
   (char**) &unbuffered, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
261.3.5 by Monty Taylor
Changed gettext_noop() to N_()
1643
  {"column-names", OPT_COLUMN_NAMES, N_("Write column names in results."),
1441.3.1 by Vijay Samuel
all required updations have been made
1644
   (char**) &column_names, (char**) &column_names, 0, GET_BOOL,
1645
   NO_ARG, 1, 0, 0, 0, 0, 0},
1 by brian
clean slate
1646
  {"skip-column-names", 'N',
1441.3.1 by Vijay Samuel
all required updations have been made
1647
   N_("Don't write column names in results. WARNING: -N is deprecated, use long version of this options instead."),
1648
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1 by brian
clean slate
1649
  {"set-variable", 'O',
1441.3.1 by Vijay Samuel
all required updations have been made
1650
   N_("Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value."),
1651
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
261.3.5 by Monty Taylor
Changed gettext_noop() to N_()
1652
  {"sigint-ignore", OPT_SIGINT_IGNORE, N_("Ignore SIGINT (CTRL-C)"),
1441.3.1 by Vijay Samuel
all required updations have been made
1653
   (char**) &opt_sigint_ignore,  (char**) &opt_sigint_ignore, 0, GET_BOOL,
1654
   NO_ARG, 0, 0, 0, 0, 0, 0},
1 by brian
clean slate
1655
  {"one-database", 'o',
1441.3.1 by Vijay Samuel
all required updations have been made
1656
   N_("Only update the default database. This is useful for skipping updates to other database in the update log."),
1657
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1 by brian
clean slate
1658
  {"pager", OPT_PAGER,
1441.3.1 by Vijay Samuel
all required updations have been made
1659
   N_("Pager to use to display results. If you don't supply an option the default pager is taken from your ENV variable PAGER. Valid pagers are less, more, cat [> filename], etc. See interactive help (\\h) also. This option does not work in batch mode. Disable with --disable-pager. This option is disabled by default."),
1660
   0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
1 by brian
clean slate
1661
  {"no-pager", OPT_NOPAGER,
1441.3.1 by Vijay Samuel
all required updations have been made
1662
   N_("Disable pager and print to stdout. See interactive help (\\h) also. WARNING: option deprecated; use --disable-pager instead."),
1663
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
673.5.1 by Andrew Hutchings
Minor coding standards cleanup
1664
  {"password", 'P',
1441.3.1 by Vijay Samuel
all required updations have been made
1665
   N_("Password to use when connecting to server. If password is not given it's asked from the tty."),
1666
   0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
673.5.1 by Andrew Hutchings
Minor coding standards cleanup
1667
  {"port", 'p', N_("Port number to use for connection or 0 for default to, in order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, ")
1441.3.1 by Vijay Samuel
all required updations have been made
1668
   N_("built-in default") " (" STRINGIFY_ARG(DRIZZLE_PORT) ").",
1669
   0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
261.3.5 by Monty Taylor
Changed gettext_noop() to N_()
1670
  {"prompt", OPT_PROMPT, N_("Set the drizzle prompt to this value."),
1441.3.1 by Vijay Samuel
all required updations have been made
1671
   (char**) &current_prompt, (char**) &current_prompt, 0, GET_STR_ALLOC,
1672
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1 by brian
clean slate
1673
  {"quick", 'q',
1441.3.1 by Vijay Samuel
all required updations have been made
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."),
1675
   (char**) &quick, (char**) &quick, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
261.3.5 by Monty Taylor
Changed gettext_noop() to N_()
1676
  {"raw", 'r', N_("Write fields without conversion. Used with --batch."),
1441.3.1 by Vijay Samuel
all required updations have been made
1677
   (char**) &opt_raw_data, (char**) &opt_raw_data, 0, GET_BOOL, NO_ARG, 0, 0, 0,
1678
   0, 0, 0},
261.3.5 by Monty Taylor
Changed gettext_noop() to N_()
1679
  {"reconnect", OPT_RECONNECT, N_("Reconnect if the connection is lost. Disable with --disable-reconnect. This option is enabled by default."),
1441.3.1 by Vijay Samuel
all required updations have been made
1680
   (char**) &opt_reconnect, (char**) &opt_reconnect, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
973.1.1 by Toru Maesaka
Added server shutdown and ping functionalities to the drizzle client app
1681
  {"shutdown", OPT_SHUTDOWN, N_("Shutdown the server."),
1441.3.1 by Vijay Samuel
all required updations have been made
1682
   (char**) &opt_shutdown, (char**) &opt_shutdown, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
261.3.5 by Monty Taylor
Changed gettext_noop() to N_()
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,
1441.3.1 by Vijay Samuel
all required updations have been made
1684
   0, 0},
261.3.5 by Monty Taylor
Changed gettext_noop() to N_()
1685
  {"table", 't', N_("Output in table format."), (char**) &output_tables,
1441.3.1 by Vijay Samuel
all required updations have been made
1686
   (char**) &output_tables, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1 by brian
clean slate
1687
  {"tee", OPT_TEE,
1441.3.1 by Vijay Samuel
all required updations have been made
1688
   N_("Append everything into outfile. See interactive help (\\h) also. Does not work in batch mode. Disable with --disable-tee. This option is disabled by default."),
1689
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
261.3.5 by Monty Taylor
Changed gettext_noop() to N_()
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,
1441.3.1 by Vijay Samuel
all required updations have been made
1691
   NO_ARG, 0, 0, 0, 0, 0, 0},
261.3.5 by Monty Taylor
Changed gettext_noop() to N_()
1692
  {"user", 'u', N_("User for login if not current user."), (char**) &current_user,
1441.3.1 by Vijay Samuel
all required updations have been made
1693
   (char**) &current_user, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
261.3.5 by Monty Taylor
Changed gettext_noop() to N_()
1694
  {"safe-updates", 'U', N_("Only allow UPDATE and DELETE that uses keys."),
1441.3.1 by Vijay Samuel
all required updations have been made
1695
   (char**) &safe_updates, (char**) &safe_updates, 0, GET_BOOL, NO_ARG, 0, 0,
1696
   0, 0, 0, 0},
261.3.5 by Monty Taylor
Changed gettext_noop() to N_()
1697
  {"i-am-a-dummy", 'U', N_("Synonym for option --safe-updates, -U."),
1441.3.1 by Vijay Samuel
all required updations have been made
1698
   (char**) &safe_updates, (char**) &safe_updates, 0, GET_BOOL, NO_ARG, 0, 0,
1699
   0, 0, 0, 0},
261.3.5 by Monty Taylor
Changed gettext_noop() to N_()
1700
  {"verbose", 'v', N_("Write more. (-v -v -v gives the table output format)."), 0,
1441.3.1 by Vijay Samuel
all required updations have been made
1701
   0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
261.3.5 by Monty Taylor
Changed gettext_noop() to N_()
1702
  {"version", 'V', N_("Output version information and exit."), 0, 0, 0,
1441.3.1 by Vijay Samuel
all required updations have been made
1703
   GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
261.3.5 by Monty Taylor
Changed gettext_noop() to N_()
1704
  {"wait", 'w', N_("Wait and retry if connection is down."), 0, 0, 0, GET_NO_ARG,
1441.3.1 by Vijay Samuel
all required updations have been made
1705
   NO_ARG, 0, 0, 0, 0, 0, 0},
1 by brian
clean slate
1706
  {"connect_timeout", OPT_CONNECT_TIMEOUT,
1441.3.1 by Vijay Samuel
all required updations have been made
1707
   N_("Number of seconds before connection timeout."),
1708
   (char**) &opt_connect_timeout,
1709
   (char**) &opt_connect_timeout, 0, GET_UINT32, REQUIRED_ARG, 0, 0, 3600*12, 0,
1710
   0, 0},
928.1.4 by Eric Day
Fixed a few bugs, more progress on conversion.
1711
  {"max_input_line", OPT_MAX_INPUT_LINE,
1441.3.1 by Vijay Samuel
all required updations have been made
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,
1715
   (int64_t) 2*1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
1 by brian
clean slate
1716
  {"select_limit", OPT_SELECT_LIMIT,
1441.3.1 by Vijay Samuel
all required updations have been made
1717
   N_("Automatic limit for SELECT when using --safe-updates"),
1718
   (char**) &select_limit,
1719
   (char**) &select_limit, 0, GET_UINT32, REQUIRED_ARG, 1000L, 1, ULONG_MAX,
1720
   0, 1, 0},
1 by brian
clean slate
1721
  {"max_join_size", OPT_MAX_JOIN_SIZE,
1441.3.1 by Vijay Samuel
all required updations have been made
1722
   N_("Automatic limit for rows in a join when using --safe-updates"),
1723
   (char**) &max_join_size,
1724
   (char**) &max_join_size, 0, GET_UINT32, REQUIRED_ARG, 1000000L, 1, ULONG_MAX,
1725
   0, 1, 0},
261.3.5 by Monty Taylor
Changed gettext_noop() to N_()
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,
1441.3.1 by Vijay Samuel
all required updations have been made
1727
   (char**) &opt_secure_auth, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
261.3.5 by Monty Taylor
Changed gettext_noop() to N_()
1728
  {"show-warnings", OPT_SHOW_WARNINGS, N_("Show warnings after every statement."),
1441.3.1 by Vijay Samuel
all required updations have been made
1729
   (char**) &show_warnings, (char**) &show_warnings, 0, GET_BOOL, NO_ARG,
1730
   0, 0, 0, 0, 0, 0},
672.1.2 by Andrew Hutchings
Fix help for show-progress-size
1731
  {"show-progress-size", OPT_SHOW_PROGRESS_SIZE, N_("Number of lines before each import progress report."),
1441.3.1 by Vijay Samuel
all required updations have been made
1732
   (char**) &show_progress_size, (char**) &show_progress_size, 0, GET_UINT32, REQUIRED_ARG,
1733
   0, 0, 0, 0, 0, 0},
973.1.1 by Toru Maesaka
Added server shutdown and ping functionalities to the drizzle client app
1734
  {"ping", OPT_PING, N_("Ping the server to check if it's alive."),
1441.3.1 by Vijay Samuel
all required updations have been made
1735
   (char**) &opt_ping, (char**) &opt_ping, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
971.8.4 by Eric Day
Added --mysql option flags to client utilities. Also removed the socket option since that is no used anymoe (requested from mailing list).
1736
  {"mysql", 'm', N_("Use MySQL Protocol."),
1441.3.1 by Vijay Samuel
all required updations have been made
1737
   (char**) &opt_mysql, (char**) &opt_mysql, 0, GET_BOOL, NO_ARG, 1, 0, 0,
1738
   0, 0, 0},
1 by brian
clean slate
1739
  { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
1740
};
1741
1742
1743
static void usage(int version)
1744
{
1745
  const char* readline= "readline";
1746
1081.1.1 by Monty Taylor
Whole boat-load of build fixes.
1747
  printf(_("%s  Ver %s Distrib %s, for %s-%s (%s) using %s %s\n"),
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1748
         internal::my_progname, VER.c_str(), drizzle_version(),
1081.1.1 by Monty Taylor
Whole boat-load of build fixes.
1749
         HOST_VENDOR, HOST_OS, HOST_CPU,
1 by brian
clean slate
1750
         readline, rl_library_version);
1751
1752
  if (version)
1753
    return;
520.4.28 by Monty Taylor
Changed my.cnf to drizzle.cnf and /etc/mysql to /etc/drizzle.
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"));
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1759
  printf(_("Usage: %s [OPTIONS] [database]\n"), internal::my_progname);
1 by brian
clean slate
1760
  my_print_help(my_long_options);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1761
  internal::print_defaults("drizzle", load_default_groups);
1 by brian
clean slate
1762
  my_print_variables(my_long_options);
1763
}
1764
1765
1410.3.4 by Djellel E. Difallah
update references to old my_'s
1766
static int get_one_option(int optid, const struct option *, char *argument)
1 by brian
clean slate
1767
{
673.5.6 by Andrew Hutchings
Fix long to uint32_t type casting problem
1768
  char *endchar= NULL;
1769
  uint64_t temp_drizzle_port= 0;
673.5.1 by Andrew Hutchings
Minor coding standards cleanup
1770
1 by brian
clean slate
1771
  switch(optid) {
1772
  case  OPT_DEFAULT_CHARSET:
1773
    default_charset_used= 1;
1774
    break;
1775
  case OPT_DELIMITER:
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
1776
    if (argument == disabled_my_option)
1 by brian
clean slate
1777
    {
641.4.1 by Toru Maesaka
First pass of replacing MySQL's my_stpcpy() with appropriate libc calls
1778
      strcpy(delimiter, DEFAULT_DELIMITER);
1 by brian
clean slate
1779
    }
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
1780
    else
1 by brian
clean slate
1781
    {
1782
      /* Check that delimiter does not contain a backslash */
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
1783
      if (!strstr(argument, "\\"))
1 by brian
clean slate
1784
      {
629.5.1 by Toru Maesaka
First pass of replacing MySQL's strmake() with libc calls
1785
        strncpy(delimiter, argument, sizeof(delimiter) - 1);
1 by brian
clean slate
1786
      }
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
1787
      else
1 by brian
clean slate
1788
      {
202.3.13 by Monty Taylor
Changed gettext() to _() in drizzle.c.
1789
        put_info(_("DELIMITER cannot contain a backslash character"),
77.3.7 by Monty Taylor
Made mysql into a pure-C program.
1790
                 INFO_ERROR,0,0);
1441.3.1 by Vijay Samuel
all required updations have been made
1791
        return false;
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
1792
      }
1 by brian
clean slate
1793
    }
895 by Brian Aker
Completion (?) of uint conversion.
1794
    delimiter_length= (uint32_t)strlen(delimiter);
1 by brian
clean slate
1795
    delimiter_str= delimiter;
1796
    break;
1797
  case OPT_TEE:
1798
    if (argument == disabled_my_option)
1799
    {
1800
      if (opt_outfile)
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
1801
        end_tee();
1 by brian
clean slate
1802
    }
1803
    else
1804
      init_tee(argument);
1805
    break;
1806
  case OPT_NOTEE:
202.3.13 by Monty Taylor
Changed gettext() to _() in drizzle.c.
1807
    printf(_("WARNING: option deprecated; use --disable-tee instead.\n"));
1 by brian
clean slate
1808
    if (opt_outfile)
1809
      end_tee();
1810
    break;
1811
  case OPT_PAGER:
1812
    if (argument == disabled_my_option)
1813
      opt_nopager= 1;
1814
    else
1815
    {
1816
      opt_nopager= 0;
1817
      if (argument && strlen(argument))
1818
      {
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
1819
        default_pager_set= 1;
629.5.1 by Toru Maesaka
First pass of replacing MySQL's strmake() with libc calls
1820
        strncpy(pager, argument, sizeof(pager) - 1);
641.4.1 by Toru Maesaka
First pass of replacing MySQL's my_stpcpy() with appropriate libc calls
1821
        strcpy(default_pager, pager);
1 by brian
clean slate
1822
      }
1823
      else if (default_pager_set)
641.4.1 by Toru Maesaka
First pass of replacing MySQL's my_stpcpy() with appropriate libc calls
1824
        strcpy(pager, default_pager);
1 by brian
clean slate
1825
      else
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
1826
        opt_nopager= 1;
1 by brian
clean slate
1827
    }
1828
    break;
1829
  case OPT_NOPAGER:
202.3.13 by Monty Taylor
Changed gettext() to _() in drizzle.c.
1830
    printf(_("WARNING: option deprecated; use --disable-pager instead.\n"));
1 by brian
clean slate
1831
    opt_nopager= 1;
1832
    break;
1833
  case OPT_SERVER_ARG:
261.3.6 by Monty Taylor
Added msg that was missed in drizzle.c
1834
    printf(_("WARNING: --server-arg option not supported in this configuration.\n"));
1 by brian
clean slate
1835
    break;
1836
  case 'A':
1837
    opt_rehash= 0;
1838
    break;
1839
  case 'N':
1840
    column_names= 0;
1841
    break;
1842
  case 'e':
1441.3.1 by Vijay Samuel
all required updations have been made
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)
1095.2.1 by Robert Klahn
Replace typedef struct LINE_BUFFER with class LineBuffer, encapsulating current logic
1848
    {
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1849
      internal::my_end();
1095.2.1 by Robert Klahn
Replace typedef struct LINE_BUFFER with class LineBuffer, encapsulating current logic
1850
      exit(1);
1851
    }
1441.3.1 by Vijay Samuel
all required updations have been made
1852
    status.getLineBuff()->addString(argument);
1 by brian
clean slate
1853
    break;
1854
  case 'o':
1855
    if (argument == disabled_my_option)
1856
      one_database= 0;
1857
    else
1858
      one_database= skip_updates= 1;
1859
    break;
1860
  case 'p':
673.5.6 by Andrew Hutchings
Fix long to uint32_t type casting problem
1861
    temp_drizzle_port= (uint64_t) strtoul(argument, &endchar, 10);
673.5.2 by Andrew Hutchings
Code cleanups
1862
    /* if there is an alpha character this is not a valid port */
1863
    if (strlen(endchar) != 0)
1864
    {
673.5.1 by Andrew Hutchings
Minor coding standards cleanup
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);
1441.3.1 by Vijay Samuel
all required updations have been made
1866
      return false;
673.5.1 by Andrew Hutchings
Minor coding standards cleanup
1867
    }
673.5.6 by Andrew Hutchings
Fix long to uint32_t type casting problem
1868
    /* If the port number is > 65535 it is not a valid port
1441.3.1 by Vijay Samuel
all required updations have been made
1869
       This also helps with potential data loss casting unsigned long to a
1870
       uint32_t. */
673.5.8 by Andrew Hutchings
Fail is user gives port 0 as well
1871
    if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
673.5.6 by Andrew Hutchings
Fix long to uint32_t type casting problem
1872
    {
1873
      put_info(_("Value supplied for port is not valid."), INFO_ERROR, 0, 0);
1441.3.1 by Vijay Samuel
all required updations have been made
1874
      return false;
673.5.6 by Andrew Hutchings
Fix long to uint32_t type casting problem
1875
    }
1876
    else
1877
    {
1878
      opt_drizzle_port= (uint32_t) temp_drizzle_port;
1879
    }
673.5.1 by Andrew Hutchings
Minor coding standards cleanup
1880
    break;
1881
  case 'P':
673.5.2 by Andrew Hutchings
Code cleanups
1882
    /* Don't require password */
1 by brian
clean slate
1883
    if (argument == disabled_my_option)
673.5.2 by Andrew Hutchings
Code cleanups
1884
    {
1885
      argument= (char*) "";
1886
    }
1 by brian
clean slate
1887
    if (argument)
1888
    {
1889
      char *start= argument;
477 by Monty Taylor
Removed my_free(). It turns out that it had been def'd to ignore the flags passed to it in the second arg anyway. Gotta love that.
1890
      free(opt_password);
182.1.2 by Jim Winstead
Various fixes to enable compilation on Mac OS X, and remove the glib dependency.
1891
      opt_password= strdup(argument);
673.5.2 by Andrew Hutchings
Code cleanups
1892
      while (*argument)
1893
      {
1894
        /* Overwriting password with 'x' */
1895
        *argument++= 'x';
1896
      }
1 by brian
clean slate
1897
      if (*start)
673.5.2 by Andrew Hutchings
Code cleanups
1898
      {
1899
        start[1]= 0;
1900
      }
1 by brian
clean slate
1901
      tty_password= 0;
1902
    }
1903
    else
673.5.2 by Andrew Hutchings
Code cleanups
1904
    {
1 by brian
clean slate
1905
      tty_password= 1;
673.5.2 by Andrew Hutchings
Code cleanups
1906
    }
1 by brian
clean slate
1907
    break;
1908
  case 's':
1909
    if (argument == disabled_my_option)
1910
      opt_silent= 0;
1911
    else
1912
      opt_silent++;
1913
    break;
1914
  case 'v':
1915
    if (argument == disabled_my_option)
1916
      verbose= 0;
1917
    else
1918
      verbose++;
1919
    break;
1920
  case 'B':
1441.3.1 by Vijay Samuel
all required updations have been made
1921
    status.setBatch(1);
1922
    status.setAddToHistory(0);
1 by brian
clean slate
1923
    set_if_bigger(opt_silent,1);                         // more silent
1924
    break;
1925
  case 'V':
1926
    usage(1);
1927
    exit(0);
1928
  case 'I':
1929
  case '?':
1930
    usage(0);
1931
    exit(0);
1932
  }
1933
  return 0;
1934
}
1935
1936
1937
static int get_options(int argc, char **argv)
1938
{
1939
  char *tmp, *pagpoint;
1940
  int ho_error;
1941
266.2.3 by Jim Winstead
Use DRIZZLE_* environment variables instead of MYSQL_*
1942
  tmp= (char *) getenv("DRIZZLE_HOST");
1 by brian
clean slate
1943
  if (tmp)
77.3.3 by Monty Taylor
Last change to migrate to glib from sql_string.
1944
    current_host= strdup(tmp);
1 by brian
clean slate
1945
1946
  pagpoint= getenv("PAGER");
1947
  if (!((char*) (pagpoint)))
1948
  {
641.4.1 by Toru Maesaka
First pass of replacing MySQL's my_stpcpy() with appropriate libc calls
1949
    strcpy(pager, "stdout");
1 by brian
clean slate
1950
    opt_nopager= 1;
1951
  }
1952
  else
641.4.1 by Toru Maesaka
First pass of replacing MySQL's my_stpcpy() with appropriate libc calls
1953
    strcpy(pager, pagpoint);
1954
  strcpy(default_pager, pager);
1 by brian
clean slate
1955
1956
  if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
1957
    exit(ho_error);
1958
1441.3.1 by Vijay Samuel
all required updations have been made
1959
  if (status.getBatch()) /* disable pager and outfile in this case */
1 by brian
clean slate
1960
  {
641.4.1 by Toru Maesaka
First pass of replacing MySQL's my_stpcpy() with appropriate libc calls
1961
    strcpy(default_pager, "stdout");
1962
    strcpy(pager, "stdout");
1 by brian
clean slate
1963
    opt_nopager= 1;
1964
    default_pager_set= 0;
1965
    opt_outfile= 0;
1966
    opt_reconnect= 0;
928.1.1 by Eric Day
Started client changes.
1967
    connect_flag= DRIZZLE_CAPABILITIES_NONE; /* Not in interactive mode */
1 by brian
clean slate
1968
  }
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
1969
1 by brian
clean slate
1970
  if (argc > 1)
1971
  {
1972
    usage(0);
1973
    exit(1);
1974
  }
1975
  if (argc == 1)
1976
  {
1977
    skip_updates= 0;
477 by Monty Taylor
Removed my_free(). It turns out that it had been def'd to ignore the flags passed to it in the second arg anyway. Gotta love that.
1978
    free(current_db);
182.1.2 by Jim Winstead
Various fixes to enable compilation on Mac OS X, and remove the glib dependency.
1979
    current_db= strdup(*argv);
1 by brian
clean slate
1980
  }
1981
  if (tty_password)
928.1.1 by Eric Day
Started client changes.
1982
    opt_password= client_get_tty_password(NULL);
1235.3.13 by Stewart Smith
remove MY_GIVE_INFO parameter to my_end() that really just gave us the output of time(1). Use UNIX, don't re-implement the kitchen sink. This also removes --debug-info from most command line utilities.
1983
1 by brian
clean slate
1984
  return(0);
1985
}
1986
1987
static int read_and_execute(bool interactive)
1988
{
77.3.7 by Monty Taylor
Made mysql into a pure-C program.
1989
  char *line;
1990
  char in_string=0;
288 by Brian Aker
ulong cleanp in client apps
1991
  uint32_t line_number=0;
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
1992
  bool ml_comment= 0;
1441.3.1 by Vijay Samuel
all required updations have been made
1993
  Commands *com;
1994
  status.setExitStatus(1);
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
1995
1 by brian
clean slate
1996
  for (;;)
1997
  {
1998
    if (!interactive)
1999
    {
1441.3.1 by Vijay Samuel
all required updations have been made
2000
      if (status.getLineBuff())
2001
        line= status.getLineBuff()->readline();
1095.2.1 by Robert Klahn
Replace typedef struct LINE_BUFFER with class LineBuffer, encapsulating current logic
2002
      else
1095.2.4 by Robert Klahn
changes from code review feedback
2003
        line= 0;
1095.2.2 by Robert Klahn
convert logic to use std::stringstream for buffer
2004
1095.2.4 by Robert Klahn
changes from code review feedback
2005
      line_number++;
2006
      if (show_progress_size > 0)
670.1.4 by Monty Taylor
Imported patch from LinuxJedi to add import status messages.
2007
      {
1095.2.4 by Robert Klahn
changes from code review feedback
2008
        if ((line_number % show_progress_size) == 0)
2009
          fprintf(stderr, _("Processing line: %"PRIu32"\n"), line_number);
670.1.4 by Monty Taylor
Imported patch from LinuxJedi to add import status messages.
2010
      }
1095.2.4 by Robert Klahn
changes from code review feedback
2011
      if (!glob_buffer->empty())
1441.3.1 by Vijay Samuel
all required updations have been made
2012
        status.setQueryStartLine(line_number);
1 by brian
clean slate
2013
    }
2014
    else
2015
    {
266.7.7 by Andy Lester
const happiness
2016
      const char *prompt= (const char*) (ml_comment ? "   /*> " :
287.3.9 by Monty Taylor
Merged from use-replace-funcs.
2017
                                         (glob_buffer->empty())
2018
                                         ?  construct_prompt()
2019
                                         : !in_string ? "    -> " :
2020
                                         in_string == '\'' ?
2021
                                         "    '> " : (in_string == '`' ?
2022
                                                      "    `> " :
2023
                                                      "    \"> "));
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2024
      if (opt_outfile && glob_buffer->empty())
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
2025
        fflush(OUTFILE);
1 by brian
clean slate
2026
2027
      if (opt_outfile)
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
2028
        fputs(prompt, OUTFILE);
1 by brian
clean slate
2029
      line= readline(prompt);
2030
      /*
2031
        When Ctrl+d or Ctrl+z is pressed, the line may be NULL on some OS
2032
        which may cause coredump.
2033
      */
2034
      if (opt_outfile && line)
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2035
        fprintf(OUTFILE, "%s\n", line);
1 by brian
clean slate
2036
    }
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2037
    // End of file
2038
    if (!line)
1 by brian
clean slate
2039
    {
1441.3.1 by Vijay Samuel
all required updations have been made
2040
      status.setExitStatus(0);
1 by brian
clean slate
2041
      break;
2042
    }
2043
2044
    /*
206.3.1 by Patrick Galbraith
Most everything working with client rename
2045
      Check if line is a drizzle command line
1 by brian
clean slate
2046
      (We want to allow help, print and clear anywhere at line start
2047
    */
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2048
    if ((named_cmds || (glob_buffer->empty()))
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2049
        && !ml_comment && !in_string && (com=find_command(line,0)))
1 by brian
clean slate
2050
    {
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2051
      if ((*com->func)(glob_buffer,line) > 0)
2052
        break;
2053
      // If buffer was emptied
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2054
      if (glob_buffer->empty())
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2055
        in_string=0;
1441.3.1 by Vijay Samuel
all required updations have been made
2056
      if (interactive && status.getAddToHistory() && not_in_history(line))
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2057
        add_history(line);
1 by brian
clean slate
2058
      continue;
2059
    }
77.3.4 by Monty Taylor
Removed debugging. Fixed multi-line processing error.
2060
    if (add_line(glob_buffer,line,&in_string,&ml_comment))
1 by brian
clean slate
2061
      break;
2062
  }
2063
  /* if in batch mode, send last query even if it doesn't end with \g or go */
2064
1441.3.1 by Vijay Samuel
all required updations have been made
2065
  if (!interactive && !status.getExitStatus())
1 by brian
clean slate
2066
  {
2067
    remove_cntrl(glob_buffer);
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2068
    if (!glob_buffer->empty())
1 by brian
clean slate
2069
    {
1441.3.1 by Vijay Samuel
all required updations have been made
2070
      status.setExitStatus(1);
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2071
      if (com_go(glob_buffer,line) <= 0)
1441.3.1 by Vijay Samuel
all required updations have been made
2072
        status.setExitStatus(0);
1 by brian
clean slate
2073
    }
2074
  }
2075
1441.3.1 by Vijay Samuel
all required updations have been made
2076
  return status.getExitStatus();
1 by brian
clean slate
2077
}
2078
2079
1441.3.1 by Vijay Samuel
all required updations have been made
2080
static Commands *find_command(const char *name,char cmd_char)
1 by brian
clean slate
2081
{
893 by Brian Aker
First pass of stripping uint
2082
  uint32_t len;
266.1.19 by Monty Taylor
Fixed const thing.
2083
  const char *end;
1 by brian
clean slate
2084
2085
  if (!name)
2086
  {
2087
    len=0;
2088
    end=0;
2089
  }
2090
  else
2091
  {
2092
    while (my_isspace(charset_info,*name))
2093
      name++;
2094
    /*
2095
      If there is an \\g in the row or if the row has a delimiter but
2096
      this is not a delimiter command, let add_line() take care of
2097
      parsing the row and calling find_command()
2098
    */
2099
    if (strstr(name, "\\g") || (strstr(name, delimiter) &&
2100
                                !(strlen(name) >= 9 &&
2101
                                  !my_strnncoll(charset_info,
481 by Brian Aker
Remove all of uchar.
2102
                                                (unsigned char*) name, 9,
2103
                                                (const unsigned char*) "delimiter",
1 by brian
clean slate
2104
                                                9))))
1441.3.3 by Vijay Samuel
Changes made to the struct conversion
2105
      return(NULL);
1 by brian
clean slate
2106
    if ((end=strcont(name," \t")))
2107
    {
895 by Brian Aker
Completion (?) of uint conversion.
2108
      len=(uint32_t) (end - name);
1 by brian
clean slate
2109
      while (my_isspace(charset_info,*end))
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
2110
        end++;
1 by brian
clean slate
2111
      if (!*end)
206.3.1 by Patrick Galbraith
Most everything working with client rename
2112
        end=0;          // no arguments to function
1 by brian
clean slate
2113
    }
2114
    else
895 by Brian Aker
Completion (?) of uint conversion.
2115
      len=(uint32_t) strlen(name);
1 by brian
clean slate
2116
  }
2117
1441.3.1 by Vijay Samuel
all required updations have been made
2118
  for (uint32_t i= 0; commands[i].getName(); i++)
1 by brian
clean slate
2119
  {
2120
    if (commands[i].func &&
1441.3.1 by Vijay Samuel
all required updations have been made
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)))
1 by brian
clean slate
2122
    {
142.1.2 by Patrick
All DBUG_x removed from client/
2123
      return(&commands[i]);
1 by brian
clean slate
2124
    }
2125
  }
1441.3.3 by Vijay Samuel
Changes made to the struct conversion
2126
  return(NULL);
1 by brian
clean slate
2127
}
2128
2129
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2130
static bool add_line(string *buffer, char *line, char *in_string,
1441.3.1 by Vijay Samuel
all required updations have been made
2131
                        bool *ml_comment)
1 by brian
clean slate
2132
{
481 by Brian Aker
Remove all of uchar.
2133
  unsigned char inchar;
1126.4.1 by Monty Taylor
Fixed a buffer overrun that was causing some translated message output to suck.
2134
  char *pos, *out;
1441.3.1 by Vijay Samuel
all required updations have been made
2135
  Commands *com;
1 by brian
clean slate
2136
  bool need_space= 0;
2137
  bool ss_comment= 0;
142.1.2 by Patrick
All DBUG_x removed from client/
2138
1 by brian
clean slate
2139
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2140
  if (!line[0] && (buffer->empty()))
142.1.2 by Patrick
All DBUG_x removed from client/
2141
    return(0);
1441.3.1 by Vijay Samuel
all required updations have been made
2142
  if (status.getAddToHistory() && line[0] && not_in_history(line))
1 by brian
clean slate
2143
    add_history(line);
895 by Brian Aker
Completion (?) of uint conversion.
2144
  char *end_of_line=line+(uint32_t) strlen(line);
1 by brian
clean slate
2145
481 by Brian Aker
Remove all of uchar.
2146
  for (pos=out=line ; (inchar= (unsigned char) *pos) ; pos++)
1 by brian
clean slate
2147
  {
2148
    if (!preserve_comments)
2149
    {
2150
      // Skip spaces at the beggining of a statement
2151
      if (my_isspace(charset_info,inchar) && (out == line) &&
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2152
          (buffer->empty()))
1 by brian
clean slate
2153
        continue;
2154
    }
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2155
1 by brian
clean slate
2156
    // Accept multi-byte characters as-is
2157
    int length;
2158
    if (use_mb(charset_info) &&
2159
        (length= my_ismbchar(charset_info, pos, end_of_line)))
2160
    {
2161
      if (!*ml_comment || preserve_comments)
2162
      {
2163
        while (length--)
2164
          *out++ = *pos++;
2165
        pos--;
2166
      }
2167
      else
2168
        pos+= length - 1;
2169
      continue;
2170
    }
1085.3.3 by Monty Taylor
Got rid of #ifdef have utf8 stuff.
2171
    if (!*ml_comment && inchar == '\\' &&
2172
        !(*in_string && (drizzle_con_status(&con) & DRIZZLE_CON_STATUS_NO_BACKSLASH_ESCAPES)))
1 by brian
clean slate
2173
    {
2174
      // Found possbile one character command like \c
2175
481 by Brian Aker
Remove all of uchar.
2176
      if (!(inchar = (unsigned char) *++pos))
206.3.1 by Patrick Galbraith
Most everything working with client rename
2177
        break;        // readline adds one '\'
2178
      if (*in_string || inchar == 'N')  // \N is short for NULL
2179
      {          // Don't allow commands in string
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2180
        *out++='\\';
2181
        *out++= (char) inchar;
2182
        continue;
1 by brian
clean slate
2183
      }
461 by Monty Taylor
Removed NullS. bu-bye.
2184
      if ((com=find_command(NULL,(char) inchar)))
1 by brian
clean slate
2185
      {
2186
        // Flush previously accepted characters
2187
        if (out != line)
2188
        {
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2189
          buffer->append(line, (out-line));
1 by brian
clean slate
2190
          out= line;
2191
        }
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2192
2193
        if ((*com->func)(buffer,pos-1) > 0)
142.1.2 by Patrick
All DBUG_x removed from client/
2194
          return(1);                       // Quit
1441.3.1 by Vijay Samuel
all required updations have been made
2195
        if (com->getTakesParams())
1 by brian
clean slate
2196
        {
2197
          if (ss_comment)
2198
          {
2199
            /*
2200
              If a client-side macro appears inside a server-side comment,
2201
              discard all characters in the comment after the macro (that is,
2202
              until the end of the comment rather than the next delimiter)
2203
            */
2204
            for (pos++; *pos && (*pos != '*' || *(pos + 1) != '/'); pos++)
2205
              ;
2206
            pos--;
2207
          }
2208
          else
2209
          {
2210
            for (pos++ ;
2211
                 *pos && (*pos != *delimiter ||
971.1.77 by Monty Taylor
Removed mysys/mystrings things from client/ progs. Still need to get rid of my_getopt, but I think that's all now.
2212
                          strncmp(pos + 1, delimiter + 1,
2213
                                  strlen(delimiter + 1))) ; pos++)
206.3.1 by Patrick Galbraith
Most everything working with client rename
2214
              ;  // Remove parameters
1 by brian
clean slate
2215
            if (!*pos)
2216
              pos--;
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
2217
            else
1 by brian
clean slate
2218
              pos+= delimiter_length - 1; // Point at last delim char
2219
          }
2220
        }
2221
      }
2222
      else
2223
      {
1126.4.1 by Monty Taylor
Fixed a buffer overrun that was causing some translated message output to suck.
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)
77.4.1 by Monty Taylor
Merged from trunk.
2230
          return(1);
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
2231
        *out++='\\';
2232
        *out++=(char) inchar;
2233
        continue;
1 by brian
clean slate
2234
      }
2235
    }
2236
    else if (!*ml_comment && !*in_string &&
2237
             (end_of_line - pos) >= 10 &&
481 by Brian Aker
Remove all of uchar.
2238
             !my_strnncoll(charset_info, (unsigned char*) pos, 10,
2239
                           (const unsigned char*) "delimiter ", 10))
1 by brian
clean slate
2240
    {
2241
      // Flush previously accepted characters
2242
      if (out != line)
2243
      {
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2244
        buffer->append(line, (out - line));
1 by brian
clean slate
2245
        out= line;
2246
      }
2247
2248
      // Flush possible comments in the buffer
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2249
      if (!buffer->empty())
1 by brian
clean slate
2250
      {
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2251
        if (com_go(buffer, 0) > 0) // < 0 is not fatal
142.1.2 by Patrick
All DBUG_x removed from client/
2252
          return(1);
77.3.3 by Monty Taylor
Last change to migrate to glib from sql_string.
2253
        assert(buffer!=NULL);
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2254
        buffer->clear();
1 by brian
clean slate
2255
      }
2256
2257
      /*
2258
        Delimiter wants the get rest of the given line as argument to
2259
        allow one to change ';' to ';;' and back
2260
      */
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2261
      buffer->append(pos);
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2262
      if (com_delimiter(buffer, pos) > 0)
142.1.2 by Patrick
All DBUG_x removed from client/
2263
        return(1);
1 by brian
clean slate
2264
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2265
      buffer->clear();
1 by brian
clean slate
2266
      break;
2267
    }
971.1.77 by Monty Taylor
Removed mysys/mystrings things from client/ progs. Still need to get rid of my_getopt, but I think that's all now.
2268
    else if (!*ml_comment && !*in_string && !strncmp(pos, delimiter,
2269
                                                     strlen(delimiter)))
1 by brian
clean slate
2270
    {
2271
      // Found a statement. Continue parsing after the delimiter
2272
      pos+= delimiter_length;
2273
2274
      if (preserve_comments)
2275
      {
2276
        while (my_isspace(charset_info, *pos))
2277
          *out++= *pos++;
2278
      }
2279
      // Flush previously accepted characters
2280
      if (out != line)
2281
      {
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2282
        buffer->append(line, (out-line));
1 by brian
clean slate
2283
        out= line;
2284
      }
2285
2286
      if (preserve_comments && ((*pos == '#') ||
2287
                                ((*pos == '-') &&
2288
                                 (pos[1] == '-') &&
2289
                                 my_isspace(charset_info, pos[2]))))
2290
      {
2291
        // Add trailing single line comments to this statement
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2292
        buffer->append(pos);
1 by brian
clean slate
2293
        pos+= strlen(pos);
2294
      }
2295
2296
      pos--;
2297
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2298
      if ((com= find_command(buffer->c_str(), 0)))
1 by brian
clean slate
2299
      {
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
2300
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2301
        if ((*com->func)(buffer, buffer->c_str()) > 0)
77.4.1 by Monty Taylor
Merged from trunk.
2302
          return(1);                       // Quit
1 by brian
clean slate
2303
      }
2304
      else
2305
      {
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2306
        if (com_go(buffer, 0) > 0)             // < 0 is not fatal
142.1.2 by Patrick
All DBUG_x removed from client/
2307
          return(1);
1 by brian
clean slate
2308
      }
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2309
      buffer->clear();
1 by brian
clean slate
2310
    }
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2311
    else if (!*ml_comment
2312
             && (!*in_string
2313
                 && (inchar == '#'
2314
                     || (inchar == '-'
2315
                         && pos[1] == '-'
2316
                         && my_isspace(charset_info,pos[2])))))
1 by brian
clean slate
2317
    {
2318
      // Flush previously accepted characters
2319
      if (out != line)
2320
      {
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2321
        buffer->append(line, (out - line));
1 by brian
clean slate
2322
        out= line;
2323
      }
2324
2325
      // comment to end of line
2326
      if (preserve_comments)
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2327
        buffer->append(pos);
1 by brian
clean slate
2328
2329
      break;
2330
    }
2331
    else if (!*in_string && inchar == '/' && *(pos+1) == '*' &&
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2332
             *(pos+2) != '!')
1 by brian
clean slate
2333
    {
2334
      if (preserve_comments)
2335
      {
2336
        *out++= *pos++;                       // copy '/'
2337
        *out++= *pos;                         // copy '*'
2338
      }
2339
      else
2340
        pos++;
2341
      *ml_comment= 1;
2342
      if (out != line)
2343
      {
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2344
        buffer->append(line, (out-line));
1 by brian
clean slate
2345
        out=line;
2346
      }
2347
    }
2348
    else if (*ml_comment && !ss_comment && inchar == '*' && *(pos + 1) == '/')
2349
    {
2350
      if (preserve_comments)
2351
      {
2352
        *out++= *pos++;                       // copy '*'
2353
        *out++= *pos;                         // copy '/'
2354
      }
2355
      else
2356
        pos++;
2357
      *ml_comment= 0;
2358
      if (out != line)
2359
      {
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2360
        buffer->append(line, (out - line));
1 by brian
clean slate
2361
        out= line;
2362
      }
2363
      // Consumed a 2 chars or more, and will add 1 at most,
2364
      // so using the 'line' buffer to edit data in place is ok.
2365
      need_space= 1;
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2366
    }
1 by brian
clean slate
2367
    else
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2368
    {
2369
      // Add found char to buffer
1 by brian
clean slate
2370
      if (!*in_string && inchar == '/' && *(pos + 1) == '*' &&
2371
          *(pos + 2) == '!')
2372
        ss_comment= 1;
2373
      else if (!*in_string && ss_comment && inchar == '*' && *(pos + 1) == '/')
2374
        ss_comment= 0;
2375
      if (inchar == *in_string)
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2376
        *in_string= 0;
1 by brian
clean slate
2377
      else if (!*ml_comment && !*in_string &&
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2378
               (inchar == '\'' || inchar == '"' || inchar == '`'))
2379
        *in_string= (char) inchar;
1 by brian
clean slate
2380
      if (!*ml_comment || preserve_comments)
2381
      {
2382
        if (need_space && !my_isspace(charset_info, (char)inchar))
2383
          *out++= ' ';
2384
        need_space= 0;
2385
        *out++= (char) inchar;
2386
      }
2387
    }
2388
  }
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2389
  if (out != line || (buffer->length() > 0))
1 by brian
clean slate
2390
  {
2391
    *out++='\n';
895 by Brian Aker
Completion (?) of uint conversion.
2392
    uint32_t length=(uint32_t) (out-line);
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2393
    if ((!*ml_comment || preserve_comments))
2394
      buffer->append(line, length);
1 by brian
clean slate
2395
  }
142.1.2 by Patrick
All DBUG_x removed from client/
2396
  return(0);
1 by brian
clean slate
2397
}
2398
2399
/*****************************************************************
1441.3.1 by Vijay Samuel
all required updations have been made
2400
            Interface to Readline Completion
2401
******************************************************************/
1 by brian
clean slate
2402
2403
182.1.6 by Jim Winstead
Fix declaration of no_completion, drop 'new_' prefix from a function to make
2404
static char **mysql_completion (const char *text, int start, int end);
520.4.43 by mordred
A set of Solaris fixes.
2405
extern "C" char *new_command_generator(const char *text, int);
182.1.6 by Jim Winstead
Fix declaration of no_completion, drop 'new_' prefix from a function to make
2406
1 by brian
clean slate
2407
/*
2408
  Tell the GNU Readline library how to complete.  We want to try to complete
2409
  on command names if this is the first word in the line, or on filenames
2410
  if not.
2411
*/
632.1.12 by Monty Taylor
Fixed more sun studio warnings.
2412
static char *no_completion(const char *, int)
1 by brian
clean slate
2413
{
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2414
  /* No filename completion */
2415
  return 0;
1 by brian
clean slate
2416
}
182.1.6 by Jim Winstead
Fix declaration of no_completion, drop 'new_' prefix from a function to make
2417
1 by brian
clean slate
2418
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2419
/* glues pieces of history back together if in pieces   */
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2420
static void fix_history(string *final_command)
1 by brian
clean slate
2421
{
2422
  int total_lines = 1;
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2423
  const char *ptr = final_command->c_str();
182.1.2 by Jim Winstead
Various fixes to enable compilation on Mac OS X, and remove the glib dependency.
2424
  char str_char = '\0';  /* Character if we are in a string or not */
2425
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2426
  /* Converted buffer */
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2427
  string fixed_buffer;
287.3.19 by Monty Taylor
Added string.reserve() calls.
2428
  fixed_buffer.reserve(512);
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2429
1 by brian
clean slate
2430
  /* find out how many lines we have and remove newlines */
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2431
  while (*ptr != '\0')
1 by brian
clean slate
2432
  {
2433
    switch (*ptr) {
2434
      /* string character */
2435
    case '"':
2436
    case '\'':
2437
    case '`':
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2438
      // open string
2439
      if (str_char == '\0')
2440
        str_char = *ptr;
1 by brian
clean slate
2441
      else if (str_char == *ptr)   /* close string */
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2442
        str_char = '\0';
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2443
      fixed_buffer.append(ptr, 1);
1 by brian
clean slate
2444
      break;
2445
    case '\n':
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2446
      /*
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
2447
        not in string, change to space
2448
        if in string, leave it alone
1 by brian
clean slate
2449
      */
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2450
      fixed_buffer.append((str_char == '\0') ? " " : "\n");
1 by brian
clean slate
2451
      total_lines++;
2452
      break;
2453
    case '\\':
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2454
      fixed_buffer.append("\\");
1 by brian
clean slate
2455
      /* need to see if the backslash is escaping anything */
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2456
      if (str_char)
1 by brian
clean slate
2457
      {
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2458
        ptr++;
2459
        /* special characters that need escaping */
2460
        if (*ptr == '\'' || *ptr == '"' || *ptr == '\\')
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2461
          fixed_buffer.append(ptr, 1);
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2462
        else
2463
          ptr--;
1 by brian
clean slate
2464
      }
2465
      break;
2466
    default:
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2467
      fixed_buffer.append(ptr, 1);
1 by brian
clean slate
2468
    }
2469
    ptr++;
2470
  }
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2471
  if (total_lines > 1)
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2472
    add_history(fixed_buffer.c_str());
1 by brian
clean slate
2473
}
2474
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2475
/*
1 by brian
clean slate
2476
  returns 0 if line matches the previous history entry
2477
  returns 1 if the line doesn't match the previous history entry
2478
*/
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2479
static int not_in_history(const char *line)
1 by brian
clean slate
2480
{
2481
  HIST_ENTRY *oldhist = history_get(history_length);
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2482
1 by brian
clean slate
2483
  if (oldhist == 0)
2484
    return 1;
2485
  if (strcmp(oldhist->line,line) == 0)
2486
    return 0;
2487
  return 1;
2488
}
2489
319 by Brian Aker
Fix (yuck!) for OSX/Google bug.
2490
static void initialize_readline (char *name)
1 by brian
clean slate
2491
{
2492
  /* Allow conditional parsing of the ~/.inputrc file. */
319 by Brian Aker
Fix (yuck!) for OSX/Google bug.
2493
  rl_readline_name= name;
1 by brian
clean slate
2494
2495
  /* Tell the completer that we want a crack first. */
236.1.15 by Monty Taylor
Fixed the previous merge. (since I suck)
2496
  rl_attempted_completion_function= (rl_completion_func_t*)&mysql_completion;
1149.2.1 by Monty Taylor
Workaround for half-present new-interface on Snow Leopard, combined
2497
  rl_completion_entry_function= (drizzle_compentry_func_t*)&no_completion;
1 by brian
clean slate
2498
}
2499
182.1.6 by Jim Winstead
Fix declaration of no_completion, drop 'new_' prefix from a function to make
2500
1 by brian
clean slate
2501
/*
2502
  Attempt to complete on the contents of TEXT.  START and END show the
2503
  region of TEXT that contains the word to complete.  We can use the
2504
  entire line in case we want to do some simple parsing.  Return the
2505
  array of matches, or NULL if there aren't any.
2506
*/
632.1.12 by Monty Taylor
Fixed more sun studio warnings.
2507
char **mysql_completion (const char *text, int, int)
1 by brian
clean slate
2508
{
1441.3.1 by Vijay Samuel
all required updations have been made
2509
  if (!status.getBatch() && !quick)
1 by brian
clean slate
2510
    return rl_completion_matches(text, new_command_generator);
2511
  else
2512
    return (char**) 0;
2513
}
2514
923.2.6 by Monty Taylor
Removing hand-done completion hash functions.
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
}
923.2.7 by Monty Taylor
Finished replacing custom HashMap with std::map. We use a map and not a set
2522
inline string lower_string(const char * from_string)
2523
{
2524
  string to_string= from_string;
2525
  return lower_string(to_string);
2526
}
923.2.6 by Monty Taylor
Removing hand-done completion hash functions.
2527
923.2.7 by Monty Taylor
Finished replacing custom HashMap with std::map. We use a map and not a set
2528
template <class T>
923.2.6 by Monty Taylor
Removing hand-done completion hash functions.
2529
class CompletionMatch :
2530
  public unary_function<const string&, bool>
2531
{
2532
  string match_text; 
923.2.7 by Monty Taylor
Finished replacing custom HashMap with std::map. We use a map and not a set
2533
  T match_func;
923.2.6 by Monty Taylor
Removing hand-done completion hash functions.
2534
public:
923.2.7 by Monty Taylor
Finished replacing custom HashMap with std::map. We use a map and not a set
2535
  CompletionMatch(string text) : match_text(text) {}
923.2.6 by Monty Taylor
Removing hand-done completion hash functions.
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()));
923.2.7 by Monty Taylor
Finished replacing custom HashMap with std::map. We use a map and not a set
2540
    return match_func(sub_match,match_text);
923.2.6 by Monty Taylor
Removing hand-done completion hash functions.
2541
  }
2542
};
2543
2544
2545
520.4.43 by mordred
A set of Solaris fixes.
2546
extern "C"
923.2.6 by Monty Taylor
Removing hand-done completion hash functions.
2547
char *new_command_generator(const char *text, int state)
1 by brian
clean slate
2548
{
2549
2550
  if (!state)
923.2.6 by Monty Taylor
Removing hand-done completion hash functions.
2551
  {
923.2.7 by Monty Taylor
Finished replacing custom HashMap with std::map. We use a map and not a set
2552
    completion_string= lower_string(text);
2553
    if (completion_string.size() == 0)
923.2.6 by Monty Taylor
Removing hand-done completion hash functions.
2554
    {
2555
      completion_iter= completion_map.begin();
923.2.7 by Monty Taylor
Finished replacing custom HashMap with std::map. We use a map and not a set
2556
      completion_end= completion_map.end();
923.2.6 by Monty Taylor
Removing hand-done completion hash functions.
2557
    }
2558
    else
923.2.7 by Monty Taylor
Finished replacing custom HashMap with std::map. We use a map and not a set
2559
    {
923.2.6 by Monty Taylor
Removing hand-done completion hash functions.
2560
      completion_iter= find_if(completion_map.begin(), completion_map.end(),
923.2.7 by Monty Taylor
Finished replacing custom HashMap with std::map. We use a map and not a set
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
    }
923.2.6 by Monty Taylor
Removing hand-done completion hash functions.
2565
  }
923.2.7 by Monty Taylor
Finished replacing custom HashMap with std::map. We use a map and not a set
2566
  if (completion_iter == completion_end || (size_t)state > completion_map.size())
923.2.6 by Monty Taylor
Removing hand-done completion hash functions.
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;
1 by brian
clean slate
2572
}
2573
2574
/* Build up the completion hash */
2575
2576
static void build_completion_hash(bool rehash, bool write_info)
2577
{
1441.3.1 by Vijay Samuel
all required updations have been made
2578
  Commands *cmd=commands;
928.1.1 by Eric Day
Started client changes.
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;
923.2.6 by Monty Taylor
Removing hand-done completion hash functions.
2583
  string tmp_str, tmp_str_lower;
142.1.2 by Patrick
All DBUG_x removed from client/
2584
1441.3.1 by Vijay Samuel
all required updations have been made
2585
  if (status.getBatch() || quick || !current_db)
206.3.1 by Patrick Galbraith
Most everything working with client rename
2586
    return;      // We don't need completion in batches
1 by brian
clean slate
2587
  if (!rehash)
142.1.2 by Patrick
All DBUG_x removed from client/
2588
    return;
1 by brian
clean slate
2589
923.2.6 by Monty Taylor
Removing hand-done completion hash functions.
2590
  completion_map.clear();
1 by brian
clean slate
2591
2592
  /* hash this file's known subset of SQL commands */
1441.3.1 by Vijay Samuel
all required updations have been made
2593
  while (cmd->getName()) {
2594
    tmp_str= cmd->getName();
923.2.6 by Monty Taylor
Removing hand-done completion hash functions.
2595
    tmp_str_lower= lower_string(tmp_str);
2596
    completion_map[tmp_str_lower]= tmp_str;
1 by brian
clean slate
2597
    cmd++;
2598
  }
2599
77.1.40 by Monty Taylor
More naming changes.
2600
  /* hash Drizzle functions (to be implemented) */
1 by brian
clean slate
2601
2602
  /* hash all database names */
928.1.4 by Eric Day
Fixed a few bugs, more progress on conversion.
2603
  if (drizzle_query_str(&con, &databases, "show databases", &ret) != NULL)
1 by brian
clean slate
2604
  {
928.1.4 by Eric Day
Fixed a few bugs, more progress on conversion.
2605
    if (ret == DRIZZLE_RETURN_OK)
1 by brian
clean slate
2606
    {
928.1.4 by Eric Day
Fixed a few bugs, more progress on conversion.
2607
      if (drizzle_result_buffer(&databases) != DRIZZLE_RETURN_OK)
2608
        put_info(drizzle_error(&drizzle),INFO_INFO,0,0);
2609
      else
1 by brian
clean slate
2610
      {
928.1.4 by Eric Day
Fixed a few bugs, more progress on conversion.
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
        }
1 by brian
clean slate
2617
      }
2618
    }
928.1.4 by Eric Day
Fixed a few bugs, more progress on conversion.
2619
2620
    drizzle_result_free(&databases);
1 by brian
clean slate
2621
  }
928.1.4 by Eric Day
Fixed a few bugs, more progress on conversion.
2622
1 by brian
clean slate
2623
  /* hash all table names */
928.1.4 by Eric Day
Fixed a few bugs, more progress on conversion.
2624
  if (drizzle_query_str(&con, &tables, "show tables", &ret) != NULL)
1 by brian
clean slate
2625
  {
928.1.4 by Eric Day
Fixed a few bugs, more progress on conversion.
2626
    if (ret != DRIZZLE_RETURN_OK)
2627
    {
2628
      drizzle_result_free(&tables);
2629
      return;
2630
    }
2631
928.1.1 by Eric Day
Started client changes.
2632
    if (drizzle_result_buffer(&tables) != DRIZZLE_RETURN_OK)
2633
      put_info(drizzle_error(&drizzle),INFO_INFO,0,0);
1 by brian
clean slate
2634
    else
2635
    {
928.1.1 by Eric Day
Started client changes.
2636
      if (drizzle_result_row_count(&tables) > 0 && !opt_silent && write_info)
1 by brian
clean slate
2637
      {
1491.5.1 by Monty Taylor
Removed bad spacing discovered while looking at translations.
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"));
1 by brian
clean slate
2643
      }
928.1.1 by Eric Day
Started client changes.
2644
      while ((table_row=drizzle_row_next(&tables)))
1 by brian
clean slate
2645
      {
928.1.4 by Eric Day
Fixed a few bugs, more progress on conversion.
2646
        tmp_str= table_row[0];
923.2.6 by Monty Taylor
Removing hand-done completion hash functions.
2647
        tmp_str_lower= lower_string(tmp_str);
2648
        completion_map[tmp_str_lower]= tmp_str;
1 by brian
clean slate
2649
      }
2650
    }
2651
  }
928.1.1 by Eric Day
Started client changes.
2652
  else
2653
    return;
1 by brian
clean slate
2654
2655
  /* hash all field names, both with the table prefix and without it */
928.1.1 by Eric Day
Started client changes.
2656
  if (drizzle_result_row_count(&tables) == 0)
928.1.4 by Eric Day
Fixed a few bugs, more progress on conversion.
2657
  {
2658
    drizzle_result_free(&tables);
142.1.2 by Patrick
All DBUG_x removed from client/
2659
    return;
928.1.4 by Eric Day
Fixed a few bugs, more progress on conversion.
2660
  }
928.1.1 by Eric Day
Started client changes.
2661
2662
  drizzle_row_seek(&tables, 0);
928.1.2 by Eric Day
Merged trunk.
2663
928.1.1 by Eric Day
Started client changes.
2664
  while ((table_row=drizzle_row_next(&tables)))
1 by brian
clean slate
2665
  {
923.1.7 by Brian Aker
Remove dead COM for Field lists.
2666
    string query;
2667
2668
    query.append("show fields in '");
928.1.4 by Eric Day
Fixed a few bugs, more progress on conversion.
2669
    query.append(table_row[0]);
923.1.7 by Brian Aker
Remove dead COM for Field lists.
2670
    query.append("'");
1441.3.1 by Vijay Samuel
all required updations have been made
2671
    
928.1.1 by Eric Day
Started client changes.
2672
    if (drizzle_query(&con, &fields, query.c_str(), query.length(),
928.1.4 by Eric Day
Fixed a few bugs, more progress on conversion.
2673
                      &ret) != NULL)
1 by brian
clean slate
2674
    {
928.1.4 by Eric Day
Fixed a few bugs, more progress on conversion.
2675
      if (ret == DRIZZLE_RETURN_OK &&
2676
          drizzle_result_buffer(&fields) == DRIZZLE_RETURN_OK)
1 by brian
clean slate
2677
      {
928.1.1 by Eric Day
Started client changes.
2678
        while ((sql_field=drizzle_column_next(&fields)))
923.1.7 by Brian Aker
Remove dead COM for Field lists.
2679
        {
928.1.4 by Eric Day
Fixed a few bugs, more progress on conversion.
2680
          tmp_str=table_row[0];
923.2.6 by Monty Taylor
Removing hand-done completion hash functions.
2681
          tmp_str.append(".");
928.1.2 by Eric Day
Merged trunk.
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;
923.1.7 by Brian Aker
Remove dead COM for Field lists.
2689
        }
2690
      }
928.1.4 by Eric Day
Fixed a few bugs, more progress on conversion.
2691
      drizzle_result_free(&fields);
1 by brian
clean slate
2692
    }
2693
  }
928.1.1 by Eric Day
Started client changes.
2694
  drizzle_result_free(&tables);
923.2.6 by Monty Taylor
Removing hand-done completion hash functions.
2695
  completion_iter= completion_map.begin();
1 by brian
clean slate
2696
}
2697
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
2698
/* for gnu readline */
1 by brian
clean slate
2699
2700
2701
static int reconnect(void)
2702
{
2703
  if (opt_reconnect)
2704
  {
202.3.13 by Monty Taylor
Changed gettext() to _() in drizzle.c.
2705
    put_info(_("No connection. Trying to reconnect..."),INFO_INFO,0,0);
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2706
    (void) com_connect((string *)0, 0);
1124.2.8 by Diego Medina
Fixes lp bug#432210
2707
    if (opt_rehash && connected)
1 by brian
clean slate
2708
      com_rehash(NULL, NULL);
2709
  }
1136 by Brian Aker
Merge for bug fixes.
2710
  if (! connected)
202.3.13 by Monty Taylor
Changed gettext() to _() in drizzle.c.
2711
    return put_info(_("Can't connect to the server\n"),INFO_ERROR,0,0);
1 by brian
clean slate
2712
  return 0;
2713
}
2714
77.3.7 by Monty Taylor
Made mysql into a pure-C program.
2715
static void get_current_db(void)
1 by brian
clean slate
2716
{
928.1.1 by Eric Day
Started client changes.
2717
  drizzle_return_t ret;
2718
  drizzle_result_st res;
1 by brian
clean slate
2719
477 by Monty Taylor
Removed my_free(). It turns out that it had been def'd to ignore the flags passed to it in the second arg anyway. Gotta love that.
2720
  free(current_db);
1 by brian
clean slate
2721
  current_db= NULL;
2722
  /* In case of error below current_db will be NULL */
928.1.4 by Eric Day
Fixed a few bugs, more progress on conversion.
2723
  if (drizzle_query_str(&con, &res, "SELECT DATABASE()", &ret) != NULL)
1 by brian
clean slate
2724
  {
928.1.4 by Eric Day
Fixed a few bugs, more progress on conversion.
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]);
1124.2.9 by Diego Medina
Fixed a crash that came after fixing lp bug#432210 if you call use <db_name> twice on a
2731
      drizzle_result_free(&res);
928.1.4 by Eric Day
Fixed a few bugs, more progress on conversion.
2732
    }
1 by brian
clean slate
2733
  }
2734
}
2735
2736
/***************************************************************************
1441.3.1 by Vijay Samuel
all required updations have been made
2737
 The different commands
2738
***************************************************************************/
1 by brian
clean slate
2739
928.1.1 by Eric Day
Started client changes.
2740
int drizzleclient_real_query_for_lazy(const char *buf, int length,
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
2741
                                      drizzle_result_st *result,
2742
                                      uint32_t *error_code)
1 by brian
clean slate
2743
{
928.1.1 by Eric Day
Started client changes.
2744
  drizzle_return_t ret;
2745
893 by Brian Aker
First pass of stripping uint
2746
  for (uint32_t retry=0;; retry++)
1 by brian
clean slate
2747
  {
2748
    int error;
928.1.1 by Eric Day
Started client changes.
2749
    if (drizzle_query(&con,result,buf,length,&ret) != NULL &&
2750
        ret == DRIZZLE_RETURN_OK)
2751
    {
1 by brian
clean slate
2752
      return 0;
928.1.1 by Eric Day
Started client changes.
2753
    }
2754
    error= put_error(&con, result);
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
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 ||
1 by brian
clean slate
2763
        !opt_reconnect)
928.1.1 by Eric Day
Started client changes.
2764
    {
1 by brian
clean slate
2765
      return error;
928.1.1 by Eric Day
Started client changes.
2766
    }
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
2767
1 by brian
clean slate
2768
    if (reconnect())
2769
      return error;
2770
  }
2771
}
2772
928.1.1 by Eric Day
Started client changes.
2773
int drizzleclient_store_result_for_lazy(drizzle_result_st *result)
1 by brian
clean slate
2774
{
928.1.1 by Eric Day
Started client changes.
2775
  if (drizzle_result_buffer(result) == DRIZZLE_RETURN_OK)
1 by brian
clean slate
2776
    return 0;
2777
928.1.1 by Eric Day
Started client changes.
2778
  if (drizzle_con_error(&con)[0])
1441.3.1 by Vijay Samuel
all required updations have been made
2779
    return put_error(&con, result);
1 by brian
clean slate
2780
  return 0;
2781
}
2782
2783
static int
820.2.1 by Toru Maesaka
Killed dead code and removed a reference to a non-existent help option
2784
com_help(string *buffer, const char *)
1 by brian
clean slate
2785
{
2786
  register int i, j;
520.4.43 by mordred
A set of Solaris fixes.
2787
  char buff[32], *end;
1 by brian
clean slate
2788
202.3.13 by Monty Taylor
Changed gettext() to _() in drizzle.c.
2789
  put_info(_("List of all Drizzle commands:"), INFO_INFO,0,0);
1 by brian
clean slate
2790
  if (!named_cmds)
202.3.13 by Monty Taylor
Changed gettext() to _() in drizzle.c.
2791
    put_info(_("Note that all text commands must be first on line and end with ';'"),INFO_INFO,0,0);
1441.3.1 by Vijay Samuel
all required updations have been made
2792
  for (i = 0; commands[i].getName(); i++)
1 by brian
clean slate
2793
  {
1441.3.1 by Vijay Samuel
all required updations have been made
2794
    end= strcpy(buff, commands[i].getName());
2795
    end+= strlen(commands[i].getName());
2796
    for (j= (int)strlen(commands[i].getName()); j < 10; j++)
641.4.1 by Toru Maesaka
First pass of replacing MySQL's my_stpcpy() with appropriate libc calls
2797
      end= strcpy(end, " ")+1;
1 by brian
clean slate
2798
    if (commands[i].func)
2799
      tee_fprintf(stdout, "%s(\\%c) %s\n", buff,
1441.3.1 by Vijay Samuel
all required updations have been made
2800
                  commands[i].getCmdChar(), _(commands[i].getDoc()));
1 by brian
clean slate
2801
  }
820.2.1 by Toru Maesaka
Killed dead code and removed a reference to a non-existent help option
2802
  tee_fprintf(stdout, "\n");
2803
  buffer->clear();
1 by brian
clean slate
2804
  return 0;
2805
}
2806
2807
2808
static int
632.1.12 by Monty Taylor
Fixed more sun studio warnings.
2809
com_clear(string *buffer, const char *)
1 by brian
clean slate
2810
{
1441.3.1 by Vijay Samuel
all required updations have been made
2811
  if (status.getAddToHistory())
1 by brian
clean slate
2812
    fix_history(buffer);
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2813
  buffer->clear();
1 by brian
clean slate
2814
  return 0;
2815
}
2816
2817
2818
/*
2819
  Execute command
1441.3.1 by Vijay Samuel
all required updations have been made
2820
  Returns: 0  if ok
2821
  -1 if not fatal error
2822
  1  if fatal error
1 by brian
clean slate
2823
*/
2824
static int
632.1.12 by Monty Taylor
Fixed more sun studio warnings.
2825
com_go(string *buffer, const char *)
1 by brian
clean slate
2826
{
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2827
  char          buff[200]; /* about 110 chars used so far */
2828
  char          time_buff[52+3+1]; /* time max + space&parens + NUL */
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
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;
1 by brian
clean slate
2834
  int           err= 0;
2835
2836
  interrupted_query= 0;
2837
2838
  /* Remove garbage for nicer messages */
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2839
  remove_cntrl(buffer);
1 by brian
clean slate
2840
287.3.17 by Monty Taylor
Fixed null-query problem.
2841
  if (buffer->empty())
1 by brian
clean slate
2842
  {
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2843
    // Ignore empty quries
1441.3.1 by Vijay Samuel
all required updations have been made
2844
    if (status.getBatch())
1 by brian
clean slate
2845
      return 0;
202.3.13 by Monty Taylor
Changed gettext() to _() in drizzle.c.
2846
    return put_info(_("No query specified\n"),INFO_ERROR,0,0);
1 by brian
clean slate
2847
2848
  }
2849
  if (!connected && reconnect())
2850
  {
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2851
    // Remove query on error
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2852
    buffer->clear();
1 by brian
clean slate
2853
    return opt_reconnect ? -1 : 1;          // Fatal error
2854
  }
2855
  if (verbose)
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2856
    (void) com_print(buffer, 0);
1 by brian
clean slate
2857
2858
  if (skip_updates &&
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2859
      ((buffer->length() < 4) || (buffer->find( "SET ") != 0)))
1 by brian
clean slate
2860
  {
202.3.13 by Monty Taylor
Changed gettext() to _() in drizzle.c.
2861
    (void) put_info(_("Ignoring query to other database"),INFO_INFO,0,0);
1 by brian
clean slate
2862
    return 0;
2863
  }
2864
2865
  timer=start_timer();
2866
  executing_query= 1;
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
2867
  error= drizzleclient_real_query_for_lazy(buffer->c_str(),buffer->length(),&result, &error_code);
1 by brian
clean slate
2868
1441.3.1 by Vijay Samuel
all required updations have been made
2869
  if (status.getAddToHistory())
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
2870
  {
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2871
    buffer->append(vertical ? "\\G" : delimiter);
1 by brian
clean slate
2872
    /* Append final command onto history */
2873
    fix_history(buffer);
2874
  }
2875
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
2876
  buffer->clear();
1 by brian
clean slate
2877
2878
  if (error)
2879
    goto end;
2880
2881
  do
2882
  {
2883
    char *pos;
2884
2885
    if (quick)
2886
    {
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
2887
      if (drizzle_column_buffer(&result) != DRIZZLE_RETURN_OK)
1 by brian
clean slate
2888
      {
928.1.1 by Eric Day
Started client changes.
2889
        error= put_error(&con, &result);
1 by brian
clean slate
2890
        goto end;
2891
      }
2892
    }
2893
    else
2894
    {
840.1.21 by Monty Taylor
ZOMG. Renamed all the rest of the stuff in libdrizzleclient to be drizzleclient_*. I love commandline perl.
2895
      error= drizzleclient_store_result_for_lazy(&result);
1 by brian
clean slate
2896
      if (error)
2897
        goto end;
2898
    }
2899
2900
    if (verbose >= 3 || !opt_silent)
206.3.1 by Patrick Galbraith
Most everything working with client rename
2901
      drizzle_end_timer(timer,time_buff);
1 by brian
clean slate
2902
    else
2903
      time_buff[0]= '\0';
2904
2905
    /* Every branch must truncate  buff . */
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
2906
    if (drizzle_result_column_count(&result) > 0)
1 by brian
clean slate
2907
    {
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
2908
      if (!quick && drizzle_result_row_count(&result) == 0 &&
2909
          !column_types_flag)
1 by brian
clean slate
2910
      {
641.4.1 by Toru Maesaka
First pass of replacing MySQL's my_stpcpy() with appropriate libc calls
2911
        strcpy(buff, _("Empty set"));
1 by brian
clean slate
2912
      }
2913
      else
2914
      {
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
2915
        init_pager();
266.2.1 by Jim Winstead
Remove HTML and XML output support from drizzle client
2916
        if (vertical || (auto_vertical_output &&
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
2917
                         (terminal_width < get_result_width(&result))))
2918
          print_table_data_vertically(&result);
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
2919
        else if (opt_silent && verbose <= 2 && !output_tables)
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
2920
          print_tab_data(&result);
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
2921
        else
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
2922
          print_table_data(&result);
1441.3.1 by Vijay Samuel
all required updations have been made
2923
        sprintf(buff,
2924
                ngettext("%ld row in set","%ld rows in set",
2925
                         (long) drizzle_result_row_count(&result)),
2926
                (long) drizzle_result_row_count(&result));
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
2927
        end_pager();
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
2928
        if (drizzle_result_error_code(&result))
2929
          error= put_error(&con, &result);
1 by brian
clean slate
2930
      }
2931
    }
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
2932
    else if (drizzle_result_affected_rows(&result) == ~(uint64_t) 0)
641.4.1 by Toru Maesaka
First pass of replacing MySQL's my_stpcpy() with appropriate libc calls
2933
      strcpy(buff,_("Query OK"));
1 by brian
clean slate
2934
    else
1441.3.1 by Vijay Samuel
all required updations have been made
2935
      sprintf(buff, ngettext("Query OK, %ld row affected",
2936
                             "Query OK, %ld rows affected",
2937
                             (long) drizzle_result_affected_rows(&result)),
2938
              (long) drizzle_result_affected_rows(&result));
1 by brian
clean slate
2939
376 by Brian Aker
strend remove
2940
    pos= strchr(buff, '\0');
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
2941
    if ((warnings= drizzle_result_warning_count(&result)))
1 by brian
clean slate
2942
    {
2943
      *pos++= ',';
2944
      *pos++= ' ';
971.1.77 by Monty Taylor
Removed mysys/mystrings things from client/ progs. Still need to get rid of my_getopt, but I think that's all now.
2945
      char warnings_buff[20];
2946
      memset(warnings_buff,0,20);
1441.3.1 by Vijay Samuel
all required updations have been made
2947
      sprintf(warnings_buff, "%d", warnings);
971.1.77 by Monty Taylor
Removed mysys/mystrings things from client/ progs. Still need to get rid of my_getopt, but I think that's all now.
2948
      strcpy(pos, warnings_buff);
2949
      pos+= strlen(warnings_buff);
641.4.1 by Toru Maesaka
First pass of replacing MySQL's my_stpcpy() with appropriate libc calls
2950
      pos= strcpy(pos, " warning")+8;
1 by brian
clean slate
2951
      if (warnings != 1)
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
2952
        *pos++= 's';
1 by brian
clean slate
2953
    }
641.4.1 by Toru Maesaka
First pass of replacing MySQL's my_stpcpy() with appropriate libc calls
2954
    strcpy(pos, time_buff);
77.3.7 by Monty Taylor
Made mysql into a pure-C program.
2955
    put_info(buff,INFO_RESULT,0,0);
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
2956
    if (strcmp(drizzle_result_info(&result), ""))
2957
      put_info(drizzle_result_info(&result),INFO_RESULT,0,0);
206.3.1 by Patrick Galbraith
Most everything working with client rename
2958
    put_info("",INFO_RESULT,0,0);      // Empty row
1 by brian
clean slate
2959
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
2960
    if (unbuffered)
1 by brian
clean slate
2961
      fflush(stdout);
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
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);
1 by brian
clean slate
2981
  if (err >= 1)
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
2982
    error= put_error(&con, NULL);
1 by brian
clean slate
2983
2984
end:
2985
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
2986
  /* Show warnings if any or error occured */
1 by brian
clean slate
2987
  if (show_warnings == 1 && (warnings >= 1 || error))
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
2988
    print_warnings(error_code);
1 by brian
clean slate
2989
1441.3.1 by Vijay Samuel
all required updations have been made
2990
  if (!error && !status.getBatch() &&
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
2991
      drizzle_con_status(&con) & DRIZZLE_CON_STATUS_DB_DROPPED)
2992
  {
1 by brian
clean slate
2993
    get_current_db();
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
2994
  }
1 by brian
clean slate
2995
2996
  executing_query= 0;
206.3.1 by Patrick Galbraith
Most everything working with client rename
2997
  return error;        /* New command follows */
1 by brian
clean slate
2998
}
2999
3000
3001
static void init_pager()
3002
{
3003
  if (!opt_nopager)
3004
  {
3005
    if (!(PAGER= popen(pager, "w")))
3006
    {
3007
      tee_fprintf(stdout, "popen() failed! defaulting PAGER to stdout!\n");
3008
      PAGER= stdout;
3009
    }
3010
  }
3011
  else
3012
    PAGER= stdout;
3013
}
3014
3015
static void end_pager()
3016
{
3017
  if (!opt_nopager)
3018
    pclose(PAGER);
3019
}
3020
3021
3022
static void init_tee(const char *file_name)
3023
{
3024
  FILE* new_outfile;
3025
  if (opt_outfile)
3026
    end_tee();
910.1.3 by Brian Aker
Remove my_fopen() and key_map.cc file (thanks to Jay's lcov)
3027
  if (!(new_outfile= fopen(file_name, "a")))
1 by brian
clean slate
3028
  {
3029
    tee_fprintf(stdout, "Error logging to file '%s'\n", file_name);
3030
    return;
3031
  }
3032
  OUTFILE = new_outfile;
629.5.1 by Toru Maesaka
First pass of replacing MySQL's strmake() with libc calls
3033
  strncpy(outfile, file_name, FN_REFLEN-1);
1 by brian
clean slate
3034
  tee_fprintf(stdout, "Logging to file '%s'\n", file_name);
3035
  opt_outfile= 1;
910.1.3 by Brian Aker
Remove my_fopen() and key_map.cc file (thanks to Jay's lcov)
3036
1 by brian
clean slate
3037
  return;
3038
}
3039
3040
3041
static void end_tee()
3042
{
910.1.3 by Brian Aker
Remove my_fopen() and key_map.cc file (thanks to Jay's lcov)
3043
  fclose(OUTFILE);
1 by brian
clean slate
3044
  OUTFILE= 0;
3045
  opt_outfile= 0;
3046
  return;
3047
}
3048
3049
3050
static int
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
3051
com_ego(string *buffer,const char *line)
1 by brian
clean slate
3052
{
3053
  int result;
3054
  bool oldvertical=vertical;
3055
  vertical=1;
3056
  result=com_go(buffer,line);
3057
  vertical=oldvertical;
3058
  return result;
3059
}
3060
3061
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3062
static const char *fieldtype2str(drizzle_column_type_t type)
1 by brian
clean slate
3063
{
3064
  switch (type) {
1441.3.1 by Vijay Samuel
all required updations have been made
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";
3075
    default:                     return "?-unknown-?";
1 by brian
clean slate
3076
  }
3077
}
3078
893 by Brian Aker
First pass of stripping uint
3079
static char *fieldflags2str(uint32_t f) {
1 by brian
clean slate
3080
  static char buf[1024];
3081
  char *s=buf;
3082
  *s=0;
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
3083
#define ff2s_check_flag(X)                                              \
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3084
  if (f & DRIZZLE_COLUMN_FLAGS_ ## X) { s=strcpy(s, # X " ")+strlen(# X " "); \
1441.3.1 by Vijay Samuel
all required updations have been made
3085
                        f &= ~ DRIZZLE_COLUMN_FLAGS_ ## X; }
1 by brian
clean slate
3086
  ff2s_check_flag(NOT_NULL);
3087
  ff2s_check_flag(PRI_KEY);
3088
  ff2s_check_flag(UNIQUE_KEY);
3089
  ff2s_check_flag(MULTIPLE_KEY);
3090
  ff2s_check_flag(BLOB);
3091
  ff2s_check_flag(UNSIGNED);
3092
  ff2s_check_flag(BINARY);
3093
  ff2s_check_flag(ENUM);
3094
  ff2s_check_flag(AUTO_INCREMENT);
3095
  ff2s_check_flag(TIMESTAMP);
3096
  ff2s_check_flag(SET);
3097
  ff2s_check_flag(NO_DEFAULT_VALUE);
3098
  ff2s_check_flag(NUM);
3099
  ff2s_check_flag(PART_KEY);
3100
  ff2s_check_flag(GROUP);
3101
  ff2s_check_flag(UNIQUE);
3102
  ff2s_check_flag(BINCMP);
3103
  ff2s_check_flag(ON_UPDATE_NOW);
3104
#undef ff2s_check_flag
3105
  if (f)
1441.3.1 by Vijay Samuel
all required updations have been made
3106
    sprintf(s, " unknows=0x%04x", f);
1 by brian
clean slate
3107
  return buf;
3108
}
3109
3110
static void
928.1.1 by Eric Day
Started client changes.
3111
print_field_types(drizzle_result_st *result)
1 by brian
clean slate
3112
{
928.1.1 by Eric Day
Started client changes.
3113
  drizzle_column_st   *field;
893 by Brian Aker
First pass of stripping uint
3114
  uint32_t i=0;
1 by brian
clean slate
3115
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3116
  while ((field = drizzle_column_next(result)))
1 by brian
clean slate
3117
  {
3118
    tee_fprintf(PAGER, "Field %3u:  `%s`\n"
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
3119
                "Catalog:    `%s`\n"
3120
                "Database:   `%s`\n"
3121
                "Table:      `%s`\n"
3122
                "Org_table:  `%s`\n"
3123
                "Type:       %s\n"
3124
                "Collation:  %s (%u)\n"
3125
                "Length:     %lu\n"
3126
                "Max_length: %lu\n"
3127
                "Decimals:   %u\n"
3128
                "Flags:      %s\n\n",
1 by brian
clean slate
3129
                ++i,
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
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)));
1 by brian
clean slate
3138
  }
3139
  tee_puts("", PAGER);
3140
}
3141
3142
3143
static void
928.1.1 by Eric Day
Started client changes.
3144
print_table_data(drizzle_result_st *result)
1 by brian
clean slate
3145
{
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3146
  drizzle_row_t cur;
3147
  drizzle_return_t ret;
3148
  drizzle_column_st *field;
3149
  bool *num_flag;
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
3150
  string separator;
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
3151
287.3.19 by Monty Taylor
Added string.reserve() calls.
3152
  separator.reserve(256);
1 by brian
clean slate
3153
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3154
  num_flag=(bool*) malloc(sizeof(bool)*drizzle_result_column_count(result));
1 by brian
clean slate
3155
  if (column_types_flag)
3156
  {
3157
    print_field_types(result);
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3158
    if (!drizzle_result_row_count(result))
1 by brian
clean slate
3159
      return;
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3160
    drizzle_column_seek(result,0);
1 by brian
clean slate
3161
  }
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
3162
  separator.append("+");
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3163
  while ((field = drizzle_column_next(result)))
1 by brian
clean slate
3164
  {
840.3.1 by Toru Maesaka
Fixed the issue of seeing an oversized separator when rendering a multibyte string to console.
3165
    uint32_t x, length= 0;
3166
3167
    if (column_names)
3168
    {
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3169
      uint32_t name_length= strlen(drizzle_column_name(field));
3170
840.3.1 by Toru Maesaka
Fixed the issue of seeing an oversized separator when rendering a multibyte string to console.
3171
      /* Check if the max_byte value is really the maximum in terms
1441.3.1 by Vijay Samuel
all required updations have been made
3172
         of visual length since multibyte characters can affect the
3173
         length of the separator. */
840.3.1 by Toru Maesaka
Fixed the issue of seeing an oversized separator when rendering a multibyte string to console.
3174
      length= charset_info->cset->numcells(charset_info,
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3175
                                           drizzle_column_name(field),
3176
                                           drizzle_column_name(field) +
3177
                                           name_length);
840.3.1 by Toru Maesaka
Fixed the issue of seeing an oversized separator when rendering a multibyte string to console.
3178
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3179
      if (name_length == drizzle_column_max_size(field))
840.1.15 by Monty Taylor
Merged from Toru.
3180
      {
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3181
        if (length < drizzle_column_max_size(field))
3182
          drizzle_column_set_max_size(field, length);
840.1.15 by Monty Taylor
Merged from Toru.
3183
      }
840.3.1 by Toru Maesaka
Fixed the issue of seeing an oversized separator when rendering a multibyte string to console.
3184
      else
840.1.15 by Monty Taylor
Merged from Toru.
3185
      {
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3186
        length= name_length;
840.1.15 by Monty Taylor
Merged from Toru.
3187
      }
840.3.1 by Toru Maesaka
Fixed the issue of seeing an oversized separator when rendering a multibyte string to console.
3188
    }
1441.3.1 by Vijay Samuel
all required updations have been made
3189
  
1 by brian
clean slate
3190
    if (quick)
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3191
      length=max(length,drizzle_column_size(field));
1 by brian
clean slate
3192
    else
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
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
    {
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
3197
      // Room for "NULL"
3198
      length=4;
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3199
    }
3200
    drizzle_column_set_max_size(field, length);
840.3.1 by Toru Maesaka
Fixed the issue of seeing an oversized separator when rendering a multibyte string to console.
3201
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
3202
    for (x=0; x< (length+2); x++)
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
3203
      separator.append("-");
3204
    separator.append("+");
1 by brian
clean slate
3205
  }
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
3206
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
3207
  tee_puts((char*) separator.c_str(), PAGER);
1 by brian
clean slate
3208
  if (column_names)
3209
  {
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3210
    drizzle_column_seek(result,0);
1 by brian
clean slate
3211
    (void) tee_fputs("|", PAGER);
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3212
    for (uint32_t off=0; (field = drizzle_column_next(result)) ; off++)
1 by brian
clean slate
3213
    {
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3214
      uint32_t name_length= (uint32_t) strlen(drizzle_column_name(field));
893 by Brian Aker
First pass of stripping uint
3215
      uint32_t numcells= charset_info->cset->numcells(charset_info,
1441.3.1 by Vijay Samuel
all required updations have been made
3216
                                                  drizzle_column_name(field),
3217
                                                  drizzle_column_name(field) +
3218
                                                  name_length);
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3219
      uint32_t display_length= drizzle_column_max_size(field) + name_length -
1441.3.1 by Vijay Samuel
all required updations have been made
3220
                               numcells;
1 by brian
clean slate
3221
      tee_fprintf(PAGER, " %-*s |",(int) min(display_length,
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
3222
                                             MAX_COLUMN_LENGTH),
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
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));
1 by brian
clean slate
3226
    }
3227
    (void) tee_fputs("\n", PAGER);
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
3228
    tee_puts((char*) separator.c_str(), PAGER);
1 by brian
clean slate
3229
  }
3230
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3231
  while (1)
1 by brian
clean slate
3232
  {
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
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)
1 by brian
clean slate
3246
      break;
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3247
3248
    size_t *lengths= drizzle_row_field_sizes(result);
1 by brian
clean slate
3249
    (void) tee_fputs("| ", PAGER);
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3250
    drizzle_column_seek(result, 0);
3251
    for (uint32_t off= 0; off < drizzle_result_column_count(result); off++)
1 by brian
clean slate
3252
    {
3253
      const char *buffer;
893 by Brian Aker
First pass of stripping uint
3254
      uint32_t data_length;
3255
      uint32_t field_max_length;
3256
      uint32_t visible_length;
3257
      uint32_t extra_padding;
1 by brian
clean slate
3258
3259
      if (cur[off] == NULL)
3260
      {
3261
        buffer= "NULL";
3262
        data_length= 4;
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
3263
      }
3264
      else
1 by brian
clean slate
3265
      {
928.1.4 by Eric Day
Fixed a few bugs, more progress on conversion.
3266
        buffer= cur[off];
895 by Brian Aker
Completion (?) of uint conversion.
3267
        data_length= (uint32_t) lengths[off];
1 by brian
clean slate
3268
      }
3269
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3270
      field= drizzle_column_next(result);
3271
      field_max_length= drizzle_column_max_size(field);
1 by brian
clean slate
3272
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
3273
      /*
3274
        How many text cells on the screen will this string span?  If it contains
3275
        multibyte characters, then the number of characters we occupy on screen
3276
        will be fewer than the number of bytes we occupy in memory.
1 by brian
clean slate
3277
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
3278
        We need to find how much screen real-estate we will occupy to know how
3279
        many extra padding-characters we should send with the printing function.
1 by brian
clean slate
3280
      */
3281
      visible_length= charset_info->cset->numcells(charset_info, buffer, buffer + data_length);
3282
      extra_padding= data_length - visible_length;
3283
3284
      if (field_max_length > MAX_COLUMN_LENGTH)
1075 by Brian Aker
Fix for CentOS
3285
        tee_print_sized_data(buffer, data_length, MAX_COLUMN_LENGTH+extra_padding, false);
1 by brian
clean slate
3286
      else
3287
      {
3288
        if (num_flag[off] != 0) /* if it is numeric, we right-justify it */
1075 by Brian Aker
Fix for CentOS
3289
          tee_print_sized_data(buffer, data_length, field_max_length+extra_padding, true);
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
3290
        else
77.3.1 by Monty Taylor
First steps in removing sql_string and using glib instead.
3291
          tee_print_sized_data(buffer, data_length,
1075 by Brian Aker
Fix for CentOS
3292
                               field_max_length+extra_padding, false);
1 by brian
clean slate
3293
      }
3294
      tee_fputs(" | ", PAGER);
3295
    }
3296
    (void) tee_fputs("\n", PAGER);
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3297
    if (quick)
3298
      drizzle_row_free(result, cur);
1 by brian
clean slate
3299
  }
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
3300
  tee_puts(separator.c_str(), PAGER);
477 by Monty Taylor
Removed my_free(). It turns out that it had been def'd to ignore the flags passed to it in the second arg anyway. Gotta love that.
3301
  free(num_flag);
1 by brian
clean slate
3302
}
3303
3304
/**
1441.3.1 by Vijay Samuel
all required updations have been made
3305
   Return the length of a field after it would be rendered into text.
3306
3307
   This doesn't know or care about multibyte characters.  Assume we're
3308
   using such a charset.  We can't know that all of the upcoming rows
3309
   for this column will have bytes that each render into some fraction
3310
   of a character.  It's at least possible that a row has bytes that
3311
   all render into one character each, and so the maximum length is
3312
   still the number of bytes.  (Assumption 1:  This can't be better
3313
   because we can never know the number of characters that the DB is
3314
   going to send -- only the number of bytes.  2: Chars <= Bytes.)
3315
3316
   @param  field  Pointer to a field to be inspected
3317
3318
   @returns  number of character positions to be used, at most
1 by brian
clean slate
3319
*/
928.1.1 by Eric Day
Started client changes.
3320
static int get_field_disp_length(drizzle_column_st *field)
1 by brian
clean slate
3321
{
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3322
  uint32_t length= column_names ? strlen(drizzle_column_name(field)) : 0;
1 by brian
clean slate
3323
3324
  if (quick)
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3325
    length= max(length, drizzle_column_size(field));
1 by brian
clean slate
3326
  else
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3327
    length= max(length, (uint32_t)drizzle_column_max_size(field));
1 by brian
clean slate
3328
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3329
  if (length < 4 &&
1441.3.1 by Vijay Samuel
all required updations have been made
3330
    !(drizzle_column_flags(field) & DRIZZLE_COLUMN_FLAGS_NOT_NULL))
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3331
  {
206.3.1 by Patrick Galbraith
Most everything working with client rename
3332
    length= 4;        /* Room for "NULL" */
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3333
  }
1 by brian
clean slate
3334
3335
  return length;
3336
}
3337
3338
/**
1441.3.1 by Vijay Samuel
all required updations have been made
3339
   For a new result, return the max number of characters that any
3340
   upcoming row may return.
3341
3342
   @param  result  Pointer to the result to judge
3343
3344
   @returns  The max number of characters in any row of this result
1 by brian
clean slate
3345
*/
928.1.1 by Eric Day
Started client changes.
3346
static int get_result_width(drizzle_result_st *result)
1 by brian
clean slate
3347
{
3348
  unsigned int len= 0;
928.1.1 by Eric Day
Started client changes.
3349
  drizzle_column_st *field;
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3350
  uint16_t offset;
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
3351
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3352
  offset= drizzle_column_current(result);
142.1.2 by Patrick
All DBUG_x removed from client/
3353
  assert(offset == 0);
1 by brian
clean slate
3354
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3355
  while ((field= drizzle_column_next(result)) != NULL)
1 by brian
clean slate
3356
    len+= get_field_disp_length(field) + 3; /* plus bar, space, & final space */
3357
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3358
  (void) drizzle_column_seek(result, offset);
1 by brian
clean slate
3359
3360
  return len + 1; /* plus final bar. */
3361
}
3362
3363
static void
3364
tee_print_sized_data(const char *data, unsigned int data_length, unsigned int total_bytes_to_send, bool right_justified)
3365
{
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
3366
  /*
1 by brian
clean slate
3367
    For '\0's print ASCII spaces instead, as '\0' is eaten by (at
3368
    least my) console driver, and that messes up the pretty table
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
3369
    grid.  (The \0 is also the reason we can't use fprintf() .)
1 by brian
clean slate
3370
  */
3371
  unsigned int i;
3372
  const char *p;
3373
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
3374
  if (right_justified)
1 by brian
clean slate
3375
    for (i= data_length; i < total_bytes_to_send; i++)
3376
      tee_putc((int)' ', PAGER);
3377
3378
  for (i= 0, p= data; i < data_length; i+= 1, p+= 1)
3379
  {
3380
    if (*p == '\0')
3381
      tee_putc((int)' ', PAGER);
3382
    else
3383
      tee_putc((int)*p, PAGER);
3384
  }
3385
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
3386
  if (! right_justified)
1 by brian
clean slate
3387
    for (i= data_length; i < total_bytes_to_send; i++)
3388
      tee_putc((int)' ', PAGER);
3389
}
3390
3391
3392
3393
static void
928.1.1 by Eric Day
Started client changes.
3394
print_table_data_vertically(drizzle_result_st *result)
1 by brian
clean slate
3395
{
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3396
  drizzle_row_t cur;
3397
  drizzle_return_t ret;
3398
  uint32_t max_length=0;
3399
  drizzle_column_st *field;
1 by brian
clean slate
3400
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3401
  while ((field = drizzle_column_next(result)))
1 by brian
clean slate
3402
  {
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3403
    uint32_t length= strlen(drizzle_column_name(field));
1 by brian
clean slate
3404
    if (length > max_length)
3405
      max_length= length;
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3406
    drizzle_column_set_max_size(field, length);
1 by brian
clean slate
3407
  }
3408
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3409
  for (uint32_t row_count=1;; row_count++)
1 by brian
clean slate
3410
  {
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
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)
1 by brian
clean slate
3424
      break;
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3425
    drizzle_column_seek(result,0);
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
3426
    tee_fprintf(PAGER,
3427
                "*************************** %d. row ***************************\n", row_count);
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3428
    for (uint32_t off=0; off < drizzle_result_column_count(result); off++)
1 by brian
clean slate
3429
    {
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3430
      field= drizzle_column_next(result);
3431
      tee_fprintf(PAGER, "%*s: ",(int) max_length,drizzle_column_name(field));
1 by brian
clean slate
3432
      tee_fprintf(PAGER, "%s\n",cur[off] ? (char*) cur[off] : "NULL");
3433
    }
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3434
    if (quick)
3435
      drizzle_row_free(result, cur);
1 by brian
clean slate
3436
  }
3437
}
3438
3439
3440
/* print_warnings should be called right after executing a statement */
3441
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3442
static void print_warnings(uint32_t error_code)
1 by brian
clean slate
3443
{
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3444
  const char *query;
3445
  drizzle_result_st result;
3446
  drizzle_row_t cur;
157 by Brian Aker
Second pass cleanup on removal of my_uint types
3447
  uint64_t num_rows;
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3448
  uint32_t new_code= 0;
1 by brian
clean slate
3449
3450
  /* Get the warnings */
3451
  query= "show warnings";
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3452
  drizzleclient_real_query_for_lazy(query, strlen(query),&result,&new_code);
840.1.21 by Monty Taylor
ZOMG. Renamed all the rest of the stuff in libdrizzleclient to be drizzleclient_*. I love commandline perl.
3453
  drizzleclient_store_result_for_lazy(&result);
1 by brian
clean slate
3454
3455
  /* Bail out when no warnings */
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3456
  if (!(num_rows= drizzle_result_row_count(&result)))
1 by brian
clean slate
3457
    goto end;
3458
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3459
  cur= drizzle_row_next(&result);
1 by brian
clean slate
3460
3461
  /*
3462
    Don't print a duplicate of the current error.  It is possible for SHOW
3463
    WARNINGS to return multiple errors with the same code, but different
3464
    messages.  To be safe, skip printing the duplicate only if it is the only
3465
    warning.
3466
  */
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3467
  if (!cur || (num_rows == 1 &&
1441.3.1 by Vijay Samuel
all required updations have been made
3468
      error_code == (uint32_t) strtoul(cur[1], NULL, 10)))
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3469
  {
1 by brian
clean slate
3470
    goto end;
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3471
  }
1 by brian
clean slate
3472
3473
  /* Print the warnings */
3474
  init_pager();
3475
  do
3476
  {
3477
    tee_fprintf(PAGER, "%s (Code %s): %s\n", cur[0], cur[1], cur[2]);
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3478
  } while ((cur= drizzle_row_next(&result)));
1 by brian
clean slate
3479
  end_pager();
3480
3481
end:
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3482
  drizzle_result_free(&result);
1 by brian
clean slate
3483
}
3484
3485
3486
static void
288 by Brian Aker
ulong cleanp in client apps
3487
safe_put_field(const char *pos,uint32_t length)
1 by brian
clean slate
3488
{
3489
  if (!pos)
3490
    tee_fputs("NULL", PAGER);
3491
  else
3492
  {
3493
    if (opt_raw_data)
3494
      tee_fputs(pos, PAGER);
3495
    else for (const char *end=pos+length ; pos != end ; pos++)
1085.3.3 by Monty Taylor
Got rid of #ifdef have utf8 stuff.
3496
    {
3497
      int l;
3498
      if (use_mb(charset_info) &&
3499
          (l = my_ismbchar(charset_info, pos, end)))
3500
      {
3501
        while (l--)
3502
          tee_putc(*pos++, PAGER);
3503
        pos--;
3504
        continue;
3505
      }
3506
      if (!*pos)
3507
        tee_fputs("\\0", PAGER); // This makes everything hard
3508
      else if (*pos == '\t')
3509
        tee_fputs("\\t", PAGER); // This would destroy tab format
3510
      else if (*pos == '\n')
3511
        tee_fputs("\\n", PAGER); // This too
3512
      else if (*pos == '\\')
3513
        tee_fputs("\\\\", PAGER);
3514
      else
3515
        tee_putc(*pos, PAGER);
3516
    }
1 by brian
clean slate
3517
  }
3518
}
3519
3520
3521
static void
928.1.1 by Eric Day
Started client changes.
3522
print_tab_data(drizzle_result_st *result)
1 by brian
clean slate
3523
{
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3524
  drizzle_row_t cur;
3525
  drizzle_return_t ret;
3526
  drizzle_column_st *field;
3527
  size_t *lengths;
1 by brian
clean slate
3528
3529
  if (opt_silent < 2 && column_names)
3530
  {
3531
    int first=0;
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3532
    while ((field = drizzle_column_next(result)))
1 by brian
clean slate
3533
    {
3534
      if (first++)
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
3535
        (void) tee_fputs("\t", PAGER);
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3536
      (void) tee_fputs(drizzle_column_name(field), PAGER);
1 by brian
clean slate
3537
    }
3538
    (void) tee_fputs("\n", PAGER);
3539
  }
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3540
  while (1)
1 by brian
clean slate
3541
  {
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3542
    if (quick)
3543
    {
3544
      cur= drizzle_row_buffer(result, &ret);
3545
      if (ret != DRIZZLE_RETURN_OK)
3546
      {
3547
        (void)put_error(&con, result);
3548
        break;
3549
      }
3550
    }
3551
    else
3552
      cur= drizzle_row_next(result);
3553
3554
    if (cur == NULL)
3555
      break;
3556
3557
    lengths= drizzle_row_field_sizes(result);
928.1.4 by Eric Day
Fixed a few bugs, more progress on conversion.
3558
    safe_put_field(cur[0],lengths[0]);
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3559
    for (uint32_t off=1 ; off < drizzle_result_column_count(result); off++)
1 by brian
clean slate
3560
    {
3561
      (void) tee_fputs("\t", PAGER);
928.1.4 by Eric Day
Fixed a few bugs, more progress on conversion.
3562
      safe_put_field(cur[off], lengths[off]);
1 by brian
clean slate
3563
    }
3564
    (void) tee_fputs("\n", PAGER);
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3565
    if (quick)
3566
      drizzle_row_free(result, cur);
1 by brian
clean slate
3567
  }
3568
}
3569
3570
static int
632.1.12 by Monty Taylor
Fixed more sun studio warnings.
3571
com_tee(string *, const char *line )
1 by brian
clean slate
3572
{
520.4.43 by mordred
A set of Solaris fixes.
3573
  char file_name[FN_REFLEN], *end;
3574
  const char *param;
1 by brian
clean slate
3575
1441.3.1 by Vijay Samuel
all required updations have been made
3576
  if (status.getBatch())
1 by brian
clean slate
3577
    return 0;
3578
  while (my_isspace(charset_info,*line))
3579
    line++;
3580
  if (!(param = strchr(line, ' '))) // if outfile wasn't given, use the default
3581
  {
3582
    if (!strlen(outfile))
3583
    {
3584
      printf("No previous outfile available, you must give a filename!\n");
3585
      return 0;
3586
    }
3587
    else if (opt_outfile)
3588
    {
3589
      tee_fprintf(stdout, "Currently logging to file '%s'\n", outfile);
3590
      return 0;
3591
    }
3592
    else
206.3.1 by Patrick Galbraith
Most everything working with client rename
3593
      param = outfile;      //resume using the old outfile
1 by brian
clean slate
3594
  }
3595
3596
  /* eliminate the spaces before the parameters */
3597
  while (my_isspace(charset_info,*param))
3598
    param++;
629.5.3 by Toru Maesaka
Third pass of replacing MySQL's strmake() with libc calls
3599
  strncpy(file_name, param, sizeof(file_name) - 1);
3600
  end= file_name + strlen(file_name);
1 by brian
clean slate
3601
  /* remove end space from command line */
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
3602
  while (end > file_name && (my_isspace(charset_info,end[-1]) ||
3603
                             my_iscntrl(charset_info,end[-1])))
1 by brian
clean slate
3604
    end--;
3605
  end[0]= 0;
3606
  if (end == file_name)
3607
  {
3608
    printf("No outfile specified!\n");
3609
    return 0;
3610
  }
3611
  init_tee(file_name);
3612
  return 0;
3613
}
3614
3615
3616
static int
632.1.12 by Monty Taylor
Fixed more sun studio warnings.
3617
com_notee(string *, const char *)
1 by brian
clean slate
3618
{
3619
  if (opt_outfile)
3620
    end_tee();
3621
  tee_fprintf(stdout, "Outfile disabled.\n");
3622
  return 0;
3623
}
3624
3625
/*
3626
  Sorry, this command is not available in Windows.
3627
*/
3628
3629
static int
632.1.12 by Monty Taylor
Fixed more sun studio warnings.
3630
com_pager(string *, const char *line)
1 by brian
clean slate
3631
{
520.4.43 by mordred
A set of Solaris fixes.
3632
  char pager_name[FN_REFLEN], *end;
3633
  const char *param;
1 by brian
clean slate
3634
1441.3.1 by Vijay Samuel
all required updations have been made
3635
  if (status.getBatch())
1 by brian
clean slate
3636
    return 0;
3637
  /* Skip spaces in front of the pager command */
3638
  while (my_isspace(charset_info, *line))
3639
    line++;
3640
  /* Skip the pager command */
3641
  param= strchr(line, ' ');
3642
  /* Skip the spaces between the command and the argument */
3643
  while (param && my_isspace(charset_info, *param))
3644
    param++;
3645
  if (!param || !strlen(param)) // if pager was not given, use the default
3646
  {
3647
    if (!default_pager_set)
3648
    {
3649
      tee_fprintf(stdout, "Default pager wasn't set, using stdout.\n");
3650
      opt_nopager=1;
641.4.1 by Toru Maesaka
First pass of replacing MySQL's my_stpcpy() with appropriate libc calls
3651
      strcpy(pager, "stdout");
1 by brian
clean slate
3652
      PAGER= stdout;
3653
      return 0;
3654
    }
641.4.1 by Toru Maesaka
First pass of replacing MySQL's my_stpcpy() with appropriate libc calls
3655
    strcpy(pager, default_pager);
1 by brian
clean slate
3656
  }
3657
  else
3658
  {
629.5.3 by Toru Maesaka
Third pass of replacing MySQL's strmake() with libc calls
3659
    end= strncpy(pager_name, param, sizeof(pager_name)-1);
3660
    end+= strlen(pager_name);
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
3661
    while (end > pager_name && (my_isspace(charset_info,end[-1]) ||
1 by brian
clean slate
3662
                                my_iscntrl(charset_info,end[-1])))
3663
      end--;
3664
    end[0]=0;
641.4.1 by Toru Maesaka
First pass of replacing MySQL's my_stpcpy() with appropriate libc calls
3665
    strcpy(pager, pager_name);
3666
    strcpy(default_pager, pager_name);
1 by brian
clean slate
3667
  }
3668
  opt_nopager=0;
3669
  tee_fprintf(stdout, "PAGER set to '%s'\n", pager);
3670
  return 0;
3671
}
3672
3673
3674
static int
632.1.12 by Monty Taylor
Fixed more sun studio warnings.
3675
com_nopager(string *, const char *)
1 by brian
clean slate
3676
{
641.4.1 by Toru Maesaka
First pass of replacing MySQL's my_stpcpy() with appropriate libc calls
3677
  strcpy(pager, "stdout");
1 by brian
clean slate
3678
  opt_nopager=1;
3679
  PAGER= stdout;
3680
  tee_fprintf(stdout, "PAGER set to stdout\n");
3681
  return 0;
3682
}
3683
3684
/* If arg is given, exit without errors. This happens on command 'quit' */
3685
3686
static int
632.1.12 by Monty Taylor
Fixed more sun studio warnings.
3687
com_quit(string *, const char *)
1 by brian
clean slate
3688
{
3689
  /* let the screen auto close on a normal shutdown */
1441.3.1 by Vijay Samuel
all required updations have been made
3690
  status.setExitStatus(0);
1 by brian
clean slate
3691
  return 1;
3692
}
3693
3694
static int
632.1.12 by Monty Taylor
Fixed more sun studio warnings.
3695
com_rehash(string *, const char *)
1 by brian
clean slate
3696
{
3697
  build_completion_hash(1, 0);
3698
  return 0;
3699
}
3700
3701
3702
3703
static int
632.1.12 by Monty Taylor
Fixed more sun studio warnings.
3704
com_print(string *buffer,const char *)
1 by brian
clean slate
3705
{
3706
  tee_puts("--------------", stdout);
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
3707
  (void) tee_fputs(buffer->c_str(), stdout);
3708
  if ( (buffer->length() == 0)
3709
       || (buffer->c_str())[(buffer->length())-1] != '\n')
1 by brian
clean slate
3710
    tee_putc('\n', stdout);
3711
  tee_puts("--------------\n", stdout);
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
3712
  /* If empty buffer */
3713
  return 0;
1 by brian
clean slate
3714
}
3715
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
3716
/* ARGSUSED */
1 by brian
clean slate
3717
static int
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
3718
com_connect(string *buffer, const char *line)
1 by brian
clean slate
3719
{
3720
  char *tmp, buff[256];
3721
  bool save_rehash= opt_rehash;
3722
  int error;
3723
212.6.1 by Mats Kindahl
Replacing all bzero() calls with memset() calls and removing the bzero.c file.
3724
  memset(buff, 0, sizeof(buff));
1 by brian
clean slate
3725
  if (buffer)
3726
  {
3727
    /*
3728
      Two null bytes are needed in the end of buff to allow
3729
      get_arg to find end of string the second time it's called.
3730
    */
629.5.3 by Toru Maesaka
Third pass of replacing MySQL's strmake() with libc calls
3731
    tmp= strncpy(buff, line, sizeof(buff)-2);
1 by brian
clean slate
3732
#ifdef EXTRA_DEBUG
3733
    tmp[1]= 0;
3734
#endif
3735
    tmp= get_arg(buff, 0);
3736
    if (tmp && *tmp)
3737
    {
477 by Monty Taylor
Removed my_free(). It turns out that it had been def'd to ignore the flags passed to it in the second arg anyway. Gotta love that.
3738
      free(current_db);
182.1.2 by Jim Winstead
Various fixes to enable compilation on Mac OS X, and remove the glib dependency.
3739
      current_db= strdup(tmp);
1 by brian
clean slate
3740
      tmp= get_arg(buff, 1);
3741
      if (tmp)
3742
      {
477 by Monty Taylor
Removed my_free(). It turns out that it had been def'd to ignore the flags passed to it in the second arg anyway. Gotta love that.
3743
        free(current_host);
182.1.2 by Jim Winstead
Various fixes to enable compilation on Mac OS X, and remove the glib dependency.
3744
        current_host=strdup(tmp);
1 by brian
clean slate
3745
      }
3746
    }
3747
    else
3748
    {
3749
      /* Quick re-connect */
971.6.11 by Eric Day
Removed purecov messages.
3750
      opt_rehash= 0;
1 by brian
clean slate
3751
    }
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
3752
    // command used
77.3.3 by Monty Taylor
Last change to migrate to glib from sql_string.
3753
    assert(buffer!=NULL);
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
3754
    buffer->clear();
1 by brian
clean slate
3755
  }
3756
  else
3757
    opt_rehash= 0;
3758
  error=sql_connect(current_host,current_db,current_user,opt_password,0);
3759
  opt_rehash= save_rehash;
3760
3761
  if (connected)
3762
  {
1441.3.1 by Vijay Samuel
all required updations have been made
3763
    sprintf(buff,"Connection id:    %u",drizzle_con_thread_id(&con));
77.3.7 by Monty Taylor
Made mysql into a pure-C program.
3764
    put_info(buff,INFO_INFO,0,0);
1441.3.1 by Vijay Samuel
all required updations have been made
3765
    sprintf(buff,"Current database: %.128s\n",
3766
            current_db ? current_db : "*** NONE ***");
77.3.7 by Monty Taylor
Made mysql into a pure-C program.
3767
    put_info(buff,INFO_INFO,0,0);
1 by brian
clean slate
3768
  }
3769
  return error;
3770
}
3771
3772
632.1.12 by Monty Taylor
Fixed more sun studio warnings.
3773
static int com_source(string *, const char *line)
1 by brian
clean slate
3774
{
520.4.43 by mordred
A set of Solaris fixes.
3775
  char source_name[FN_REFLEN], *end;
3776
  const char *param;
1095.2.1 by Robert Klahn
Replace typedef struct LINE_BUFFER with class LineBuffer, encapsulating current logic
3777
  LineBuffer *line_buff;
1 by brian
clean slate
3778
  int error;
1441.3.1 by Vijay Samuel
all required updations have been made
3779
  Status old_status;
1 by brian
clean slate
3780
  FILE *sql_file;
3781
3782
  /* Skip space from file name */
3783
  while (my_isspace(charset_info,*line))
3784
    line++;
206.3.1 by Patrick Galbraith
Most everything working with client rename
3785
  if (!(param = strchr(line, ' ')))    // Skip command name
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
3786
    return put_info("Usage: \\. <filename> | source <filename>",
77.3.7 by Monty Taylor
Made mysql into a pure-C program.
3787
                    INFO_ERROR, 0,0);
1 by brian
clean slate
3788
  while (my_isspace(charset_info,*param))
3789
    param++;
629.5.3 by Toru Maesaka
Third pass of replacing MySQL's strmake() with libc calls
3790
  end= strncpy(source_name,param,sizeof(source_name)-1);
3791
  end+= strlen(source_name);
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
3792
  while (end > source_name && (my_isspace(charset_info,end[-1]) ||
1 by brian
clean slate
3793
                               my_iscntrl(charset_info,end[-1])))
3794
    end--;
3795
  end[0]=0;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
3796
  internal::unpack_filename(source_name,source_name);
1 by brian
clean slate
3797
  /* open file name */
910.1.3 by Brian Aker
Remove my_fopen() and key_map.cc file (thanks to Jay's lcov)
3798
  if (!(sql_file = fopen(source_name, "r")))
1 by brian
clean slate
3799
  {
3800
    char buff[FN_REFLEN+60];
1441.3.1 by Vijay Samuel
all required updations have been made
3801
    sprintf(buff,"Failed to open file '%s', error: %d", source_name,errno);
77.3.7 by Monty Taylor
Made mysql into a pure-C program.
3802
    return put_info(buff, INFO_ERROR, 0 ,0);
1 by brian
clean slate
3803
  }
3804
1095.2.6 by Robert Klahn
Changes from additional code review feedback
3805
  line_buff= new(std::nothrow) LineBuffer(opt_max_input_line,sql_file);
1095.2.4 by Robert Klahn
changes from code review feedback
3806
  if (line_buff == NULL)
1 by brian
clean slate
3807
  {
910.1.3 by Brian Aker
Remove my_fopen() and key_map.cc file (thanks to Jay's lcov)
3808
    fclose(sql_file);
1095.2.1 by Robert Klahn
Replace typedef struct LINE_BUFFER with class LineBuffer, encapsulating current logic
3809
    return put_info("Can't initialize LineBuffer", INFO_ERROR, 0, 0);
1 by brian
clean slate
3810
  }
3811
3812
  /* Save old status */
3813
  old_status=status;
212.6.10 by Mats Kindahl
Removing redundant use of casts in client/ for memcmp(), memcpy(), memset(), and memmove().
3814
  memset(&status, 0, sizeof(status));
1 by brian
clean slate
3815
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
3816
  // Run in batch mode
1441.3.1 by Vijay Samuel
all required updations have been made
3817
  status.setBatch(old_status.getBatch());
3818
  status.setLineBuff(line_buff);
3819
  status.setFileName(source_name);
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
3820
  // Empty command buffer
77.3.3 by Monty Taylor
Last change to migrate to glib from sql_string.
3821
  assert(glob_buffer!=NULL);
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
3822
  glob_buffer->clear();
1 by brian
clean slate
3823
  error= read_and_execute(false);
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
3824
  // Continue as before
3825
  status=old_status;
910.1.3 by Brian Aker
Remove my_fopen() and key_map.cc file (thanks to Jay's lcov)
3826
  fclose(sql_file);
1441.3.1 by Vijay Samuel
all required updations have been made
3827
  delete status.getLineBuff();
3828
  line_buff=0;
3829
  status.setLineBuff(0);
1 by brian
clean slate
3830
  return error;
3831
}
3832
3833
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
3834
/* ARGSUSED */
1 by brian
clean slate
3835
static int
632.1.12 by Monty Taylor
Fixed more sun studio warnings.
3836
com_delimiter(string *, const char *line)
1 by brian
clean slate
3837
{
3838
  char buff[256], *tmp;
3839
629.5.1 by Toru Maesaka
First pass of replacing MySQL's strmake() with libc calls
3840
  strncpy(buff, line, sizeof(buff) - 1);
1 by brian
clean slate
3841
  tmp= get_arg(buff, 0);
3842
3843
  if (!tmp || !*tmp)
3844
  {
3845
    put_info("DELIMITER must be followed by a 'delimiter' character or string",
77.3.7 by Monty Taylor
Made mysql into a pure-C program.
3846
             INFO_ERROR, 0, 0);
1 by brian
clean slate
3847
    return 0;
3848
  }
3849
  else
3850
  {
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
3851
    if (strstr(tmp, "\\"))
1 by brian
clean slate
3852
    {
77.3.7 by Monty Taylor
Made mysql into a pure-C program.
3853
      put_info("DELIMITER cannot contain a backslash character",
3854
               INFO_ERROR, 0, 0);
1 by brian
clean slate
3855
      return 0;
3856
    }
3857
  }
629.5.1 by Toru Maesaka
First pass of replacing MySQL's strmake() with libc calls
3858
  strncpy(delimiter, tmp, sizeof(delimiter) - 1);
1 by brian
clean slate
3859
  delimiter_length= (int)strlen(delimiter);
3860
  delimiter_str= delimiter;
3861
  return 0;
3862
}
3863
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
3864
/* ARGSUSED */
1 by brian
clean slate
3865
static int
632.1.12 by Monty Taylor
Fixed more sun studio warnings.
3866
com_use(string *, const char *line)
1 by brian
clean slate
3867
{
3868
  char *tmp, buff[FN_REFLEN + 1];
3869
  int select_db;
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3870
  drizzle_result_st result;
3871
  drizzle_return_t ret;
1 by brian
clean slate
3872
212.6.1 by Mats Kindahl
Replacing all bzero() calls with memset() calls and removing the bzero.c file.
3873
  memset(buff, 0, sizeof(buff));
629.5.1 by Toru Maesaka
First pass of replacing MySQL's strmake() with libc calls
3874
  strncpy(buff, line, sizeof(buff) - 1);
1 by brian
clean slate
3875
  tmp= get_arg(buff, 0);
3876
  if (!tmp || !*tmp)
3877
  {
77.3.7 by Monty Taylor
Made mysql into a pure-C program.
3878
    put_info("USE must be followed by a database name", INFO_ERROR, 0, 0);
1 by brian
clean slate
3879
    return 0;
3880
  }
3881
  /*
3882
    We need to recheck the current database, because it may change
3883
    under our feet, for example if DROP DATABASE or RENAME DATABASE
3884
    (latter one not yet available by the time the comment was written)
3885
  */
3886
  get_current_db();
3887
919.2.11 by Monty Taylor
Removed C99 isnan() usage, which allows us to remove the util/math.{cc,h} workarounds. Yay for standards!
3888
  if (!current_db || strcmp(current_db,tmp))
1 by brian
clean slate
3889
  {
3890
    if (one_database)
3891
    {
3892
      skip_updates= 1;
840.1.21 by Monty Taylor
ZOMG. Renamed all the rest of the stuff in libdrizzleclient to be drizzleclient_*. I love commandline perl.
3893
      select_db= 0;    // don't do drizzleclient_select_db()
1 by brian
clean slate
3894
    }
3895
    else
840.1.21 by Monty Taylor
ZOMG. Renamed all the rest of the stuff in libdrizzleclient to be drizzleclient_*. I love commandline perl.
3896
      select_db= 2;    // do drizzleclient_select_db() and build_completion_hash()
1 by brian
clean slate
3897
  }
3898
  else
3899
  {
3900
    /*
3901
      USE to the current db specified.
840.1.21 by Monty Taylor
ZOMG. Renamed all the rest of the stuff in libdrizzleclient to be drizzleclient_*. I love commandline perl.
3902
      We do need to send drizzleclient_select_db() to make server
1 by brian
clean slate
3903
      update database level privileges, which might
3904
      change since last USE (see bug#10979).
3905
      For performance purposes, we'll skip rebuilding of completion hash.
3906
    */
3907
    skip_updates= 0;
840.1.21 by Monty Taylor
ZOMG. Renamed all the rest of the stuff in libdrizzleclient to be drizzleclient_*. I love commandline perl.
3908
    select_db= 1;      // do only drizzleclient_select_db(), without completion
1 by brian
clean slate
3909
  }
3910
3911
  if (select_db)
3912
  {
3913
    /*
3914
      reconnect once if connection is down or if connection was found to
3915
      be down during query
3916
    */
3917
    if (!connected && reconnect())
3918
      return opt_reconnect ? -1 : 1;                        // Fatal error
928.1.4 by Eric Day
Fixed a few bugs, more progress on conversion.
3919
    for (bool try_again= true; try_again; try_again= false)
1 by brian
clean slate
3920
    {
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
3921
      if (drizzle_select_db(&con,&result,tmp,&ret) == NULL ||
3922
          ret != DRIZZLE_RETURN_OK)
3923
      {
3924
        if (ret == DRIZZLE_RETURN_ERROR_CODE)
3925
        {
3926
          int error= put_error(&con, &result);
3927
          drizzle_result_free(&result);
3928
          return error;
3929
        }
3930
3931
        if (ret != DRIZZLE_RETURN_SERVER_GONE || !try_again)
3932
          return put_error(&con, NULL);
3933
3934
        if (reconnect())
3935
          return opt_reconnect ? -1 : 1;                      // Fatal error
3936
      }
928.1.4 by Eric Day
Fixed a few bugs, more progress on conversion.
3937
      else
3938
        drizzle_result_free(&result);
1 by brian
clean slate
3939
    }
477 by Monty Taylor
Removed my_free(). It turns out that it had been def'd to ignore the flags passed to it in the second arg anyway. Gotta love that.
3940
    free(current_db);
182.1.2 by Jim Winstead
Various fixes to enable compilation on Mac OS X, and remove the glib dependency.
3941
    current_db= strdup(tmp);
1 by brian
clean slate
3942
    if (select_db > 1)
3943
      build_completion_hash(opt_rehash, 1);
3944
  }
3945
77.3.7 by Monty Taylor
Made mysql into a pure-C program.
3946
  put_info("Database changed",INFO_INFO, 0, 0);
1 by brian
clean slate
3947
  return 0;
3948
}
3949
3950
static int
632.1.12 by Monty Taylor
Fixed more sun studio warnings.
3951
com_warnings(string *, const char *)
1 by brian
clean slate
3952
{
3953
  show_warnings = 1;
77.3.7 by Monty Taylor
Made mysql into a pure-C program.
3954
  put_info("Show warnings enabled.",INFO_INFO, 0, 0);
1 by brian
clean slate
3955
  return 0;
3956
}
3957
3958
static int
632.1.12 by Monty Taylor
Fixed more sun studio warnings.
3959
com_nowarnings(string *, const char *)
1 by brian
clean slate
3960
{
3961
  show_warnings = 0;
77.3.7 by Monty Taylor
Made mysql into a pure-C program.
3962
  put_info("Show warnings disabled.",INFO_INFO, 0, 0);
1 by brian
clean slate
3963
  return 0;
3964
}
3965
3966
/*
3967
  Gets argument from a command on the command line. If get_next_arg is
3968
  not defined, skips the command and returns the first argument. The
3969
  line is modified by adding zero to the end of the argument. If
3970
  get_next_arg is defined, then the function searches for end of string
3971
  first, after found, returns the next argument and adds zero to the
3972
  end. If you ever wish to use this feature, remember to initialize all
3973
  items in the array to zero first.
3974
*/
3975
143 by Brian Aker
Bool cleanup.
3976
char *get_arg(char *line, bool get_next_arg)
1 by brian
clean slate
3977
{
3978
  char *ptr, *start;
143 by Brian Aker
Bool cleanup.
3979
  bool quoted= 0, valid_arg= 0;
1 by brian
clean slate
3980
  char qtype= 0;
3981
3982
  ptr= line;
3983
  if (get_next_arg)
3984
  {
3985
    for (; *ptr; ptr++) ;
3986
    if (*(ptr + 1))
3987
      ptr++;
3988
  }
3989
  else
3990
  {
3991
    /* skip leading white spaces */
3992
    while (my_isspace(charset_info, *ptr))
3993
      ptr++;
3994
    if (*ptr == '\\') // short command was used
3995
      ptr+= 2;
3996
    else
3997
      while (*ptr &&!my_isspace(charset_info, *ptr)) // skip command
3998
        ptr++;
3999
  }
4000
  if (!*ptr)
461 by Monty Taylor
Removed NullS. bu-bye.
4001
    return NULL;
1 by brian
clean slate
4002
  while (my_isspace(charset_info, *ptr))
4003
    ptr++;
4004
  if (*ptr == '\'' || *ptr == '\"' || *ptr == '`')
4005
  {
4006
    qtype= *ptr;
4007
    quoted= 1;
4008
    ptr++;
4009
  }
4010
  for (start=ptr ; *ptr; ptr++)
4011
  {
4012
    if (*ptr == '\\' && ptr[1]) // escaped character
4013
    {
4014
      // Remove the backslash
641.4.1 by Toru Maesaka
First pass of replacing MySQL's my_stpcpy() with appropriate libc calls
4015
      strcpy(ptr, ptr+1);
1 by brian
clean slate
4016
    }
4017
    else if ((!quoted && *ptr == ' ') || (quoted && *ptr == qtype))
4018
    {
4019
      *ptr= 0;
4020
      break;
4021
    }
4022
  }
4023
  valid_arg= ptr != start;
461 by Monty Taylor
Removed NullS. bu-bye.
4024
  return valid_arg ? start : NULL;
1 by brian
clean slate
4025
}
4026
4027
4028
static int
206.3.1 by Patrick Galbraith
Most everything working with client rename
4029
sql_connect(char *host,char *database,char *user,char *password,
1441.3.1 by Vijay Samuel
all required updations have been made
4030
                 uint32_t silent)
1 by brian
clean slate
4031
{
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
4032
  drizzle_return_t ret;
4033
1 by brian
clean slate
4034
  if (connected)
4035
  {
4036
    connected= 0;
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
4037
    drizzle_con_free(&con);
4038
    drizzle_free(&drizzle);
4039
  }
4040
  drizzle_create(&drizzle);
4041
  if (drizzle_con_add_tcp(&drizzle, &con, host, opt_drizzle_port, user,
971.8.4 by Eric Day
Added --mysql option flags to client utilities. Also removed the socket option since that is no used anymoe (requested from mailing list).
4042
                          password, database, opt_mysql ? DRIZZLE_CON_MYSQL : DRIZZLE_CON_NONE) == NULL)
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
4043
  {
4044
    (void) put_error(&con, NULL);
4045
    (void) fflush(stdout);
4046
    return 1;
4047
  }
4048
1441.3.1 by Vijay Samuel
all required updations have been made
4049
/* XXX add this back in
4050
  if (opt_connect_timeout)
4051
  {
893 by Brian Aker
First pass of stripping uint
4052
    uint32_t timeout=opt_connect_timeout;
840.1.21 by Monty Taylor
ZOMG. Renamed all the rest of the stuff in libdrizzleclient to be drizzleclient_*. I love commandline perl.
4053
    drizzleclient_options(&drizzle,DRIZZLE_OPT_CONNECT_TIMEOUT,
1441.3.1 by Vijay Samuel
all required updations have been made
4054
                  (char*) &timeout);
4055
  }
4056
*/
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
4057
1441.3.1 by Vijay Samuel
all required updations have been made
4058
/* XXX Do we need this?
4059
  if (safe_updates)
4060
  {
1 by brian
clean slate
4061
    char init_command[100];
4062
    sprintf(init_command,
1441.3.1 by Vijay Samuel
all required updations have been made
4063
            "SET SQL_SAFE_UPDATES=1,SQL_SELECT_LIMIT=%"PRIu32
4064
            ",MAX_JOIN_SIZE=%"PRIu32,
4065
            select_limit, max_join_size);
840.1.21 by Monty Taylor
ZOMG. Renamed all the rest of the stuff in libdrizzleclient to be drizzleclient_*. I love commandline perl.
4066
    drizzleclient_options(&drizzle, DRIZZLE_INIT_COMMAND, init_command);
1441.3.1 by Vijay Samuel
all required updations have been made
4067
  }
4068
*/
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
4069
  if ((ret= drizzle_con_connect(&con)) != DRIZZLE_RETURN_OK)
1 by brian
clean slate
4070
  {
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
4071
    if (!silent || (ret != DRIZZLE_RETURN_GETADDRINFO &&
4072
                    ret != DRIZZLE_RETURN_COULD_NOT_CONNECT))
1 by brian
clean slate
4073
    {
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
4074
      (void) put_error(&con, NULL);
1 by brian
clean slate
4075
      (void) fflush(stdout);
206.3.1 by Patrick Galbraith
Most everything working with client rename
4076
      return ignore_errors ? -1 : 1;    // Abort
1 by brian
clean slate
4077
    }
206.3.1 by Patrick Galbraith
Most everything working with client rename
4078
    return -1;          // Retryable
1 by brian
clean slate
4079
  }
4080
  connected=1;
1235.3.13 by Stewart Smith
remove MY_GIVE_INFO parameter to my_end() that really just gave us the output of time(1). Use UNIX, don't re-implement the kitchen sink. This also removes --debug-info from most command line utilities.
4081
1 by brian
clean slate
4082
  build_completion_hash(opt_rehash, 1);
4083
  return 0;
4084
}
4085
4086
4087
static int
632.1.12 by Monty Taylor
Fixed more sun studio warnings.
4088
com_status(string *, const char *)
1 by brian
clean slate
4089
{
1441.3.1 by Vijay Samuel
all required updations have been made
4090
/*
4091
  char buff[40];
4092
  uint64_t id;
4093
*/
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
4094
  drizzle_result_st result;
4095
  drizzle_return_t ret;
1 by brian
clean slate
4096
4097
  tee_puts("--------------", stdout);
206.3.1 by Patrick Galbraith
Most everything working with client rename
4098
  usage(1);          /* Print version */
1 by brian
clean slate
4099
  if (connected)
4100
  {
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
4101
    tee_fprintf(stdout, "\nConnection id:\t\t%lu\n",drizzle_con_thread_id(&con));
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4102
    /*
4103
      Don't remove "limit 1",
1 by brian
clean slate
4104
      it is protection againts SQL_SELECT_LIMIT=0
4105
    */
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
4106
    if (drizzle_query_str(&con,&result,"select DATABASE(), USER() limit 1",
4107
                          &ret) != NULL && ret == DRIZZLE_RETURN_OK &&
4108
        drizzle_result_buffer(&result) == DRIZZLE_RETURN_OK)
1 by brian
clean slate
4109
    {
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
4110
      drizzle_row_t cur=drizzle_row_next(&result);
1 by brian
clean slate
4111
      if (cur)
4112
      {
928.1.4 by Eric Day
Fixed a few bugs, more progress on conversion.
4113
        tee_fprintf(stdout, "Current database:\t%s\n", cur[0] ? cur[0] : "");
1 by brian
clean slate
4114
        tee_fprintf(stdout, "Current user:\t\t%s\n", cur[1]);
4115
      }
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
4116
      drizzle_result_free(&result);
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4117
    }
928.1.4 by Eric Day
Fixed a few bugs, more progress on conversion.
4118
    else if (ret == DRIZZLE_RETURN_ERROR_CODE)
4119
      drizzle_result_free(&result);
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4120
    tee_puts("SSL:\t\t\tNot in use", stdout);
1 by brian
clean slate
4121
  }
4122
  else
4123
  {
4124
    vidattr(A_BOLD);
4125
    tee_fprintf(stdout, "\nNo connection\n");
4126
    vidattr(A_NORMAL);
4127
    return 0;
4128
  }
4129
  if (skip_updates)
4130
  {
4131
    vidattr(A_BOLD);
4132
    tee_fprintf(stdout, "\nAll updates ignored to this database\n");
4133
    vidattr(A_NORMAL);
4134
  }
4135
  tee_fprintf(stdout, "Current pager:\t\t%s\n", pager);
4136
  tee_fprintf(stdout, "Using outfile:\t\t'%s'\n", opt_outfile ? outfile : "");
4137
  tee_fprintf(stdout, "Using delimiter:\t%s\n", delimiter);
928.1.1 by Eric Day
Started client changes.
4138
  tee_fprintf(stdout, "Server version:\t\t%s\n", server_version_string(&con));
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
4139
  tee_fprintf(stdout, "Protocol version:\t%d\n", drizzle_con_protocol_version(&con));
4140
  tee_fprintf(stdout, "Connection:\t\t%s\n", drizzle_con_host(&con));
1441.3.1 by Vijay Samuel
all required updations have been made
4141
/* XXX need to save this from result
4142
  if ((id= drizzleclient_insert_id(&drizzle)))
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
4143
    tee_fprintf(stdout, "Insert id:\t\t%s\n", internal::llstr(id, buff));
1441.3.1 by Vijay Samuel
all required updations have been made
4144
*/
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
4145
1377.2.2 by Zimin
bug fix: ./bin/drizzle with \s would segfault.
4146
  if (drizzle_con_uds(&con))
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
4147
    tee_fprintf(stdout, "UNIX socket:\t\t%s\n", drizzle_con_uds(&con));
1 by brian
clean slate
4148
  else
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
4149
    tee_fprintf(stdout, "TCP port:\t\t%d\n", drizzle_con_port(&con));
1 by brian
clean slate
4150
4151
  if (safe_updates)
4152
  {
4153
    vidattr(A_BOLD);
4154
    tee_fprintf(stdout, "\nNote that you are running in safe_update_mode:\n");
4155
    vidattr(A_NORMAL);
4156
    tee_fprintf(stdout, "\
1441.3.1 by Vijay Samuel
all required updations have been made
4157
UPDATEs and DELETEs that don't use a key in the WHERE clause are not allowed.\n\
4158
(One can force an UPDATE/DELETE by adding LIMIT # at the end of the command.)\n \
4159
SELECT has an automatic 'LIMIT %lu' if LIMIT is not used.\n             \
4160
Max number of examined row combination in a join is set to: %lu\n\n",
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4161
                select_limit, max_join_size);
1 by brian
clean slate
4162
  }
4163
  tee_puts("--------------\n", stdout);
4164
  return 0;
4165
}
4166
4167
static const char *
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
4168
server_version_string(drizzle_con_st *local_con)
1 by brian
clean slate
4169
{
534 by Monty Taylor
Removed stxnmov. Also deleted strstr which had already been removed.
4170
  static string buf("");
4171
  static bool server_version_string_reserved= false;
1 by brian
clean slate
4172
534 by Monty Taylor
Removed stxnmov. Also deleted strstr which had already been removed.
4173
  if (!server_version_string_reserved)
4174
  {
4175
    buf.reserve(MAX_SERVER_VERSION_LENGTH);
4176
    server_version_string_reserved= true;
4177
  }
1 by brian
clean slate
4178
  /* Only one thread calls this, so no synchronization is needed */
4179
  if (buf[0] == '\0')
4180
  {
928.1.1 by Eric Day
Started client changes.
4181
    drizzle_result_st result;
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
4182
    drizzle_return_t ret;
1 by brian
clean slate
4183
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
4184
    buf.append(drizzle_con_server_version(local_con));
1 by brian
clean slate
4185
4186
    /* "limit 1" is protection against SQL_SELECT_LIMIT=0 */
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
4187
    (void)drizzle_query_str(local_con, &result,
4188
                            "select @@version_comment limit 1", &ret);
928.1.1 by Eric Day
Started client changes.
4189
    if (ret == DRIZZLE_RETURN_OK &&
4190
        drizzle_result_buffer(&result) == DRIZZLE_RETURN_OK)
1 by brian
clean slate
4191
    {
928.1.1 by Eric Day
Started client changes.
4192
      drizzle_row_t cur = drizzle_row_next(&result);
1 by brian
clean slate
4193
      if (cur && cur[0])
4194
      {
534 by Monty Taylor
Removed stxnmov. Also deleted strstr which had already been removed.
4195
        buf.append(" ");
928.1.4 by Eric Day
Fixed a few bugs, more progress on conversion.
4196
        buf.append(cur[0]);
1 by brian
clean slate
4197
      }
928.1.1 by Eric Day
Started client changes.
4198
      drizzle_result_free(&result);
1 by brian
clean slate
4199
    }
928.1.4 by Eric Day
Fixed a few bugs, more progress on conversion.
4200
    else if (ret == DRIZZLE_RETURN_ERROR_CODE)
4201
      drizzle_result_free(&result);
1 by brian
clean slate
4202
  }
4203
534 by Monty Taylor
Removed stxnmov. Also deleted strstr which had already been removed.
4204
  return buf.c_str();
1 by brian
clean slate
4205
}
4206
4207
static int
893 by Brian Aker
First pass of stripping uint
4208
put_info(const char *str,INFO_TYPE info_type, uint32_t error, const char *sqlstate)
1 by brian
clean slate
4209
{
4210
  FILE *file= (info_type == INFO_ERROR ? stderr : stdout);
4211
  static int inited=0;
4212
1441.3.1 by Vijay Samuel
all required updations have been made
4213
  if (status.getBatch())
1 by brian
clean slate
4214
  {
4215
    if (info_type == INFO_ERROR)
4216
    {
4217
      (void) fflush(file);
4218
      fprintf(file,"ERROR");
4219
      if (error)
4220
      {
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4221
        if (sqlstate)
4222
          (void) fprintf(file," %d (%s)",error, sqlstate);
1 by brian
clean slate
4223
        else
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4224
          (void) fprintf(file," %d",error);
1 by brian
clean slate
4225
      }
1441.3.1 by Vijay Samuel
all required updations have been made
4226
      if (status.getQueryStartLine() && line_numbers)
1 by brian
clean slate
4227
      {
1441.3.1 by Vijay Samuel
all required updations have been made
4228
        (void) fprintf(file," at line %"PRIu32,status.getQueryStartLine());
4229
        if (status.getFileName())
4230
          (void) fprintf(file," in file: '%s'", status.getFileName());
1 by brian
clean slate
4231
      }
4232
      (void) fprintf(file,": %s\n",str);
4233
      (void) fflush(file);
4234
      if (!ignore_errors)
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4235
        return 1;
1 by brian
clean slate
4236
    }
4237
    else if (info_type == INFO_RESULT && verbose > 1)
4238
      tee_puts(str, file);
4239
    if (unbuffered)
4240
      fflush(file);
4241
    return info_type == INFO_ERROR ? -1 : 0;
4242
  }
4243
  if (!opt_silent || info_type == INFO_ERROR)
4244
  {
4245
    if (!inited)
4246
    {
4247
      inited=1;
4248
#ifdef HAVE_SETUPTERM
4249
      (void) setupterm((char *)0, 1, (int *) 0);
4250
#endif
4251
    }
4252
    if (info_type == INFO_ERROR)
4253
    {
4254
      if (!opt_nobeep)
77.3.7 by Monty Taylor
Made mysql into a pure-C program.
4255
        /* This should make a bell */
4256
        putchar('\a');
1 by brian
clean slate
4257
      vidattr(A_STANDOUT);
4258
      if (error)
4259
      {
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4260
        if (sqlstate)
1 by brian
clean slate
4261
          (void) tee_fprintf(file, "ERROR %d (%s): ", error, sqlstate);
4262
        else
4263
          (void) tee_fprintf(file, "ERROR %d: ", error);
4264
      }
4265
      else
4266
        tee_puts("ERROR: ", file);
4267
    }
4268
    else
4269
      vidattr(A_BOLD);
4270
    (void) tee_puts(str, file);
4271
    vidattr(A_NORMAL);
4272
  }
4273
  if (unbuffered)
4274
    fflush(file);
4275
  return info_type == INFO_ERROR ? -1 : 0;
4276
}
4277
4278
4279
static int
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
4280
put_error(drizzle_con_st *local_con, drizzle_result_st *res)
1 by brian
clean slate
4281
{
928.1.4 by Eric Day
Fixed a few bugs, more progress on conversion.
4282
  const char *error;
4283
4284
  if (res != NULL)
4285
  {
4286
    error= drizzle_result_error(res);
4287
    if (!strcmp(error, ""))
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
4288
      error= drizzle_con_error(local_con);
928.1.4 by Eric Day
Fixed a few bugs, more progress on conversion.
4289
  }
4290
  else
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
4291
    error= drizzle_con_error(local_con);
928.1.4 by Eric Day
Fixed a few bugs, more progress on conversion.
4292
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
4293
  return put_info(error, INFO_ERROR,
928.1.8 by Eric Day
All tests now passing now, fixed a few more client utility bugs.
4294
                  res == NULL ? drizzle_con_error_code(local_con) :
1441.3.1 by Vijay Samuel
all required updations have been made
4295
                                drizzle_result_error_code(res),
928.1.8 by Eric Day
All tests now passing now, fixed a few more client utility bugs.
4296
                  res == NULL ? drizzle_con_sqlstate(local_con) :
1441.3.1 by Vijay Samuel
all required updations have been made
4297
                                drizzle_result_sqlstate(res));
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4298
}
1 by brian
clean slate
4299
4300
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
4301
static void remove_cntrl(string *buffer)
1 by brian
clean slate
4302
{
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
4303
  const char *start=  buffer->c_str();
4304
  const char *end= start + (buffer->length());
1 by brian
clean slate
4305
  while (start < end && !my_isgraph(charset_info,end[-1]))
4306
    end--;
893 by Brian Aker
First pass of stripping uint
4307
  uint32_t pos_to_truncate= (end-start);
287.3.17 by Monty Taylor
Fixed null-query problem.
4308
  if (buffer->length() > pos_to_truncate)
4309
    buffer->erase(pos_to_truncate);
1 by brian
clean slate
4310
}
4311
4312
4313
void tee_fprintf(FILE *file, const char *fmt, ...)
4314
{
4315
  va_list args;
4316
4317
  va_start(args, fmt);
4318
  (void) vfprintf(file, fmt, args);
4319
  va_end(args);
4320
4321
  if (opt_outfile)
4322
  {
4323
    va_start(args, fmt);
4324
    (void) vfprintf(OUTFILE, fmt, args);
4325
    va_end(args);
4326
  }
4327
}
4328
4329
4330
void tee_fputs(const char *s, FILE *file)
4331
{
4332
  fputs(s, file);
4333
  if (opt_outfile)
4334
    fputs(s, OUTFILE);
4335
}
4336
4337
4338
void tee_puts(const char *s, FILE *file)
4339
{
4340
  fputs(s, file);
4341
  fputc('\n', file);
4342
  if (opt_outfile)
4343
  {
4344
    fputs(s, OUTFILE);
4345
    fputc('\n', OUTFILE);
4346
  }
4347
}
4348
4349
void tee_putc(int c, FILE *file)
4350
{
4351
  putc(c, file);
4352
  if (opt_outfile)
4353
    putc(c, OUTFILE);
4354
}
4355
4356
#include <sys/times.h>
206.3.1 by Patrick Galbraith
Most everything working with client rename
4357
#ifdef _SC_CLK_TCK        // For mit-pthreads
1 by brian
clean slate
4358
#undef CLOCKS_PER_SEC
4359
#define CLOCKS_PER_SEC (sysconf(_SC_CLK_TCK))
4360
#endif
4361
288 by Brian Aker
ulong cleanp in client apps
4362
static uint32_t start_timer(void)
1 by brian
clean slate
4363
{
4364
  struct tms tms_tmp;
4365
  return times(&tms_tmp);
4366
}
4367
4368
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4369
/**
1441.3.1 by Vijay Samuel
all required updations have been made
4370
   Write as many as 52+1 bytes to buff, in the form of a legible
4371
   duration of time.
1 by brian
clean slate
4372
1441.3.1 by Vijay Samuel
all required updations have been made
4373
   len("4294967296 days, 23 hours, 59 minutes, 60.00 seconds")  ->  52
1 by brian
clean slate
4374
*/
4375
static void nice_time(double sec,char *buff,bool part_second)
4376
{
288 by Brian Aker
ulong cleanp in client apps
4377
  uint32_t tmp;
971.1.77 by Monty Taylor
Removed mysys/mystrings things from client/ progs. Still need to get rid of my_getopt, but I think that's all now.
4378
  ostringstream tmp_buff_str;
4379
1 by brian
clean slate
4380
  if (sec >= 3600.0*24)
4381
  {
288 by Brian Aker
ulong cleanp in client apps
4382
    tmp=(uint32_t) floor(sec/(3600.0*24));
641.4.1 by Toru Maesaka
First pass of replacing MySQL's my_stpcpy() with appropriate libc calls
4383
    sec-= 3600.0*24*tmp;
971.1.77 by Monty Taylor
Removed mysys/mystrings things from client/ progs. Still need to get rid of my_getopt, but I think that's all now.
4384
    tmp_buff_str << tmp;
641.4.1 by Toru Maesaka
First pass of replacing MySQL's my_stpcpy() with appropriate libc calls
4385
4386
    if (tmp > 1)
971.1.77 by Monty Taylor
Removed mysys/mystrings things from client/ progs. Still need to get rid of my_getopt, but I think that's all now.
4387
      tmp_buff_str << " days ";
641.4.1 by Toru Maesaka
First pass of replacing MySQL's my_stpcpy() with appropriate libc calls
4388
    else
971.1.77 by Monty Taylor
Removed mysys/mystrings things from client/ progs. Still need to get rid of my_getopt, but I think that's all now.
4389
      tmp_buff_str << " day ";
641.4.1 by Toru Maesaka
First pass of replacing MySQL's my_stpcpy() with appropriate libc calls
4390
1 by brian
clean slate
4391
  }
4392
  if (sec >= 3600.0)
4393
  {
288 by Brian Aker
ulong cleanp in client apps
4394
    tmp=(uint32_t) floor(sec/3600.0);
1 by brian
clean slate
4395
    sec-=3600.0*tmp;
971.1.77 by Monty Taylor
Removed mysys/mystrings things from client/ progs. Still need to get rid of my_getopt, but I think that's all now.
4396
    tmp_buff_str << tmp;
641.4.1 by Toru Maesaka
First pass of replacing MySQL's my_stpcpy() with appropriate libc calls
4397
4398
    if (tmp > 1)
971.1.77 by Monty Taylor
Removed mysys/mystrings things from client/ progs. Still need to get rid of my_getopt, but I think that's all now.
4399
      tmp_buff_str << " hours ";
641.4.1 by Toru Maesaka
First pass of replacing MySQL's my_stpcpy() with appropriate libc calls
4400
    else
971.1.77 by Monty Taylor
Removed mysys/mystrings things from client/ progs. Still need to get rid of my_getopt, but I think that's all now.
4401
      tmp_buff_str << " hour ";
1 by brian
clean slate
4402
  }
4403
  if (sec >= 60.0)
4404
  {
288 by Brian Aker
ulong cleanp in client apps
4405
    tmp=(uint32_t) floor(sec/60.0);
1 by brian
clean slate
4406
    sec-=60.0*tmp;
971.1.77 by Monty Taylor
Removed mysys/mystrings things from client/ progs. Still need to get rid of my_getopt, but I think that's all now.
4407
    tmp_buff_str << tmp << " min ";
1 by brian
clean slate
4408
  }
4409
  if (part_second)
971.1.77 by Monty Taylor
Removed mysys/mystrings things from client/ progs. Still need to get rid of my_getopt, but I think that's all now.
4410
    tmp_buff_str.precision(2);
1 by brian
clean slate
4411
  else
971.1.77 by Monty Taylor
Removed mysys/mystrings things from client/ progs. Still need to get rid of my_getopt, but I think that's all now.
4412
    tmp_buff_str.precision(0);
4413
  tmp_buff_str << sec << " sec";
4414
  strcpy(buff, tmp_buff_str.str().c_str());
1 by brian
clean slate
4415
}
4416
4417
288 by Brian Aker
ulong cleanp in client apps
4418
static void end_timer(uint32_t start_time,char *buff)
1 by brian
clean slate
4419
{
4420
  nice_time((double) (start_timer() - start_time) /
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4421
            CLOCKS_PER_SEC,buff,1);
1 by brian
clean slate
4422
}
4423
4424
288 by Brian Aker
ulong cleanp in client apps
4425
static void drizzle_end_timer(uint32_t start_time,char *buff)
1 by brian
clean slate
4426
{
4427
  buff[0]=' ';
4428
  buff[1]='(';
4429
  end_timer(start_time,buff+2);
641.4.1 by Toru Maesaka
First pass of replacing MySQL's my_stpcpy() with appropriate libc calls
4430
  strcpy(strchr(buff, '\0'),")");
1 by brian
clean slate
4431
}
4432
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4433
static const char * construct_prompt()
1 by brian
clean slate
4434
{
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4435
  // Erase the old prompt
77.3.3 by Monty Taylor
Last change to migrate to glib from sql_string.
4436
  assert(processed_prompt!=NULL);
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
4437
  processed_prompt->clear();
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4438
4439
  // Get the date struct
4440
  time_t  lclock = time(NULL);
1 by brian
clean slate
4441
  struct tm *t = localtime(&lclock);
4442
4443
  /* parse thru the settings for the prompt */
77.3.7 by Monty Taylor
Made mysql into a pure-C program.
4444
  for (char *c= current_prompt; *c; (void)*c++)
1 by brian
clean slate
4445
  {
4446
    if (*c != PROMPT_CHAR)
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4447
    {
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
4448
      processed_prompt->append(c, 1);
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4449
    }
1 by brian
clean slate
4450
    else
4451
    {
77.3.7 by Monty Taylor
Made mysql into a pure-C program.
4452
      int getHour;
4453
      int getYear;
971.4.1 by Monty Taylor
GCC on Solaris build fixes.
4454
      /* Room for Dow MMM DD HH:MM:SS YYYY */ 
4455
      char dateTime[32];
1 by brian
clean slate
4456
      switch (*++c) {
4457
      case '\0':
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4458
        // stop it from going beyond if ends with %
4459
        c--;
4460
        break;
1 by brian
clean slate
4461
      case 'c':
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4462
        add_int_to_prompt(++prompt_counter);
4463
        break;
1 by brian
clean slate
4464
      case 'v':
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4465
        if (connected)
928.1.3 by Eric Day
More changes towards getting the client utilities converted.
4466
          processed_prompt->append(drizzle_con_server_version(&con));
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4467
        else
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
4468
          processed_prompt->append("not_connected");
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4469
        break;
1 by brian
clean slate
4470
      case 'd':
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
4471
        processed_prompt->append(current_db ? current_db : "(none)");
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4472
        break;
1 by brian
clean slate
4473
      case 'h':
1441.3.1 by Vijay Samuel
all required updations have been made
4474
      {
4475
        const char *prompt;
4476
        prompt= connected ? drizzle_con_host(&con) : "not_connected";
4477
        if (strstr(prompt, "Localhost"))
4478
          processed_prompt->append("localhost");
4479
        else
4480
        {
4481
          const char *end=strrchr(prompt,' ');
4482
          if (end != NULL)
4483
            processed_prompt->append(prompt, (end-prompt));
4484
        }
4485
        break;
4486
      }
4487
      case 'p':
4488
      {
4489
        if (!connected)
4490
        {
4491
          processed_prompt->append("not_connected");
1407 by Brian Aker
Merge Siddharth, ran formatting across it.
4492
          break;
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4493
        }
1441.3.1 by Vijay Samuel
all required updations have been made
4494
4495
        if (drizzle_con_uds(&con))
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4496
        {
1441.3.1 by Vijay Samuel
all required updations have been made
4497
          const char *pos=strrchr(drizzle_con_uds(&con),'/');
4498
          processed_prompt->append(pos ? pos+1 : drizzle_con_uds(&con));
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4499
        }
1441.3.1 by Vijay Samuel
all required updations have been made
4500
        else
4501
          add_int_to_prompt(drizzle_con_port(&con));
4502
      }
4503
      break;
1 by brian
clean slate
4504
      case 'U':
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4505
        if (!full_username)
4506
          init_username();
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
4507
        processed_prompt->append(full_username ? full_username :
4508
                                 (current_user ?  current_user : "(unknown)"));
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4509
        break;
1 by brian
clean slate
4510
      case 'u':
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4511
        if (!full_username)
4512
          init_username();
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
4513
        processed_prompt->append(part_username ? part_username :
4514
                                 (current_user ?  current_user : "(unknown)"));
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4515
        break;
1 by brian
clean slate
4516
      case PROMPT_CHAR:
182.1.2 by Jim Winstead
Various fixes to enable compilation on Mac OS X, and remove the glib dependency.
4517
        {
632.1.12 by Monty Taylor
Fixed more sun studio warnings.
4518
          processed_prompt->append(PROMPT_CHAR, 1);
182.1.2 by Jim Winstead
Various fixes to enable compilation on Mac OS X, and remove the glib dependency.
4519
        }
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4520
        break;
1 by brian
clean slate
4521
      case 'n':
182.1.2 by Jim Winstead
Various fixes to enable compilation on Mac OS X, and remove the glib dependency.
4522
        {
632.1.12 by Monty Taylor
Fixed more sun studio warnings.
4523
          processed_prompt->append('\n', 1);
182.1.2 by Jim Winstead
Various fixes to enable compilation on Mac OS X, and remove the glib dependency.
4524
        }
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4525
        break;
1 by brian
clean slate
4526
      case ' ':
4527
      case '_':
182.1.2 by Jim Winstead
Various fixes to enable compilation on Mac OS X, and remove the glib dependency.
4528
        {
632.1.12 by Monty Taylor
Fixed more sun studio warnings.
4529
          processed_prompt->append(' ', 1);
182.1.2 by Jim Winstead
Various fixes to enable compilation on Mac OS X, and remove the glib dependency.
4530
        }
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4531
        break;
1 by brian
clean slate
4532
      case 'R':
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4533
        if (t->tm_hour < 10)
182.1.2 by Jim Winstead
Various fixes to enable compilation on Mac OS X, and remove the glib dependency.
4534
          add_int_to_prompt(0);
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4535
        add_int_to_prompt(t->tm_hour);
4536
        break;
1 by brian
clean slate
4537
      case 'r':
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4538
        getHour = t->tm_hour % 12;
4539
        if (getHour == 0)
4540
          getHour=12;
4541
        if (getHour < 10)
182.1.2 by Jim Winstead
Various fixes to enable compilation on Mac OS X, and remove the glib dependency.
4542
          add_int_to_prompt(0);
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4543
        add_int_to_prompt(getHour);
4544
        break;
1 by brian
clean slate
4545
      case 'm':
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4546
        if (t->tm_min < 10)
182.1.2 by Jim Winstead
Various fixes to enable compilation on Mac OS X, and remove the glib dependency.
4547
          add_int_to_prompt(0);
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4548
        add_int_to_prompt(t->tm_min);
4549
        break;
1 by brian
clean slate
4550
      case 'y':
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4551
        getYear = t->tm_year % 100;
4552
        if (getYear < 10)
182.1.2 by Jim Winstead
Various fixes to enable compilation on Mac OS X, and remove the glib dependency.
4553
          add_int_to_prompt(0);
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4554
        add_int_to_prompt(getYear);
4555
        break;
1 by brian
clean slate
4556
      case 'Y':
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4557
        add_int_to_prompt(t->tm_year+1900);
4558
        break;
1 by brian
clean slate
4559
      case 'D':
971.4.1 by Monty Taylor
GCC on Solaris build fixes.
4560
        strftime(dateTime, 32, "%a %b %d %H:%M:%S %Y", localtime(&lclock));
4561
        processed_prompt->append(dateTime);
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4562
        break;
1 by brian
clean slate
4563
      case 's':
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4564
        if (t->tm_sec < 10)
182.1.2 by Jim Winstead
Various fixes to enable compilation on Mac OS X, and remove the glib dependency.
4565
          add_int_to_prompt(0);
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4566
        add_int_to_prompt(t->tm_sec);
4567
        break;
1 by brian
clean slate
4568
      case 'w':
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
4569
        processed_prompt->append(day_names[t->tm_wday]);
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4570
        break;
1 by brian
clean slate
4571
      case 'P':
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
4572
        processed_prompt->append(t->tm_hour < 12 ? "am" : "pm");
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4573
        break;
1 by brian
clean slate
4574
      case 'o':
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4575
        add_int_to_prompt(t->tm_mon+1);
4576
        break;
1 by brian
clean slate
4577
      case 'O':
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
4578
        processed_prompt->append(month_names[t->tm_mon]);
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4579
        break;
1 by brian
clean slate
4580
      case '\'':
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
4581
        processed_prompt->append("'");
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4582
        break;
1 by brian
clean slate
4583
      case '"':
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
4584
        processed_prompt->append("\"");
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4585
        break;
1 by brian
clean slate
4586
      case 'S':
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
4587
        processed_prompt->append(";");
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4588
        break;
1 by brian
clean slate
4589
      case 't':
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
4590
        processed_prompt->append("\t");
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4591
        break;
1 by brian
clean slate
4592
      case 'l':
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
4593
        processed_prompt->append(delimiter_str);
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4594
        break;
1 by brian
clean slate
4595
      default:
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
4596
        processed_prompt->append(c, 1);
1 by brian
clean slate
4597
      }
4598
    }
4599
  }
279.2.2 by Monty Taylor
Replaced DYNAMIC_STRING with C++ string in drizzle command line client.
4600
  return processed_prompt->c_str();
1 by brian
clean slate
4601
}
4602
4603
4604
static void add_int_to_prompt(int toadd)
4605
{
971.1.77 by Monty Taylor
Removed mysys/mystrings things from client/ progs. Still need to get rid of my_getopt, but I think that's all now.
4606
  ostringstream buffer;
4607
  buffer << toadd;
4608
  processed_prompt->append(buffer.str().c_str());
1 by brian
clean slate
4609
}
4610
4611
static void init_username()
4612
{
1441.3.1 by Vijay Samuel
all required updations have been made
4613
/* XXX need this?
4614
  free(full_username);
4615
  free(part_username);
1 by brian
clean slate
4616
1441.3.1 by Vijay Samuel
all required updations have been made
4617
  drizzle_result_st *result;
4618
  if (!drizzleclient_query(&drizzle,"select USER()") &&
4619
      (result=drizzleclient_use_result(&drizzle)))
4620
  {
928.1.1 by Eric Day
Started client changes.
4621
    drizzle_row_t cur=drizzleclient_fetch_row(result);
182.1.2 by Jim Winstead
Various fixes to enable compilation on Mac OS X, and remove the glib dependency.
4622
    full_username= strdup(cur[0]);
4623
    part_username= strdup(strtok(cur[0],"@"));
840.1.21 by Monty Taylor
ZOMG. Renamed all the rest of the stuff in libdrizzleclient to be drizzleclient_*. I love commandline perl.
4624
    (void) drizzleclient_fetch_row(result);        // Read eof
1441.3.1 by Vijay Samuel
all required updations have been made
4625
  }
4626
*/
1 by brian
clean slate
4627
}
4628
632.1.12 by Monty Taylor
Fixed more sun studio warnings.
4629
static int com_prompt(string *, const char *line)
1 by brian
clean slate
4630
{
520.4.43 by mordred
A set of Solaris fixes.
4631
  const char *ptr=strchr(line, ' ');
656.1.51 by Monty Taylor
Fixed strdup return checking in client/
4632
  if (ptr == NULL)
77.3.2 by Monty Taylor
Got it compiling... now, too bad it doesn't work.
4633
    tee_fprintf(stdout, "Returning to default PROMPT of %s\n",
182.1.2 by Jim Winstead
Various fixes to enable compilation on Mac OS X, and remove the glib dependency.
4634
                default_prompt);
656.1.51 by Monty Taylor
Fixed strdup return checking in client/
4635
  prompt_counter = 0;
4636
  char * tmpptr= strdup(ptr ? ptr+1 : default_prompt);
4637
  if (tmpptr == NULL)
4638
    tee_fprintf(stdout, "Memory allocation error. Not changing prompt\n");
1 by brian
clean slate
4639
  else
656.1.51 by Monty Taylor
Fixed strdup return checking in client/
4640
  {
4641
    free(current_prompt);
4642
    current_prompt= tmpptr;
1 by brian
clean slate
4643
    tee_fprintf(stdout, "PROMPT set to '%s'\n", current_prompt);
656.1.51 by Monty Taylor
Fixed strdup return checking in client/
4644
  }
1 by brian
clean slate
4645
  return 0;
4646
}
266.6.1 by Andy Lester
merging from main
4647
4648
/*
1441.3.1 by Vijay Samuel
all required updations have been made
4649
    strcont(str, set) if str contanies any character in the string set.
4650
    The result is the position of the first found character in str, or NULL
4651
    if there isn't anything found.
266.6.1 by Andy Lester
merging from main
4652
*/
4653
4654
static const char * strcont(register const char *str, register const char *set)
4655
{
4656
  register const char * start = (const char *) set;
4657
4658
  while (*str)
4659
  {
4660
    while (*set)
4661
    {
4662
      if (*set++ == *str)
4663
        return ((const char*) str);
4664
    }
4665
    set=start; str++;
4666
  }
4667
  return NULL;
4668
} /* strcont */