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