~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzle.c

  • Committer: Brian Aker
  • Date: 2008-07-20 07:10:24 UTC
  • Revision ID: brian@tangent.org-20080720071024-o1wv37gyy8ln5xgk
More my_bool cleanup.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
/* drizzle command tool
 
21
/* mysql command tool
22
22
 * Commands compatible with mSQL by David J. Hughes
23
23
 *
24
24
 * Written by:
33
33
 *
34
34
 **/
35
35
 
36
 
#include <string>
37
 
 
38
36
#include "client_priv.h"
39
 
#include <mystrings/m_ctype.h>
 
37
#include <m_ctype.h>
40
38
#include <stdarg.h>
 
39
#include <my_dir.h>
41
40
#ifndef __GNU_LIBRARY__
42
 
#define __GNU_LIBRARY__          // Skip warnings in getopt.h
 
41
#define __GNU_LIBRARY__               // Skip warnings in getopt.h
43
42
#endif
44
43
#include <readline/history.h>
45
44
#include "my_readline.h"
46
45
#include <signal.h>
47
 
#include <vio/violite.h>
48
 
#include <sys/ioctl.h>
49
 
 
50
 
 
51
 
#if defined(HAVE_LOCALE_H)
 
46
#include <violite.h>
 
47
 
 
48
#if defined(USE_LIBEDIT_INTERFACE) && defined(HAVE_LOCALE_H)
52
49
#include <locale.h>
53
50
#endif
54
51
 
55
 
#include <libdrizzle/gettext.h>
 
52
#include <glib.h>
56
53
 
57
54
const char *VER= "14.14";
58
55
 
59
56
/* Don't try to make a nice table if the data is too big */
60
 
#define MAX_COLUMN_LENGTH       (uint32_t)1024
 
57
#define MAX_COLUMN_LENGTH            1024
61
58
 
62
59
/* Buffer to hold 'version' and 'version_comment' */
63
60
#define MAX_SERVER_VERSION_LENGTH     128
64
61
 
65
 
/* Array of options to pass to libdrizzled */
 
62
/* Array of options to pass to libemysqld */
66
63
#define MAX_SERVER_ARGS               64
67
64
 
68
 
void* sql_alloc(unsigned size);       // Don't use drizzled alloc for these
 
65
void* sql_alloc(unsigned size);      // Don't use mysqld alloc for these
69
66
void sql_element_free(void *ptr);
70
67
 
71
68
#if defined(HAVE_CURSES_H) && defined(HAVE_TERM_H)
78
75
#elif defined(HAVE_TERMBITS_H)
79
76
#include <termbits.h>
80
77
#elif defined(HAVE_ASM_TERMBITS_H) && (!defined __GLIBC__ || !(__GLIBC__ > 2 || __GLIBC__ == 2 && __GLIBC_MINOR__ > 0))
81
 
#include <asm/termbits.h>    // Standard linux
 
78
#include <asm/termbits.h>               // Standard linux
82
79
#endif
83
80
#undef VOID
84
81
#if defined(HAVE_TERMCAP_H)
87
84
#ifdef HAVE_CURSES_H
88
85
#include <curses.h>
89
86
#endif
90
 
#undef SYSV        // hack to avoid syntax error
 
87
#undef SYSV                             // hack to avoid syntax error
91
88
#ifdef HAVE_TERM_H
92
89
#include <term.h>
93
90
#endif
96
93
 
97
94
#undef bcmp                             // Fix problem with new readline
98
95
 
99
 
#ifdef HAVE_READLINE_HISTORY_H
100
 
#include <readline/history.h>
101
 
#endif
102
96
#include <readline/readline.h>
103
97
 
104
 
/**
105
 
 Make the old readline interface look like the new one.
106
 
*/
107
 
#ifndef USE_NEW_READLINE_INTERFACE
108
 
typedef CPPFunction rl_completion_func_t;
109
 
typedef Function rl_compentry_func_t;
110
 
#define rl_completion_matches(str, func) \
111
 
  completion_matches((char *)str, (CPFunction *)func)
112
 
#endif
113
 
 
114
98
 
115
99
#if !defined(HAVE_VIDATTR)
116
100
#undef vidattr
117
 
#define vidattr(A) {}      // Can't get this to work
 
101
#define vidattr(A) {}                   // Can't get this to work
118
102
#endif
119
103
 
120
104
#ifdef FN_NO_CASE_SENCE
125
109
 
126
110
#include "completion_hash.h"
127
111
 
128
 
using namespace std;
129
 
 
130
112
#define PROMPT_CHAR '\\'
131
113
#define DEFAULT_DELIMITER ";"
132
114
 
146
128
enum enum_info_type { INFO_INFO,INFO_ERROR,INFO_RESULT};
147
129
typedef enum enum_info_type INFO_TYPE;
148
130
 
149
 
static DRIZZLE drizzle;      /* The connection */
150
 
static bool ignore_errors=0,quick=0,
 
131
static MYSQL mysql;                     /* The connection */
 
132
static bool ignore_errors=0,wait_flag=0,quick=0,
151
133
  connected=0,opt_raw_data=0,unbuffered=0,output_tables=0,
152
134
  opt_rehash=1,skip_updates=0,safe_updates=0,one_database=0,
153
135
  opt_compress=0, using_opt_local_infile=0,
154
 
  vertical=0, line_numbers=1, column_names=1,
155
 
  opt_nopager=1, opt_outfile=0, named_cmds= 0,
 
136
  vertical=0, line_numbers=1, column_names=1,opt_html=0,
 
137
  opt_xml=0,opt_nopager=1, opt_outfile=0, named_cmds= 0,
156
138
  tty_password= 0, opt_nobeep=0, opt_reconnect=1,
157
139
  default_charset_used= 0, opt_secure_auth= 0,
158
140
  default_pager_set= 0, opt_sigint_ignore= 0,
161
143
static bool debug_info_flag, debug_check_flag;
162
144
static bool column_types_flag;
163
145
static bool preserve_comments= 0;
164
 
static uint32_t opt_max_allowed_packet, opt_net_buffer_length;
165
 
static int verbose=0,opt_silent=0,opt_drizzle_port=0, opt_local_infile=0;
 
146
static ulong opt_max_allowed_packet, opt_net_buffer_length;
 
147
static int verbose=0,opt_silent=0,opt_mysql_port=0, opt_local_infile=0;
166
148
static uint my_end_arg;
167
 
static char * opt_drizzle_unix_port=0;
 
149
static char * opt_mysql_unix_port=0;
168
150
static int connect_flag=CLIENT_INTERACTIVE;
169
151
static char *current_host,*current_db,*current_user=0,*opt_password=0,
170
 
  *delimiter_str= 0,* current_prompt= 0;
 
152
  *delimiter_str= 0,*current_prompt=0,
 
153
  *default_charset= (char*) MYSQL_DEFAULT_CHARSET_NAME;
171
154
static char *histfile;
172
155
static char *histfile_tmp;
173
 
static string *glob_buffer;
174
 
static string *processed_prompt= NULL;
175
 
static char *default_prompt= NULL;
 
156
static GString *glob_buffer;
 
157
static GString *processed_prompt= NULL;
 
158
static GString *default_prompt= NULL;
176
159
static char *full_username=0,*part_username=0;
 
160
static int wait_time = 5;
177
161
static STATUS status;
178
162
static uint32_t select_limit;
179
163
static uint32_t max_join_size;
180
 
static uint32_t opt_connect_timeout= 0;
181
 
static char drizzle_charsets_dir[FN_REFLEN+1];
182
 
// TODO: Need to i18n these
 
164
static ulong opt_connect_timeout= 0;
 
165
static char mysql_charsets_dir[FN_REFLEN+1];
 
166
static const char *xmlmeta[] = {
 
167
  "&", "&amp;",
 
168
  "<", "&lt;",
 
169
  ">", "&gt;",
 
170
  "\"", "&quot;",
 
171
  0, 0
 
172
};
183
173
static const char *day_names[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
184
174
static const char *month_names[]={"Jan","Feb","Mar","Apr","May","Jun","Jul",
185
175
                                  "Aug","Sep","Oct","Nov","Dec"};
192
182
static uint delimiter_length= 1;
193
183
unsigned short terminal_width= 80;
194
184
 
195
 
static const CHARSET_INFO *charset_info= &my_charset_utf8_general_ci;
 
185
static uint opt_protocol= MYSQL_PROTOCOL_TCP;
 
186
static CHARSET_INFO *charset_info= &my_charset_latin1;
196
187
 
197
 
int drizzle_real_query_for_lazy(const char *buf, int length);
198
 
int drizzle_store_result_for_lazy(DRIZZLE_RES **result);
 
188
const char *default_dbug_option="d:t:o,/tmp/mysql.trace";
 
189
int mysql_real_query_for_lazy(const char *buf, int length);
 
190
int mysql_store_result_for_lazy(MYSQL_RES **result);
199
191
 
200
192
 
201
193
void tee_fprintf(FILE *file, const char *fmt, ...);
207
199
static int get_options(int argc,char **argv);
208
200
bool get_one_option(int optid, const struct my_option *opt,
209
201
                    char *argument);
210
 
static int com_quit(string *str,const char*),
211
 
  com_go(string *str,const char*), com_ego(string *str,const char*),
212
 
  com_print(string *str,const char*),
213
 
  com_help(string *str,const char*), com_clear(string *str,const char*),
214
 
  com_connect(string *str,const char*), com_status(string *str,const char*),
215
 
  com_use(string *str,const char*), com_source(string *str, const char*),
216
 
  com_rehash(string *str, const char*), com_tee(string *str, const char*),
217
 
  com_notee(string *str, const char*),
218
 
  com_prompt(string *str, const char*), com_delimiter(string *str, const char*),
219
 
  com_warnings(string *str, const char*), com_nowarnings(string *str, const char*),
220
 
  com_nopager(string *str, const char*), com_pager(string *str, const char*);
 
202
static int com_quit(GString *str,char*),
 
203
  com_go(GString *str,char*), com_ego(GString *str,char*),
 
204
  com_print(GString *str,char*),
 
205
  com_help(GString *str,char*), com_clear(GString *str,char*),
 
206
  com_connect(GString *str,char*), com_status(GString *str,char*),
 
207
  com_use(GString *str,char*), com_source(GString *str, char*),
 
208
  com_rehash(GString *str, char*), com_tee(GString *str, char*),
 
209
  com_notee(GString *str, char*), com_charset(GString *str,char*),
 
210
  com_prompt(GString *str, char*), com_delimiter(GString *str, char*),
 
211
  com_warnings(GString *str, char*), com_nowarnings(GString *str, char*),
 
212
  com_nopager(GString *str, char*), com_pager(GString *str, char*);
221
213
 
222
214
static int read_and_execute(bool interactive);
223
215
static int sql_connect(char *host,char *database,char *user,char *password,
224
216
                       uint silent);
225
 
static const char *server_version_string(DRIZZLE *drizzle);
 
217
static const char *server_version_string(MYSQL *mysql);
226
218
static int put_info(const char *str,INFO_TYPE info,uint error,
227
219
                    const char *sql_state);
228
 
static int put_error(DRIZZLE *drizzle);
229
 
static void safe_put_field(const char *pos,uint32_t length);
 
220
static int put_error(MYSQL *mysql);
 
221
static void safe_put_field(const char *pos,ulong length);
 
222
static void xmlencode_print(const char *src, uint length);
230
223
static void init_pager(void);
231
224
static void end_pager(void);
232
225
static void init_tee(const char *);
235
228
static char *get_arg(char *line, bool get_next_arg);
236
229
static void init_username(void);
237
230
static void add_int_to_prompt(int toadd);
238
 
static int get_result_width(DRIZZLE_RES *res);
239
 
static int get_field_disp_length(DRIZZLE_FIELD * field);
240
 
static const char * strcont(register const char *str, register const char *set);
 
231
static int get_result_width(MYSQL_RES *res);
 
232
static int get_field_disp_length(MYSQL_FIELD * field);
241
233
 
242
234
/* A structure which contains information on the commands this program
243
235
   can understand. */
244
236
typedef struct {
245
 
  const char *name;        /* User printable name of the function. */
246
 
  char cmd_char;        /* msql command character */
247
 
  int (*func)(string *str,const char *); /* Function to call to do the job. */
248
 
  bool takes_params;        /* Max parameters for command */
249
 
  const char *doc;        /* Documentation for this function.  */
 
237
  const char *name;             /* User printable name of the function. */
 
238
  char cmd_char;                /* msql command character */
 
239
  int (*func)(GString *str,char *); /* Function to call to do the job. */
 
240
  bool takes_params;            /* Max parameters for command */
 
241
  const char *doc;              /* Documentation for this function.  */
250
242
} COMMANDS;
251
243
 
252
244
 
253
245
static COMMANDS commands[] = {
254
 
  { "?",      '?', com_help,   1, N_("Synonym for `help'.") },
255
 
  { "clear",  'c', com_clear,  0, N_("Clear command.")},
 
246
  { "?",      '?', com_help,   1, "Synonym for `help'." },
 
247
  { "clear",  'c', com_clear,  0, "Clear command."},
256
248
  { "connect",'r', com_connect,1,
257
 
    N_("Reconnect to the server. Optional arguments are db and host." }),
 
249
    "Reconnect to the server. Optional arguments are db and host." },
258
250
  { "delimiter", 'd', com_delimiter,    1,
259
 
    N_("Set statement delimiter. NOTE: Takes the rest of the line as new delimiter.") },
 
251
    "Set statement delimiter. NOTE: Takes the rest of the line as new delimiter." },
260
252
  { "ego",    'G', com_ego,    0,
261
 
    N_("Send command to drizzle server, display result vertically.")},
262
 
  { "exit",   'q', com_quit,   0, N_("Exit drizzle. Same as quit.")},
263
 
  { "go",     'g', com_go,     0, N_("Send command to drizzle server.") },
264
 
  { "help",   'h', com_help,   1, N_("Display this help.") },
265
 
  { "nopager",'n', com_nopager,0, N_("Disable pager, print to stdout.") },
266
 
  { "notee",  't', com_notee,  0, N_("Don't write into outfile.") },
 
253
    "Send command to mysql server, display result vertically."},
 
254
  { "exit",   'q', com_quit,   0, "Exit mysql. Same as quit."},
 
255
  { "go",     'g', com_go,     0, "Send command to mysql server." },
 
256
  { "help",   'h', com_help,   1, "Display this help." },
 
257
  { "nopager",'n', com_nopager,0, "Disable pager, print to stdout." },
 
258
  { "notee",  't', com_notee,  0, "Don't write into outfile." },
267
259
  { "pager",  'P', com_pager,  1,
268
 
    N_("Set PAGER [to_pager]. Print the query results via PAGER.") },
269
 
  { "print",  'p', com_print,  0, N_("Print current command.") },
270
 
  { "prompt", 'R', com_prompt, 1, N_("Change your drizzle prompt.")},
271
 
  { "quit",   'q', com_quit,   0, N_("Quit drizzle.") },
272
 
  { "rehash", '#', com_rehash, 0, N_("Rebuild completion hash.") },
 
260
    "Set PAGER [to_pager]. Print the query results via PAGER." },
 
261
  { "print",  'p', com_print,  0, "Print current command." },
 
262
  { "prompt", 'R', com_prompt, 1, "Change your mysql prompt."},
 
263
  { "quit",   'q', com_quit,   0, "Quit mysql." },
 
264
  { "rehash", '#', com_rehash, 0, "Rebuild completion hash." },
273
265
  { "source", '.', com_source, 1,
274
 
    N_("Execute an SQL script file. Takes a file name as an argument.")},
275
 
  { "status", 's', com_status, 0, N_("Get status information from the server.")},
 
266
    "Execute an SQL script file. Takes a file name as an argument."},
 
267
  { "status", 's', com_status, 0, "Get status information from the server."},
276
268
  { "tee",    'T', com_tee,    1,
277
 
    N_("Set outfile [to_outfile]. Append everything into given outfile.") },
 
269
    "Set outfile [to_outfile]. Append everything into given outfile." },
278
270
  { "use",    'u', com_use,    1,
279
 
    N_("Use another database. Takes database name as argument.") },
 
271
    "Use another database. Takes database name as argument." },
 
272
  { "charset",    'C', com_charset,    1,
 
273
    "Switch to another charset. Might be needed for processing binlog with multi-byte charsets." },
280
274
  { "warnings", 'W', com_warnings,  0,
281
 
    N_("Show warnings after every statement.") },
 
275
    "Show warnings after every statement." },
282
276
  { "nowarning", 'w', com_nowarnings, 0,
283
 
    N_("Don't show warnings after every statement.") },
 
277
    "Don't show warnings after every statement." },
284
278
  /* Get bash-like expansion for some commands */
285
279
  { "create table",     0, 0, 0, ""},
286
280
  { "create database",  0, 0, 0, ""},
991
985
  { (char *)NULL,       0, 0, 0, ""}
992
986
};
993
987
 
994
 
static const char *load_default_groups[]= { "drizzle","client",0 };
 
988
static const char *load_default_groups[]= { "mysql","client",0 };
 
989
 
 
990
static int         embedded_server_arg_count= 0;
 
991
static char       *embedded_server_args[MAX_SERVER_ARGS];
 
992
static const char *embedded_server_groups[]=
 
993
{ "server", "mysql_SERVER", 0 };
995
994
 
996
995
int history_length;
997
996
static int not_in_history(const char *line);
998
 
static void initialize_readline (char *name);
999
 
static void fix_history(string *final_command);
 
997
static void initialize_readline (const char *name);
 
998
static void fix_history(GString *final_command);
1000
999
 
1001
 
static COMMANDS *find_command(const char *name,char cmd_name);
1002
 
