97
#undef bcmp // Fix problem with new readline
76
#ifdef HAVE_LIBREADLINE
77
# if defined(HAVE_READLINE_READLINE_H)
78
# include <readline/readline.h>
79
# elif defined(HAVE_READLINE_H)
80
# include <readline.h>
81
# else /* !defined(HAVE_READLINE_H) */
82
extern char *readline ();
83
# endif /* !defined(HAVE_READLINE_H) */
85
#else /* !defined(HAVE_READLINE_READLINE_H) */
87
# error Readline Required
88
#endif /* HAVE_LIBREADLINE */
99
#ifdef HAVE_READLINE_HISTORY_H
100
#include <readline/history.h>
102
#include <readline/readline.h>
90
#ifdef HAVE_READLINE_HISTORY
91
# if defined(HAVE_READLINE_HISTORY_H)
92
# include <readline/history.h>
93
# elif defined(HAVE_HISTORY_H)
95
# else /* !defined(HAVE_HISTORY_H) */
96
extern void add_history ();
97
extern int write_history ();
98
extern int read_history ();
99
# endif /* defined(HAVE_READLINE_HISTORY_H) */
101
#endif /* HAVE_READLINE_HISTORY */
105
104
Make the old readline interface look like the new one.
147
167
typedef enum enum_info_type INFO_TYPE;
149
169
static DRIZZLE drizzle; /* The connection */
150
static bool ignore_errors=0,quick=0,
151
connected=0,opt_raw_data=0,unbuffered=0,output_tables=0,
152
opt_rehash=1,skip_updates=0,safe_updates=0,one_database=0,
153
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,
156
tty_password= 0, opt_nobeep=0, opt_reconnect=1,
157
default_charset_used= 0, opt_secure_auth= 0,
158
default_pager_set= 0, opt_sigint_ignore= 0,
159
auto_vertical_output= 0,
160
show_warnings= 0, executing_query= 0, interrupted_query= 0;
170
static bool ignore_errors= false, quick= false,
171
connected= false, opt_raw_data= false, unbuffered= false,
172
output_tables= false, opt_rehash= true, skip_updates= false,
173
safe_updates= false, one_database= false,
174
opt_compress= false, using_opt_local_infile= false,
175
vertical= false, line_numbers= true, column_names= true,
176
opt_nopager= true, opt_outfile= false, named_cmds= false,
177
tty_password= false, opt_nobeep= false, opt_reconnect= true,
178
default_charset_used= false, opt_secure_auth= false,
179
default_pager_set= false, opt_sigint_ignore= false,
180
auto_vertical_output= false,
181
show_warnings= false, executing_query= false, interrupted_query= false;
182
static uint32_t show_progress_size= 0;
161
183
static bool debug_info_flag, debug_check_flag;
162
184
static bool column_types_flag;
163
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;
185
static bool preserve_comments= false;
186
static uint32_t opt_max_allowed_packet, opt_net_buffer_length,
188
static int verbose= 0, opt_silent= 0, opt_local_infile= 0;
166
189
static uint my_end_arg;
167
static char * opt_drizzle_unix_port=0;
168
static int connect_flag=CLIENT_INTERACTIVE;
169
static char *current_host,*current_db,*current_user=0,*opt_password=0,
170
*delimiter_str= 0,* current_prompt= 0,
171
*default_charset= (char*) DRIZZLE_DEFAULT_CHARSET_NAME;
190
static char * opt_drizzle_unix_port= NULL;
191
static int connect_flag= CLIENT_INTERACTIVE;
192
static char *current_host, *current_db, *current_user= NULL,
193
*opt_password= NULL, *delimiter_str= NULL, *current_prompt= NULL;
172
194
static char *histfile;
173
195
static char *histfile_tmp;
174
196
static string *glob_buffer;
175
197
static string *processed_prompt= NULL;
176
198
static char *default_prompt= NULL;
177
static char *full_username=0,*part_username=0;
199
static char *full_username= NULL,*part_username= NULL;
178
200
static STATUS status;
179
201
static uint32_t select_limit;
180
202
static uint32_t max_join_size;
181
203
static uint32_t opt_connect_timeout= 0;
182
204
static char drizzle_charsets_dir[FN_REFLEN+1];
183
205
// TODO: Need to i18n these
184
static const char *day_names[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
185
static const char *month_names[]={"Jan","Feb","Mar","Apr","May","Jun","Jul",
206
static const char *day_names[]= {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
207
static const char *month_names[]= {"Jan","Feb","Mar","Apr","May","Jun","Jul",
186
208
"Aug","Sep","Oct","Nov","Dec"};
187
209
static char default_pager[FN_REFLEN];
188
210
static char pager[FN_REFLEN], outfile[FN_REFLEN];
216
237
com_connect(string *str,const char*), com_status(string *str,const char*),
217
238
com_use(string *str,const char*), com_source(string *str, const char*),
218
239
com_rehash(string *str, const char*), com_tee(string *str, const char*),
219
com_notee(string *str, const char*), com_charset(string *str,const char*),
240
com_notee(string *str, const char*),
220
241
com_prompt(string *str, const char*), com_delimiter(string *str, const char*),
221
242
com_warnings(string *str, const char*), com_nowarnings(string *str, const char*),
222
243
com_nopager(string *str, const char*), com_pager(string *str, const char*);
1035
1050
MY_INIT(argv[0]);
1036
1051
delimiter_str= delimiter;
1037
default_prompt= my_strdup(getenv("DRIZZLE_PS1") ?
1038
getenv("DRIZZLE_PS1") :
1039
"drizzle>> ", MYF(0));
1040
current_prompt= my_strdup(default_prompt, MYF(0));
1052
default_prompt= strdup(getenv("DRIZZLE_PS1") ?
1053
getenv("DRIZZLE_PS1") :
1056
if (default_prompt == NULL)
1058
fprintf(stderr, _("Memory allocation error while constructing initial "
1059
"prompt. Aborting.\n"));
1062
current_prompt= strdup(default_prompt);
1063
if (current_prompt == NULL)
1065
fprintf(stderr, _("Memory allocation error while constructing initial "
1066
"prompt. Aborting.\n"));
1041
1069
processed_prompt= new string();
1042
1070
processed_prompt->reserve(32);
1044
1072
prompt_counter=0;
1046
1074
outfile[0]=0; // no (default) outfile
1047
stpcpy(pager, "stdout"); // the default, if --pager wasn't given
1075
strcpy(pager, "stdout"); // the default, if --pager wasn't given
1049
1077
char *tmp=getenv("PAGER");
1050
1078
if (tmp && strlen(tmp))
1052
1080
default_pager_set= 1;
1053
stpcpy(default_pager, tmp);
1081
strcpy(default_pager, tmp);
1056
1084
if (!isatty(0) || !isatty(1))
1201
1226
delete glob_buffer;
1202
1227
if (processed_prompt)
1203
1228
delete processed_prompt;
1204
my_free(opt_password,MYF(MY_ALLOW_ZERO_PTR));
1205
my_free(opt_drizzle_unix_port,MYF(MY_ALLOW_ZERO_PTR));
1206
my_free(histfile,MYF(MY_ALLOW_ZERO_PTR));
1207
my_free(histfile_tmp,MYF(MY_ALLOW_ZERO_PTR));
1208
my_free(current_db,MYF(MY_ALLOW_ZERO_PTR));
1209
my_free(current_host,MYF(MY_ALLOW_ZERO_PTR));
1210
my_free(current_user,MYF(MY_ALLOW_ZERO_PTR));
1211
my_free(full_username,MYF(MY_ALLOW_ZERO_PTR));
1212
my_free(part_username,MYF(MY_ALLOW_ZERO_PTR));
1213
my_free(default_prompt,MYF(MY_ALLOW_ZERO_PTR));
1214
my_free(current_prompt,MYF(MY_ALLOW_ZERO_PTR));
1215
drizzle_server_end();
1230
free(opt_drizzle_unix_port);
1236
free(full_username);
1237
free(part_username);
1238
free(default_prompt);
1239
free(current_prompt);
1216
1240
free_defaults(defaults_argv);
1217
1241
my_end(my_end_arg);
1218
1242
exit(status.exit_status);
1304
1329
{"database", 'D', N_("Database to use."), (char**) ¤t_db,
1305
1330
(char**) ¤t_db, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1306
1331
{"default-character-set", OPT_DEFAULT_CHARSET,
1307
N_("Set the default character set."), (char**) &default_charset,
1308
(char**) &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1332
N_("(not used)"), 0,
1333
0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1309
1334
{"delimiter", OPT_DELIMITER, N_("Delimiter to be used."), (char**) &delimiter_str,
1310
1335
(char**) &delimiter_str, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1311
1336
{"execute", 'e', N_("Execute command and quit. (Disables --force and history file)"), 0,
1360
1385
{"no-pager", OPT_NOPAGER,
1361
1386
N_("Disable pager and print to stdout. See interactive help (\\h) also. WARNING: option deprecated; use --disable-pager instead."),
1362
1387
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1364
1389
N_("Password to use when connecting to server. If password is not given it's asked from the tty."),
1365
1390
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
1366
{"port", 'P', N_("Port number to use for connection or 0 for default to, in order of preference, my.cnf, $DRIZZLE_TCP_PORT, ")
1391
{"port", 'p', N_("Port number to use for connection or 0 for default to, in order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, ")
1367
1392
N_("built-in default") " (" STRINGIFY_ARG(DRIZZLE_PORT) ").",
1368
(char**) &opt_drizzle_port,
1369
(char**) &opt_drizzle_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1393
0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1370
1394
{"prompt", OPT_PROMPT, N_("Set the drizzle prompt to this value."),
1371
1395
(char**) ¤t_prompt, (char**) ¤t_prompt, 0, GET_STR_ALLOC,
1372
1396
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1373
{"protocol", OPT_DRIZZLE_PROTOCOL, N_("The protocol of connection (tcp,socket,pipe,memory)."),
1374
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1376
1398
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."),
1377
1399
(char**) &quick, (char**) &quick, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1456
Copyright (C) 2000-2008 MySQL AB\n \
1457
This software comes with ABSOLUTELY NO WARRANTY. This is free software,\n \
1458
and you are welcome to modify and redistribute it under the GPL license\n"));
1480
printf(_("Copyright (C) 2008 Sun Microsystems\n"
1481
"This software comes with ABSOLUTELY NO WARRANTY. "
1482
"This is free software,\n"
1483
"and you are welcome to modify and redistribute it "
1484
"under the GPL license\n"));
1459
1485
printf(_("Usage: %s [OPTIONS] [database]\n"), my_progname);
1460
1486
my_print_help(my_long_options);
1461
print_defaults("my", load_default_groups);
1487
print_defaults("drizzle", load_default_groups);
1462
1488
my_print_variables(my_long_options);
1467
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
1493
get_one_option(int optid, const struct my_option *, char *argument)
1495
char *endchar= NULL;
1496
uint64_t temp_drizzle_port= 0;
1470
1498
switch(optid) {
1471
1499
case OPT_CHARSETS_DIR:
1472
strmake(drizzle_charsets_dir, argument, sizeof(drizzle_charsets_dir) - 1);
1500
strncpy(drizzle_charsets_dir, argument, sizeof(drizzle_charsets_dir) - 1);
1473
1501
charsets_dir = drizzle_charsets_dir;
1475
1503
case OPT_DEFAULT_CHARSET:
1560
1588
one_database= skip_updates= 1;
1591
temp_drizzle_port= (uint64_t) strtoul(argument, &endchar, 10);
1592
/* if there is an alpha character this is not a valid port */
1593
if (strlen(endchar) != 0)
1595
put_info(_("Non-integer value supplied for port. If you are trying to enter a password please use --password instead."), INFO_ERROR, 0, 0);
1598
/* If the port number is > 65535 it is not a valid port
1599
This also helps with potential data loss casting unsigned long to a
1601
if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
1603
put_info(_("Value supplied for port is not valid."), INFO_ERROR, 0, 0);
1608
opt_drizzle_port= (uint32_t) temp_drizzle_port;
1612
/* Don't require password */
1563
1613
if (argument == disabled_my_option)
1564
argument= (char*) ""; // Don't require password
1615
argument= (char*) "";
1567
1619
char *start= argument;
1568
my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR));
1569
1621
opt_password= strdup(argument);
1570
while (*argument) *argument++= 'x'; // Destroy argument
1624
/* Overwriting password with 'x' */
1573
1631
tty_password= 0;
1576
1635
tty_password= 1;
1579
1639
if (argument == disabled_my_option)
2776
2808
else if (drizzle_affected_rows(&drizzle) == ~(uint64_t) 0)
2777
stpcpy(buff,_("Query OK"));
2809
strcpy(buff,_("Query OK"));
2779
2811
sprintf(buff, ngettext("Query OK, %ld row affected",
2780
2812
"Query OK, %ld rows affected",
2781
2813
(long) drizzle_affected_rows(&drizzle)),
2782
2814
(long) drizzle_affected_rows(&drizzle));
2816
pos= strchr(buff, '\0');
2785
2817
if ((warnings= drizzle_warning_count(&drizzle)))
2789
pos=int10_to_str(warnings, pos, 10);
2790
pos=stpcpy(pos, " warning");
2821
pos= int10_to_str(warnings, pos, 10);
2822
pos= strcpy(pos, " warning")+8;
2791
2823
if (warnings != 1)
2794
stpcpy(pos, time_buff);
2826
strcpy(pos, time_buff);
2795
2827
put_info(buff,INFO_RESULT,0,0);
2796
2828
if (drizzle_info(&drizzle))
2797
2829
put_info(drizzle_info(&drizzle),INFO_RESULT,0,0);
3390
3424
tee_fprintf(stdout, "Default pager wasn't set, using stdout.\n");
3392
stpcpy(pager, "stdout");
3426
strcpy(pager, "stdout");
3396
stpcpy(pager, default_pager);
3430
strcpy(pager, default_pager);
3400
end= strmake(pager_name, param, sizeof(pager_name)-1);
3434
end= strncpy(pager_name, param, sizeof(pager_name)-1);
3435
end+= strlen(pager_name);
3401
3436
while (end > pager_name && (my_isspace(charset_info,end[-1]) ||
3402
3437
my_iscntrl(charset_info,end[-1])))
3405
stpcpy(pager, pager_name);
3406
stpcpy(default_pager, pager_name);
3440
strcpy(pager, pager_name);
3441
strcpy(default_pager, pager_name);
3409
3444
tee_fprintf(stdout, "PAGER set to '%s'\n", pager);
3769
3801
(char*) &timeout);
3771
3803
if (opt_compress)
3772
drizzle_options(&drizzle,DRIZZLE_OPT_COMPRESS,NullS);
3804
drizzle_options(&drizzle,DRIZZLE_OPT_COMPRESS,NULL);
3773
3805
if (opt_secure_auth)
3774
3806
drizzle_options(&drizzle, DRIZZLE_SECURE_AUTH, (char *) &opt_secure_auth);
3775
3807
if (using_opt_local_infile)
3776
3808
drizzle_options(&drizzle,DRIZZLE_OPT_LOCAL_INFILE, (char*) &opt_local_infile);
3777
drizzle_options(&drizzle,DRIZZLE_OPT_PROTOCOL,(char*)&opt_protocol);
3778
3809
if (safe_updates)
3780
3811
char init_command[100];
3781
3812
sprintf(init_command,
3782
3813
"SET SQL_SAFE_UPDATES=1,SQL_SELECT_LIMIT=%"PRIu32
3783
",SQL_MAX_JOIN_SIZE=%"PRIu32,
3814
",MAX_JOIN_SIZE=%"PRIu32,
3784
3815
select_limit, max_join_size);
3785
3816
drizzle_options(&drizzle, DRIZZLE_INIT_COMMAND, init_command);
3787
if (default_charset_used)
3788
drizzle_options(&drizzle, DRIZZLE_SET_CHARSET_NAME, default_charset);
3789
3818
if (!drizzle_connect(&drizzle, host, user, password,
3790
3819
database, opt_drizzle_port, opt_drizzle_unix_port,
3791
3820
connect_flag | CLIENT_MULTI_STATEMENTS))
4096
4120
if (sec >= 3600.0*24)
4098
4122
tmp=(uint32_t) floor(sec/(3600.0*24));
4100
buff=int10_to_str((long) tmp, buff, 10);
4101
buff=stpcpy(buff,tmp > 1 ? " days " : " day ");
4123
sec-= 3600.0*24*tmp;
4124
buff= int10_to_str((long) tmp, buff, 10);
4127
buff= strcpy(buff," days ")+6;
4129
buff= strcpy(buff," day ")+5;
4103
4132
if (sec >= 3600.0)
4105
4134
tmp=(uint32_t) floor(sec/3600.0);
4106
4135
sec-=3600.0*tmp;
4107
4136
buff=int10_to_str((long) tmp, buff, 10);
4108
buff=stpcpy(buff,tmp > 1 ? " hours " : " hour ");
4139
buff= strcpy(buff, " hours ")+7;
4141
buff= strcpy(buff, " hour ")+6;
4110
4143
if (sec >= 60.0)
4112
4145
tmp=(uint32_t) floor(sec/60.0);
4114
4147
buff=int10_to_str((long) tmp, buff, 10);
4115
buff=stpcpy(buff," min ");
4148
buff= strcpy(buff," min ")+5;
4117
4150
if (part_second)
4118
4151
sprintf(buff,"%.2f sec",sec);
4341
static int com_prompt(string *buffer __attribute__((unused)),
4371
static int com_prompt(string *, const char *line)
4344
char *ptr=strchr(line, ' ');
4346
my_free(current_prompt, MYF(MY_ALLOW_ZERO_PTR));
4347
current_prompt= strdup(ptr ? ptr+1 : default_prompt);
4373
const char *ptr=strchr(line, ' ');
4349
4375
tee_fprintf(stdout, "Returning to default PROMPT of %s\n",
4350
4376
default_prompt);
4378
char * tmpptr= strdup(ptr ? ptr+1 : default_prompt);
4380
tee_fprintf(stdout, "Memory allocation error. Not changing prompt\n");
4383
free(current_prompt);
4384
current_prompt= tmpptr;
4352
4385
tee_fprintf(stdout, "PROMPT set to '%s'\n", current_prompt);
4357
4391
strcont(str, set) if str contanies any character in the string set.
4358
The result is the position of the first found character in str, or NullS
4392
The result is the position of the first found character in str, or NULL
4359
4393
if there isn't anything found.