Commit 97042da6 authored by unknown's avatar unknown

Merge abarkov@work.mysql.com:/home/bk/mysql-4.1

into bar.mysql.r18.ru:/usr/home/bar/mysql-4.1.wrk

parents 86f1a1e0 9ef9f59d
...@@ -402,16 +402,16 @@ String *Item_date::val_str(String *str) ...@@ -402,16 +402,16 @@ String *Item_date::val_str(String *str)
return (String*) 0; return (String*) 0;
if (!value) // zero daynr if (!value) // zero daynr
{ {
str->copy("0000-00-00",10,my_charset_latin1); str->copy("0000-00-00",10,my_charset_latin1,thd_charset());
return str; return str;
} }
if (str->alloc(11))
return &empty_string; /* purecov: inspected */ char tmpbuff[11];
sprintf((char*) str->ptr(),"%04d-%02d-%02d", sprintf(tmpbuff,"%04d-%02d-%02d",
(int) (value/10000L) % 10000, (int) (value/10000L) % 10000,
(int) (value/100)%100, (int) (value/100)%100,
(int) (value%100)); (int) (value%100));
str->length(10); str->copy(tmpbuff,10,my_charset_latin1,thd_charset());
return str; return str;
} }
...@@ -448,7 +448,10 @@ void Item_func_curdate::fix_length_and_dec() ...@@ -448,7 +448,10 @@ void Item_func_curdate::fix_length_and_dec()
{ {
struct tm tm_tmp,*start; struct tm tm_tmp,*start;
time_t query_start=current_thd->query_start(); time_t query_start=current_thd->query_start();
decimals=0; max_length=10;
set_charset(thd_charset());
decimals=0;
max_length=10*thd_charset()->mbmaxlen;
localtime_r(&query_start,&tm_tmp); localtime_r(&query_start,&tm_tmp);
start=&tm_tmp; start=&tm_tmp;
value=(longlong) ((ulong) ((uint) start->tm_year+1900)*10000L+ value=(longlong) ((ulong) ((uint) start->tm_year+1900)*10000L+
...@@ -473,27 +476,48 @@ bool Item_func_curdate::get_date(TIME *res, ...@@ -473,27 +476,48 @@ bool Item_func_curdate::get_date(TIME *res,
return 0; return 0;
} }
String *Item_func_curtime::val_str(String *str)
{
str_value.set(buff,buff_length,thd_charset());
return &str_value;
}
void Item_func_curtime::fix_length_and_dec() void Item_func_curtime::fix_length_and_dec()
{ {
struct tm tm_tmp,*start; struct tm tm_tmp,*start;
time_t query_start=current_thd->query_start(); time_t query_start=current_thd->query_start();
decimals=0; max_length=8; CHARSET_INFO *cs=thd_charset();
decimals=0;
max_length=8*cs->mbmaxlen;
localtime_r(&query_start,&tm_tmp); localtime_r(&query_start,&tm_tmp);
start=&tm_tmp; start=&tm_tmp;
set_charset(cs);
value=(longlong) ((ulong) ((uint) start->tm_hour)*10000L+ value=(longlong) ((ulong) ((uint) start->tm_hour)*10000L+
(ulong) (((uint) start->tm_min)*100L+ (ulong) (((uint) start->tm_min)*100L+
(uint) start->tm_sec)); (uint) start->tm_sec));
buff_length= my_sprintf(buff, (buff,"%02d:%02d:%02d",
buff_length=cs->snprintf(cs,buff,sizeof(buff),"%02d:%02d:%02d",
(int) start->tm_hour, (int) start->tm_hour,
(int) start->tm_min, (int) start->tm_min,
(int) start->tm_sec)); (int) start->tm_sec);
}
String *Item_func_now::val_str(String *str)
{
str_value.set(buff,buff_length,thd_charset());
return &str_value;
} }
void Item_func_now::fix_length_and_dec() void Item_func_now::fix_length_and_dec()
{ {
struct tm tm_tmp,*start; struct tm tm_tmp,*start;
time_t query_start=current_thd->query_start(); time_t query_start=current_thd->query_start();
decimals=0; max_length=19; CHARSET_INFO *cs=thd_charset();
decimals=0;
max_length=19*cs->mbmaxlen;
set_charset(cs);
localtime_r(&query_start,&tm_tmp); localtime_r(&query_start,&tm_tmp);
start=&tm_tmp; start=&tm_tmp;
value=((longlong) ((ulong) ((uint) start->tm_year+1900)*10000L+ value=((longlong) ((ulong) ((uint) start->tm_year+1900)*10000L+
...@@ -502,13 +526,14 @@ void Item_func_now::fix_length_and_dec() ...@@ -502,13 +526,14 @@ void Item_func_now::fix_length_and_dec()
(longlong) ((ulong) ((uint) start->tm_hour)*10000L+ (longlong) ((ulong) ((uint) start->tm_hour)*10000L+
(ulong) (((uint) start->tm_min)*100L+ (ulong) (((uint) start->tm_min)*100L+
(uint) start->tm_sec))); (uint) start->tm_sec)));
buff_length= (uint) my_sprintf(buff, (buff,"%04d-%02d-%02d %02d:%02d:%02d",
buff_length= (uint) cs->snprintf(cs,buff, sizeof(buff),"%04d-%02d-%02d %02d:%02d:%02d",
((int) (start->tm_year+1900)) % 10000, ((int) (start->tm_year+1900)) % 10000,
(int) start->tm_mon+1, (int) start->tm_mon+1,
(int) start->tm_mday, (int) start->tm_mday,
(int) start->tm_hour, (int) start->tm_hour,
(int) start->tm_min, (int) start->tm_min,
(int) start->tm_sec)); (int) start->tm_sec);
/* For getdate */ /* For getdate */
ltime.year= start->tm_year+1900; ltime.year= start->tm_year+1900;
ltime.month= start->tm_mon+1; ltime.month= start->tm_mon+1;
...@@ -539,7 +564,7 @@ int Item_func_now::save_in_field(Field *to) ...@@ -539,7 +564,7 @@ int Item_func_now::save_in_field(Field *to)
String *Item_func_sec_to_time::val_str(String *str) String *Item_func_sec_to_time::val_str(String *str)
{ {
char buff[23]; char buff[23*2];
const char *sign=""; const char *sign="";
longlong seconds=(longlong) args[0]->val_int(); longlong seconds=(longlong) args[0]->val_int();
ulong length; ulong length;
...@@ -553,7 +578,7 @@ String *Item_func_sec_to_time::val_str(String *str) ...@@ -553,7 +578,7 @@ String *Item_func_sec_to_time::val_str(String *str)
uint sec= (uint) ((ulonglong) seconds % 3600); uint sec= (uint) ((ulonglong) seconds % 3600);
length= my_sprintf(buff,(buff,"%s%02lu:%02u:%02u",sign,(long) (seconds/3600), length= my_sprintf(buff,(buff,"%s%02lu:%02u:%02u",sign,(long) (seconds/3600),
sec/60, sec % 60)); sec/60, sec % 60));
str->copy(buff, length, my_charset_latin1); str->copy(buff, length, my_charset_latin1, thd_charset());
return str; return str;
} }
...@@ -897,20 +922,26 @@ String *Item_func_from_unixtime::val_str(String *str) ...@@ -897,20 +922,26 @@ String *Item_func_from_unixtime::val_str(String *str)
{ {
struct tm tm_tmp,*start; struct tm tm_tmp,*start;
time_t tmp=(time_t) args[0]->val_int(); time_t tmp=(time_t) args[0]->val_int();
uint32 l;
CHARSET_INFO *cs=thd_charset();
if ((null_value=args[0]->null_value)) if ((null_value=args[0]->null_value))
return 0; return 0;
localtime_r(&tmp,&tm_tmp); localtime_r(&tmp,&tm_tmp);
start=&tm_tmp; start=&tm_tmp;
if (str->alloc(20))
l=20*cs->mbmaxlen+32;
if (str->alloc(l))
return str; /* purecov: inspected */ return str; /* purecov: inspected */
sprintf((char*) str->ptr(),"%04d-%02d-%02d %02d:%02d:%02d", l=cs->snprintf(cs,(char*) str->ptr(),l,"%04d-%02d-%02d %02d:%02d:%02d",
(int) start->tm_year+1900, (int) start->tm_year+1900,
(int) start->tm_mon+1, (int) start->tm_mon+1,
(int) start->tm_mday, (int) start->tm_mday,
(int) start->tm_hour, (int) start->tm_hour,
(int) start->tm_min, (int) start->tm_min,
(int) start->tm_sec); (int) start->tm_sec);
str->length(19); str->length(l);
str->set_charset(cs);
return str; return str;
} }
...@@ -1041,26 +1072,31 @@ bool Item_date_add_interval::get_date(TIME *ltime, bool fuzzy_date) ...@@ -1041,26 +1072,31 @@ bool Item_date_add_interval::get_date(TIME *ltime, bool fuzzy_date)
String *Item_date_add_interval::val_str(String *str) String *Item_date_add_interval::val_str(String *str)
{ {
TIME ltime; TIME ltime;
CHARSET_INFO *cs=thd_charset();
uint32 l;
if (Item_date_add_interval::get_date(&ltime,0)) if (Item_date_add_interval::get_date(&ltime,0))
return 0; return 0;
if (ltime.time_type == TIMESTAMP_DATE) if (ltime.time_type == TIMESTAMP_DATE)
{ {
if (str->alloc(11)) l=11*cs->mbmaxlen+32;
if (str->alloc(l))
goto null_date; goto null_date;
sprintf((char*) str->ptr(),"%04d-%02d-%02d", l=cs->snprintf(cs,(char*) str->ptr(),l,"%04d-%02d-%02d",
ltime.year,ltime.month,ltime.day); ltime.year,ltime.month,ltime.day);
str->length(10); str->length(l);
} }
else else
{ {
if (str->alloc(20)) l=20*cs->mbmaxlen+32;
if (str->alloc(l))
goto null_date; goto null_date;
sprintf((char*) str->ptr(),"%04d-%02d-%02d %02d:%02d:%02d", l=cs->snprintf(cs,(char*) str->ptr(),l,"%04d-%02d-%02d %02d:%02d:%02d",
ltime.year,ltime.month,ltime.day, ltime.year,ltime.month,ltime.day,
ltime.hour,ltime.minute,ltime.second); ltime.hour,ltime.minute,ltime.second);
str->length(19); str->length(l);
} }
str->set_charset(cs);
return str; return str;
null_date: null_date:
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment