Commit 13e11faa 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/hdc/Sinisa/mysql-4.1
parents 17384904 1c4138bf
......@@ -49,7 +49,7 @@ sqlsources = convert.cc derror.cc field.cc field_conv.cc filesort.cc \
repl_failsafe.cc slave.cc \
sql_analyse.cc sql_base.cc sql_cache.cc sql_class.cc \
sql_crypt.cc sql_db.cc sql_delete.cc sql_insert.cc sql_lex.cc \
sql_list.cc sql_manager.cc sql_map.cc sql_parse.cc \
sql_list.cc sql_manager.cc sql_map.cc sql_parse.cc sql_derived.cc \
sql_rename.cc sql_repl.cc sql_select.cc sql_do.cc sql_show.cc \
sql_string.cc sql_table.cc sql_test.cc sql_udf.cc \
sql_update.cc sql_yacc.cc table.cc thr_malloc.cc time.cc \
......
......@@ -79,7 +79,7 @@ mysqld_SOURCES = sql_lex.cc sql_handler.cc \
sql_db.cc sql_table.cc sql_rename.cc sql_crypt.cc \
sql_load.cc mf_iocache.cc field_conv.cc sql_show.cc \
sql_udf.cc sql_analyse.cc sql_analyse.h sql_cache.cc \
slave.cc sql_repl.cc sql_union.cc \
slave.cc sql_repl.cc sql_union.cc sql_derived.cc \
mini_client.cc mini_client_errors.c \
stacktrace.c repl_failsafe.h repl_failsafe.cc \
gstream.cc spatial.cc
......
......@@ -1776,6 +1776,146 @@ String *Item_func_conv::val_str(String *str)
}
String *Item_func_conv_charset::val_str(String *str)
{
my_wc_t wc;
int cnvres;
const uchar *s, *se;
uchar *d, *d0, *de;
uint dmaxlen;
String *arg= args[0]->val_str(str);
CHARSET_INFO *from,*to;
if (!arg)
{
null_value=1;
return 0;
}
from=arg->charset();
to=conv_charset;
s=(const uchar*)arg->ptr();
se=s+arg->length();
dmaxlen=arg->length()*(conv_charset->mbmaxlen?conv_charset->mbmaxlen:1)+1;
str->alloc(dmaxlen);
d0=d=(unsigned char*)str->ptr();
de=d+dmaxlen;
while( s < se && d < de){
cnvres=from->mb_wc(from,&wc,s,se);
if (cnvres>0)
{
s+=cnvres;
}
else if (cnvres==MY_CS_ILSEQ)
{
s++;
wc='?';
}
else
break;
outp:
cnvres=to->wc_mb(to,wc,d,de);
if (cnvres>0)
{
d+=cnvres;
}
else if (cnvres==MY_CS_ILUNI && wc!='?')
{
wc='?';
goto outp;
}
else
break;
};
str->length((uint) (d-d0));
str->set_charset(to);
return str;
}
void Item_func_conv_charset::fix_length_and_dec()
{
/* BAR TODO: What to do here??? */
}
String *Item_func_conv_charset3::val_str(String *str)
{
my_wc_t wc;
int cnvres;
const uchar *s, *se;
uchar *d, *d0, *de;
uint dmaxlen;
String *arg= args[0]->val_str(str);
String *to_cs= args[1]->val_str(str);
String *from_cs= args[2]->val_str(str);
CHARSET_INFO *from_charset;
CHARSET_INFO *to_charset;
if (!arg || args[0]->null_value ||
!to_cs || args[1]->null_value ||
!from_cs || args[2]->null_value ||
!(from_charset=find_compiled_charset_by_name(from_cs->ptr())) ||
!(to_charset=find_compiled_charset_by_name(to_cs->ptr())))
{
null_value=1;
return 0;
}
s=(const uchar*)arg->ptr();
se=s+arg->length();
dmaxlen=arg->length()*(to_charset->mbmaxlen?to_charset->mbmaxlen:1)+1;
str->alloc(dmaxlen);
d0=d=(unsigned char*)str->ptr();
de=d+dmaxlen;
while( s < se && d < de){
cnvres=from_charset->mb_wc(from_charset,&wc,s,se);
if (cnvres>0)
{
s+=cnvres;
}
else if (cnvres==MY_CS_ILSEQ)
{
s++;
wc='?';
}
else
break;
outp:
cnvres=to_charset->wc_mb(to_charset,wc,d,de);
if (cnvres>0)
{
d+=cnvres;
}
else if (cnvres==MY_CS_ILUNI && wc!='?')
{
wc='?';
goto outp;
}
else
break;
};
str->length((uint) (d-d0));
str->set_charset(to_charset);
return str;
}
void Item_func_conv_charset3::fix_length_and_dec()
{
/* BAR TODO: What to do here??? */
}
String *Item_func_hex::val_str(String *str)
{
if (args[0]->result_type() != STRING_RESULT)
......
......@@ -476,6 +476,29 @@ class Item_func_export_set: public Item_str_func
void fix_length_and_dec() { decimals = 0; max_length=3*8+7; }
};
class Item_func_conv_charset :public Item_str_func
{
CHARSET_INFO *conv_charset;
public:
Item_func_conv_charset(Item *a, CHARSET_INFO *cs) :Item_str_func(a)
{
conv_charset=cs;
}
String *val_str(String *);
void fix_length_and_dec();
const char *func_name() const { return "conv_charset"; }
};
class Item_func_conv_charset3 :public Item_str_func
{
public:
Item_func_conv_charset3(Item *arg1,Item *arg2,Item *arg3)
:Item_str_func(arg1,arg2,arg3) {}
String *val_str(String *);
void fix_length_and_dec();
const char *func_name() const { return "conv_charset3"; }
};
/*******************************************************
Spatial functions
......
......@@ -1654,6 +1654,20 @@ simple_expr:
| CASE_SYM opt_expr WHEN_SYM when_list opt_else END
{ $$= new Item_func_case(* $4, $2, $5 ); }
| CONVERT_SYM '(' expr ',' cast_type ')' { $$= create_func_cast($3, $5); }
| CONVERT_SYM '(' expr USING IDENT ')'
{
CHARSET_INFO *cs=find_compiled_charset_by_name($5.str);
if (!cs)
{
net_printf(&current_thd->net,ER_UNKNOWN_CHARACTER_SET,$5);
YYABORT;
}
$$= new Item_func_conv_charset($3,cs);
}
| CONVERT_SYM '(' expr ',' expr ',' expr ')'
{
$$= new Item_func_conv_charset3($3,$5,$7);
}
| FUNC_ARG0 '(' ')'
{ $$= ((Item*(*)(void))($1.symbol->create_func))();}
| FUNC_ARG1 '(' expr ')'
......
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