~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/mysql.cc

  • Committer: Monty Taylor
  • Date: 2008-07-05 11:08:18 UTC
  • mto: This revision was merged to the branch mainline in revision 62.
  • Revision ID: monty@inaugust.com-20080705110818-xyc8ehdym3r7nf6t
Add Jay's test optoins at the target of make test.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
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
 
 */
20
 
 
21
 
/* drizzle command tool
 
1
/* Copyright (C) 2000-2008 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
/* mysql command tool
22
17
 * Commands compatible with mSQL by David J. Hughes
23
18
 *
24
19
 * Written by:
33
28
 *
34
29
 **/
35
30
 
36
 
#include "config.h"
37
 
 
38
 
#include <string>
39
 
 
40
31
#include "client_priv.h"
41
 
#include <mystrings/m_ctype.h>
 
32
#include <m_ctype.h>
42
33
#include <stdarg.h>
 
34
#include <my_dir.h>
43
35
#ifndef __GNU_LIBRARY__
44
 
#define __GNU_LIBRARY__          // Skip warnings in getopt.h
 
36
#define __GNU_LIBRARY__               // Skip warnings in getopt.h
45
37
#endif
46
 
#include <readline/history.h>
47
38
#include "my_readline.h"
48
39
#include <signal.h>
49
 
#include <sys/ioctl.h>
50
 
 
51
 
 
52
 
#if defined(HAVE_LOCALE_H)
 
40
#include <violite.h>
 
41
 
 
42
#if defined(USE_LIBEDIT_INTERFACE) && defined(HAVE_LOCALE_H)
53
43
#include <locale.h>
54
44
#endif
55
45
 
56
 
#include <libdrizzle/gettext.h>
57
 
 
58
46
const char *VER= "14.14";
59
47
 
60
48
/* Don't try to make a nice table if the data is too big */
61
 
#define MAX_COLUMN_LENGTH       (uint32_t)1024
 
49
#define MAX_COLUMN_LENGTH            1024
62
50
 
63
51
/* Buffer to hold 'version' and 'version_comment' */
64
52
#define MAX_SERVER_VERSION_LENGTH     128
65
53
 
66
 
/* Array of options to pass to libdrizzled */
 
54
/* Array of options to pass to libemysqld */
67
55
#define MAX_SERVER_ARGS               64
68
56
 
69
 
void* sql_alloc(unsigned size);       // Don't use drizzled alloc for these
 
57
void* sql_alloc(unsigned size);      // Don't use mysqld alloc for these
70
58
void sql_element_free(void *ptr);
71
 
 
72
 
 
 
59
#include "sql_string.h"
 
60
 
 
61
extern "C" {
73
62
#if defined(HAVE_CURSES_H) && defined(HAVE_TERM_H)
74
63
#include <curses.h>
75
 
#ifdef __sun
76
 
#undef clear
77
 
#undef erase
78
 
#endif
79
64
#include <term.h>
80
65
#else
81
66
#if defined(HAVE_TERMIOS_H)
84
69
#elif defined(HAVE_TERMBITS_H)
85
70
#include <termbits.h>
86
71
#elif defined(HAVE_ASM_TERMBITS_H) && (!defined __GLIBC__ || !(__GLIBC__ > 2 || __GLIBC__ == 2 && __GLIBC_MINOR__ > 0))
87
 
#include <asm/termbits.h>    // Standard linux
 
72
#include <asm/termbits.h>               // Standard linux
88
73
#endif
 
74
#undef VOID
89
75
#if defined(HAVE_TERMCAP_H)
90
76
#include <termcap.h>
91
77
#else
92
78
#ifdef HAVE_CURSES_H
93
79
#include <curses.h>
94
80
#endif
95
 
#undef SYSV        // hack to avoid syntax error
 
81
#undef SYSV                             // hack to avoid syntax error
96
82
#ifdef HAVE_TERM_H
97
83
#include <term.h>
98
84
#endif
101
87
 
102
88
#undef bcmp                             // Fix problem with new readline
103
89
 
104
 
#ifdef HAVE_READLINE_HISTORY_H
105
 
#include <readline/history.h>
106
 
#endif
107
90
#include <readline/readline.h>
108
 
 
109
 
/**
110
 
 Make the old readline interface look like the new one.
111
 
*/
112
 
#ifndef USE_NEW_READLINE_INTERFACE
113
 
typedef CPPFunction rl_completion_func_t;
114
 
typedef Function rl_compentry_func_t;
115
 
#define rl_completion_matches(str, func) \
116
 
  completion_matches((char *)str, (CPFunction *)func)
117
 
#endif
118
 
 
 
91
#define HAVE_READLINE
 
92
 
 
93
  //int vidattr(long unsigned int attrs);       // Was missing in sun curses
 
94
}
119
95
 
120
96
#if !defined(HAVE_VIDATTR)
121
97
#undef vidattr
122
 
#define vidattr(A) {}      // Can't get this to work
 
98
#define vidattr(A) {}                   // Can't get this to work
123
99
#endif
124
100
 
125
101
#ifdef FN_NO_CASE_SENCE
130
106
 
131
107
#include "completion_hash.h"
132
108
 
133
 
using namespace std;
134
 
 
135
109
#define PROMPT_CHAR '\\'
136
110
#define DEFAULT_DELIMITER ";"
137
111
 
138
112
typedef struct st_status
139
113
{
140
114
  int exit_status;
141
 
  uint32_t query_start_line;
 
115
  ulong query_start_line;
142
116
  char *file_name;
143
117
  LINE_BUFFER *line_buff;
144
118
  bool batch,add_to_history;
151
125
enum enum_info_type { INFO_INFO,INFO_ERROR,INFO_RESULT};
152
126
typedef enum enum_info_type INFO_TYPE;
153
127
 
154
 
static DRIZZLE drizzle;      /* The connection */
155
 
static bool ignore_errors=0,quick=0,
156
 
  connected=0,opt_raw_data=0,unbuffered=0,output_tables=0,
157
 
  opt_rehash=1,skip_updates=0,safe_updates=0,one_database=0,
158
 
  opt_compress=0, using_opt_local_infile=0,
159
 
  vertical=0, line_numbers=1, column_names=1,
160
 
  opt_nopager=1, opt_outfile=0, named_cmds= 0,
161
 
  tty_password= 0, opt_nobeep=0, opt_reconnect=1,
162
 
  default_charset_used= 0, opt_secure_auth= 0,
163
 
  default_pager_set= 0, opt_sigint_ignore= 0,
164
 
  auto_vertical_output= 0,
165
 
  show_warnings= 0, executing_query= 0, interrupted_query= 0;
166
 
static bool debug_info_flag, debug_check_flag;
167
 
static bool column_types_flag;
168
 
static bool preserve_comments= 0;
169
 
static uint32_t opt_max_allowed_packet, opt_net_buffer_length;
170
 
static int verbose=0,opt_silent=0,opt_drizzle_port=0, opt_local_infile=0;
 
128
static MYSQL mysql;                     /* The connection */
 
129
static my_bool ignore_errors=0,wait_flag=0,quick=0,
 
130
               connected=0,opt_raw_data=0,unbuffered=0,output_tables=0,
 
131
               opt_rehash=1,skip_updates=0,safe_updates=0,one_database=0,
 
132
               opt_compress=0, using_opt_local_infile=0,
 
133
               vertical=0, line_numbers=1, column_names=1,opt_html=0,
 
134
               opt_xml=0,opt_nopager=1, opt_outfile=0, named_cmds= 0,
 
135
               tty_password= 0, opt_nobeep=0, opt_reconnect=1,
 
136
               default_charset_used= 0, opt_secure_auth= 0,
 
137
               default_pager_set= 0, opt_sigint_ignore= 0,
 
138
               auto_vertical_output= 0,
 
139
               show_warnings= 0, executing_query= 0, interrupted_query= 0;
 
140
static my_bool debug_info_flag, debug_check_flag;
 
141
static my_bool column_types_flag;
 
142
static my_bool preserve_comments= 0;
 
143
static ulong opt_max_allowed_packet, opt_net_buffer_length;
 
144
static uint verbose=0,opt_silent=0,opt_mysql_port=0, opt_local_infile=0;
171
145
static uint my_end_arg;
172
 
static char * opt_drizzle_unix_port=0;
 
146
static char * opt_mysql_unix_port=0;
173
147
static int connect_flag=CLIENT_INTERACTIVE;
174
148
static char *current_host,*current_db,*current_user=0,*opt_password=0,
175
 
  *delimiter_str= 0,* current_prompt= 0;
 
149
            *current_prompt=0, *delimiter_str= 0,
 
150
            *default_charset= (char*) MYSQL_DEFAULT_CHARSET_NAME;
176
151
static char *histfile;
177
152
static char *histfile_tmp;
178
 
static string *glob_buffer;
179
 
static string *processed_prompt= NULL;
180
 
static char *default_prompt= NULL;
181
 
static char *full_username=0,*part_username=0;
 
153
static String glob_buffer,old_buffer;
 
154
static String processed_prompt;
 
155
static char *full_username=0,*part_username=0,*default_prompt=0;
 
156
static int wait_time = 5;
182
157
static STATUS status;
183
 
static uint32_t select_limit;
184
 
static uint32_t max_join_size;
185
 
static uint32_t opt_connect_timeout= 0;
186
 
static char drizzle_charsets_dir[FN_REFLEN+1];
187
 
// TODO: Need to i18n these
 
158
static ulong select_limit,max_join_size,opt_connect_timeout=0;
 
159
static char mysql_charsets_dir[FN_REFLEN+1];
 
160
static const char *xmlmeta[] = {
 
161
  "&", "&amp;",
 
162
  "<", "&lt;",
 
163
  ">", "&gt;",
 
164
  "\"", "&quot;",
 
165
  0, 0
 
166
};
188
167
static const char *day_names[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
189
168
static const char *month_names[]={"Jan","Feb","Mar","Apr","May","Jun","Jul",
190
 
                                  "Aug","Sep","Oct","Nov","Dec"};
 
169
                            "Aug","Sep","Oct","Nov","Dec"};
191
170
static char default_pager[FN_REFLEN];
192
171
static char pager[FN_REFLEN], outfile[FN_REFLEN];
193
172
static FILE *PAGER, *OUTFILE;
197
176
static uint delimiter_length= 1;
198
177
unsigned short terminal_width= 80;
199
178
 
200
 
static const CHARSET_INFO *charset_info= &my_charset_utf8_general_ci;
201
 
 
202
 
int drizzle_real_query_for_lazy(const char *buf, int length);
203
 
int drizzle_store_result_for_lazy(DRIZZLE_RES **result);
204
 
 
 
179
#ifdef HAVE_SMEM
 
180
static char *shared_memory_base_name=0;
 
181
#endif
 
182
static uint opt_protocol= MYSQL_PROTOCOL_TCP;
 
183
static CHARSET_INFO *charset_info= &my_charset_latin1;
 
184
 
 
185
const char *default_dbug_option="d:t:o,/tmp/mysql.trace";
205
186
 
206
187
void tee_fprintf(FILE *file, const char *fmt, ...);
207
188
void tee_fputs(const char *s, FILE *file);
210
191
static void tee_print_sized_data(const char *, unsigned int, unsigned int, bool);
211
192
/* The names of functions that actually do the manipulation. */
212
193
static int get_options(int argc,char **argv);
213
 
bool get_one_option(int optid, const struct my_option *opt,
214
 
                    char *argument);
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*),
222
 
  com_notee(string *str, const char*),
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*);
 
194
extern "C" my_bool get_one_option(int optid, const struct my_option *opt,
 
195
                                  char *argument);
 
196
static int com_quit(String *str,char*),
 
197
           com_go(String *str,char*), com_ego(String *str,char*),
 
198
           com_print(String *str,char*),
 
199
           com_help(String *str,char*), com_clear(String *str,char*),
 
200
           com_connect(String *str,char*), com_status(String *str,char*),
 
201
           com_use(String *str,char*), com_source(String *str, char*),
 
202
           com_rehash(String *str, char*), com_tee(String *str, char*),
 
203
           com_notee(String *str, char*), com_charset(String *str,char*),
 
204
           com_prompt(String *str, char*), com_delimiter(String *str, char*),
 
205
     com_warnings(String *str, char*), com_nowarnings(String *str, char*);
 
206
 
 
207
#ifdef USE_POPEN
 
208
static int com_nopager(String *str, char*), com_pager(String *str, char*),
 
209
           com_edit(String *str,char*), com_shell(String *str, char *);
 
210
#endif
226
211
 
227
212
static int read_and_execute(bool interactive);
228
213
static int sql_connect(char *host,char *database,char *user,char *password,
229
 
                       uint silent);
230
 
static const char *server_version_string(DRIZZLE *drizzle);
231
 
static int put_info(const char *str,INFO_TYPE info,uint error,
232
 
                    const char *sql_state);
233
 
static int put_error(DRIZZLE *drizzle);
234
 
static void safe_put_field(const char *pos,uint32_t length);
235
 
static void init_pager(void);
236
 
static void end_pager(void);
 
214
                       uint silent);
 
215
static const char *server_version_string(MYSQL *mysql);
 
216
static int put_info(const char *str,INFO_TYPE info,uint error=0,
 
217
                    const char *sql_state=0);
 
218
static int put_error(MYSQL *mysql);
 
219
static void safe_put_field(const char *pos,ulong length);
 
220
static void xmlencode_print(const char *src, uint length);
 
221
static void init_pager();
 
222
static void end_pager();
237
223
static void init_tee(const char *);
238
 
static void end_tee(void);
239
 
static const char* construct_prompt(void);
240
 
static char *get_arg(char *line, bool get_next_arg);
241
 
static void init_username(void);
 
224
static void end_tee();
 
225
static const char* construct_prompt();
 
226
static char *get_arg(char *line, my_bool get_next_arg);
 
227
static void init_username();
242
228
static void add_int_to_prompt(int toadd);
243
 
static int get_result_width(DRIZZLE_RES *res);
244
 
static int get_field_disp_length(DRIZZLE_FIELD * field);
245
 
static const char * strcont(register const char *str, register const char *set);
 
229
static int get_result_width(MYSQL_RES *res);
 
230
static int get_field_disp_length(MYSQL_FIELD * field);
246
231
 
247
232
/* A structure which contains information on the commands this program
248
233
   can understand. */
 
234
 
249
235
typedef struct {
250
 
  const char *name;        /* User printable name of the function. */
251
 
  char cmd_char;        /* msql command character */
252
 
  int (*func)(string *str,const char *); /* Function to call to do the job. */
253
 
  bool takes_params;        /* Max parameters for command */
254
 
  const char *doc;        /* Documentation for this function.  */
 
236
  const char *name;             /* User printable name of the function. */
 
237
  char cmd_char;                /* msql command character */
 
238
  int (*func)(String *str,char *); /* Function to call to do the job. */
 
239
  bool takes_params;            /* Max parameters for command */
 
240
  const char *doc;              /* Documentation for this function.  */
255
241
} COMMANDS;
256
242
 
257
 
 
258
243
static COMMANDS commands[] = {
259
 
  { "?",      '?', com_help,   1, N_("Synonym for `help'.") },
260
 
  { "clear",  'c', com_clear,  0, N_("Clear command.")},
 
244
  { "?",      '?', com_help,   1, "Synonym for `help'." },
 
245
  { "clear",  'c', com_clear,  0, "Clear command."},
261
246
  { "connect",'r', com_connect,1,
262
 
    N_("Reconnect to the server. Optional arguments are db and host." }),
 
247
    "Reconnect to the server. Optional arguments are db and host." },
263
248
  { "delimiter", 'd', com_delimiter,    1,
264
 
    N_("Set statement delimiter. NOTE: Takes the rest of the line as new delimiter.") },
 
249
    "Set statement delimiter. NOTE: Takes the rest of the line as new delimiter." },
 
250
#ifdef USE_POPEN
 
251
  { "edit",   'e', com_edit,   0, "Edit command with $EDITOR."},
 
252
#endif
265
253
  { "ego",    'G', com_ego,    0,
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.") },
272
 
  { "pager",  'P', com_pager,  1,
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.") },
 
254
    "Send command to mysql server, display result vertically."},
 
255
  { "exit",   'q', com_quit,   0, "Exit mysql. Same as quit."},
 
256
  { "go",     'g', com_go,     0, "Send command to mysql server." },
 
257
  { "help",   'h', com_help,   1, "Display this help." },
 
258
#ifdef USE_POPEN
 
259
  { "nopager",'n', com_nopager,0, "Disable pager, print to stdout." },
 
260
#endif
 
261
  { "notee",  't', com_notee,  0, "Don't write into outfile." },
 
262
#ifdef USE_POPEN
 
263
  { "pager",  'P', com_pager,  1, 
 
264
    "Set PAGER [to_pager]. Print the query results via PAGER." },
 
265
#endif
 
266
  { "print",  'p', com_print,  0, "Print current command." },
 
267
  { "prompt", 'R', com_prompt, 1, "Change your mysql prompt."},
 
268
  { "quit",   'q', com_quit,   0, "Quit mysql." },
 
269
  { "rehash", '#', com_rehash, 0, "Rebuild completion hash." },
278
270
  { "source", '.', com_source, 1,
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.")},
281
 
  { "tee",    'T', com_tee,    1,
282
 
    N_("Set outfile [to_outfile]. Append everything into given outfile.") },
 
271
    "Execute an SQL script file. Takes a file name as an argument."},
 
272
  { "status", 's', com_status, 0, "Get status information from the server."},
 
273
#ifdef USE_POPEN
 
274
  { "system", '!', com_shell,  1, "Execute a system shell command."},
 
275
#endif
 
276
  { "tee",    'T', com_tee,    1, 
 
277
    "Set outfile [to_outfile]. Append everything into given outfile." },
283
278
  { "use",    'u', com_use,    1,
284
 
    N_("Use another database. Takes database name as argument.") },
 
279
    "Use another database. Takes database name as argument." },
 
280
  { "charset",    'C', com_charset,    1,
 
281
    "Switch to another charset. Might be needed for processing binlog with multi-byte charsets." },
285
282
  { "warnings", 'W', com_warnings,  0,
286
 
    N_("Show warnings after every statement.") },
 
283
    "Show warnings after every statement." },
287
284
  { "nowarning", 'w', com_nowarnings, 0,
288
 
    N_("Don't show warnings after every statement.") },
 
285
    "Don't show warnings after every statement." },
289
286
  /* Get bash-like expansion for some commands */
290
287
  { "create table",     0, 0, 0, ""},
291
288
  { "create database",  0, 0, 0, ""},
386
383
  { "DAY_MICROSECOND", 0, 0, 0, ""},
387
384
  { "DAY_MINUTE", 0, 0, 0, ""},
388
385
  { "DAY_SECOND", 0, 0, 0, ""},
389
 
  { "DEALLOCATE", 0, 0, 0, ""},
 
386
  { "DEALLOCATE", 0, 0, 0, ""},     
390
387
  { "DEC", 0, 0, 0, ""},
391
388
  { "DECIMAL", 0, 0, 0, ""},
392
389
  { "DECLARE", 0, 0, 0, ""},
451
448
  { "FULL", 0, 0, 0, ""},
452
449
  { "FULLTEXT", 0, 0, 0, ""},
453
450
  { "FUNCTION", 0, 0, 0, ""},
 
451
  { "GEOMETRY", 0, 0, 0, ""},
 
452
  { "GEOMETRYCOLLECTION", 0, 0, 0, ""},
454
453
  { "GET_FORMAT", 0, 0, 0, ""},
455
454
  { "GLOBAL", 0, 0, 0, ""},
456
455
  { "GRANT", 0, 0, 0, ""},
519
518
  { "LOCKS", 0, 0, 0, ""},
520
519
  { "LOGS", 0, 0, 0, ""},
521
520
  { "LONG", 0, 0, 0, ""},
 
521
  { "LONGBLOB", 0, 0, 0, ""},
522
522
  { "LONGTEXT", 0, 0, 0, ""},
523
523
  { "LOOP", 0, 0, 0, ""},
524
524
  { "LOW_PRIORITY", 0, 0, 0, ""},
544
544
  { "MAX_UPDATES_PER_HOUR", 0, 0, 0, ""},
545
545
  { "MAX_USER_CONNECTIONS", 0, 0, 0, ""},
546
546
  { "MEDIUM", 0, 0, 0, ""},
 
547
  { "MEDIUMBLOB", 0, 0, 0, ""},
 
548
  { "MEDIUMINT", 0, 0, 0, ""},
547
549
  { "MEDIUMTEXT", 0, 0, 0, ""},
548
550
  { "MERGE", 0, 0, 0, ""},
549
551
  { "MICROSECOND", 0, 0, 0, ""},
610
612
  { "QUARTER", 0, 0, 0, ""},
611
613
  { "QUERY", 0, 0, 0, ""},
612
614
  { "QUICK", 0, 0, 0, ""},
 
615
  { "RAID0", 0, 0, 0, ""},
 
616
  { "RAID_CHUNKS", 0, 0, 0, ""},
 
617
  { "RAID_CHUNKSIZE", 0, 0, 0, ""},
 
618
  { "RAID_TYPE", 0, 0, 0, ""},
613
619
  { "READ", 0, 0, 0, ""},
614
620
  { "READS", 0, 0, 0, ""},
615
621
  { "REAL", 0, 0, 0, ""},
715
721
  { "TIMESTAMP", 0, 0, 0, ""},
716
722
  { "TIMESTAMPADD", 0, 0, 0, ""},
717
723
  { "TIMESTAMPDIFF", 0, 0, 0, ""},
 
724
  { "TINYBLOB", 0, 0, 0, ""},
718
725
  { "TINYINT", 0, 0, 0, ""},
719
726
  { "TINYTEXT", 0, 0, 0, ""},
720
727
  { "TO", 0, 0, 0, ""},
843
850
  { "FROM_DAYS", 0, 0, 0, ""},
844
851
  { "FROM_UNIXTIME", 0, 0, 0, ""},
845
852
  { "GET_LOCK", 0, 0, 0, ""},
 
853
  { "GEOMETRYN", 0, 0, 0, ""},
 
854
  { "GEOMETRYTYPE", 0, 0, 0, ""},
 
855
  { "GEOMCOLLFROMTEXT", 0, 0, 0, ""},
 
856
  { "GEOMCOLLFROMWKB", 0, 0, 0, ""},
 
857
  { "GEOMETRYCOLLECTIONFROMTEXT", 0, 0, 0, ""},
 
858
  { "GEOMETRYCOLLECTIONFROMWKB", 0, 0, 0, ""},
 
859
  { "GEOMETRYFROMTEXT", 0, 0, 0, ""},
 
860
  { "GEOMETRYFROMWKB", 0, 0, 0, ""},
 
861
  { "GEOMFROMTEXT", 0, 0, 0, ""},
 
862
  { "GEOMFROMWKB", 0, 0, 0, ""},
846
863
  { "GLENGTH", 0, 0, 0, ""},
847
864
  { "GREATEST", 0, 0, 0, ""},
848
865
  { "GROUP_CONCAT", 0, 0, 0, ""},
909
926
  { "NAME_CONST", 0, 0, 0, ""},
910
927
  { "NOW", 0, 0, 0, ""},
911
928
  { "NULLIF", 0, 0, 0, ""},
 
929
  { "NUMGEOMETRIES", 0, 0, 0, ""},
912
930
  { "NUMINTERIORRINGS", 0, 0, 0, ""},
913
931
  { "NUMPOINTS", 0, 0, 0, ""},
914
932
  { "OCTET_LENGTH", 0, 0, 0, ""},
992
1010
  { (char *)NULL,       0, 0, 0, ""}
993
1011
};
994
1012
 
995
 
static const char *load_default_groups[]= { "drizzle","client",0 };
996
 
 
997
 
int history_length;
 
1013
static const char *load_default_groups[]= { "mysql","client",0 };
 
1014
 
 
1015
static int         embedded_server_arg_count= 0;
 
1016
static char       *embedded_server_args[MAX_SERVER_ARGS];
 
1017
static const char *embedded_server_groups[]=
 
1018
{ "server", "embedded", "mysql_SERVER", 0 };
 
1019
 
 
1020
#ifdef HAVE_READLINE
 
1021
/*
 
1022
 HIST_ENTRY is defined for libedit, but not for the real readline
 
1023
 Need to redefine it for real readline to find it
 
1024
*/
 
1025
#if !defined(HAVE_HIST_ENTRY)
 
1026
typedef struct _hist_entry {
 
1027
  const char      *line;
 
1028
  const char      *data;
 
1029
} HIST_ENTRY; 
 
1030
#endif
 
1031
 
 
1032
extern "C" int add_history(const char *command); /* From readline directory */
 
1033
extern "C" int read_history(const char *command);
 
1034
extern "C" int write_history(const char *command);
 
1035
extern "C" HIST_ENTRY *history_get(int num);
 
1036
extern "C" int history_length;
998
1037
static int not_in_history(const char *line);
999
1038
static void initialize_readline (char *name);
1000
 
static void fix_history(string *final_command);
 
1039
static void fix_history(String *final_command);
 
1040
#endif
1001
1041
 
1002
 
static COMMANDS *find_command(const char *name,char cmd_name);
1003
 
static bool add_line(string *buffer,char *line,char *in_string,
 
1042
static COMMANDS *find_command(char *name,char cmd_name);
 
1043
static bool add_line(String &buffer,char *line,char *in_string,
1004
1044
                     bool *ml_comment);
1005
 
static void remove_cntrl(string *buffer);
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);
 
1045
static void remove_cntrl(String &buffer);
 
1046
static void print_table_data(MYSQL_RES *result);
 
1047
static void print_table_data_html(MYSQL_RES *result);
 
1048
static void print_table_data_xml(MYSQL_RES *result);
 
1049
static void print_tab_data(MYSQL_RES *result);
 
1050
static void print_table_data_vertically(MYSQL_RES *result);
1009
1051
static void print_warnings(void);
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);
 
1052
static ulong start_timer(void);
 
1053
static void end_timer(ulong start_time,char *buff);
 
1054
static void mysql_end_timer(ulong start_time,char *buff);
1013
1055
static void nice_time(double sec,char *buff,bool part_second);
1014
 
extern RETSIGTYPE drizzle_end(int sig);
1015
 
extern RETSIGTYPE handle_sigint(int sig);
 
1056
extern "C" sig_handler mysql_end(int sig);
 
1057
extern "C" sig_handler handle_sigint(int sig);
1016
1058
#if defined(HAVE_TERMIOS_H) && defined(GWINSZ_IN_SYS_IOCTL)
1017
 
static RETSIGTYPE window_resize(int sig);
 
1059
static sig_handler window_resize(int sig);
1018
1060
#endif
1019
1061
 
1020
1062
int main(int argc,char *argv[])
1021
1063
{
1022
1064
  char buff[80];
1023
1065
 
1024
 
#if defined(ENABLE_NLS)
1025
 
# if defined(HAVE_LOCALE_H)
1026
 
  setlocale(LC_ALL, "");
1027
 
# endif
1028
 
  bindtextdomain("drizzle", LOCALEDIR);
1029
 
  textdomain("drizzle");
1030
 
#endif
1031
 
 
1032
1066
  MY_INIT(argv[0]);
 
1067
  DBUG_ENTER("main");
 
1068
  DBUG_PROCESS(argv[0]);
 
1069
  
1033
1070
  delimiter_str= delimiter;
1034
 
  default_prompt= my_strdup(getenv("DRIZZLE_PS1") ?
1035
 
                            getenv("DRIZZLE_PS1") :
1036
 
                            "drizzle>> ", MYF(0));
1037
 
  current_prompt= my_strdup(default_prompt, MYF(0));
1038
 
  processed_prompt= new string();
1039
 
  processed_prompt->reserve(32);
1040
 
 
 
1071
  default_prompt = my_strdup(getenv("MYSQL_PS1") ? 
 
1072
                             getenv("MYSQL_PS1") : 
 
1073
                             "mysql> ",MYF(MY_WME));
 
1074
  current_prompt = my_strdup(default_prompt,MYF(MY_WME));
1041
1075
  prompt_counter=0;
1042
1076
 
1043
 
  outfile[0]=0;      // no (default) outfile
1044
 
  my_stpcpy(pager, "stdout");  // the default, if --pager wasn't given
 
1077
  outfile[0]=0;                 // no (default) outfile
 
1078
  strmov(pager, "stdout");      // the default, if --pager wasn't given
1045
1079
  {
1046
1080
    char *tmp=getenv("PAGER");
1047
1081
    if (tmp && strlen(tmp))
1048
1082
    {
1049
1083
      default_pager_set= 1;
1050
 
      my_stpcpy(default_pager, tmp);
 
1084
      strmov(default_pager, tmp);
1051
1085
    }
1052
1086
  }
1053
1087
  if (!isatty(0) || !isatty(1))
1060
1094
  status.exit_status=1;
1061
1095
 
1062
1096
  {
1063
 
    /*
1064
 
      The file descriptor-layer may be out-of-sync with the file-number layer,
1065
 
      so we make sure that "stdout" is really open.  If its file is closed then
1066
 
      explicitly close the FD layer.
 
1097
    /* 
 
1098
     The file descriptor-layer may be out-of-sync with the file-number layer,
 
1099
     so we make sure that "stdout" is really open.  If its file is closed then
 
1100
     explicitly close the FD layer. 
1067
1101
    */
1068
1102
    int stdout_fileno_copy;
1069
1103
    stdout_fileno_copy= dup(fileno(stdout)); /* Okay if fileno fails. */
1088
1122
    my_end(0);
1089
1123
    exit(1);
1090
1124
  }
 
1125
  if (mysql_server_init(embedded_server_arg_count, embedded_server_args, 
 
1126
                        (char**) embedded_server_groups))
 
1127
  {
 
1128
    put_error(NULL);
 
1129
    free_defaults(defaults_argv);
 
1130
    my_end(0);
 
1131
    exit(1);
 
1132
  }
 
1133
  glob_buffer.realloc(512);
1091
1134
  completion_hash_init(&ht, 128);
1092
1135
  init_alloc_root(&hash_mem_root, 16384, 0);
1093
 
  memset(&drizzle, 0, sizeof(drizzle));
 
1136
  bzero((char*) &mysql, sizeof(mysql));
1094
1137
  if (sql_connect(current_host,current_db,current_user,opt_password,
1095
 
                  opt_silent))
 
1138
                  opt_silent))
