152
149
typedef enum enum_info_type INFO_TYPE;
154
151
static DRIZZLE drizzle; /* The connection */
155
static bool ignore_errors=0,quick=0,
156
connected=0,opt_raw_data=0,unbuffered=0,output_tables=0,
157
opt_rehash=1,skip_updates=0,safe_updates=0,one_database=0,
158
opt_compress=0, using_opt_local_infile=0,
159
vertical=0, line_numbers=1, column_names=1,
160
opt_nopager=1, opt_outfile=0, named_cmds= 0,
161
tty_password= 0, opt_nobeep=0, opt_reconnect=1,
162
default_charset_used= 0, opt_secure_auth= 0,
163
default_pager_set= 0, opt_sigint_ignore= 0,
164
auto_vertical_output= 0,
165
show_warnings= 0, executing_query= 0, interrupted_query= 0;
152
static bool ignore_errors= false, quick= false,
153
connected= false, opt_raw_data= false, unbuffered= false,
154
output_tables= false, opt_rehash= true, skip_updates= false,
155
safe_updates= false, one_database= false,
156
opt_compress= false, using_opt_local_infile= false,
157
vertical= false, line_numbers= true, column_names= true,
158
opt_nopager= true, opt_outfile= false, named_cmds= false,
159
tty_password= false, opt_nobeep= false, opt_reconnect= true,
160
default_charset_used= false, opt_secure_auth= false,
161
default_pager_set= false, opt_sigint_ignore= false,
162
auto_vertical_output= false,
163
show_warnings= false, executing_query= false, interrupted_query= false;
164
static uint32_t show_progress_size= 0;
166
165
static bool debug_info_flag, debug_check_flag;
167
166
static bool column_types_flag;
168
static bool preserve_comments= 0;
169
static uint32_t opt_max_allowed_packet, opt_net_buffer_length;
170
static int verbose=0,opt_silent=0,opt_drizzle_port=0, opt_local_infile=0;
167
static bool preserve_comments= false;
168
static uint32_t opt_max_allowed_packet, opt_net_buffer_length,
170
static int verbose= 0, opt_silent= 0, opt_local_infile= 0;
171
171
static uint my_end_arg;
172
static char * opt_drizzle_unix_port=0;
173
static int connect_flag=CLIENT_INTERACTIVE;
174
static char *current_host,*current_db,*current_user=0,*opt_password=0,
175
*delimiter_str= 0,* current_prompt= 0;
172
static char * opt_drizzle_unix_port= NULL;
173
static int connect_flag= CLIENT_INTERACTIVE;
174
static char *current_host, *current_db, *current_user= NULL,
175
*opt_password= NULL, *delimiter_str= NULL, *current_prompt= NULL;
176
176
static char *histfile;
177
177
static char *histfile_tmp;
178
178
static string *glob_buffer;
179
179
static string *processed_prompt= NULL;
180
180
static char *default_prompt= NULL;
181
static char *full_username=0,*part_username=0;
181
static char *full_username= NULL,*part_username= NULL;
182
182
static STATUS status;
183
183
static uint32_t select_limit;
184
184
static uint32_t max_join_size;
185
185
static uint32_t opt_connect_timeout= 0;
186
186
static char drizzle_charsets_dir[FN_REFLEN+1];
187
187
// TODO: Need to i18n these
188
static const char *day_names[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
189
static const char *month_names[]={"Jan","Feb","Mar","Apr","May","Jun","Jul",
188
static const char *day_names[]= {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
189
static const char *month_names[]= {"Jan","Feb","Mar","Apr","May","Jun","Jul",
190
190
"Aug","Sep","Oct","Nov","Dec"};
191
191
static char default_pager[FN_REFLEN];
192
192
static char pager[FN_REFLEN], outfile[FN_REFLEN];
1036
1032
MY_INIT(argv[0]);
1037
1033
delimiter_str= delimiter;
1038
default_prompt= my_strdup(getenv("DRIZZLE_PS1") ?
1039
getenv("DRIZZLE_PS1") :
1040
"drizzle>> ", MYF(0));
1041
current_prompt= my_strdup(default_prompt, MYF(0));
1034
default_prompt= strdup(getenv("DRIZZLE_PS1") ?
1035
getenv("DRIZZLE_PS1") :
1038
if (default_prompt == NULL)
1040
fprintf(stderr, _("Memory allocation error while constructing initial "
1041
"prompt. Aborting.\n"));
1044
current_prompt= strdup(default_prompt);
1045
if (current_prompt == NULL)
1047
fprintf(stderr, _("Memory allocation error while constructing initial "
1048
"prompt. Aborting.\n"));
1042
1051
processed_prompt= new string();
1043
1052
processed_prompt->reserve(32);
1045
1054
prompt_counter=0;
1047
1056
outfile[0]=0; // no (default) outfile
1048
my_stpcpy(pager, "stdout"); // the default, if --pager wasn't given
1057
strcpy(pager, "stdout"); // the default, if --pager wasn't given
1050
1059
char *tmp=getenv("PAGER");
1051
1060
if (tmp && strlen(tmp))
1053
1062
default_pager_set= 1;
1054
my_stpcpy(default_pager, tmp);
1063
strcpy(default_pager, tmp);
1057
1066
if (!isatty(0) || !isatty(1))
1360
1367
{"no-pager", OPT_NOPAGER,
1361
1368
N_("Disable pager and print to stdout. See interactive help (\\h) also. WARNING: option deprecated; use --disable-pager instead."),
1362
1369
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1364
1371
N_("Password to use when connecting to server. If password is not given it's asked from the tty."),
1365
1372
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, ")
1373
{"port", 'p', N_("Port number to use for connection or 0 for default to, in order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, ")
1367
1374
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},
1375
0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1370
1376
{"prompt", OPT_PROMPT, N_("Set the drizzle prompt to this value."),
1371
1377
(char**) ¤t_prompt, (char**) ¤t_prompt, 0, GET_STR_ALLOC,
1372
1378
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
1380
N_("Don't cache result, print it row by row. This may slow down the server if the output is suspended. Doesn't use history file."),
1377
1381
(char**) &quick, (char**) &quick, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1437
1441
{"show-warnings", OPT_SHOW_WARNINGS, N_("Show warnings after every statement."),
1438
1442
(char**) &show_warnings, (char**) &show_warnings, 0, GET_BOOL, NO_ARG,
1439
1443
0, 0, 0, 0, 0, 0},
1444
{"show-progress-size", OPT_SHOW_PROGRESS_SIZE, N_("Number of lines before each import progress report."),
1445
(char**) &show_progress_size, (char**) &show_progress_size, 0, GET_ULONG, REQUIRED_ARG,
1440
1447
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, 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"));
1462
printf(_("Copyright (C) 2008 Sun Microsystems\n"
1463
"This software comes with ABSOLUTELY NO WARRANTY. "
1464
"This is free software,\n"
1465
"and you are welcome to modify and redistribute it "
1466
"under the GPL license\n"));
1459
1467
printf(_("Usage: %s [OPTIONS] [database]\n"), my_progname);
1460
1468
my_print_help(my_long_options);
1461
print_defaults("my", load_default_groups);
1469
print_defaults("drizzle", load_default_groups);
1462
1470
my_print_variables(my_long_options);
1467
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
1475
get_one_option(int optid, const struct my_option *, char *argument)
1477
char *endchar= NULL;
1478
uint64_t temp_drizzle_port= 0;
1470
1480
switch(optid) {
1471
1481
case OPT_CHARSETS_DIR:
1472
strmake(drizzle_charsets_dir, argument, sizeof(drizzle_charsets_dir) - 1);
1482
strncpy(drizzle_charsets_dir, argument, sizeof(drizzle_charsets_dir) - 1);
1473
1483
charsets_dir = drizzle_charsets_dir;
1475
1485
case OPT_DEFAULT_CHARSET:
1560
1570
one_database= skip_updates= 1;
1573
temp_drizzle_port= (uint64_t) strtoul(argument, &endchar, 10);
1574
/* if there is an alpha character this is not a valid port */
1575
if (strlen(endchar) != 0)
1577
put_info(_("Non-integer value supplied for port. If you are trying to enter a password please use --password instead."), INFO_ERROR, 0, 0);
1580
/* If the port number is > 65535 it is not a valid port
1581
This also helps with potential data loss casting unsigned long to a
1583
if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
1585
put_info(_("Value supplied for port is not valid."), INFO_ERROR, 0, 0);
1590
opt_drizzle_port= (uint32_t) temp_drizzle_port;
1594
/* Don't require password */
1563
1595
if (argument == disabled_my_option)
1564
argument= (char*) ""; // Don't require password
1597
argument= (char*) "";
1567
1601
char *start= argument;
1568
1602
free(opt_password);
1569
1603
opt_password= strdup(argument);
1570
while (*argument) *argument++= 'x'; // Destroy argument
1606
/* Overwriting password with 'x' */
1573
1613
tty_password= 0;
1576
1617
tty_password= 1;
1579
1621
if (argument == disabled_my_option)
3361
3406
tee_fprintf(stdout, "Default pager wasn't set, using stdout.\n");
3363
my_stpcpy(pager, "stdout");
3408
strcpy(pager, "stdout");
3367
my_stpcpy(pager, default_pager);
3412
strcpy(pager, default_pager);
3371
end= strmake(pager_name, param, sizeof(pager_name)-1);
3416
end= strncpy(pager_name, param, sizeof(pager_name)-1);
3417
end+= strlen(pager_name);
3372
3418
while (end > pager_name && (my_isspace(charset_info,end[-1]) ||
3373
3419
my_iscntrl(charset_info,end[-1])))
3376
my_stpcpy(pager, pager_name);
3377
my_stpcpy(default_pager, pager_name);
3422
strcpy(pager, pager_name);
3423
strcpy(default_pager, pager_name);
3380
3426
tee_fprintf(stdout, "PAGER set to '%s'\n", pager);
4058
4102
if (sec >= 3600.0*24)
4060
4104
tmp=(uint32_t) floor(sec/(3600.0*24));
4062
buff=int10_to_str((long) tmp, buff, 10);
4063
buff=my_stpcpy(buff,tmp > 1 ? " days " : " day ");
4105
sec-= 3600.0*24*tmp;
4106
buff= int10_to_str((long) tmp, buff, 10);
4109
buff= strcpy(buff," days ")+6;
4111
buff= strcpy(buff," day ")+5;
4065
4114
if (sec >= 3600.0)
4067
4116
tmp=(uint32_t) floor(sec/3600.0);
4068
4117
sec-=3600.0*tmp;
4069
4118
buff=int10_to_str((long) tmp, buff, 10);
4070
buff=my_stpcpy(buff,tmp > 1 ? " hours " : " hour ");
4121
buff= strcpy(buff, " hours ")+7;
4123
buff= strcpy(buff, " hour ")+6;
4072
4125
if (sec >= 60.0)
4074
4127
tmp=(uint32_t) floor(sec/60.0);
4076
4129
buff=int10_to_str((long) tmp, buff, 10);
4077
buff=my_stpcpy(buff," min ");
4130
buff= strcpy(buff," min ")+5;
4079
4132
if (part_second)
4080
4133
sprintf(buff,"%.2f sec",sec);