static bool add_line(string *buffer,char *line,char *in_string,
 
1000
static COMMANDS *find_command(char *name,char cmd_name);
 
1001
static bool add_line(GString *buffer,char *line,char *in_string,
1003
1002
                     bool *ml_comment);
1004
 
static void remove_cntrl(string *buffer);
1005
 
static void print_table_data(DRIZZLE_RES *result);
1006
 
static void print_tab_data(DRIZZLE_RES *result);
1007
 
static void print_table_data_vertically(DRIZZLE_RES *result);
 
1003
static void remove_cntrl(GString *buffer);
 
1004
static void print_table_data(MYSQL_RES *result);
 
1005
static void print_table_data_html(MYSQL_RES *result);
 
1006
static void print_table_data_xml(MYSQL_RES *result);
 
1007
static void print_tab_data(MYSQL_RES *result);
 
1008
static void print_table_data_vertically(MYSQL_RES *result);
1008
1009
static void print_warnings(void);
1009
 
static uint32_t start_timer(void);
1010
 
static void end_timer(uint32_t start_time,char *buff);
1011
 
static void drizzle_end_timer(uint32_t start_time,char *buff);
 
1010
static ulong start_timer(void);
 
1011
static void end_timer(ulong start_time,char *buff);
 
1012
static void mysql_end_timer(ulong start_time,char *buff);
1012
1013
static void nice_time(double sec,char *buff,bool part_second);
1013
 
extern sig_handler drizzle_end(int sig);
 
1014
extern sig_handler mysql_end(int sig);
1014
1015
extern sig_handler handle_sigint(int sig);
1015
1016
#if defined(HAVE_TERMIOS_H) && defined(GWINSZ_IN_SYS_IOCTL)
1016
1017
static sig_handler window_resize(int sig);
1020
1021
{
1021
1022
  char buff[80];
1022
1023
 
1023
 
#if defined(ENABLE_NLS)
1024
 
# if defined(HAVE_LOCALE_H)
1025
 
  setlocale(LC_ALL, "");
1026
 
# endif
1027
 
  bindtextdomain("drizzle", LOCALEDIR);
1028
 
  textdomain("drizzle");
1029
 
#endif
1030
 
 
1031
1024
  MY_INIT(argv[0]);
1032
1025
  delimiter_str= delimiter;
1033
 
  default_prompt= my_strdup(getenv("DRIZZLE_PS1") ?
1034
 
                            getenv("DRIZZLE_PS1") :
1035
 
                            "drizzle>> ", MYF(0));
1036
 
  current_prompt= my_strdup(default_prompt, MYF(0));
1037
 
  processed_prompt= new string();
1038
 
  processed_prompt->reserve(32);
1039
 
 
 
1026
  default_prompt = g_string_new(g_strdup(getenv("DRIZZLE_PS1") ?
 
1027
                                         getenv("DRIZZLE_PS1") :
 
1028
                                         "drizzle>> "));
 
1029
  current_prompt = g_strdup(default_prompt->str);
 
1030
  processed_prompt = g_string_sized_new(16);
1040
1031
  prompt_counter=0;
1041
1032
 
1042
 
  outfile[0]=0;      // no (default) outfile
1043
 
  stpcpy(pager, "stdout");  // the default, if --pager wasn't given
 
1033
  outfile[0]=0;                 // no (default) outfile
 
1034
  strmov(pager, "stdout");      // the default, if --pager wasn't given
1044
1035
  {
1045
1036
    char *tmp=getenv("PAGER");
1046
1037
    if (tmp && strlen(tmp))
1047
1038
    {
1048
1039
      default_pager_set= 1;
1049
 
      stpcpy(default_pager, tmp);
 
1040
      strmov(default_pager, tmp);
1050
1041
    }
1051
1042
  }
1052
1043
  if (!isatty(0) || !isatty(1))
1087
1078
    my_end(0);
1088
1079
    exit(1);
1089
1080
  }
 
1081
  if (mysql_server_init(embedded_server_arg_count, embedded_server_args,
 
1082
                        (char**) embedded_server_groups))
 
1083
  {
 
1084
    put_error(NULL);
 
1085
    free_defaults(defaults_argv);
 
1086
    my_end(0);
 
1087
    exit(1);
 
1088
  }
1090
1089
  completion_hash_init(&ht, 128);
1091
1090
  init_alloc_root(&hash_mem_root, 16384, 0);
1092
 
  memset(&drizzle, 0, sizeof(drizzle));
 
1091
  bzero((char*) &mysql, sizeof(mysql));
1093
1092
  if (sql_connect(current_host,current_db,current_user,opt_password,
1094
1093
                  opt_silent))
1095
1094
  {
1096
 
    quick= 1;          // Avoid history
 
1095
    quick= 1;                                   // Avoid history
1097
1096
    status.exit_status= 1;
1098
 
    drizzle_end(-1);
 
1097
    mysql_end(-1);
1099
1098
  }
1100
1099
  if (!status.batch)
1101
 
    ignore_errors=1;        // Don't abort monitor
 
1100
    ignore_errors=1;                            // Don't abort monitor
1102
1101
 
1103
1102
  if (opt_sigint_ignore)
1104
1103
    signal(SIGINT, SIG_IGN);
1105
1104
  else
1106
1105
    signal(SIGINT, handle_sigint);              // Catch SIGINT to clean up
1107
 
  signal(SIGQUIT, drizzle_end);      // Catch SIGQUIT to clean up
 
1106
  signal(SIGQUIT, mysql_end);                   // Catch SIGQUIT to clean up
1108
1107
 
1109
1108
#if defined(HAVE_TERMIOS_H) && defined(GWINSZ_IN_SYS_IOCTL)
1110
1109
  /* Readline will call this if it installs a handler */
1113
1112
  window_resize(0);
1114
1113
#endif
1115
1114
 
1116
 
  put_info(_("Welcome to the Drizzle client..  Commands end with ; or \\g."),
 
1115
  put_info("Welcome to the Drizzle client..  Commands end with ; or \\g.",
1117
1116
           INFO_INFO,0,0);
1118
 
 
1119
 
  glob_buffer= new string();
1120
 
  glob_buffer->reserve(512);
1121
 
  
1122
 
  char * output_buff= (char *)malloc(512);
1123
 
  memset(output_buff, '\0', 512);
1124
 
 
1125
 
  sprintf(output_buff,
1126
 
          _("Your Drizzle connection id is %u\nServer version: %s\n"),
1127
 
          drizzle_thread_id(&drizzle),
1128
 
          server_version_string(&drizzle));
1129
 
  put_info(output_buff, INFO_INFO, 0, 0);
1130
 
 
1131
 
  initialize_readline(current_prompt);
1132
 
  if (!status.batch && !quick)
 
1117
  glob_buffer = g_string_sized_new(512);
 
1118
  g_string_printf(glob_buffer,
 
1119
                  "Your Drizzle connection id is %u\nServer version: %s\n",
 
1120
                  mysql_thread_id(&mysql), server_version_string(&mysql));
 
1121
  put_info(glob_buffer->str,INFO_INFO,0,0);
 
1122
  g_string_truncate(glob_buffer,0);
 
1123
 
 
1124
  initialize_readline(my_progname);
 
1125
  if (!status.batch && !quick && !opt_html && !opt_xml)
1133
1126
  {
1134
 
    /* read-history from file, default ~/.drizzle_history*/
1135
 
    if (getenv("DRIZZLE_HISTFILE"))
1136
 
      histfile= strdup(getenv("DRIZZLE_HISTFILE"));
 
1127
    /* read-history from file, default ~/.mysql_history*/
 
1128
    if (getenv("MYSQL_HISTFILE"))
 
1129
      histfile=g_strdup(getenv("MYSQL_HISTFILE"));
1137
1130
    else if (getenv("HOME"))
1138
1131
    {
1139
1132
      histfile=(char*) my_malloc((uint) strlen(getenv("HOME"))
1140
 
                                 + (uint) strlen("/.drizzle_history")+2,
 
1133
                                 + (uint) strlen("/.mysql_history")+2,
1141
1134
                                 MYF(MY_WME));
1142
1135
      if (histfile)
1143
 
        sprintf(histfile,"%s/.drizzle_history",getenv("HOME"));
 
1136
        sprintf(histfile,"%s/.mysql_history",getenv("HOME"));
1144
1137
      char link_name[FN_REFLEN];
1145
1138
      if (my_readlink(link_name, histfile, 0) == 0 &&
1146
1139
          strncmp(link_name, "/dev/null", 10) == 0)
1147
1140
      {
1148
 
        /* The .drizzle_history file is a symlink to /dev/null, don't use it */
 
1141
        /* The .mysql_history file is a symlink to /dev/null, don't use it */
1149
1142
        my_free(histfile, MYF(MY_ALLOW_ZERO_PTR));
1150
1143
        histfile= 0;
1151
1144
      }
1153
1146
    if (histfile)
1154
1147
    {
1155
1148
      if (verbose)
1156
 
        tee_fprintf(stdout, _("Reading history-file %s\n"),histfile);
 
1149
        tee_fprintf(stdout, "Reading history-file %s\n",histfile);
1157
1150
      read_history(histfile);
1158
1151
      if (!(histfile_tmp= (char*) my_malloc((uint) strlen(histfile) + 5,
1159
1152
                                            MYF(MY_WME))))
1160
1153
      {
1161
 
        fprintf(stderr, _("Couldn't allocate memory for temp histfile!\n"));
 
1154
        fprintf(stderr, "Couldn't allocate memory for temp histfile!\n");
1162
1155
        exit(1);
1163
1156
      }
1164
1157
      sprintf(histfile_tmp, "%s.TMP", histfile);
1165
1158
    }
1166
1159
  }
1167
1160
  sprintf(buff, "%s",
1168
 
          _("Type 'help;' or '\\h' for help. Type '\\c' to clear the buffer.\n"));
 
1161
          "Type 'help;' or '\\h' for help. Type '\\c' to clear the buffer.\n");
1169
1162
 
1170
1163
  put_info(buff,INFO_INFO,0,0);
1171
1164
  status.exit_status= read_and_execute(!status.batch);
1172
1165
  if (opt_outfile)
1173
1166
    end_tee();
1174
 
  drizzle_end(0);
1175
 
 
1176
 
  return(0);        // Keep compiler happy
 
1167
  mysql_end(0);
 
1168
#ifndef _lint
 
1169
  return(0);                            // Keep compiler happy
 
1170
#endif
1177
1171
}
1178
1172
 
1179
 
sig_handler drizzle_end(int sig)
 
1173
sig_handler mysql_end(int sig)
1180
1174
{
1181
 
  drizzle_close(&drizzle);
1182
 
  if (!status.batch && !quick && histfile)
 
1175
  mysql_close(&mysql);
 
1176
  if (!status.batch && !quick && !opt_html && !opt_xml && histfile)
1183
1177
  {
1184
1178
    /* write-history */
1185
1179
    if (verbose)
1186
 
      tee_fprintf(stdout, _("Writing history-file %s\n"),histfile);
 
1180
      tee_fprintf(stdout, "Writing history-file %s\n",histfile);
1187
1181
    if (!write_history(histfile_tmp))
1188
1182
      my_rename(histfile_tmp, histfile, MYF(MY_WME));
1189
1183
  }
1192
1186
  free_root(&hash_mem_root,MYF(0));
1193
1187
 
1194
1188
  if (sig >= 0)
1195
 
    put_info(sig ? _("Aborted") : _("Bye"), INFO_RESULT,0,0);
1196
 
  if (glob_buffer)
1197
 
    delete glob_buffer;
1198
 
  if (processed_prompt)
1199
 
    delete processed_prompt;
 
1189
    put_info(sig ? "Aborted" : "Bye", INFO_RESULT,0,0);
 
1190
  assert(glob_buffer != NULL);
 
1191
  g_string_free(glob_buffer,true);
 
1192
  assert(processed_prompt != NULL);
 
1193
  g_string_free(processed_prompt,true);
 
1194
  assert(default_prompt != NULL);
 
1195
  g_string_free(default_prompt,true);
1200
1196
  my_free(opt_password,MYF(MY_ALLOW_ZERO_PTR));
1201
 
  my_free(opt_drizzle_unix_port,MYF(MY_ALLOW_ZERO_PTR));
 
1197
  my_free(opt_mysql_unix_port,MYF(MY_ALLOW_ZERO_PTR));
1202
1198
  my_free(histfile,MYF(MY_ALLOW_ZERO_PTR));
1203
1199
  my_free(histfile_tmp,MYF(MY_ALLOW_ZERO_PTR));
1204
1200
  my_free(current_db,MYF(MY_ALLOW_ZERO_PTR));
1208
1204
  my_free(part_username,MYF(MY_ALLOW_ZERO_PTR));
1209
1205
  my_free(default_prompt,MYF(MY_ALLOW_ZERO_PTR));
1210
1206
  my_free(current_prompt,MYF(MY_ALLOW_ZERO_PTR));
1211
 
  drizzle_server_end();
 
1207
  while (embedded_server_arg_count > 1)
 
1208
    my_free(embedded_server_args[--embedded_server_arg_count],MYF(0));
 
1209
  mysql_server_end();
1212
1210
  free_defaults(defaults_argv);
1213
1211
  my_end(my_end_arg);
1214
1212
  exit(status.exit_status);
1223
1221
sig_handler handle_sigint(int sig)
1224
1222
{
1225
1223
  char kill_buffer[40];
1226
 
  DRIZZLE *kill_drizzle= NULL;
 
1224
  MYSQL *kill_mysql= NULL;
1227
1225
 
1228
1226
  /* terminate if no query being executed, or we already tried interrupting */
1229
1227
  if (!executing_query || interrupted_query) {
1230
1228
    goto err;
1231
1229
  }
1232
1230
 
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))
 
1231
  kill_mysql= mysql_init(kill_mysql);
 
1232
  if (!mysql_real_connect(kill_mysql,current_host, current_user, opt_password,
 
1233
                          "", opt_mysql_port, opt_mysql_unix_port,0))
1236
1234
  {
1237
1235
    goto err;
1238
1236
  }
1239
1237
 
1240
1238
  /* 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"));
 
1239
  sprintf(kill_buffer, "KILL /*!50000 QUERY */ %u", mysql_thread_id(&mysql));
 
1240
  mysql_real_query(kill_mysql, kill_buffer, strlen(kill_buffer));
 
1241
  mysql_close(kill_mysql);
 
1242
  tee_fprintf(stdout, "Query aborted by Ctrl+C\n");
1245
1243
 
1246
1244
  interrupted_query= 1;
1247
1245
 
1248
1246
  return;
1249
1247
 
1250
1248
err:
1251
 
  drizzle_end(sig);
 
1249
  mysql_end(sig);
1252
1250
}
1253
1251
 
1254
1252
 
1255
1253
#if defined(HAVE_TERMIOS_H) && defined(GWINSZ_IN_SYS_IOCTL)
1256
 
sig_handler window_resize(int sig __attribute__((unused)))
 
