hi all:
I have a
problem about the type cast when I have read the source of Maria &
MySQL
I notice
that when cast from string into int, Maria & MySQL do
it like the C function atoi
code:
for (ul= 0 ; str <
end9 && (ch= (uchar) (*str - '0')) < 10;
str++)
{
ul= ul * 10 +
ch;
}
but cast from hex into int, the
code is:
code:
char *end=(char*)
str_value.ptr()+str_value.length(),
*ptr=end-min(str_value.length(),sizeof(longlong));
ulonglong
value=0;
for (; ptr != end ;
ptr++)
value=(value <<
8)+ (ulonglong) (uchar) *ptr;
so I do the
test blew:
create table t(id int auto_increment primary key, a
int)engine=innodb;
insert into t(a) values('1');
insert into t(a)
values(0x31);
everything is ok, I get the
result:
mysql> select * from
t;
+----+------+
| id | a
|
+----+------+
|
1
| 1 |
|
2 | 49
|
+----+------+
the value 0x31 is the ascii of
the string '1', but we got the different result after
inserting
maybe it's not a problem, but in
the replication environment, it maybe cause the data of slave not the same as
master
In the master, when we set the
connection characterset into multi-bytes characterset and this characterset may
escape with backslash is dangerous (like gbk, cp932) and then we use the
prepared statement to do the insert, the string value in the insert must be cast
into hex before write into the binlog, so we do the insert(insert into t(a)
values('1')) on the master, but in the slave it does the another(insert into
t(a) values(0x31)) , the data is not the same.
how to
reappear:
master(binlog
format=statement):
create table t(id int
auto_increment primay key, a int) engine=innodb;
set names
gbk;
prepare stmt from 'insert
into t(a) values(?)';
set
@a='1';
execute stmt using
@a;
the result in master
is:
mysql> select * from
t;
+----+------+
|
id | a
|
+----+------+
|
1 | 1
|
+----+------+
and result in slave
is:
mysql> select * from
t;
+----+------+
|
id | a
|
+----+------+
|
1 | 49
|
+----+------+
I test the newest release version
mariadb-10.0.2 and MySQL-5.6.10, the problem is still exist, is this a
bug?
2013-04-28
jhx1008
@netease