1096
1139
  {
1097
 
    quick= 1;          // Avoid history
 
1140
    quick= 1;                                   // Avoid history
1098
1141
    status.exit_status= 1;
1099
 
    drizzle_end(-1);
 
1142
    mysql_end(-1);
1100
1143
  }
1101
1144
  if (!status.batch)
1102
 
    ignore_errors=1;        // Don't abort monitor
 
1145
    ignore_errors=1;                            // Don't abort monitor
1103
1146
 
1104
1147
  if (opt_sigint_ignore)
1105
1148
    signal(SIGINT, SIG_IGN);
1106
1149
  else
1107
1150
    signal(SIGINT, handle_sigint);              // Catch SIGINT to clean up
1108
 
  signal(SIGQUIT, drizzle_end);      // Catch SIGQUIT to clean up
 
1151
  signal(SIGQUIT, mysql_end);                   // Catch SIGQUIT to clean up
1109
1152
 
1110
1153
#if defined(HAVE_TERMIOS_H) && defined(GWINSZ_IN_SYS_IOCTL)
1111
1154
  /* Readline will call this if it installs a handler */
1114
1157
  window_resize(0);
1115
1158
#endif
1116
1159
 
1117
 
  put_info(_("Welcome to the Drizzle client..  Commands end with ; or \\g."),
1118
 
           INFO_INFO,0,0);
1119
 
 
1120
 
  glob_buffer= new string();
1121
 
  glob_buffer->reserve(512);
1122
 
  
1123
 
  char * output_buff= (char *)malloc(512);
1124
 
  memset(output_buff, '\0', 512);
1125
 
 
1126
 
  sprintf(output_buff,
1127
 
          _("Your Drizzle connection id is %u\nServer version: %s\n"),
1128
 
          drizzle_thread_id(&drizzle),
1129
 
          server_version_string(&drizzle));
1130
 
  put_info(output_buff, INFO_INFO, 0, 0);
1131
 
 
1132
 
  initialize_readline(current_prompt);
1133
 
  if (!status.batch && !quick)
 
1160
  put_info("Welcome to the MySQL monitor.  Commands end with ; or \\g.",
 
1161
           INFO_INFO);
 
1162
  sprintf((char*) glob_buffer.ptr(),
 
1163
          "Your MySQL connection id is %lu\nServer version: %s\n",
 
1164
          mysql_thread_id(&mysql), server_version_string(&mysql));
 
1165
  put_info((char*) glob_buffer.ptr(),INFO_INFO);
 
1166
 
 
1167
#ifdef HAVE_READLINE
 
1168
  initialize_readline((char*) my_progname);
 
1169
  if (!status.batch && !quick && !opt_html && !opt_xml)
1134
1170
  {
1135
 
    /* read-history from file, default ~/.drizzle_history*/
1136
 
    if (getenv("DRIZZLE_HISTFILE"))
1137
 
      histfile= strdup(getenv("DRIZZLE_HISTFILE"));
 
1171
    /* read-history from file, default ~/.mysql_history*/
 
1172
    if (getenv("MYSQL_HISTFILE"))
 
1173
      histfile=my_strdup(getenv("MYSQL_HISTFILE"),MYF(MY_WME));
1138
1174
    else if (getenv("HOME"))
1139
1175
    {
1140
1176
      histfile=(char*) my_malloc((uint) strlen(getenv("HOME"))
1141
 
                                 + (uint) strlen("/.drizzle_history")+2,
1142
 
                                 MYF(MY_WME));
 
1177
                                 + (uint) strlen("/.mysql_history")+2,
 
1178
                                 MYF(MY_WME));
1143
1179
      if (histfile)
1144
 
        sprintf(histfile,"%s/.drizzle_history",getenv("HOME"));
 
1180
        sprintf(histfile,"%s/.mysql_history",getenv("HOME"));
1145
1181
      char link_name[FN_REFLEN];
1146
1182
      if (my_readlink(link_name, histfile, 0) == 0 &&
1147
1183
          strncmp(link_name, "/dev/null", 10) == 0)
1148
1184
      {
1149
 
        /* The .drizzle_history file is a symlink to /dev/null, don't use it */
1150
 
        free(histfile);
 
1185
        /* The .mysql_history file is a symlink to /dev/null, don't use it */
 
1186
        my_free(histfile, MYF(MY_ALLOW_ZERO_PTR));
1151
1187
        histfile= 0;
1152
1188
      }
1153
1189
    }
1154
1190
    if (histfile)
1155
1191
    {
1156
1192
      if (verbose)
1157
 
        tee_fprintf(stdout, _("Reading history-file %s\n"),histfile);
 
1193
        tee_fprintf(stdout, "Reading history-file %s\n",histfile);
1158
1194
      read_history(histfile);
1159
1195
      if (!(histfile_tmp= (char*) my_malloc((uint) strlen(histfile) + 5,
1160
 
                                            MYF(MY_WME))))
 
1196
                                            MYF(MY_WME))))
1161
1197
      {
1162
 
        fprintf(stderr, _("Couldn't allocate memory for temp histfile!\n"));
1163
 
        exit(1);
 
1198
        fprintf(stderr, "Couldn't allocate memory for temp histfile!\n");
 
1199
        exit(1);
1164
1200
      }
1165
1201
      sprintf(histfile_tmp, "%s.TMP", histfile);
1166
1202
    }
1167
1203
  }
 
1204
#endif
1168
1205
  sprintf(buff, "%s",
1169
 
          _("Type 'help;' or '\\h' for help. Type '\\c' to clear the buffer.\n"));
1170
 
 
1171
 
  put_info(buff,INFO_INFO,0,0);
 
1206
#ifndef NOT_YET
 
1207
          "Type 'help;' or '\\h' for help. Type '\\c' to clear the buffer.\n");
 
1208
#else
 
1209
          "Type 'help [[%]function name[%]]' to get help on usage of function.\n");
 
1210
#endif
 
1211
  put_info(buff,INFO_INFO);
1172
1212
  status.exit_status= read_and_execute(!status.batch);
1173
1213
  if (opt_outfile)
1174
1214
    end_tee();
1175
 
  drizzle_end(0);
1176
 
 
1177
 
  return(0);        // Keep compiler happy
 
1215
  mysql_end(0);
 
1216
#ifndef _lint
 
1217
  DBUG_RETURN(0);                               // Keep compiler happy
 
1218
#endif
1178
1219
}
1179
1220
 
1180
 
RETSIGTYPE drizzle_end(int sig)
 
1221
sig_handler mysql_end(int sig)
1181
1222
{
1182
 
  drizzle_close(&drizzle);
1183
 
  if (!status.batch && !quick && histfile)
 
1223
  mysql_close(&mysql);
 
1224
#ifdef HAVE_READLINE
 
1225
  if (!status.batch && !quick && !opt_html && !opt_xml && histfile)
1184
1226
  {
1185
1227
    /* write-history */
1186
1228
    if (verbose)
1187
 
      tee_fprintf(stdout, _("Writing history-file %s\n"),histfile);
 
1229
      tee_fprintf(stdout, "Writing history-file %s\n",histfile);
1188
1230
    if (!write_history(histfile_tmp))
1189
1231
      my_rename(histfile_tmp, histfile, MYF(MY_WME));
1190
1232
  }
1192
1234
  completion_hash_free(&ht);
1193
1235
  free_root(&hash_mem_root,MYF(0));
1194
1236
 
 
1237
#endif
1195
1238
  if (sig >= 0)
1196
 
    put_info(sig ? _("Aborted") : _("Bye"), INFO_RESULT,0,0);
1197
 
  if (glob_buffer)
1198
 
    delete glob_buffer;
1199
 
  if (processed_prompt)
1200
 
    delete processed_prompt;
1201
 
  free(opt_password);
1202
 
  free(opt_drizzle_unix_port);
1203
 
  free(histfile);
1204
 
  free(histfile_tmp);
1205
 
  free(current_db);
1206
 
  free(current_host);
1207
 
  free(current_user);
1208
 
  free(full_username);
1209
 
  free(part_username);
1210
 
  free(default_prompt);
1211
 
  free(current_prompt);
 
1239
    put_info(sig ? "Aborted" : "Bye", INFO_RESULT);
 
1240
  glob_buffer.free();
 
1241
  old_buffer.free();
 
1242
  processed_prompt.free();
 
1243
  my_free(opt_password,MYF(MY_ALLOW_ZERO_PTR));
 
1244
  my_free(opt_mysql_unix_port,MYF(MY_ALLOW_ZERO_PTR));
 
1245
  my_free(histfile,MYF(MY_ALLOW_ZERO_PTR));
 
1246
  my_free(histfile_tmp,MYF(MY_ALLOW_ZERO_PTR));
 
1247
  my_free(current_db,MYF(MY_ALLOW_ZERO_PTR));
 
1248
  my_free(current_host,MYF(MY_ALLOW_ZERO_PTR));
 
1249
  my_free(current_user,MYF(MY_ALLOW_ZERO_PTR));
 
1250
  my_free(full_username,MYF(MY_ALLOW_ZERO_PTR));
 
1251
  my_free(part_username,MYF(MY_ALLOW_ZERO_PTR));
 
1252
  my_free(default_prompt,MYF(MY_ALLOW_ZERO_PTR));
 
1253
#ifdef HAVE_SMEM
 
1254
  my_free(shared_memory_base_name,MYF(MY_ALLOW_ZERO_PTR));
 
1255
#endif
 
1256
  my_free(current_prompt,MYF(MY_ALLOW_ZERO_PTR));
 
1257
  while (embedded_server_arg_count > 1)
 
1258
    my_free(embedded_server_args[--embedded_server_arg_count],MYF(0));
 
1259
  mysql_server_end();
1212
1260
  free_defaults(defaults_argv);
1213
1261
  my_end(my_end_arg);
1214
1262
  exit(status.exit_status);
1219
1267
  This function handles sigint calls
1220
1268
  If query is in process, kill query
1221
1269
  no query in process, terminate like previous behavior
1222
 
*/
1223
 
RETSIGTYPE handle_sigint(int sig)
 
1270
 */
 
1271
sig_handler handle_sigint(int sig)
1224
1272
{
1225
1273
  char kill_buffer[40];
1226
 
  DRIZZLE *kill_drizzle= NULL;
 
1274
  MYSQL *kill_mysql= NULL;
1227
1275
 
1228
1276
  /* terminate if no query being executed, or we already tried interrupting */
1229
 
  if (!executing_query || interrupted_query) {
 
1277
  if (!executing_query || interrupted_query)
1230
1278
    goto err;
1231
 
  }
1232
1279
 
1233
 
  kill_drizzle= drizzle_create(kill_drizzle);
1234
 
  if (!drizzle_connect(kill_drizzle,current_host, current_user, opt_password,
1235
 
                          "", opt_drizzle_port, opt_drizzle_unix_port,0))
1236
 
  {
 
1280
  kill_mysql= mysql_init(kill_mysql);
 
1281
  if (!mysql_real_connect(kill_mysql,current_host, current_user, opt_password,
 
1282
                          "", opt_mysql_port, opt_mysql_unix_port,0))
1237
1283
    goto err;
1238
 
  }
1239
1284
 
1240
1285
  /* kill_buffer is always big enough because max length of %lu is 15 */
1241
 
  sprintf(kill_buffer, "KILL /*!50000 QUERY */ %u", drizzle_thread_id(&drizzle));
1242
 
  drizzle_real_query(kill_drizzle, kill_buffer, strlen(kill_buffer));
1243
 
  drizzle_close(kill_drizzle);
1244
 
  tee_fprintf(stdout, _("Query aborted by Ctrl+C\n"));
 
1286
  sprintf(kill_buffer, "KILL /*!50000 QUERY */ %lu", mysql_thread_id(&mysql));
 
1287
  mysql_real_query(kill_mysql, kill_buffer, strlen(kill_buffer));
 
1288
  mysql_close(kill_mysql);
 
1289
  tee_fprintf(stdout, "Query aborted by Ctrl+C\n");
1245
1290
 
1246
1291
  interrupted_query= 1;
1247
1292
 
1248
1293
  return;
1249
1294
 
1250
1295
err:
1251
 
  drizzle_end(sig);
 
1296
  mysql_end(sig);
1252
1297
}
1253
1298
 
1254
1299
 
1255
1300
#if defined(HAVE_TERMIOS_H) && defined(GWINSZ_IN_SYS_IOCTL)
1256
 
RETSIGTYPE window_resize(int sig __attribute__((unused)))
 
1301
sig_handler window_resize(int sig __attribute__((__unused__)))
1257
1302
{
1258
1303
  struct winsize window_size;
1259
1304
 
1264
1309
 
1265
1310
static struct my_option my_long_options[] =
1266
1311
{
1267
 
  {"help", '?', N_("Display this help and exit."), 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
 
1312
  {"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
1268
1313
   0, 0, 0, 0, 0},
1269
 
  {"help", 'I', N_("Synonym for -?"), 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
 
1314
  {"help", 'I', "Synonym for -?", 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
1270
1315
   0, 0, 0, 0, 0},
1271
1316
  {"auto-rehash", OPT_AUTO_REHASH,
1272
 
   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."),
1273
 
   (char**) &opt_rehash, (char**) &opt_rehash, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0,
 
1317
   "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.",
 
1318
   (uchar**) &opt_rehash, (uchar**) &opt_rehash, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0,
1274
1319
   0, 0},
1275
1320
  {"no-auto-rehash", 'A',
1276
 
   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."),
 
1321
   "No automatic rehashing. One has to use 'rehash' to get table and field completion. This gives a quicker start of mysql and disables rehashing on reconnect. WARNING: options deprecated; use --disable-auto-rehash instead.",
1277
1322
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1278
 
  {"auto-vertical-output", OPT_AUTO_VERTICAL_OUTPUT,
1279
 
   N_("Automatically switch to vertical output mode if the result is wider than the terminal width."),
1280
 
   (char**) &auto_vertical_output, (char**) &auto_vertical_output, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1323
   {"auto-vertical-output", OPT_AUTO_VERTICAL_OUTPUT,
 
1324
    "Automatically switch to vertical output mode if the result is wider than the terminal width.",
 
1325
    (uchar**) &auto_vertical_output, (uchar**) &auto_vertical_output, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1281
1326
  {"batch", 'B',
1282
 
   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},
 
1327
   "Don't use history file. Disable interactive behavior. (Enables --silent)", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1283
1328
  {"character-sets-dir", OPT_CHARSETS_DIR,
1284
 
   N_("Directory where character sets are."), (char**) &charsets_dir,
1285
 
   (char**) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1286
 
  {"column-type-info", OPT_COLUMN_TYPES, N_("Display column type information."),
1287
 
   (char**) &column_types_flag, (char**) &column_types_flag,
1288
 
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1289
 
  {"comments", 'c', N_("Preserve comments. Send comments to the server. The default is --skip-comments (discard comments), enable with --comments"),
1290
 
   (char**) &preserve_comments, (char**) &preserve_comments,
1291
 
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1292
 
  {"compress", 'C', N_("Use compression in server/client protocol."),
1293
 
   (char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
 
1329
   "Directory where character sets are.", (uchar**) &charsets_dir,
 
1330
   (uchar**) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1331
  {"column-type-info", OPT_COLUMN_TYPES, "Display column type information.",
 
1332
   (uchar**) &column_types_flag, (uchar**) &column_types_flag,
 
1333
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1334
  {"comments", 'c', "Preserve comments. Send comments to the server."
 
1335
   " The default is --skip-comments (discard comments), enable with --comments",
 
1336
   (uchar**) &preserve_comments, (uchar**) &preserve_comments,
 
1337
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1338
  {"compress", 'C', "Use compression in server/client protocol.",
 
1339
   (uchar**) &opt_compress, (uchar**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
1294
1340
   0, 0, 0},
1295
 
  {"debug-check", OPT_DEBUG_CHECK, N_("Check memory and open file usage at exit ."),
1296
 
   (char**) &debug_check_flag, (char**) &debug_check_flag, 0,
 
1341
 
 
1342
#ifdef DBUG_OFF
 
1343
  {"debug", '#', "This is a non-debug version. Catch this and exit",
 
1344
   0,0, 0, GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
1345
#else
 
1346
  {"debug", '#', "Output debug log", (uchar**) &default_dbug_option,
 
1347
   (uchar**) &default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
1348
#endif
 
1349
  {"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit .",
 
1350
   (uchar**) &debug_check_flag, (uchar**) &debug_check_flag, 0,
1297
1351
   GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1298
 
  {"debug-info", 'T', N_("Print some debug info at exit."), (char**) &debug_info_flag,
1299
 
   (char**) &debug_info_flag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1300
 
  {"database", 'D', N_("Database to use."), (char**) &current_db,
1301
 
   (char**) &current_db, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1352
  {"debug-info", 'T', "Print some debug info at exit.", (uchar**) &debug_info_flag,
 
1353
   (uchar**) &debug_info_flag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1354
  {"database", 'D', "Database to use.", (uchar**) &current_db,
 
1355
   (uchar**) &current_db, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1302
1356
  {"default-character-set", OPT_DEFAULT_CHARSET,
1303
 
   N_("(not used)"), 0,
1304
 
   0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1305
 
  {"delimiter", OPT_DELIMITER, N_("Delimiter to be used."), (char**) &delimiter_str,
1306
 
   (char**) &delimiter_str, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1307
 
  {"execute", 'e', N_("Execute command and quit. (Disables --force and history file)"), 0,
1308
 
   0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1309
 
  {"vertical", 'E', N_("Print the output of a query (rows) vertically."),
1310
 
   (char**) &vertical, (char**) &vertical, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
 
1357
   "Set the default character set.", (uchar**) &default_charset,
 
1358
   (uchar**) &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1359
  {"delimiter", OPT_DELIMITER, "Delimiter to be used.", (uchar**) &delimiter_str,
 
1360
   (uchar**) &delimiter_str, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1361
  {"execute", 'e', "Execute command and quit. (Disables --force and history file)", 0,
 
1362
   0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1363
  {"vertical", 'E', "Print the output of a query (rows) vertically.",
 
1364
   (uchar**) &vertical, (uchar**) &vertical, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
1311
1365
   0},
1312
 
  {"force", 'f', N_("Continue even if we get an sql error."),
1313
 
   (char**) &ignore_errors, (char**) &ignore_errors, 0, GET_BOOL, NO_ARG, 0, 0,
 
1366
  {"force", 'f', "Continue even if we get an sql error.",
 
1367
   (uchar**) &ignore_errors, (uchar**) &ignore_errors, 0, GET_BOOL, NO_ARG, 0, 0,
1314
1368
   0, 0, 0, 0},
1315
1369
  {"named-commands", 'G',
1316
 
   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."),
1317
 
   (char**) &named_cmds, (char**) &named_cmds, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
 
1370
   "Enable named commands. Named commands mean this program's internal commands; see mysql> 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.",
 
1371
   (uchar**) &named_cmds, (uchar**) &named_cmds, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
1318
1372
   0, 0},
1319
1373
  {"no-named-commands", 'g',
1320
 
   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."),
 
1374
   "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.",
1321
1375
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1322
 
  {"ignore-spaces", 'i', N_("Ignore space after function names."), 0, 0, 0,
 
1376
  {"ignore-spaces", 'i', "Ignore space after function names.", 0, 0, 0,
1323
1377
   GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1324
 
  {"local-infile", OPT_LOCAL_INFILE, N_("Enable/disable LOAD DATA LOCAL INFILE."),
1325
 
   (char**) &opt_local_infile,
1326
 
   (char**) &opt_local_infile, 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
1327
 
  {"no-beep", 'b', N_("Turn off beep on error."), (char**) &opt_nobeep,
1328
 
   (char**) &opt_nobeep, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1329
 
  {"host", 'h', N_("Connect to host."), (char**) &current_host,
1330
 
   (char**) &current_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1331
 
  {"line-numbers", OPT_LINE_NUMBERS, N_("Write line numbers for errors."),
1332
 
   (char**) &line_numbers, (char**) &line_numbers, 0, GET_BOOL,
1333
 
   NO_ARG, 1, 0, 0, 0, 0, 0},
1334
 
  {"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,
 
1378
  {"local-infile", OPT_LOCAL_INFILE, "Enable/disable LOAD DATA LOCAL INFILE.",
 
1379
   (uchar**) &opt_local_infile,
 
1380
   (uchar**) &opt_local_infile, 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
1381
  {"no-beep", 'b', "Turn off beep on error.", (uchar**) &opt_nobeep,
 
1382
   (uchar**) &opt_nobeep, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, 
 
1383
  {"host", 'h', "Connect to host.", (uchar**) &current_host,
 
1384
   (uchar**) &current_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1385
  {"html", 'H', "Produce HTML output.", (uchar**) &opt_html, (uchar**) &opt_html,
 
1386
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1387
  {"xml", 'X', "Produce XML output", (uchar**) &opt_xml, (uchar**) &opt_xml, 0,
 
1388
   GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1389
  {"line-numbers", OPT_LINE_NUMBERS, "Write line numbers for errors.",
 
1390
   (uchar**) &line_numbers, (uchar**) &line_numbers, 0, GET_BOOL,
 
1391
   NO_ARG, 1, 0, 0, 0, 0, 0},  
 
1392
  {"skip-line-numbers", 'L', "Don't write line number for errors. WARNING: -L is deprecated, use long version of this option instead.", 0, 0, 0, GET_NO_ARG,
1335
1393
   NO_ARG, 0, 0, 0, 0, 0, 0},
1336
 
  {"unbuffered", 'n', N_("Flush buffer after each query."), (char**) &unbuffered,
1337
 
   (char**) &unbuffered, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1338
 
  {"column-names", OPT_COLUMN_NAMES, N_("Write column names in results."),
1339
 
   (char**) &column_names, (char**) &column_names, 0, GET_BOOL,
 
1394
  {"unbuffered", 'n', "Flush buffer after each query.", (uchar**) &unbuffered,
 
1395
   (uchar**) &unbuffered, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1396
  {"column-names", OPT_COLUMN_NAMES, "Write column names in results.",
 
1397
   (uchar**) &column_names, (uchar**) &column_names, 0, GET_BOOL,
1340
1398
   NO_ARG, 1, 0, 0, 0, 0, 0},
1341
1399
  {"skip-column-names", 'N',
1342
 
   N_("Don't write column names in results. WARNING: -N is deprecated, use long version of this options instead."),
 
1400
   "Don't write column names in results. WARNING: -N is deprecated, use long version of this options instead.",
1343
1401
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1344
1402
  {"set-variable", 'O',
1345
 
   N_("Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value."),
 
1403
   "Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value.",
1346
1404
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1347
 
  {"sigint-ignore", OPT_SIGINT_IGNORE, N_("Ignore SIGINT (CTRL-C)"),
1348
 
   (char**) &opt_sigint_ignore,  (char**) &opt_sigint_ignore, 0, GET_BOOL,
 
1405
  {"sigint-ignore", OPT_SIGINT_IGNORE, "Ignore SIGINT (CTRL-C)",
 
1406
   (uchar**) &opt_sigint_ignore,  (uchar**) &opt_sigint_ignore, 0, GET_BOOL,
1349
1407
   NO_ARG, 0, 0, 0, 0, 0, 0},
1350
1408
  {"one-database", 'o',
1351
 
   N_("Only update the default database. This is useful for skipping updates to other database in the update log."),
 
1409
   "Only update the default database. This is useful for skipping updates to other database in the update log.",
1352
1410
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1411
#ifdef USE_POPEN
1353
1412
  {"pager", OPT_PAGER,
1354
 
   N_("Pager to use to display results. If you don't supply an option the default pager is taken from your ENV variable PAGER. Valid pagers are less, more, cat [> filename], etc. See interactive help (\\h) also. This option does not work in batch mode. Disable with --disable-pager. This option is disabled by default."),
 
1413
   "Pager to use to display results. If you don't supply an option the default pager is taken from your ENV variable PAGER. Valid pagers are less, more, cat [> filename], etc. See interactive help (\\h) also. This option does not work in batch mode. Disable with --disable-pager. This option is disabled by default.",
1355
1414
   0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
1356
1415
  {"no-pager", OPT_NOPAGER,
1357
 
   N_("Disable pager and print to stdout. See interactive help (\\h) also. WARNING: option deprecated; use --disable-pager instead."),
 
1416
   "Disable pager and print to stdout. See interactive help (\\h) also. WARNING: option deprecated; use --disable-pager instead.",
1358
1417
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1418
#endif
1359
1419
  {"password", 'p',
1360
 
   N_("Password to use when connecting to server. If password is not given it's asked from the tty."),
 
1420
   "Password to use when connecting to server. If password is not given it's asked from the tty.",
1361
1421
   0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
1362
 
  {"port", 'P', N_("Port number to use for connection or 0 for default to, in order of preference, my.cnf, $DRIZZLE_TCP_PORT, ")
1363
 
   N_("built-in default") " (" STRINGIFY_ARG(DRIZZLE_PORT) ").",
1364
 
   (char**) &opt_drizzle_port,
1365
 
   (char**) &opt_drizzle_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,  0},
1366
 
  {"prompt", OPT_PROMPT, N_("Set the drizzle prompt to this value."),
1367
 
   (char**) &current_prompt, (char**) &current_prompt, 0, GET_STR_ALLOC,
 
1422
  {"port", 'P', "Port number to use for connection or 0 for default to, in "
 
1423
   "order of preference, my.cnf, $MYSQL_TCP_PORT, "
 
1424
#if MYSQL_PORT_DEFAULT == 0
 
1425
   "/etc/services, "
 
1426
#endif
 
1427
   "built-in default (" STRINGIFY_ARG(MYSQL_PORT) ").",
 
1428
   (uchar**) &opt_mysql_port,
 
1429
   (uchar**) &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,  0},
 
1430
  {"prompt", OPT_PROMPT, "Set the mysql prompt to this value.",
 
1431
   (uchar**) &current_prompt, (uchar**) &current_prompt, 0, GET_STR_ALLOC,
1368
1432
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1369
 
  {"protocol", OPT_DRIZZLE_PROTOCOL, N_("The protocol of connection (tcp,socket,pipe,memory)."),
 
1433
  {"protocol", OPT_MYSQL_PROTOCOL, "The protocol of connection (tcp,socket,pipe,memory).",
1370
1434
   0, 0, 0, GET_STR,  REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1371
1435
  {"quick", 'q',
1372
 
   N_("Don't cache result, print it row by row. This may slow down the server if the output is suspended. Doesn't use history file."),
1373
 
   (char**) &quick, (char**) &quick, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1374
 
  {"raw", 'r', N_("Write fields without conversion. Used with --batch."),
1375
 
   (char**) &opt_raw_data, (char**) &opt_raw_data, 0, GET_BOOL, NO_ARG, 0, 0, 0,
 
1436
   "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.",
 
1437
   (uchar**) &quick, (uchar**) &quick, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1438
  {"raw", 'r', "Write fields without conversion. Used with --batch.",
 
1439
   (uchar**) &opt_raw_data, (uchar**) &opt_raw_data, 0, GET_BOOL, NO_ARG, 0, 0, 0,
1376
1440
   0, 0, 0},
1377
 
  {"reconnect", OPT_RECONNECT, N_("Reconnect if the connection is lost. Disable with --disable-reconnect. This option is enabled by default."),
1378
 
   (char**) &opt_reconnect, (char**) &opt_reconnect, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
1379
 
  {"silent", 's', N_("Be more silent. Print results with a tab as separator, each row on new line."), 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0,
 
1441
  {"reconnect", OPT_RECONNECT, "Reconnect if the connection is lost. Disable with --disable-reconnect. This option is enabled by default.", 
 
1442
   (uchar**) &opt_reconnect, (uchar**) &opt_reconnect, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
 
1443
  {"silent", 's', "Be more silent. Print results with a tab as separator, each row on new line.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0,
1380
1444
   0, 0},
1381
 
  {"socket", 'S', N_("Socket file to use for connection."),
1382
 
   (char**) &opt_drizzle_unix_port, (char**) &opt_drizzle_unix_port, 0, GET_STR_ALLOC,
 
1445
#ifdef HAVE_SMEM
 
1446
  {"shared-memory-base-name", OPT_SHARED_MEMORY_BASE_NAME,
 
1447
   "Base name of shared memory.", (uchar**) &shared_memory_base_name, (uchar**) &shared_memory_base_name, 
 
1448
   0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1449
#endif
 
1450
  {"socket", 'S', "Socket file to use for connection.",
 
1451
   (uchar**) &opt_mysql_unix_port, (uchar**) &opt_mysql_unix_port, 0, GET_STR_ALLOC,
1383
1452
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1384
 
  {"table", 't', N_("Output in table format."), (char**) &output_tables,
1385
 
   (char**) &output_tables, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1453
  {"table", 't', "Output in table format.", (uchar**) &output_tables,
 
1454
   (uchar**) &output_tables, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1386
1455
  {"tee", OPT_TEE,
1387
 
   N_("Append everything into outfile. See interactive help (\\h) also. Does not work in batch mode. Disable with --disable-tee. This option is disabled by default."),
 
1456
   "Append everything into outfile. See interactive help (\\h) also. Does not work in batch mode. Disable with --disable-tee. This option is disabled by default.",
1388
1457
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1389
 
  {"no-tee", OPT_NOTEE, N_("Disable outfile. See interactive help (\\h) also. WARNING: option deprecated; use --disable-tee instead"), 0, 0, 0, GET_NO_ARG,
 
1458
  {"no-tee", OPT_NOTEE, "Disable outfile. See interactive help (\\h) also. WARNING: option deprecated; use --disable-tee instead", 0, 0, 0, GET_NO_ARG,
1390
1459
   NO_ARG, 0, 0, 0, 0, 0, 0},
1391
1460
#ifndef DONT_ALLOW_USER_CHANGE
1392
 
  {"user", 'u', N_("User for login if not current user."), (char**) &current_user,
1393
 
   (char**) &current_user, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1461
  {"user", 'u', "User for login if not current user.", (uchar**) &current_user,
 
1462
   (uchar**) &current_user, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1394
1463
#endif
1395
 
  {"safe-updates", 'U', N_("Only allow UPDATE and DELETE that uses keys."),
1396
 
   (char**) &safe_updates, (char**) &safe_updates, 0, GET_BOOL, NO_ARG, 0, 0,
1397
 
   0, 0, 0, 0},
1398
 
  {"i-am-a-dummy", 'U', N_("Synonym for option --safe-updates, -U."),
1399
 
   (char**) &safe_updates, (char**) &safe_updates, 0, GET_BOOL, NO_ARG, 0, 0,
1400
 
   0, 0, 0, 0},
1401
 
  {"verbose", 'v', N_("Write more. (-v -v -v gives the table output format)."), 0,
 
1464
  {"safe-updates", 'U', "Only allow UPDATE and DELETE that uses keys.",
 
1465
   (uchar**) &safe_updates, (uchar**) &safe_updates, 0, GET_BOOL, NO_ARG, 0, 0,
 
1466
   0, 0, 0, 0},
 
1467
  {"i-am-a-dummy", 'U', "Synonym for option --safe-updates, -U.",
 
1468
   (uchar**) &safe_updates, (uchar**) &safe_updates, 0, GET_BOOL, NO_ARG, 0, 0,
 
1469
   0, 0, 0, 0},
 
1470
  {"verbose", 'v', "Write more. (-v -v -v gives the table output format).", 0,
1402
1471
   0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1403
 
  {"version", 'V', N_("Output version information and exit."), 0, 0, 0,
 
1472
  {"version", 'V', "Output version information and exit.", 0, 0, 0,
1404
1473
   GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1405
 
  {"wait", 'w', N_("Wait and retry if connection is down."), 0, 0, 0, GET_NO_ARG,
 
1474
  {"wait", 'w', "Wait and retry if connection is down.", 0, 0, 0, GET_NO_ARG,
1406
1475
   NO_ARG, 0, 0, 0, 0, 0, 0},
1407
1476
  {"connect_timeout", OPT_CONNECT_TIMEOUT,
1408
 
   N_("Number of seconds before connection timeout."),
1409
 
   (char**) &opt_connect_timeout,
1410
 
   (char**) &opt_connect_timeout, 0, GET_ULONG, REQUIRED_ARG, 0, 0, 3600*12, 0,
 
1477
   "Number of seconds before connection timeout.",
 
1478
   (uchar**) &opt_connect_timeout,
 
1479
   (uchar**) &opt_connect_timeout, 0, GET_ULONG, REQUIRED_ARG, 0, 0, 3600*12, 0,
1411
1480
   0, 0},
1412
1481
  {"max_allowed_packet", OPT_MAX_ALLOWED_PACKET,
1413
 
   N_("Max packet length to send to, or receive from server"),
1414
 
   (char**) &opt_max_allowed_packet, (char**) &opt_max_allowed_packet, 0,
 
1482
   "Max packet length to send to, or receive from server",
 
1483
   (uchar**) &opt_max_allowed_packet, (uchar**) &opt_max_allowed_packet, 0,
1415
1484
   GET_ULONG, REQUIRED_ARG, 16 *1024L*1024L, 4096,
1416
 
   (int64_t) 2*1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
 
1485
   (longlong) 2*1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
1417
1486
  {"net_buffer_length", OPT_NET_BUFFER_LENGTH,
1418
 
   N_("Buffer for TCP/IP and socket communication"),
1419
 
   (char**) &opt_net_buffer_length, (char**) &opt_net_buffer_length, 0, GET_ULONG,
 
1487
   "Buffer for TCP/IP and socket communication",
 
1488
   (uchar**) &opt_net_buffer_length, (uchar**) &opt_net_buffer_length, 0, GET_ULONG,
1420
1489
   REQUIRED_ARG, 16384, 1024, 512*1024*1024L, MALLOC_OVERHEAD, 1024, 0},
1421
1490
  {"select_limit", OPT_SELECT_LIMIT,
1422
 
   N_("Automatic limit for SELECT when using --safe-updates"),
1423
 
   (char**) &select_limit,
1424
 
   (char**) &select_limit, 0, GET_ULONG, REQUIRED_ARG, 1000L, 1, ULONG_MAX,
 
1491
   "Automatic limit for SELECT when using --safe-updates",
 
1492
   (uchar**) &select_limit,
 
1493
   (uchar**) &select_limit, 0, GET_ULONG, REQUIRED_ARG, 1000L, 1, ULONG_MAX,
1425
1494
   0, 1, 0},
1426
1495
  {"max_join_size", OPT_MAX_JOIN_SIZE,
1427
 
   N_("Automatic limit for rows in a join when using --safe-updates"),
1428
 
   (char**) &max_join_size,
1429
 
   (char**) &max_join_size, 0, GET_ULONG, REQUIRED_ARG, 1000000L, 1, ULONG_MAX,
 
1496
   "Automatic limit for rows in a join when using --safe-updates",
 
1497
   (uchar**) &max_join_size,
 
1498
   (uchar**) &max_join_size, 0, GET_ULONG, REQUIRED_ARG, 1000000L, 1, ULONG_MAX,
1430
1499
   0, 1, 0},
1431
 
  {"secure-auth", OPT_SECURE_AUTH, N_("Refuse client connecting to server if it uses old (pre-4.1.1) protocol"), (char**) &opt_secure_auth,
1432
 
   (char**) &opt_secure_auth, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1433
 
  {"show-warnings", OPT_SHOW_WARNINGS, N_("Show warnings after every statement."),
1434
 
   (char**) &show_warnings, (char**) &show_warnings, 0, GET_BOOL, NO_ARG,
1435
 
   0, 0, 0, 0, 0, 0},
 
1500
  {"secure-auth", OPT_SECURE_AUTH, "Refuse client connecting to server if it"
 
1501
    " uses old (pre-4.1.1) protocol", (uchar**) &opt_secure_auth,
 
1502
    (uchar**) &opt_secure_auth, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1503
  {"server-arg", OPT_SERVER_ARG, "Send embedded server this as a parameter.",
 
1504
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1505
  {"show-warnings", OPT_SHOW_WARNINGS, "Show warnings after every statement.",
 
1506
    (uchar**) &show_warnings, (uchar**) &show_warnings, 0, GET_BOOL, NO_ARG, 
 
1507
    0, 0, 0, 0, 0, 0},
1436
1508
  { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
1437
1509
};
1438
1510
 
1439
1511
 
1440
1512
static void usage(int version)
1441
1513
{
 
1514
#if defined(USE_LIBEDIT_INTERFACE)
 
1515
  const char* readline= "";
 
1516
#else
1442
1517
  const char* readline= "readline";
 
1518
#endif
1443
1519
 
1444
 
  printf(_("%s  Ver %s Distrib %s, for %s (%s) using %s %s\n"),
1445
 
         my_progname, VER, drizzle_get_client_info(),
1446
 
         SYSTEM_TYPE, MACHINE_TYPE,
 
1520
#ifdef HAVE_READLINE
 
1521
  printf("%s  Ver %s Distrib %s, for %s (%s) using %s %s\n",
 
1522
         my_progname, VER, MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE,
1447
1523
         readline, rl_library_version);
 
1524
#else
 
1525
  printf("%s  Ver %s Distrib %s, for %s (%s)\n", my_progname, VER,
 
1526
        MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE);
 
1527
#endif
1448
1528
 
1449
1529
  if (version)
1450
1530
    return;
1451
 
  printf(_("\
1452
 
Copyright (C) 2000-2008 MySQL AB\n                                      \
1453
 
This software comes with ABSOLUTELY NO WARRANTY. This is free software,\n \
1454
 
and you are welcome to modify and redistribute it under the GPL license\n"));
1455
 
  printf(_("Usage: %s [OPTIONS] [database]\n"), my_progname);
 
1531
  printf("\
 
1532
Copyright (C) 2000-2008 MySQL AB\n\
 
1533
This software comes with ABSOLUTELY NO WARRANTY. This is free software,\n\
 
1534
and you are welcome to modify and redistribute it under the GPL license\n");
 
1535
  printf("Usage: %s [OPTIONS] [database]\n", my_progname);
1456
1536
  my_print_help(my_long_options);
1457
1537
  print_defaults("my", load_default_groups);
1458
1538
  my_print_variables(my_long_options);
1459
1539
}
1460
1540
 
1461
1541
 
1462
 
bool
 
1542
my_bool
1463
1543
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
1464
 
               char *argument)
 
1544
               char *argument)
1465
1545
{
1466
1546
  switch(optid) {
1467
1547
  case OPT_CHARSETS_DIR:
1468
 
    strmake(drizzle_charsets_dir, argument, sizeof(drizzle_charsets_dir) - 1);
1469
 
    charsets_dir = drizzle_charsets_dir;
 
1548
    strmake(mysql_charsets_dir, argument, sizeof(mysql_charsets_dir) - 1);
 
1549
    charsets_dir = mysql_charsets_dir;
1470
1550
    break;
1471
1551
  case  OPT_DEFAULT_CHARSET:
1472
1552
    default_charset_used= 1;
1473
1553
    break;
1474
1554
  case OPT_DELIMITER:
1475
 
    if (argument == disabled_my_option)
 
1555
    if (argument == disabled_my_option) 
1476
1556
    {
1477
 
      my_stpcpy(delimiter, DEFAULT_DELIMITER);
 
1557
      strmov(delimiter, DEFAULT_DELIMITER);
1478
1558
    }
1479
 
    else
 
1559
    else 
1480
1560
    {
1481
1561
      /* Check that delimiter does not contain a backslash */
1482
 
      if (!strstr(argument, "\\"))
 
1562
      if (!strstr(argument, "\\")) 
1483
1563
      {
1484
1564
        strmake(delimiter, argument, sizeof(delimiter) - 1);
1485
1565
      }
1486
 
      else
 
1566
      else 
1487
1567
      {
1488
 
        put_info(_("DELIMITER cannot contain a backslash character"),
1489
 
                 INFO_ERROR,0,0);
 
1568
        put_info("DELIMITER cannot contain a backslash character", INFO_ERROR);
1490
1569
        return 0;
1491
 
      }
 
1570
      } 
1492
1571
    }
1493
1572
    delimiter_length= (uint)strlen(delimiter);
1494
1573
    delimiter_str= delimiter;
1500
1579
    if (argument == disabled_my_option)
1501
1580
    {
1502
1581
      if (opt_outfile)
1503
 
        end_tee();
 
1582
        end_tee();
1504
1583
    }
1505
1584
    else
1506
1585
      init_tee(argument);
1507
1586
    break;
1508
1587
  case OPT_NOTEE:
1509
 
    printf(_("WARNING: option deprecated; use --disable-tee instead.\n"));
 
1588
    printf("WARNING: option deprecated; use --disable-tee instead.\n");
1510
1589
    if (opt_outfile)
1511
1590
      end_tee();
1512
1591
    break;
1518
1597
      opt_nopager= 0;
1519
1598
      if (argument && strlen(argument))
1520
1599
      {
1521
 
        default_pager_set= 1;
1522
 
        strmake(pager, argument, sizeof(pager) - 1);
1523
 
        my_stpcpy(default_pager, pager);
 
1600
        default_pager_set= 1;
 
1601
        strmake(pager, argument, sizeof(pager) - 1);
 
1602
        strmov(default_pager, pager);
1524
1603
      }
1525
1604
      else if (default_pager_set)
1526
 
        my_stpcpy(pager, default_pager);
 
1605
        strmov(pager, default_pager);
1527
1606
      else
1528
 
        opt_nopager= 1;
 
1607
        opt_nopager= 1;
1529
1608
    }
1530
1609
    break;
1531
1610
  case OPT_NOPAGER:
1532
 
    printf(_("WARNING: option deprecated; use --disable-pager instead.\n"));
 
1611
    printf("WARNING: option deprecated; use --disable-pager instead.\n");
1533
1612
    opt_nopager= 1;
1534
1613
    break;
 
1614
  case OPT_MYSQL_PROTOCOL:
 
1615
    opt_protocol= find_type_or_exit(argument, &sql_protocol_typelib,
 
1616
                                    opt->name);
 
1617
    break;
1535
1618
  case OPT_SERVER_ARG:
1536
 
    printf(_("WARNING: --server-arg option not supported in this configuration.\n"));
 
1619
#ifdef EMBEDDED_LIBRARY
 
1620
    /*
 
1621
      When the embedded server is being tested, the client needs to be
 
1622
      able to pass command-line arguments to the embedded server so it can
 
1623
      locate the language files and data directory.
 
1624
    */
 
1625
    if (!embedded_server_arg_count)
 
1626
    {
 
1627
      embedded_server_arg_count= 1;
 
1628
      embedded_server_args[0]= (char*) "";
 
1629
    }
 
1630
    if (embedded_server_arg_count == MAX_SERVER_ARGS-1 ||
 
1631
        !(embedded_server_args[embedded_server_arg_count++]=
 
1632
          my_strdup(argument, MYF(MY_FAE))))
 
1633
    {
 
1634
        put_info("Can't use server argument", INFO_ERROR);
 
1635
        return 0;
 
1636
    }
 
1637
#else /*EMBEDDED_LIBRARY */
 
1638
    printf("WARNING: --server-arg option not supported in this configuration.\n");
 
1639
#endif
1537
1640
    break;
1538
1641
  case 'A':
1539
1642
    opt_rehash= 0;
1557
1660
    break;
1558
1661
  case 'p':
1559
1662
    if (argument == disabled_my_option)
1560
 
      argument= (char*) "";      // Don't require password
 
1663
      argument= (char*) "";                     // Don't require password
1561
1664
    if (argument)
1562
1665
    {
1563
1666
      char *start= argument;
1564
 
      free(opt_password);
1565
 
      opt_password= strdup(argument);
1566
 
      while (*argument) *argument++= 'x';        // Destroy argument
 
1667
      my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR));
 
1668
      opt_password= my_strdup(argument, MYF(MY_FAE));
 
1669
      while (*argument) *argument++= 'x';               // Destroy argument
1567
1670
      if (*start)
1568
 
        start[1]=0 ;
 
1671
        start[1]=0 ;
1569
1672
      tty_password= 0;
1570
1673
    }
1571
1674
    else
1572
1675
      tty_password= 1;
1573
1676
    break;
 
1677
  case '#':
 
1678
    DBUG_PUSH(argument ? argument : default_dbug_option);
 
1679
    debug_info_flag= 1;
 
1680
    break;
1574
1681
  case 's':
1575
1682
    if (argument == disabled_my_option)
1576
1683
      opt_silent= 0;
1605
1712
{
1606
1713
  char *tmp, *pagpoint;
1607
1714
  int ho_error;
1608
 
  const DRIZZLE_PARAMETERS *drizzle_params= drizzle_get_parameters();
 
1715
  MYSQL_PARAMETERS *mysql_params= mysql_get_parameters();
1609
1716
 
1610
 
  tmp= (char *) getenv("DRIZZLE_HOST");
 
1717
  tmp= (char *) getenv("MYSQL_HOST");
1611
1718
  if (tmp)
1612
 
    current_host= strdup(tmp);
 
1719
    current_host= my_strdup(tmp, MYF(MY_WME));
1613
1720
 
1614
1721
  pagpoint= getenv("PAGER");
1615
1722
  if (!((char*) (pagpoint)))
1616
1723
  {
1617
 
    my_stpcpy(pager, "stdout");
 
1724
    strmov(pager, "stdout");
1618
1725
    opt_nopager= 1;
1619
1726
  }
1620
1727
  else
1621
 
    my_stpcpy(pager, pagpoint);
1622
 
  my_stpcpy(default_pager, pager);
 
1728
    strmov(pager, pagpoint);
 
1729
  strmov(default_pager, pager);
1623
1730
 
1624
 
  opt_max_allowed_packet= *drizzle_params->p_max_allowed_packet;
1625
 
  opt_net_buffer_length= *drizzle_params->p_net_buffer_length;
 
1731
  opt_max_allowed_packet= *mysql_params->p_max_allowed_packet;
 
1732
  opt_net_buffer_length= *mysql_params->p_net_buffer_length;
1626
1733
 
1627
1734
  if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
1628
1735
    exit(ho_error);
1629
1736
 
1630
 
  *drizzle_params->p_max_allowed_packet= opt_max_allowed_packet;
1631
 
  *drizzle_params->p_net_buffer_length= opt_net_buffer_length;
 
1737
  *mysql_params->p_max_allowed_packet= opt_max_allowed_packet;
 
1738
  *mysql_params->p_net_buffer_length= opt_net_buffer_length;
1632
1739
 
1633
1740
  if (status.batch) /* disable pager and outfile in this case */
1634
1741
  {
1635
 
    my_stpcpy(default_pager, "stdout");
1636
 
    my_stpcpy(pager, "stdout");
 
1742
    strmov(default_pager, "stdout");
 
1743
    strmov(pager, "stdout");
1637
1744
    opt_nopager= 1;
1638
1745
    default_pager_set= 0;
1639
1746
    opt_outfile= 0;
1640
1747
    opt_reconnect= 0;
1641
1748
    connect_flag= 0; /* Not in interactive mode */
1642
1749
  }
1643
 
 
 
1750
  
 
1751
  if (strcmp(default_charset, charset_info->csname) &&
 
1752
      !(charset_info= get_charset_by_csname(default_charset, 
 
1753
                                            MY_CS_PRIMARY, MYF(MY_WME))))
 
1754
    exit(1);
1644
1755
  if (argc > 1)
1645
1756
  {
1646
1757
    usage(0);
1649
1760
  if (argc == 1)
1650
1761
  {
1651
1762
    skip_updates= 0;
1652
 
    free(current_db);
1653
 
    current_db= strdup(*argv);
 
1763
    my_free(current_db, MYF(MY_ALLOW_ZERO_PTR));
 
1764
    current_db= my_strdup(*argv, MYF(MY_WME));
1654
1765
  }
1655
1766
  if (tty_password)
1656
 
    opt_password= get_tty_password(NULL);
 
1767
    opt_password= get_tty_password(NullS);
1657
1768
  if (debug_info_flag)
1658
1769
    my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
1659
1770
  if (debug_check_flag)
1663
1774
 
1664
1775
static int read_and_execute(bool interactive)
1665
1776
{
1666
 
  char *line;
1667
 
  char in_string=0;
1668
 
  uint32_t line_number=0;
1669
 
  bool ml_comment= 0;
 
1777
  char  *line;
 
1778
  char  in_string=0;
 
1779
  ulong line_number=0;
 
1780
  bool ml_comment= 0;  
1670
1781
  COMMANDS *com;
1671
1782
  status.exit_status=1;
1672
 
 
 
1783
  
1673
1784
  for (;;)
1674
1785
  {
1675
1786
    if (!interactive)
1682
1793
        you save the file using "Unicode UTF-8" format.
1683
1794
      */
1684
1795
      if (!line_number &&
1685
 
          (unsigned char) line[0] == 0xEF &&
1686
 
          (unsigned char) line[1] == 0xBB &&
1687
 
          (unsigned char) line[2] == 0xBF)
 
1796
           (uchar) line[0] == 0xEF &&
 
1797
           (uchar) line[1] == 0xBB &&
 
1798
           (uchar) line[2] == 0xBF)
1688
1799
        line+= 3;
1689
1800
      line_number++;
1690
 
      if (!glob_buffer->empty())
1691
 
        status.query_start_line=line_number;
 
1801
      if (!glob_buffer.length())
 
1802
        status.query_start_line=line_number;
1692
1803
    }
1693
1804
    else
1694
1805
    {
1695
 
      const char *prompt= (const char*) (ml_comment ? "   /*> " :
1696
 
                                         (glob_buffer->empty())
1697
 
                                         ?  construct_prompt()
1698
 
                                         : !in_string ? "    -> " :
1699
 
                                         in_string == '\'' ?
1700
 
                                         "    '> " : (in_string == '`' ?
1701
 
                                                      "    `> " :
1702
 
                                                      "    \"> "));
1703
 
      if (opt_outfile && glob_buffer->empty())
1704
 
        fflush(OUTFILE);
 
1806
      char *prompt= (char*) (ml_comment ? "   /*> " :
 
1807
                             glob_buffer.is_empty() ?  construct_prompt() :
 
1808
                             !in_string ? "    -> " :
 
1809
                             in_string == '\'' ?
 
1810
                             "    '> " : (in_string == '`' ?
 
1811
                             "    `> " :
 
1812
                             "    \"> "));
 
1813
      if (opt_outfile && glob_buffer.is_empty())
 
1814
        fflush(OUTFILE);
1705
1815
 
1706
1816
      if (opt_outfile)
1707
 
        fputs(prompt, OUTFILE);
 
1817
        fputs(prompt, OUTFILE);
1708
1818
      line= readline(prompt);
 
1819
 
1709
1820
      /*
1710
1821
        When Ctrl+d or Ctrl+z is pressed, the line may be NULL on some OS
1711
1822
        which may cause coredump.
1712
1823
      */
1713
1824
      if (opt_outfile && line)
1714
 
        fprintf(OUTFILE, "%s\n", line);
 
1825
        fprintf(OUTFILE, "%s\n", line);
1715
1826
    }
1716
 
    // End of file
1717
 
    if (!line)
 
1827
    if (!line)                                  // End of file
1718
1828
    {
1719
1829
      status.exit_status=0;
1720
1830
      break;
1721
1831
    }
1722
1832
 
1723
1833
    /*
1724
 
      Check if line is a drizzle command line
 
1834
      Check if line is a mysql command line
1725
1835
      (We want to allow help, print and clear anywhere at line start
1726
1836
    */
1727
 
    if ((named_cmds || (glob_buffer->empty()))
1728
 
        && !ml_comment && !in_string && (com=find_command(line,0)))
 
1837
    if ((named_cmds || glob_buffer.is_empty())
 
1838
        && !ml_comment && !in_string && (com=find_command(line,0)))
1729
1839
    {
1730
 
      if ((*com->func)(glob_buffer,line) > 0)
1731
 
        break;
1732
 
      // If buffer was emptied
1733
 
      if (glob_buffer->empty())
1734
 
        in_string=0;
 
1840
      if ((*com->func)(&glob_buffer,line) > 0)
 
1841
        break;
 
1842
      if (glob_buffer.is_empty())               // If buffer was emptied
 
1843
        in_string=0;
 
1844
#ifdef HAVE_READLINE
1735
1845
      if (interactive && status.add_to_history && not_in_history(line))
1736
 
        add_history(line);
 
1846
        add_history(line);
 
1847
#endif
1737
1848
      continue;
1738
1849
    }
1739
1850
    if (add_line(glob_buffer,line,&in_string,&ml_comment))
1744
1855
  if (!interactive && !status.exit_status)
1745
1856
  {
1746
1857
    remove_cntrl(glob_buffer);
1747
 
    if (!glob_buffer->empty())
 
1858
    if (!glob_buffer.is_empty())
1748
1859
    {
1749
1860
      status.exit_status=1;
1750
 
      if (com_go(glob_buffer,line) <= 0)
1751
 
        status.exit_status=0;
 
1861
      if (com_go(&glob_buffer,line) <= 0)
 
1862
        status.exit_status=0;
1752
1863
    }
1753
1864
  }
1754
1865
 
1756
1867
}
1757
1868
 
1758
1869
 
1759
 
static COMMANDS *find_command(const char *name,char cmd_char)
 
1870
static COMMANDS *find_command(char *name,char cmd_char)
1760
1871
{
1761
1872
  uint len;
1762
 
  const char *end;
 
1873
  char *end;
 
1874
  DBUG_ENTER("find_command");
 
1875
  DBUG_PRINT("enter",("name: '%s'  char: %d", name ? name : "NULL", cmd_char));
1763
1876
 
1764
1877
  if (!name)
1765
1878
  {
1778
1891
    if (strstr(name, "\\g") || (strstr(name, delimiter) &&
1779
1892
                                !(strlen(name) >= 9 &&
1780
1893
                                  !my_strnncoll(charset_info,
1781
 
                                                (unsigned char*) name, 9,
1782
 
                                                (const unsigned char*) "delimiter",
 
1894
                                                (uchar*) name, 9,
 
1895
                                                (const uchar*) "delimiter",
1783
1896
                                                9))))
1784
 
      return((COMMANDS *) 0);
 
1897
      DBUG_RETURN((COMMANDS *) 0);
1785
1898
    if ((end=strcont(name," \t")))
1786
1899
    {
1787
1900
      len=(uint) (end - name);
1788
1901
      while (my_isspace(charset_info,*end))
1789
 
        end++;
 
1902
        end++;
1790
1903
      if (!*end)
1791
 
        end=0;          // no arguments to function
 
1904
        end=0;                                  // no arguments to function
1792
1905
    }
1793
1906
    else
1794
1907
      len=(uint) strlen(name);
1797
1910
  for (uint i= 0; commands[i].name; i++)
1798
1911
  {
1799
1912
    if (commands[i].func &&
1800
 
        ((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)))
 
1913
        ((name &&
 
1914
          !my_strnncoll(charset_info,(uchar*)name,len,
 
1915
                                     (uchar*)commands[i].name,len) &&
 
1916
          !commands[i].name[len] &&
 
1917
          (!end || (end && commands[i].takes_params))) ||
 
1918
         !name && commands[i].cmd_char == cmd_char))
1801
1919
    {
1802
 
      return(&commands[i]);
 
1920
      DBUG_PRINT("exit",("found command: %s", commands[i].name));
 
1921
      DBUG_RETURN(&commands[i]);
1803
1922
    }
1804
1923
  }
1805
 
  return((COMMANDS *) 0);
 
1924
  DBUG_RETURN((COMMANDS *) 0);
1806
1925
}
1807
1926
 
1808
1927
 
1809
 
static bool add_line(string *buffer, char *line, char *in_string,
1810
 
                        bool *ml_comment)
 
1928
static bool add_line(String &buffer,char *line,char *in_string,
 
1929
                     bool *ml_comment)
1811
1930
{
1812
 
  unsigned char inchar;
 
1931
  uchar inchar;
1813
1932
  char buff[80], *pos, *out;
1814
1933
  COMMANDS *com;
1815
1934
  bool need_space= 0;
1816
1935
  bool ss_comment= 0;
1817
 
 
1818
 
 
1819
 
  if (!line[0] && (buffer->empty()))
1820
 
    return(0);
 
1936
  DBUG_ENTER("add_line");
 
1937
 
 
1938
  if (!line[0] && buffer.is_empty())
 
1939
    DBUG_RETURN(0);
 
1940
#ifdef HAVE_READLINE
1821
1941
  if (status.add_to_history && line[0] && not_in_history(line))
1822
1942
    add_history(line);
 
1943
#endif
1823
1944
  char *end_of_line=line+(uint) strlen(line);
1824
1945
 
1825
 
  for (pos=out=line ; (inchar= (unsigned char) *pos) ; pos++)
 
1946
  for (pos=out=line ; (inchar= (uchar) *pos) ; pos++)
1826
1947
  {
1827
1948
    if (!preserve_comments)
1828
1949
    {
1829
1950
      // Skip spaces at the beggining of a statement
1830
1951
      if (my_isspace(charset_info,inchar) && (out == line) &&
1831
 
          (buffer->empty()))
 
1952
          buffer.is_empty())
1832
1953
        continue;
1833
1954
    }
1834
 
 
 
1955
        
1835
1956
#ifdef USE_MB
1836
1957
    // Accept multi-byte characters as-is
1837
1958
    int length;
1849
1970
      continue;
1850
1971
    }
1851
1972
#endif
1852
 
        if (!*ml_comment && inchar == '\\' &&
1853
 
            !(*in_string && (drizzle.server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)))
 
1973
    if (!*ml_comment && inchar == '\\' &&
 
1974
        !(mysql.server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES))
1854
1975
    {
1855
1976
      // Found possbile one character command like \c
1856
1977
 
1857
 
      if (!(inchar = (unsigned char) *++pos))
1858
 
        break;        // readline adds one '\'
1859
 
      if (*in_string || inchar == 'N')  // \N is short for NULL
1860
 
      {          // Don't allow commands in string
1861
 
        *out++='\\';
1862
 
        *out++= (char) inchar;
1863
 
        continue;
 
1978
      if (!(inchar = (uchar) *++pos))
 
1979
        break;                          // readline adds one '\'
 
1980
      if (*in_string || inchar == 'N')  // \N is short for NULL
 
1981
      {                                 // Don't allow commands in string
 
1982
        *out++='\\';
 
1983
        *out++= (char) inchar;
 
1984
        continue;
1864
1985
      }
1865
 
      if ((com=find_command(NULL,(char) inchar)))
 
1986
      if ((com=find_command(NullS,(char) inchar)))
1866
1987
      {
1867
1988
        // Flush previously accepted characters
1868
1989
        if (out != line)
1869
1990
        {
1870
 
          buffer->append(line, (out-line));
 
1991
          buffer.append(line, (uint) (out-line));
1871
1992
          out= line;
1872
1993
        }
1873
 
 
1874
 
        if ((*com->func)(buffer,pos-1) > 0)
1875
 
          return(1);                       // Quit
 
1994
        
 
1995
        if ((*com->func)(&buffer,pos-1) > 0)
 
1996
          DBUG_RETURN(1);                       // Quit
1876
1997
        if (com->takes_params)
1877
1998
        {
1878
1999
          if (ss_comment)
1891
2012
            for (pos++ ;
1892
2013
                 *pos && (*pos != *delimiter ||
1893
2014
                          !is_prefix(pos + 1, delimiter + 1)) ; pos++)
1894
 
              ;  // Remove parameters
 
2015
              ; // Remove parameters
1895
2016
            if (!*pos)
1896
2017
              pos--;
1897
 
            else
 
2018
            else 
1898
2019
              pos+= delimiter_length - 1; // Point at last delim char
1899
2020
          }
1900
2021
        }
1901
2022
      }
1902
2023
      else
1903
2024
      {
1904
 
        sprintf(buff,_("Unknown command '\\%c'."),inchar);
1905
 
        if (put_info(buff,INFO_ERROR,0,0) > 0)
1906
 
          return(1);
1907
 
        *out++='\\';
1908
 
        *out++=(char) inchar;
1909
 
        continue;
 
2025
        sprintf(buff,"Unknown command '\\%c'.",inchar);
 
2026
        if (put_info(buff,INFO_ERROR) > 0)
 
2027
          DBUG_RETURN(1);
 
2028
        *out++='\\';
 
2029
        *out++=(char) inchar;
 
2030
        continue;
1910
2031
      }
1911
2032
    }
1912
2033
    else if (!*ml_comment && !*in_string &&
1913
2034
             (end_of_line - pos) >= 10 &&
1914
 
             !my_strnncoll(charset_info, (unsigned char*) pos, 10,
1915
 
                           (const unsigned char*) "delimiter ", 10))
 
2035
             !my_strnncoll(charset_info, (uchar*) pos, 10,
 
2036
                           (const uchar*) "delimiter ", 10))
1916
2037
    {
1917
2038
      // Flush previously accepted characters
1918
2039
      if (out != line)
1919
2040
      {
1920
 
        buffer->append(line, (out - line));
 
2041
        buffer.append(line, (uint32) (out - line));
1921
2042
        out= line;
1922
2043
      }
1923
2044
 
1924
2045
      // Flush possible comments in the buffer
1925
 
      if (!buffer->empty())
 
2046
      if (!buffer.is_empty())
1926
2047
      {
1927
 
        if (com_go(buffer, 0) > 0) // < 0 is not fatal
1928
 
          return(1);
1929
 
        assert(buffer!=NULL);
1930
 
        buffer->clear();
 
2048
        if (com_go(&buffer, 0) > 0) // < 0 is not fatal
 
2049
          DBUG_RETURN(1);
 
2050
        buffer.length(0);
1931
2051
      }
1932
2052
 
1933
2053
      /*
1934
2054
        Delimiter wants the get rest of the given line as argument to
1935
2055
        allow one to change ';' to ';;' and back
1936
2056
      */
1937
 
      buffer->append(pos);
1938
 
      if (com_delimiter(buffer, pos) > 0)
1939
 
        return(1);
 
2057
      buffer.append(pos);
 
2058
      if (com_delimiter(&buffer, pos) > 0)
 
2059
        DBUG_RETURN(1);
1940
2060
 
1941
 
      buffer->clear();
 
2061
      buffer.length(0);
1942
2062
      break;
1943
2063
    }
1944
2064
    else if (!*ml_comment && !*in_string && is_prefix(pos, delimiter))
1954
2074
      // Flush previously accepted characters
1955
2075
      if (out != line)
1956
2076
      {
1957
 
        buffer->append(line, (out-line));
 
2077
        buffer.append(line, (uint32) (out-line));
1958
2078
        out= line;
1959
2079
      }
1960
2080
 
1964
2084
                                 my_isspace(charset_info, pos[2]))))
1965
2085
      {
1966
2086
        // Add trailing single line comments to this statement
1967
 
        buffer->append(pos);
 
2087
        buffer.append(pos);
1968
2088
        pos+= strlen(pos);
1969
2089
      }
1970
2090
 
1971
2091
      pos--;
1972
2092
 
1973
 
      if ((com= find_command(buffer->c_str(), 0)))
 
2093
      if ((com= find_command(buffer.c_ptr(), 0)))
1974
2094
      {
1975
 
 
1976
 
        if ((*com->func)(buffer, buffer->c_str()) > 0)
1977
 
          return(1);                       // Quit
 
2095
          
 
2096
        if ((*com->func)(&buffer, buffer.c_ptr()) > 0)
 
2097
          DBUG_RETURN(1);                       // Quit 
1978
2098
      }
1979
2099
      else
1980
2100
      {
1981
 
        if (com_go(buffer, 0) > 0)             // < 0 is not fatal
1982
 
          return(1);
 
2101
        if (com_go(&buffer, 0) > 0)             // < 0 is not fatal
 
2102
          DBUG_RETURN(1);
1983
2103
      }
1984
 
      buffer->clear();
 
2104
      buffer.length(0);
1985
2105
    }
1986
 
    else if (!*ml_comment
1987
 
             && (!*in_string
1988
 
                 && (inchar == '#'
1989
 
                     || (inchar == '-'
1990
 
                         && pos[1] == '-'
1991
 
                         && my_isspace(charset_info,pos[2])))))
 
2106
    else if (!*ml_comment && (!*in_string && (inchar == '#' ||
 
2107
                              inchar == '-' && pos[1] == '-' &&
 
2108
                              my_isspace(charset_info,pos[2]))))
1992
2109
    {
1993
2110
      // Flush previously accepted characters
1994
2111
      if (out != line)
1995
2112
      {
1996
 
        buffer->append(line, (out - line));
 
2113
        buffer.append(line, (uint32) (out - line));
1997
2114
        out= line;
1998
2115
      }
1999
2116
 
2000
2117
      // comment to end of line
2001
2118
      if (preserve_comments)
2002
 
        buffer->append(pos);
 
2119
        buffer.append(pos);
2003
2120
 
2004
2121
      break;
2005
2122
    }
2006
2123
    else if (!*in_string && inchar == '/' && *(pos+1) == '*' &&
2007
 
             *(pos+2) != '!')
 
2124
             *(pos+2) != '!')
2008
2125
    {
2009
2126
      if (preserve_comments)
2010
2127
      {
2016
2133
      *ml_comment= 1;
2017
2134
      if (out != line)
2018
2135
      {
2019
 
        buffer->append(line, (out-line));
 
2136
        buffer.append(line,(uint) (out-line));
2020
2137
        out=line;
2021
2138
      }
2022
2139
    }
2032
2149
      *ml_comment= 0;
2033
2150
      if (out != line)
2034
2151
      {
2035
 
        buffer->append(line, (out - line));
 
2152
        buffer.append(line, (uint32) (out - line));
2036
2153
        out= line;
2037
2154
      }
2038
2155
      // Consumed a 2 chars or more, and will add 1 at most,
2039
2156
      // so using the 'line' buffer to edit data in place is ok.
2040
2157
      need_space= 1;
2041
 
    }
 
2158
    }      
2042
2159
    else
2043
 
    {
2044
 
      // Add found char to buffer
 
2160
    {                                           // Add found char to buffer
2045
2161
      if (!*in_string && inchar == '/' && *(pos + 1) == '*' &&
2046
2162
          *(pos + 2) == '!')
2047
2163
        ss_comment= 1;
2048
2164
      else if (!*in_string && ss_comment && inchar == '*' && *(pos + 1) == '/')
2049
2165
        ss_comment= 0;
2050
2166
      if (inchar == *in_string)
2051
 
        *in_string= 0;
 
2167
        *in_string= 0;
2052
2168
      else if (!*ml_comment && !*in_string &&
2053
 
               (inchar == '\'' || inchar == '"' || inchar == '`'))
2054
 
        *in_string= (char) inchar;
 
2169
               (inchar == '\'' || inchar == '"' || inchar == '`'))
 
2170
        *in_string= (char) inchar;
2055
2171
      if (!*ml_comment || preserve_comments)
2056
2172
      {
2057
2173
        if (need_space && !my_isspace(charset_info, (char)inchar))
2061
2177
      }
2062
2178
    }
2063
2179
  }
2064
 
  if (out != line || (buffer->length() > 0))
 
2180
  if (out != line || !buffer.is_empty())
2065
2181
  {
2066
2182
    *out++='\n';
2067
2183
    uint length=(uint) (out-line);
2068
 
    if ((!*ml_comment || preserve_comments))
2069
 
      buffer->append(line, length);
 
2184
    if (buffer.length() + length >= buffer.alloced_length())
 
2185
      buffer.realloc(buffer.length()+length+IO_SIZE);
 
2186
    if ((!*ml_comment || preserve_comments) && buffer.append(line, length))
 
2187
      DBUG_RETURN(1);
2070
2188
  }
2071
 
  return(0);
 
2189
  DBUG_RETURN(0);
2072
2190
}
2073
2191
 
2074
2192
/*****************************************************************
2075
 
            Interface to Readline Completion
 
2193
            Interface to Readline Completion
2076
2194
******************************************************************/
2077
2195
 
 
2196
#ifdef HAVE_READLINE
2078
2197
 
2079
 
static char **mysql_completion (const char *text, int start, int end);
2080
2198
static char *new_command_generator(const char *text, int);
 
2199
extern "C" char **new_mysql_completion (const char *text, int start, int end);
2081
2200
 
2082
2201
/*
2083
2202
  Tell the GNU Readline library how to complete.  We want to try to complete
2084
2203
  on command names if this is the first word in the line, or on filenames
2085
2204
  if not.
2086
2205
*/
2087
 
static char *no_completion(const char * a __attribute__((unused)),
2088
 
                           int b __attribute__((unused)))
 
2206
 
 
2207
#if defined(USE_NEW_READLINE_INTERFACE) || defined(USE_LIBEDIT_INTERFACE)
 
2208
extern "C" char *no_completion(const char*,int)
 
2209
#else
 
2210
extern "C" char *no_completion()
 
2211
#endif
2089
2212
{
2090
 
  /* No filename completion */
2091
 
  return 0;
 
2213
  return 0;                                     /* No filename completion */
2092
2214
}
2093
2215
 
2094
 
 
2095
 
/* glues pieces of history back together if in pieces   */
2096
 
static void fix_history(string *final_command)
 
2216
/*      glues pieces of history back together if in pieces   */
 
2217
static void fix_history(String *final_command) 
2097
2218
{
2098
2219
  int total_lines = 1;
2099
 
  const char *ptr = final_command->c_str();
 
2220
  char *ptr = final_command->c_ptr();
 
2221
  String fixed_buffer;  /* Converted buffer */
2100
2222
  char str_char = '\0';  /* Character if we are in a string or not */
2101
 
 
2102
 
  /* Converted buffer */
2103
 
  string fixed_buffer;
2104
 
  fixed_buffer.reserve(512);
2105
 
 
 
2223
  
2106
2224
  /* find out how many lines we have and remove newlines */
2107
 
  while (*ptr != '\0')
 
2225
  while (*ptr != '\0') 
2108
2226
  {
2109
2227
    switch (*ptr) {
2110
2228
      /* string character */
2111
2229
    case '"':
2112
2230
    case '\'':
2113
2231
    case '`':
2114
 
      // open string
2115
 
      if (str_char == '\0')
2116
 
        str_char = *ptr;
 
2232
      if (str_char == '\0')     /* open string */
 
2233
        str_char = *ptr;
2117
2234
      else if (str_char == *ptr)   /* close string */
2118
 
        str_char = '\0';
2119
 
      fixed_buffer.append(ptr, 1);
 
2235
        str_char = '\0';
 
2236
      fixed_buffer.append(ptr,1);
2120
2237
      break;
2121
2238
    case '\n':
2122
 
      /*
2123
 
        not in string, change to space
2124
 
        if in string, leave it alone
 
2239
      /* 
 
2240
         not in string, change to space
 
2241
         if in string, leave it alone 
2125
2242
      */
2126
 
      fixed_buffer.append((str_char == '\0') ? " " : "\n");
 
2243
      fixed_buffer.append(str_char == '\0' ? " " : "\n");
2127
2244
      total_lines++;
2128
2245
      break;
2129
2246
    case '\\':
2130
 
      fixed_buffer.append("\\");
 
2247
      fixed_buffer.append('\\');
2131
2248
      /* need to see if the backslash is escaping anything */
2132
 
      if (str_char)
 
2249
      if (str_char) 
2133
2250
      {
2134
 
        ptr++;
2135
 
        /* special characters that need escaping */
2136
 
        if (*ptr == '\'' || *ptr == '"' || *ptr == '\\')
2137
 
          fixed_buffer.append(ptr, 1);
2138
 
        else
2139
 
          ptr--;
 
2251
        ptr++;
 
2252
        /* special characters that need escaping */
 
2253
        if (*ptr == '\'' || *ptr == '"' || *ptr == '\\')
 
2254
          fixed_buffer.append(ptr,1);
 
2255
        else
 
2256
          ptr--;
2140
2257
      }
2141
2258
      break;
 
2259
      
2142
2260
    default:
2143
 
      fixed_buffer.append(ptr, 1);
 
2261
      fixed_buffer.append(ptr,1);
2144
2262
    }
2145
2263
    ptr++;
2146
2264
  }
2147
 
  if (total_lines > 1)
2148
 
    add_history(fixed_buffer.c_str());
 
2265
  if (total_lines > 1)                  
 
2266
    add_history(fixed_buffer.ptr());
2149
2267
}
2150
2268
 
2151
 
/*
 
2269
/*      
2152
2270
  returns 0 if line matches the previous history entry
2153
2271
  returns 1 if the line doesn't match the previous history entry
2154
2272
*/
2155
 
static int not_in_history(const char *line)
 
2273
static int not_in_history(const char *line) 
2156
2274
{
2157
2275
  HIST_ENTRY *oldhist = history_get(history_length);
2158
 
 
 
2276
  
2159
2277
  if (oldhist == 0)
2160
2278
    return 1;
2161
2279
  if (strcmp(oldhist->line,line) == 0)
2166
2284
static void initialize_readline (char *name)
2167
2285
{
2168
2286
  /* Allow conditional parsing of the ~/.inputrc file. */
2169
 
  rl_readline_name= name;
 
2287
  rl_readline_name = name;
2170
2288
 
2171
2289
  /* Tell the completer that we want a crack first. */
2172
 
  rl_attempted_completion_function= (rl_completion_func_t*)&mysql_completion;
 
2290
  rl_attempted_completion_function= (rl_completion_func_t*)&new_mysql_completion;
2173
2291
  rl_completion_entry_function= (rl_compentry_func_t*)&no_completion;
2174
2292
}
2175
2293
 
2176
 
 
2177
2294
/*
2178
2295
  Attempt to complete on the contents of TEXT.  START and END show the
2179
2296
  region of TEXT that contains the word to complete.  We can use the
2180
2297
  entire line in case we want to do some simple parsing.  Return the
2181
2298
  array of matches, or NULL if there aren't any.
2182
2299
*/
2183
 
char **mysql_completion (const char *text,
2184
 
                        int start __attribute__((unused)),
2185
 
                        int end __attribute__((unused)))
 
2300
 
 
2301
char **new_mysql_completion (const char *text,
 
2302
                             int start __attribute__((unused)),
 
2303
                             int end __attribute__((unused)))
2186
2304
{
2187
2305
  if (!status.batch && !quick)
2188
2306
    return rl_completion_matches(text, new_command_generator);
2190
2308
    return (char**) 0;
2191
2309
}
2192
2310
 
2193
 
 
2194
2311
static char *new_command_generator(const char *text,int state)
2195
2312
{
2196
2313
  static int textlen;
2203
2320
    textlen=(uint) strlen(text);
2204
2321
 
2205
2322
  if (textlen>0)
2206
 
  {            /* lookup in the hash */
 
2323
  {                                             /* lookup in the hash */
2207
2324
    if (!state)
2208
2325
    {
2209
2326
      uint len;
2210
2327
 
2211
2328
      b = find_all_matches(&ht,text,(uint) strlen(text),&len);
2212
2329
      if (!b)
2213
 
        return NULL;
 
2330
        return NullS;
2214
2331
      e = b->pData;
2215
2332
    }
2216
2333
 
2229
2346
      /* find the first used bucket */
2230
2347
      for (i=0 ; i < ht.nTableSize ; i++)
2231
2348
      {
2232
 
        if (ht.arBuckets[i])
2233
 
        {
2234
 
          b = ht.arBuckets[i];
2235
 
          e = b->pData;
2236
 
          break;
2237
 
        }
 
2349
        if (ht.arBuckets[i])
 
2350
        {
 
2351
          b = ht.arBuckets[i];
 
2352
          e = b->pData;
 
2353
          break;
 
2354
        }
2238
2355
      }
2239
2356
    }
2240
 
    ptr= NULL;
 
2357
    ptr= NullS;
2241
2358
    while (e && !ptr)
2242
 
    {          /* find valid entry in bucket */
 
2359
    {                                   /* find valid entry in bucket */
2243
2360
      if ((uint) strlen(e->str) == b->nKeyLength)
2244
 
        ptr = strdup(e->str);
 
2361
        ptr = strdup(e->str);
2245
2362
      /* find the next used entry */
2246
2363
      e = e->pNext;
2247
2364
      if (!e)
2248
2365
      { /* find the next used bucket */
2249
 
        b = b->pNext;
2250
 
        if (!b)
2251
 
        {
2252
 
          for (i++ ; i<ht.nTableSize; i++)
2253
 
          {
2254
 
            if (ht.arBuckets[i])
2255
 
            {
2256
 
              b = ht.arBuckets[i];
2257
 
              e = b->pData;
2258
 
              break;
2259
 
            }
2260
 
          }
2261
 
        }
2262
 
        else
2263
 
          e = b->pData;
 
2366
        b = b->pNext;
 
2367
        if (!b)
 
2368
        {
 
2369
          for (i++ ; i<ht.nTableSize; i++)
 
2370
          {
 
2371
            if (ht.arBuckets[i])
 
2372
            {
 
2373
              b = ht.arBuckets[i];
 
2374
              e = b->pData;
 
2375
              break;
 
2376
            }
 
2377
          }
 
2378
        }
 
2379
        else
 
2380
          e = b->pData;
2264
2381
      }
2265
2382
    }
2266
2383
    if (ptr)
2267
2384
      return ptr;
2268
2385
  }
2269
 
  return NULL;
 
2386
  return NullS;
2270
2387
}
2271
2388
 
2272
2389
 
2275
2392
static void build_completion_hash(bool rehash, bool write_info)
2276
2393
{
2277
2394
  COMMANDS *cmd=commands;
2278
 
  DRIZZLE_RES *databases=0,*tables=0;
2279
 
  DRIZZLE_RES *fields;
 
2395
  MYSQL_RES *databases=0,*tables=0;
 
2396
  MYSQL_RES *fields;
2280
2397
  static char ***field_names= 0;
2281
 
  DRIZZLE_ROW database_row,table_row;
2282
 
  DRIZZLE_FIELD *sql_field;
2283
 
  char buf[NAME_LEN*2+2];     // table name plus field name plus 2
 
2398
  MYSQL_ROW database_row,table_row;
 
2399
  MYSQL_FIELD *sql_field;
 
2400
  char buf[NAME_LEN*2+2];                // table name plus field name plus 2
2284
2401
  int i,j,num_fields;
2285
 
 
 
2402
  DBUG_ENTER("build_completion_hash");
2286
2403
 
2287
2404
  if (status.batch || quick || !current_db)
2288
 
    return;      // We don't need completion in batches
 
2405
    DBUG_VOID_RETURN;                   // We don't need completion in batches
2289
2406
  if (!rehash)
2290
 
    return;
 
2407
    DBUG_VOID_RETURN;
2291
2408
 
2292
2409
  /* Free old used memory */
2293
2410
  if (field_names)
2301
2418
    cmd++;
2302
2419
  }
2303
2420
 
2304
 
  /* hash Drizzle functions (to be implemented) */
 
2421
  /* hash MySQL functions (to be implemented) */
2305
2422
 
2306
2423
  /* hash all database names */
2307
 
  if (drizzle_query(&drizzle,"show databases") == 0)
 
2424
  if (mysql_query(&mysql,"show databases") == 0)
2308
2425
  {
2309
 
    if (!(databases = drizzle_store_result(&drizzle)))
2310
 
      put_info(drizzle_error(&drizzle),INFO_INFO,0,0);
 
2426
    if (!(databases = mysql_store_result(&mysql)))
 
2427
      put_info(mysql_error(&mysql),INFO_INFO);
2311
2428
    else
2312
2429
    {
2313
 
      while ((database_row=drizzle_fetch_row(databases)))
 
2430
      while ((database_row=mysql_fetch_row(databases)))
2314
2431
      {
2315
 
        char *str=strdup_root(&hash_mem_root, (char*) database_row[0]);
2316
 
        if (str)
2317
 
          add_word(&ht,(char*) str);
 
2432
        char *str=strdup_root(&hash_mem_root, (char*) database_row[0]);
 
2433
        if (str)
 
2434
          add_word(&ht,(char*) str);
2318
2435
      }
2319
 
      drizzle_free_result(databases);
 
2436
      mysql_free_result(databases);
2320
2437
    }
2321
2438
  }
2322
2439
  /* hash all table names */
2323
 
  if (drizzle_query(&drizzle,"show tables")==0)
 
2440
  if (mysql_query(&mysql,"show tables")==0)
2324
2441
  {
2325
 
    if (!(tables = drizzle_store_result(&drizzle)))
2326
 
      put_info(drizzle_error(&drizzle),INFO_INFO,0,0);
 
2442
    if (!(tables = mysql_store_result(&mysql)))
 
2443
      put_info(mysql_error(&mysql),INFO_INFO);
2327
2444
    else
2328
2445
    {
2329
 
      if (drizzle_num_rows(tables) > 0 && !opt_silent && write_info)
 
2446
      if (mysql_num_rows(tables) > 0 && !opt_silent && write_info)
2330
2447
      {
2331
 
        tee_fprintf(stdout, _("\
2332
 
Reading table information for completion of table and column names\n    \
2333
 
You can turn off this feature to get a quicker startup with -A\n\n"));
 
2448
        tee_fprintf(stdout, "\
 
2449
Reading table information for completion of table and column names\n\
 
2450
You can turn off this feature to get a quicker startup with -A\n\n");
2334
2451
      }
2335
 
      while ((table_row=drizzle_fetch_row(tables)))
 
2452
      while ((table_row=mysql_fetch_row(tables)))
2336
2453
      {
2337
 
        char *str=strdup_root(&hash_mem_root, (char*) table_row[0]);
2338
 
        if (str &&
2339
 
            !completion_hash_exists(&ht,(char*) str, (uint) strlen(str)))
2340
 
          add_word(&ht,str);
 
2454
        char *str=strdup_root(&hash_mem_root, (char*) table_row[0]);
 
2455
        if (str &&
 
2456
            !completion_hash_exists(&ht,(char*) str, (uint) strlen(str)))
 
2457
          add_word(&ht,str);
2341
2458
      }
2342
2459
    }
2343
2460
  }
2344
2461
 
2345
2462
  /* hash all field names, both with the table prefix and without it */
2346
 
  if (!tables)          /* no tables */
 
2463
  if (!tables)                                  /* no tables */
2347
2464
  {
2348
 
    return;
 
2465
    DBUG_VOID_RETURN;
2349
2466
  }
2350
 
  drizzle_data_seek(tables,0);
 
2467
  mysql_data_seek(tables,0);
2351
2468
  if (!(field_names= (char ***) alloc_root(&hash_mem_root,sizeof(char **) *
2352
 
                                           (uint) (drizzle_num_rows(tables)+1))))
 
2469
                                           (uint) (mysql_num_rows(tables)+1))))
2353
2470
  {
2354
 
    drizzle_free_result(tables);
2355
 
    return;
 
2471
    mysql_free_result(tables);
 
2472
    DBUG_VOID_RETURN;
2356
2473
  }
2357
2474
  i=0;
2358
 
  while ((table_row=drizzle_fetch_row(tables)))
 
2475
  while ((table_row=mysql_fetch_row(tables)))
2359
2476
  {
2360
 
    if ((fields=drizzle_list_fields(&drizzle,(const char*) table_row[0],NULL)))
 
2477
    if ((fields=mysql_list_fields(&mysql,(const char*) table_row[0],NullS)))
2361
2478
    {
2362
 
      num_fields=drizzle_num_fields(fields);
 
2479
      num_fields=mysql_num_fields(fields);
2363
2480
      if (!(field_names[i] = (char **) alloc_root(&hash_mem_root,
2364
 
                                                  sizeof(char *) *
2365
 
                                                  (num_fields*2+1))))
 
2481
                                                  sizeof(char *) *
 
2482
                                                  (num_fields*2+1))))
2366
2483
      {
2367
 
        drizzle_free_result(fields);
 
2484
        mysql_free_result(fields);
2368
2485
        break;
2369
2486
      }
2370
2487
      field_names[i][num_fields*2]= '\0';
2371
2488
      j=0;
2372
 
      while ((sql_field=drizzle_fetch_field(fields)))
 
2489
      while ((sql_field=mysql_fetch_field(fields)))
2373
2490
      {
2374
 
        sprintf(buf,"%.64s.%.64s",table_row[0],sql_field->name);
2375
 
        field_names[i][j] = strdup_root(&hash_mem_root,buf);
2376
 
        add_word(&ht,field_names[i][j]);
2377
 
        field_names[i][num_fields+j] = strdup_root(&hash_mem_root,
2378
 
                                                   sql_field->name);
2379
 
        if (!completion_hash_exists(&ht,field_names[i][num_fields+j],
2380
 
                                    (uint) strlen(field_names[i][num_fields+j])))
2381
 
          add_word(&ht,field_names[i][num_fields+j]);
2382
 
        j++;
 
2491
        sprintf(buf,"%.64s.%.64s",table_row[0],sql_field->name);
 
2492
        field_names[i][j] = strdup_root(&hash_mem_root,buf);
 
2493
        add_word(&ht,field_names[i][j]);
 
2494
        field_names[i][num_fields+j] = strdup_root(&hash_mem_root,
 
2495
                                                   sql_field->name);
 
2496
        if (!completion_hash_exists(&ht,field_names[i][num_fields+j],
 
2497
                                    (uint) strlen(field_names[i][num_fields+j])))
 
2498
          add_word(&ht,field_names[i][num_fields+j]);
 
2499
        j++;
2383
2500
      }
2384
 
      drizzle_free_result(fields);
 
2501
      mysql_free_result(fields);
2385
2502
    }
2386
2503
    else
2387
2504
      field_names[i]= 0;
2388
2505
 
2389
2506
    i++;
2390
2507
  }
2391
 
  drizzle_free_result(tables);
2392
 
  field_names[i]=0;        // End pointer
2393
 
  return;
 
2508
  mysql_free_result(tables);
 
2509
  field_names[i]=0;                             // End pointer
 
2510
  DBUG_VOID_RETURN;
2394
2511
}
2395
2512
 
2396
 
/* for gnu readline */
 
2513
        /* for gnu readline */
2397
2514
 
2398
2515
#ifndef HAVE_INDEX
2399
2516
extern "C" {
2400
 
  extern char *index(const char *,int c),*rindex(const char *,int);
2401
 
 
2402
 
  char *index(const char *s,int c)
2403
 
  {
2404
 
    for (;;)
2405
 
    {
2406
 
      if (*s == (char) c) return (char*) s;
2407
 
      if (!*s++) return NULL;
2408
 
    }
2409
 
  }
2410
 
 
2411
 
  char *rindex(const char *s,int c)
2412
 
  {
2413
 
    register char *t;
2414
 
 
2415
 
    t = NULL;
2416
 
    do if (*s == (char) c) t = (char*) s; while (*s++);
2417
 
    return (char*) t;
2418
 
  }
 
2517
extern char *index(const char *,int c),*rindex(const char *,int);
 
2518
 
 
2519
char *index(const char *s,int c)
 
2520
{
 
2521
  for (;;)
 
2522
  {
 
2523
     if (*s == (char) c) return (char*) s;
 
2524
     if (!*s++) return NullS;
 
2525
  }
 
2526
}
 
2527
 
 
2528
char *rindex(const char *s,int c)
 
2529
{
 
2530
  register char *t;
 
2531
 
 
2532
  t = NullS;
 
2533
  do if (*s == (char) c) t = (char*) s; while (*s++);
 
2534
  return (char*) t;
 
2535
}
2419
2536
}
2420
2537
#endif
 
2538
#endif /* HAVE_READLINE */
2421
2539
 
2422
2540
 
2423
2541
static int reconnect(void)
2425
2543
  /* purecov: begin tested */
2426
2544
  if (opt_reconnect)
2427
2545
  {
2428
 
    put_info(_("No connection. Trying to reconnect..."),INFO_INFO,0,0);
2429
 
    (void) com_connect((string *)0, 0);
 
2546
    put_info("No connection. Trying to reconnect...",INFO_INFO);
 
2547
    (void) com_connect((String *) 0, 0);
2430
2548
    if (opt_rehash)
2431
2549
      com_rehash(NULL, NULL);
2432
2550
  }
2433
2551
  if (!connected)
2434
 
    return put_info(_("Can't connect to the server\n"),INFO_ERROR,0,0);
 
2552
    return put_info("Can't connect to the server\n",INFO_ERROR);
2435
2553
  /* purecov: end */
2436
2554
  return 0;
2437
2555
}
2438
2556
 
2439
 
static void get_current_db(void)
 
2557
static void get_current_db()
2440
2558
{
2441
 
  DRIZZLE_RES *res;
 
2559
  MYSQL_RES *res;
2442
2560
 
2443
 
  free(current_db);
 
2561
  my_free(current_db, MYF(MY_ALLOW_ZERO_PTR));
2444
2562
  current_db= NULL;
2445
2563
  /* In case of error below current_db will be NULL */
2446
 
  if (!drizzle_query(&drizzle, "SELECT DATABASE()") &&
2447
 
      (res= drizzle_use_result(&drizzle)))
 
2564
  if (!mysql_query(&mysql, "SELECT DATABASE()") &&
 
2565
      (res= mysql_use_result(&mysql)))
2448
2566
  {
2449
 
    DRIZZLE_ROW row= drizzle_fetch_row(res);
 
2567
    MYSQL_ROW row= mysql_fetch_row(res);
2450
2568
    if (row[0])
2451
 
      current_db= strdup(row[0]);
2452
 
    drizzle_free_result(res);
 
2569
      current_db= my_strdup(row[0], MYF(MY_WME));
 
2570
    mysql_free_result(res);
2453
2571
  }
2454
2572
}
2455
2573
 
2457
2575
 The different commands
2458
2576
***************************************************************************/
2459
2577
 
2460
 
int drizzle_real_query_for_lazy(const char *buf, int length)
 
2578
int mysql_real_query_for_lazy(const char *buf, int length)
2461
2579
{
2462
2580
  for (uint retry=0;; retry++)
2463
2581
  {
2464
2582
    int error;
2465
 
    if (!drizzle_real_query(&drizzle,buf,length))
 
2583
    if (!mysql_real_query(&mysql,buf,length))
2466
2584
      return 0;
2467
 
    error= put_error(&drizzle);
2468
 
    if (drizzle_errno(&drizzle) != CR_SERVER_GONE_ERROR || retry > 1 ||
 
2585
    error= put_error(&mysql);
 
2586
    if (mysql_errno(&mysql) != CR_SERVER_GONE_ERROR || retry > 1 ||
2469
2587
        !opt_reconnect)
2470
2588
      return error;
2471
2589
    if (reconnect())
2473
2591
  }
2474
2592
}
2475
2593
 
2476
 
int drizzle_store_result_for_lazy(DRIZZLE_RES **result)
 
2594
int mysql_store_result_for_lazy(MYSQL_RES **result)
2477
2595
{
2478
 
  if ((*result=drizzle_store_result(&drizzle)))
 
2596
  if ((*result=mysql_store_result(&mysql)))
2479
2597
    return 0;
2480
2598
 
2481
 
  if (drizzle_error(&drizzle)[0])
2482
 
    return put_error(&drizzle);
 
2599
  if (mysql_error(&mysql)[0])
 
2600
    return put_error(&mysql);
2483
2601
  return 0;
2484
2602
}
2485
2603
 
2486
 
static void print_help_item(DRIZZLE_ROW *cur, int num_name, int num_cat, char *last_char)
 
2604
static void print_help_item(MYSQL_ROW *cur, int num_name, int num_cat, char *last_char)
2487
2605
{
2488
2606
  char ccat= (*cur)[num_cat][0];
2489
2607
  if (*last_char != ccat)
2490
2608
  {
2491
 
    put_info(ccat == 'Y' ? _("categories:") : _("topics:"), INFO_INFO,0,0);
 
2609
    put_info(ccat == 'Y' ? "categories:" : "topics:", INFO_INFO);
2492
2610
    *last_char= ccat;
2493
2611
  }
2494
2612
  tee_fprintf(PAGER, "   %s\n", (*cur)[num_name]);
2495
2613
}
2496
2614
 
2497
2615
 
2498
 
static int com_server_help(string *buffer,
2499
 
                           const char *line __attribute__((unused)),
2500
 
                           char *help_arg)
 
2616
static int com_server_help(String *buffer __attribute__((unused)),
 
2617
                           char *line __attribute__((unused)), char *help_arg)
2501
2618
{
2502
 
  DRIZZLE_ROW cur;
2503
 
  const char *server_cmd= buffer->c_str();
 
2619
  MYSQL_ROW cur;
 
2620
  const char *server_cmd= buffer->ptr();
2504
2621
  char cmd_buf[100];
2505
 
  DRIZZLE_RES *result;
 
2622
  MYSQL_RES *result;
2506
2623
  int error;
2507
 
 
 
2624
  
2508
2625
  if (help_arg[0] != '\'')
2509
2626
  {
2510
 
    char *end_arg= strchr(help_arg, '\0');
2511
 
    if(--end_arg)
2512
 
    {
2513
 
      while (my_isspace(charset_info,*end_arg))
2514
 
        end_arg--;
2515
 
      *++end_arg= '\0';
2516
 
    }
2517
 
    (void) strxnmov(cmd_buf, sizeof(cmd_buf), "help '", help_arg, "'", NULL);
 
2627
        char *end_arg= strend(help_arg);
 
2628
        if(--end_arg)
 
2629
        {
 
2630
                while (my_isspace(charset_info,*end_arg))
 
2631
          end_arg--;
 
2632
                *++end_arg= '\0';
 
2633
        }
 
2634
        (void) strxnmov(cmd_buf, sizeof(cmd_buf), "help '", help_arg, "'", NullS);
2518
2635
    server_cmd= cmd_buf;
2519
2636
  }
 
2637
  
 
2638
  if (!status.batch)
 
2639
  {
 
2640
    old_buffer= *buffer;
 
2641
    old_buffer.copy();
 
2642
  }
2520
2643
 
2521
2644
  if (!connected && reconnect())
2522
2645
    return 1;
2523
2646
 
2524
 
  if ((error= drizzle_real_query_for_lazy(server_cmd,(int)strlen(server_cmd))) ||
2525
 
      (error= drizzle_store_result_for_lazy(&result)))
 
2647
  if ((error= mysql_real_query_for_lazy(server_cmd,(int)strlen(server_cmd))) ||
 
2648
      (error= mysql_store_result_for_lazy(&result)))
2526
2649
    return error;
2527
2650
 
2528
2651
  if (result)
2529
2652
  {
2530
 
    unsigned int num_fields= drizzle_num_fields(result);
2531
 
    uint64_t num_rows= drizzle_num_rows(result);
2532
 
    drizzle_fetch_fields(result);
 
2653
    unsigned int num_fields= mysql_num_fields(result);
 
2654
    my_ulonglong num_rows= mysql_num_rows(result);
 
2655
    mysql_fetch_fields(result);
2533
2656
    if (num_fields==3 && num_rows==1)
2534
2657
    {
2535
 
      if (!(cur= drizzle_fetch_row(result)))
 
2658
      if (!(cur= mysql_fetch_row(result)))
2536
2659
      {
2537
 
        error= -1;
2538
 
        goto err;
 
2660
        error= -1;
 
2661
        goto err;
2539
2662
      }
2540
2663
 
2541
2664
      init_pager();
2542
 
      tee_fprintf(PAGER,   _("Name: \'%s\'\n"), cur[0]);
2543
 
      tee_fprintf(PAGER,   _("Description:\n%s"), cur[1]);
 
2665
      tee_fprintf(PAGER,   "Name: \'%s\'\n", cur[0]);
 
2666
      tee_fprintf(PAGER,   "Description:\n%s", cur[1]);
2544
2667
      if (cur[2] && *((char*)cur[2]))
2545
 
        tee_fprintf(PAGER, _("Examples:\n%s"), cur[2]);
 
2668
        tee_fprintf(PAGER, "Examples:\n%s", cur[2]);
2546
2669
      tee_fprintf(PAGER,   "\n");
2547
2670
      end_pager();
2548
2671
    }
2555
2678
 
2556
2679
      if (num_fields == 2)
2557
2680
      {
2558
 
        put_info(_("Many help items for your request exist."), INFO_INFO,0,0);
2559
 
        put_info(_("To make a more specific request, please type 'help <item>',\nwhere <item> is one of the following"), INFO_INFO,0,0);
2560
 
        num_name= 0;
2561
 
        num_cat= 1;
 
2681
        put_info("Many help items for your request exist.", INFO_INFO);
 
2682
        put_info("To make a more specific request, please type 'help <item>',\nwhere <item> is one of the following", INFO_INFO);
 
2683
        num_name= 0;
 
2684
        num_cat= 1;
2562
2685
      }
2563
 
      else if ((cur= drizzle_fetch_row(result)))
 
2686
      else if ((cur= mysql_fetch_row(result)))
2564
2687
      {
2565
 
        tee_fprintf(PAGER, _("You asked for help about help category: '%s'\n"), cur[0]);
2566
 
        put_info(_("For more information, type 'help <item>', where <item> is one of the following"), INFO_INFO,0,0);
2567
 
        num_name= 1;
2568
 
        num_cat= 2;
2569
 
        print_help_item(&cur,1,2,&last_char);
 
2688
        tee_fprintf(PAGER, "You asked for help about help category: \"%s\"\n", cur[0]);
 
2689
        put_info("For more information, type 'help <item>', where <item> is one of the following", INFO_INFO);
 
2690
        num_name= 1;
 
2691
        num_cat= 2;
 
2692
        print_help_item(&cur,1,2,&last_char);
2570
2693
      }
2571
2694
 
2572
 
      while ((cur= drizzle_fetch_row(result)))
2573
 
        print_help_item(&cur,num_name,num_cat,&last_char);
 
2695
      while ((cur= mysql_fetch_row(result)))
 
2696
        print_help_item(&cur,num_name,num_cat,&last_char);
2574
2697
      tee_fprintf(PAGER, "\n");
2575
2698
      end_pager();
2576
2699
    }
2577
2700
    else
2578
2701
    {
2579
 
      put_info(_("\nNothing found"), INFO_INFO,0,0);
2580
 
      put_info(_("Please try to run 'help contents' for a list of all accessible topics\n"), INFO_INFO,0,0);
 
2702
      put_info("\nNothing found", INFO_INFO);
 
2703
      put_info("Please try to run 'help contents' for a list of all accessible topics\n", INFO_INFO);
2581
2704
    }
2582
2705
  }
2583
2706
 
2584
2707
err:
2585
 
  drizzle_free_result(result);
 
2708
  mysql_free_result(result);
2586
2709
  return error;
2587
2710
}
2588
2711
 
2589
2712
static int
2590
 
com_help(string *buffer __attribute__((unused)),
2591
 
         const char *line __attribute__((unused)))
 
2713
com_help(String *buffer __attribute__((unused)),
 
2714
         char *line __attribute__((unused)))
2592
2715
{
2593
2716
  register int i, j;
2594
2717
  char * help_arg= strchr(line,' '), buff[32], *end;
2596
2719
  {
2597
2720
    while (my_isspace(charset_info,*help_arg))
2598
2721
      help_arg++;
2599
 
    if (*help_arg) return com_server_help(buffer,line,help_arg);
 
2722
        if (*help_arg)    
 
2723
          return com_server_help(buffer,line,help_arg);
2600
2724
  }
2601
2725
 
2602
 
  put_info(_("List of all Drizzle commands:"), INFO_INFO,0,0);
 
2726
  put_info("\nFor information about MySQL products and services, visit:\n"
 
2727
           "   http://www.mysql.com/\n"
 
2728
           "For developer information, including the MySQL Reference Manual, "
 
2729
           "visit:\n"
 
2730
           "   http://dev.mysql.com/\n"
 
2731
           "To buy MySQL Network Support, training, or other products, visit:\n"
 
2732
           "   https://shop.mysql.com/\n", INFO_INFO);
 
2733
  put_info("List of all MySQL commands:", INFO_INFO);
2603
2734
  if (!named_cmds)
2604
 
    put_info(_("Note that all text commands must be first on line and end with ';'"),INFO_INFO,0,0);
 
2735
    put_info("Note that all text commands must be first on line and end with ';'",INFO_INFO);
2605
2736
  for (i = 0; commands[i].name; i++)
2606
2737
  {
2607
 
    end= my_stpcpy(buff, commands[i].name);
 
2738
    end= strmov(buff, commands[i].name);
2608
2739
    for (j= (int)strlen(commands[i].name); j < 10; j++)
2609
 
      end= my_stpcpy(end, " ");
 
2740
      end= strmov(end, " ");
2610
2741
    if (commands[i].func)
2611
2742
      tee_fprintf(stdout, "%s(\\%c) %s\n", buff,
2612
 
                  commands[i].cmd_char, _(commands[i].doc));
 
2743
                  commands[i].cmd_char, commands[i].doc);
2613
2744
  }
2614
 
  if (connected && drizzle_get_server_version(&drizzle) >= 40100)
2615
 
    put_info(_("\nFor server side help, type 'help contents'\n"), INFO_INFO,0,0);
 
2745
  if (connected && mysql_get_server_version(&mysql) >= 40100)
 
2746
    put_info("\nFor server side help, type 'help contents'\n", INFO_INFO);
2616
2747
  return 0;
2617
2748
}
2618
2749
 
2619
2750
 
 
2751
        /* ARGSUSED */
2620
2752
static int
2621
 
com_clear(string *buffer,
2622
 
          const char *line __attribute__((unused)))
 
2753
com_clear(String *buffer,char *line __attribute__((unused)))
2623
2754
{
 
2755
#ifdef HAVE_READLINE
2624
2756
  if (status.add_to_history)
2625
2757
    fix_history(buffer);
2626
 
  buffer->clear();
 
2758
#endif
 
2759
  buffer->length(0);
2627
2760
  return 0;
2628
2761
}
2629
2762
 
 
2763
        /* ARGSUSED */
 
2764
static int
 
2765
com_charset(String *buffer __attribute__((unused)), char *line)
 
2766
{
 
2767
  char buff[256], *param;
 
2768
  CHARSET_INFO * new_cs;
 
2769
  strmake(buff, line, sizeof(buff) - 1);
 
2770
  param= get_arg(buff, 0);
 
2771
  if (!param || !*param)
 
2772
  {
 
2773
    return put_info("Usage: \\C char_setname | charset charset_name", 
 
2774
                    INFO_ERROR, 0);
 
2775
  }
 
2776
  new_cs= get_charset_by_csname(param, MY_CS_PRIMARY, MYF(MY_WME));
 
2777
  if (new_cs)
 
2778
  {
 
2779
    charset_info= new_cs;
 
2780
    mysql_set_character_set(&mysql, charset_info->csname);
 
2781
    default_charset= (char *)charset_info->csname;
 
2782
    default_charset_used= 1;
 
2783
    put_info("Charset changed", INFO_INFO);
 
2784
  }
 
2785
  else put_info("Charset is not found", INFO_INFO);
 
2786
  return 0;
 
2787
}
2630
2788
 
2631
2789
/*
2632
2790
  Execute command
2633
2791
  Returns: 0  if ok
2634
 
  -1 if not fatal error
2635
 
  1  if fatal error
 
2792
          -1 if not fatal error
 
2793
          1  if fatal error
2636
2794
*/
 
2795
 
 
2796
 
2637
2797
static int
2638
 
com_go(string *buffer,
2639
 
       const char *line __attribute__((unused)))
 
2798
com_go(String *buffer,char *line __attribute__((unused)))
2640
2799
{
2641
 
  char          buff[200]; /* about 110 chars used so far */
2642
 
  char          time_buff[52+3+1]; /* time max + space&parens + NUL */
2643
 
  DRIZZLE_RES     *result;
2644
 
  uint32_t         timer, warnings= 0;
2645
 
  uint          error= 0;
 
2800
  char          buff[200]; /* about 110 chars used so far */
 
2801
  char          time_buff[52+3+1]; /* time max + space&parens + NUL */
 
2802
  MYSQL_RES     *result;
 
2803
  ulong         timer, warnings= 0;
 
2804
  uint          error= 0;
2646
2805
  int           err= 0;
2647
2806
 
2648
2807
  interrupted_query= 0;
 
2808
  if (!status.batch)
 
2809
  {
 
2810
    old_buffer= *buffer;                        // Save for edit command
 
2811
    old_buffer.copy();
 
2812
  }
2649
2813
 
2650
2814
  /* Remove garbage for nicer messages */
2651
 
  remove_cntrl(buffer);
 
2815
  remove_cntrl(*buffer);
2652
2816
 
2653
 
  if (buffer->empty())
 
2817
  if (buffer->is_empty())
2654
2818
  {
2655
 
    // Ignore empty quries
2656
 
    if (status.batch)
 
2819
    if (status.batch)                           // Ignore empty quries
2657
2820
      return 0;
2658
 
    return put_info(_("No query specified\n"),INFO_ERROR,0,0);
 
2821
    return put_info("No query specified\n",INFO_ERROR);
2659
2822
 
2660
2823
  }
2661
2824
  if (!connected && reconnect())
2662
2825
  {
2663
 
    // Remove query on error
2664
 
    buffer->clear();
 
2826
    buffer->length(0);                          // Remove query on error
2665
2827
    return opt_reconnect ? -1 : 1;          // Fatal error
2666
2828
  }
2667
2829
  if (verbose)
2668
 
    (void) com_print(buffer, 0);
 
2830
    (void) com_print(buffer,0);
2669
2831
 
2670
2832
  if (skip_updates &&
2671
 
      ((buffer->length() < 4) || (buffer->find( "SET ") != 0)))
 
2833
      (buffer->length() < 4 || my_strnncoll(charset_info,
 
2834
                                            (const uchar*)buffer->ptr(),4,
 
2835
                                            (const uchar*)"SET ",4)))
2672
2836
  {
2673
 
    (void) put_info(_("Ignoring query to other database"),INFO_INFO,0,0);
 
2837
    (void) put_info("Ignoring query to other database",INFO_INFO);
2674
2838
    return 0;
2675
2839
  }
2676
2840
 
2677
2841
  timer=start_timer();
2678
2842
  executing_query= 1;
2679
 
  error= drizzle_real_query_for_lazy(buffer->c_str(),buffer->length());
 
2843
  error= mysql_real_query_for_lazy(buffer->ptr(),buffer->length());
2680
2844
 
2681
 
  if (status.add_to_history)
2682
 
  {
 
2845
#ifdef HAVE_READLINE
 
2846
  if (status.add_to_history) 
 
2847
  {  
2683
2848
    buffer->append(vertical ? "\\G" : delimiter);
2684
2849
    /* Append final command onto history */
2685
2850
    fix_history(buffer);
2686
2851
  }
 
2852
#endif
2687
2853
 
2688
 
  buffer->clear();
 
2854
  buffer->length(0);
2689
2855
 
2690
2856
  if (error)
2691
2857
    goto end;
2696
2862
 
2697
2863
    if (quick)
2698
2864
    {
2699
 
      if (!(result=drizzle_use_result(&drizzle)) && drizzle_field_count(&drizzle))
 
2865
      if (!(result=mysql_use_result(&mysql)) && mysql_field_count(&mysql))
2700
2866
      {
2701
 
        error= put_error(&drizzle);
 
2867
        error= put_error(&mysql);
2702
2868
        goto end;
2703
2869
      }
2704
2870
    }
2705
2871
    else
2706
2872
    {
2707
 
      error= drizzle_store_result_for_lazy(&result);
 
2873
      error= mysql_store_result_for_lazy(&result);
2708
2874
      if (error)
2709
2875
        goto end;
2710
2876
    }
2711
2877
 
2712
2878
    if (verbose >= 3 || !opt_silent)
2713
 
      drizzle_end_timer(timer,time_buff);
 
2879
      mysql_end_timer(timer,time_buff);
2714
2880
    else
2715
2881
      time_buff[0]= '\0';
2716
2882
 
2717
2883
    /* Every branch must truncate  buff . */
2718
2884
    if (result)
2719
2885
    {
2720
 
      if (!drizzle_num_rows(result) && ! quick && !column_types_flag)
 
2886
      if (!mysql_num_rows(result) && ! quick && !column_types_flag)
2721
2887
      {
2722
 
        my_stpcpy(buff, _("Empty set"));
 
2888
        strmov(buff, "Empty set");
 
2889
        if (opt_xml)
 
2890
        { 
 
2891
          /*
 
2892
            We must print XML header and footer
 
2893
            to produce a well-formed XML even if
 
2894
            the result set is empty (Bug#27608).
 
2895
          */
 
2896
          init_pager();
 
2897
          print_table_data_xml(result);
 
2898
          end_pager();
 
2899
        }
2723
2900
      }
2724
2901
      else
2725
2902
      {
2726
 
        init_pager();
2727
 
        if (vertical || (auto_vertical_output &&
2728
 
                         (terminal_width < get_result_width(result))))
2729
 
          print_table_data_vertically(result);
2730
 
        else if (opt_silent && verbose <= 2 && !output_tables)
2731
 
          print_tab_data(result);
2732
 
        else
2733
 
          print_table_data(result);
2734
 
        sprintf(buff,
2735
 
                ngettext("%ld row in set","%ld rows in set",
2736
 
                         (long) drizzle_num_rows(result)),
2737
 
                (long) drizzle_num_rows(result));
2738
 
        end_pager();
2739
 
        if (drizzle_errno(&drizzle))
2740
 
          error= put_error(&drizzle);
 
2903
        init_pager();
 
2904
        if (opt_html)
 
2905
          print_table_data_html(result);
 
2906
        else if (opt_xml)
 
2907
          print_table_data_xml(result);
 
2908
  else if (vertical || (auto_vertical_output && (terminal_width < get_result_width(result))))
 
2909
          print_table_data_vertically(result);
 
2910
        else if (opt_silent && verbose <= 2 && !output_tables)
 
2911
          print_tab_data(result);
 
2912
        else
 
2913
          print_table_data(result);
 
2914
        sprintf(buff,"%ld %s in set",
 
2915
                (long) mysql_num_rows(result),
 
2916
                (long) mysql_num_rows(result) == 1 ? "row" : "rows");
 
2917
        end_pager();
 
2918
        if (mysql_errno(&mysql))
 
2919
          error= put_error(&mysql);
2741
2920
      }
2742
2921
    }
2743
 
    else if (drizzle_affected_rows(&drizzle) == ~(uint64_t) 0)
2744
 
      my_stpcpy(buff,_("Query OK"));
 
2922
    else if (mysql_affected_rows(&mysql) == ~(ulonglong) 0)
 
2923
      strmov(buff,"Query OK");
2745
2924
    else
2746
 
      sprintf(buff, ngettext("Query OK, %ld row affected",
2747
 
                             "Query OK, %ld rows affected",
2748
 
                             (long) drizzle_affected_rows(&drizzle)),
2749
 
              (long) drizzle_affected_rows(&drizzle));
 
2925
      sprintf(buff,"Query OK, %ld %s affected",
 
2926
              (long) mysql_affected_rows(&mysql),
 
2927
              (long) mysql_affected_rows(&mysql) == 1 ? "row" : "rows");
2750
2928
 
2751
 
    pos= strchr(buff, '\0');
2752
 
    if ((warnings= drizzle_warning_count(&drizzle)))
 
2929
    pos=strend(buff);
 
2930
    if ((warnings= mysql_warning_count(&mysql)))
2753
2931
    {
2754
2932
      *pos++= ',';
2755
2933
      *pos++= ' ';
2756
2934
      pos=int10_to_str(warnings, pos, 10);
2757
 
      pos=my_stpcpy(pos, " warning");
 
2935
      pos=strmov(pos, " warning");
2758
2936
      if (warnings != 1)
2759
 
        *pos++= 's';
 
2937
        *pos++= 's';
2760
2938
    }
2761
 
    my_stpcpy(pos, time_buff);
2762
 
    put_info(buff,INFO_RESULT,0,0);
2763
 
    if (drizzle_info(&drizzle))
2764
 
      put_info(drizzle_info(&drizzle),INFO_RESULT,0,0);
2765
 
    put_info("",INFO_RESULT,0,0);      // Empty row
 
2939
    strmov(pos, time_buff);
 
2940
    put_info(buff,INFO_RESULT);
 
2941
    if (mysql_info(&mysql))
 
2942
      put_info(mysql_info(&mysql),INFO_RESULT);
 
2943
    put_info("",INFO_RESULT);                   // Empty row
2766
2944
 
2767
 
    if (result && !drizzle_eof(result))  /* Something wrong when using quick */
2768
 
      error= put_error(&drizzle);
 
2945
    if (result && !mysql_eof(result))   /* Something wrong when using quick */
 
2946
      error= put_error(&mysql);
2769
2947
    else if (unbuffered)
2770
2948
      fflush(stdout);
2771
 
    drizzle_free_result(result);
2772
 
  } while (!(err= drizzle_next_result(&drizzle)));
 
2949
    mysql_free_result(result);
 
2950
  } while (!(err= mysql_next_result(&mysql)));
2773
2951
  if (err >= 1)
2774
 
    error= put_error(&drizzle);
 
2952
    error= put_error(&mysql);
2775
2953
 
2776
2954
end:
2777
2955
 
2778
 
  /* Show warnings if any or error occured */
 
2956
 /* Show warnings if any or error occured */
2779
2957
  if (show_warnings == 1 && (warnings >= 1 || error))
2780
2958
    print_warnings();
2781
2959
 
2782
 
  if (!error && !status.batch &&
2783
 
      (drizzle.server_status & SERVER_STATUS_DB_DROPPED))
 
2960
  if (!error && !status.batch && 
 
2961
      (mysql.server_status & SERVER_STATUS_DB_DROPPED))
2784
2962
    get_current_db();
2785
2963
 
2786
2964
  executing_query= 0;
2787
 
  return error;        /* New command follows */
 
2965
  return error;                         /* New command follows */
2788
2966
}
2789
2967
 
2790
2968
 
2791
2969
static void init_pager()
2792
2970
{
 
2971
#ifdef USE_POPEN
2793
2972
  if (!opt_nopager)
2794
2973
  {
2795
2974
    if (!(PAGER= popen(pager, "w")))
2799
2978
    }
2800
2979
  }
2801
2980
  else
 
2981
#endif
2802
2982
    PAGER= stdout;
2803
2983
}
2804
2984
 
2805
2985
static void end_pager()
2806
2986
{
 
2987
#ifdef USE_POPEN
2807
2988
  if (!opt_nopager)
2808
2989
    pclose(PAGER);
 
2990
#endif
2809
2991
}
2810
2992
 
2811
2993
 
2837
3019
 
2838
3020
 
2839
3021
static int
2840
 
com_ego(string *buffer,const char *line)
 
3022
com_ego(String *buffer,char *line)
2841
3023
{
2842
3024
  int result;
2843
3025
  bool oldvertical=vertical;
2851
3033
static const char *fieldtype2str(enum enum_field_types type)
2852
3034
{
2853
3035
  switch (type) {
2854
 
    case DRIZZLE_TYPE_BLOB:        return "BLOB";
2855
 
    case DRIZZLE_TYPE_NEWDATE:        return "DATE";
2856
 
    case DRIZZLE_TYPE_DATETIME:    return "DATETIME";
2857
 
    case DRIZZLE_TYPE_NEWDECIMAL:  return "DECIMAL";
2858
 
    case DRIZZLE_TYPE_DOUBLE:      return "DOUBLE";
2859
 
    case DRIZZLE_TYPE_ENUM:        return "ENUM";
2860
 
    case DRIZZLE_TYPE_LONG:        return "LONG";
2861
 
    case DRIZZLE_TYPE_LONGLONG:    return "LONGLONG";
2862
 
    case DRIZZLE_TYPE_NULL:        return "NULL";
2863
 
    case DRIZZLE_TYPE_TIME:        return "TIME";
2864
 
    case DRIZZLE_TYPE_TIMESTAMP:   return "TIMESTAMP";
2865
 
    case DRIZZLE_TYPE_TINY:        return "TINY";
2866
 
    case DRIZZLE_TYPE_VIRTUAL:     return "VIRTUAL";
 
3036
    case MYSQL_TYPE_BIT:         return "BIT";
 
3037
    case MYSQL_TYPE_BLOB:        return "BLOB";
 
3038
    case MYSQL_TYPE_DATE:        return "DATE";
 
3039
    case MYSQL_TYPE_DATETIME:    return "DATETIME";
 
3040
    case MYSQL_TYPE_NEWDECIMAL:  return "NEWDECIMAL";
 
3041
    case MYSQL_TYPE_DECIMAL:     return "DECIMAL";
 
3042
    case MYSQL_TYPE_DOUBLE:      return "DOUBLE";
 
3043
    case MYSQL_TYPE_ENUM:        return "ENUM";
 
3044
    case MYSQL_TYPE_FLOAT:       return "FLOAT";
 
3045
    case MYSQL_TYPE_GEOMETRY:    return "GEOMETRY";
 
3046
    case MYSQL_TYPE_INT24:       return "INT24";
 
3047
    case MYSQL_TYPE_LONG:        return "LONG";
 
3048
    case MYSQL_TYPE_LONGLONG:    return "LONGLONG";
 
3049
    case MYSQL_TYPE_LONG_BLOB:   return "LONG_BLOB";
 
3050
    case MYSQL_TYPE_MEDIUM_BLOB: return "MEDIUM_BLOB";
 
3051
    case MYSQL_TYPE_NEWDATE:     return "NEWDATE";
 
3052
    case MYSQL_TYPE_NULL:        return "NULL";
 
3053
    case MYSQL_TYPE_SET:         return "SET";
 
3054
    case MYSQL_TYPE_SHORT:       return "SHORT";
 
3055
    case MYSQL_TYPE_STRING:      return "STRING";
 
3056
    case MYSQL_TYPE_TIME:        return "TIME";
 
3057
    case MYSQL_TYPE_TIMESTAMP:   return "TIMESTAMP";
 
3058
    case MYSQL_TYPE_TINY:        return "TINY";
 
3059
    case MYSQL_TYPE_TINY_BLOB:   return "TINY_BLOB";
 
3060
    case MYSQL_TYPE_VAR_STRING:  return "VAR_STRING";
 
3061
    case MYSQL_TYPE_YEAR:        return "YEAR";
2867
3062
    default:                     return "?-unknown-?";
2868
3063
  }
2869
3064
}
2872
3067
  static char buf[1024];
2873
3068
  char *s=buf;
2874
3069
  *s=0;
2875
 
#define ff2s_check_flag(X)                                              \
2876
 
  if (f & X ## _FLAG) { s=my_stpcpy(s, # X " "); f &= ~ X ## _FLAG; }
 
3070
#define ff2s_check_flag(X) \
 
3071
                if (f & X ## _FLAG) { s=strmov(s, # X " "); f &= ~ X ## _FLAG; }
2877
3072
  ff2s_check_flag(NOT_NULL);
2878
3073
  ff2s_check_flag(PRI_KEY);
2879
3074
  ff2s_check_flag(UNIQUE_KEY);
2880
3075
  ff2s_check_flag(MULTIPLE_KEY);
2881
3076
  ff2s_check_flag(BLOB);
2882
3077
  ff2s_check_flag(UNSIGNED);
 
3078
  ff2s_check_flag(ZEROFILL);
2883
3079
  ff2s_check_flag(BINARY);
2884
3080
  ff2s_check_flag(ENUM);
2885
3081
  ff2s_check_flag(AUTO_INCREMENT);
2899
3095
}
2900
3096
 
2901
3097
static void
2902
 
print_field_types(DRIZZLE_RES *result)
 
3098
print_field_types(MYSQL_RES *result)
2903
3099
{
2904
 
  DRIZZLE_FIELD   *field;
 
3100
  MYSQL_FIELD   *field;
2905
3101
  uint i=0;
2906
3102
 
2907
 
  while ((field = drizzle_fetch_field(result)))
 
3103
  while ((field = mysql_fetch_field(result)))
2908
3104
  {
2909
3105
    tee_fprintf(PAGER, "Field %3u:  `%s`\n"
2910
 
                "Catalog:    `%s`\n"
2911
 
                "Database:   `%s`\n"
2912
 
                "Table:      `%s`\n"
2913
 
                "Org_table:  `%s`\n"
2914
 
                "Type:       %s\n"
2915
 
                "Collation:  %s (%u)\n"
2916
 
                "Length:     %lu\n"
2917
 
                "Max_length: %lu\n"
2918
 
                "Decimals:   %u\n"
2919
 
                "Flags:      %s\n\n",
 
3106
                       "Catalog:    `%s`\n"
 
3107
                       "Database:   `%s`\n"
 
3108
                       "Table:      `%s`\n"
 
3109
                       "Org_table:  `%s`\n"
 
3110
                       "Type:       %s\n"
 
3111
                       "Collation:  %s (%u)\n"
 
3112
                       "Length:     %lu\n"
 
3113
                       "Max_length: %lu\n"
 
3114
                       "Decimals:   %u\n"
 
3115
                       "Flags:      %s\n\n",
2920
3116
                ++i,
2921
3117
                field->name, field->catalog, field->db, field->table,
2922
3118
                field->org_table, fieldtype2str(field->type),
2929
3125
 
2930
3126
 
2931
3127
static void
2932
 
print_table_data(DRIZZLE_RES *result)
 
3128
print_table_data(MYSQL_RES *result)
2933
3129
{
2934
 
  DRIZZLE_ROW     cur;
2935
 
  DRIZZLE_FIELD   *field;
2936
 
  bool          *num_flag;
2937
 
  string separator;
2938
 
  
2939
 
  separator.reserve(256);
 
3130
  String separator(256);
 
3131
  MYSQL_ROW     cur;
 
3132
  MYSQL_FIELD   *field;
 
3133
  bool          *num_flag;
2940
3134
 
2941
 
  num_flag=(bool*) my_malloc(sizeof(bool)*drizzle_num_fields(result),
2942
 
                             MYF(MY_WME));
 
3135
  num_flag=(bool*) my_alloca(sizeof(bool)*mysql_num_fields(result));
2943
3136
  if (column_types_flag)
2944
3137
  {
2945
3138
    print_field_types(result);
2946
 
    if (!drizzle_num_rows(result))
 
3139
    if (!mysql_num_rows(result))
2947
3140
      return;
2948
 
    drizzle_field_seek(result,0);
 
3141
    mysql_field_seek(result,0);
2949
3142
  }
2950
 
  separator.append("+");
2951
 
  while ((field = drizzle_fetch_field(result)))
 
3143
  separator.copy("+",1,charset_info);
 
3144
  while ((field = mysql_fetch_field(result)))
2952
3145
  {
2953
 
    uint32_t length= column_names ? field->name_length : 0;
 
3146
    uint length= column_names ? field->name_length : 0;
2954
3147
    if (quick)
2955
3148
      length=max(length,field->length);
2956
3149
    else
2957
3150
      length=max(length,field->max_length);
2958
 
    if (length < 4 && !(field->flags & NOT_NULL_FLAG))
2959
 
      // Room for "NULL"
2960
 
      length=4;
 
3151
    if (length < 4 && !IS_NOT_NULL(field->flags))
 
3152
      length=4;                                 // Room for "NULL"
2961
3153
    field->max_length=length;
2962
 
    uint x;
2963
 
    for (x=0; x< (length+2); x++)
2964
 
      separator.append("-");
2965
 
    separator.append("+");
 
3154
    separator.fill(separator.length()+length+2,'-');
 
3155
    separator.append('+');
2966
3156
  }
2967
 
 
2968
 
  tee_puts((char*) separator.c_str(), PAGER);
 
3157
  separator.append('\0');                       // End marker for \0
 
3158
  tee_puts((char*) separator.ptr(), PAGER);
2969
3159
  if (column_names)
2970
3160
  {
2971
 
    drizzle_field_seek(result,0);
 
3161
    mysql_field_seek(result,0);
2972
3162
    (void) tee_fputs("|", PAGER);
2973
 
    for (uint off=0; (field = drizzle_fetch_field(result)) ; off++)
 
3163
    for (uint off=0; (field = mysql_fetch_field(result)) ; off++)
2974
3164
    {
2975
3165
      uint name_length= (uint) strlen(field->name);
2976
3166
      uint numcells= charset_info->cset->numcells(charset_info,
2977
3167
                                                  field->name,
2978
3168
                                                  field->name + name_length);
2979
 
      uint32_t display_length= field->max_length + name_length - numcells;
 
3169
      uint display_length= field->max_length + name_length - numcells;
2980
3170
      tee_fprintf(PAGER, " %-*s |",(int) min(display_length,
2981
 
                                             MAX_COLUMN_LENGTH),
 
3171
                                            MAX_COLUMN_LENGTH),
2982
3172
                  field->name);
2983
 
      num_flag[off]= ((field->type <= DRIZZLE_TYPE_LONGLONG) || 
2984
 
                      (field->type == DRIZZLE_TYPE_NEWDECIMAL));
 
3173
      num_flag[off]= IS_NUM(field->type);
2985
3174
    }
2986
3175
    (void) tee_fputs("\n", PAGER);
2987
 
    tee_puts((char*) separator.c_str(), PAGER);
 
3176
    tee_puts((char*) separator.ptr(), PAGER);
2988
3177
  }
2989
3178
 
2990
 
  while ((cur= drizzle_fetch_row(result)))
 
3179
  while ((cur= mysql_fetch_row(result)))
2991
3180
  {
2992
3181
    if (interrupted_query)
2993
3182
      break;
2994
 
    uint32_t *lengths= drizzle_fetch_lengths(result);
 
3183
    ulong *lengths= mysql_fetch_lengths(result);
2995
3184
    (void) tee_fputs("| ", PAGER);
2996
 
    drizzle_field_seek(result, 0);
2997
 
    for (uint off= 0; off < drizzle_num_fields(result); off++)
 
3185
    mysql_field_seek(result, 0);
 
3186
    for (uint off= 0; off < mysql_num_fields(result); off++)
2998
3187
    {
2999
3188
      const char *buffer;
3000
3189
      uint data_length;
3006
3195
      {
3007
3196
        buffer= "NULL";
3008
3197
        data_length= 4;
3009
 
      }
3010
 
      else
 
3198
      } 
 
3199
      else 
3011
3200
      {
3012
3201
        buffer= cur[off];
3013
3202
        data_length= (uint) lengths[off];
3014
3203
      }
3015
3204
 
3016
 
      field= drizzle_fetch_field(result);
 
3205
      field= mysql_fetch_field(result);
3017
3206
      field_max_length= field->max_length;
3018
3207
 
3019
 
      /*
3020
 
        How many text cells on the screen will this string span?  If it contains
3021
 
        multibyte characters, then the number of characters we occupy on screen
3022
 
        will be fewer than the number of bytes we occupy in memory.
 
3208
      /* 
 
3209
       How many text cells on the screen will this string span?  If it contains
 
3210
       multibyte characters, then the number of characters we occupy on screen
 
3211
       will be fewer than the number of bytes we occupy in memory.
3023
3212
 
3024
 
        We need to find how much screen real-estate we will occupy to know how
3025
 
        many extra padding-characters we should send with the printing function.
 
3213
       We need to find how much screen real-estate we will occupy to know how 
 
3214
       many extra padding-characters we should send with the printing function.
3026
3215
      */
3027
3216
      visible_length= charset_info->cset->numcells(charset_info, buffer, buffer + data_length);
3028
3217
      extra_padding= data_length - visible_length;
3033
3222
      {
3034
3223
        if (num_flag[off] != 0) /* if it is numeric, we right-justify it */
3035
3224
          tee_print_sized_data(buffer, data_length, field_max_length+extra_padding, TRUE);
3036
 
        else
3037
 
          tee_print_sized_data(buffer, data_length,
3038
 
                               field_max_length+extra_padding, FALSE);
 
3225
        else 
 
3226
          tee_print_sized_data(buffer, data_length, field_max_length+extra_padding, FALSE);
3039
3227
      }
3040
3228
      tee_fputs(" | ", PAGER);
3041
3229
    }
3042
3230
    (void) tee_fputs("\n", PAGER);
3043
3231
  }
3044
 
  tee_puts(separator.c_str(), PAGER);
3045
 
  free(num_flag);
 
3232
  tee_puts((char*) separator.ptr(), PAGER);
 
3233
  my_afree((uchar*) num_flag);
3046
3234
}
3047
3235
 
3048
3236
/**
3049
 
   Return the length of a field after it would be rendered into text.
3050
 
 
3051
 
   This doesn't know or care about multibyte characters.  Assume we're
3052
 
   using such a charset.  We can't know that all of the upcoming rows
3053
 
   for this column will have bytes that each render into some fraction
3054
 
   of a character.  It's at least possible that a row has bytes that
3055
 
   all render into one character each, and so the maximum length is
3056
 
   still the number of bytes.  (Assumption 1:  This can't be better
3057
 
   because we can never know the number of characters that the DB is
3058
 
   going to send -- only the number of bytes.  2: Chars <= Bytes.)
3059
 
 
3060
 
   @param  field  Pointer to a field to be inspected
3061
 
 
3062
 
   @returns  number of character positions to be used, at most
 
3237
  Return the length of a field after it would be rendered into text.
 
3238
 
 
3239
  This doesn't know or care about multibyte characters.  Assume we're
 
3240
  using such a charset.  We can't know that all of the upcoming rows 
 
3241
  for this column will have bytes that each render into some fraction
 
3242
  of a character.  It's at least possible that a row has bytes that 
 
3243
  all render into one character each, and so the maximum length is 
 
3244
  still the number of bytes.  (Assumption 1:  This can't be better 
 
3245
  because we can never know the number of characters that the DB is 
 
3246
  going to send -- only the number of bytes.  2: Chars <= Bytes.)
 
3247
 
 
3248
  @param  field  Pointer to a field to be inspected
 
3249
 
 
3250
  @returns  number of character positions to be used, at most
3063
3251
*/
3064
 
static int get_field_disp_length(DRIZZLE_FIELD *field)
 
3252
static int get_field_disp_length(MYSQL_FIELD *field)
3065
3253
{
3066
3254
  uint length= column_names ? field->name_length : 0;
3067
3255
 
3070
3258
  else
3071
3259
    length= max(length, field->max_length);
3072
3260
 
3073
 
  if (length < 4 && !(field->flags & NOT_NULL_FLAG))
3074
 
    length= 4;        /* Room for "NULL" */
 
3261
  if (length < 4 && !IS_NOT_NULL(field->flags))
 
3262
    length= 4;                          /* Room for "NULL" */
3075
3263
 
3076
3264
  return length;
3077
3265
}
3078
3266
 
3079
3267
/**
3080
 
   For a new result, return the max number of characters that any
3081
 
   upcoming row may return.
3082
 
 
3083
 
   @param  result  Pointer to the result to judge
3084
 
 
3085
 
   @returns  The max number of characters in any row of this result
 
3268
  For a new result, return the max number of characters that any
 
3269
  upcoming row may return.
 
3270
 
 
3271
  @param  result  Pointer to the result to judge
 
3272
 
 
3273
  @returns  The max number of characters in any row of this result
3086
3274
*/
3087
 
static int get_result_width(DRIZZLE_RES *result)
 
3275
static int get_result_width(MYSQL_RES *result)
3088
3276
{
3089
3277
  unsigned int len= 0;
3090
 
  DRIZZLE_FIELD *field;
3091
 
  DRIZZLE_FIELD_OFFSET offset;
3092
 
 
3093
 
  offset= drizzle_field_tell(result);
3094
 
  assert(offset == 0);
3095
 
 
3096
 
  while ((field= drizzle_fetch_field(result)) != NULL)
 
3278
  MYSQL_FIELD *field;
 
3279
  MYSQL_FIELD_OFFSET offset;
 
3280
  
 
3281
#ifndef DBUG_OFF
 
3282
  offset= mysql_field_tell(result);
 
3283
  DBUG_ASSERT(offset == 0);
 
3284
#else
 
3285
  offset= 0;
 
3286
#endif
 
3287
 
 
3288
  while ((field= mysql_fetch_field(result)) != NULL)
3097
3289
    len+= get_field_disp_length(field) + 3; /* plus bar, space, & final space */
3098
3290
 
3099
 
  (void) drizzle_field_seek(result, offset);
 
3291
  (void) mysql_field_seek(result, offset);      
3100
3292
 
3101
3293
  return len + 1; /* plus final bar. */
3102
3294
}
3104
3296
static void
3105
3297
tee_print_sized_data(const char *data, unsigned int data_length, unsigned int total_bytes_to_send, bool right_justified)
3106
3298
{
3107
 
  /*
 
3299
  /* 
3108
3300
    For '\0's print ASCII spaces instead, as '\0' is eaten by (at
3109
3301
    least my) console driver, and that messes up the pretty table
3110
 
    grid.  (The \0 is also the reason we can't use fprintf() .)
 
3302
    grid.  (The \0 is also the reason we can't use fprintf() .) 
3111
3303
  */
3112
3304
  unsigned int i;
3113
3305
  const char *p;
3114
3306
 
3115
 
  if (right_justified)
 
3307
  if (right_justified) 
3116
3308
    for (i= data_length; i < total_bytes_to_send; i++)
3117
3309
      tee_putc((int)' ', PAGER);
3118
3310
 
3124
3316
      tee_putc((int)*p, PAGER);
3125
3317
  }
3126
3318
 
3127
 
  if (! right_justified)
 
3319
  if (! right_justified) 
3128
3320
    for (i= data_length; i < total_bytes_to_send; i++)
3129
3321
      tee_putc((int)' ', PAGER);
3130
3322
}
3132
3324
 
3133
3325
 
3134
3326
static void
3135
 
print_table_data_vertically(DRIZZLE_RES *result)
3136
 
{
3137
 
  DRIZZLE_ROW  cur;
3138
 
  uint    max_length=0;
3139
 
  DRIZZLE_FIELD  *field;
3140
 
 
3141
 
  while ((field = drizzle_fetch_field(result)))
 
3327
print_table_data_html(MYSQL_RES *result)
 
3328
{
 
3329
  MYSQL_ROW     cur;
 
3330
  MYSQL_FIELD   *field;
 
3331
 
 
3332
  mysql_field_seek(result,0);
 
3333
  (void) tee_fputs("<TABLE BORDER=1><TR>", PAGER);
 
3334
  if (column_names)
 
3335
  {
 
3336
    while((field = mysql_fetch_field(result)))
 
3337
    {
 
3338
      tee_fprintf(PAGER, "<TH>%s</TH>", (field->name ? 
 
3339
                                         (field->name[0] ? field->name : 
 
3340
                                          " &nbsp; ") : "NULL"));
 
3341
    }
 
3342
    (void) tee_fputs("</TR>", PAGER);
 
3343
  }
 
3344
  while ((cur = mysql_fetch_row(result)))
 
3345
  {
 
3346
    if (interrupted_query)
 
3347
      break;
 
3348
    ulong *lengths=mysql_fetch_lengths(result);
 
3349
    (void) tee_fputs("<TR>", PAGER);
 
3350
    for (uint i=0; i < mysql_num_fields(result); i++)
 
3351
    {
 
3352
      (void) tee_fputs("<TD>", PAGER);
 
3353
      safe_put_field(cur[i],lengths[i]);
 
3354
      (void) tee_fputs("</TD>", PAGER);
 
3355
    }
 
3356
    (void) tee_fputs("</TR>", PAGER);
 
3357
  }
 
3358
  (void) tee_fputs("</TABLE>", PAGER);
 
3359
}
 
3360
 
 
3361
 
 
3362
static void
 
3363
print_table_data_xml(MYSQL_RES *result)
 
3364
{
 
3365
  MYSQL_ROW   cur;
 
3366
  MYSQL_FIELD *fields;
 
3367
 
 
3368
  mysql_field_seek(result,0);
 
3369
 
 
3370
  tee_fputs("<?xml version=\"1.0\"?>\n\n<resultset statement=\"", PAGER);
 
3371
  xmlencode_print(glob_buffer.ptr(), (int)strlen(glob_buffer.ptr()));
 
3372
  tee_fputs("\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">",
 
3373
            PAGER);
 
3374
 
 
3375
  fields = mysql_fetch_fields(result);
 
3376
  while ((cur = mysql_fetch_row(result)))
 
3377
  {
 
3378
    if (interrupted_query)
 
3379
      break;
 
3380
    ulong *lengths=mysql_fetch_lengths(result);
 
3381
    (void) tee_fputs("\n  <row>\n", PAGER);
 
3382
    for (uint i=0; i < mysql_num_fields(result); i++)
 
3383
    {
 
3384
      tee_fprintf(PAGER, "\t<field name=\"");
 
3385
      xmlencode_print(fields[i].name, (uint) strlen(fields[i].name));
 
3386
      if (cur[i])
 
3387
      {
 
3388
        tee_fprintf(PAGER, "\">");
 
3389
        xmlencode_print(cur[i], lengths[i]);
 
3390
        tee_fprintf(PAGER, "</field>\n");
 
3391
      }
 
3392
      else
 
3393
        tee_fprintf(PAGER, "\" xsi:nil=\"true\" />\n");
 
3394
    }
 
3395
    (void) tee_fputs("  </row>\n", PAGER);
 
3396
  }
 
3397
  (void) tee_fputs("</resultset>\n", PAGER);
 
3398
}
 
3399
 
 
3400
 
 
3401
static void
 
3402
print_table_data_vertically(MYSQL_RES *result)
 
3403
{
 
3404
  MYSQL_ROW     cur;
 
3405
  uint          max_length=0;
 
3406
  MYSQL_FIELD   *field;
 
3407
 
 
3408
  while ((field = mysql_fetch_field(result)))
3142
3409
  {
3143
3410
    uint length= field->name_length;
3144
3411
    if (length > max_length)
3146
3413
    field->max_length=length;
3147
3414
  }
3148
3415
 
3149
 
  drizzle_field_seek(result,0);
3150
 
  for (uint row_count=1; (cur= drizzle_fetch_row(result)); row_count++)
 
3416
  mysql_field_seek(result,0);
 
3417
  for (uint row_count=1; (cur= mysql_fetch_row(result)); row_count++)
3151
3418
  {
3152
3419
    if (interrupted_query)
3153
3420
      break;
3154
 
    drizzle_field_seek(result,0);
3155
 
    tee_fprintf(PAGER,
3156
 
                "*************************** %d. row ***************************\n", row_count);
3157
 
    for (uint off=0; off < drizzle_num_fields(result); off++)
 
3421
    mysql_field_seek(result,0);
 
3422
    tee_fprintf(PAGER, 
 
3423
                "*************************** %d. row ***************************\n", row_count);
 
3424
    for (uint off=0; off < mysql_num_fields(result); off++)
3158
3425
    {
3159
 
      field= drizzle_fetch_field(result);
 
3426
      field= mysql_fetch_field(result);
3160
3427
      tee_fprintf(PAGER, "%*s: ",(int) max_length,field->name);
3161
3428
      tee_fprintf(PAGER, "%s\n",cur[off] ? (char*) cur[off] : "NULL");
3162
3429
    }
3169
3436
static void print_warnings()
3170
3437
{
3171
3438
  const char   *query;
3172
 
  DRIZZLE_RES    *result;
3173
 
  DRIZZLE_ROW    cur;
3174
 
  uint64_t num_rows;
3175
 
 
 
3439
  MYSQL_RES    *result;
 
3440
  MYSQL_ROW    cur;
 
3441
  my_ulonglong num_rows;
 
3442
  
3176
3443
  /* Save current error before calling "show warnings" */
3177
 
  uint error= drizzle_errno(&drizzle);
 
3444
  uint error= mysql_errno(&mysql);
3178
3445
 
3179
3446
  /* Get the warnings */
3180
3447
  query= "show warnings";
3181
 
  drizzle_real_query_for_lazy(query, strlen(query));
3182
 
  drizzle_store_result_for_lazy(&result);
 
3448
  mysql_real_query_for_lazy(query, strlen(query));
 
3449
  mysql_store_result_for_lazy(&result);
3183
3450
 
3184
3451
  /* Bail out when no warnings */
3185
 
  if (!(num_rows= drizzle_num_rows(result)))
 
3452
  if (!(num_rows= mysql_num_rows(result)))
3186
3453
    goto end;
3187
3454
 
3188
 
  cur= drizzle_fetch_row(result);
 
3455
  cur= mysql_fetch_row(result);
3189
3456
 
3190
3457
  /*
3191
3458
    Don't print a duplicate of the current error.  It is possible for SHOW
3193
3460
    messages.  To be safe, skip printing the duplicate only if it is the only
3194
3461
    warning.
3195
3462
  */
3196
 
  if (!cur || (num_rows == 1 && error == (uint) strtoul(cur[1], NULL, 10)))
 
3463
  if (!cur || num_rows == 1 && error == (uint) strtoul(cur[1], NULL, 10))
3197
3464
    goto end;
3198
3465
 
3199
3466
  /* Print the warnings */
3201
3468
  do
3202
3469
  {
3203
3470
    tee_fprintf(PAGER, "%s (Code %s): %s\n", cur[0], cur[1], cur[2]);
3204
 
  } while ((cur= drizzle_fetch_row(result)));
 
3471
  } while ((cur= mysql_fetch_row(result)));
3205
3472
  end_pager();
3206
3473
 
3207
3474
end:
3208
 
  drizzle_free_result(result);
3209
 
}
3210
 
 
3211
 
 
3212
 
static void
3213
 
safe_put_field(const char *pos,uint32_t length)
 
3475
  mysql_free_result(result);
 
3476
}
 
3477
 
 
3478
 
 
3479
static const char *array_value(const char **array, char key)
 
3480
{
 
3481
  for (; *array; array+= 2)
 
3482
    if (**array == key)
 
3483
      return array[1];
 
3484
  return 0;
 
3485
}
 
3486
 
 
3487
 
 
3488
static void
 
3489
xmlencode_print(const char *src, uint length)
 
3490
{
 
3491
  if (!src)
 
3492
    tee_fputs("NULL", PAGER);
 
3493
  else
 
3494
  {
 
3495
    for (const char *p = src; *p && length; *p++, length--)
 
3496
    {
 
3497
      const char *t;
 
3498
      if ((t = array_value(xmlmeta, *p)))
 
3499
        tee_fputs(t, PAGER);
 
3500
      else
 
3501
        tee_putc(*p, PAGER);
 
3502
    }
 
3503
  }
 
3504
}
 
3505
 
 
3506
 
 
3507
static void
 
3508
safe_put_field(const char *pos,ulong length)
3214
3509
{
3215
3510
  if (!pos)
3216
3511
    tee_fputs("NULL", PAGER);
3219
3514
    if (opt_raw_data)
3220
3515
      tee_fputs(pos, PAGER);
3221
3516
    else for (const char *end=pos+length ; pos != end ; pos++)
3222
 
         {
 
3517
    {
3223
3518
#ifdef USE_MB
3224
 
           int l;
3225
 
           if (use_mb(charset_info) &&
3226
 
               (l = my_ismbchar(charset_info, pos, end)))
3227
 
           {
3228
 
             while (l--)
3229
 
               tee_putc(*pos++, PAGER);
3230
 
             pos--;
3231
 
             continue;
3232
 
           }
 
3519
      int l;
 
3520
      if (use_mb(charset_info) &&
 
3521
          (l = my_ismbchar(charset_info, pos, end)))
 
3522
      {
 
3523
          while (l--)
 
3524
            tee_putc(*pos++, PAGER);
 
3525
          pos--;
 
3526
          continue;
 
3527
      }
3233
3528
#endif
3234
 
           if (!*pos)
3235
 
             tee_fputs("\\0", PAGER); // This makes everything hard
3236
 
           else if (*pos == '\t')
3237
 
             tee_fputs("\\t", PAGER); // This would destroy tab format
3238
 
           else if (*pos == '\n')
3239
 
             tee_fputs("\\n", PAGER); // This too
3240
 
           else if (*pos == '\\')
3241
 
             tee_fputs("\\\\", PAGER);
3242
 
           else
3243
 
             tee_putc(*pos, PAGER);
3244
 
         }
 
3529
      if (!*pos)
 
3530
        tee_fputs("\\0", PAGER); // This makes everything hard
 
3531
      else if (*pos == '\t')
 
3532
        tee_fputs("\\t", PAGER); // This would destroy tab format
 
3533
      else if (*pos == '\n')
 
3534
        tee_fputs("\\n", PAGER); // This too
 
3535
      else if (*pos == '\\')
 
3536
        tee_fputs("\\\\", PAGER);
 
3537
        else
 
3538
        tee_putc(*pos, PAGER);
 
3539
    }
3245
3540
  }
3246
3541
}
3247
3542
 
3248
3543
 
3249
3544
static void
3250
 
print_tab_data(DRIZZLE_RES *result)
 
3545
print_tab_data(MYSQL_RES *result)
3251
3546
{
3252
 
  DRIZZLE_ROW  cur;
3253
 
  DRIZZLE_FIELD  *field;
3254
 
  uint32_t    *lengths;
 
3547
  MYSQL_ROW     cur;
 
3548
  MYSQL_FIELD   *field;
 
3549
  ulong         *lengths;
3255
3550
 
3256
3551
  if (opt_silent < 2 && column_names)
3257
3552
  {
3258
3553
    int first=0;
3259
 
    while ((field = drizzle_fetch_field(result)))
 
3554
    while ((field = mysql_fetch_field(result)))
3260
3555
    {
3261
3556
      if (first++)
3262
 
        (void) tee_fputs("\t", PAGER);
 
3557
        (void) tee_fputs("\t", PAGER);
3263
3558
      (void) tee_fputs(field->name, PAGER);
3264
3559
    }
3265
3560
    (void) tee_fputs("\n", PAGER);
3266
3561
  }
3267
 
  while ((cur = drizzle_fetch_row(result)))
 
3562
  while ((cur = mysql_fetch_row(result)))
3268
3563
  {
3269
 
    lengths= drizzle_fetch_lengths(result);
 
3564
    lengths=mysql_fetch_lengths(result);
3270
3565
    safe_put_field(cur[0],lengths[0]);
3271
 
    for (uint off=1 ; off < drizzle_num_fields(result); off++)
 
3566
    for (uint off=1 ; off < mysql_num_fields(result); off++)
3272
3567
    {
3273
3568
      (void) tee_fputs("\t", PAGER);
3274
3569
      safe_put_field(cur[off], lengths[off]);
3278
3573
}
3279
3574
 
3280
3575
static int
3281
 
com_tee(string *buffer __attribute__((unused)), const char *line )
 
3576
com_tee(String *buffer __attribute__((__unused__)), char *line )
3282
3577
{
3283
3578
  char file_name[FN_REFLEN], *end, *param;
3284
3579
 
3299
3594
      return 0;
3300
3595
    }
3301
3596
    else
3302
 
      param = outfile;      //resume using the old outfile
 
3597
      param = outfile;                  //resume using the old outfile
3303
3598
  }
3304
3599
 
3305
3600
  /* eliminate the spaces before the parameters */
3307
3602
    param++;
3308
3603
  end= strmake(file_name, param, sizeof(file_name) - 1);
3309
3604
  /* remove end space from command line */
3310
 
  while (end > file_name && (my_isspace(charset_info,end[-1]) ||
3311
 
                             my_iscntrl(charset_info,end[-1])))
 
3605
  while (end > file_name && (my_isspace(charset_info,end[-1]) || 
 
3606
                             my_iscntrl(charset_info,end[-1])))
3312
3607
    end--;
3313
3608
  end[0]= 0;
3314
3609
  if (end == file_name)
3322
3617
 
3323
3618
 
3324
3619
static int
3325
 
com_notee(string *buffer __attribute__((unused)),
3326
 
          const char *line __attribute__((unused)))
 
3620
com_notee(String *buffer __attribute__((unused)),
 
3621
          char *line __attribute__((unused)))
3327
3622
{
3328
3623
  if (opt_outfile)
3329
3624
    end_tee();
3335
3630
  Sorry, this command is not available in Windows.
3336
3631
*/
3337
3632
 
 
3633
#ifdef USE_POPEN
3338
3634
static int
3339
 
com_pager(string *buffer __attribute__((unused)),
3340
 
          const char *line __attribute__((unused)))
 
3635
com_pager(String *buffer, char *line __attribute__((unused)))
3341
3636
{
3342
3637
  char pager_name[FN_REFLEN], *end, *param;
3343
3638
 
3357
3652
    {
3358
3653
      tee_fprintf(stdout, "Default pager wasn't set, using stdout.\n");
3359
3654
      opt_nopager=1;
3360
 
      my_stpcpy(pager, "stdout");
 
3655
      strmov(pager, "stdout");
3361
3656
      PAGER= stdout;
3362
3657
      return 0;
3363
3658
    }
3364
 
    my_stpcpy(pager, default_pager);
 
3659
    strmov(pager, default_pager);
3365
3660
  }
3366
3661
  else
3367
3662
  {
3368
3663
    end= strmake(pager_name, param, sizeof(pager_name)-1);
3369
 
    while (end > pager_name && (my_isspace(charset_info,end[-1]) ||
 
3664
    while (end > pager_name && (my_isspace(charset_info,end[-1]) || 
3370
3665
                                my_iscntrl(charset_info,end[-1])))
3371
3666
      end--;
3372
3667
    end[0]=0;
3373
 
    my_stpcpy(pager, pager_name);
3374
 
    my_stpcpy(default_pager, pager_name);
 
3668
    strmov(pager, pager_name);
 
3669
    strmov(default_pager, pager_name);
3375
3670
  }
3376
3671
  opt_nopager=0;
3377
3672
  tee_fprintf(stdout, "PAGER set to '%s'\n", pager);
3380
3675
 
3381
3676
 
3382
3677
static int
3383
 
com_nopager(string *buffer __attribute__((unused)),
3384
 
            const char *line __attribute__((unused)))
 
3678
com_nopager(String *buffer __attribute__((unused)),
 
3679
            char *line __attribute__((unused)))
3385
3680
{
3386
 
  my_stpcpy(pager, "stdout");
 
3681
  strmov(pager, "stdout");
3387
3682
  opt_nopager=1;
3388
3683
  PAGER= stdout;
3389
3684
  tee_fprintf(stdout, "PAGER set to stdout\n");
3390
3685
  return 0;
3391
3686
}
 
3687
#endif
 
3688
 
 
3689
 
 
3690
/*
 
3691
  Sorry, you can't send the result to an editor in Win32
 
3692
*/
 
3693
 
 
3694
#ifdef USE_POPEN
 
3695
static int
 
3696
com_edit(String *buffer,char *line __attribute__((unused)))
 
3697
{
 
3698
  char  filename[FN_REFLEN],buff[160];
 
3699
  int   fd,tmp;
 
3700
  const char *editor;
 
3701
 
 
3702
  if ((fd=create_temp_file(filename,NullS,"sql", O_CREAT | O_WRONLY,
 
3703
                           MYF(MY_WME))) < 0)
 
3704
    goto err;
 
3705
  if (buffer->is_empty() && !old_buffer.is_empty())
 
3706
    (void) my_write(fd,(uchar*) old_buffer.ptr(),old_buffer.length(),
 
3707
                    MYF(MY_WME));
 
3708
  else
 
3709
    (void) my_write(fd,(uchar*) buffer->ptr(),buffer->length(),MYF(MY_WME));
 
3710
  (void) my_close(fd,MYF(0));
 
3711
 
 
3712
  if (!(editor = (char *)getenv("EDITOR")) &&
 
3713
      !(editor = (char *)getenv("VISUAL")))
 
3714
    editor = "vi";
 
3715
  strxmov(buff,editor," ",filename,NullS);
 
3716
  (void) system(buff);
 
3717
 
 
3718
  struct stat stat_arg;
 
3719
  if (stat(filename,&stat_arg))
 
3720
    goto err;
 
3721
  if ((fd = my_open(filename,O_RDONLY, MYF(MY_WME))) < 0)
 
3722
    goto err;
 
3723
  (void) buffer->alloc((uint) stat_arg.st_size);
 
3724
  if ((tmp=read(fd,(char*) buffer->ptr(),buffer->alloced_length())) >= 0L)
 
3725
    buffer->length((uint) tmp);
 
3726
  else
 
3727
    buffer->length(0);
 
3728
  (void) my_close(fd,MYF(0));
 
3729
  (void) my_delete(filename,MYF(MY_WME));
 
3730
err:
 
3731
  return 0;
 
3732
}
 
3733
#endif
 
3734
 
3392
3735
 
3393
3736
/* If arg is given, exit without errors. This happens on command 'quit' */
3394
3737
 
3395
3738
static int
3396
 
com_quit(string *buffer __attribute__((unused)),
3397
 
         const char *line __attribute__((unused)))
 
3739
com_quit(String *buffer __attribute__((unused)),
 
3740
         char *line __attribute__((unused)))
3398
3741
{
3399
3742
  /* let the screen auto close on a normal shutdown */
3400
3743
  status.exit_status=0;
3402
3745
}
3403
3746
 
3404
3747
static int
3405
 
com_rehash(string *buffer __attribute__((unused)),
3406
 
           const char *line __attribute__((unused)))
 
3748
com_rehash(String *buffer __attribute__((unused)),
 
3749
         char *line __attribute__((unused)))
3407
3750
{
 
3751
#ifdef HAVE_READLINE
3408
3752
  build_completion_hash(1, 0);
3409
 
  return 0;
3410
 
}
3411
 
 
3412
 
 
3413
 
 
3414
 
static int
3415
 
com_print(string *buffer,const char *line __attribute__((unused)))
 
3753
#endif
 
3754
  return 0;
 
3755
}
 
3756
 
 
3757
 
 
3758
#ifdef USE_POPEN
 
3759
static int
 
3760
com_shell(String *buffer, char *line __attribute__((unused)))
 
3761
{
 
3762
  char *shell_cmd;
 
3763
 
 
3764
  /* Skip space from line begin */
 
3765
  while (my_isspace(charset_info, *line))
 
3766
    line++;
 
3767
  if (!(shell_cmd = strchr(line, ' ')))
 
3768
  {
 
3769
    put_info("Usage: \\! shell-command", INFO_ERROR);
 
3770
    return -1;
 
3771
  }
 
3772
  /*
 
3773
    The output of the shell command does not
 
3774
    get directed to the pager or the outfile
 
3775
  */
 
3776
  if (system(shell_cmd) == -1)
 
3777
  {
 
3778
    put_info(strerror(errno), INFO_ERROR, errno);
 
3779
    return -1;
 
3780
  }
 
3781
  return 0;
 
3782
}
 
3783
#endif
 
3784
 
 
3785
 
 
3786
static int
 
3787
com_print(String *buffer,char *line __attribute__((unused)))
3416
3788
{
3417
3789
  tee_puts("--------------", stdout);
3418
 
  (void) tee_fputs(buffer->c_str(), stdout);
3419
 
  if ( (buffer->length() == 0)
3420
 
       || (buffer->c_str())[(buffer->length())-1] != '\n')
 
3790
  (void) tee_fputs(buffer->c_ptr(), stdout);
 
3791
  if (!buffer->length() || (*buffer)[buffer->length()-1] != '\n')
3421
3792
    tee_putc('\n', stdout);
3422
3793
  tee_puts("--------------\n", stdout);
3423
 
  /* If empty buffer */
3424
 
  return 0;
 
3794
  return 0;                                     /* If empty buffer */
3425
3795
}
3426
3796
 
3427
 
/* ARGSUSED */
 
3797
        /* ARGSUSED */
3428
3798
static int
3429
 
com_connect(string *buffer, const char *line)
 
3799
com_connect(String *buffer, char *line)
3430
3800
{
3431
3801
  char *tmp, buff[256];
3432
3802
  bool save_rehash= opt_rehash;
3433
3803
  int error;
3434
3804
 
3435
 
  memset(buff, 0, sizeof(buff));
 
3805
  bzero(buff, sizeof(buff));
3436
3806
  if (buffer)
3437
3807
  {
3438
3808
    /*
3446
3816
    tmp= get_arg(buff, 0);
3447
3817
    if (tmp && *tmp)
3448
3818
    {
3449
 
      free(current_db);
3450
 
      current_db= strdup(tmp);
 
3819
      my_free(current_db, MYF(MY_ALLOW_ZERO_PTR));
 
3820
      current_db= my_strdup(tmp, MYF(MY_WME));
3451
3821
      tmp= get_arg(buff, 1);
3452
3822
      if (tmp)
3453
3823
      {
3454
 
        free(current_host);
3455
 
        current_host=strdup(tmp);
 
3824
        my_free(current_host,MYF(MY_ALLOW_ZERO_PTR));
 
3825
        current_host=my_strdup(tmp,MYF(MY_WME));
3456
3826
      }
3457
3827
    }
3458
3828
    else
3460
3830
      /* Quick re-connect */
3461
3831
      opt_rehash= 0;                            /* purecov: tested */
3462
3832
    }
3463
 
    // command used
3464
 
    assert(buffer!=NULL);
3465
 
    buffer->clear();
 
3833
    buffer->length(0);                          // command used
3466
3834
  }
3467
3835
  else
3468
3836
    opt_rehash= 0;
3471
3839
 
3472
3840
  if (connected)
3473
3841
  {
3474
 
    sprintf(buff,"Connection id:    %u",drizzle_thread_id(&drizzle));
3475
 
    put_info(buff,INFO_INFO,0,0);
 
3842
    sprintf(buff,"Connection id:    %lu",mysql_thread_id(&mysql));
 
3843
    put_info(buff,INFO_INFO);
3476
3844
    sprintf(buff,"Current database: %.128s\n",
3477
 
            current_db ? current_db : "*** NONE ***");
3478
 
    put_info(buff,INFO_INFO,0,0);
 
3845
            current_db ? current_db : "*** NONE ***");
 
3846
    put_info(buff,INFO_INFO);
3479
3847
  }
3480
3848
  return error;
3481
3849
}
3482
3850
 
3483
3851
 
3484
 
static int com_source(string *buffer __attribute__((unused)), const char *line)
 
3852
static int com_source(String *buffer __attribute__((__unused__)), char *line)
3485
3853
{
3486
3854
  char source_name[FN_REFLEN], *end, *param;
3487
3855
  LINE_BUFFER *line_buff;
3492
3860
  /* Skip space from file name */
3493
3861
  while (my_isspace(charset_info,*line))
3494
3862
    line++;
3495
 
  if (!(param = strchr(line, ' ')))    // Skip command name
3496
 
    return put_info("Usage: \\. <filename> | source <filename>",
3497
 
                    INFO_ERROR, 0,0);
 
3863
  if (!(param = strchr(line, ' ')))             // Skip command name
 
3864
    return put_info("Usage: \\. <filename> | source <filename>", 
 
3865
                    INFO_ERROR, 0);
3498
3866
  while (my_isspace(charset_info,*param))
3499
3867
    param++;
3500
3868
  end=strmake(source_name,param,sizeof(source_name)-1);
3501
 
  while (end > source_name && (my_isspace(charset_info,end[-1]) ||
 
3869
  while (end > source_name && (my_isspace(charset_info,end[-1]) || 
3502
3870
                               my_iscntrl(charset_info,end[-1])))
3503
3871
    end--;
3504
3872
  end[0]=0;
3505
3873
  unpack_filename(source_name,source_name);
3506
3874
  /* open file name */
3507
 
  if (!(sql_file = my_fopen(source_name, O_RDONLY,MYF(0))))
 
3875
  if (!(sql_file = my_fopen(source_name, O_RDONLY | O_BINARY,MYF(0))))
3508
3876
  {
3509
3877
    char buff[FN_REFLEN+60];
3510
3878
    sprintf(buff,"Failed to open file '%s', error: %d", source_name,errno);
3511
 
    return put_info(buff, INFO_ERROR, 0 ,0);
 
3879
    return put_info(buff, INFO_ERROR, 0);
3512
3880
  }
3513
3881
 
3514
3882
  if (!(line_buff=batch_readline_init(opt_max_allowed_packet+512,sql_file)))
3515
3883
  {
3516
3884
    my_fclose(sql_file,MYF(0));
3517
 
    return put_info("Can't initialize batch_readline", INFO_ERROR, 0 ,0);
 
3885
    return put_info("Can't initialize batch_readline", INFO_ERROR, 0);
3518
3886
  }
3519
3887
 
3520
3888
  /* Save old status */
3521
3889
  old_status=status;
3522
 
  memset(&status, 0, sizeof(status));
 
3890
  bfill((char*) &status,sizeof(status),(char) 0);
3523
3891
 
3524
 
  // Run in batch mode
3525
 
  status.batch=old_status.batch;
 
3892
  status.batch=old_status.batch;                // Run in batch mode
3526
3893
  status.line_buff=line_buff;
3527
3894
  status.file_name=source_name;
3528
 
  // Empty command buffer
3529
 
  assert(glob_buffer!=NULL);
3530
 
  glob_buffer->clear();
 
3895
  glob_buffer.length(0);                        // Empty command buffer
3531
3896
  error= read_and_execute(false);
3532
 
  // Continue as before
3533
 
  status=old_status;
 
3897
  status=old_status;                            // Continue as before
3534
3898
  my_fclose(sql_file,MYF(0));
3535
3899
  batch_readline_end(line_buff);
3536
3900
  return error;
3537
3901
}
3538
3902
 
3539
3903
 
3540
 
/* ARGSUSED */
 
3904
        /* ARGSUSED */
3541
3905
static int
3542
 
com_delimiter(string *buffer __attribute__((unused)), const char *line)
 
3906
com_delimiter(String *buffer __attribute__((unused)), char *line)
3543
3907
{
3544
3908
  char buff[256], *tmp;
3545
3909
 
3549
3913
  if (!tmp || !*tmp)
3550
3914
  {
3551
3915
    put_info("DELIMITER must be followed by a 'delimiter' character or string",
3552
 
             INFO_ERROR, 0, 0);
 
3916
             INFO_ERROR);
3553
3917
    return 0;
3554
3918
  }
3555
3919
  else
3556
3920
  {
3557
 
    if (strstr(tmp, "\\"))
 
3921
    if (strstr(tmp, "\\")) 
3558
3922
    {
3559
 
      put_info("DELIMITER cannot contain a backslash character",
3560
 
               INFO_ERROR, 0, 0);
 
3923
      put_info("DELIMITER cannot contain a backslash character", INFO_ERROR);
3561
3924
      return 0;
3562
3925
    }
3563
3926
  }
3567
3930
  return 0;
3568
3931
}
3569
3932
 
3570
 
/* ARGSUSED */
 
3933
        /* ARGSUSED */
3571
3934
static int
3572
 
com_use(string *buffer __attribute__((unused)), const char *line)
 
3935
com_use(String *buffer __attribute__((unused)), char *line)
3573
3936
{
3574
3937
  char *tmp, buff[FN_REFLEN + 1];
3575
3938
  int select_db;
3576
3939
 
3577
 
  memset(buff, 0, sizeof(buff));
 
3940
  bzero(buff, sizeof(buff));
3578
3941
  strmake(buff, line, sizeof(buff) - 1);
3579
3942
  tmp= get_arg(buff, 0);
3580
3943
  if (!tmp || !*tmp)
3581
3944
  {
3582
 
    put_info("USE must be followed by a database name", INFO_ERROR, 0, 0);
 
3945
    put_info("USE must be followed by a database name", INFO_ERROR);
3583
3946
    return 0;
3584
3947
  }
3585
3948
  /*
3594
3957
    if (one_database)
3595
3958
    {
3596
3959
      skip_updates= 1;
3597
 
      select_db= 0;    // don't do drizzle_select_db()
 
3960
      select_db= 0;    // don't do mysql_select_db()
3598
3961
    }
3599
3962
    else
3600
 
      select_db= 2;    // do drizzle_select_db() and build_completion_hash()
 
3963
      select_db= 2;    // do mysql_select_db() and build_completion_hash()
3601
3964
  }
3602
3965
  else
3603
3966
  {
3604
3967
    /*
3605
3968
      USE to the current db specified.
3606
 
      We do need to send drizzle_select_db() to make server
 
3969
      We do need to send mysql_select_db() to make server
3607
3970
      update database level privileges, which might
3608
3971
      change since last USE (see bug#10979).
3609
3972
      For performance purposes, we'll skip rebuilding of completion hash.
3610
3973
    */
3611
3974
    skip_updates= 0;
3612
 
    select_db= 1;      // do only drizzle_select_db(), without completion
 
3975
    select_db= 1;      // do only mysql_select_db(), without completion
3613
3976
  }
3614
3977
 
3615
3978
  if (select_db)
3620
3983
    */
3621
3984
    if (!connected && reconnect())
3622
3985
      return opt_reconnect ? -1 : 1;                        // Fatal error
3623
 
    if (drizzle_select_db(&drizzle,tmp))
 
3986
    if (mysql_select_db(&mysql,tmp))
3624
3987
    {
3625
 
      if (drizzle_errno(&drizzle) != CR_SERVER_GONE_ERROR)
3626
 
        return put_error(&drizzle);
 
3988
      if (mysql_errno(&mysql) != CR_SERVER_GONE_ERROR)
 
3989
        return put_error(&mysql);
3627
3990
 
3628
3991
      if (reconnect())
3629
3992
        return opt_reconnect ? -1 : 1;                      // Fatal error
3630
 
      if (drizzle_select_db(&drizzle,tmp))
3631
 
        return put_error(&drizzle);
 
3993
      if (mysql_select_db(&mysql,tmp))
 
3994
        return put_error(&mysql);
3632
3995
    }
3633
 
    free(current_db);
3634
 
    current_db= strdup(tmp);
 
3996
    my_free(current_db,MYF(MY_ALLOW_ZERO_PTR));
 
3997
    current_db=my_strdup(tmp,MYF(MY_WME));
 
3998
#ifdef HAVE_READLINE
3635
3999
    if (select_db > 1)
3636
4000
      build_completion_hash(opt_rehash, 1);
 
4001
#endif
3637
4002
  }
3638
4003
 
3639
 
  put_info("Database changed",INFO_INFO, 0, 0);
 
4004
  put_info("Database changed",INFO_INFO);
3640
4005
  return 0;
3641
4006
}
3642
4007
 
3643
4008
static int
3644
 
com_warnings(string *buffer __attribute__((unused)),
3645
 
             const char *line __attribute__((unused)))
 
4009
com_warnings(String *buffer __attribute__((unused)),
 
4010
   char *line __attribute__((unused)))
3646
4011
{
3647
4012
  show_warnings = 1;
3648
 
  put_info("Show warnings enabled.",INFO_INFO, 0, 0);
 
4013
  put_info("Show warnings enabled.",INFO_INFO);
3649
4014
  return 0;
3650
4015
}
3651
4016
 
3652
4017
static int
3653
 
com_nowarnings(string *buffer __attribute__((unused)),
3654
 
               const char *line __attribute__((unused)))
 
4018
com_nowarnings(String *buffer __attribute__((unused)),
 
4019
   char *line __attribute__((unused)))
3655
4020
{
3656
4021
  show_warnings = 0;
3657
 
  put_info("Show warnings disabled.",INFO_INFO, 0, 0);
 
4022
  put_info("Show warnings disabled.",INFO_INFO);
3658
4023
  return 0;
3659
4024
}
3660
4025
 
3668
4033
  items in the array to zero first.
3669
4034
*/
3670
4035
 
3671
 
char *get_arg(char *line, bool get_next_arg)
 
4036
char *get_arg(char *line, my_bool get_next_arg)
3672
4037
{
3673
4038
  char *ptr, *start;
3674
 
  bool quoted= 0, valid_arg= 0;
 
4039
  my_bool quoted= 0, valid_arg= 0;
3675
4040
  char qtype= 0;
3676
4041
 
3677
4042
  ptr= line;
3693
4058
        ptr++;
3694
4059
  }
3695
4060
  if (!*ptr)
3696
 
    return NULL;
 
4061
    return NullS;
3697
4062
  while (my_isspace(charset_info, *ptr))
3698
4063
    ptr++;
3699
4064
  if (*ptr == '\'' || *ptr == '\"' || *ptr == '`')
3707
4072
    if (*ptr == '\\' && ptr[1]) // escaped character
3708
4073
    {
3709
4074
      // Remove the backslash
3710
 
      my_stpcpy(ptr, ptr+1);
 
4075
      strmov(ptr, ptr+1);
3711
4076
    }
3712
4077
    else if ((!quoted && *ptr == ' ') || (quoted && *ptr == qtype))
3713
4078
    {
3716
4081
    }
3717
4082
  }
3718
4083
  valid_arg= ptr != start;
3719
 
  return valid_arg ? start : NULL;
 
4084
  return valid_arg ? start : NullS;
3720
4085
}
3721
4086
 
3722
4087
 
3723
4088
static int
3724
 
sql_connect(char *host,char *database,char *user,char *password,
3725
 
                 uint silent)
 
4089
sql_real_connect(char *host,char *database,char *user,char *password,
 
4090
                 uint silent)
3726
4091
{
3727
4092
  if (connected)
3728
4093
  {
3729
4094
    connected= 0;
3730
 
    drizzle_close(&drizzle);
 
4095
    mysql_close(&mysql);
3731
4096
  }
3732
 
  drizzle_create(&drizzle);
 
4097
  mysql_init(&mysql);
3733
4098
  if (opt_connect_timeout)
3734
4099
  {
3735
4100
    uint timeout=opt_connect_timeout;
3736
 
    drizzle_options(&drizzle,DRIZZLE_OPT_CONNECT_TIMEOUT,
3737
 
                  (char*) &timeout);
 
4101
    mysql_options(&mysql,MYSQL_OPT_CONNECT_TIMEOUT,
 
4102
                  (char*) &timeout);
3738
4103
  }
3739
4104
  if (opt_compress)
3740
 
    drizzle_options(&drizzle,DRIZZLE_OPT_COMPRESS,NULL);
 
4105
    mysql_options(&mysql,MYSQL_OPT_COMPRESS,NullS);
3741
4106
  if (opt_secure_auth)
3742
 
    drizzle_options(&drizzle, DRIZZLE_SECURE_AUTH, (char *) &opt_secure_auth);
 
4107
    mysql_options(&mysql, MYSQL_SECURE_AUTH, (char *) &opt_secure_auth);
3743
4108
  if (using_opt_local_infile)
3744
 
    drizzle_options(&drizzle,DRIZZLE_OPT_LOCAL_INFILE, (char*) &opt_local_infile);
 
4109
    mysql_options(&mysql,MYSQL_OPT_LOCAL_INFILE, (char*) &opt_local_infile);
 
4110
  if (opt_protocol)
 
4111
    mysql_options(&mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
 
4112
#ifdef HAVE_SMEM
 
4113
  if (shared_memory_base_name)
 
4114
    mysql_options(&mysql,MYSQL_SHARED_MEMORY_BASE_NAME,shared_memory_base_name);
 
4115
#endif
3745
4116
  if (safe_updates)
3746
4117
  {
3747
4118
    char init_command[100];
3748
4119
    sprintf(init_command,
3749
 
            "SET SQL_SAFE_UPDATES=1,SQL_SELECT_LIMIT=%"PRIu32
3750
 
            ",SQL_MAX_JOIN_SIZE=%"PRIu32,
3751
 
            select_limit, max_join_size);
3752
 
    drizzle_options(&drizzle, DRIZZLE_INIT_COMMAND, init_command);
 
4120
            "SET SQL_SAFE_UPDATES=1,SQL_SELECT_LIMIT=%lu,SQL_MAX_JOIN_SIZE=%lu",
 
4121
            select_limit,max_join_size);
 
4122
    mysql_options(&mysql, MYSQL_INIT_COMMAND, init_command);
3753
4123
  }
3754
 
  if (!drizzle_connect(&drizzle, host, user, password,
3755
 
                          database, opt_drizzle_port, opt_drizzle_unix_port,
3756
 
                          connect_flag | CLIENT_MULTI_STATEMENTS))
 
4124
  if (default_charset_used)
 
4125
    mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, default_charset);
 
4126
  if (!mysql_real_connect(&mysql, host, user, password,
 
4127
                          database, opt_mysql_port, opt_mysql_unix_port,
 
4128
                          connect_flag | CLIENT_MULTI_STATEMENTS))
3757
4129
  {
3758
4130
    if (!silent ||
3759
 
        (drizzle_errno(&drizzle) != CR_CONN_HOST_ERROR &&
3760
 
         drizzle_errno(&drizzle) != CR_CONNECTION_ERROR))
 
4131
        (mysql_errno(&mysql) != CR_CONN_HOST_ERROR &&
 
4132
         mysql_errno(&mysql) != CR_CONNECTION_ERROR))
3761
4133
    {
3762
 
      (void) put_error(&drizzle);
 
4134
      (void) put_error(&mysql);
3763
4135
      (void) fflush(stdout);
3764
 
      return ignore_errors ? -1 : 1;    // Abort
 
4136
      return ignore_errors ? -1 : 1;            // Abort
3765
4137
    }
3766
 
    return -1;          // Retryable
 
4138
    return -1;                                  // Retryable
3767
4139
  }
3768
4140
  connected=1;
3769
 
  drizzle.reconnect= debug_info_flag; // We want to know if this happens
 
4141
#ifndef EMBEDDED_LIBRARY
 
4142
  mysql.reconnect= debug_info_flag; // We want to know if this happens
 
4143
#else
 
4144
  mysql.reconnect= 1;
 
4145
#endif
 
4146
#ifdef HAVE_READLINE
3770
4147
  build_completion_hash(opt_rehash, 1);
 
4148
#endif
3771
4149
  return 0;
3772
4150
}
3773
4151
 
3774
4152
 
3775
4153
static int
3776
 
com_status(string *buffer __attribute__((unused)),
3777
 
           const char *line __attribute__((unused)))
3778
 
{
 
4154
sql_connect(char *host,char *database,char *user,char *password,uint silent)
 
4155
{
 
4156
  bool message=0;
 
4157
  uint count=0;
 
4158
  int error;
 
4159
  for (;;)
 
4160
  {
 
4161
    if ((error=sql_real_connect(host,database,user,password,wait_flag)) >= 0)
 
4162
    {
 
4163
      if (count)
 
4164
      {
 
4165
        tee_fputs("\n", stderr);
 
4166
        (void) fflush(stderr);
 
4167
      }
 
4168
      return error;
 
4169
    }
 
4170
    if (!wait_flag)
 
4171
      return ignore_errors ? -1 : 1;
 
4172
    if (!message && !silent)
 
4173
    {
 
4174
      message=1;
 
4175
      tee_fputs("Waiting",stderr); (void) fflush(stderr);
 
4176
    }
 
4177
    (void) sleep(wait_time);
 
4178
    if (!silent)
 
4179
    {
 
4180
      putc('.',stderr); (void) fflush(stderr);
 
4181
      count++;
 
4182
    }
 
4183
  }
 
4184
}
 
4185
 
 
4186
 
 
4187
 
 
4188
static int
 
4189
com_status(String *buffer __attribute__((unused)),
 
4190
           char *line __attribute__((unused)))
 
4191
{
 
4192
  const char *status_str;
3779
4193
  char buff[40];
3780
 
  uint64_t id;
3781
 
  DRIZZLE_RES *result;
 
4194
  ulonglong id;
 
4195
  MYSQL_RES *result;
3782
4196
 
3783
4197
  tee_puts("--------------", stdout);
3784
 
  usage(1);          /* Print version */
 
4198
  usage(1);                                     /* Print version */
3785
4199
  if (connected)
3786
4200
  {
3787
 
    tee_fprintf(stdout, "\nConnection id:\t\t%lu\n",drizzle_thread_id(&drizzle));
3788
 
    /*
3789
 
      Don't remove "limit 1",
 
4201
    tee_fprintf(stdout, "\nConnection id:\t\t%lu\n",mysql_thread_id(&mysql));
 
4202
    /* 
 
4203
      Don't remove "limit 1", 
3790
4204
      it is protection againts SQL_SELECT_LIMIT=0
3791
4205
    */
3792
 
    if (!drizzle_query(&drizzle,"select DATABASE(), USER() limit 1") &&
3793
 
        (result=drizzle_use_result(&drizzle)))
 
4206
    if (!mysql_query(&mysql,"select DATABASE(), USER() limit 1") &&
 
4207
        (result=mysql_use_result(&mysql)))
3794
4208
    {
3795
 
      DRIZZLE_ROW cur=drizzle_fetch_row(result);
 
4209
      MYSQL_ROW cur=mysql_fetch_row(result);
3796
4210
      if (cur)
3797
4211
      {
3798
4212
        tee_fprintf(stdout, "Current database:\t%s\n", cur[0] ? cur[0] : "");
3799
4213
        tee_fprintf(stdout, "Current user:\t\t%s\n", cur[1]);
3800
4214
      }
3801
 
      drizzle_free_result(result);
3802
 
    }
3803
 
    tee_puts("SSL:\t\t\tNot in use", stdout);
 
4215
      mysql_free_result(result);
 
4216
    } 
 
4217
      tee_puts("SSL:\t\t\tNot in use", stdout);
3804
4218
  }
3805
4219
  else
3806
4220
  {
3815
4229
    tee_fprintf(stdout, "\nAll updates ignored to this database\n");
3816
4230
    vidattr(A_NORMAL);
3817
4231
  }
 
4232
#ifdef USE_POPEN
3818
4233
  tee_fprintf(stdout, "Current pager:\t\t%s\n", pager);
3819
4234
  tee_fprintf(stdout, "Using outfile:\t\t'%s'\n", opt_outfile ? outfile : "");
 
4235
#endif
3820
4236
  tee_fprintf(stdout, "Using delimiter:\t%s\n", delimiter);
3821
 
  tee_fprintf(stdout, "Server version:\t\t%s\n", server_version_string(&drizzle));
3822
 
  tee_fprintf(stdout, "Protocol version:\t%d\n", drizzle_get_proto_info(&drizzle));
3823
 
  tee_fprintf(stdout, "Connection:\t\t%s\n", drizzle_get_host_info(&drizzle));
3824
 
  if ((id= drizzle_insert_id(&drizzle)))
 
4237
  tee_fprintf(stdout, "Server version:\t\t%s\n", server_version_string(&mysql));
 
4238
  tee_fprintf(stdout, "Protocol version:\t%d\n", mysql_get_proto_info(&mysql));
 
4239
  tee_fprintf(stdout, "Connection:\t\t%s\n", mysql_get_host_info(&mysql));
 
4240
  if ((id= mysql_insert_id(&mysql)))
3825
4241
    tee_fprintf(stdout, "Insert id:\t\t%s\n", llstr(id, buff));
3826
4242
 
3827
4243
  /* "limit 1" is protection against SQL_SELECT_LIMIT=0 */
3828
 
  if (!drizzle_query(&drizzle,"select @@character_set_client, @@character_set_connection, @@character_set_server, @@character_set_database limit 1") &&
3829
 
      (result=drizzle_use_result(&drizzle)))
 
4244
  if (!mysql_query(&mysql,"select @@character_set_client, @@character_set_connection, @@character_set_server, @@character_set_database limit 1") &&
 
4245
      (result=mysql_use_result(&mysql)))
3830
4246
  {
3831
 
    DRIZZLE_ROW cur=drizzle_fetch_row(result);
 
4247
    MYSQL_ROW cur=mysql_fetch_row(result);
3832
4248
    if (cur)
3833
4249
    {
3834
4250
      tee_fprintf(stdout, "Server characterset:\t%s\n", cur[2] ? cur[2] : "");
3836
4252
      tee_fprintf(stdout, "Client characterset:\t%s\n", cur[0] ? cur[0] : "");
3837
4253
      tee_fprintf(stdout, "Conn.  characterset:\t%s\n", cur[1] ? cur[1] : "");
3838
4254
    }
3839
 
    drizzle_free_result(result);
 
4255
    mysql_free_result(result);
 
4256
  }
 
4257
  else
 
4258
  {
 
4259
    /* Probably pre-4.1 server */
 
4260
    tee_fprintf(stdout, "Client characterset:\t%s\n", charset_info->csname);
 
4261
    tee_fprintf(stdout, "Server characterset:\t%s\n", mysql.charset->csname);
3840
4262
  }
3841
4263
 
3842
 
  if (strstr(drizzle_get_host_info(&drizzle),"TCP/IP") || ! drizzle.unix_socket)
3843
 
    tee_fprintf(stdout, "TCP port:\t\t%d\n", drizzle.port);
 
4264
#ifndef EMBEDDED_LIBRARY
 
4265
  if (strstr(mysql_get_host_info(&mysql),"TCP/IP") || ! mysql.unix_socket)
 
4266
    tee_fprintf(stdout, "TCP port:\t\t%d\n", mysql.port);
3844
4267
  else
3845
 
    tee_fprintf(stdout, "UNIX socket:\t\t%s\n", drizzle.unix_socket);
3846
 
  if (drizzle.net.compress)
 
4268
    tee_fprintf(stdout, "UNIX socket:\t\t%s\n", mysql.unix_socket);
 
4269
  if (mysql.net.compress)
3847
4270
    tee_fprintf(stdout, "Protocol:\t\tCompressed\n");
 
4271
#endif
3848
4272
 
 
4273
  if ((status_str= mysql_stat(&mysql)) && !mysql_error(&mysql)[0])
 
4274
  {
 
4275
    ulong sec;
 
4276
    const char *pos= strchr(status_str,' ');
 
4277
    /* print label */
 
4278
    tee_fprintf(stdout, "%.*s\t\t\t", (int) (pos-status_str), status_str);
 
4279
    if ((status_str= str2int(pos,10,0,LONG_MAX,(long*) &sec)))
 
4280
    {
 
4281
      nice_time((double) sec,buff,0);
 
4282
      tee_puts(buff, stdout);                   /* print nice time */
 
4283
      while (*status_str == ' ')
 
4284
        status_str++;  /* to next info */
 
4285
      tee_putc('\n', stdout);
 
4286
      tee_puts(status_str, stdout);
 
4287
    }
 
4288
  }
3849
4289
  if (safe_updates)
3850
4290
  {
3851
4291
    vidattr(A_BOLD);
3853
4293
    vidattr(A_NORMAL);
3854
4294
    tee_fprintf(stdout, "\
3855
4295
UPDATEs and DELETEs that don't use a key in the WHERE clause are not allowed.\n\
3856
 
(One can force an UPDATE/DELETE by adding LIMIT # at the end of the command.)\n \
3857
 
SELECT has an automatic 'LIMIT %lu' if LIMIT is not used.\n             \
 
4296
(One can force an UPDATE/DELETE by adding LIMIT # at the end of the command.)\n\
 
4297
SELECT has an automatic 'LIMIT %lu' if LIMIT is not used.\n\
3858
4298
Max number of examined row combination in a join is set to: %lu\n\n",
3859
 
                select_limit, max_join_size);
 
4299
select_limit, max_join_size);
3860
4300
  }
3861
4301
  tee_puts("--------------\n", stdout);
3862
4302
  return 0;
3863
4303
}
3864
4304
 
3865
4305
static const char *
3866
 
server_version_string(DRIZZLE *con)
 
4306
server_version_string(MYSQL *con)
3867
4307
{
3868
4308
  static char buf[MAX_SERVER_VERSION_LENGTH] = "";
3869
4309
 
3871
4311
  if (buf[0] == '\0')
3872
4312
  {
3873
4313
    char *bufp = buf;
3874
 
    DRIZZLE_RES *result;
 
4314
    MYSQL_RES *result;
3875
4315
 
3876
 
    bufp= my_stpncpy(buf, drizzle_get_server_info(con), sizeof buf);
 
4316
    bufp= strnmov(buf, mysql_get_server_info(con), sizeof buf);
3877
4317
 
3878
4318
    /* "limit 1" is protection against SQL_SELECT_LIMIT=0 */
3879
 
    if (!drizzle_query(con, "select @@version_comment limit 1") &&
3880
 
        (result = drizzle_use_result(con)))
 
4319
    if (!mysql_query(con, "select @@version_comment limit 1") &&
 
4320
        (result = mysql_use_result(con)))
3881
4321
    {
3882
 
      DRIZZLE_ROW cur = drizzle_fetch_row(result);
 
4322
      MYSQL_ROW cur = mysql_fetch_row(result);
3883
4323
      if (cur && cur[0])
3884
4324
      {
3885
 
        bufp = strxnmov(bufp, sizeof buf - (bufp - buf), " ", cur[0], NULL);
 
4325
        bufp = strxnmov(bufp, sizeof buf - (bufp - buf), " ", cur[0], NullS);
3886
4326
      }
3887
 
      drizzle_free_result(result);
 
4327
      mysql_free_result(result);
3888
4328
    }
3889
4329
 
3890
4330
    /* str*nmov doesn't guarantee NUL-termination */
3909
4349
      fprintf(file,"ERROR");
3910
4350
      if (error)
3911
4351
      {
3912
 
        if (sqlstate)
3913
 
          (void) fprintf(file," %d (%s)",error, sqlstate);
 
4352
        if (sqlstate)
 
4353
          (void) fprintf(file," %d (%s)",error, sqlstate);
3914
4354
        else
3915
 
          (void) fprintf(file," %d",error);
 
4355
          (void) fprintf(file," %d",error);
3916
4356
      }
3917
4357
      if (status.query_start_line && line_numbers)
3918
4358
      {
3919
 
        (void) fprintf(file," at line %"PRIu32,status.query_start_line);
3920
 
        if (status.file_name)
3921
 
          (void) fprintf(file," in file: '%s'", status.file_name);
 
4359
        (void) fprintf(file," at line %lu",status.query_start_line);
 
4360
        if (status.file_name)
 
4361
          (void) fprintf(file," in file: '%s'", status.file_name);
3922
4362
      }
3923
4363
      (void) fprintf(file,": %s\n",str);
3924
4364
      (void) fflush(file);
3925
4365
      if (!ignore_errors)
3926
 
        return 1;
 
4366
        return 1;
3927
4367
    }
3928
4368
    else if (info_type == INFO_RESULT && verbose > 1)
3929
4369
      tee_puts(str, file);
3943
4383
    if (info_type == INFO_ERROR)
3944
4384
    {
3945
4385
      if (!opt_nobeep)
3946
 
        /* This should make a bell */
3947
 
        putchar('\a');
 
4386
        putchar('\a');                  /* This should make a bell */
3948
4387
      vidattr(A_STANDOUT);
3949
4388
      if (error)
3950
4389
      {
3951
 
        if (sqlstate)
 
4390
        if (sqlstate)
3952
4391
          (void) tee_fprintf(file, "ERROR %d (%s): ", error, sqlstate);
3953
4392
        else
3954
4393
          (void) tee_fprintf(file, "ERROR %d: ", error);
3968
4407
 
3969
4408
 
3970
4409
static int
3971
 
put_error(DRIZZLE *con)
3972
 
{
3973
 
  return put_info(drizzle_error(con), INFO_ERROR, drizzle_errno(con),
3974
 
                  drizzle_sqlstate(con));
3975
 
}
3976
 
 
3977
 
 
3978
 
static void remove_cntrl(string *buffer)
3979
 
{
3980
 
  const char *start=  buffer->c_str();
3981
 
  const char *end= start + (buffer->length());
 
4410
put_error(MYSQL *con)
 
4411
{
 
4412
  return put_info(mysql_error(con), INFO_ERROR, mysql_errno(con),
 
4413
                  mysql_sqlstate(con));
 
4414
}  
 
4415
 
 
4416
 
 
4417
static void remove_cntrl(String &buffer)
 
4418
{
 
4419
  char *start,*end;
 
4420
  end=(start=(char*) buffer.ptr())+buffer.length();
3982
4421
  while (start < end && !my_isgraph(charset_info,end[-1]))
3983
4422
    end--;
3984
 
  uint pos_to_truncate= (end-start);
3985
 
  if (buffer->length() > pos_to_truncate)
3986
 
    buffer->erase(pos_to_truncate);
 
4423
  buffer.length((uint) (end-start));
3987
4424
}
3988
4425
 
3989
4426
 
4031
4468
}
4032
4469
 
4033
4470
#include <sys/times.h>
4034
 
#ifdef _SC_CLK_TCK        // For mit-pthreads
 
4471
#ifdef _SC_CLK_TCK                              // For mit-pthreads
4035
4472
#undef CLOCKS_PER_SEC
4036
4473
#define CLOCKS_PER_SEC (sysconf(_SC_CLK_TCK))
4037
4474
#endif
4038
4475
 
4039
 
static uint32_t start_timer(void)
 
4476
static ulong start_timer(void)
4040
4477
{
4041
4478
  struct tms tms_tmp;
4042
4479
  return times(&tms_tmp);
4043
4480
}
4044
4481
 
4045
4482
 
4046
 
/**
4047
 
   Write as many as 52+1 bytes to buff, in the form of a legible
4048
 
   duration of time.
 
4483
/** 
 
4484
  Write as many as 52+1 bytes to buff, in the form of a legible duration of time.
4049
4485
 
4050
 
   len("4294967296 days, 23 hours, 59 minutes, 60.00 seconds")  ->  52
 
4486
  len("4294967296 days, 23 hours, 59 minutes, 60.00 seconds")  ->  52
4051
4487
*/
4052
4488
static void nice_time(double sec,char *buff,bool part_second)
4053
4489
{
4054
 
  uint32_t tmp;
 
4490
  ulong tmp;
4055
4491
  if (sec >= 3600.0*24)
4056
4492
  {
4057
 
    tmp=(uint32_t) floor(sec/(3600.0*24));
 
4493
    tmp=(ulong) floor(sec/(3600.0*24));
4058
4494
    sec-=3600.0*24*tmp;
4059
4495
    buff=int10_to_str((long) tmp, buff, 10);
4060
 
    buff=my_stpcpy(buff,tmp > 1 ? " days " : " day ");
 
4496
    buff=strmov(buff,tmp > 1 ? " days " : " day ");
4061
4497
  }
4062
4498
  if (sec >= 3600.0)
4063
4499
  {
4064
 
    tmp=(uint32_t) floor(sec/3600.0);
 
4500
    tmp=(ulong) floor(sec/3600.0);
4065
4501
    sec-=3600.0*tmp;
4066
4502
    buff=int10_to_str((long) tmp, buff, 10);
4067
 
    buff=my_stpcpy(buff,tmp > 1 ? " hours " : " hour ");
 
4503
    buff=strmov(buff,tmp > 1 ? " hours " : " hour ");
4068
4504
  }
4069
4505
  if (sec >= 60.0)
4070
4506
  {
4071
 
    tmp=(uint32_t) floor(sec/60.0);
 
4507
    tmp=(ulong) floor(sec/60.0);
4072
4508
    sec-=60.0*tmp;
4073
4509
    buff=int10_to_str((long) tmp, buff, 10);
4074
 
    buff=my_stpcpy(buff," min ");
 
4510
    buff=strmov(buff," min ");
4075
4511
  }
4076
4512
  if (part_second)
4077
4513
    sprintf(buff,"%.2f sec",sec);
4080
4516
}
4081
4517
 
4082
4518
 
4083
 
static void end_timer(uint32_t start_time,char *buff)
 
4519
static void end_timer(ulong start_time,char *buff)
4084
4520
{
4085
4521
  nice_time((double) (start_timer() - start_time) /
4086
 
            CLOCKS_PER_SEC,buff,1);
 
4522
            CLOCKS_PER_SEC,buff,1);
4087
4523
}
4088
4524
 
4089
4525
 
4090
 
static void drizzle_end_timer(uint32_t start_time,char *buff)
 
4526
static void mysql_end_timer(ulong start_time,char *buff)
4091
4527
{
4092
4528
  buff[0]=' ';
4093
4529
  buff[1]='(';
4094
4530
  end_timer(start_time,buff+2);
4095
 
  my_stpcpy(strchr(buff, '\0'),")");
 
4531
  strmov(strend(buff),")");
4096
4532
}
4097
4533
 
4098
 
static const char * construct_prompt()
 
4534
static const char* construct_prompt()
4099
4535
{
4100
 
  // Erase the old prompt
4101
 
  assert(processed_prompt!=NULL);
4102
 
  processed_prompt->clear();
4103
 
 
4104
 
  // Get the date struct
4105
 
  time_t  lclock = time(NULL);
 
4536
  processed_prompt.free();                      // Erase the old prompt
 
4537
  time_t  lclock = time(NULL);                  // Get the date struct
4106
4538
  struct tm *t = localtime(&lclock);
4107
4539
 
4108
4540
  /* parse thru the settings for the prompt */
4109
 
  for (char *c= current_prompt; *c; (void)*c++)
 
4541
  for (char *c = current_prompt; *c ; *c++)
4110
4542
  {
4111
4543
    if (*c != PROMPT_CHAR)
4112
 
    {
4113
 
      processed_prompt->append(c, 1);
4114
 
    }
 
4544
        processed_prompt.append(*c);
4115
4545
    else
4116
4546
    {
4117
 
      int getHour;
4118
 
      int getYear;
4119
 
      char* dateTime= NULL;
4120
4547
      switch (*++c) {
4121
4548
      case '\0':
4122
 
        // stop it from going beyond if ends with %
4123
 
        c--;
4124
 
        break;
 
4549
        c--;                    // stop it from going beyond if ends with %
 
4550
        break;
4125
4551
      case 'c':
4126
 
        add_int_to_prompt(++prompt_counter);
4127
 
        break;
 
4552
        add_int_to_prompt(++prompt_counter);
 
4553
        break;
4128
4554
      case 'v':
4129
 
        if (connected)
4130
 
          processed_prompt->append(drizzle_get_server_info(&drizzle));
4131
 
        else
4132
 
          processed_prompt->append("not_connected");
4133
 
        break;
 
4555
        if (connected)
 
4556
          processed_prompt.append(mysql_get_server_info(&mysql));
 
4557
        else
 
4558
          processed_prompt.append("not_connected");
 
4559
        break;
4134
4560
      case 'd':
4135
 
        processed_prompt->append(current_db ? current_db : "(none)");
4136
 
        break;
 
4561
        processed_prompt.append(current_db ? current_db : "(none)");
 
4562
        break;
4137
4563
      case 'h':
4138
4564
      {
4139
 
        const char *prompt;
4140
 
        prompt= connected ? drizzle_get_host_info(&drizzle) : "not_connected";
4141
 
        if (strstr(prompt, "Localhost"))
4142
 
          processed_prompt->append("localhost");
4143
 
        else
4144
 
        {
4145
 
          const char *end=strrchr(prompt,' ');
4146
 
          if (end != NULL)
4147
 
            processed_prompt->append(prompt, (end-prompt));
4148
 
        }
4149
 
        break;
 
4565
        const char *prompt;
 
4566
        prompt= connected ? mysql_get_host_info(&mysql) : "not_connected";
 
4567
        if (strstr(prompt, "Localhost"))
 
4568
          processed_prompt.append("localhost");
 
4569
        else
 
4570
        {
 
4571
          const char *end=strcend(prompt,' ');
 
4572
          processed_prompt.append(prompt, (uint) (end-prompt));
 
4573
        }
 
4574
        break;
4150
4575
      }
4151
4576
      case 'p':
4152
4577
      {
4153
 
        if (!connected)
4154
 
        {
4155
 
          processed_prompt->append("not_connected");
4156
 
          break;
4157
 
        }
 
4578
#ifndef EMBEDDED_LIBRARY
 
4579
        if (!connected)
 
4580
        {
 
4581
          processed_prompt.append("not_connected");
 
4582
          break;
 
4583
        }
4158
4584
 
4159
 
        const char *host_info = drizzle_get_host_info(&drizzle);
4160
 
        if (strstr(host_info, "memory"))
4161
 
        {
4162
 
          processed_prompt->append(drizzle.host);
4163
 
        }
4164
 
        else if (strstr(host_info,"TCP/IP") ||
4165
 
                 !drizzle.unix_socket)
4166
 
          add_int_to_prompt(drizzle.port);
4167
 
        else
4168
 
        {
4169
 
          char *pos=strrchr(drizzle.unix_socket,'/');
4170
 
          processed_prompt->append(pos ? pos+1 : drizzle.unix_socket);
4171
 
        }
 
4585
        const char *host_info = mysql_get_host_info(&mysql);
 
4586
        if (strstr(host_info, "memory")) 
 
4587
        {
 
4588
                processed_prompt.append( mysql.host );
 
4589
        }
 
4590
        else if (strstr(host_info,"TCP/IP") ||
 
4591
            !mysql.unix_socket)
 
4592
          add_int_to_prompt(mysql.port);
 
4593
        else
 
4594
        {
 
4595
          char *pos=strrchr(mysql.unix_socket,'/');
 
4596
          processed_prompt.append(pos ? pos+1 : mysql.unix_socket);
 
4597
        }
 
4598
#endif
4172
4599
      }
4173
 
      break;
 
4600
        break;
4174
4601
      case 'U':
4175
 
        if (!full_username)
4176
 
          init_username();
4177
 
        processed_prompt->append(full_username ? full_username :
4178
 
                                 (current_user ?  current_user : "(unknown)"));
4179
 
        break;
 
4602
        if (!full_username)
 
4603
          init_username();
 
4604
        processed_prompt.append(full_username ? full_username :
 
4605
                                (current_user ?  current_user : "(unknown)"));
 
4606
        break;
4180
4607
      case 'u':
4181
 
        if (!full_username)
4182
 
          init_username();
4183
 
        processed_prompt->append(part_username ? part_username :
4184
 
                                 (current_user ?  current_user : "(unknown)"));
4185
 
        break;
 
4608
        if (!full_username)
 
4609
          init_username();
 
4610
        processed_prompt.append(part_username ? part_username :
 
4611
                                (current_user ?  current_user : "(unknown)"));
 
4612
        break;
4186
4613
      case PROMPT_CHAR:
4187
 
        {
4188
 
          char c= PROMPT_CHAR;
4189
 
          processed_prompt->append(&c, 1);
4190
 
        }
4191
 
        break;
 
4614
        processed_prompt.append(PROMPT_CHAR);
 
4615
        break;
4192
4616
      case 'n':
4193
 
        {
4194
 
          char c= '\n';
4195
 
          processed_prompt->append(&c, 1);
4196
 
        }
4197
 
        break;
 
4617
        processed_prompt.append('\n');
 
4618
        break;
4198
4619
      case ' ':
4199
4620
      case '_':
4200
 
        {
4201
 
          char c= ' ';
4202
 
          processed_prompt->append(&c, 1);
4203
 
        }
4204
 
        break;
 
4621
        processed_prompt.append(' ');
 
4622
        break;
4205
4623
      case 'R':
4206
 
        if (t->tm_hour < 10)
4207
 
          add_int_to_prompt(0);
4208
 
        add_int_to_prompt(t->tm_hour);
4209
 
        break;
 
4624
        if (t->tm_hour < 10)
 
4625
          processed_prompt.append('0');
 
4626
        add_int_to_prompt(t->tm_hour);
 
4627
        break;
4210
4628
      case 'r':
4211
 
        getHour = t->tm_hour % 12;
4212
 
        if (getHour == 0)
4213
 
          getHour=12;
4214
 
        if (getHour < 10)
4215
 
          add_int_to_prompt(0);
4216
 
        add_int_to_prompt(getHour);
4217
 
        break;
 
4629
        int getHour;
 
4630
        getHour = t->tm_hour % 12;
 
4631
        if (getHour == 0)
 
4632
          getHour=12;
 
4633
        if (getHour < 10)
 
4634
          processed_prompt.append('0');
 
4635
        add_int_to_prompt(getHour);
 
4636
        break;
4218
4637
      case 'm':
4219
 
        if (t->tm_min < 10)
4220
 
          add_int_to_prompt(0);
4221
 
        add_int_to_prompt(t->tm_min);
4222
 
        break;
 
4638
        if (t->tm_min < 10)
 
4639
          processed_prompt.append('0');
 
4640
        add_int_to_prompt(t->tm_min);
 
4641
        break;
4223
4642
      case 'y':
4224
 
        getYear = t->tm_year % 100;
4225
 
        if (getYear < 10)
4226
 
          add_int_to_prompt(0);
4227
 
        add_int_to_prompt(getYear);
4228
 
        break;
 
4643
        int getYear;
 
4644
        getYear = t->tm_year % 100;
 
4645
        if (getYear < 10)
 
4646
          processed_prompt.append('0');
 
4647
        add_int_to_prompt(getYear);
 
4648
        break;
4229
4649
      case 'Y':
4230
 
        add_int_to_prompt(t->tm_year+1900);
4231
 
        break;
 
4650
        add_int_to_prompt(t->tm_year+1900);
 
4651
        break;
4232
4652
      case 'D':
4233
 
        dateTime = ctime(&lclock);
4234
 
        processed_prompt->append(strtok(dateTime,"\n"));
4235
 
        break;
 
4653
        char* dateTime;
 
4654
        dateTime = ctime(&lclock);
 
4655
        processed_prompt.append(strtok(dateTime,"\n"));
 
4656
        break;
4236
4657
      case 's':
4237
 
        if (t->tm_sec < 10)
4238
 
          add_int_to_prompt(0);
4239
 
        add_int_to_prompt(t->tm_sec);
4240
 
        break;
 
4658
        if (t->tm_sec < 10)
 
4659
          processed_prompt.append('0');
 
4660
        add_int_to_prompt(t->tm_sec);
 
4661
        break;
4241
4662
      case 'w':
4242
 
        processed_prompt->append(day_names[t->tm_wday]);
4243
 
        break;
 
4663
        processed_prompt.append(day_names[t->tm_wday]);
 
4664
        break;
4244
4665
      case 'P':
4245
 
        processed_prompt->append(t->tm_hour < 12 ? "am" : "pm");
4246
 
        break;
 
4666
        processed_prompt.append(t->tm_hour < 12 ? "am" : "pm");
 
4667
        break;
4247
4668
      case 'o':
4248
 
        add_int_to_prompt(t->tm_mon+1);
4249
 
        break;
 
4669
        add_int_to_prompt(t->tm_mon+1);
 
4670
        break;
4250
4671
      case 'O':
4251
 
        processed_prompt->append(month_names[t->tm_mon]);
4252
 
        break;
 
4672
        processed_prompt.append(month_names[t->tm_mon]);
 
4673
        break;
4253
4674
      case '\'':
4254
 
        processed_prompt->append("'");
4255
 
        break;
 
4675
        processed_prompt.append("'");
 
4676
        break;
4256
4677
      case '"':
4257
 
        processed_prompt->append("\"");
4258
 
        break;
 
4678
        processed_prompt.append('"');
 
4679
        break;
4259
4680
      case 'S':
4260
 
        processed_prompt->append(";");
4261
 
        break;
 
4681
        processed_prompt.append(';');
 
4682
        break;
4262
4683
      case 't':
4263
 
        processed_prompt->append("\t");
4264
 
        break;
 
4684
        processed_prompt.append('\t');
 
4685
        break;
4265
4686
      case 'l':
4266
 
        processed_prompt->append(delimiter_str);
4267
 
        break;
 
4687
        processed_prompt.append(delimiter_str);
 
4688
        break;
4268
4689
      default:
4269
 
        processed_prompt->append(c, 1);
 
4690
        processed_prompt.append(c);
4270
4691
      }
4271
4692
    }
4272
4693
  }
4273
 
  return processed_prompt->c_str();
 
4694
  processed_prompt.append('\0');
 
4695
  return processed_prompt.ptr();
4274
4696
}
4275
4697
 
4276
4698
 
4277
4699
static void add_int_to_prompt(int toadd)
4278
4700
{
4279
4701
  char buffer[16];
4280
 
  int10_to_str(toadd, buffer, 10);
4281
 
  processed_prompt->append(buffer);
 
4702
  int10_to_str(toadd,buffer,10);
 
4703
  processed_prompt.append(buffer);
4282
4704
}
4283
4705
 
4284
4706
static void init_username()
4285
4707
{
4286
 
  free(full_username);
4287
 
  free(part_username);
 
4708
  my_free(full_username,MYF(MY_ALLOW_ZERO_PTR));
 
4709
  my_free(part_username,MYF(MY_ALLOW_ZERO_PTR));
4288
4710
 
4289
 
  DRIZZLE_RES *result;
4290
 
  if (!drizzle_query(&drizzle,"select USER()") &&
4291
 
      (result=drizzle_use_result(&drizzle)))
 
4711
  MYSQL_RES *result;
 
4712
  if (!mysql_query(&mysql,"select USER()") &&
 
4713
      (result=mysql_use_result(&mysql)))
4292
4714
  {
4293
 
    DRIZZLE_ROW cur=drizzle_fetch_row(result);
4294
 
    full_username= strdup(cur[0]);
4295
 
    part_username= strdup(strtok(cur[0],"@"));
4296
 
    (void) drizzle_fetch_row(result);        // Read eof
 
4715
    MYSQL_ROW cur=mysql_fetch_row(result);
 
4716
    full_username=my_strdup(cur[0],MYF(MY_WME));
 
4717
    part_username=my_strdup(strtok(cur[0],"@"),MYF(MY_WME));
 
4718
    (void) mysql_fetch_row(result);             // Read eof
4297
4719
  }
4298
4720
}
4299
4721
 
4300
 
static int com_prompt(string *buffer __attribute__((unused)),
4301
 
                      const char *line)
 
4722
static int com_prompt(String *buffer __attribute__((__unused__)), char *line)
4302
4723
{
4303
4724
  char *ptr=strchr(line, ' ');
4304
4725
  prompt_counter = 0;
4305
 
  free(current_prompt);
4306
 
  current_prompt= strdup(ptr ? ptr+1 : default_prompt);
 
4726
  my_free(current_prompt,MYF(MY_ALLOW_ZERO_PTR));
 
4727
  current_prompt=my_strdup(ptr ? ptr+1 : default_prompt,MYF(MY_WME));
4307
4728
  if (!ptr)
4308
 
    tee_fprintf(stdout, "Returning to default PROMPT of %s\n",
4309
 
                default_prompt);
 
4729
    tee_fprintf(stdout, "Returning to default PROMPT of %s\n", default_prompt);
4310
4730
  else
4311
4731
    tee_fprintf(stdout, "PROMPT set to '%s'\n", current_prompt);
4312
4732
  return 0;
4313
4733
}
4314
4734
 
4315
 
/*
4316
 
    strcont(str, set) if str contanies any character in the string set.
4317
 
    The result is the position of the first found character in str, or NULL
4318
 
    if there isn't anything found.
4319
 
*/
4320
 
 
4321
 
static const char * strcont(register const char *str, register const char *set)
4322
 
{
4323
 
  register const char * start = (const char *) set;
4324
 
 
4325
 
  while (*str)
4326
 
  {
4327
 
    while (*set)
4328
 
    {
4329
 
      if (*set++ == *str)
4330
 
        return ((const char*) str);
4331
 
    }
4332
 
    set=start; str++;
4333
 
  }
4334
 
  return NULL;
4335
 
} /* strcont */
 
4735
#ifndef EMBEDDED_LIBRARY
 
4736
/* Keep sql_string library happy */
 
4737
 
 
4738
void *sql_alloc(size_t Size)
 
4739
{
 
4740
  return my_malloc(Size,MYF(MY_WME));
 
4741
}
 
4742
 
 
4743
void sql_element_free(void *ptr)
 
4744
{
 
4745
  my_free(ptr,MYF(0));
 
4746
}
 
4747
#endif /* EMBEDDED_LIBRARY */