Commit e56fb196 authored by bar@bar.mysql.r18.ru's avatar bar@bar.mysql.r18.ru

sql_type() is now ucs2 compatible

parent bedaf376
......@@ -207,10 +207,17 @@ bool Field::send_binary(Protocol *protocol)
void Field_num::add_zerofill_and_unsigned(String &res) const
{
if (unsigned_flag)
res.append(" unsigned");
if (zerofill)
res.append(" zerofill");
uint oldlen=res.length();
if (oldlen < res.alloced_length())
{
uint len=res.alloced_length()-oldlen;
char *end=(char*)(res.ptr()+oldlen);
CHARSET_INFO *cs=res.charset();
len=cs->snprintf(cs,end,len,"%s%s",
unsigned_flag ? " unsigned" : "",
zerofill ? " zerofill" : "");
res.length(len+oldlen);
}
}
void Field_num::make_field(Send_field *field)
......@@ -242,12 +249,17 @@ void Field_str::make_field(Send_field *field)
void Field_str::add_binary_or_charset(String &res) const
{
if (binary())
res.append(" binary");
else
uint oldlen=res.length();
if (oldlen < res.alloced_length())
{
res.append(" character set ");
res.append(field_charset->name);
CHARSET_INFO *cs=res.charset();
uint len=res.alloced_length() - oldlen;
char *end=(char*)(res.ptr()+oldlen);
if (binary())
len=cs->snprintf(cs,end,len," binary");
else
len=cs->snprintf(cs,end,len," character set %s",field_charset->name);
res.length(oldlen+len);
}
}
......@@ -333,7 +345,10 @@ bool Field::optimize_range(uint idx)
void Field_null::sql_type(String &res) const
{
res.copy("null",4,my_charset_latin1,res.charset());
CHARSET_INFO *cs=res.charset();
uint len;
len=cs->snprintf(cs,(char*)res.ptr(),res.alloced_length(),"null");
res.length(len);
}
......@@ -909,13 +924,15 @@ void Field_decimal::sort_string(char *to,uint length)
void Field_decimal::sql_type(String &res) const
{
CHARSET_INFO *cs=res.charset();
uint tmp=field_length;
uint len;
if (!unsigned_flag)
tmp--;
if (dec)
tmp--;
len=sprintf((char*) res.ptr(),"decimal(%d,%d)",tmp,dec);
len=cs->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
"decimal(%d,%d)",tmp,dec);
res.length(len);
add_zerofill_and_unsigned(res);
}
......@@ -1115,7 +1132,9 @@ void Field_tiny::sort_string(char *to,uint length __attribute__((unused)))
void Field_tiny::sql_type(String &res) const
{
uint len=sprintf((char*) res.ptr(),"tinyint(%d)",(int) field_length);
CHARSET_INFO *cs=res.charset();
uint len=cs->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
"tinyint(%d)",(int) field_length);
res.length(len);
add_zerofill_and_unsigned(res);
}
......@@ -1387,7 +1406,9 @@ void Field_short::sort_string(char *to,uint length __attribute__((unused)))
void Field_short::sql_type(String &res) const
{
uint len=sprintf((char*) res.ptr(),"smallint(%d)",(int) field_length);
CHARSET_INFO *cs=res.charset();
uint len=cs->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
"smallint(%d)",(int) field_length);
res.length(len);
add_zerofill_and_unsigned(res);
}
......@@ -1603,7 +1624,9 @@ void Field_medium::sort_string(char *to,uint length __attribute__((unused)))
void Field_medium::sql_type(String &res) const
{
uint len=sprintf((char*) res.ptr(),"mediumint(%d)",(int) field_length);
CHARSET_INFO *cs=res.charset();
uint len=cs->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
"mediumint(%d)",(int) field_length);
res.length(len);
add_zerofill_and_unsigned(res);
}
......@@ -1865,7 +1888,9 @@ void Field_long::sort_string(char *to,uint length __attribute__((unused)))
void Field_long::sql_type(String &res) const
{
uint len=sprintf((char*) res.ptr(),"int(%d)",(int) field_length);
CHARSET_INFO *cs=res.charset();
uint len=cs->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
"int(%d)",(int) field_length);
res.length(len);
add_zerofill_and_unsigned(res);
}
......@@ -2095,7 +2120,9 @@ void Field_longlong::sort_string(char *to,uint length __attribute__((unused)))
void Field_longlong::sql_type(String &res) const
{
uint len=sprintf((char*) res.ptr(),"bigint(%d)",(int) field_length);
CHARSET_INFO *cs=res.charset();
uint len=cs->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
"bigint(%d)",(int) field_length);
res.length(len);
add_zerofill_and_unsigned(res);
}
......@@ -2360,15 +2387,16 @@ bool Field_float::send_binary(Protocol *protocol)
void Field_float::sql_type(String &res) const
{
CHARSET_INFO *cs=res.charset();
uint len;
if (dec == NOT_FIXED_DEC)
{
strmov((char*) res.ptr(),"float");
len=5;
len=cs->snprintf(cs,(char*) res.ptr(),res.alloced_length(),"float");
}
else
{
len=sprintf((char*) res.ptr(),"float(%d,%d)",(int) field_length,dec);
len=cs->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
"float(%d,%d)",(int) field_length,dec);
}
res.length(len);
add_zerofill_and_unsigned(res);
......@@ -2619,15 +2647,16 @@ void Field_double::sort_string(char *to,uint length __attribute__((unused)))
void Field_double::sql_type(String &res) const
{
CHARSET_INFO *cs=res.charset();
uint len;
if (dec == NOT_FIXED_DEC)
{
strmov((char*) res.ptr(),"double");
len=6;
len=cs->snprintf(cs,(char*) res.ptr(),res.alloced_length(),"double");
}
else
{
len=sprintf((char*) res.ptr(),"double(%d,%d)",(int) field_length,dec);
len=cs->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
"double(%d,%d)",(int) field_length,dec);
}
res.length(len);
add_zerofill_and_unsigned(res);
......@@ -2960,7 +2989,9 @@ void Field_timestamp::sort_string(char *to,uint length __attribute__((unused)))
void Field_timestamp::sql_type(String &res) const
{
res.copy("timestamp", 9, my_charset_latin1, res.charset());
CHARSET_INFO *cs=res.charset();
uint len=cs->snprintf(cs,(char*)res.ptr(),res.alloced_length(),"timestamp");
res.length(len);
}
......@@ -3152,7 +3183,9 @@ void Field_time::sort_string(char *to,uint length __attribute__((unused)))
void Field_time::sql_type(String &res) const
{
res.copy("time",4,my_charset_latin1, res.charset());
CHARSET_INFO *cs=res.charset();
uint len=cs->snprintf(cs,(char*)res.ptr(),res.alloced_length(),"time");
res.length(len);
}
/****************************************************************************
......@@ -3242,9 +3275,10 @@ String *Field_year::val_str(String *val_buffer,
void Field_year::sql_type(String &res) const
{
ulong length=my_sprintf((char*) res.ptr(),
((char*) res.ptr(),"year(%d)",(int) field_length));
res.length(length);
CHARSET_INFO *cs=res.charset();
ulong len=cs->snprintf(cs,(char*)res.ptr(),res.alloced_length(),
"year(%d)",(int) field_length);
res.length(len);
}
......@@ -3414,7 +3448,9 @@ void Field_date::sort_string(char *to,uint length __attribute__((unused)))
void Field_date::sql_type(String &res) const
{
res.copy("date",4,my_charset_latin1, res.charset());
CHARSET_INFO *cs=res.charset();
uint len=cs->snprintf(cs,(char*)res.ptr(),res.alloced_length(),"date");
res.length(len);
}
/****************************************************************************
......@@ -3577,7 +3613,9 @@ void Field_newdate::sort_string(char *to,uint length __attribute__((unused)))
void Field_newdate::sql_type(String &res) const
{
res.copy("date",4,my_charset_latin1, res.charset());
CHARSET_INFO *cs=res.charset();
uint len=cs->snprintf(cs,(char*)res.ptr(),res.alloced_length(),"date");
res.length(len);
}
......@@ -3801,7 +3839,9 @@ void Field_datetime::sort_string(char *to,uint length __attribute__((unused)))
void Field_datetime::sql_type(String &res) const
{
res.copy("datetime",8,my_charset_latin1, res.charset());
CHARSET_INFO *cs=res.charset();
uint len=cs->snprintf(cs,(char*)res.ptr(),res.alloced_length(),"datetime");
res.length(len);
}
/****************************************************************************
......@@ -3930,13 +3970,14 @@ void Field_string::sort_string(char *to,uint length)
void Field_string::sql_type(String &res) const
{
ulong length= my_sprintf((char*) res.ptr(),
((char*) res.ptr(), "%s(%d)",
CHARSET_INFO *cs=res.charset();
ulong length= cs->snprintf(cs,(char*) res.ptr(),
res.alloced_length(), "%s(%d)",
(field_length > 3 &&
(table->db_options_in_use &
HA_OPTION_PACK_RECORD) ?
"varchar" : "char"),
(int) field_length));
(int) field_length);
res.length(length);
add_binary_or_charset(res);
}
......@@ -4126,9 +4167,10 @@ void Field_varstring::sort_string(char *to,uint length)
void Field_varstring::sql_type(String &res) const
{
ulong length= my_sprintf((char*) res.ptr(),
((char*) res.ptr(),"varchar(%u)",
field_length));
CHARSET_INFO *cs=res.charset();
ulong length= cs->snprintf(cs,(char*) res.ptr(),
res.alloced_length(),"varchar(%u)",
field_length);
res.length(length);
add_binary_or_charset(res);
}
......@@ -4619,20 +4661,22 @@ void Field_blob::sort_string(char *to,uint length)
void Field_blob::sql_type(String &res) const
{
CHARSET_INFO *cs=res.charset();
const char *str;
uint len;
switch (packlength) {
default: str="tiny"; break;
case 2: str=""; break;
case 3: str="medium"; break;
case 4: str="long"; break;
}
res.set(str,(uint) strlen(str),my_charset_latin1);
res.append(binary() ? "blob" : "text");
if (!binary())
{
res.append(" character set ");
res.append(field_charset->name);
}
len=cs->snprintf(cs,(char*)res.ptr(),res.alloced_length(),"%s%s%s%s",
str,
binary() ? "blob" : "text",
binary() ? "" : " character set ",
binary() ? "" : field_charset->name);
res.length(len);
}
......
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