Commit 8fa71530 authored by Sinisa@sinisa.nasamreza.org's avatar Sinisa@sinisa.nasamreza.org

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

into sinisa.nasamreza.org:/mnt/work/mysql-4.1
parents c6b0d336 442509ac
...@@ -1366,17 +1366,25 @@ String *Item_func_database::val_str(String *str) ...@@ -1366,17 +1366,25 @@ String *Item_func_database::val_str(String *str)
if (!current_thd->db) if (!current_thd->db)
str->length(0); str->length(0);
else else
str->set((const char*) current_thd->db,(uint) strlen(current_thd->db), default_charset_info); str->copy((const char*) current_thd->db,(uint) strlen(current_thd->db), system_charset_info, thd_charset());
return str; return str;
} }
String *Item_func_user::val_str(String *str) String *Item_func_user::val_str(String *str)
{ {
THD *thd=current_thd; THD *thd=current_thd;
if (str->copy((const char*) thd->user,(uint) strlen(thd->user), system_charset_info) || CHARSET_INFO *cs=thd_charset();
str->append('@') || const char *host=thd->host ? thd->host : thd->ip ? thd->ip : "";
str->append(thd->host ? thd->host : thd->ip ? thd->ip : "")) uint32 res_length=(strlen(thd->user)+strlen(host)+10) * cs->mbmaxlen;
return &empty_string;
if (str->alloc(res_length))
{
null_value=1;
return 0;
}
res_length=cs->snprintf(cs, (char*)str->ptr(), res_length, "%s@%s",thd->user,host);
str->length(res_length);
str->set_charset(cs);
return str; return str;
} }
...@@ -2120,7 +2128,7 @@ String *Item_func_charset::val_str(String *str) ...@@ -2120,7 +2128,7 @@ String *Item_func_charset::val_str(String *str)
if ((null_value=(args[0]->null_value || !res->charset()))) if ((null_value=(args[0]->null_value || !res->charset())))
return 0; return 0;
str->copy(res->charset()->name,strlen(res->charset()->name),default_charset_info); str->copy(res->charset()->name,strlen(res->charset()->name),my_charset_latin1,thd_charset());
return str; return str;
} }
......
...@@ -310,7 +310,11 @@ class Item_func_database :public Item_str_func ...@@ -310,7 +310,11 @@ class Item_func_database :public Item_str_func
public: public:
Item_func_database() {} Item_func_database() {}
String *val_str(String *); String *val_str(String *);
void fix_length_and_dec() { max_length= MAX_FIELD_NAME; } void fix_length_and_dec()
{
max_length= MAX_FIELD_NAME * thd_charset()->mbmaxlen;
set_charset(thd_charset());
}
const char *func_name() const { return "database"; } const char *func_name() const { return "database"; }
}; };
...@@ -319,7 +323,11 @@ class Item_func_user :public Item_str_func ...@@ -319,7 +323,11 @@ class Item_func_user :public Item_str_func
public: public:
Item_func_user() {} Item_func_user() {}
String *val_str(String *); String *val_str(String *);
void fix_length_and_dec() { max_length= USERNAME_LENGTH+HOSTNAME_LENGTH+1; } void fix_length_and_dec()
{
max_length= (USERNAME_LENGTH+HOSTNAME_LENGTH+1)*thd_charset()->mbmaxlen;
set_charset(thd_charset());
}
const char *func_name() const { return "user"; } const char *func_name() const { return "user"; }
}; };
...@@ -567,7 +575,8 @@ public: ...@@ -567,7 +575,8 @@ public:
const char *func_name() const { return "charset"; } const char *func_name() const { return "charset"; }
void fix_length_and_dec() void fix_length_and_dec()
{ {
max_length=20; // should be enough max_length=40; // should be enough
set_charset(thd_charset());
}; };
}; };
......
...@@ -62,7 +62,7 @@ public: ...@@ -62,7 +62,7 @@ public:
{ value=atof(str); } { value=atof(str); }
double val() { return value; } double val() { return value; }
longlong val_int() { return (longlong) value; } longlong val_int() { return (longlong) value; }
String *val_str(String *s) { s->set(value,decimals,my_thd_charset); return s; } String *val_str(String *s) { s->set(value,decimals,thd_charset()); return s; }
unsigned int size_of() { return sizeof(*this);} unsigned int size_of() { return sizeof(*this);}
}; };
...@@ -80,7 +80,7 @@ public: ...@@ -80,7 +80,7 @@ public:
{ value=strtoll(str,NULL,10); } { value=strtoll(str,NULL,10); }
double val() { return (double) value; } double val() { return (double) value; }
longlong val_int() { return value; } longlong val_int() { return value; }
String *val_str(String *s) { s->set(value, my_thd_charset); return s; } String *val_str(String *s) { s->set(value, thd_charset()); return s; }
unsigned int size_of() { return sizeof(*this);} unsigned int size_of() { return sizeof(*this);}
}; };
...@@ -92,9 +92,9 @@ public: ...@@ -92,9 +92,9 @@ public:
{ this->max_length=length; } { this->max_length=length; }
enum Item_result result_type () const { return STRING_RESULT; } enum Item_result result_type () const { return STRING_RESULT; }
enum_field_types field_type() const { return FIELD_TYPE_STRING; } enum_field_types field_type() const { return FIELD_TYPE_STRING; }
void set(double nr) { str_value.set(nr, 2, my_thd_charset); } void set(double nr) { str_value.set(nr, 2, thd_charset()); }
void set(longlong nr) { str_value.set(nr, my_thd_charset); } void set(longlong nr) { str_value.set(nr, thd_charset()); }
void set(const char *str, uint length) { str_value.copy(str,length, my_thd_charset); } void set(const char *str, uint length) { str_value.copy(str,length, thd_charset()); }
double val() { return atof(str_value.ptr()); } double val() { return atof(str_value.ptr()); }
longlong val_int() { return strtoll(str_value.ptr(),NULL,10); } longlong val_int() { return strtoll(str_value.ptr(),NULL,10); }
String *val_str(String*) String *val_str(String*)
......
...@@ -93,18 +93,36 @@ bool String::realloc(uint32 alloc_length) ...@@ -93,18 +93,36 @@ bool String::realloc(uint32 alloc_length)
bool String::set(longlong num, CHARSET_INFO *cs) bool String::set(longlong num, CHARSET_INFO *cs)
{ {
if (alloc(21)) uint l=20*cs->mbmaxlen+1;
if (alloc(l))
return TRUE; return TRUE;
str_length=(uint32) (longlong10_to_str(num,Ptr,-10)-Ptr); if (cs->snprintf == my_snprintf_8bit)
{
str_length=(uint32) (longlong10_to_str(num,Ptr,-10)-Ptr);
}
else
{
str_length=cs->snprintf(cs,Ptr,l,"%d",num);
}
str_charset=cs; str_charset=cs;
return FALSE; return FALSE;
} }
bool String::set(ulonglong num, CHARSET_INFO *cs) bool String::set(ulonglong num, CHARSET_INFO *cs)
{ {
if (alloc(21)) uint l=20*cs->mbmaxlen+1;
if (alloc(l))
return TRUE; return TRUE;
str_length=(uint32) (longlong10_to_str(num,Ptr,10)-Ptr); if (cs->snprintf == my_snprintf_8bit)
{
str_length=(uint32) (longlong10_to_str(num,Ptr,10)-Ptr);
}
else
{
str_length=cs->snprintf(cs,Ptr,l,"%d",num);
}
str_charset=cs; str_charset=cs;
return FALSE; return FALSE;
} }
...@@ -117,14 +135,14 @@ bool String::set(double num,uint decimals, CHARSET_INFO *cs) ...@@ -117,14 +135,14 @@ bool String::set(double num,uint decimals, CHARSET_INFO *cs)
if (decimals >= NOT_FIXED_DEC) if (decimals >= NOT_FIXED_DEC)
{ {
sprintf(buff,"%.14g",num); // Enough for a DATETIME sprintf(buff,"%.14g",num); // Enough for a DATETIME
return copy(buff, (uint32) strlen(buff), my_charset_latin1); return copy(buff, (uint32) strlen(buff), my_charset_latin1, cs);
} }
#ifdef HAVE_FCONVERT #ifdef HAVE_FCONVERT
int decpt,sign; int decpt,sign;
char *pos,*to; char *pos,*to;
VOID(fconvert(num,(int) decimals,&decpt,&sign,buff+1)); VOID(fconvert(num,(int) decimals,&decpt,&sign,buff+1));
if (!my_isdigit(system_charset_info, buff[1])) if (!my_isdigit(my_charset_latin1, buff[1]))
{ // Nan or Inf { // Nan or Inf
pos=buff+1; pos=buff+1;
if (sign) if (sign)
...@@ -132,7 +150,7 @@ bool String::set(double num,uint decimals, CHARSET_INFO *cs) ...@@ -132,7 +150,7 @@ bool String::set(double num,uint decimals, CHARSET_INFO *cs)
buff[0]='-'; buff[0]='-';
pos=buff; pos=buff;
} }
return copy(pos,(uint32) strlen(pos)); return copy(pos,(uint32) strlen(pos), my_charset_latin1, cs);
} }
if (alloc((uint32) ((uint32) decpt+3+decimals))) if (alloc((uint32) ((uint32) decpt+3+decimals)))
return TRUE; return TRUE;
...@@ -182,7 +200,7 @@ end: ...@@ -182,7 +200,7 @@ end:
#else #else
sprintf(buff,"%.*f",(int) decimals,num); sprintf(buff,"%.*f",(int) decimals,num);
#endif #endif
return copy(buff,(uint32) strlen(buff), my_charset_latin1); return copy(buff,(uint32) strlen(buff), my_charset_latin1, cs);
#endif #endif
} }
...@@ -219,6 +237,55 @@ bool String::copy(const char *str,uint32 arg_length, CHARSET_INFO *cs) ...@@ -219,6 +237,55 @@ bool String::copy(const char *str,uint32 arg_length, CHARSET_INFO *cs)
return FALSE; return FALSE;
} }
/* Copy with charset convertion */
bool String::copy(const char *str,uint32 arg_length, CHARSET_INFO *from, CHARSET_INFO *to)
{
uint32 new_length=to->mbmaxlen*arg_length;
int cnvres;
my_wc_t wc;
const uchar *s=(const uchar *)str;
const uchar *se=s+arg_length;
uchar *d, *de;
if (alloc(new_length))
return TRUE;
d=(uchar *)Ptr;
de=d+new_length;
for (str_length=new_length ; s < se && d < de ; )
{
if ((cnvres=from->mb_wc(from,&wc,s,se)) > 0 )
{
s+=cnvres;
}
else if (cnvres==MY_CS_ILSEQ)
{
s++;
wc='?';
}
else
break;
outp:
if((cnvres=to->wc_mb(to,wc,d,de)) >0 )
{
d+=cnvres;
}
else if (cnvres==MY_CS_ILUNI && wc!='?')
{
wc='?';
goto outp;
}
else
break;
}
Ptr[new_length]=0;
length((uint32) (d-(uchar *)Ptr));
str_charset=to;
return FALSE;
}
/* This is used by mysql.cc */ /* This is used by mysql.cc */
bool String::fill(uint32 max_length,char fill_char) bool String::fill(uint32 max_length,char fill_char)
......
...@@ -179,6 +179,7 @@ public: ...@@ -179,6 +179,7 @@ public:
bool copy(); // Alloc string if not alloced bool copy(); // Alloc string if not alloced
bool copy(const String &s); // Allocate new string bool copy(const String &s); // Allocate new string
bool copy(const char *s,uint32 arg_length, CHARSET_INFO *cs); // Allocate new string bool copy(const char *s,uint32 arg_length, CHARSET_INFO *cs); // Allocate new string
bool copy(const char*s,uint32 arg_length, CHARSET_INFO *csfrom, CHARSET_INFO *csto);
bool append(const String &s); bool append(const String &s);
bool append(const char *s,uint32 arg_length=0); bool append(const char *s,uint32 arg_length=0);
bool append(IO_CACHE* file, uint32 arg_length); bool append(IO_CACHE* file, uint32 arg_length);
......
...@@ -2383,7 +2383,7 @@ static int my_vsnprintf_ucs2(char *dst, uint n, const char* fmt, va_list ap) ...@@ -2383,7 +2383,7 @@ static int my_vsnprintf_ucs2(char *dst, uint n, const char* fmt, va_list ap)
if (left_len <= plen*2) if (left_len <= plen*2)
plen = left_len/2 - 1; plen = left_len/2 - 1;
for ( ; plen ; plen--, dst++, par++) for ( ; plen ; plen--, dst+=2, par++)
{ {
dst[0]='\0'; dst[0]='\0';
dst[1]=par[0]; dst[1]=par[0];
......
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