1254
sig_handler window_resize(int sig __attribute__((__unused__)))
1257
1255
{
1258
1256
  struct winsize window_size;
1259
1257
 
1264
1262
 
1265
1263
static struct my_option my_long_options[] =
1266
1264
{
1267
 
  {"help", '?', N_("Display this help and exit."), 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
 
1265
  {"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
1268
1266
   0, 0, 0, 0, 0},
1269
 
  {"help", 'I', N_("Synonym for -?"), 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
 
1267
  {"help", 'I', "Synonym for -?", 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
1270
1268
   0, 0, 0, 0, 0},
1271
1269
  {"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."),
 
1270
   "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
1271
   (char**) &opt_rehash, (char**) &opt_rehash, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0,
1274
1272
   0, 0},
1275
1273
  {"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."),
 
1274
   "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
1275
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1278
1276
  {"auto-vertical-output", OPT_AUTO_VERTICAL_OUTPUT,
1279
 
   N_("Automatically switch to vertical output mode if the result is wider than the terminal width."),
 
1277
   "Automatically switch to vertical output mode if the result is wider than the terminal width.",
1280
1278
   (char**) &auto_vertical_output, (char**) &auto_vertical_output, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1281
1279
  {"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},
 
1280
   "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
1281
  {"character-sets-dir", OPT_CHARSETS_DIR,
1284
 
   N_("Directory where character sets are."), (char**) &charsets_dir,
 
1282
   "Directory where character sets are.", (char**) &charsets_dir,
1285
1283
   (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."),
 
1284
  {"column-type-info", OPT_COLUMN_TYPES, "Display column type information.",
1287
1285
   (char**) &column_types_flag, (char**) &column_types_flag,
1288
1286
   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"),
 
1287
  {"comments", 'c', "Preserve comments. Send comments to the server."
 
1288
   " The default is --skip-comments (discard comments), enable with --comments",
1290
1289
   (char**) &preserve_comments, (char**) &preserve_comments,
1291
1290
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1292
 
  {"compress", 'C', N_("Use compression in server/client protocol."),
 
1291
  {"compress", 'C', "Use compression in server/client protocol.",
1293
1292
   (char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
1294
1293
   0, 0, 0},
1295
 
  {"debug-check", OPT_DEBUG_CHECK, N_("Check memory and open file usage at exit ."),
 
1294
  {"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit .",
1296
1295
   (char**) &debug_check_flag, (char**) &debug_check_flag, 0,
1297
1296
   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,
 
1297
  {"debug-info", 'T', "Print some debug info at exit.", (char**) &debug_info_flag,
1299
1298
   (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,
 
1299
  {"database", 'D', "Database to use.", (char**) &current_db,
1301
1300
   (char**) &current_db, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1302
1301
  {"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,
 
1302
   "Set the default character set.", (char**) &default_charset,
 
1303
   (char**) &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1304
  {"delimiter", OPT_DELIMITER, "Delimiter to be used.", (char**) &delimiter_str,
1306
1305
   (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,
 
1306
  {"execute", 'e', "Execute command and quit. (Disables --force and history file)", 0,
1308
1307
   0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1309
 
  {"vertical", 'E', N_("Print the output of a query (rows) vertically."),
 
1308
  {"vertical", 'E', "Print the output of a query (rows) vertically.",
1310
1309
   (char**) &vertical, (char**) &vertical, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
1311
1310
   0},
1312
 
  {"force", 'f', N_("Continue even if we get an sql error."),
 
1311
  {"force", 'f', "Continue even if we get an sql error.",
1313
1312
   (char**) &ignore_errors, (char**) &ignore_errors, 0, GET_BOOL, NO_ARG, 0, 0,
1314
1313
   0, 0, 0, 0},
1315
1314
  {"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."),
 
1315
   "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.",
1317
1316
   (char**) &named_cmds, (char**) &named_cmds, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
1318
1317
   0, 0},
1319
1318
  {"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."),
 
1319
   "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
1320
   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,
 
1321
  {"ignore-spaces", 'i', "Ignore space after function names.", 0, 0, 0,
1323
1322
   GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1324
 
  {"local-infile", OPT_LOCAL_INFILE, N_("Enable/disable LOAD DATA LOCAL INFILE."),
 
1323
  {"local-infile", OPT_LOCAL_INFILE, "Enable/disable LOAD DATA LOCAL INFILE.",
1325
1324
   (char**) &opt_local_infile,
1326
1325
   (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,
 
1326
  {"no-beep", 'b', "Turn off beep on error.", (char**) &opt_nobeep,
1328
1327
   (char**) &opt_nobeep, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1329
 
  {"host", 'h', N_("Connect to host."), (char**) &current_host,
 
1328
  {"host", 'h', "Connect to host.", (char**) &current_host,
1330
1329
   (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."),
 
1330
  {"html", 'H', "Produce HTML output.", (char**) &opt_html, (char**) &opt_html,
 
1331
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1332
  {"xml", 'X', "Produce XML output", (char**) &opt_xml, (char**) &opt_xml, 0,
 
1333
   GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1334
  {"line-numbers", OPT_LINE_NUMBERS, "Write line numbers for errors.",
1332
1335
   (char**) &line_numbers, (char**) &line_numbers, 0, GET_BOOL,
1333
1336
   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,
 
1337
  {"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
1338
   NO_ARG, 0, 0, 0, 0, 0, 0},
1336
 
  {"unbuffered", 'n', N_("Flush buffer after each query."), (char**) &unbuffered,
 
1339
  {"unbuffered", 'n', "Flush buffer after each query.", (char**) &unbuffered,
1337
1340
   (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."),
 
1341
  {"column-names", OPT_COLUMN_NAMES, "Write column names in results.",
1339
1342
   (char**) &column_names, (char**) &column_names, 0, GET_BOOL,
1340
1343
   NO_ARG, 1, 0, 0, 0, 0, 0},
1341
1344
  {"skip-column-names", 'N',
1342
 
   N_("Don't write column names in results. WARNING: -N is deprecated, use long version of this options instead."),
 
1345
   "Don't write column names in results. WARNING: -N is deprecated, use long version of this options instead.",
1343
1346
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1344
1347
  {"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."),
 
1348
   "Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value.",
1346
1349
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1347
 
  {"sigint-ignore", OPT_SIGINT_IGNORE, N_("Ignore SIGINT (CTRL-C)"),
 
1350
  {"sigint-ignore", OPT_SIGINT_IGNORE, "Ignore SIGINT (CTRL-C)",
1348
1351
   (char**) &opt_sigint_ignore,  (char**) &opt_sigint_ignore, 0, GET_BOOL,
1349
1352
   NO_ARG, 0, 0, 0, 0, 0, 0},
1350
1353
  {"one-database", 'o',
1351
 
   N_("Only update the default database. This is useful for skipping updates to other database in the update log."),
 
1354
   "Only update the default database. This is useful for skipping updates to other database in the update log.",
1352
1355
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1353
1356
  {"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."),
 
1357
   "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
1358
   0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
1356
1359
  {"no-pager", OPT_NOPAGER,
1357
 
   N_("Disable pager and print to stdout. See interactive help (\\h) also. WARNING: option deprecated; use --disable-pager instead."),
 
1360
   "Disable pager and print to stdout. See interactive help (\\h) also. WARNING: option deprecated; use --disable-pager instead.",
1358
1361
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1359
1362
  {"password", 'p',
1360
 
   N_("Password to use when connecting to server. If password is not given it's asked from the tty."),
 
1363
   "Password to use when connecting to server. If password is not given it's asked from the tty.",
1361
1364
   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."),
 
1365
  {"port", 'P', "Port number to use for connection or 0 for default to, in "
 
1366
   "order of preference, my.cnf, $MYSQL_TCP_PORT, "
 
1367
#if MYSQL_PORT_DEFAULT == 0
 
1368
   "/etc/services, "
 
1369
#endif
 
1370
   "built-in default (" STRINGIFY_ARG(MYSQL_PORT) ").",
 
1371
   (char**) &opt_mysql_port,
 
1372
   (char**) &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,  0},
 
1373
  {"prompt", OPT_PROMPT, "Set the mysql prompt to this value.",
1367
1374
   (char**) &current_prompt, (char**) &current_prompt, 0, GET_STR_ALLOC,
1368
1375
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1369
 
  {"protocol", OPT_DRIZZLE_PROTOCOL, N_("The protocol of connection (tcp,socket,pipe,memory)."),
 
1376
  {"protocol", OPT_MYSQL_PROTOCOL, "The protocol of connection (tcp,socket,pipe,memory).",
1370
1377
   0, 0, 0, GET_STR,  REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1371
1378
  {"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."),
 
1379
   "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
1380
   (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."),
 
1381
  {"raw", 'r', "Write fields without conversion. Used with --batch.",
1375
1382
   (char**) &opt_raw_data, (char**) &opt_raw_data, 0, GET_BOOL, NO_ARG, 0, 0, 0,
1376
1383
   0, 0, 0},
1377
 
  {"reconnect", OPT_RECONNECT, N_("Reconnect if the connection is lost. Disable with --disable-reconnect. This option is enabled by default."),
 
1384
  {"reconnect", OPT_RECONNECT, "Reconnect if the connection is lost. Disable with --disable-reconnect. This option is enabled by default.",
1378
1385
   (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,
 
1386
  {"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
1387
   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,
 
1388
  {"socket", 'S', "Socket file to use for connection.",
 
1389
   (char**) &opt_mysql_unix_port, (char**) &opt_mysql_unix_port, 0, GET_STR_ALLOC,
1383
1390
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1384
 
  {"table", 't', N_("Output in table format."), (char**) &output_tables,
 
1391
  {"table", 't', "Output in table format.", (char**) &output_tables,
1385
1392
   (char**) &output_tables, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1386
1393
  {"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."),
 
1394
   "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
1395
   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,
 
1396
  {"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
1397
   NO_ARG, 0, 0, 0, 0, 0, 0},
1391
1398
#ifndef DONT_ALLOW_USER_CHANGE
1392
 
  {"user", 'u', N_("User for login if not current user."), (char**) &current_user,
 
1399
  {"user", 'u', "User for login if not current user.", (char**) &current_user,
1393
1400
   (char**) &current_user, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1394
1401
#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,
 
1402
  {"safe-updates", 'U', "Only allow UPDATE and DELETE that uses keys.",
 
1403
   (char**) &safe_updates, (char**) &safe_updates, 0, GET_BOOL, NO_ARG, 0, 0,
 
1404
   0, 0, 0, 0},
 
1405
  {"i-am-a-dummy", 'U', "Synonym for option --safe-updates, -U.",
 
1406
   (char**) &safe_updates, (char**) &safe_updates, 0, GET_BOOL, NO_ARG, 0, 0,
 
1407
   0, 0, 0, 0},
 
1408
  {"verbose", 'v', "Write more. (-v -v -v gives the table output format).", 0,
1402
1409
   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,
 
1410
  {"version", 'V', "Output version information and exit.", 0, 0, 0,
1404
1411
   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,
 
1412
  {"wait", 'w', "Wait and retry if connection is down.", 0, 0, 0, GET_NO_ARG,
1406
1413
   NO_ARG, 0, 0, 0, 0, 0, 0},
1407
1414
  {"connect_timeout", OPT_CONNECT_TIMEOUT,
1408
 
   N_("Number of seconds before connection timeout."),
 
1415
   "Number of seconds before connection timeout.",
1409
1416
   (char**) &opt_connect_timeout,
1410
1417
   (char**) &opt_connect_timeout, 0, GET_ULONG, REQUIRED_ARG, 0, 0, 3600*12, 0,
1411
1418
   0, 0},
1412
1419
  {"max_allowed_packet", OPT_MAX_ALLOWED_PACKET,
1413
 
   N_("Max packet length to send to, or receive from server"),
 
1420
   "Max packet length to send to, or receive from server",
1414
1421
   (char**) &opt_max_allowed_packet, (char**) &opt_max_allowed_packet, 0,
1415
1422
   GET_ULONG, REQUIRED_ARG, 16 *1024L*1024L, 4096,
1416
1423
   (int64_t) 2*1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
1417
1424
  {"net_buffer_length", OPT_NET_BUFFER_LENGTH,
1418
 
   N_("Buffer for TCP/IP and socket communication"),
 
1425
   "Buffer for TCP/IP and socket communication",
1419
1426
   (char**) &opt_net_buffer_length, (char**) &opt_net_buffer_length, 0, GET_ULONG,
1420
1427
   REQUIRED_ARG, 16384, 1024, 512*1024*1024L, MALLOC_OVERHEAD, 1024, 0},
1421
1428
  {"select_limit", OPT_SELECT_LIMIT,
1422
 
   N_("Automatic limit for SELECT when using --safe-updates"),
 
1429
   "Automatic limit for SELECT when using --safe-updates",
1423
1430
   (char**) &select_limit,
1424
1431
   (char**) &select_limit, 0, GET_ULONG, REQUIRED_ARG, 1000L, 1, ULONG_MAX,
1425
1432
   0, 1, 0},
1426
1433
  {"max_join_size", OPT_MAX_JOIN_SIZE,
1427
 
   N_("Automatic limit for rows in a join when using --safe-updates"),
 
1434
   "Automatic limit for rows in a join when using --safe-updates",
1428
1435
   (char**) &max_join_size,
1429
1436
   (char**) &max_join_size, 0, GET_ULONG, REQUIRED_ARG, 1000000L, 1, ULONG_MAX,
1430
1437
   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,
 
1438
  {"secure-auth", OPT_SECURE_AUTH, "Refuse client connecting to server if it"
 
1439
   " uses old (pre-4.1.1) protocol", (char**) &opt_secure_auth,
1432
1440
   (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."),
 
1441
  {"server-arg", OPT_SERVER_ARG, "Send embedded server this as a parameter.",
 
1442
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1443
  {"show-warnings", OPT_SHOW_WARNINGS, "Show warnings after every statement.",
1434
1444
   (char**) &show_warnings, (char**) &show_warnings, 0, GET_BOOL, NO_ARG,
1435
1445
   0, 0, 0, 0, 0, 0},
1436
1446
  { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
1441
1451
{
1442
1452
  const char* readline= "readline";
1443
1453
 
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,
 
1454
  printf("%s  Ver %s Distrib %s, for %s (%s) using %s %s\n",
 
1455
         my_progname, VER, MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE,
1447
1456
         readline, rl_library_version);
1448
1457
 
1449
1458
  if (version)
1450
1459
    return;
1451
 
  printf(_("\
 
1460
  printf("\
1452
1461
Copyright (C) 2000-2008 MySQL AB\n                                      \
1453
1462
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);
 
1463
and you are welcome to modify and redistribute it under the GPL license\n");
 
1464
  printf("Usage: %s [OPTIONS] [database]\n", my_progname);
1456
1465
  my_print_help(my_long_options);
1457
1466
  print_defaults("my", load_default_groups);
1458
1467
  my_print_variables(my_long_options);
1465
1474
{
1466
1475
  switch(optid) {
1467
1476
  case OPT_CHARSETS_DIR:
1468
 
    strmake(drizzle_charsets_dir, argument, sizeof(drizzle_charsets_dir) - 1);
1469
 
    charsets_dir = drizzle_charsets_dir;
 
1477
    strmake(mysql_charsets_dir, argument, sizeof(mysql_charsets_dir) - 1);
 
1478
    charsets_dir = mysql_charsets_dir;
1470
1479
    break;
1471
1480
  case  OPT_DEFAULT_CHARSET:
1472
1481
    default_charset_used= 1;
1474
1483
  case OPT_DELIMITER:
1475
1484
    if (argument == disabled_my_option)
1476
1485
    {
1477
 
      stpcpy(delimiter, DEFAULT_DELIMITER);
 
1486
      strmov(delimiter, DEFAULT_DELIMITER);
1478
1487
    }
1479
1488
    else
1480
1489
    {
1485
1494
      }
1486
1495
      else
1487
1496
      {
1488
 
        put_info(_("DELIMITER cannot contain a backslash character"),
 
1497
        put_info("DELIMITER cannot contain a backslash character",
1489
1498
                 INFO_ERROR,0,0);
1490
1499
        return 0;
1491
1500
      }
1506
1515
      init_tee(argument);
1507
1516
    break;
1508
1517
  case OPT_NOTEE:
1509
 
    printf(_("WARNING: option deprecated; use --disable-tee instead.\n"));
 
1518
    printf("WARNING: option deprecated; use --disable-tee instead.\n");
1510
1519
    if (opt_outfile)
1511
1520
      end_tee();
1512
1521
    break;
1520
1529
      {
1521
1530
        default_pager_set= 1;
1522
1531
        strmake(pager, argument, sizeof(pager) - 1);
1523
 
        stpcpy(default_pager, pager);
 
1532
        strmov(default_pager, pager);
1524
1533
      }
1525
1534
      else if (default_pager_set)
1526
 
        stpcpy(pager, default_pager);
 
1535
        strmov(pager, default_pager);
1527
1536
      else
1528
1537
        opt_nopager= 1;
1529
1538
    }
1530
1539
    break;
1531
1540
  case OPT_NOPAGER:
1532
 
    printf(_("WARNING: option deprecated; use --disable-pager instead.\n"));
 
1541
    printf("WARNING: option deprecated; use --disable-pager instead.\n");
1533
1542
    opt_nopager= 1;
1534
1543
    break;
 
1544
  case OPT_MYSQL_PROTOCOL:
 
1545
    opt_protocol= find_type_or_exit(argument, &sql_protocol_typelib,
 
1546
                                    opt->name);
 
1547
    break;
1535
1548
  case OPT_SERVER_ARG:
1536
 
    printf(_("WARNING: --server-arg option not supported in this configuration.\n"));
 
1549
#ifdef EMBEDDED_LIBRARY
 
1550
    /*
 
1551
      When the embedded server is being tested, the client needs to be
 
1552
      able to pass command-line arguments to the embedded server so it can
 
1553
      locate the language files and data directory.
 
1554
    */
 
1555
    if (!embedded_server_arg_count)
 
1556
    {
 
1557
      embedded_server_arg_count= 1;
 
1558
      embedded_server_args[0]= (char*) "";
 
1559
    }
 
1560
    if (embedded_server_arg_count == MAX_SERVER_ARGS-1 ||
 
1561
        !(embedded_server_args[embedded_server_arg_count++]=
 
1562
          g_strdup(argument)))
 
1563
    {
 
1564
      put_info("Can't use server argument", INFO_ERROR);
 
1565
      return 0;
 
1566
    }
 
1567
#else /*EMBEDDED_LIBRARY */
 
1568
    printf("WARNING: --server-arg option not supported in this configuration.\n");
 
1569
#endif
1537
1570
    break;
1538
1571
  case 'A':
1539
1572
    opt_rehash= 0;
1557
1590
    break;
1558
1591
  case 'p':
1559
1592
    if (argument == disabled_my_option)
1560
 
      argument= (char*) "";      // Don't require password
 
1593
      argument= (char*) "";                     // Don't require password
1561
1594
    if (argument)
1562
1595
    {
1563
1596
      char *start= argument;
1564
1597
      my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR));
1565
 
      opt_password= strdup(argument);
1566
 
      while (*argument) *argument++= 'x';        // Destroy argument
 
1598
      opt_password= g_strdup(argument);
 
1599
      while (*argument) *argument++= 'x';               // Destroy argument
1567
1600
      if (*start)
1568
1601
        start[1]=0 ;
1569
1602
      tty_password= 0;
1605
1638
{
1606
1639
  char *tmp, *pagpoint;
1607
1640
  int ho_error;
1608
 
  const DRIZZLE_PARAMETERS *drizzle_params= drizzle_get_parameters();
 
1641
  MYSQL_PARAMETERS *mysql_params= mysql_get_parameters();
1609
1642
 
1610
 
  tmp= (char *) getenv("DRIZZLE_HOST");
 
1643
  tmp= (char *) getenv("MYSQL_HOST");
1611
1644
  if (tmp)
1612
1645
    current_host= strdup(tmp);
1613
1646
 
1614
1647
  pagpoint= getenv("PAGER");
1615
1648
  if (!((char*) (pagpoint)))
1616
1649
  {
1617
 
    stpcpy(pager, "stdout");
 
1650
    strmov(pager, "stdout");
1618
1651
    opt_nopager= 1;
1619
1652
  }
1620
1653
  else
1621
 
    stpcpy(pager, pagpoint);
1622
 
  stpcpy(default_pager, pager);
 
1654
    strmov(pager, pagpoint);
 
1655
  strmov(default_pager, pager);
1623
1656
 
1624
 
  opt_max_allowed_packet= *drizzle_params->p_max_allowed_packet;
1625
 
  opt_net_buffer_length= *drizzle_params->p_net_buffer_length;
 
1657
  opt_max_allowed_packet= *mysql_params->p_max_allowed_packet;
 
1658
  opt_net_buffer_length= *mysql_params->p_net_buffer_length;
1626
1659
 
1627
1660
  if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
1628
1661
    exit(ho_error);
1629
1662
 
1630
 
  *drizzle_params->p_max_allowed_packet= opt_max_allowed_packet;
1631
 
  *drizzle_params->p_net_buffer_length= opt_net_buffer_length;
 
1663
  *mysql_params->p_max_allowed_packet= opt_max_allowed_packet;
 
1664
  *mysql_params->p_net_buffer_length= opt_net_buffer_length;
1632
1665
 
1633
1666
  if (status.batch) /* disable pager and outfile in this case */
1634
1667
  {
1635
 
    stpcpy(default_pager, "stdout");
1636
 
    stpcpy(pager, "stdout");
 
1668
    strmov(default_pager, "stdout");
 
1669
    strmov(pager, "stdout");
1637
1670
    opt_nopager= 1;
1638
1671
    default_pager_set= 0;
1639
1672
    opt_outfile= 0;
1641
1674
    connect_flag= 0; /* Not in interactive mode */
1642
1675
  }
1643
1676
 
 
1677
  if (strcmp(default_charset, charset_info->csname) &&
 
1678
      !(charset_info= get_charset_by_csname(default_charset,
 
1679
                                            MY_CS_PRIMARY, MYF(MY_WME))))
 
1680
    exit(1);
1644
1681
  if (argc > 1)
1645
1682
  {
1646
1683
    usage(0);
1650
1687
  {
1651
1688
    skip_updates= 0;
1652
1689
    my_free(current_db, MYF(MY_ALLOW_ZERO_PTR));
1653
 
    current_db= strdup(*argv);
 
1690
    current_db= g_strdup(*argv);
1654
1691
  }
1655
1692
  if (tty_password)
1656
1693
    opt_password= get_tty_password(NullS);
1665
1702
{
1666
1703
  char *line;
1667
1704
  char in_string=0;
1668
 
  uint32_t line_number=0;
 
1705
  ulong line_number=0;
1669
1706
  bool ml_comment= 0;
1670
1707
  COMMANDS *com;
1671
1708
  status.exit_status=1;
1687
1724
          (uchar) line[2] == 0xBF)
1688
1725
        line+= 3;
1689
1726
      line_number++;
1690
 
      if (!glob_buffer->empty())
 
1727
      if (glob_buffer->len!=0)
1691
1728
        status.query_start_line=line_number;
1692
1729
    }
1693
1730
    else
1694
1731
    {
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())
 
1732
      char *prompt= (char*) (ml_comment ? "   /*> " :
 
1733
                             (glob_buffer->len == 0) ?  construct_prompt() :
 
1734
                             !in_string ? "    -> " :
 
1735
                             in_string == '\'' ?
 
1736
                             "    '> " : (in_string == '`' ?
 
1737
                                          "    `> " :
 
1738
                                          "    \"> "));
 
1739
      if (opt_outfile && (glob_buffer->len==0))
1704
1740
        fflush(OUTFILE);
1705
1741
 
1706
1742
      if (opt_outfile)
1721
1757
    }
1722
1758
 
1723
1759
    /*
1724
 
      Check if line is a drizzle command line
 
1760
      Check if line is a mysql command line
1725
1761
      (We want to allow help, print and clear anywhere at line start
1726
1762
    */
1727
 
    if ((named_cmds || (glob_buffer->empty()))
 
1763
    if ((named_cmds || (glob_buffer->len==0))
1728
1764
        && !ml_comment && !in_string && (com=find_command(line,0)))
1729
1765
    {
1730
1766
      if ((*com->func)(glob_buffer,line) > 0)
1731
1767
        break;
1732
1768
      // If buffer was emptied
1733
 
      if (glob_buffer->empty())
 
1769
      if (glob_buffer->len==0)
1734
1770
        in_string=0;
1735
1771
      if (interactive && status.add_to_history && not_in_history(line))
1736
1772
        add_history(line);
1744
1780
  if (!interactive && !status.exit_status)
1745
1781
  {
1746
1782
    remove_cntrl(glob_buffer);
1747
 
    if (!glob_buffer->empty())
 
1783
    if (glob_buffer->len != 0)
1748
1784
    {
1749
1785
      status.exit_status=1;
1750
1786
      if (com_go(glob_buffer,line) <= 0)
1756
1792
}
1757
1793
 
1758
1794
 
1759
 
static COMMANDS *find_command(const char *name,char cmd_char)
 
1795
static COMMANDS *find_command(char *name,char cmd_char)
1760
1796
{
1761
1797
  uint len;
1762
 
  const char *end;
 
1798
  char *end;
1763
1799
 
1764
1800
  if (!name)
1765
1801
  {
1788
1824
      while (my_isspace(charset_info,*end))
1789
1825
        end++;
1790
1826
      if (!*end)
1791
 
        end=0;          // no arguments to function
 
1827
        end=0;                                  // no arguments to function
1792
1828
    }
1793
1829
    else
1794
1830
      len=(uint) strlen(name);
1797
1833
  for (uint i= 0; commands[i].name; i++)
1798
1834
  {
1799
1835
    if (commands[i].func &&
1800
 
        ((name && !my_strnncoll(charset_info,(const uchar*)name,len, (const uchar*)commands[i].name,len) && !commands[i].name[len] && (!end || (end && commands[i].takes_params))) || (!name && commands[i].cmd_char == cmd_char)))
 
1836
        ((name && !my_strnncoll(charset_info,(uchar*)name,len, (uchar*)commands[i].name,len) && !commands[i].name[len] && (!end || (end && commands[i].takes_params))) || (!name && commands[i].cmd_char == cmd_char)))
1801
1837
    {
1802
1838
      return(&commands[i]);
1803
1839
    }
1806
1842
}
1807
1843
 
1808
1844
 
1809
 
static bool add_line(string *buffer, char *line, char *in_string,
 
1845
static bool add_line(GString *buffer,char *line,char *in_string,
1810
1846
                        bool *ml_comment)
1811
1847
{
1812
1848
  uchar inchar;
1816
1852
  bool ss_comment= 0;
1817
1853
 
1818
1854
 
1819
 
  if (!line[0] && (buffer->empty()))
 
1855
  if (!line[0] && (buffer->len==0))
1820
1856
    return(0);
1821
1857
  if (status.add_to_history && line[0] && not_in_history(line))
1822
1858
    add_history(line);
1828
1864
    {
1829
1865
      // Skip spaces at the beggining of a statement
1830
1866
      if (my_isspace(charset_info,inchar) && (out == line) &&
1831
 
          (buffer->empty()))
 
1867
          (buffer->len==0))
1832
1868
        continue;
1833
1869
    }
1834
1870
 
1850
1886
    }
1851
1887
#endif
1852
1888
        if (!*ml_comment && inchar == '\\' &&
1853
 
            !(*in_string && (drizzle.server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)))
 
1889
        !(mysql.server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES))
1854
1890
    {
1855
1891
      // Found possbile one character command like \c
1856
1892
 
1857
1893
      if (!(inchar = (uchar) *++pos))
1858
 
        break;        // readline adds one '\'
1859
 
      if (*in_string || inchar == 'N')  // \N is short for NULL
1860
 
      {          // Don't allow commands in string
 
1894
        break;                          // readline adds one '\'
 
1895
      if (*in_string || inchar == 'N')  // \N is short for NULL
 
1896
      {                                 // Don't allow commands in string
1861
1897
        *out++='\\';
1862
1898
        *out++= (char) inchar;
1863
1899
        continue;
1867
1903
        // Flush previously accepted characters
1868
1904
        if (out != line)
1869
1905
        {
1870
 
          buffer->append(line, (out-line));
 
1906
          g_string_append_len(buffer, line, (gssize) (out-line));
1871
1907
          out= line;
1872
1908
        }
1873
1909
 
1891
1927
            for (pos++ ;
1892
1928
                 *pos && (*pos != *delimiter ||
1893
1929
                          !is_prefix(pos + 1, delimiter + 1)) ; pos++)
1894
 
              ;  // Remove parameters
 
1930
              ; // Remove parameters
1895
1931
            if (!*pos)
1896
1932
              pos--;
1897
1933
            else
1901
1937
      }
1902
1938
      else
1903
1939
      {
1904
 
        sprintf(buff,_("Unknown command '\\%c'."),inchar);
 
1940
        sprintf(buff,"Unknown command '\\%c'.",inchar);
1905
1941
        if (put_info(buff,INFO_ERROR,0,0) > 0)
1906
1942
          return(1);
1907
1943
        *out++='\\';
1917
1953
      // Flush previously accepted characters
1918
1954
      if (out != line)
1919
1955
      {
1920
 
        buffer->append(line, (out - line));
 
1956
        g_string_append_len(buffer, line, (gssize) (out - line));
1921
1957
        out= line;
1922
1958
      }
1923
1959
 
1924
1960
      // Flush possible comments in the buffer
1925
 
      if (!buffer->empty())
 
1961
      if (buffer->len != 0)
1926
1962
      {
1927
1963
        if (com_go(buffer, 0) > 0) // < 0 is not fatal
1928
1964
          return(1);
1929
1965
        assert(buffer!=NULL);
1930
 
        buffer->clear();
 
1966
        g_string_truncate(buffer,0);
1931
1967
      }
1932
1968
 
1933
1969
      /*
1934
1970
        Delimiter wants the get rest of the given line as argument to
1935
1971
        allow one to change ';' to ';;' and back
1936
1972
      */
1937
 
      buffer->append(pos);
 
1973
      g_string_append(buffer,pos);
1938
1974
      if (com_delimiter(buffer, pos) > 0)
1939
1975
        return(1);
1940
1976
 
1941
 
      buffer->clear();
 
1977
      g_string_truncate(buffer,0);
1942
1978
      break;
1943
1979
    }
1944
1980
    else if (!*ml_comment && !*in_string && is_prefix(pos, delimiter))
1954
1990
      // Flush previously accepted characters
1955
1991
      if (out != line)
1956
1992
      {
1957
 
        buffer->append(line, (out-line));
 
1993
        g_string_append_len(buffer, line, (gssize) (out-line));
1958
1994
        out= line;
1959
1995
      }
1960
1996
 
1964
2000
                                 my_isspace(charset_info, pos[2]))))
1965
2001
      {
1966
2002
        // Add trailing single line comments to this statement
1967
 
        buffer->append(pos);
 
2003
        g_string_append(buffer, pos);
1968
2004
        pos+= strlen(pos);
1969
2005
      }
1970
2006
 
1971
2007
      pos--;
1972
2008
 
1973
 
      if ((com= find_command(buffer->c_str(), 0)))
 
2009
      if ((com= find_command(buffer->str, 0)))
1974
2010
      {
1975
2011
 
1976
 
        if ((*com->func)(buffer, buffer->c_str()) > 0)
 
2012
        if ((*com->func)(buffer, buffer->str) > 0)
1977
2013
          return(1);                       // Quit
1978
2014
      }
1979
2015
      else
1981
2017
        if (com_go(buffer, 0) > 0)             // < 0 is not fatal
1982
2018
          return(1);
1983
2019
      }
1984
 
      buffer->clear();
 
2020
      g_string_truncate(buffer,0);
1985
2021
    }
1986
2022
    else if (!*ml_comment
1987
2023
             && (!*in_string
1993
2029
      // Flush previously accepted characters
1994
2030
      if (out != line)
1995
2031
      {
1996
 
        buffer->append(line, (out - line));
 
2032
        g_string_append_len(buffer, line, (gssize) (out - line));
1997
2033
        out= line;
1998
2034
      }
1999
2035
 
2000
2036
      // comment to end of line
2001
2037
      if (preserve_comments)
2002
 
        buffer->append(pos);
 
2038
        g_string_append(buffer,pos);
2003
2039
 
2004
2040
      break;
2005
2041
    }
2016
2052
      *ml_comment= 1;
2017
2053
      if (out != line)
2018
2054
      {
2019
 
        buffer->append(line, (out-line));
 
2055
        g_string_append_len(buffer, line, (gssize) (out-line));
2020
2056
        out=line;
2021
2057
      }
2022
2058
    }
2032
2068
      *ml_comment= 0;
2033
2069
      if (out != line)
2034
2070
      {
2035
 
        buffer->append(line, (out - line));
 
2071
        g_string_append_len(buffer, line, (gssize) (out - line));
2036
2072
        out= line;
2037
2073
      }
2038
2074
      // Consumed a 2 chars or more, and will add 1 at most,
2061
2097
      }
2062
2098
    }
2063
2099
  }
2064
 
  if (out != line || (buffer->length() > 0))
 
2100
  if (out != line || (buffer->len > 0))
2065
2101
  {
2066
2102
    *out++='\n';
2067
2103
    uint length=(uint) (out-line);
2068
 
    if ((!*ml_comment || preserve_comments))
2069
 
      buffer->append(line, length);
 
2104
    if ((!*ml_comment || preserve_comments)
 
2105
        && (g_string_append_len(buffer, line, length) == NULL))
 
2106
      return(1);
2070
2107
  }
2071
2108
  return(0);
2072
2109
}
2076
2113
******************************************************************/
2077
2114
 
2078
2115
 
2079
 
static char **mysql_completion (const char *text, int start, int end);
2080
2116
static char *new_command_generator(const char *text, int);
 
2117
extern char **new_mysql_completion (const char *text, int start, int end);
2081
2118
 
2082
2119
/*
2083
2120
  Tell the GNU Readline library how to complete.  We want to try to complete
2084
2121
  on command names if this is the first word in the line, or on filenames
2085
2122
  if not.
2086
2123
*/
2087
 
static char *no_completion(const char * a __attribute__((unused)),
2088
 
                           int b __attribute__((unused)))
 
2124
 
 
2125
#if defined(USE_NEW_READLINE_INTERFACE) || defined(USE_LIBEDIT_INTERFACE)
 
2126
extern char *no_completion(const char*,int);
 
2127
#else
 
2128
char *no_completion(void);
 
2129
char *no_completion(void)
2089
2130
{
2090
2131
  /* No filename completion */
2091
2132
  return 0;
2092
2133
}
2093
 
 
 
2134
#endif
2094
2135
 
2095
2136
/* glues pieces of history back together if in pieces   */
2096
 
static void fix_history(string *final_command)
 
2137
static void fix_history(GString *final_command)
2097
2138
{
2098
2139
  int total_lines = 1;
2099
 
  const char *ptr = final_command->c_str();
 
2140
  const char *ptr = final_command->str;
 
2141
  /* Converted buffer */
 
2142
  GString * fixed_buffer;
 
2143
  fixed_buffer = g_string_sized_new(16);
2100
2144
  char str_char = '\0';  /* Character if we are in a string or not */
2101
2145
 
2102
 
  /* Converted buffer */
2103
 
  string fixed_buffer;
2104
 
  fixed_buffer.reserve(512);
2105
 
 
2106
2146
  /* find out how many lines we have and remove newlines */
2107
2147
  while (*ptr != '\0')
2108
2148
  {
2116
2156
        str_char = *ptr;
2117
2157
      else if (str_char == *ptr)   /* close string */
2118
2158
        str_char = '\0';
2119
 
      fixed_buffer.append(ptr, 1);
 
2159
      g_string_append_len(fixed_buffer, ptr, 1);
2120
2160
      break;
2121
2161
    case '\n':
2122
2162
      /*
2123
2163
        not in string, change to space
2124
2164
        if in string, leave it alone
2125
2165
      */
2126
 
      fixed_buffer.append((str_char == '\0') ? " " : "\n");
 
2166
      g_string_append(fixed_buffer,(str_char == '\0') ? " " : "\n");
2127
2167
      total_lines++;
2128
2168
      break;
2129
2169
    case '\\':
2130
 
      fixed_buffer.append("\\");
 
2170
      g_string_append_c(fixed_buffer, '\\');
2131
2171
      /* need to see if the backslash is escaping anything */
2132
2172
      if (str_char)
2133
2173
      {
2134
2174
        ptr++;
2135
2175
        /* special characters that need escaping */
2136
2176
        if (*ptr == '\'' || *ptr == '"' || *ptr == '\\')
2137
 
          fixed_buffer.append(ptr, 1);
 
2177
          g_string_append_len(fixed_buffer, ptr, 1);
2138
2178
        else
2139
2179
          ptr--;
2140
2180
      }
2141
2181
      break;
2142
2182
    default:
2143
 
      fixed_buffer.append(ptr, 1);
 
2183
      g_string_append_len(fixed_buffer, ptr, 1);
2144
2184
    }
2145
2185
    ptr++;
2146
2186
  }
2147
2187
  if (total_lines > 1)
2148
 
    add_history(fixed_buffer.c_str());
 
2188
    add_history(fixed_buffer->str);
2149
2189
}
2150
2190
 
2151
2191
/*
2163
2203
  return 1;
2164
2204
}
2165
2205
 
2166
 
static void initialize_readline (char *name)
 
2206
static void initialize_readline (const char *name)
2167
2207
{
2168
2208
  /* Allow conditional parsing of the ~/.inputrc file. */
2169
2209
  rl_readline_name= name;
2170
2210
 
2171
2211
  /* Tell the completer that we want a crack first. */
2172
 
  rl_attempted_completion_function= (rl_completion_func_t*)&mysql_completion;
 
2212
  rl_attempted_completion_function= (rl_completion_func_t*)&new_mysql_completion;
2173
2213
  rl_completion_entry_function= (rl_compentry_func_t*)&no_completion;
2174
2214
}
2175
2215
 
2176
 
 
2177
2216
/*
2178
2217
  Attempt to complete on the contents of TEXT.  START and END show the
2179
2218
  region of TEXT that contains the word to complete.  We can use the
2180
2219
  entire line in case we want to do some simple parsing.  Return the
2181
2220
  array of matches, or NULL if there aren't any.
2182
2221
*/
2183
 
char **mysql_completion (const char *text,
2184
 
                        int start __attribute__((unused)),
2185
 
                        int end __attribute__((unused)))
 
2222
 
 
2223
char **new_mysql_completion (const char *text,
 
2224
                             int start __attribute__((unused)),
 
2225
                             int end __attribute__((unused)))
2186
2226
{
2187
2227
  if (!status.batch && !quick)
2188
2228
    return rl_completion_matches(text, new_command_generator);
2190
2230
    return (char**) 0;
2191
2231
}
2192
2232
 
2193
 
 
2194
2233
static char *new_command_generator(const char *text,int state)
2195
2234
{
2196
2235
  static int textlen;
2203
2242
    textlen=(uint) strlen(text);
2204
2243
 
2205
2244
  if (textlen>0)
2206
 
  {            /* lookup in the hash */
 
2245
  {                                             /* lookup in the hash */
2207
2246
    if (!state)
2208
2247
    {
2209
2248
      uint len;
2216
2255
 
2217
2256
    if (e)
2218
2257
    {
2219
 
      ptr= strdup(e->str);
 
2258
      ptr= g_strdup(e->str);
2220
2259
      e = e->pNext;
2221
2260
      return ptr;
2222
2261
    }
2239
2278
    }
2240
2279
    ptr= NullS;
2241
2280
    while (e && !ptr)
2242
 
    {          /* find valid entry in bucket */
 
2281
    {                                   /* find valid entry in bucket */
2243
2282
      if ((uint) strlen(e->str) == b->nKeyLength)
2244
 
        ptr = strdup(e->str);
 
2283
        ptr = g_strdup(e->str);
2245
2284
      /* find the next used entry */
2246
2285
      e = e->pNext;
2247
2286
      if (!e)
2275
2314
static void build_completion_hash(bool rehash, bool write_info)
2276
2315
{
2277
2316
  COMMANDS *cmd=commands;
2278
 
  DRIZZLE_RES *databases=0,*tables=0;
2279
 
  DRIZZLE_RES *fields;
 
2317
  MYSQL_RES *databases=0,*tables=0;
 
2318
  MYSQL_RES *fields;
2280
2319
  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
 
2320
  MYSQL_ROW database_row,table_row;
 
2321
  MYSQL_FIELD *sql_field;
 
2322
  char buf[NAME_LEN*2+2];                // table name plus field name plus 2
2284
2323
  int i,j,num_fields;
2285
2324
 
2286
2325
 
2287
2326
  if (status.batch || quick || !current_db)
2288
 
    return;      // We don't need completion in batches
 
2327
    return;                     // We don't need completion in batches
2289
2328
  if (!rehash)
2290
2329
    return;
2291
2330
 
2304
2343
  /* hash Drizzle functions (to be implemented) */
2305
2344
 
2306
2345
  /* hash all database names */
2307
 
  if (drizzle_query(&drizzle,"show databases") == 0)
 
2346
  if (mysql_query(&mysql,"show databases") == 0)
2308
2347
  {
2309
 
    if (!(databases = drizzle_store_result(&drizzle)))
2310
 
      put_info(drizzle_error(&drizzle),INFO_INFO,0,0);
 
2348
    if (!(databases = mysql_store_result(&mysql)))
 
2349
      put_info(mysql_error(&mysql),INFO_INFO,0,0);
2311
2350
    else
2312
2351
    {
2313
 
      while ((database_row=drizzle_fetch_row(databases)))
 
2352
      while ((database_row=mysql_fetch_row(databases)))
2314
2353
      {
2315
2354
        char *str=strdup_root(&hash_mem_root, (char*) database_row[0]);
2316
2355
        if (str)
2317
2356
          add_word(&ht,(char*) str);
2318
2357
      }
2319
 
      drizzle_free_result(databases);
 
2358
      mysql_free_result(databases);
2320
2359
    }
2321
2360
  }
2322
2361
  /* hash all table names */
2323
 
  if (drizzle_query(&drizzle,"show tables")==0)
 
2362
  if (mysql_query(&mysql,"show tables")==0)
2324
2363
  {
2325
 
    if (!(tables = drizzle_store_result(&drizzle)))
2326
 
      put_info(drizzle_error(&drizzle),INFO_INFO,0,0);
 
2364
    if (!(tables = mysql_store_result(&mysql)))
 
2365
      put_info(mysql_error(&mysql),INFO_INFO,0,0);
2327
2366
    else
2328
2367
    {
2329
 
      if (drizzle_num_rows(tables) > 0 && !opt_silent && write_info)
 
2368
      if (mysql_num_rows(tables) > 0 && !opt_silent && write_info)
2330
2369
      {
2331
 
        tee_fprintf(stdout, _("\
 
2370
        tee_fprintf(stdout, "\
2332
2371
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"));
 
2372
You can turn off this feature to get a quicker startup with -A\n\n");
2334
2373
      }
2335
 
      while ((table_row=drizzle_fetch_row(tables)))
 
2374
      while ((table_row=mysql_fetch_row(tables)))
2336
2375
      {
2337
2376
        char *str=strdup_root(&hash_mem_root, (char*) table_row[0]);
2338
2377
        if (str &&
2343
2382
  }
2344
2383
 
2345
2384
  /* hash all field names, both with the table prefix and without it */
2346
 
  if (!tables)          /* no tables */
 
2385
  if (!tables)                                  /* no tables */
2347
2386
  {
2348
2387
    return;
2349
2388
  }
2350
 
  drizzle_data_seek(tables,0);
 
2389
  mysql_data_seek(tables,0);
2351
2390
  if (!(field_names= (char ***) alloc_root(&hash_mem_root,sizeof(char **) *
2352
 
                                           (uint) (drizzle_num_rows(tables)+1))))
 
2391
                                           (uint) (mysql_num_rows(tables)+1))))
2353
2392
  {
2354
 
    drizzle_free_result(tables);
 
2393
    mysql_free_result(tables);
2355
2394
    return;
2356
2395
  }
2357
2396
  i=0;
2358
 
  while ((table_row=drizzle_fetch_row(tables)))
 
2397
  while ((table_row=mysql_fetch_row(tables)))
2359
2398
  {
2360
 
    if ((fields=drizzle_list_fields(&drizzle,(const char*) table_row[0],NullS)))
 
2399
    if ((fields=mysql_list_fields(&mysql,(const char*) table_row[0],NullS)))
2361
2400
    {
2362
 
      num_fields=drizzle_num_fields(fields);
 
2401
      num_fields=mysql_num_fields(fields);
2363
2402
      if (!(field_names[i] = (char **) alloc_root(&hash_mem_root,
2364
2403
                                                  sizeof(char *) *
2365
2404
                                                  (num_fields*2+1))))
2366
2405
      {
2367
 
        drizzle_free_result(fields);
 
2406
        mysql_free_result(fields);
2368
2407
        break;
2369
2408
      }
2370
2409
      field_names[i][num_fields*2]= '\0';
2371
2410
      j=0;
2372
 
      while ((sql_field=drizzle_fetch_field(fields)))
 
2411
      while ((sql_field=mysql_fetch_field(fields)))
2373
2412
      {
2374
2413
        sprintf(buf,"%.64s.%.64s",table_row[0],sql_field->name);
2375
2414
        field_names[i][j] = strdup_root(&hash_mem_root,buf);
2381
2420
          add_word(&ht,field_names[i][num_fields+j]);
2382
2421
        j++;
2383
2422
      }
2384
 
      drizzle_free_result(fields);
 
2423
      mysql_free_result(fields);
2385
2424
    }
2386
2425
    else
2387
2426
      field_names[i]= 0;
2388
2427
 
2389
2428
    i++;
2390
2429
  }
2391
 
  drizzle_free_result(tables);
2392
 
  field_names[i]=0;        // End pointer
 
2430
  mysql_free_result(tables);
 
2431
  field_names[i]=0;                             // End pointer
2393
2432
  return;
2394
2433
}
2395
2434
 
2425
2464
  /* purecov: begin tested */
2426
2465
  if (opt_reconnect)
2427
2466
  {
2428
 
    put_info(_("No connection. Trying to reconnect..."),INFO_INFO,0,0);
2429
 
    (void) com_connect((string *)0, 0);
 
2467
    put_info("No connection. Trying to reconnect...",INFO_INFO,0,0);
 
2468
    (void) com_connect((GString *) 0, 0);
2430
2469
    if (opt_rehash)
2431
2470
      com_rehash(NULL, NULL);
2432
2471
  }
2433
2472
  if (!connected)
2434
 
    return put_info(_("Can't connect to the server\n"),INFO_ERROR,0,0);
 
2473
    return put_info("Can't connect to the server\n",INFO_ERROR,0,0);
2435
2474
  /* purecov: end */
2436
2475
  return 0;
2437
2476
}
2438
2477
 
2439
2478
static void get_current_db(void)
2440
2479
{
2441
 
  DRIZZLE_RES *res;
 
2480
  MYSQL_RES *res;
2442
2481
 
2443
2482
  my_free(current_db, MYF(MY_ALLOW_ZERO_PTR));
2444
2483
  current_db= NULL;
2445
2484
  /* In case of error below current_db will be NULL */
2446
 
  if (!drizzle_query(&drizzle, "SELECT DATABASE()") &&
2447
 
      (res= drizzle_use_result(&drizzle)))
 
2485
  if (!mysql_query(&mysql, "SELECT DATABASE()") &&
 
2486
      (res= mysql_use_result(&mysql)))
2448
2487
  {
2449
 
    DRIZZLE_ROW row= drizzle_fetch_row(res);
 
2488
    MYSQL_ROW row= mysql_fetch_row(res);
2450
2489
    if (row[0])
2451
 
      current_db= strdup(row[0]);
2452
 
    drizzle_free_result(res);
 
2490
      current_db= g_strdup(row[0]);
 
2491
    mysql_free_result(res);
2453
2492
  }
2454
2493
}
2455
2494
 
2457
2496
 The different commands
2458
2497
***************************************************************************/
2459
2498
 
2460
 
int drizzle_real_query_for_lazy(const char *buf, int length)
 
2499
int mysql_real_query_for_lazy(const char *buf, int length)
2461
2500
{
2462
2501
  for (uint retry=0;; retry++)
2463
2502
  {
2464
2503
    int error;
2465
 
    if (!drizzle_real_query(&drizzle,buf,length))
 
2504
    if (!mysql_real_query(&mysql,buf,length))
2466
2505
      return 0;
2467
 
    error= put_error(&drizzle);
2468
 
    if (drizzle_errno(&drizzle) != CR_SERVER_GONE_ERROR || retry > 1 ||
 
2506
    error= put_error(&mysql);
 
2507
    if (mysql_errno(&mysql) != CR_SERVER_GONE_ERROR || retry > 1 ||
2469
2508
        !opt_reconnect)
2470
2509
      return error;
2471
2510
    if (reconnect())
2473
2512
  }
2474
2513
}
2475
2514
 
2476
 
int drizzle_store_result_for_lazy(DRIZZLE_RES **result)
 
2515
int mysql_store_result_for_lazy(MYSQL_RES **result)
2477
2516
{
2478
 
  if ((*result=drizzle_store_result(&drizzle)))
 
2517
  if ((*result=mysql_store_result(&mysql)))
2479
2518
    return 0;
2480
2519
 
2481
 
  if (drizzle_error(&drizzle)[0])
2482
 
    return put_error(&drizzle);
 
2520
  if (mysql_error(&mysql)[0])
 
2521
    return put_error(&mysql);
2483
2522
  return 0;
2484
2523
}
2485
2524
 
2486
 
static void print_help_item(DRIZZLE_ROW *cur, int num_name, int num_cat, char *last_char)
 
2525
static void print_help_item(MYSQL_ROW *cur, int num_name, int num_cat, char *last_char)
2487
2526
{
2488
2527
  char ccat= (*cur)[num_cat][0];
2489
2528
  if (*last_char != ccat)
2490
2529
  {
2491
 
    put_info(ccat == 'Y' ? _("categories:") : _("topics:"), INFO_INFO,0,0);
 
2530
    put_info(ccat == 'Y' ? "categories:" : "topics:", INFO_INFO,0,0);
2492
2531
    *last_char= ccat;
2493
2532
  }
2494
2533
  tee_fprintf(PAGER, "   %s\n", (*cur)[num_name]);
2495
2534
}
2496
2535
 
2497
2536
 
2498
 
static int com_server_help(string *buffer,
2499
 
                           const char *line __attribute__((unused)),
 
2537
static int com_server_help(GString *buffer,
 
2538
                           char *line __attribute__((unused)),
2500
2539
                           char *help_arg)
2501
2540
{
2502
 
  DRIZZLE_ROW cur;
2503
 
  const char *server_cmd= buffer->c_str();
 
2541
  MYSQL_ROW cur;
 
2542
  const char *server_cmd= buffer->str;
2504
2543
  char cmd_buf[100];
2505
 
  DRIZZLE_RES *result;
 
2544
  MYSQL_RES *result;
2506
2545
  int error;
2507
2546
 
2508
2547
  if (help_arg[0] != '\'')
2509
2548
  {
2510
 
    char *end_arg= strchr(help_arg, '\0');
 
2549
    char *end_arg= strend(help_arg);
2511
2550
    if(--end_arg)
2512
2551
    {
2513
2552
      while (my_isspace(charset_info,*end_arg))
2521
2560
  if (!connected && reconnect())
2522
2561
    return 1;
2523
2562
 
2524
 
  if ((error= drizzle_real_query_for_lazy(server_cmd,(int)strlen(server_cmd))) ||
2525
 
      (error= drizzle_store_result_for_lazy(&result)))
 
2563
  if ((error= mysql_real_query_for_lazy(server_cmd,(int)strlen(server_cmd))) ||
 
2564
      (error= mysql_store_result_for_lazy(&result)))
2526
2565
    return error;
2527
2566
 
2528
2567
  if (result)
2529
2568
  {
2530
 
    unsigned int num_fields= drizzle_num_fields(result);
2531
 
    uint64_t num_rows= drizzle_num_rows(result);
2532
 
    drizzle_fetch_fields(result);
 
2569
    unsigned int num_fields= mysql_num_fields(result);
 
2570
    uint64_t num_rows= mysql_num_rows(result);
 
2571
    mysql_fetch_fields(result);
2533
2572
    if (num_fields==3 && num_rows==1)
2534
2573
    {
2535
 
      if (!(cur= drizzle_fetch_row(result)))
 
2574
      if (!(cur= mysql_fetch_row(result)))
2536
2575
      {
2537
2576
        error= -1;
2538
2577
        goto err;
2539
2578
      }
2540
2579
 
2541
2580
      init_pager();
2542
 
      tee_fprintf(PAGER,   _("Name: \'%s\'\n"), cur[0]);
2543
 
      tee_fprintf(PAGER,   _("Description:\n%s"), cur[1]);
 
2581
      tee_fprintf(PAGER,   "Name: \'%s\'\n", cur[0]);
 
2582
      tee_fprintf(PAGER,   "Description:\n%s", cur[1]);
2544
2583
      if (cur[2] && *((char*)cur[2]))
2545
 
        tee_fprintf(PAGER, _("Examples:\n%s"), cur[2]);
 
2584
        tee_fprintf(PAGER, "Examples:\n%s", cur[2]);
2546
2585
      tee_fprintf(PAGER,   "\n");
2547
2586
      end_pager();
2548
2587
    }
2555
2594
 
2556
2595
      if (num_fields == 2)
2557
2596
      {
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);
 
2597
        put_info("Many help items for your request exist.", INFO_INFO,0,0);
 
2598
        put_info("To make a more specific request, please type 'help <item>',\nwhere <item> is one of the following", INFO_INFO,0,0);
2560
2599
        num_name= 0;
2561
2600
        num_cat= 1;
2562
2601
      }
2563
 
      else if ((cur= drizzle_fetch_row(result)))
 
2602
      else if ((cur= mysql_fetch_row(result)))
2564
2603
      {
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);
 
2604
        tee_fprintf(PAGER, "You asked for help about help category: \"%s\"\n", cur[0]);
 
2605
        put_info("For more information, type 'help <item>', where <item> is one of the following", INFO_INFO,0,0);
2567
2606
        num_name= 1;
2568
2607
        num_cat= 2;
2569
2608
        print_help_item(&cur,1,2,&last_char);
2570
2609
      }
2571
2610
 
2572
 
      while ((cur= drizzle_fetch_row(result)))
 
2611
      while ((cur= mysql_fetch_row(result)))
2573
2612
        print_help_item(&cur,num_name,num_cat,&last_char);
2574
2613
      tee_fprintf(PAGER, "\n");
2575
2614
      end_pager();
2576
2615
    }
2577
2616
    else
2578
2617
    {
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);
 
2618
      put_info("\nNothing found", INFO_INFO,0,0);
 
2619
      put_info("Please try to run 'help contents' for a list of all accessible topics\n", INFO_INFO,0,0);
2581
2620
    }
2582
2621
  }
2583
2622
 
2584
2623
err:
2585
 
  drizzle_free_result(result);
 
2624
  mysql_free_result(result);
2586
2625
  return error;
2587
2626
}
2588
2627
 
2589
2628
static int
2590
 
com_help(string *buffer __attribute__((unused)),
2591
 
         const char *line __attribute__((unused)))
 
2629
com_help(GString *buffer __attribute__((unused)),
 
2630
         char *line __attribute__((unused)))
2592
2631
{
2593
2632
  register int i, j;
2594
2633
  char * help_arg= strchr(line,' '), buff[32], *end;
2596
2635
  {
2597
2636
    while (my_isspace(charset_info,*help_arg))
2598
2637
      help_arg++;
2599
 
    if (*help_arg) return com_server_help(buffer,line,help_arg);
 
2638
    if (*help_arg)
 
2639
      return com_server_help(buffer,line,help_arg);
2600
2640
  }
2601
2641
 
2602
 
  put_info(_("List of all Drizzle commands:"), INFO_INFO,0,0);
 
2642
  put_info("List of all Drizzle commands:", INFO_INFO,0,0);
2603
2643
  if (!named_cmds)
2604
 
    put_info(_("Note that all text commands must be first on line and end with ';'"),INFO_INFO,0,0);
 
2644
    put_info("Note that all text commands must be first on line and end with ';'",INFO_INFO,0,0);
2605
2645
  for (i = 0; commands[i].name; i++)
2606
2646
  {
2607
 
    end= stpcpy(buff, commands[i].name);
 
2647
    end= strmov(buff, commands[i].name);
2608
2648
    for (j= (int)strlen(commands[i].name); j < 10; j++)
2609
 
      end= stpcpy(end, " ");
 
2649
      end= strmov(end, " ");
2610
2650
    if (commands[i].func)
2611
2651
      tee_fprintf(stdout, "%s(\\%c) %s\n", buff,
2612
 
                  commands[i].cmd_char, _(commands[i].doc));
 
2652
                  commands[i].cmd_char, commands[i].doc);
2613
2653
  }
2614
 
  if (connected && drizzle_get_server_version(&drizzle) >= 40100)
2615
 
    put_info(_("\nFor server side help, type 'help contents'\n"), INFO_INFO,0,0);
 
2654
  if (connected && mysql_get_server_version(&mysql) >= 40100)
 
2655
    put_info("\nFor server side help, type 'help contents'\n", INFO_INFO,0,0);
2616
2656
  return 0;
2617
2657
}
2618
2658
 
2619
2659
 
2620
2660
static int
2621
 
com_clear(string *buffer,
2622
 
          const char *line __attribute__((unused)))
 
2661
com_clear(GString *buffer,char *line __attribute__((unused)))
2623
2662
{
2624
2663
  if (status.add_to_history)
2625
2664
    fix_history(buffer);
2626
 
  buffer->clear();
 
2665
  g_string_truncate(buffer, 0);
2627
2666
  return 0;
2628
2667
}
2629
2668
 
 
2669
static int
 
2670
com_charset(GString *buffer __attribute__((unused)), char *line)
 
2671
{
 
2672
  char buff[256], *param;
 
2673
  CHARSET_INFO * new_cs;
 
2674
  strmake(buff, line, sizeof(buff) - 1);
 
2675
  param= get_arg(buff, 0);
 
2676
  if (!param || !*param)
 
2677
  {
 
2678
    return put_info("Usage: \\C char_setname | charset charset_name",
 
2679
                    INFO_ERROR, 0, 0);
 
2680
  }
 
2681
  new_cs= get_charset_by_csname(param, MY_CS_PRIMARY, MYF(MY_WME));
 
2682
  if (new_cs)
 
2683
  {
 
2684
    charset_info= new_cs;
 
2685
    mysql_set_character_set(&mysql, charset_info->csname);
 
2686
    default_charset= (char *)charset_info->csname;
 
2687
    default_charset_used= 1;
 
2688
    put_info("Charset changed", INFO_INFO,0,0);
 
2689
  }
 
2690
  else put_info("Charset is not found", INFO_INFO,0,0);
 
2691
  return 0;
 
2692
}
2630
2693
 
2631
2694
/*
2632
2695
  Execute command
2635
2698
  1  if fatal error
2636
2699
*/
2637
2700
static int
2638
 
com_go(string *buffer,
2639
 
       const char *line __attribute__((unused)))
 
2701
com_go(GString *buffer,
 
2702
       char *line __attribute__((unused)))
2640
2703
{
2641
2704
  char          buff[200]; /* about 110 chars used so far */
2642
2705
  char          time_buff[52+3+1]; /* time max + space&parens + NUL */
2643
 
  DRIZZLE_RES     *result;
2644
 
  uint32_t         timer, warnings= 0;
 
2706
  MYSQL_RES     *result;
 
2707
  ulong         timer, warnings= 0;
2645
2708
  uint          error= 0;
2646
2709
  int           err= 0;
2647
2710
 
2650
2713
  /* Remove garbage for nicer messages */
2651
2714
  remove_cntrl(buffer);
2652
2715
 
2653
 
  if (buffer->empty())
 
2716
  if (buffer->len == 0)
2654
2717
  {
2655
2718
    // Ignore empty quries
2656
2719
    if (status.batch)
2657
2720
      return 0;
2658
 
    return put_info(_("No query specified\n"),INFO_ERROR,0,0);
 
2721
    return put_info("No query specified\n",INFO_ERROR,0,0);
2659
2722
 
2660
2723
  }
2661
2724
  if (!connected && reconnect())
2662
2725
  {
2663
2726
    // Remove query on error
2664
 
    buffer->clear();
 
2727
    g_string_truncate(buffer, 0);
2665
2728
    return opt_reconnect ? -1 : 1;          // Fatal error
2666
2729
  }
2667
2730
  if (verbose)
2668
2731
    (void) com_print(buffer, 0);
2669
2732
 
2670
2733
  if (skip_updates &&
2671
 
      ((buffer->length() < 4) || (buffer->find( "SET ") != 0)))
 
2734
      ((buffer->len < 4)
 
2735
      || g_string_equal(g_string_new_len(buffer->str,4),
 
2736
                        g_string_new("SET "))))
2672
2737
  {
2673
 
    (void) put_info(_("Ignoring query to other database"),INFO_INFO,0,0);
 
2738
    (void) put_info("Ignoring query to other database",INFO_INFO,0,0);
2674
2739
    return 0;
2675
2740
  }
2676
2741
 
2677
2742
  timer=start_timer();
2678
2743
  executing_query= 1;
2679
 
  error= drizzle_real_query_for_lazy(buffer->c_str(),buffer->length());
 
2744
  error= mysql_real_query_for_lazy(buffer->str,buffer->len);
2680
2745
 
2681
2746
  if (status.add_to_history)
2682
2747
  {
2683
 
    buffer->append(vertical ? "\\G" : delimiter);
 
2748
    g_string_append(buffer, vertical ? "\\G" : delimiter);
2684
2749
    /* Append final command onto history */
2685
2750
    fix_history(buffer);
2686
2751
  }
2687
2752
 
2688
 
  buffer->clear();
 
2753
  g_string_truncate(buffer, 0);
2689
2754
 
2690
2755
  if (error)
2691
2756
    goto end;
2696
2761
 
2697
2762
    if (quick)
2698
2763
    {
2699
 
      if (!(result=drizzle_use_result(&drizzle)) && drizzle_field_count(&drizzle))
 
2764
      if (!(result=mysql_use_result(&mysql)) && mysql_field_count(&mysql))
2700
2765
      {
2701
 
        error= put_error(&drizzle);
 
2766
        error= put_error(&mysql);
2702
2767
        goto end;
2703
2768
      }
2704
2769
    }
2705
2770
    else
2706
2771
    {
2707
 
      error= drizzle_store_result_for_lazy(&result);
 
2772
      error= mysql_store_result_for_lazy(&result);
2708
2773
      if (error)
2709
2774
        goto end;
2710
2775
    }
2711
2776
 
2712
2777
    if (verbose >= 3 || !opt_silent)
2713
 
      drizzle_end_timer(timer,time_buff);
 
2778
      mysql_end_timer(timer,time_buff);
2714
2779
    else
2715
2780
      time_buff[0]= '\0';
2716
2781
 
2717
2782
    /* Every branch must truncate  buff . */
2718
2783
    if (result)
2719
2784
    {
2720
 
      if (!drizzle_num_rows(result) && ! quick && !column_types_flag)
 
2785
      if (!mysql_num_rows(result) && ! quick && !column_types_flag)
2721
2786
      {
2722
 
        stpcpy(buff, _("Empty set"));
 
2787
        strmov(buff, "Empty set");
 
2788
        if (opt_xml)
 
2789
        {
 
2790
          /*
 
2791
            We must print XML header and footer
 
2792
            to produce a well-formed XML even if
 
2793
            the result set is empty (Bug#27608).
 
2794
          */
 
2795
          init_pager();
 
2796
          print_table_data_xml(result);
 
2797
          end_pager();
 
2798
        }
2723
2799
      }
2724
2800
      else
2725
2801
      {
2726
2802
        init_pager();
2727
 
        if (vertical || (auto_vertical_output &&
2728
 
                         (terminal_width < get_result_width(result))))
 
2803
        if (opt_html)
 
2804
          print_table_data_html(result);
 
2805
        else if (opt_xml)
 
2806
          print_table_data_xml(result);
 
2807
        else if (vertical || (auto_vertical_output && (terminal_width < get_result_width(result))))
2729
2808
          print_table_data_vertically(result);
2730
2809
        else if (opt_silent && verbose <= 2 && !output_tables)
2731
2810
          print_tab_data(result);
2732
2811
        else
2733
2812
          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));
 
2813
        sprintf(buff,"%ld %s in set",
 
2814
                (long) mysql_num_rows(result),
 
2815
                (long) mysql_num_rows(result) == 1 ? "row" : "rows");
2738
2816
        end_pager();
2739
 
        if (drizzle_errno(&drizzle))
2740
 
          error= put_error(&drizzle);
 
2817
        if (mysql_errno(&mysql))
 
2818
          error= put_error(&mysql);
2741
2819
      }
2742
2820
    }
2743
 
    else if (drizzle_affected_rows(&drizzle) == ~(uint64_t) 0)
2744
 
      stpcpy(buff,_("Query OK"));
 
2821
    else if (mysql_affected_rows(&mysql) == ~(uint64_t) 0)
 
2822
      strmov(buff,"Query OK");
2745
2823
    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));
 
2824
      sprintf(buff,"Query OK, %ld %s affected",
 
2825
              (long) mysql_affected_rows(&mysql),
 
2826
              (long) mysql_affected_rows(&mysql) == 1 ? "row" : "rows");
2750
2827
 
2751
 
    pos= strchr(buff, '\0');
2752
 
    if ((warnings= drizzle_warning_count(&drizzle)))
 
2828
    pos=strend(buff);
 
2829
    if ((warnings= mysql_warning_count(&mysql)))
2753
2830
    {
2754
2831
      *pos++= ',';
2755
2832
      *pos++= ' ';
2756
2833
      pos=int10_to_str(warnings, pos, 10);
2757
 
      pos=stpcpy(pos, " warning");
 
2834
      pos=strmov(pos, " warning");
2758
2835
      if (warnings != 1)
2759
2836
        *pos++= 's';
2760
2837
    }
2761
 
    stpcpy(pos, time_buff);
 
2838
    strmov(pos, time_buff);
2762
2839
    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
 
2840
    if (mysql_info(&mysql))
 
2841
      put_info(mysql_info(&mysql),INFO_RESULT,0,0);
 
2842
    put_info("",INFO_RESULT,0,0);                       // Empty row
2766
2843
 
2767
 
    if (result && !drizzle_eof(result))  /* Something wrong when using quick */
2768
 
      error= put_error(&drizzle);
 
2844
    if (result && !mysql_eof(result))   /* Something wrong when using quick */
 
2845
      error= put_error(&mysql);
2769
2846
    else if (unbuffered)
2770
2847
      fflush(stdout);
2771
 
    drizzle_free_result(result);
2772
 
  } while (!(err= drizzle_next_result(&drizzle)));
 
2848
    mysql_free_result(result);
 
2849
  } while (!(err= mysql_next_result(&mysql)));
2773
2850
  if (err >= 1)
2774
 
    error= put_error(&drizzle);
 
2851
    error= put_error(&mysql);
2775
2852
 
2776
2853
end:
2777
2854
 
2780
2857
    print_warnings();
2781
2858
 
2782
2859
  if (!error && !status.batch &&
2783
 
      (drizzle.server_status & SERVER_STATUS_DB_DROPPED))
 
2860
      (mysql.server_status & SERVER_STATUS_DB_DROPPED))
2784
2861
    get_current_db();
2785
2862
 
2786
2863
  executing_query= 0;
2787
 
  return error;        /* New command follows */
 
2864
  return error;                         /* New command follows */
2788
2865
}
2789
2866
 
2790
2867
 
2837
2914
 
2838
2915
 
2839
2916
static int
2840
 
com_ego(string *buffer,const char *line)
 
2917
com_ego(GString *buffer,char *line)
2841
2918
{
2842
2919
  int result;
2843
2920
  bool oldvertical=vertical;
2851
2928
static const char *fieldtype2str(enum enum_field_types type)
2852
2929
{
2853
2930
  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_SHORT:       return "SHORT";
2864
 
    case DRIZZLE_TYPE_TIME:        return "TIME";
2865
 
    case DRIZZLE_TYPE_TIMESTAMP:   return "TIMESTAMP";
2866
 
    case DRIZZLE_TYPE_TINY:        return "TINY";
 
2931
    case MYSQL_TYPE_BLOB:        return "BLOB";
 
2932
    case MYSQL_TYPE_NEWDATE:        return "DATE";
 
2933
    case MYSQL_TYPE_DATETIME:    return "DATETIME";
 
2934
    case MYSQL_TYPE_NEWDECIMAL:  return "DECIMAL";
 
2935
    case MYSQL_TYPE_DOUBLE:      return "DOUBLE";
 
2936
    case MYSQL_TYPE_ENUM:        return "ENUM";
 
2937
    case MYSQL_TYPE_LONG:        return "LONG";
 
2938
    case MYSQL_TYPE_LONGLONG:    return "LONGLONG";
 
2939
    case MYSQL_TYPE_NULL:        return "NULL";
 
2940
    case MYSQL_TYPE_SET:         return "SET";
 
2941
    case MYSQL_TYPE_SHORT:       return "SHORT";
 
2942
    case MYSQL_TYPE_STRING:      return "STRING";
 
2943
    case MYSQL_TYPE_TIME:        return "TIME";
 
2944
    case MYSQL_TYPE_TIMESTAMP:   return "TIMESTAMP";
 
2945
    case MYSQL_TYPE_TINY:        return "TINY";
 
2946
    case MYSQL_TYPE_VAR_STRING:  return "VAR_STRING";
 
2947
    case MYSQL_TYPE_YEAR:        return "YEAR";
2867
2948
    default:                     return "?-unknown-?";
2868
2949
  }
2869
2950
}
2873
2954
  char *s=buf;
2874
2955
  *s=0;
2875
2956
#define ff2s_check_flag(X)                                              \
2876
 
  if (f & X ## _FLAG) { s=stpcpy(s, # X " "); f &= ~ X ## _FLAG; }
 
2957
  if (f & X ## _FLAG) { s=strmov(s, # X " "); f &= ~ X ## _FLAG; }
2877
2958
  ff2s_check_flag(NOT_NULL);
2878
2959
  ff2s_check_flag(PRI_KEY);
2879
2960
  ff2s_check_flag(UNIQUE_KEY);
2880
2961
  ff2s_check_flag(MULTIPLE_KEY);
2881
2962
  ff2s_check_flag(BLOB);
2882
2963
  ff2s_check_flag(UNSIGNED);
 
2964
  ff2s_check_flag(ZEROFILL);
2883
2965
  ff2s_check_flag(BINARY);
2884
2966
  ff2s_check_flag(ENUM);
2885
2967
  ff2s_check_flag(AUTO_INCREMENT);
2899
2981
}
2900
2982
 
2901
2983
static void
2902
 
print_field_types(DRIZZLE_RES *result)
 
2984
print_field_types(MYSQL_RES *result)
2903
2985
{
2904
 
  DRIZZLE_FIELD   *field;
 
2986
  MYSQL_FIELD   *field;
2905
2987
  uint i=0;
2906
2988
 
2907
 
  while ((field = drizzle_fetch_field(result)))
 
2989
  while ((field = mysql_fetch_field(result)))
2908
2990
  {
2909
2991
    tee_fprintf(PAGER, "Field %3u:  `%s`\n"
2910
2992
                "Catalog:    `%s`\n"
2929
3011
 
2930
3012
 
2931
3013
static void
2932
 
print_table_data(DRIZZLE_RES *result)
 
3014
print_table_data(MYSQL_RES *result)
2933
3015
{
2934
 
  DRIZZLE_ROW     cur;
2935
 
  DRIZZLE_FIELD   *field;
 
3016
  GString       *separator = g_string_sized_new(256);
 
3017
  MYSQL_ROW     cur;
 
3018
  MYSQL_FIELD   *field;
2936
3019
  bool          *num_flag;
2937
 
  string separator;
2938
 
  
2939
 
  separator.reserve(256);
2940
3020
 
2941
 
  num_flag=(bool*) my_malloc(sizeof(bool)*drizzle_num_fields(result),
 
3021
  num_flag=(bool*) my_malloc(sizeof(bool)*mysql_num_fields(result),
2942
3022
                             MYF(MY_WME));
2943
3023
  if (column_types_flag)
2944
3024
  {
2945
3025
    print_field_types(result);
2946
 
    if (!drizzle_num_rows(result))
 
3026
    if (!mysql_num_rows(result))
2947
3027
      return;
2948
 
    drizzle_field_seek(result,0);
 
3028
    mysql_field_seek(result,0);
2949
3029
  }
2950
 
  separator.append("+");
2951
 
  while ((field = drizzle_fetch_field(result)))
 
3030
  separator = g_string_append_c(separator, '+');
 
3031
  while ((field = mysql_fetch_field(result)))
2952
3032
  {
2953
 
    uint32_t length= column_names ? field->name_length : 0;
 
3033
    uint length= column_names ? field->name_length : 0;
2954
3034
    if (quick)
2955
3035
      length=max(length,field->length);
2956
3036
    else
2957
3037
      length=max(length,field->max_length);
2958
 
    if (length < 4 && !(field->flags & NOT_NULL_FLAG))
 
3038
    if (length < 4 && !IS_NOT_NULL(field->flags))
2959
3039
      // Room for "NULL"
2960
3040
      length=4;
2961
3041
    field->max_length=length;
2962
3042
    uint x;
2963
3043
    for (x=0; x< (length+2); x++)
2964
 
      separator.append("-");
2965
 
    separator.append("+");
 
3044
      g_string_append_c(separator, '-');
 
3045
    g_string_append_c(separator, '+');
2966
3046
  }
 
3047
  // End marker for \0
 
3048
  // TODO: Huh? Do we need this with GString?
 
3049
  g_string_append_c(separator, '\0');
2967
3050
 
2968
 
  tee_puts((char*) separator.c_str(), PAGER);
 
3051
  tee_puts((char*) separator->str, PAGER);
2969
3052
  if (column_names)
2970
3053
  {
2971
 
    drizzle_field_seek(result,0);
 
3054
    mysql_field_seek(result,0);
2972
3055
    (void) tee_fputs("|", PAGER);
2973
 
    for (uint off=0; (field = drizzle_fetch_field(result)) ; off++)
 
3056
    for (uint off=0; (field = mysql_fetch_field(result)) ; off++)
2974
3057
    {
2975
3058
      uint name_length= (uint) strlen(field->name);
2976
3059
      uint numcells= charset_info->cset->numcells(charset_info,
2977
3060
                                                  field->name,
2978
3061
                                                  field->name + name_length);
2979
 
      uint32_t display_length= field->max_length + name_length - numcells;
 
3062
      uint display_length= field->max_length + name_length - numcells;
2980
3063
      tee_fprintf(PAGER, " %-*s |",(int) min(display_length,
2981
3064
                                             MAX_COLUMN_LENGTH),
2982
3065
                  field->name);
2983
 
      num_flag[off]= ((field->type <= DRIZZLE_TYPE_LONGLONG) || 
2984
 
                      (field->type == DRIZZLE_TYPE_NEWDECIMAL));
 
3066
      num_flag[off]= IS_NUM(field->type);
2985
3067
    }
2986
3068
    (void) tee_fputs("\n", PAGER);
2987
 
    tee_puts((char*) separator.c_str(), PAGER);
 
3069
    tee_puts((char*) separator->str, PAGER);
2988
3070
  }
2989
3071
 
2990
 
  while ((cur= drizzle_fetch_row(result)))
 
3072
  while ((cur= mysql_fetch_row(result)))
2991
3073
  {
2992
3074
    if (interrupted_query)
2993
3075
      break;
2994
 
    uint32_t *lengths= drizzle_fetch_lengths(result);
 
3076
    uint32_t *lengths= mysql_fetch_lengths(result);
2995
3077
    (void) tee_fputs("| ", PAGER);
2996
 
    drizzle_field_seek(result, 0);
2997
 
    for (uint off= 0; off < drizzle_num_fields(result); off++)
 
3078
    mysql_field_seek(result, 0);
 
3079
    for (uint off= 0; off < mysql_num_fields(result); off++)
2998
3080
    {
2999
3081
      const char *buffer;
3000
3082
      uint data_length;
3013
3095
        data_length= (uint) lengths[off];
3014
3096
      }
3015
3097
 
3016
 
      field= drizzle_fetch_field(result);
 
3098
      field= mysql_fetch_field(result);
3017
3099
      field_max_length= field->max_length;
3018
3100
 
3019
3101
      /*
3041
3123
    }
3042
3124
    (void) tee_fputs("\n", PAGER);
3043
3125
  }
3044
 
  tee_puts(separator.c_str(), PAGER);
 
3126
  tee_puts(separator->str, PAGER);
3045
3127
  my_free(num_flag, MYF(MY_ALLOW_ZERO_PTR));
3046
3128
}
3047
3129
 
3061
3143
 
3062
3144
   @returns  number of character positions to be used, at most
3063
3145
*/
3064
 
static int get_field_disp_length(DRIZZLE_FIELD *field)
 
3146
static int get_field_disp_length(MYSQL_FIELD *field)
3065
3147
{
3066
3148
  uint length= column_names ? field->name_length : 0;
3067
3149
 
3070
3152
  else
3071
3153
    length= max(length, field->max_length);
3072
3154
 
3073
 
  if (length < 4 && !(field->flags & NOT_NULL_FLAG))
3074
 
    length= 4;        /* Room for "NULL" */
 
3155
  if (length < 4 && !IS_NOT_NULL(field->flags))
 
3156
    length= 4;                          /* Room for "NULL" */
3075
3157
 
3076
3158
  return length;
3077
3159
}
3084
3166
 
3085
3167
   @returns  The max number of characters in any row of this result
3086
3168
*/
3087
 
static int get_result_width(DRIZZLE_RES *result)
 
3169
static int get_result_width(MYSQL_RES *result)
3088
3170
{
3089
3171
  unsigned int len= 0;
3090
 
  DRIZZLE_FIELD *field;
3091
 
  DRIZZLE_FIELD_OFFSET offset;
 
3172
  MYSQL_FIELD *field;
 
3173
  MYSQL_FIELD_OFFSET offset;
3092
3174
 
3093
 
  offset= drizzle_field_tell(result);
 
3175
  offset= mysql_field_tell(result);
3094
3176
  assert(offset == 0);
3095
3177
 
3096
 
  while ((field= drizzle_fetch_field(result)) != NULL)
 
3178
  while ((field= mysql_fetch_field(result)) != NULL)
3097
3179
    len+= get_field_disp_length(field) + 3; /* plus bar, space, & final space */
3098
3180
 
3099
 
  (void) drizzle_field_seek(result, offset);
 
3181
  (void) mysql_field_seek(result, offset);
3100
3182
 
3101
3183
  return len + 1; /* plus final bar. */
3102
3184
}
3132
3214
 
3133
3215
 
3134
3216
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)))
 
3217
print_table_data_html(MYSQL_RES *result)
 
3218
{
 
3219
  MYSQL_ROW     cur;
 
3220
  MYSQL_FIELD   *field;
 
3221
 
 
3222
  mysql_field_seek(result,0);
 
3223
  (void) tee_fputs("<TABLE BORDER=1><TR>", PAGER);
 
3224
  if (column_names)
 
3225
  {
 
3226
    while((field = mysql_fetch_field(result)))
 
3227
    {
 
3228
      tee_fprintf(PAGER, "<TH>%s</TH>", (field->name ?
 
3229
                                         (field->name[0] ? field->name :
 
3230
                                          " &nbsp; ") : "NULL"));
 
3231
    }
 
3232
    (void) tee_fputs("</TR>", PAGER);
 
3233
  }
 
3234
  while ((cur = mysql_fetch_row(result)))
 
3235
  {
 
3236
    if (interrupted_query)
 
3237
      break;
 
3238
    uint32_t *lengths=mysql_fetch_lengths(result);
 
3239
    (void) tee_fputs("<TR>", PAGER);
 
3240
    for (uint32_t i= 0; i < mysql_num_fields(result); i++)
 
3241
    {
 
3242
      (void) tee_fputs("<TD>", PAGER);
 
3243
      safe_put_field(cur[i],lengths[i]);
 
3244
      (void) tee_fputs("</TD>", PAGER);
 
3245
    }
 
3246
    (void) tee_fputs("</TR>", PAGER);
 
3247
  }
 
3248
  (void) tee_fputs("</TABLE>", PAGER);
 
3249
}
 
3250
 
 
3251
 
 
3252
static void
 
3253
print_table_data_xml(MYSQL_RES *result)
 
3254
{
 
3255
  MYSQL_ROW   cur;
 
3256
  MYSQL_FIELD *fields;
 
3257
 
 
3258
  mysql_field_seek(result,0);
 
3259
 
 
3260
  tee_fputs("<?xml version=\"1.0\"?>\n\n<resultset statement=\"", PAGER);
 
3261
  xmlencode_print(glob_buffer->str, glob_buffer->len);
 
3262
  tee_fputs("\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">",
 
3263
            PAGER);
 
3264
 
 
3265
  fields = mysql_fetch_fields(result);
 
3266
  while ((cur = mysql_fetch_row(result)))
 
3267
  {
 
3268
    if (interrupted_query)
 
3269
      break;
 
3270
    uint32_t *lengths=mysql_fetch_lengths(result);
 
3271
    (void) tee_fputs("\n  <row>\n", PAGER);
 
3272
    for (uint i=0; i < mysql_num_fields(result); i++)
 
3273
    {
 
3274
      tee_fprintf(PAGER, "\t<field name=\"");
 
3275
      xmlencode_print(fields[i].name, (uint) strlen(fields[i].name));
 
3276
      if (cur[i])
 
3277
      {
 
3278
        tee_fprintf(PAGER, "\">");
 
3279
        xmlencode_print(cur[i], lengths[i]);
 
3280
        tee_fprintf(PAGER, "</field>\n");
 
3281
      }
 
3282
      else
 
3283
        tee_fprintf(PAGER, "\" xsi:nil=\"true\" />\n");
 
3284
    }
 
3285
    (void) tee_fputs("  </row>\n", PAGER);
 
3286
  }
 
3287
  (void) tee_fputs("</resultset>\n", PAGER);
 
3288
}
 
3289
 
 
3290
 
 
3291
static void
 
3292
print_table_data_vertically(MYSQL_RES *result)
 
3293
{
 
3294
  MYSQL_ROW     cur;
 
3295
  uint          max_length=0;
 
3296
  MYSQL_FIELD   *field;
 
3297
 
 
3298
  while ((field = mysql_fetch_field(result)))
3142
3299
  {
3143
3300
    uint length= field->name_length;
3144
3301
    if (length > max_length)
3146
3303
    field->max_length=length;
3147
3304
  }
3148
3305
 
3149
 
  drizzle_field_seek(result,0);
3150
 
  for (uint row_count=1; (cur= drizzle_fetch_row(result)); row_count++)
 
3306
  mysql_field_seek(result,0);
 
3307
  for (uint row_count=1; (cur= mysql_fetch_row(result)); row_count++)
3151
3308
  {
3152
3309
    if (interrupted_query)
3153
3310
      break;
3154
 
    drizzle_field_seek(result,0);
 
3311
    mysql_field_seek(result,0);
3155
3312
    tee_fprintf(PAGER,
3156
3313
                "*************************** %d. row ***************************\n", row_count);
3157
 
    for (uint off=0; off < drizzle_num_fields(result); off++)
 
3314
    for (uint off=0; off < mysql_num_fields(result); off++)
3158
3315
    {
3159
 
      field= drizzle_fetch_field(result);
 
3316
      field= mysql_fetch_field(result);
3160
3317
      tee_fprintf(PAGER, "%*s: ",(int) max_length,field->name);
3161
3318
      tee_fprintf(PAGER, "%s\n",cur[off] ? (char*) cur[off] : "NULL");
3162
3319
    }
3169
3326
static void print_warnings()
3170
3327
{
3171
3328
  const char   *query;
3172
 
  DRIZZLE_RES    *result;
3173
 
  DRIZZLE_ROW    cur;
 
3329
  MYSQL_RES    *result;
 
3330
  MYSQL_ROW    cur;
3174
3331
  uint64_t num_rows;
3175
 
 
 
3332
  
3176
3333
  /* Save current error before calling "show warnings" */
3177
 
  uint error= drizzle_errno(&drizzle);
 
3334
  uint error= mysql_errno(&mysql);
3178
3335
 
3179
3336
  /* Get the warnings */
3180
3337
  query= "show warnings";
3181
 
  drizzle_real_query_for_lazy(query, strlen(query));
3182
 
  drizzle_store_result_for_lazy(&result);
 
3338
  mysql_real_query_for_lazy(query, strlen(query));
 
3339
  mysql_store_result_for_lazy(&result);
3183
3340
 
3184
3341
  /* Bail out when no warnings */
3185
 
  if (!(num_rows= drizzle_num_rows(result)))
 
3342
  if (!(num_rows= mysql_num_rows(result)))
3186
3343
    goto end;
3187
3344
 
3188
 
  cur= drizzle_fetch_row(result);
 
3345
  cur= mysql_fetch_row(result);
3189
3346
 
3190
3347
  /*
3191
3348
    Don't print a duplicate of the current error.  It is possible for SHOW
3201
3358
  do
3202
3359
  {
3203
3360
    tee_fprintf(PAGER, "%s (Code %s): %s\n", cur[0], cur[1], cur[2]);
3204
 
  } while ((cur= drizzle_fetch_row(result)));
 
3361
  } while ((cur= mysql_fetch_row(result)));
3205
3362
  end_pager();
3206
3363
 
3207
3364
end:
3208
 
  drizzle_free_result(result);
3209
 
}
3210
 
 
3211
 
 
3212
 
static void
3213
 
safe_put_field(const char *pos,uint32_t length)
 
3365
  mysql_free_result(result);
 
3366
}
 
3367
 
 
3368
 
 
3369
static const char *array_value(const char **array, char key)
 
3370
{
 
3371
  for (; *array; array+= 2)
 
3372
    if (**array == key)
 
3373
      return array[1];
 
3374
  return 0;
 
3375
}
 
3376
 
 
3377
 
 
3378
static void
 
3379
xmlencode_print(const char *src, uint length)
 
3380
{
 
3381
  if (!src)
 
3382
    tee_fputs("NULL", PAGER);
 
3383
  else
 
3384
  {
 
3385
    for (const char *p = src; *p && length; length--)
 
3386
    {
 
3387
      const char *t;
 
3388
      if ((t = array_value(xmlmeta, *p++)))
 
3389
        tee_fputs(t, PAGER);
 
3390
      else
 
3391
        tee_putc(*p, PAGER);
 
3392
    }
 
3393
  }
 
3394
}
 
3395
 
 
3396
 
 
3397
static void
 
3398
safe_put_field(const char *pos,ulong length)
3214
3399
{
3215
3400
  if (!pos)
3216
3401
    tee_fputs("NULL", PAGER);
3247
3432
 
3248
3433
 
3249
3434
static void
3250
 
print_tab_data(DRIZZLE_RES *result)
 
3435
print_tab_data(MYSQL_RES *result)
3251
3436
{
3252
 
  DRIZZLE_ROW  cur;
3253
 
  DRIZZLE_FIELD  *field;
3254
 
  uint32_t    *lengths;
 
3437
  MYSQL_ROW     cur;
 
3438
  MYSQL_FIELD   *field;
 
3439
  uint32_t              *lengths;
3255
3440
 
3256
3441
  if (opt_silent < 2 && column_names)
3257
3442
  {
3258
3443
    int first=0;
3259
 
    while ((field = drizzle_fetch_field(result)))
 
3444
    while ((field = mysql_fetch_field(result)))
3260
3445
    {
3261
3446
      if (first++)
3262
3447
        (void) tee_fputs("\t", PAGER);
3264
3449
    }
3265
3450
    (void) tee_fputs("\n", PAGER);
3266
3451
  }
3267
 
  while ((cur = drizzle_fetch_row(result)))
 
3452
  while ((cur = mysql_fetch_row(result)))
3268
3453
  {
3269
 
    lengths= drizzle_fetch_lengths(result);
 
3454
    lengths= mysql_fetch_lengths(result);
3270
3455
    safe_put_field(cur[0],lengths[0]);
3271
 
    for (uint off=1 ; off < drizzle_num_fields(result); off++)
 
3456
    for (uint off=1 ; off < mysql_num_fields(result); off++)
3272
3457
    {
3273
3458
      (void) tee_fputs("\t", PAGER);
3274
3459
      safe_put_field(cur[off], lengths[off]);
3278
3463
}
3279
3464
 
3280
3465
static int
3281
 
com_tee(string *buffer __attribute__((unused)), const char *line )
 
3466
com_tee(GString *buffer __attribute__((__unused__)), char *line )
3282
3467
{
3283
3468
  char file_name[FN_REFLEN], *end, *param;
3284
3469
 
3299
3484
      return 0;
3300
3485
    }
3301
3486
    else
3302
 
      param = outfile;      //resume using the old outfile
 
3487
      param = outfile;                  //resume using the old outfile
3303
3488
  }
3304
3489
 
3305
3490
  /* eliminate the spaces before the parameters */
3322
3507
 
3323
3508
 
3324
3509
static int
3325
 
com_notee(string *buffer __attribute__((unused)),
3326
 
          const char *line __attribute__((unused)))
 
3510
com_notee(GString *buffer __attribute__((unused)),
 
3511
          char *line __attribute__((unused)))
3327
3512
{
3328
3513
  if (opt_outfile)
3329
3514
    end_tee();
3336
3521
*/
3337
3522
 
3338
3523
static int
3339
 
com_pager(string *buffer __attribute__((unused)),
3340
 
          const char *line __attribute__((unused)))
 
3524
com_pager(GString *buffer __attribute__((__unused__)),
 
3525
          char *line __attribute__((unused)))
3341
3526
{
3342
3527
  char pager_name[FN_REFLEN], *end, *param;
3343
3528
 
3357
3542
    {
3358
3543
      tee_fprintf(stdout, "Default pager wasn't set, using stdout.\n");
3359
3544
      opt_nopager=1;
3360
 
      stpcpy(pager, "stdout");
 
3545
      strmov(pager, "stdout");
3361
3546
      PAGER= stdout;
3362
3547
      return 0;
3363
3548
    }
3364
 
    stpcpy(pager, default_pager);
 
3549
    strmov(pager, default_pager);
3365
3550
  }
3366
3551
  else
3367
3552
  {
3370
3555
                                my_iscntrl(charset_info,end[-1])))
3371
3556
      end--;
3372
3557
    end[0]=0;
3373
 
    stpcpy(pager, pager_name);
3374
 
    stpcpy(default_pager, pager_name);
 
3558
    strmov(pager, pager_name);
 
3559
    strmov(default_pager, pager_name);
3375
3560
  }
3376
3561
  opt_nopager=0;
3377
3562
  tee_fprintf(stdout, "PAGER set to '%s'\n", pager);
3380
3565
 
3381
3566
 
3382
3567
static int
3383
 
com_nopager(string *buffer __attribute__((unused)),
3384
 
            const char *line __attribute__((unused)))
 
3568
com_nopager(GString *buffer __attribute__((unused)),
 
3569
            char *line __attribute__((unused)))
3385
3570
{
3386
 
  stpcpy(pager, "stdout");
 
3571
  strmov(pager, "stdout");
3387
3572
  opt_nopager=1;
3388
3573
  PAGER= stdout;
3389
3574
  tee_fprintf(stdout, "PAGER set to stdout\n");
3393
3578
/* If arg is given, exit without errors. This happens on command 'quit' */
3394
3579
 
3395
3580
static int
3396
 
com_quit(string *buffer __attribute__((unused)),
3397
 
         const char *line __attribute__((unused)))
 
3581
com_quit(GString *buffer __attribute__((unused)),
 
3582
         char *line __attribute__((unused)))
3398
3583
{
3399
3584
  /* let the screen auto close on a normal shutdown */
3400
3585
  status.exit_status=0;
3402
3587
}
3403
3588
 
3404
3589
static int
3405
 
com_rehash(string *buffer __attribute__((unused)),
3406
 
           const char *line __attribute__((unused)))
 
3590
com_rehash(GString *buffer __attribute__((unused)),
 
3591
           char *line __attribute__((unused)))
3407
3592
{
3408
3593
  build_completion_hash(1, 0);
3409
3594
  return 0;
3412
3597
 
3413
3598
 
3414
3599
static int
3415
 
com_print(string *buffer,const char *line __attribute__((unused)))
 
3600
com_print(GString *buffer,char *line __attribute__((unused)))
3416
3601
{
3417
3602
  tee_puts("--------------", stdout);
3418
 
  (void) tee_fputs(buffer->c_str(), stdout);
3419
 
  if ( (buffer->length() == 0)
3420
 
       || (buffer->c_str())[(buffer->length())-1] != '\n')
 
3603
  (void) tee_fputs(buffer->str, stdout);
 
3604
  if ( (buffer->len == 0)
 
3605
       || (buffer->str)[(buffer->len)-1] != '\n')
3421
3606
    tee_putc('\n', stdout);
3422
3607
  tee_puts("--------------\n", stdout);
3423
3608
  /* If empty buffer */
3426
3611
 
3427
3612
/* ARGSUSED */
3428
3613
static int
3429
 
com_connect(string *buffer, const char *line)
 
3614
com_connect(GString *buffer, char *line)
3430
3615
{
3431
3616
  char *tmp, buff[256];
3432
3617
  bool save_rehash= opt_rehash;
3433
3618
  int error;
3434
3619
 
3435
 
  memset(buff, 0, sizeof(buff));
 
3620
  bzero(buff, sizeof(buff));
3436
3621
  if (buffer)
3437
3622
  {
3438
3623
    /*
3447
3632
    if (tmp && *tmp)
3448
3633
    {
3449
3634
      my_free(current_db, MYF(MY_ALLOW_ZERO_PTR));
3450
 
      current_db= strdup(tmp);
 
3635
      current_db= g_strdup(tmp);
3451
3636
      tmp= get_arg(buff, 1);
3452
3637
      if (tmp)
3453
3638
      {
3454
3639
        my_free(current_host,MYF(MY_ALLOW_ZERO_PTR));
3455
 
        current_host=strdup(tmp);
 
3640
        current_host=g_strdup(tmp);
3456
3641
      }
3457
3642
    }
3458
3643
    else
3462
3647
    }
3463
3648
    // command used
3464
3649
    assert(buffer!=NULL);
3465
 
    buffer->clear();
 
3650
    g_string_truncate(buffer, 0);
3466
3651
  }
3467
3652
  else
3468
3653
    opt_rehash= 0;
3471
3656
 
3472
3657
  if (connected)
3473
3658
  {
3474
 
    sprintf(buff,"Connection id:    %u",drizzle_thread_id(&drizzle));
 
3659
    sprintf(buff,"Connection id:    %u",mysql_thread_id(&mysql));
3475
3660
    put_info(buff,INFO_INFO,0,0);
3476
3661
    sprintf(buff,"Current database: %.128s\n",
3477
3662
            current_db ? current_db : "*** NONE ***");
3481
3666
}
3482
3667
 
3483
3668
 
3484
 
static int com_source(string *buffer __attribute__((unused)), const char *line)
 
3669
static int com_source(GString *buffer __attribute__((__unused__)), char *line)
3485
3670
{
3486
3671
  char source_name[FN_REFLEN], *end, *param;
3487
3672
  LINE_BUFFER *line_buff;
3492
3677
  /* Skip space from file name */
3493
3678
  while (my_isspace(charset_info,*line))
3494
3679
    line++;
3495
 
  if (!(param = strchr(line, ' ')))    // Skip command name
 
3680
  if (!(param = strchr(line, ' ')))             // Skip command name
3496
3681
    return put_info("Usage: \\. <filename> | source <filename>",
3497
3682
                    INFO_ERROR, 0,0);
3498
3683
  while (my_isspace(charset_info,*param))
3519
3704
 
3520
3705
  /* Save old status */
3521
3706
  old_status=status;
3522
 
  memset(&status, 0, sizeof(status));
 
3707
  bfill((char*) &status,sizeof(status),(char) 0);
3523
3708
 
3524
3709
  // Run in batch mode
3525
3710
  status.batch=old_status.batch;
3527
3712
  status.file_name=source_name;
3528
3713
  // Empty command buffer
3529
3714
  assert(glob_buffer!=NULL);
3530
 
  glob_buffer->clear();
 
3715
  g_string_truncate(glob_buffer, 0);
3531
3716
  error= read_and_execute(false);
3532
3717
  // Continue as before
3533
3718
  status=old_status;
3539
3724
 
3540
3725
/* ARGSUSED */
3541
3726
static int
3542
 
com_delimiter(string *buffer __attribute__((unused)), const char *line)
 
3727
com_delimiter(GString *buffer __attribute__((unused)), char *line)
3543
3728
{
3544
3729
  char buff[256], *tmp;
3545
3730
 
3569
3754
 
3570
3755
/* ARGSUSED */
3571
3756
static int
3572
 
com_use(string *buffer __attribute__((unused)), const char *line)
 
3757
com_use(GString *buffer __attribute__((unused)), char *line)
3573
3758
{
3574
3759
  char *tmp, buff[FN_REFLEN + 1];
3575
3760
  int select_db;
3576
3761
 
3577
 
  memset(buff, 0, sizeof(buff));
 
3762
  bzero(buff, sizeof(buff));
3578
3763
  strmake(buff, line, sizeof(buff) - 1);
3579
3764
  tmp= get_arg(buff, 0);
3580
3765
  if (!tmp || !*tmp)
3594
3779
    if (one_database)
3595
3780
    {
3596
3781
      skip_updates= 1;
3597
 
      select_db= 0;    // don't do drizzle_select_db()
 
3782
      select_db= 0;    // don't do mysql_select_db()
3598
3783
    }
3599
3784
    else
3600
 
      select_db= 2;    // do drizzle_select_db() and build_completion_hash()
 
3785
      select_db= 2;    // do mysql_select_db() and build_completion_hash()
3601
3786
  }
3602
3787
  else
3603
3788
  {
3604
3789
    /*
3605
3790
      USE to the current db specified.
3606
 
      We do need to send drizzle_select_db() to make server
 
3791
      We do need to send mysql_select_db() to make server
3607
3792
      update database level privileges, which might
3608
3793
      change since last USE (see bug#10979).
3609
3794
      For performance purposes, we'll skip rebuilding of completion hash.
3610
3795
    */
3611
3796
    skip_updates= 0;
3612
 
    select_db= 1;      // do only drizzle_select_db(), without completion
 
3797
    select_db= 1;      // do only mysql_select_db(), without completion
3613
3798
  }
3614
3799
 
3615
3800
  if (select_db)
3620
3805
    */
3621
3806
    if (!connected && reconnect())
3622
3807
      return opt_reconnect ? -1 : 1;                        // Fatal error
3623
 
    if (drizzle_select_db(&drizzle,tmp))
 
3808
    if (mysql_select_db(&mysql,tmp))
3624
3809
    {
3625
 
      if (drizzle_errno(&drizzle) != CR_SERVER_GONE_ERROR)
3626
 
        return put_error(&drizzle);
 
3810
      if (mysql_errno(&mysql) != CR_SERVER_GONE_ERROR)
 
3811
        return put_error(&mysql);
3627
3812
 
3628
3813
      if (reconnect())
3629
3814
        return opt_reconnect ? -1 : 1;                      // Fatal error
3630
 
      if (drizzle_select_db(&drizzle,tmp))
3631
 
        return put_error(&drizzle);
 
3815
      if (mysql_select_db(&mysql,tmp))
 
3816
        return put_error(&mysql);
3632
3817
    }
3633
3818
    my_free(current_db,MYF(MY_ALLOW_ZERO_PTR));
3634
 
    current_db= strdup(tmp);
 
3819
    current_db=g_strdup(tmp);
3635
3820
    if (select_db > 1)
3636
3821
      build_completion_hash(opt_rehash, 1);
3637
3822
  }
3641
3826
}
3642
3827
 
3643
3828
static int
3644
 
com_warnings(string *buffer __attribute__((unused)),
3645
 
             const char *line __attribute__((unused)))
 
3829
com_warnings(GString *buffer __attribute__((unused)),
 
3830
             char *line __attribute__((unused)))
3646
3831
{
3647
3832
  show_warnings = 1;
3648
3833
  put_info("Show warnings enabled.",INFO_INFO, 0, 0);
3650
3835
}
3651
3836
 
3652
3837
static int
3653
 
com_nowarnings(string *buffer __attribute__((unused)),
3654
 
               const char *line __attribute__((unused)))
 
3838
com_nowarnings(GString *buffer __attribute__((unused)),
 
3839
               char *line __attribute__((unused)))
3655
3840
{
3656
3841
  show_warnings = 0;
3657
3842
  put_info("Show warnings disabled.",INFO_INFO, 0, 0);
3707
3892
    if (*ptr == '\\' && ptr[1]) // escaped character
3708
3893
    {
3709
3894
      // Remove the backslash
3710
 
      stpcpy(ptr, ptr+1);
 
3895
      strmov(ptr, ptr+1);
3711
3896
    }
3712
3897
    else if ((!quoted && *ptr == ' ') || (quoted && *ptr == qtype))
3713
3898
    {
3721
3906
 
3722
3907
 
3723
3908
static int
3724
 
sql_connect(char *host,char *database,char *user,char *password,
 
3909
sql_real_connect(char *host,char *database,char *user,char *password,
3725
3910
                 uint silent)
3726
3911
{
3727
3912
  if (connected)
3728
3913
  {
3729
3914
    connected= 0;
3730
 
    drizzle_close(&drizzle);
 
3915
    mysql_close(&mysql);
3731
3916
  }
3732
 
  drizzle_create(&drizzle);
 
3917
  mysql_init(&mysql);
3733
3918
  if (opt_connect_timeout)
3734
3919
  {
3735
3920
    uint timeout=opt_connect_timeout;
3736
 
    drizzle_options(&drizzle,DRIZZLE_OPT_CONNECT_TIMEOUT,
 
3921
    mysql_options(&mysql,MYSQL_OPT_CONNECT_TIMEOUT,
3737
3922
                  (char*) &timeout);
3738
3923
  }
3739
3924
  if (opt_compress)
3740
 
    drizzle_options(&drizzle,DRIZZLE_OPT_COMPRESS,NullS);
 
3925
    mysql_options(&mysql,MYSQL_OPT_COMPRESS,NullS);
3741
3926
  if (opt_secure_auth)
3742
 
    drizzle_options(&drizzle, DRIZZLE_SECURE_AUTH, (char *) &opt_secure_auth);
 
3927
    mysql_options(&mysql, MYSQL_SECURE_AUTH, (char *) &opt_secure_auth);
3743
3928
  if (using_opt_local_infile)
3744
 
    drizzle_options(&drizzle,DRIZZLE_OPT_LOCAL_INFILE, (char*) &opt_local_infile);
 
3929
    mysql_options(&mysql,MYSQL_OPT_LOCAL_INFILE, (char*) &opt_local_infile);
 
3930
  if (opt_protocol)
 
3931
    mysql_options(&mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
3745
3932
  if (safe_updates)
3746
3933
  {
3747
3934
    char init_command[100];
3748
3935
    sprintf(init_command,
3749
 
            "SET SQL_SAFE_UPDATES=1,SQL_SELECT_LIMIT=%"PRIu32
 
3936
                  "SET SQL_SAFE_UPDATES=1,SQL_SELECT_LIMIT=%"PRIu32
3750
3937
            ",SQL_MAX_JOIN_SIZE=%"PRIu32,
3751
 
            select_limit, max_join_size);
3752
 
    drizzle_options(&drizzle, DRIZZLE_INIT_COMMAND, init_command);
 
3938
                  select_limit, max_join_size);
 
3939
    mysql_options(&mysql, MYSQL_INIT_COMMAND, init_command);
3753
3940
  }
3754
 
  if (!drizzle_connect(&drizzle, host, user, password,
3755
 
                          database, opt_drizzle_port, opt_drizzle_unix_port,
 
3941
  if (default_charset_used)
 
3942
    mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, default_charset);
 
3943
  if (!mysql_real_connect(&mysql, host, user, password,
 
3944
                          database, opt_mysql_port, opt_mysql_unix_port,
3756
3945
                          connect_flag | CLIENT_MULTI_STATEMENTS))
3757
3946
  {
3758
3947
    if (!silent ||
3759
 
        (drizzle_errno(&drizzle) != CR_CONN_HOST_ERROR &&
3760
 
         drizzle_errno(&drizzle) != CR_CONNECTION_ERROR))
 
3948
        (mysql_errno(&mysql) != CR_CONN_HOST_ERROR &&
 
3949
         mysql_errno(&mysql) != CR_CONNECTION_ERROR))
3761
3950
    {
3762
 
      (void) put_error(&drizzle);
 
3951
      (void) put_error(&mysql);
3763
3952
      (void) fflush(stdout);
3764
 
      return ignore_errors ? -1 : 1;    // Abort
 
3953
      return ignore_errors ? -1 : 1;            // Abort
3765
3954
    }
3766
 
    return -1;          // Retryable
 
3955
    return -1;                                  // Retryable
3767
3956
  }
3768
3957
  connected=1;
3769
 
  drizzle.reconnect= debug_info_flag; // We want to know if this happens
 
3958
  mysql.reconnect= debug_info_flag; // We want to know if this happens
3770
3959
  build_completion_hash(opt_rehash, 1);
3771
3960
  return 0;
3772
3961
}
3773
3962
 
3774
3963
 
3775
3964
static int
3776
 
com_status(string *buffer __attribute__((unused)),
3777
 
           const char *line __attribute__((unused)))
3778
 
{
 
3965
sql_connect(char *host,char *database,char *user,char *password,uint silent)
 
3966
{
 
3967
  bool message=0;
 
3968
  uint count=0;
 
3969
  int error;
 
3970
  for (;;)
 
3971
  {
 
3972
    if ((error=sql_real_connect(host,database,user,password,wait_flag)) >= 0)
 
3973
    {
 
3974
      if (count)
 
3975
      {
 
3976
        tee_fputs("\n", stderr);
 
3977
        (void) fflush(stderr);
 
3978
      }
 
3979
      return error;
 
3980
    }
 
3981
    if (!wait_flag)
 
3982
      return ignore_errors ? -1 : 1;
 
3983
    if (!message && !silent)
 
3984
    {
 
3985
      message=1;
 
3986
      tee_fputs("Waiting",stderr); (void) fflush(stderr);
 
3987
    }
 
3988
    (void) sleep(wait_time);
 
3989
    if (!silent)
 
3990
    {
 
3991
      putc('.',stderr); (void) fflush(stderr);
 
3992
      count++;
 
3993
    }
 
3994
  }
 
3995
}
 
3996
 
 
3997
 
 
3998
 
 
3999
static int
 
4000
com_status(GString *buffer __attribute__((unused)),
 
4001
           char *line __attribute__((unused)))
 
4002
{
 
4003
  const char *status_str;
3779
4004
  char buff[40];
3780
4005
  uint64_t id;
3781
 
  DRIZZLE_RES *result;
 
4006
  MYSQL_RES *result;
3782
4007
 
3783
4008
  tee_puts("--------------", stdout);
3784
 
  usage(1);          /* Print version */
 
4009
  usage(1);                                     /* Print version */
3785
4010
  if (connected)
3786
4011
  {
3787
 
    tee_fprintf(stdout, "\nConnection id:\t\t%lu\n",drizzle_thread_id(&drizzle));
 
4012
    tee_fprintf(stdout, "\nConnection id:\t\t%lu\n",mysql_thread_id(&mysql));
3788
4013
    /*
3789
4014
      Don't remove "limit 1",
3790
4015
      it is protection againts SQL_SELECT_LIMIT=0
3791
4016
    */
3792
 
    if (!drizzle_query(&drizzle,"select DATABASE(), USER() limit 1") &&
3793
 
        (result=drizzle_use_result(&drizzle)))
 
4017
    if (!mysql_query(&mysql,"select DATABASE(), USER() limit 1") &&
 
4018
        (result=mysql_use_result(&mysql)))
3794
4019
    {
3795
 
      DRIZZLE_ROW cur=drizzle_fetch_row(result);
 
4020
      MYSQL_ROW cur=mysql_fetch_row(result);
3796
4021
      if (cur)
3797
4022
      {
3798
4023
        tee_fprintf(stdout, "Current database:\t%s\n", cur[0] ? cur[0] : "");
3799
4024
        tee_fprintf(stdout, "Current user:\t\t%s\n", cur[1]);
3800
4025
      }
3801
 
      drizzle_free_result(result);
 
4026
      mysql_free_result(result);
3802
4027
    }
3803
4028
    tee_puts("SSL:\t\t\tNot in use", stdout);
3804
4029
  }
3818
4043
  tee_fprintf(stdout, "Current pager:\t\t%s\n", pager);
3819
4044
  tee_fprintf(stdout, "Using outfile:\t\t'%s'\n", opt_outfile ? outfile : "");
3820
4045
  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)))
 
4046
  tee_fprintf(stdout, "Server version:\t\t%s\n", server_version_string(&mysql));
 
4047
  tee_fprintf(stdout, "Protocol version:\t%d\n", mysql_get_proto_info(&mysql));
 
4048
  tee_fprintf(stdout, "Connection:\t\t%s\n", mysql_get_host_info(&mysql));
 
4049
  if ((id= mysql_insert_id(&mysql)))
3825
4050
    tee_fprintf(stdout, "Insert id:\t\t%s\n", llstr(id, buff));
3826
4051
 
3827
4052
  /* "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)))
 
4053
  if (!mysql_query(&mysql,"select @@character_set_client, @@character_set_connection, @@character_set_server, @@character_set_database limit 1") &&
 
4054
      (result=mysql_use_result(&mysql)))
3830
4055
  {
3831
 
    DRIZZLE_ROW cur=drizzle_fetch_row(result);
 
4056
    MYSQL_ROW cur=mysql_fetch_row(result);
3832
4057
    if (cur)
3833
4058
    {
3834
4059
      tee_fprintf(stdout, "Server characterset:\t%s\n", cur[2] ? cur[2] : "");
3836
4061
      tee_fprintf(stdout, "Client characterset:\t%s\n", cur[0] ? cur[0] : "");
3837
4062
      tee_fprintf(stdout, "Conn.  characterset:\t%s\n", cur[1] ? cur[1] : "");
3838
4063
    }
3839
 
    drizzle_free_result(result);
 
4064
    mysql_free_result(result);
 
4065
  }
 
4066
  else
 
4067
  {
 
4068
    /* Probably pre-4.1 server */
 
4069
    tee_fprintf(stdout, "Client characterset:\t%s\n", charset_info->csname);
 
4070
    tee_fprintf(stdout, "Server characterset:\t%s\n", mysql.charset->csname);
3840
4071
  }
3841
4072
 
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);
 
4073
#ifndef EMBEDDED_LIBRARY
 
4074
  if (strstr(mysql_get_host_info(&mysql),"TCP/IP") || ! mysql.unix_socket)
 
4075
    tee_fprintf(stdout, "TCP port:\t\t%d\n", mysql.port);
3844
4076
  else
3845
 
    tee_fprintf(stdout, "UNIX socket:\t\t%s\n", drizzle.unix_socket);
3846
 
  if (drizzle.net.compress)
 
4077
    tee_fprintf(stdout, "UNIX socket:\t\t%s\n", mysql.unix_socket);
 
4078
  if (mysql.net.compress)
3847
4079
    tee_fprintf(stdout, "Protocol:\t\tCompressed\n");
 
4080
#endif
3848
4081
 
 
4082
  if ((status_str= mysql_stat(&mysql)) && !mysql_error(&mysql)[0])
 
4083
  {
 
4084
    ulong sec;
 
4085
    const char *pos= strchr(status_str,' ');
 
4086
    /* print label */
 
4087
    tee_fprintf(stdout, "%.*s\t\t\t", (int) (pos-status_str), status_str);
 
4088
    if ((status_str= str2int(pos,10,0,LONG_MAX,(long*) &sec)))
 
4089
    {
 
4090
      nice_time((double) sec,buff,0);
 
4091
      tee_puts(buff, stdout);                   /* print nice time */
 
4092
      while (*status_str == ' ')
 
4093
        status_str++;  /* to next info */
 
4094
      tee_putc('\n', stdout);
 
4095
      tee_puts(status_str, stdout);
 
4096
    }
 
4097
  }
3849
4098
  if (safe_updates)
3850
4099
  {
3851
4100
    vidattr(A_BOLD);
3863
4112
}
3864
4113
 
3865
4114
static const char *
3866
 
server_version_string(DRIZZLE *con)
 
4115
server_version_string(MYSQL *con)
3867
4116
{
3868
4117
  static char buf[MAX_SERVER_VERSION_LENGTH] = "";
3869
4118
 
3871
4120
  if (buf[0] == '\0')
3872
4121
  {
3873
4122
    char *bufp = buf;
3874
 
    DRIZZLE_RES *result;
 
4123
    MYSQL_RES *result;
3875
4124
 
3876
 
    bufp= stpncpy(buf, drizzle_get_server_info(con), sizeof buf);
 
4125
    bufp= strnmov(buf, mysql_get_server_info(con), sizeof buf);
3877
4126
 
3878
4127
    /* "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)))
 
4128
    if (!mysql_query(con, "select @@version_comment limit 1") &&
 
4129
        (result = mysql_use_result(con)))
3881
4130
    {
3882
 
      DRIZZLE_ROW cur = drizzle_fetch_row(result);
 
4131
      MYSQL_ROW cur = mysql_fetch_row(result);
3883
4132
      if (cur && cur[0])
3884
4133
      {
3885
4134
        bufp = strxnmov(bufp, sizeof buf - (bufp - buf), " ", cur[0], NullS);
3886
4135
      }
3887
 
      drizzle_free_result(result);
 
4136
      mysql_free_result(result);
3888
4137
    }
3889
4138
 
3890
4139
    /* str*nmov doesn't guarantee NUL-termination */
3968
4217
 
3969
4218
 
3970
4219
static int
3971
 
put_error(DRIZZLE *con)
 
4220
put_error(MYSQL *con)
3972
4221
{
3973
 
  return put_info(drizzle_error(con), INFO_ERROR, drizzle_errno(con),
3974
 
                  drizzle_sqlstate(con));
 
4222
  return put_info(mysql_error(con), INFO_ERROR, mysql_errno(con),
 
4223
                  mysql_sqlstate(con));
3975
4224
}
3976
4225
 
3977
4226
 
3978
 
static void remove_cntrl(string *buffer)
 
4227
static void remove_cntrl(GString *buffer)
3979
4228
{
3980
 
  const char *start=  buffer->c_str();
3981
 
  const char *end= start + (buffer->length());
 
4229
  char *start=  buffer->str;
 
4230
  char *end= start + (buffer->len);
3982
4231
  while (start < end && !my_isgraph(charset_info,end[-1]))
3983
4232
    end--;
3984
 
  uint pos_to_truncate= (end-start);
3985
 
  if (buffer->length() > pos_to_truncate)
3986
 
    buffer->erase(pos_to_truncate);
 
4233
  uint chars_to_truncate = end-start;
 
4234
  if (buffer->len > chars_to_truncate)
 
4235
    g_string_truncate(buffer, chars_to_truncate);
3987
4236
}
3988
4237
 
3989
4238
 
4031
4280
}
4032
4281
 
4033
4282
#include <sys/times.h>
4034
 
#ifdef _SC_CLK_TCK        // For mit-pthreads
 
4283
#ifdef _SC_CLK_TCK                              // For mit-pthreads
4035
4284
#undef CLOCKS_PER_SEC
4036
4285
#define CLOCKS_PER_SEC (sysconf(_SC_CLK_TCK))
4037
4286
#endif
4038
4287
 
4039
 
static uint32_t start_timer(void)
 
4288
static ulong start_timer(void)
4040
4289
{
4041
4290
  struct tms tms_tmp;
4042
4291
  return times(&tms_tmp);
4044
4293
 
4045
4294
 
4046
4295
/**
4047
 
   Write as many as 52+1 bytes to buff, in the form of a legible
4048
 
   duration of time.
 
4296
   Write as many as 52+1 bytes to buff, in the form of a legible duration of time.
4049
4297
 
4050
4298
   len("4294967296 days, 23 hours, 59 minutes, 60.00 seconds")  ->  52
4051
4299
*/
4052
4300
static void nice_time(double sec,char *buff,bool part_second)
4053
4301
{
4054
 
  uint32_t tmp;
 
4302
  ulong tmp;
4055
4303
  if (sec >= 3600.0*24)
4056
4304
  {
4057
 
    tmp=(uint32_t) floor(sec/(3600.0*24));
 
4305
    tmp=(ulong) floor(sec/(3600.0*24));
4058
4306
    sec-=3600.0*24*tmp;
4059
4307
    buff=int10_to_str((long) tmp, buff, 10);
4060
 
    buff=stpcpy(buff,tmp > 1 ? " days " : " day ");
 
4308
    buff=strmov(buff,tmp > 1 ? " days " : " day ");
4061
4309
  }
4062
4310
  if (sec >= 3600.0)
4063
4311
  {
4064
 
    tmp=(uint32_t) floor(sec/3600.0);
 
4312
    tmp=(ulong) floor(sec/3600.0);
4065
4313
    sec-=3600.0*tmp;
4066
4314
    buff=int10_to_str((long) tmp, buff, 10);
4067
 
    buff=stpcpy(buff,tmp > 1 ? " hours " : " hour ");
 
4315
    buff=strmov(buff,tmp > 1 ? " hours " : " hour ");
4068
4316
  }
4069
4317
  if (sec >= 60.0)
4070
4318
  {
4071
 
    tmp=(uint32_t) floor(sec/60.0);
 
4319
    tmp=(ulong) floor(sec/60.0);
4072
4320
    sec-=60.0*tmp;
4073
4321
    buff=int10_to_str((long) tmp, buff, 10);
4074
 
    buff=stpcpy(buff," min ");
 
4322
    buff=strmov(buff," min ");
4075
4323
  }
4076
4324
  if (part_second)
4077
4325
    sprintf(buff,"%.2f sec",sec);
4080
4328
}
4081
4329
 
4082
4330
 
4083
 
static void end_timer(uint32_t start_time,char *buff)
 
4331
static void end_timer(ulong start_time,char *buff)
4084
4332
{
4085
4333
  nice_time((double) (start_timer() - start_time) /
4086
4334
            CLOCKS_PER_SEC,buff,1);
4087
4335
}
4088
4336
 
4089
4337
 
4090
 
static void drizzle_end_timer(uint32_t start_time,char *buff)
 
4338
static void mysql_end_timer(ulong start_time,char *buff)
4091
4339
{
4092
4340
  buff[0]=' ';
4093
4341
  buff[1]='(';
4094
4342
  end_timer(start_time,buff+2);
4095
 
  stpcpy(strchr(buff, '\0'),")");
 
4343
  strmov(strend(buff),")");
4096
4344
}
4097
4345
 
4098
4346
static const char * construct_prompt()
4099
4347
{
4100
4348
  // Erase the old prompt
4101
4349
  assert(processed_prompt!=NULL);
4102
 
  processed_prompt->clear();
 
4350
  g_string_truncate(processed_prompt, 0);
4103
4351
 
4104
4352
  // Get the date struct
4105
4353
  time_t  lclock = time(NULL);
4110
4358
  {
4111
4359
    if (*c != PROMPT_CHAR)
4112
4360
    {
4113
 
      processed_prompt->append(c, 1);
 
4361
      g_string_append_c(processed_prompt, c[0]);
4114
4362
    }
4115
4363
    else
4116
4364
    {
4127
4375
        break;
4128
4376
      case 'v':
4129
4377
        if (connected)
4130
 
          processed_prompt->append(drizzle_get_server_info(&drizzle));
 
4378
          g_string_append(processed_prompt, mysql_get_server_info(&mysql));
4131
4379
        else
4132
 
          processed_prompt->append("not_connected");
 
4380
          g_string_append(processed_prompt, "not_connected");
4133
4381
        break;
4134
4382
      case 'd':
4135
 
        processed_prompt->append(current_db ? current_db : "(none)");
 
4383
        g_string_append(processed_prompt, current_db ? current_db : "(none)");
4136
4384
        break;
4137
4385
      case 'h':
4138
4386
      {
4139
4387
        const char *prompt;
4140
 
        prompt= connected ? drizzle_get_host_info(&drizzle) : "not_connected";
 
4388
        prompt= connected ? mysql_get_host_info(&mysql) : "not_connected";
4141
4389
        if (strstr(prompt, "Localhost"))
4142
 
          processed_prompt->append("localhost");
 
4390
          g_string_append(processed_prompt, "localhost");
4143
4391
        else
4144
4392
        {
4145
 
          const char *end=strrchr(prompt,' ');
4146
 
          if (end != NULL)
4147
 
            processed_prompt->append(prompt, (end-prompt));
 
4393
          const char *end=strcend(prompt,' ');
 
4394
          g_string_append_len(processed_prompt, prompt, (gssize) (end-prompt));
4148
4395
        }
4149
4396
        break;
4150
4397
      }
4152
4399
      {
4153
4400
        if (!connected)
4154
4401
        {
4155
 
          processed_prompt->append("not_connected");
 
4402
          g_string_append(processed_prompt, "not_connected");
4156
4403
          break;
4157
4404
        }
4158
4405
 
4159
 
        const char *host_info = drizzle_get_host_info(&drizzle);
 
4406
        const char *host_info = mysql_get_host_info(&mysql);
4160
4407
        if (strstr(host_info, "memory"))
4161
4408
        {
4162
 
          processed_prompt->append(drizzle.host);
 
4409
          g_string_append(processed_prompt, mysql.host );
4163
4410
        }
4164
4411
        else if (strstr(host_info,"TCP/IP") ||
4165
 
                 !drizzle.unix_socket)
4166
 
          add_int_to_prompt(drizzle.port);
 
4412
                 !mysql.unix_socket)
 
4413
          add_int_to_prompt(mysql.port);
4167
4414
        else
4168
4415
        {
4169
 
          char *pos=strrchr(drizzle.unix_socket,'/');
4170
 
          processed_prompt->append(pos ? pos+1 : drizzle.unix_socket);
 
4416
          char *pos=strrchr(mysql.unix_socket,'/');
 
4417
          g_string_append(processed_prompt, pos ? pos+1 : mysql.unix_socket);
4171
4418
        }
4172
4419
      }
4173
4420
      break;
4174
4421
      case 'U':
4175
4422
        if (!full_username)
4176
4423
          init_username();
4177
 
        processed_prompt->append(full_username ? full_username :
4178
 
                                 (current_user ?  current_user : "(unknown)"));
 
4424
        g_string_append(processed_prompt, full_username ? full_username :
 
4425
                        (current_user ?  current_user : "(unknown)"));
4179
4426
        break;
4180
4427
      case 'u':
4181
4428
        if (!full_username)
4182
4429
          init_username();
4183
 
        processed_prompt->append(part_username ? part_username :
4184
 
                                 (current_user ?  current_user : "(unknown)"));
 
4430
        g_string_append(processed_prompt, part_username ? part_username :
 
4431
                        (current_user ?  current_user : "(unknown)"));
4185
4432
        break;
4186
4433
      case PROMPT_CHAR:
4187
 
        {
4188
 
          char c= PROMPT_CHAR;
4189
 
          processed_prompt->append(&c, 1);
4190
 
        }
 
4434
        g_string_append_c(processed_prompt, PROMPT_CHAR);
4191
4435
        break;
4192
4436
      case 'n':
4193
 
        {
4194
 
          char c= '\n';
4195
 
          processed_prompt->append(&c, 1);
4196
 
        }
 
4437
        g_string_append_c(processed_prompt, '\n');
4197
4438
        break;
4198
4439
      case ' ':
4199
4440
      case '_':
4200
 
        {
4201
 
          char c= ' ';
4202
 
          processed_prompt->append(&c, 1);
4203
 
        }
 
4441
        g_string_append_c(processed_prompt, ' ');
4204
4442
        break;
4205
4443
      case 'R':
4206
4444
        if (t->tm_hour < 10)
4207
 
          add_int_to_prompt(0);
 
4445
          g_string_append_c(processed_prompt, '0');
4208
4446
        add_int_to_prompt(t->tm_hour);
4209
4447
        break;
4210
4448
      case 'r':
4212
4450
        if (getHour == 0)
4213
4451
          getHour=12;
4214
4452
        if (getHour < 10)
4215
 
          add_int_to_prompt(0);
 
4453
          g_string_append_c(processed_prompt, '0');
4216
4454
        add_int_to_prompt(getHour);
4217
4455
        break;
4218
4456
      case 'm':
4219
4457
        if (t->tm_min < 10)
4220
 
          add_int_to_prompt(0);
 
4458
          g_string_append_c(processed_prompt, '0');
4221
4459
        add_int_to_prompt(t->tm_min);
4222
4460
        break;
4223
4461
      case 'y':
4224
4462
        getYear = t->tm_year % 100;
4225
4463
        if (getYear < 10)
4226
 
          add_int_to_prompt(0);
 
4464
          g_string_append_c(processed_prompt, '0');
4227
4465
        add_int_to_prompt(getYear);
4228
4466
        break;
4229
4467
      case 'Y':
4231
4469
        break;
4232
4470
      case 'D':
4233
4471
        dateTime = ctime(&lclock);
4234
 
        processed_prompt->append(strtok(dateTime,"\n"));
 
4472
        g_string_append(processed_prompt, strtok(dateTime,"\n"));
4235
4473
        break;
4236
4474
      case 's':
4237
4475
        if (t->tm_sec < 10)
4238
 
          add_int_to_prompt(0);
 
4476
          g_string_append_c(processed_prompt, '0');
4239
4477
        add_int_to_prompt(t->tm_sec);
4240
4478
        break;
4241
4479
      case 'w':
4242
 
        processed_prompt->append(day_names[t->tm_wday]);
 
4480
        g_string_append(processed_prompt, (day_names[t->tm_wday]));
4243
4481
        break;
4244
4482
      case 'P':
4245
 
        processed_prompt->append(t->tm_hour < 12 ? "am" : "pm");
 
4483
        g_string_append(processed_prompt, t->tm_hour < 12 ? "am" : "pm");
4246
4484
        break;
4247
4485
      case 'o':
4248
4486
        add_int_to_prompt(t->tm_mon+1);
4249
4487
        break;
4250
4488
      case 'O':
4251
 
        processed_prompt->append(month_names[t->tm_mon]);
 
4489
        g_string_append(processed_prompt, month_names[t->tm_mon]);
4252
4490
        break;
4253
4491
      case '\'':
4254
 
        processed_prompt->append("'");
 
4492
        g_string_append(processed_prompt, "'");
4255
4493
        break;
4256
4494
      case '"':
4257
 
        processed_prompt->append("\"");
 
4495
        g_string_append_c(processed_prompt, '"');
4258
4496
        break;
4259
4497
      case 'S':
4260
 
        processed_prompt->append(";");
 
4498
        g_string_append_c(processed_prompt, ';');
4261
4499
        break;
4262
4500
      case 't':
4263
 
        processed_prompt->append("\t");
 
4501
        g_string_append_c(processed_prompt, '\t');
4264
4502
        break;
4265
4503
      case 'l':
4266
 
        processed_prompt->append(delimiter_str);
 
4504
        g_string_append(processed_prompt, delimiter_str);
4267
4505
        break;
4268
4506
      default:
4269
 
        processed_prompt->append(c, 1);
 
4507
        g_string_append(processed_prompt, c);
4270
4508
      }
4271
4509
    }
4272
4510
  }
4273
 
  return processed_prompt->c_str();
 
4511
  // TODO: Is this needed with GString?
 
4512
  g_string_append_c(processed_prompt, '\0');
 
4513
  return processed_prompt->str;
4274
4514
}
4275
4515
 
4276
4516
 
4277
4517
static void add_int_to_prompt(int toadd)
4278
4518
{
4279
4519
  char buffer[16];
4280
 
  int10_to_str(toadd, buffer, 10);
4281
 
  processed_prompt->append(buffer);
 
4520
  int10_to_str(toadd,buffer,10);
 
4521
  g_string_append(processed_prompt, buffer);
4282
4522
}
4283
4523
 
4284
4524
static void init_username()
4286
4526
  my_free(full_username,MYF(MY_ALLOW_ZERO_PTR));
4287
4527
  my_free(part_username,MYF(MY_ALLOW_ZERO_PTR));
4288
4528
 
4289
 
  DRIZZLE_RES *result;
4290
 
  if (!drizzle_query(&drizzle,"select USER()") &&
4291
 
      (result=drizzle_use_result(&drizzle)))
 
4529
  MYSQL_RES *result;
 
4530
  if (!mysql_query(&mysql,"select USER()") &&
 
4531
      (result=mysql_use_result(&mysql)))
4292
4532
  {
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
 
4533
    MYSQL_ROW cur=mysql_fetch_row(result);
 
4534
    full_username=g_strdup(cur[0]);
 
4535
    part_username=g_strdup(strtok(cur[0],"@"));
 
4536
    (void) mysql_fetch_row(result);             // Read eof
4297
4537
  }
4298
4538
}
4299
4539
 
4300
 
static int com_prompt(string *buffer __attribute__((unused)),
4301
 
                      const char *line)
 
4540
static int com_prompt(GString *buffer __attribute__((__unused__)), char *line)
4302
4541
{
4303
4542
  char *ptr=strchr(line, ' ');
4304
4543
  prompt_counter = 0;
4305
 
  my_free(current_prompt, MYF(MY_ALLOW_ZERO_PTR));
4306
 
  current_prompt= strdup(ptr ? ptr+1 : default_prompt);
 
4544
  my_free(current_prompt,MYF(MY_ALLOW_ZERO_PTR));
 
4545
  current_prompt=g_strdup(ptr ? ptr+1 : default_prompt->str);
4307
4546
  if (!ptr)
4308
4547
    tee_fprintf(stdout, "Returning to default PROMPT of %s\n",
4309
 
                default_prompt);
 
4548
                default_prompt->str);
4310
4549
  else
4311
4550
    tee_fprintf(stdout, "PROMPT set to '%s'\n", current_prompt);
4312
4551
  return 0;
4313
4552
}
4314
 
 
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 NullS
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 */