318
325
current_password,
322
static const char* get_day_name(int day_of_week)
345
static const char* get_month_name(int month)
328
// TODO: Need to i18n these
329
static const char *day_names[]= {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
330
static const char *month_names[]= {"Jan","Feb","Mar","Apr","May","Jun","Jul",
331
"Aug","Sep","Oct","Nov","Dec"};
378
332
/* @TODO: Remove this */
379
333
#define FN_REFLEN 512
430
384
static void add_int_to_prompt(int toadd);
431
385
static int get_result_width(drizzle_result_st *res);
432
386
static int get_field_disp_length(drizzle_column_st * field);
433
static const char * strcont(const char *str, const char *set);
387
static const char * strcont(register const char *str, register const char *set);
435
389
/* A class which contains information on the commands this program
436
390
can understand. */
1167
1121
static void print_tab_data(drizzle_result_st *result);
1168
1122
static void print_table_data_vertically(drizzle_result_st *result);
1169
1123
static void print_warnings(uint32_t error_code);
1170
static boost::posix_time::ptime start_timer(void);
1171
static void end_timer(boost::posix_time::ptime, string &buff);
1172
static void drizzle_end_timer(boost::posix_time::ptime, string &buff);
1173
static void nice_time(boost::posix_time::time_duration duration, string &buff);
1124
static uint32_t start_timer(void);
1125
static void end_timer(uint32_t start_time,char *buff);
1126
static void drizzle_end_timer(uint32_t start_time,char *buff);
1127
static void nice_time(double sec,char *buff,bool part_second);
1174
1128
extern "C" void drizzle_end(int sig);
1175
1129
extern "C" void handle_sigint(int sig);
1176
1130
#if defined(HAVE_TERMIOS_H) && defined(GWINSZ_IN_SYS_IOCTL)
2936
2888
if (warnings != 1)
2939
strcpy(pos, time_buff.c_str());
2891
strcpy(pos, time_buff);
2940
2892
put_info(buff,INFO_RESULT,0,0);
2941
2893
if (strcmp(drizzle_result_info(&result), ""))
2942
2894
put_info(drizzle_result_info(&result),INFO_RESULT,0,0);
3130
3082
drizzle_return_t ret;
3131
3083
drizzle_column_st *field;
3132
3084
std::vector<bool> num_flag;
3133
std::vector<bool> boolean_flag;
3134
std::vector<bool> ansi_boolean_flag;
3135
3085
string separator;
3137
3087
separator.reserve(256);
3139
3089
num_flag.resize(drizzle_result_column_count(result));
3140
boolean_flag.resize(drizzle_result_column_count(result));
3141
ansi_boolean_flag.resize(drizzle_result_column_count(result));
3142
3090
if (column_types_flag)
3144
3092
print_field_types(result);
3212
3152
drizzle_column_name(field));
3213
3153
num_flag[off]= ((drizzle_column_type(field) <= DRIZZLE_COLUMN_TYPE_LONGLONG) ||
3214
3154
(drizzle_column_type(field) == DRIZZLE_COLUMN_TYPE_NEWDECIMAL));
3215
if ((server_type == ServerDetect::SERVER_DRIZZLE_FOUND) and
3216
(drizzle_column_type(field) == DRIZZLE_COLUMN_TYPE_TINY))
3218
if ((drizzle_column_flags(field) & DRIZZLE_COLUMN_FLAGS_UNSIGNED))
3220
ansi_boolean_flag[off]= true;
3224
ansi_boolean_flag[off]= false;
3226
boolean_flag[off]= true;
3227
num_flag[off]= false;
3231
boolean_flag[off]= false;
3234
3156
(void) tee_fputs("\n", PAGER);
3235
3157
tee_puts((char*) separator.c_str(), PAGER);
3570
3463
drizzle_return_t ret;
3571
3464
drizzle_column_st *field;
3572
3465
size_t *lengths;
3573
std::vector<bool> boolean_flag;
3574
std::vector<bool> ansi_boolean_flag;
3576
boolean_flag.resize(drizzle_result_column_count(result));
3577
ansi_boolean_flag.resize(drizzle_result_column_count(result));
3580
for (uint32_t off= 0; (field = drizzle_column_next(result)); off++)
3467
if (opt_silent < 2 && column_names)
3582
if (opt_silent < 2 && column_names)
3470
while ((field = drizzle_column_next(result)))
3585
3473
(void) tee_fputs("\t", PAGER);
3586
3474
(void) tee_fputs(drizzle_column_name(field), PAGER);
3588
if ((server_type == ServerDetect::SERVER_DRIZZLE_FOUND) and
3589
(drizzle_column_type(field) == DRIZZLE_COLUMN_TYPE_TINY))
3591
if ((drizzle_column_flags(field) & DRIZZLE_COLUMN_FLAGS_UNSIGNED))
3593
ansi_boolean_flag[off]= true;
3597
ansi_boolean_flag[off]= false;
3599
boolean_flag[off]= true;
3603
boolean_flag[off]= false;
3606
if (opt_silent < 2 && column_names)
3608
3476
(void) tee_fputs("\n", PAGER);
3627
3495
lengths= drizzle_row_field_sizes(result);
3628
drizzle_column_seek(result, 0);
3629
for (uint32_t off=0 ; off < drizzle_result_column_count(result); off++)
3496
safe_put_field(cur[0],lengths[0]);
3497
for (uint32_t off=1 ; off < drizzle_result_column_count(result); off++)
3632
(void) tee_fputs("\t", PAGER);
3633
if (boolean_flag[off])
3635
if (strncmp(cur[off],"1", 1) == 0)
3637
if (ansi_boolean_flag[off])
3639
safe_put_field("YES", 3);
3643
safe_put_field("TRUE", 4);
3648
if (ansi_boolean_flag[off])
3650
safe_put_field("NO", 2);
3654
safe_put_field("FALSE", 5);
3660
safe_put_field(cur[off], lengths[off]);
3499
(void) tee_fputs("\t", PAGER);
3500
safe_put_field(cur[off], lengths[off]);
3663
3502
(void) tee_fputs("\n", PAGER);
4508
4344
#include <sys/times.h>
4345
#ifdef _SC_CLK_TCK // For mit-pthreads
4346
#undef CLOCKS_PER_SEC
4347
#define CLOCKS_PER_SEC (sysconf(_SC_CLK_TCK))
4510
static boost::posix_time::ptime start_timer(void)
4350
static uint32_t start_timer(void)
4512
return boost::posix_time::microsec_clock::universal_time();
4353
return times(&tms_tmp);
4515
static void nice_time(boost::posix_time::time_duration duration, string &buff)
4358
Write as many as 52+1 bytes to buff, in the form of a legible
4361
len("4294967296 days, 23 hours, 59 minutes, 60.00 seconds") -> 52
4363
static void nice_time(double sec,char *buff,bool part_second)
4517
4366
ostringstream tmp_buff_str;
4519
if (duration.hours() > 0)
4521
tmp_buff_str << duration.hours();
4522
if (duration.hours() > 1)
4368
if (sec >= 3600.0*24)
4370
tmp=(uint32_t) floor(sec/(3600.0*24));
4371
sec-= 3600.0*24*tmp;
4372
tmp_buff_str << tmp;
4375
tmp_buff_str << " days ";
4377
tmp_buff_str << " day ";
4382
tmp=(uint32_t) floor(sec/3600.0);
4384
tmp_buff_str << tmp;
4523
4387
tmp_buff_str << _(" hours ");
4525
4389
tmp_buff_str << _(" hour ");
4527
if (duration.hours() > 0 || duration.minutes() > 0)
4529
tmp_buff_str << duration.minutes() << _(" min ");
4393
tmp=(uint32_t) floor(sec/60.0);
4395
tmp_buff_str << tmp << _(" min ");
4532
tmp_buff_str.precision(duration.num_fractional_digits());
4534
double seconds= duration.fractional_seconds();
4536
seconds/= pow(10.0,duration.num_fractional_digits());
4538
seconds+= duration.seconds();
4539
tmp_buff_str << seconds << _(" sec");
4541
buff.append(tmp_buff_str.str());
4544
static void end_timer(boost::posix_time::ptime start_time, string &buff)
4546
boost::posix_time::ptime end_time= start_timer();
4547
boost::posix_time::time_period duration(start_time, end_time);
4549
nice_time(duration.length(), buff);
4553
static void drizzle_end_timer(boost::posix_time::ptime start_time, string &buff)
4556
end_timer(start_time,buff);
4398
tmp_buff_str.precision(2);
4400
tmp_buff_str.precision(0);
4401
tmp_buff_str << sec << _(" sec");
4402
strcpy(buff, tmp_buff_str.str().c_str());
4406
static void end_timer(uint32_t start_time,char *buff)
4408
nice_time((double) (start_timer() - start_time) /
4409
CLOCKS_PER_SEC,buff,1);
4413
static void drizzle_end_timer(uint32_t start_time,char *buff)
4417
end_timer(start_time,buff+2);
4418
strcpy(strchr(buff, '\0'),")");
4560
4421
static const char * construct_prompt()