36
36
#include "client_priv.h"
37
#include <mystrings/m_ctype.h>
38
38
#include <stdarg.h>
40
39
#ifndef __GNU_LIBRARY__
41
#define __GNU_LIBRARY__ // Skip warnings in getopt.h
40
#define __GNU_LIBRARY__ // Skip warnings in getopt.h
43
42
#include <readline/history.h>
44
43
#include "my_readline.h"
45
44
#include <signal.h>
45
#include <vio/violite.h>
46
#include <sys/ioctl.h>
48
49
#if defined(USE_LIBEDIT_INTERFACE) && defined(HAVE_LOCALE_H)
49
50
#include <locale.h>
54
53
const char *VER= "14.14";
56
55
/* Don't try to make a nice table if the data is too big */
57
#define MAX_COLUMN_LENGTH 1024
56
#define MAX_COLUMN_LENGTH 1024
59
58
/* Buffer to hold 'version' and 'version_comment' */
60
59
#define MAX_SERVER_VERSION_LENGTH 128
62
/* Array of options to pass to libemysqld */
61
/* Array of options to pass to libdrizzled */
63
62
#define MAX_SERVER_ARGS 64
65
void* sql_alloc(unsigned size); // Don't use mysqld alloc for these
64
void* sql_alloc(unsigned size); // Don't use drizzled alloc for these
66
65
void sql_element_free(void *ptr);
68
67
#if defined(HAVE_CURSES_H) && defined(HAVE_TERM_H)
144
156
static bool column_types_flag;
145
157
static bool preserve_comments= 0;
146
158
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;
159
static int verbose=0,opt_silent=0,opt_drizzle_port=0, opt_local_infile=0;
148
160
static uint my_end_arg;
149
static char * opt_mysql_unix_port=0;
161
static char * opt_drizzle_unix_port=0;
150
162
static int connect_flag=CLIENT_INTERACTIVE;
151
163
static char *current_host,*current_db,*current_user=0,*opt_password=0,
152
164
*delimiter_str= 0,*current_prompt=0,
153
165
*default_charset= (char*) MYSQL_DEFAULT_CHARSET_NAME;
154
166
static char *histfile;
155
167
static char *histfile_tmp;
156
static GString *glob_buffer;
157
static GString *processed_prompt= NULL;
158
static GString *default_prompt= NULL;
168
static DYNAMIC_STRING *glob_buffer;
169
static DYNAMIC_STRING *processed_prompt= NULL;
170
static char *default_prompt= NULL;
159
171
static char *full_username=0,*part_username=0;
160
static int wait_time = 5;
161
172
static STATUS status;
162
173
static uint32_t select_limit;
163
174
static uint32_t max_join_size;
164
175
static ulong opt_connect_timeout= 0;
165
static char mysql_charsets_dir[FN_REFLEN+1];
176
static char drizzle_charsets_dir[FN_REFLEN+1];
166
177
static const char *xmlmeta[] = {
199
210
static int get_options(int argc,char **argv);
200
211
bool get_one_option(int optid, const struct my_option *opt,
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*);
213
static int com_quit(DYNAMIC_STRING *str,char*),
214
com_go(DYNAMIC_STRING *str,char*), com_ego(DYNAMIC_STRING *str,char*),
215
com_print(DYNAMIC_STRING *str,char*),
216
com_help(DYNAMIC_STRING *str,char*), com_clear(DYNAMIC_STRING *str,char*),
217
com_connect(DYNAMIC_STRING *str,char*), com_status(DYNAMIC_STRING *str,char*),
218
com_use(DYNAMIC_STRING *str,char*), com_source(DYNAMIC_STRING *str, char*),
219
com_rehash(DYNAMIC_STRING *str, char*), com_tee(DYNAMIC_STRING *str, char*),
220
com_notee(DYNAMIC_STRING *str, char*), com_charset(DYNAMIC_STRING *str,char*),
221
com_prompt(DYNAMIC_STRING *str, char*), com_delimiter(DYNAMIC_STRING *str, char*),
222
com_warnings(DYNAMIC_STRING *str, char*), com_nowarnings(DYNAMIC_STRING *str, char*),
223
com_nopager(DYNAMIC_STRING *str, char*), com_pager(DYNAMIC_STRING *str, char*);
214
225
static int read_and_execute(bool interactive);
215
226
static int sql_connect(char *host,char *database,char *user,char *password,
217
static const char *server_version_string(MYSQL *mysql);
228
static const char *server_version_string(DRIZZLE *drizzle);
218
229
static int put_info(const char *str,INFO_TYPE info,uint error,
219
230
const char *sql_state);
220
static int put_error(MYSQL *mysql);
231
static int put_error(DRIZZLE *drizzle);
221
232
static void safe_put_field(const char *pos,ulong length);
222
233
static void xmlencode_print(const char *src, uint length);
223
234
static void init_pager(void);
228
239
static char *get_arg(char *line, bool get_next_arg);
229
240
static void init_username(void);
230
241
static void add_int_to_prompt(int toadd);
231
static int get_result_width(MYSQL_RES *res);
232
static int get_field_disp_length(MYSQL_FIELD * field);
242
static int get_result_width(DRIZZLE_RES *res);
243
static int get_field_disp_length(DRIZZLE_FIELD * field);
234
245
/* A structure which contains information on the commands this program
235
246
can understand. */
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. */
248
const char *name; /* User printable name of the function. */
249
char cmd_char; /* msql command character */
250
int (*func)(DYNAMIC_STRING *str,char *); /* Function to call to do the job. */
251
bool takes_params; /* Max parameters for command */
252
const char *doc; /* Documentation for this function. */
250
261
{ "delimiter", 'd', com_delimiter, 1,
251
262
"Set statement delimiter. NOTE: Takes the rest of the line as new delimiter." },
252
263
{ "ego", 'G', com_ego, 0,
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." },
264
"Send command to drizzle server, display result vertically."},
265
{ "exit", 'q', com_quit, 0, "Exit drizzle. Same as quit."},
266
{ "go", 'g', com_go, 0, "Send command to drizzle server." },
256
267
{ "help", 'h', com_help, 1, "Display this help." },
257
268
{ "nopager",'n', com_nopager,0, "Disable pager, print to stdout." },
258
269
{ "notee", 't', com_notee, 0, "Don't write into outfile." },
259
270
{ "pager", 'P', com_pager, 1,
260
271
"Set PAGER [to_pager]. Print the query results via PAGER." },
261
272
{ "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." },
273
{ "prompt", 'R', com_prompt, 1, "Change your drizzle prompt."},
274
{ "quit", 'q', com_quit, 0, "Quit drizzle." },
264
275
{ "rehash", '#', com_rehash, 0, "Rebuild completion hash." },
265
276
{ "source", '.', com_source, 1,
266
277
"Execute an SQL script file. Takes a file name as an argument."},
985
996
{ (char *)NULL, 0, 0, 0, ""}
988
static const char *load_default_groups[]= { "mysql","client",0 };
999
static const char *load_default_groups[]= { "drizzle","client",0 };
990
1001
static int embedded_server_arg_count= 0;
991
1002
static char *embedded_server_args[MAX_SERVER_ARGS];
992
static const char *embedded_server_groups[]=
993
{ "server", "mysql_SERVER", 0 };
995
1004
int history_length;
996
1005
static int not_in_history(const char *line);
997
1006
static void initialize_readline (const char *name);
998
static void fix_history(GString *final_command);
1007
static void fix_history(DYNAMIC_STRING *final_command);
1000
1009
static COMMANDS *find_command(char *name,char cmd_name);
1001
static bool add_line(GString *buffer,char *line,char *in_string,
1010
static bool add_line(DYNAMIC_STRING *buffer,char *line,char *in_string,
1002
1011
bool *ml_comment);
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);
1012
static void remove_cntrl(DYNAMIC_STRING *buffer);
1013
static void print_table_data(DRIZZLE_RES *result);
1014
static void print_table_data_html(DRIZZLE_RES *result);
1015
static void print_table_data_xml(DRIZZLE_RES *result);
1016
static void print_tab_data(DRIZZLE_RES *result);
1017
static void print_table_data_vertically(DRIZZLE_RES *result);
1009
1018
static void print_warnings(void);
1010
1019
static ulong start_timer(void);
1011
1020
static void end_timer(ulong start_time,char *buff);
1012
static void mysql_end_timer(ulong start_time,char *buff);
1021
static void drizzle_end_timer(ulong start_time,char *buff);
1013
1022
static void nice_time(double sec,char *buff,bool part_second);
1014
extern sig_handler mysql_end(int sig);
1023
extern sig_handler drizzle_end(int sig);
1015
1024
extern sig_handler handle_sigint(int sig);
1016
1025
#if defined(HAVE_TERMIOS_H) && defined(GWINSZ_IN_SYS_IOCTL)
1017
1026
static sig_handler window_resize(int sig);
1081
if (mysql_server_init(embedded_server_arg_count, embedded_server_args,
1082
(char**) embedded_server_groups))
1085
free_defaults(defaults_argv);
1089
1093
completion_hash_init(&ht, 128);
1090
1094
init_alloc_root(&hash_mem_root, 16384, 0);
1091
bzero((char*) &mysql, sizeof(mysql));
1095
memset((char*) &drizzle, 0, sizeof(drizzle));
1092
1096
if (sql_connect(current_host,current_db,current_user,opt_password,
1095
quick= 1; // Avoid history
1099
quick= 1; // Avoid history
1096
1100
status.exit_status= 1;
1099
1103
if (!status.batch)
1100
ignore_errors=1; // Don't abort monitor
1104
ignore_errors=1; // Don't abort monitor
1102
1106
if (opt_sigint_ignore)
1103
1107
signal(SIGINT, SIG_IGN);
1105
1109
signal(SIGINT, handle_sigint); // Catch SIGINT to clean up
1106
signal(SIGQUIT, mysql_end); // Catch SIGQUIT to clean up
1110
signal(SIGQUIT, drizzle_end); // Catch SIGQUIT to clean up
1108
1112
#if defined(HAVE_TERMIOS_H) && defined(GWINSZ_IN_SYS_IOCTL)
1109
1113
/* Readline will call this if it installs a handler */
1115
1119
put_info("Welcome to the Drizzle client.. Commands end with ; or \\g.",
1116
1120
INFO_INFO,0,0);
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);
1122
glob_buffer= (DYNAMIC_STRING *)my_malloc(sizeof(DYNAMIC_STRING), MYF(0));
1123
init_dynamic_string(glob_buffer, "", 512, 512);
1125
/* this is a slight abuse of the DYNAMIC_STRING interface. deal. */
1126
sprintf(glob_buffer->str,
1127
"Your Drizzle connection id is %u\nServer version: %s\n",
1128
drizzle_thread_id(&drizzle), server_version_string(&drizzle));
1129
put_info(glob_buffer->str, INFO_INFO, 0, 0);
1130
dynstr_set(glob_buffer, NULL);
1124
1132
initialize_readline(my_progname);
1125
1133
if (!status.batch && !quick && !opt_html && !opt_xml)
1127
/* read-history from file, default ~/.mysql_history*/
1135
/* read-history from file, default ~/.drizzle_history*/
1128
1136
if (getenv("MYSQL_HISTFILE"))
1129
histfile=g_strdup(getenv("MYSQL_HISTFILE"));
1137
histfile= strdup(getenv("MYSQL_HISTFILE"));
1130
1138
else if (getenv("HOME"))
1132
1140
histfile=(char*) my_malloc((uint) strlen(getenv("HOME"))
1133
+ (uint) strlen("/.mysql_history")+2,
1141
+ (uint) strlen("/.drizzle_history")+2,
1136
sprintf(histfile,"%s/.mysql_history",getenv("HOME"));
1144
sprintf(histfile,"%s/.drizzle_history",getenv("HOME"));
1137
1145
char link_name[FN_REFLEN];
1138
1146
if (my_readlink(link_name, histfile, 0) == 0 &&
1139
1147
strncmp(link_name, "/dev/null", 10) == 0)
1141
/* The .mysql_history file is a symlink to /dev/null, don't use it */
1149
/* The .drizzle_history file is a symlink to /dev/null, don't use it */
1142
1150
my_free(histfile, MYF(MY_ALLOW_ZERO_PTR));
1189
1197
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);
1199
dynstr_free(glob_buffer);
1200
my_free(glob_buffer, MYF(MY_ALLOW_ZERO_PTR));
1201
if (processed_prompt)
1202
dynstr_free(processed_prompt);
1203
my_free(processed_prompt,MYF(MY_ALLOW_ZERO_PTR));
1196
1204
my_free(opt_password,MYF(MY_ALLOW_ZERO_PTR));
1197
my_free(opt_mysql_unix_port,MYF(MY_ALLOW_ZERO_PTR));
1205
my_free(opt_drizzle_unix_port,MYF(MY_ALLOW_ZERO_PTR));
1198
1206
my_free(histfile,MYF(MY_ALLOW_ZERO_PTR));
1199
1207
my_free(histfile_tmp,MYF(MY_ALLOW_ZERO_PTR));
1200
1208
my_free(current_db,MYF(MY_ALLOW_ZERO_PTR));
1221
1229
sig_handler handle_sigint(int sig)
1223
1231
char kill_buffer[40];
1224
MYSQL *kill_mysql= NULL;
1232
DRIZZLE *kill_drizzle= NULL;
1226
1234
/* terminate if no query being executed, or we already tried interrupting */
1227
1235
if (!executing_query || interrupted_query) {
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))
1239
kill_drizzle= drizzle_create(kill_drizzle);
1240
if (!drizzle_connect(kill_drizzle,current_host, current_user, opt_password,
1241
"", opt_drizzle_port, opt_drizzle_unix_port,0))
1238
1246
/* kill_buffer is always big enough because max length of %lu is 15 */
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);
1247
sprintf(kill_buffer, "KILL /*!50000 QUERY */ %u", drizzle_thread_id(&drizzle));
1248
drizzle_real_query(kill_drizzle, kill_buffer, strlen(kill_buffer));
1249
drizzle_close(kill_drizzle);
1242
1250
tee_fprintf(stdout, "Query aborted by Ctrl+C\n");
1244
1252
interrupted_query= 1;
1271
1279
(char**) &opt_rehash, (char**) &opt_rehash, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0,
1273
1281
{"no-auto-rehash", 'A',
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.",
1282
"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.",
1275
1283
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1276
1284
{"auto-vertical-output", OPT_AUTO_VERTICAL_OUTPUT,
1277
1285
"Automatically switch to vertical output mode if the result is wider than the terminal width.",
1312
1320
(char**) &ignore_errors, (char**) &ignore_errors, 0, GET_BOOL, NO_ARG, 0, 0,
1314
1322
{"named-commands", 'G',
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.",
1323
"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.",
1316
1324
(char**) &named_cmds, (char**) &named_cmds, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
1318
1326
{"no-named-commands", 'g',
1368
1376
"/etc/services, "
1370
1378
"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.",
1379
(char**) &opt_drizzle_port,
1380
(char**) &opt_drizzle_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1381
{"prompt", OPT_PROMPT, "Set the drizzle prompt to this value.",
1374
1382
(char**) ¤t_prompt, (char**) ¤t_prompt, 0, GET_STR_ALLOC,
1375
1383
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1376
{"protocol", OPT_MYSQL_PROTOCOL, "The protocol of connection (tcp,socket,pipe,memory).",
1384
{"protocol", OPT_DRIZZLE_PROTOCOL, "The protocol of connection (tcp,socket,pipe,memory).",
1377
1385
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1379
1387
"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.",
1386
1394
{"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,
1388
1396
{"socket", 'S', "Socket file to use for connection.",
1389
(char**) &opt_mysql_unix_port, (char**) &opt_mysql_unix_port, 0, GET_STR_ALLOC,
1397
(char**) &opt_drizzle_unix_port, (char**) &opt_drizzle_unix_port, 0, GET_STR_ALLOC,
1390
1398
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1391
1399
{"table", 't', "Output in table format.", (char**) &output_tables,
1392
1400
(char**) &output_tables, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1953
1941
// Flush previously accepted characters
1954
1942
if (out != line)
1956
g_string_append_len(buffer, line, (gssize) (out - line));
1944
dynstr_append_mem(buffer, line, (out - line));
1960
1948
// Flush possible comments in the buffer
1961
if (buffer->len != 0)
1949
if (buffer->length != 0)
1963
1951
if (com_go(buffer, 0) > 0) // < 0 is not fatal
1965
1953
assert(buffer!=NULL);
1966
g_string_truncate(buffer,0);
1954
dynstr_set(buffer, NULL);
1970
1958
Delimiter wants the get rest of the given line as argument to
1971
1959
allow one to change ';' to ';;' and back
1973
g_string_append(buffer,pos);
1961
dynstr_append(buffer,pos);
1974
1962
if (com_delimiter(buffer, pos) > 0)
1977
g_string_truncate(buffer,0);
1965
dynstr_set(buffer, NULL);
1980
1968
else if (!*ml_comment && !*in_string && is_prefix(pos, delimiter))
2113
2101
******************************************************************/
2104
static char **mysql_completion (const char *text, int start, int end);
2116
2105
static char *new_command_generator(const char *text, int);
2117
extern char **new_mysql_completion (const char *text, int start, int end);
2120
2108
Tell the GNU Readline library how to complete. We want to try to complete
2121
2109
on command names if this is the first word in the line, or on filenames
2125
#if defined(USE_NEW_READLINE_INTERFACE) || defined(USE_LIBEDIT_INTERFACE)
2126
extern char *no_completion(const char*,int);
2128
char *no_completion(void);
2129
char *no_completion(void)
2112
static char *no_completion(const char * a __attribute__((unused)),
2113
int b __attribute__((unused)))
2131
2115
/* No filename completion */
2136
2120
/* glues pieces of history back together if in pieces */
2137
static void fix_history(GString *final_command)
2121
static void fix_history(DYNAMIC_STRING *final_command)
2139
2123
int total_lines = 1;
2140
2124
const char *ptr = final_command->str;
2125
char str_char = '\0'; /* Character if we are in a string or not */
2141
2127
/* Converted buffer */
2142
GString * fixed_buffer;
2143
fixed_buffer = g_string_sized_new(16);
2144
char str_char = '\0'; /* Character if we are in a string or not */
2128
DYNAMIC_STRING *fixed_buffer=
2129
(DYNAMIC_STRING *)my_malloc(sizeof(DYNAMIC_STRING), MYF(0));
2131
init_dynamic_string(fixed_buffer, "", 512, 512);
2146
2133
/* find out how many lines we have and remove newlines */
2147
2134
while (*ptr != '\0')
2156
2143
str_char = *ptr;
2157
2144
else if (str_char == *ptr) /* close string */
2158
2145
str_char = '\0';
2159
g_string_append_len(fixed_buffer, ptr, 1);
2146
dynstr_append_mem(fixed_buffer, ptr, 1);
2163
2150
not in string, change to space
2164
2151
if in string, leave it alone
2166
g_string_append(fixed_buffer,(str_char == '\0') ? " " : "\n");
2153
dynstr_append(fixed_buffer,(str_char == '\0') ? " " : "\n");
2170
g_string_append_c(fixed_buffer, '\\');
2157
dynstr_append(fixed_buffer, "\\");
2171
2158
/* need to see if the backslash is escaping anything */
2175
2162
/* special characters that need escaping */
2176
2163
if (*ptr == '\'' || *ptr == '"' || *ptr == '\\')
2177
g_string_append_len(fixed_buffer, ptr, 1);
2164
dynstr_append_mem(fixed_buffer, ptr, 1);
2183
g_string_append_len(fixed_buffer, ptr, 1);
2170
dynstr_append_mem(fixed_buffer, ptr, 1);
2206
2193
static void initialize_readline (const char *name)
2208
2195
/* Allow conditional parsing of the ~/.inputrc file. */
2209
rl_readline_name= name;
2196
rl_readline_name= (char *)name;
2211
2198
/* Tell the completer that we want a crack first. */
2212
rl_attempted_completion_function= (rl_completion_func_t*)&new_mysql_completion;
2213
rl_completion_entry_function= (rl_compentry_func_t*)&no_completion;
2199
rl_attempted_completion_function= (typeof rl_attempted_completion_function)&new_mysql_completion;
2200
rl_completion_entry_function= (typeof rl_completion_entry_function)&no_completion;
2217
2205
Attempt to complete on the contents of TEXT. START and END show the
2218
2206
region of TEXT that contains the word to complete. We can use the
2219
2207
entire line in case we want to do some simple parsing. Return the
2220
2208
array of matches, or NULL if there aren't any.
2223
char **new_mysql_completion (const char *text,
2224
int start __attribute__((unused)),
2225
int end __attribute__((unused)))
2210
char **mysql_completion (const char *text,
2211
int start __attribute__((unused)),
2212
int end __attribute__((unused)))
2227
2214
if (!status.batch && !quick)
2215
#ifdef HAVE_DECL_COMPLETION_MATCHES
2216
return completion_matches(text, new_command_generator);
2228
2218
return rl_completion_matches(text, new_command_generator);
2230
2221
return (char**) 0;
2233
2225
static char *new_command_generator(const char *text,int state)
2235
2227
static int textlen;
2343
2335
/* hash Drizzle functions (to be implemented) */
2345
2337
/* hash all database names */
2346
if (mysql_query(&mysql,"show databases") == 0)
2338
if (drizzle_query(&drizzle,"show databases") == 0)
2348
if (!(databases = mysql_store_result(&mysql)))
2349
put_info(mysql_error(&mysql),INFO_INFO,0,0);
2340
if (!(databases = drizzle_store_result(&drizzle)))
2341
put_info(drizzle_error(&drizzle),INFO_INFO,0,0);
2352
while ((database_row=mysql_fetch_row(databases)))
2344
while ((database_row=drizzle_fetch_row(databases)))
2354
2346
char *str=strdup_root(&hash_mem_root, (char*) database_row[0]);
2356
2348
add_word(&ht,(char*) str);
2358
mysql_free_result(databases);
2350
drizzle_free_result(databases);
2361
2353
/* hash all table names */
2362
if (mysql_query(&mysql,"show tables")==0)
2354
if (drizzle_query(&drizzle,"show tables")==0)
2364
if (!(tables = mysql_store_result(&mysql)))
2365
put_info(mysql_error(&mysql),INFO_INFO,0,0);
2356
if (!(tables = drizzle_store_result(&drizzle)))
2357
put_info(drizzle_error(&drizzle),INFO_INFO,0,0);
2368
if (mysql_num_rows(tables) > 0 && !opt_silent && write_info)
2360
if (drizzle_num_rows(tables) > 0 && !opt_silent && write_info)
2370
2362
tee_fprintf(stdout, "\
2371
2363
Reading table information for completion of table and column names\n \
2372
2364
You can turn off this feature to get a quicker startup with -A\n\n");
2374
while ((table_row=mysql_fetch_row(tables)))
2366
while ((table_row=drizzle_fetch_row(tables)))
2376
2368
char *str=strdup_root(&hash_mem_root, (char*) table_row[0]);
2384
2376
/* hash all field names, both with the table prefix and without it */
2385
if (!tables) /* no tables */
2377
if (!tables) /* no tables */
2389
mysql_data_seek(tables,0);
2381
drizzle_data_seek(tables,0);
2390
2382
if (!(field_names= (char ***) alloc_root(&hash_mem_root,sizeof(char **) *
2391
(uint) (mysql_num_rows(tables)+1))))
2383
(uint) (drizzle_num_rows(tables)+1))))
2393
mysql_free_result(tables);
2385
drizzle_free_result(tables);
2397
while ((table_row=mysql_fetch_row(tables)))
2389
while ((table_row=drizzle_fetch_row(tables)))
2399
if ((fields=mysql_list_fields(&mysql,(const char*) table_row[0],NullS)))
2391
if ((fields=drizzle_list_fields(&drizzle,(const char*) table_row[0],NullS)))
2401
num_fields=mysql_num_fields(fields);
2393
num_fields=drizzle_num_fields(fields);
2402
2394
if (!(field_names[i] = (char **) alloc_root(&hash_mem_root,
2403
2395
sizeof(char *) *
2404
2396
(num_fields*2+1))))
2406
mysql_free_result(fields);
2398
drizzle_free_result(fields);
2409
2401
field_names[i][num_fields*2]= '\0';
2411
while ((sql_field=mysql_fetch_field(fields)))
2403
while ((sql_field=drizzle_fetch_field(fields)))
2413
2405
sprintf(buf,"%.64s.%.64s",table_row[0],sql_field->name);
2414
2406
field_names[i][j] = strdup_root(&hash_mem_root,buf);
2651
2643
tee_fprintf(stdout, "%s(\\%c) %s\n", buff,
2652
2644
commands[i].cmd_char, commands[i].doc);
2654
if (connected && mysql_get_server_version(&mysql) >= 40100)
2646
if (connected && drizzle_get_server_version(&drizzle) >= 40100)
2655
2647
put_info("\nFor server side help, type 'help contents'\n", INFO_INFO,0,0);
2661
com_clear(GString *buffer,char *line __attribute__((unused)))
2653
com_clear(DYNAMIC_STRING *buffer,char *line __attribute__((unused)))
2663
2655
if (status.add_to_history)
2664
2656
fix_history(buffer);
2665
g_string_truncate(buffer, 0);
2657
dynstr_set(buffer, NULL);
2670
com_charset(GString *buffer __attribute__((unused)), char *line)
2662
com_charset(DYNAMIC_STRING *buffer __attribute__((unused)), char *line)
2672
2664
char buff[256], *param;
2673
2665
CHARSET_INFO * new_cs;
2812
2802
print_table_data(result);
2813
2803
sprintf(buff,"%ld %s in set",
2814
(long) mysql_num_rows(result),
2815
(long) mysql_num_rows(result) == 1 ? "row" : "rows");
2804
(long) drizzle_num_rows(result),
2805
(long) drizzle_num_rows(result) == 1 ? "row" : "rows");
2817
if (mysql_errno(&mysql))
2818
error= put_error(&mysql);
2807
if (drizzle_errno(&drizzle))
2808
error= put_error(&drizzle);
2821
else if (mysql_affected_rows(&mysql) == ~(uint64_t) 0)
2811
else if (drizzle_affected_rows(&drizzle) == ~(uint64_t) 0)
2822
2812
strmov(buff,"Query OK");
2824
2814
sprintf(buff,"Query OK, %ld %s affected",
2825
(long) mysql_affected_rows(&mysql),
2826
(long) mysql_affected_rows(&mysql) == 1 ? "row" : "rows");
2815
(long) drizzle_affected_rows(&drizzle),
2816
(long) drizzle_affected_rows(&drizzle) == 1 ? "row" : "rows");
2828
2818
pos=strend(buff);
2829
if ((warnings= mysql_warning_count(&mysql)))
2819
if ((warnings= drizzle_warning_count(&drizzle)))
2838
2828
strmov(pos, time_buff);
2839
2829
put_info(buff,INFO_RESULT,0,0);
2840
if (mysql_info(&mysql))
2841
put_info(mysql_info(&mysql),INFO_RESULT,0,0);
2842
put_info("",INFO_RESULT,0,0); // Empty row
2830
if (drizzle_info(&drizzle))
2831
put_info(drizzle_info(&drizzle),INFO_RESULT,0,0);
2832
put_info("",INFO_RESULT,0,0); // Empty row
2844
if (result && !mysql_eof(result)) /* Something wrong when using quick */
2845
error= put_error(&mysql);
2834
if (result && !drizzle_eof(result)) /* Something wrong when using quick */
2835
error= put_error(&drizzle);
2846
2836
else if (unbuffered)
2847
2837
fflush(stdout);
2848
mysql_free_result(result);
2849
} while (!(err= mysql_next_result(&mysql)));
2838
drizzle_free_result(result);
2839
} while (!(err= drizzle_next_result(&drizzle)));
2851
error= put_error(&mysql);
2841
error= put_error(&drizzle);
2928
2918
static const char *fieldtype2str(enum enum_field_types type)
2930
2920
switch (type) {
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";
2921
case DRIZZLE_TYPE_BLOB: return "BLOB";
2922
case DRIZZLE_TYPE_NEWDATE: return "DATE";
2923
case DRIZZLE_TYPE_DATETIME: return "DATETIME";
2924
case DRIZZLE_TYPE_NEWDECIMAL: return "DECIMAL";
2925
case DRIZZLE_TYPE_DOUBLE: return "DOUBLE";
2926
case DRIZZLE_TYPE_ENUM: return "ENUM";
2927
case DRIZZLE_TYPE_LONG: return "LONG";
2928
case DRIZZLE_TYPE_LONGLONG: return "LONGLONG";
2929
case DRIZZLE_TYPE_NULL: return "NULL";
2930
case DRIZZLE_TYPE_SET: return "SET";
2931
case DRIZZLE_TYPE_SHORT: return "SHORT";
2932
case DRIZZLE_TYPE_STRING: return "STRING";
2933
case DRIZZLE_TYPE_TIME: return "TIME";
2934
case DRIZZLE_TYPE_TIMESTAMP: return "TIMESTAMP";
2935
case DRIZZLE_TYPE_TINY: return "TINY";
2936
case DRIZZLE_TYPE_VAR_STRING: return "VAR_STRING";
2948
2937
default: return "?-unknown-?";
3014
print_table_data(MYSQL_RES *result)
3002
print_table_data(DRIZZLE_RES *result)
3016
GString *separator = g_string_sized_new(256);
3005
DRIZZLE_FIELD *field;
3019
3006
bool *num_flag;
3007
DYNAMIC_STRING *separator=
3008
(DYNAMIC_STRING *)my_malloc(sizeof(DYNAMIC_STRING), MYF(0));
3009
init_dynamic_string(separator, "", 256, 256);
3021
num_flag=(bool*) my_malloc(sizeof(bool)*mysql_num_fields(result),
3011
num_flag=(bool*) my_malloc(sizeof(bool)*drizzle_num_fields(result),
3023
3013
if (column_types_flag)
3025
3015
print_field_types(result);
3026
if (!mysql_num_rows(result))
3016
if (!drizzle_num_rows(result))
3028
mysql_field_seek(result,0);
3018
drizzle_field_seek(result,0);
3030
separator = g_string_append_c(separator, '+');
3031
while ((field = mysql_fetch_field(result)))
3020
dynstr_append(separator, "+");
3021
while ((field = drizzle_fetch_field(result)))
3033
3023
uint length= column_names ? field->name_length : 0;
3041
3031
field->max_length=length;
3043
3033
for (x=0; x< (length+2); x++)
3044
g_string_append_c(separator, '-');
3045
g_string_append_c(separator, '+');
3034
dynstr_append(separator, "-");
3035
dynstr_append(separator, "+");
3047
// End marker for \0
3048
// TODO: Huh? Do we need this with GString?
3049
g_string_append_c(separator, '\0');
3051
3038
tee_puts((char*) separator->str, PAGER);
3052
3039
if (column_names)
3054
mysql_field_seek(result,0);
3041
drizzle_field_seek(result,0);
3055
3042
(void) tee_fputs("|", PAGER);
3056
for (uint off=0; (field = mysql_fetch_field(result)) ; off++)
3043
for (uint off=0; (field = drizzle_fetch_field(result)) ; off++)
3058
3045
uint name_length= (uint) strlen(field->name);
3059
3046
uint numcells= charset_info->cset->numcells(charset_info,
3253
print_table_data_xml(MYSQL_RES *result)
3240
print_table_data_xml(DRIZZLE_RES *result)
3256
MYSQL_FIELD *fields;
3243
DRIZZLE_FIELD *fields;
3258
mysql_field_seek(result,0);
3245
drizzle_field_seek(result,0);
3260
3247
tee_fputs("<?xml version=\"1.0\"?>\n\n<resultset statement=\"", PAGER);
3261
xmlencode_print(glob_buffer->str, glob_buffer->len);
3248
xmlencode_print(glob_buffer->str, glob_buffer->length);
3262
3249
tee_fputs("\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">",
3265
fields = mysql_fetch_fields(result);
3266
while ((cur = mysql_fetch_row(result)))
3252
fields = drizzle_fetch_fields(result);
3253
while ((cur = drizzle_fetch_row(result)))
3268
3255
if (interrupted_query)
3270
uint32_t *lengths=mysql_fetch_lengths(result);
3257
uint32_t *lengths=drizzle_fetch_lengths(result);
3271
3258
(void) tee_fputs("\n <row>\n", PAGER);
3272
for (uint i=0; i < mysql_num_fields(result); i++)
3259
for (uint i=0; i < drizzle_num_fields(result); i++)
3274
3261
tee_fprintf(PAGER, "\t<field name=\"");
3275
3262
xmlencode_print(fields[i].name, (uint) strlen(fields[i].name));
3303
3290
field->max_length=length;
3306
mysql_field_seek(result,0);
3307
for (uint row_count=1; (cur= mysql_fetch_row(result)); row_count++)
3293
drizzle_field_seek(result,0);
3294
for (uint row_count=1; (cur= drizzle_fetch_row(result)); row_count++)
3309
3296
if (interrupted_query)
3311
mysql_field_seek(result,0);
3298
drizzle_field_seek(result,0);
3312
3299
tee_fprintf(PAGER,
3313
3300
"*************************** %d. row ***************************\n", row_count);
3314
for (uint off=0; off < mysql_num_fields(result); off++)
3301
for (uint off=0; off < drizzle_num_fields(result); off++)
3316
field= mysql_fetch_field(result);
3303
field= drizzle_fetch_field(result);
3317
3304
tee_fprintf(PAGER, "%*s: ",(int) max_length,field->name);
3318
3305
tee_fprintf(PAGER, "%s\n",cur[off] ? (char*) cur[off] : "NULL");
3806
3793
if (!connected && reconnect())
3807
3794
return opt_reconnect ? -1 : 1; // Fatal error
3808
if (mysql_select_db(&mysql,tmp))
3795
if (drizzle_select_db(&drizzle,tmp))
3810
if (mysql_errno(&mysql) != CR_SERVER_GONE_ERROR)
3811
return put_error(&mysql);
3797
if (drizzle_errno(&drizzle) != CR_SERVER_GONE_ERROR)
3798
return put_error(&drizzle);
3813
3800
if (reconnect())
3814
3801
return opt_reconnect ? -1 : 1; // Fatal error
3815
if (mysql_select_db(&mysql,tmp))
3816
return put_error(&mysql);
3802
if (drizzle_select_db(&drizzle,tmp))
3803
return put_error(&drizzle);
3818
3805
my_free(current_db,MYF(MY_ALLOW_ZERO_PTR));
3819
current_db=g_strdup(tmp);
3806
current_db= strdup(tmp);
3820
3807
if (select_db > 1)
3821
3808
build_completion_hash(opt_rehash, 1);
3909
sql_real_connect(char *host,char *database,char *user,char *password,
3896
sql_connect(char *host,char *database,char *user,char *password,
3915
mysql_close(&mysql);
3902
drizzle_close(&drizzle);
3904
drizzle_create(&drizzle);
3918
3905
if (opt_connect_timeout)
3920
3907
uint timeout=opt_connect_timeout;
3921
mysql_options(&mysql,MYSQL_OPT_CONNECT_TIMEOUT,
3908
drizzle_options(&drizzle,DRIZZLE_OPT_CONNECT_TIMEOUT,
3922
3909
(char*) &timeout);
3924
3911
if (opt_compress)
3925
mysql_options(&mysql,MYSQL_OPT_COMPRESS,NullS);
3912
drizzle_options(&drizzle,DRIZZLE_OPT_COMPRESS,NullS);
3926
3913
if (opt_secure_auth)
3927
mysql_options(&mysql, MYSQL_SECURE_AUTH, (char *) &opt_secure_auth);
3914
drizzle_options(&drizzle, DRIZZLE_SECURE_AUTH, (char *) &opt_secure_auth);
3928
3915
if (using_opt_local_infile)
3929
mysql_options(&mysql,MYSQL_OPT_LOCAL_INFILE, (char*) &opt_local_infile);
3916
drizzle_options(&drizzle,DRIZZLE_OPT_LOCAL_INFILE, (char*) &opt_local_infile);
3930
3917
if (opt_protocol)
3931
mysql_options(&mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
3918
drizzle_options(&drizzle,DRIZZLE_OPT_PROTOCOL,(char*)&opt_protocol);
3932
3919
if (safe_updates)
3934
3921
char init_command[100];
3935
3922
sprintf(init_command,
3936
"SET SQL_SAFE_UPDATES=1,SQL_SELECT_LIMIT=%"PRIu32
3923
"SET SQL_SAFE_UPDATES=1,SQL_SELECT_LIMIT=%"PRIu32
3937
3924
",SQL_MAX_JOIN_SIZE=%"PRIu32,
3938
select_limit, max_join_size);
3939
mysql_options(&mysql, MYSQL_INIT_COMMAND, init_command);
3925
select_limit, max_join_size);
3926
drizzle_options(&drizzle, DRIZZLE_INIT_COMMAND, init_command);
3941
3928
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,
3929
drizzle_options(&drizzle, DRIZZLE_SET_CHARSET_NAME, default_charset);
3930
if (!drizzle_connect(&drizzle, host, user, password,
3931
database, opt_drizzle_port, opt_drizzle_unix_port,
3945
3932
connect_flag | CLIENT_MULTI_STATEMENTS))
3948
(mysql_errno(&mysql) != CR_CONN_HOST_ERROR &&
3949
mysql_errno(&mysql) != CR_CONNECTION_ERROR))
3935
(drizzle_errno(&drizzle) != CR_CONN_HOST_ERROR &&
3936
drizzle_errno(&drizzle) != CR_CONNECTION_ERROR))
3951
(void) put_error(&mysql);
3938
(void) put_error(&drizzle);
3952
3939
(void) fflush(stdout);
3953
return ignore_errors ? -1 : 1; // Abort
3940
return ignore_errors ? -1 : 1; // Abort
3955
return -1; // Retryable
3942
return -1; // Retryable
3958
mysql.reconnect= debug_info_flag; // We want to know if this happens
3945
drizzle.reconnect= debug_info_flag; // We want to know if this happens
3959
3946
build_completion_hash(opt_rehash, 1);
3965
sql_connect(char *host,char *database,char *user,char *password,uint silent)
3972
if ((error=sql_real_connect(host,database,user,password,wait_flag)) >= 0)
3976
tee_fputs("\n", stderr);
3977
(void) fflush(stderr);
3982
return ignore_errors ? -1 : 1;
3983
if (!message && !silent)
3986
tee_fputs("Waiting",stderr); (void) fflush(stderr);
3988
(void) sleep(wait_time);
3991
putc('.',stderr); (void) fflush(stderr);
4000
com_status(GString *buffer __attribute__((unused)),
3952
com_status(DYNAMIC_STRING *buffer __attribute__((unused)),
4001
3953
char *line __attribute__((unused)))
4003
3955
const char *status_str;
3958
DRIZZLE_RES *result;
4008
3960
tee_puts("--------------", stdout);
4009
usage(1); /* Print version */
3961
usage(1); /* Print version */
4012
tee_fprintf(stdout, "\nConnection id:\t\t%lu\n",mysql_thread_id(&mysql));
3964
tee_fprintf(stdout, "\nConnection id:\t\t%lu\n",drizzle_thread_id(&drizzle));
4014
3966
Don't remove "limit 1",
4015
3967
it is protection againts SQL_SELECT_LIMIT=0
4017
if (!mysql_query(&mysql,"select DATABASE(), USER() limit 1") &&
4018
(result=mysql_use_result(&mysql)))
3969
if (!drizzle_query(&drizzle,"select DATABASE(), USER() limit 1") &&
3970
(result=drizzle_use_result(&drizzle)))
4020
MYSQL_ROW cur=mysql_fetch_row(result);
3972
DRIZZLE_ROW cur=drizzle_fetch_row(result);
4023
3975
tee_fprintf(stdout, "Current database:\t%s\n", cur[0] ? cur[0] : "");
4024
3976
tee_fprintf(stdout, "Current user:\t\t%s\n", cur[1]);
4026
mysql_free_result(result);
3978
drizzle_free_result(result);
4028
3980
tee_puts("SSL:\t\t\tNot in use", stdout);
4043
3995
tee_fprintf(stdout, "Current pager:\t\t%s\n", pager);
4044
3996
tee_fprintf(stdout, "Using outfile:\t\t'%s'\n", opt_outfile ? outfile : "");
4045
3997
tee_fprintf(stdout, "Using delimiter:\t%s\n", delimiter);
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)))
3998
tee_fprintf(stdout, "Server version:\t\t%s\n", server_version_string(&drizzle));
3999
tee_fprintf(stdout, "Protocol version:\t%d\n", drizzle_get_proto_info(&drizzle));
4000
tee_fprintf(stdout, "Connection:\t\t%s\n", drizzle_get_host_info(&drizzle));
4001
if ((id= drizzle_insert_id(&drizzle)))
4050
4002
tee_fprintf(stdout, "Insert id:\t\t%s\n", llstr(id, buff));
4052
4004
/* "limit 1" is protection against SQL_SELECT_LIMIT=0 */
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)))
4005
if (!drizzle_query(&drizzle,"select @@character_set_client, @@character_set_connection, @@character_set_server, @@character_set_database limit 1") &&
4006
(result=drizzle_use_result(&drizzle)))
4056
MYSQL_ROW cur=mysql_fetch_row(result);
4008
DRIZZLE_ROW cur=drizzle_fetch_row(result);
4059
4011
tee_fprintf(stdout, "Server characterset:\t%s\n", cur[2] ? cur[2] : "");
4061
4013
tee_fprintf(stdout, "Client characterset:\t%s\n", cur[0] ? cur[0] : "");
4062
4014
tee_fprintf(stdout, "Conn. characterset:\t%s\n", cur[1] ? cur[1] : "");
4064
mysql_free_result(result);
4016
drizzle_free_result(result);
4068
4020
/* Probably pre-4.1 server */
4069
4021
tee_fprintf(stdout, "Client characterset:\t%s\n", charset_info->csname);
4070
tee_fprintf(stdout, "Server characterset:\t%s\n", mysql.charset->csname);
4022
tee_fprintf(stdout, "Server characterset:\t%s\n", drizzle.charset->csname);
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);
4025
if (strstr(drizzle_get_host_info(&drizzle),"TCP/IP") || ! drizzle.unix_socket)
4026
tee_fprintf(stdout, "TCP port:\t\t%d\n", drizzle.port);
4077
tee_fprintf(stdout, "UNIX socket:\t\t%s\n", mysql.unix_socket);
4078
if (mysql.net.compress)
4028
tee_fprintf(stdout, "UNIX socket:\t\t%s\n", drizzle.unix_socket);
4029
if (drizzle.net.compress)
4079
4030
tee_fprintf(stdout, "Protocol:\t\tCompressed\n");
4082
if ((status_str= mysql_stat(&mysql)) && !mysql_error(&mysql)[0])
4032
if ((status_str= drizzle_stat(&drizzle)) && !drizzle_error(&drizzle)[0])
4085
4035
const char *pos= strchr(status_str,' ');
4120
4070
if (buf[0] == '\0')
4122
4072
char *bufp = buf;
4073
DRIZZLE_RES *result;
4125
bufp= strnmov(buf, mysql_get_server_info(con), sizeof buf);
4075
bufp= strnmov(buf, drizzle_get_server_info(con), sizeof buf);
4127
4077
/* "limit 1" is protection against SQL_SELECT_LIMIT=0 */
4128
if (!mysql_query(con, "select @@version_comment limit 1") &&
4129
(result = mysql_use_result(con)))
4078
if (!drizzle_query(con, "select @@version_comment limit 1") &&
4079
(result = drizzle_use_result(con)))
4131
MYSQL_ROW cur = mysql_fetch_row(result);
4081
DRIZZLE_ROW cur = drizzle_fetch_row(result);
4132
4082
if (cur && cur[0])
4134
4084
bufp = strxnmov(bufp, sizeof buf - (bufp - buf), " ", cur[0], NullS);
4136
mysql_free_result(result);
4086
drizzle_free_result(result);
4139
4089
/* str*nmov doesn't guarantee NUL-termination */
4378
g_string_append(processed_prompt, mysql_get_server_info(&mysql));
4329
dynstr_append(processed_prompt, drizzle_get_server_info(&drizzle));
4380
g_string_append(processed_prompt, "not_connected");
4331
dynstr_append(processed_prompt, "not_connected");
4383
g_string_append(processed_prompt, current_db ? current_db : "(none)");
4334
dynstr_append(processed_prompt, current_db ? current_db : "(none)");
4387
4338
const char *prompt;
4388
prompt= connected ? mysql_get_host_info(&mysql) : "not_connected";
4339
prompt= connected ? drizzle_get_host_info(&drizzle) : "not_connected";
4389
4340
if (strstr(prompt, "Localhost"))
4390
g_string_append(processed_prompt, "localhost");
4341
dynstr_append(processed_prompt, "localhost");
4393
4344
const char *end=strcend(prompt,' ');
4394
g_string_append_len(processed_prompt, prompt, (gssize) (end-prompt));
4345
dynstr_append_mem(processed_prompt, prompt, (end-prompt));
4400
4351
if (!connected)
4402
g_string_append(processed_prompt, "not_connected");
4353
dynstr_append(processed_prompt, "not_connected");
4406
const char *host_info = mysql_get_host_info(&mysql);
4357
const char *host_info = drizzle_get_host_info(&drizzle);
4407
4358
if (strstr(host_info, "memory"))
4409
g_string_append(processed_prompt, mysql.host );
4360
dynstr_append(processed_prompt, drizzle.host);
4411
4362
else if (strstr(host_info,"TCP/IP") ||
4413
add_int_to_prompt(mysql.port);
4363
!drizzle.unix_socket)
4364
add_int_to_prompt(drizzle.port);
4416
char *pos=strrchr(mysql.unix_socket,'/');
4417
g_string_append(processed_prompt, pos ? pos+1 : mysql.unix_socket);
4367
char *pos=strrchr(drizzle.unix_socket,'/');
4368
dynstr_append(processed_prompt, pos ? pos+1 : drizzle.unix_socket);
4422
4373
if (!full_username)
4423
4374
init_username();
4424
g_string_append(processed_prompt, full_username ? full_username :
4375
dynstr_append(processed_prompt, full_username ? full_username :
4425
4376
(current_user ? current_user : "(unknown)"));
4428
4379
if (!full_username)
4429
4380
init_username();
4430
g_string_append(processed_prompt, part_username ? part_username :
4381
dynstr_append(processed_prompt, part_username ? part_username :
4431
4382
(current_user ? current_user : "(unknown)"));
4433
4384
case PROMPT_CHAR:
4434
g_string_append_c(processed_prompt, PROMPT_CHAR);
4386
char c= PROMPT_CHAR;
4387
dynstr_append_mem(processed_prompt, &c, 1);
4437
g_string_append_c(processed_prompt, '\n');
4393
dynstr_append_mem(processed_prompt, &c, 1);
4441
g_string_append_c(processed_prompt, ' ');
4400
dynstr_append_mem(processed_prompt, &c, 1);
4444
4404
if (t->tm_hour < 10)
4445
g_string_append_c(processed_prompt, '0');
4405
add_int_to_prompt(0);
4446
4406
add_int_to_prompt(t->tm_hour);
4471
4431
dateTime = ctime(&lclock);
4472
g_string_append(processed_prompt, strtok(dateTime,"\n"));
4432
dynstr_append(processed_prompt, strtok(dateTime,"\n"));
4475
4435
if (t->tm_sec < 10)
4476
g_string_append_c(processed_prompt, '0');
4436
add_int_to_prompt(0);
4477
4437
add_int_to_prompt(t->tm_sec);
4480
g_string_append(processed_prompt, (day_names[t->tm_wday]));
4440
dynstr_append(processed_prompt, (day_names[t->tm_wday]));
4483
g_string_append(processed_prompt, t->tm_hour < 12 ? "am" : "pm");
4443
dynstr_append(processed_prompt, t->tm_hour < 12 ? "am" : "pm");
4486
4446
add_int_to_prompt(t->tm_mon+1);
4489
g_string_append(processed_prompt, month_names[t->tm_mon]);
4449
dynstr_append(processed_prompt, month_names[t->tm_mon]);
4492
g_string_append(processed_prompt, "'");
4452
dynstr_append(processed_prompt, "'");
4495
g_string_append_c(processed_prompt, '"');
4455
dynstr_append(processed_prompt, "\"");
4498
g_string_append_c(processed_prompt, ';');
4458
dynstr_append(processed_prompt, ";");
4501
g_string_append_c(processed_prompt, '\t');
4461
dynstr_append(processed_prompt, "\t");
4504
g_string_append(processed_prompt, delimiter_str);
4464
dynstr_append(processed_prompt, delimiter_str);
4507
g_string_append(processed_prompt, c);
4467
dynstr_append_mem(processed_prompt, c, 1);
4511
// TODO: Is this needed with GString?
4512
g_string_append_c(processed_prompt, '\0');
4513
4471
return processed_prompt->str;
4526
4484
my_free(full_username,MYF(MY_ALLOW_ZERO_PTR));
4527
4485
my_free(part_username,MYF(MY_ALLOW_ZERO_PTR));
4530
if (!mysql_query(&mysql,"select USER()") &&
4531
(result=mysql_use_result(&mysql)))
4487
DRIZZLE_RES *result;
4488
if (!drizzle_query(&drizzle,"select USER()") &&
4489
(result=drizzle_use_result(&drizzle)))
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
4491
DRIZZLE_ROW cur=drizzle_fetch_row(result);
4492
full_username= strdup(cur[0]);
4493
part_username= strdup(strtok(cur[0],"@"));
4494
(void) drizzle_fetch_row(result); // Read eof
4540
static int com_prompt(GString *buffer __attribute__((__unused__)), char *line)
4498
static int com_prompt(DYNAMIC_STRING *buffer __attribute__((unused)),
4542
4501
char *ptr=strchr(line, ' ');
4543
4502
prompt_counter = 0;
4544
4503
my_free(current_prompt,MYF(MY_ALLOW_ZERO_PTR));
4545
current_prompt=g_strdup(ptr ? ptr+1 : default_prompt->str);
4504
current_prompt= strdup(ptr ? ptr+1 : default_prompt);
4547
4506
tee_fprintf(stdout, "Returning to default PROMPT of %s\n",
4548
default_prompt->str);
4550
4509
tee_fprintf(stdout, "PROMPT set to '%s'\n", current_prompt);