Commit b37386d8 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-20785 Converting INET6 to CHAR(39) produces garbage without a warning

parent c78ae293
...@@ -1266,6 +1266,117 @@ Warning 1292 Incorrect inet6 value: '::192.168.0.1' ...@@ -1266,6 +1266,117 @@ Warning 1292 Incorrect inet6 value: '::192.168.0.1'
Warning 1292 Incorrect inet6 value: '::ffff:192.168.0.1' Warning 1292 Incorrect inet6 value: '::ffff:192.168.0.1'
DROP TABLE t1; DROP TABLE t1;
# #
# ALTER to character string data types
#
CREATE OR REPLACE TABLE t1 (a INET6);
INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329');
SELECT CAST(a AS CHAR(39)) FROM t1;
CAST(a AS CHAR(39))
2001:db8::ff00:42:8329
ALTER TABLE t1 MODIFY a CHAR(39);
SELECT * FROM t1;
a
2001:db8::ff00:42:8329
DROP TABLE t1;
CREATE OR REPLACE TABLE t1 (a INET6);
INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329');
ALTER TABLE t1 MODIFY a VARCHAR(39);
SELECT * FROM t1;
a
2001:db8::ff00:42:8329
DROP TABLE t1;
CREATE OR REPLACE TABLE t1 (a INET6);
INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329');
ALTER TABLE t1 MODIFY a TINYTEXT;
SELECT * FROM t1;
a
2001:db8::ff00:42:8329
DROP TABLE t1;
CREATE OR REPLACE TABLE t1 (a INET6);
INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329');
ALTER TABLE t1 MODIFY a TEXT;
SELECT * FROM t1;
a
2001:db8::ff00:42:8329
DROP TABLE t1;
CREATE OR REPLACE TABLE t1 (a INET6);
INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329');
ALTER TABLE t1 MODIFY a MEDIUMTEXT;
SELECT * FROM t1;
a
2001:db8::ff00:42:8329
DROP TABLE t1;
CREATE OR REPLACE TABLE t1 (a INET6);
INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329');
ALTER TABLE t1 MODIFY a LONGTEXT;
SELECT * FROM t1;
a
2001:db8::ff00:42:8329
DROP TABLE t1;
#
# ALTER from character string data types
#
CREATE OR REPLACE TABLE t1 (a CHAR(64));
INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329');
SELECT CAST(a AS INET6) FROM t1;
CAST(a AS INET6)
2001:db8::ff00:42:8329
ALTER TABLE t1 MODIFY a INET6;
SELECT * FROM t1;
a
2001:db8::ff00:42:8329
DROP TABLE t1;
CREATE OR REPLACE TABLE t1 (a VARCHAR(64));
INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329');
SELECT CAST(a AS INET6) FROM t1;
CAST(a AS INET6)
2001:db8::ff00:42:8329
ALTER TABLE t1 MODIFY a INET6;
SELECT * FROM t1;
a
2001:db8::ff00:42:8329
DROP TABLE t1;
CREATE OR REPLACE TABLE t1 (a TINYTEXT);
INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329');
SELECT CAST(a AS INET6) FROM t1;
CAST(a AS INET6)
2001:db8::ff00:42:8329
ALTER TABLE t1 MODIFY a INET6;
SELECT * FROM t1;
a
2001:db8::ff00:42:8329
DROP TABLE t1;
CREATE OR REPLACE TABLE t1 (a TEXT);
INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329');
SELECT CAST(a AS INET6) FROM t1;
CAST(a AS INET6)
2001:db8::ff00:42:8329
ALTER TABLE t1 MODIFY a INET6;
SELECT * FROM t1;
a
2001:db8::ff00:42:8329
DROP TABLE t1;
CREATE OR REPLACE TABLE t1 (a MEDIUMTEXT);
INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329');
SELECT CAST(a AS INET6) FROM t1;
CAST(a AS INET6)
2001:db8::ff00:42:8329
ALTER TABLE t1 MODIFY a INET6;
SELECT * FROM t1;
a
2001:db8::ff00:42:8329
DROP TABLE t1;
CREATE OR REPLACE TABLE t1 (a LONGTEXT);
INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329');
SELECT CAST(a AS INET6) FROM t1;
CAST(a AS INET6)
2001:db8::ff00:42:8329
ALTER TABLE t1 MODIFY a INET6;
SELECT * FROM t1;
a
2001:db8::ff00:42:8329
DROP TABLE t1;
#
# Limit clause parameter # Limit clause parameter
# TODO: this should fail. # TODO: this should fail.
# The test for a valid data type should be moved # The test for a valid data type should be moved
...@@ -1274,3 +1385,16 @@ DROP TABLE t1; ...@@ -1274,3 +1385,16 @@ DROP TABLE t1;
# #
EXECUTE IMMEDIATE 'SELECT 1 FROM DUAL LIMIT ?' USING CAST('::' AS INET6); EXECUTE IMMEDIATE 'SELECT 1 FROM DUAL LIMIT ?' USING CAST('::' AS INET6);
1 1
#
# MDEV-20785 Converting INET6 to CHAR(39) produces garbage without a warning
#
CREATE OR REPLACE TABLE t1 (a INET6);
INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329');
SELECT CAST(a AS CHAR(39)) FROM t1;
CAST(a AS CHAR(39))
2001:db8::ff00:42:8329
ALTER TABLE t1 MODIFY a CHAR(39);
SELECT * FROM t1;
a
2001:db8::ff00:42:8329
DROP TABLE t1;
...@@ -813,6 +813,96 @@ SELECT id, length(a), a, IS_IPV4_MAPPED(BINARY a) FROM t1 ORDER BY id; ...@@ -813,6 +813,96 @@ SELECT id, length(a), a, IS_IPV4_MAPPED(BINARY a) FROM t1 ORDER BY id;
SELECT id, length(a), a, IS_IPV4_COMPAT(BINARY a) FROM t1 ORDER BY id; SELECT id, length(a), a, IS_IPV4_COMPAT(BINARY a) FROM t1 ORDER BY id;
DROP TABLE t1; DROP TABLE t1;
--echo #
--echo # ALTER to character string data types
--echo #
CREATE OR REPLACE TABLE t1 (a INET6);
INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329');
SELECT CAST(a AS CHAR(39)) FROM t1;
ALTER TABLE t1 MODIFY a CHAR(39);
SELECT * FROM t1;
DROP TABLE t1;
CREATE OR REPLACE TABLE t1 (a INET6);
INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329');
ALTER TABLE t1 MODIFY a VARCHAR(39);
SELECT * FROM t1;
DROP TABLE t1;
CREATE OR REPLACE TABLE t1 (a INET6);
INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329');
ALTER TABLE t1 MODIFY a TINYTEXT;
SELECT * FROM t1;
DROP TABLE t1;
CREATE OR REPLACE TABLE t1 (a INET6);
INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329');
ALTER TABLE t1 MODIFY a TEXT;
SELECT * FROM t1;
DROP TABLE t1;
CREATE OR REPLACE TABLE t1 (a INET6);
INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329');
ALTER TABLE t1 MODIFY a MEDIUMTEXT;
SELECT * FROM t1;
DROP TABLE t1;
CREATE OR REPLACE TABLE t1 (a INET6);
INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329');
ALTER TABLE t1 MODIFY a LONGTEXT;
SELECT * FROM t1;
DROP TABLE t1;
--echo #
--echo # ALTER from character string data types
--echo #
CREATE OR REPLACE TABLE t1 (a CHAR(64));
INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329');
SELECT CAST(a AS INET6) FROM t1;
ALTER TABLE t1 MODIFY a INET6;
SELECT * FROM t1;
DROP TABLE t1;
CREATE OR REPLACE TABLE t1 (a VARCHAR(64));
INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329');
SELECT CAST(a AS INET6) FROM t1;
ALTER TABLE t1 MODIFY a INET6;
SELECT * FROM t1;
DROP TABLE t1;
CREATE OR REPLACE TABLE t1 (a TINYTEXT);
INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329');
SELECT CAST(a AS INET6) FROM t1;
ALTER TABLE t1 MODIFY a INET6;
SELECT * FROM t1;
DROP TABLE t1;
CREATE OR REPLACE TABLE t1 (a TEXT);
INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329');
SELECT CAST(a AS INET6) FROM t1;
ALTER TABLE t1 MODIFY a INET6;
SELECT * FROM t1;
DROP TABLE t1;
CREATE OR REPLACE TABLE t1 (a MEDIUMTEXT);
INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329');
SELECT CAST(a AS INET6) FROM t1;
ALTER TABLE t1 MODIFY a INET6;
SELECT * FROM t1;
DROP TABLE t1;
CREATE OR REPLACE TABLE t1 (a LONGTEXT);
INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329');
SELECT CAST(a AS INET6) FROM t1;
ALTER TABLE t1 MODIFY a INET6;
SELECT * FROM t1;
DROP TABLE t1;
--echo # --echo #
--echo # Limit clause parameter --echo # Limit clause parameter
--echo # TODO: this should fail. --echo # TODO: this should fail.
...@@ -833,3 +923,15 @@ EXECUTE IMMEDIATE 'SELECT 1 FROM DUAL LIMIT ?' USING CAST('::' AS INET6); ...@@ -833,3 +923,15 @@ EXECUTE IMMEDIATE 'SELECT 1 FROM DUAL LIMIT ?' USING CAST('::' AS INET6);
## - This should fail with the "illegal data type" error: ## - This should fail with the "illegal data type" error:
## EXTRACT(MINUTE...) ## EXTRACT(MINUTE...)
## ##
--echo #
--echo # MDEV-20785 Converting INET6 to CHAR(39) produces garbage without a warning
--echo #
CREATE OR REPLACE TABLE t1 (a INET6);
INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329');
SELECT CAST(a AS CHAR(39)) FROM t1;
ALTER TABLE t1 MODIFY a CHAR(39);
SELECT * FROM t1;
DROP TABLE t1;
...@@ -786,7 +786,7 @@ Field::Copy_func *Field_string::get_copy_func(const Field *from) const ...@@ -786,7 +786,7 @@ Field::Copy_func *Field_string::get_copy_func(const Field *from) const
{ {
if (from->type() == MYSQL_TYPE_BIT) if (from->type() == MYSQL_TYPE_BIT)
return do_field_int; return do_field_int;
if (Field_string::real_type() != from->real_type() || if (Field_string::type_handler() != from->type_handler() ||
Field_string::charset() != from->charset()) Field_string::charset() != from->charset())
return do_field_string; return do_field_string;
if (Field_string::pack_length() < from->pack_length()) if (Field_string::pack_length() < from->pack_length())
......
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