Commit 4b65859a authored by Alexander Barkov's avatar Alexander Barkov

MDEV-32645 CAST(AS UNSIGNED) fails with --view-protocol

Item_char_typecast::print() did not print the "binary" keyword
in such cases:
   CAST('a' AS CHAR CHARACTER SET latin1 BINARY)

This caused a difference in "mtr" vs "mtr --view-protocol"
parent 9b049266
...@@ -158,10 +158,9 @@ select cast(1 as double(64,63)); ...@@ -158,10 +158,9 @@ select cast(1 as double(64,63));
# #
set names binary; set names binary;
select cast(_latin1'test' as char character set latin2); select cast(_latin1'test' as char character set latin2);
#enable after MDEV-32461 fix --disable_service_connection
--disable_view_protocol
select cast(_koi8r'' as char character set cp1251); select cast(_koi8r'' as char character set cp1251);
--enable_view_protocol --enable_service_connection
create table t1 select cast(_koi8r'' as char character set cp1251) as t; create table t1 select cast(_koi8r'' as char character set cp1251) as t;
show create table t1; show create table t1;
drop table t1; drop table t1;
...@@ -169,8 +168,7 @@ drop table t1; ...@@ -169,8 +168,7 @@ drop table t1;
# #
# CAST to CHAR with/without length # CAST to CHAR with/without length
# #
#enable after MDEV-32461 fix --disable_service_connection
--disable_view_protocol
select select
cast(_latin1'ab' AS char) as c1, cast(_latin1'ab' AS char) as c1,
cast(_latin1'a ' AS char) as c2, cast(_latin1'a ' AS char) as c2,
...@@ -178,7 +176,7 @@ select ...@@ -178,7 +176,7 @@ select
cast(_latin1'a ' AS char(2)) as c4, cast(_latin1'a ' AS char(2)) as c4,
hex(cast(_latin1'a' AS char(2))) as c5; hex(cast(_latin1'a' AS char(2))) as c5;
select cast(1000 as CHAR(3)); select cast(1000 as CHAR(3));
--enable_view_protocol --enable_service_connection
SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR
create table t1 select create table t1 select
...@@ -239,15 +237,14 @@ select cast("1:2:3" as TIME) = "1:02:03"; ...@@ -239,15 +237,14 @@ select cast("1:2:3" as TIME) = "1:02:03";
# #
CREATE TABLE t1 (a enum ('aac','aab','aaa') not null); CREATE TABLE t1 (a enum ('aac','aab','aaa') not null);
INSERT INTO t1 VALUES ('aaa'),('aab'),('aac'); INSERT INTO t1 VALUES ('aaa'),('aab'),('aac');
#enable after MDEV-32461 fix --disable_service_connection
--disable_view_protocol
# these two should be in enum order # these two should be in enum order
SELECT a, CAST(a AS CHAR) FROM t1 ORDER BY CAST(a AS UNSIGNED) ; SELECT a, CAST(a AS CHAR) FROM t1 ORDER BY CAST(a AS UNSIGNED) ;
SELECT a, CAST(a AS CHAR(3)) FROM t1 ORDER BY CAST(a AS CHAR(2)), a; SELECT a, CAST(a AS CHAR(3)) FROM t1 ORDER BY CAST(a AS CHAR(2)), a;
# these two should be in alphabetic order # these two should be in alphabetic order
SELECT a, CAST(a AS UNSIGNED) FROM t1 ORDER BY CAST(a AS CHAR) ; SELECT a, CAST(a AS UNSIGNED) FROM t1 ORDER BY CAST(a AS CHAR) ;
SELECT a, CAST(a AS CHAR(2)) FROM t1 ORDER BY CAST(a AS CHAR(3)), a; SELECT a, CAST(a AS CHAR(2)) FROM t1 ORDER BY CAST(a AS CHAR(3)), a;
--enable_view_protocol --enable_service_connection
DROP TABLE t1; DROP TABLE t1;
# #
...@@ -349,12 +346,11 @@ select cast(NULL as decimal(6)) as t1; ...@@ -349,12 +346,11 @@ select cast(NULL as decimal(6)) as t1;
# Bug #17903: cast to char results in binary # Bug #17903: cast to char results in binary
# #
set names latin1; set names latin1;
#enable after MDEV-32461 fix --disable_service_connection
--disable_view_protocol
select hex(cast('a' as char(2) binary)); select hex(cast('a' as char(2) binary));
select hex(cast('a' as binary(2))); select hex(cast('a' as binary(2)));
select hex(cast('a' as char(2) binary)); select hex(cast('a' as char(2) binary));
--enable_view_protocol --enable_service_connection
# #
# Bug#29898: Item_date_typecast::val_int doesn't reset the null_value flag. # Bug#29898: Item_date_typecast::val_int doesn't reset the null_value flag.
...@@ -484,14 +480,13 @@ drop table t1; ...@@ -484,14 +480,13 @@ drop table t1;
# #
# CAST (... BINARY) # CAST (... BINARY)
# #
#enable after MDEV-32461 fix --disable_service_connection
--disable_view_protocol
select collation(cast("a" as char(10) binary)); select collation(cast("a" as char(10) binary));
select collation(cast("a" as char(10) charset utf8 binary)); select collation(cast("a" as char(10) charset utf8 binary));
select collation(cast("a" as char(10) ascii binary)); select collation(cast("a" as char(10) ascii binary));
select collation(cast("a" as char(10) binary charset utf8)); select collation(cast("a" as char(10) binary charset utf8));
select collation(cast("a" as char(10) binary ascii)); select collation(cast("a" as char(10) binary ascii));
--enable_view_protocol --enable_service_connection
--echo # --echo #
--echo # MDEV-11030 Assertion `precision > 0' failed in decimal_bin_size --echo # MDEV-11030 Assertion `precision > 0' failed in decimal_bin_size
...@@ -773,14 +768,14 @@ INSERT INTO t1 VALUES (-1.0); ...@@ -773,14 +768,14 @@ INSERT INTO t1 VALUES (-1.0);
SELECT * FROM t1; SELECT * FROM t1;
DROP TABLE t1; DROP TABLE t1;
#enable after MDEV-32461 fix #enable after MDEV-32645 is fixed
--disable_view_protocol --disable_view_protocol
SELECT CAST(-1e0 AS UNSIGNED); SELECT CAST(-1e0 AS UNSIGNED);
--enable_view_protocol
CREATE TABLE t1 (a BIGINT UNSIGNED); CREATE TABLE t1 (a BIGINT UNSIGNED);
INSERT INTO t1 VALUES (-1e0); INSERT INTO t1 VALUES (-1e0);
SELECT * FROM t1; SELECT * FROM t1;
DROP TABLE t1; DROP TABLE t1;
--enable_view_protocol
SELECT CAST(-1e308 AS UNSIGNED); SELECT CAST(-1e308 AS UNSIGNED);
CREATE TABLE t1 (a BIGINT UNSIGNED); CREATE TABLE t1 (a BIGINT UNSIGNED);
......
...@@ -2268,6 +2268,13 @@ void Item_char_typecast::print(String *str, enum_query_type query_type) ...@@ -2268,6 +2268,13 @@ void Item_char_typecast::print(String *str, enum_query_type query_type)
{ {
str->append(STRING_WITH_LEN(" charset ")); str->append(STRING_WITH_LEN(" charset "));
str->append(cast_cs->csname); str->append(cast_cs->csname);
/*
Print the "binary" keyword in cases like:
CAST('str' AS CHAR CHARACTER SET latin1 BINARY)
*/
if ((cast_cs->state & MY_CS_BINSORT) &&
Charset(cast_cs).can_have_collate_clause())
str->append(STRING_WITH_LEN(" binary"));
} }
str->append(')'); str->append(')');
} }
......
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