mirror of
https://github.com/MariaDB/server.git
synced 2025-01-31 11:01:52 +01:00
Merge abarkov@bk-internal.mysql.com:/home/bk/mysql-4.1
into mysql.com:/usr/home/bar/mysql-4.1.b10446
This commit is contained in:
commit
5c1ba75cfd
5 changed files with 53 additions and 15 deletions
|
@ -181,11 +181,18 @@ select * from t1 where a=_koi8r'
|
|||
a
|
||||
×ÁÓÑ
|
||||
select * from t1 where a=concat(_koi8r'×ÁÓÑ');
|
||||
ERROR HY000: Illegal mix of collations (cp1251_general_ci,IMPLICIT) and (koi8r_general_ci,COERCIBLE) for operation '='
|
||||
a
|
||||
×ÁÓÑ
|
||||
select * from t1 where a=_latin1'×ÁÓÑ';
|
||||
ERROR HY000: Illegal mix of collations (cp1251_general_ci,IMPLICIT) and (latin1_swedish_ci,COERCIBLE) for operation '='
|
||||
drop table t1;
|
||||
set names latin1;
|
||||
create table t1 (a char(10) character set utf8 collate utf8_bin);
|
||||
insert into t1 values (' xxx');
|
||||
select * from t1 where a=lpad('xxx',10,' ');
|
||||
a
|
||||
xxx
|
||||
drop table t1;
|
||||
set names koi8r;
|
||||
create table t1 (c1 char(10) character set cp1251);
|
||||
insert into t1 values ('ß');
|
||||
|
|
|
@ -144,8 +144,7 @@ create table t1 (a char(10) character set cp1251);
|
|||
insert into t1 values (_koi8r'×ÁÓÑ');
|
||||
# this is possible:
|
||||
select * from t1 where a=_koi8r'×ÁÓÑ';
|
||||
# this is not possible, because we have a function, not just a constant:
|
||||
--error 1267
|
||||
# this is possible, because we have a function with constant arguments:
|
||||
select * from t1 where a=concat(_koi8r'×ÁÓÑ');
|
||||
# this is not posible, cannot convert _latin1'×ÁÓÑ' into cp1251:
|
||||
--error 1267
|
||||
|
@ -153,6 +152,14 @@ select * from t1 where a=_latin1'
|
|||
drop table t1;
|
||||
set names latin1;
|
||||
|
||||
#
|
||||
# Bug#10446 Illegal mix of collations
|
||||
#
|
||||
create table t1 (a char(10) character set utf8 collate utf8_bin);
|
||||
insert into t1 values (' xxx');
|
||||
select * from t1 where a=lpad('xxx',10,' ');
|
||||
drop table t1;
|
||||
|
||||
#
|
||||
# Check more automatic conversion
|
||||
#
|
||||
|
|
12
sql/item.cc
12
sql/item.cc
|
@ -211,16 +211,8 @@ bool Item::eq(const Item *item, bool binary_cmp) const
|
|||
|
||||
Item *Item::safe_charset_converter(CHARSET_INFO *tocs)
|
||||
{
|
||||
/*
|
||||
Allow conversion from and to "binary".
|
||||
Don't allow automatic conversion to non-Unicode charsets,
|
||||
as it potentially loses data.
|
||||
*/
|
||||
if (collation.collation != &my_charset_bin &&
|
||||
tocs != &my_charset_bin &&
|
||||
!(tocs->state & MY_CS_UNICODE))
|
||||
return NULL; // safe conversion is not possible
|
||||
return new Item_func_conv_charset(this, tocs);
|
||||
Item_func_conv_charset *conv= new Item_func_conv_charset(this, tocs, 1);
|
||||
return conv->safe ? conv : NULL;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2252,6 +2252,8 @@ String *Item_func_conv::val_str(String *str)
|
|||
String *Item_func_conv_charset::val_str(String *str)
|
||||
{
|
||||
DBUG_ASSERT(fixed == 1);
|
||||
if (use_cached_value)
|
||||
return null_value ? 0 : &str_value;
|
||||
String *arg= args[0]->val_str(str);
|
||||
uint dummy_errors;
|
||||
if (!arg)
|
||||
|
|
|
@ -614,10 +614,40 @@ public:
|
|||
|
||||
class Item_func_conv_charset :public Item_str_func
|
||||
{
|
||||
bool use_cached_value;
|
||||
public:
|
||||
bool safe;
|
||||
CHARSET_INFO *conv_charset; // keep it public
|
||||
Item_func_conv_charset(Item *a, CHARSET_INFO *cs) :Item_str_func(a)
|
||||
{ conv_charset=cs; }
|
||||
{ conv_charset= cs; use_cached_value= 0; safe= 0; }
|
||||
Item_func_conv_charset(Item *a, CHARSET_INFO *cs, bool cache_if_const)
|
||||
:Item_str_func(a)
|
||||
{
|
||||
DBUG_ASSERT(args[0]->fixed);
|
||||
conv_charset= cs;
|
||||
if (cache_if_const && args[0]->const_item())
|
||||
{
|
||||
uint errors= 0;
|
||||
String tmp, *str= args[0]->val_str(&tmp);
|
||||
if (!str || str_value.copy(str->ptr(), str->length(),
|
||||
str->charset(), conv_charset, &errors))
|
||||
null_value= 1;
|
||||
use_cached_value= 1;
|
||||
safe= (errors == 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
use_cached_value= 0;
|
||||
/*
|
||||
Conversion from and to "binary" is safe.
|
||||
Conversion to Unicode is safe.
|
||||
Other kind of conversions are potentially lossy.
|
||||
*/
|
||||
safe= (args[0]->collation.collation == &my_charset_bin ||
|
||||
cs == &my_charset_bin ||
|
||||
(cs->state & MY_CS_UNICODE));
|
||||
}
|
||||
}
|
||||
String *val_str(String *);
|
||||
void fix_length_and_dec();
|
||||
const char *func_name() const { return "convert"; }
|
||||
|
|
Loading…
Add table
Reference in a new issue