#
# Start of 10.7 tests
#
#
# MDEV-28918 Implicit cast from INET6 UNSIGNED works differently on UPDATE vs ALTER
#
SET @ignore='IGNORE';
CREATE TABLE t1 (target INET6 DEFAULT '::0', source DOUBLE DEFAULT 0);
# Start of type_store_assignment_incompatible.inc
SET @sql_mode_save= @@sql_mode;
SET @source_type= (SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME='source'
                   AND TABLE_NAME='t1'
                   AND TABLE_SCHEMA='test');
SET @target_type= (SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME='target'
                   AND TABLE_NAME='t1'
                   AND TABLE_SCHEMA='test');
SET @ignore= CASE WHEN @ignore IS NULL OR @ignore = '' THEN ''
                  WHEN @ignore NOT LIKE ' %' THEN CONCAT(' ',@ignore)
ELSE @ignore
END;
CREATE TABLE t2 LIKE t1;
ALTER TABLE t2 ADD id INT NOT NULL PRIMARY KEY FIRST;
INSERT INTO t2 VALUES (1,DEFAULT,DEFAULT);
SHOW CREATE TABLE t2;
Table	Create Table
t2	CREATE TABLE `t2` (
  `id` int(11) NOT NULL,
  `target` inet6 DEFAULT '::',
  `source` double DEFAULT 0,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
CREATE TABLE t3 LIKE t2;
INSERT IGNORE INTO t3 VALUES
(1,
(SELECT source FROM t2 ORDER BY id LIMIT 1),
(SELECT source FROM t2 ORDER BY id LIMIT 1));
Warnings:
Warning	4078	Cannot cast 'double' as 'inet6' in assignment of `test`.`t3`.`target`
Warning	1292	Incorrect inet6 value: '0' for column `test`.`t3`.`target` at row 1
DROP TABLE t3;
SET sql_mode='';
CREATE TABLE t3 LIKE t2;
ALTER TABLE t3 ENGINE=MyISAM;
EXECUTE IMMEDIATE
CONCAT('CREATE VIEW v3 AS SELECT id,',
IF(@target_type='geometry','AsText(target)','target'), ' AS target,',
IF(@source_type='geometry','AsText(source)','source'), ' AS source ',
' FROM t3');
INSERT IGNORE INTO t3 VALUES
(1,
(SELECT target FROM t2 ORDER BY id LIMIT 1),
(SELECT source FROM t2 ORDER BY id LIMIT 1)),
(2,
(SELECT source FROM t2 ORDER BY id LIMIT 1),
(SELECT source FROM t2 ORDER BY id LIMIT 1));
Warnings:
Warning	1292	Incorrect inet6 value: '0' for column `test`.`t3`.`target` at row 2
SELECT * FROM v3;
id	target	source
1	::	0
2	::	0
TRUNCATE TABLE t3;
SET sql_mode=STRICT_ALL_TABLES;
INSERT IGNORE INTO t3 VALUES
(1,
(SELECT target FROM t2 ORDER BY id LIMIT 1),
(SELECT source FROM t2 ORDER BY id LIMIT 1)),
(2,
(SELECT source FROM t2 ORDER BY id LIMIT 1),
(SELECT source FROM t2 ORDER BY id LIMIT 1));
Warnings:
Warning	1292	Incorrect inet6 value: '0' for column `test`.`t3`.`target` at row 2
SELECT * FROM v3;
id	target	source
1	::	0
2	::	0
TRUNCATE TABLE t3;
SET sql_mode=@sql_mode_save;
DROP TABLE t3;
DROP VIEW v3;
CREATE TABLE t3 LIKE t2;
INSERT IGNORE INTO t3 SELECT id,source,source FROM t2;
Warnings:
Warning	4078	Cannot cast 'double' as 'inet6' in assignment of `test`.`t3`.`target`
Warning	1292	Incorrect inet6 value: '0' for column `test`.`t3`.`target` at row 1
INSERT IGNORE INTO t3 (id,target,source) SELECT id,source,source FROM t2;
Warnings:
Warning	4078	Cannot cast 'double' as 'inet6' in assignment of `test`.`t3`.`target`
Warning	1292	Incorrect inet6 value: '0' for column `test`.`t3`.`target` at row 1
Warning	1062	Duplicate entry '1' for key 'PRIMARY'
INSERT IGNORE INTO t3 VALUES (1,DEFAULT,DEFAULT) ON DUPLICATE KEY UPDATE target=source;
Warnings:
Warning	4078	Cannot cast 'double' as 'inet6' in assignment of `test`.`t3`.`target`
Warning	1292	Incorrect inet6 value: '0' for column `test`.`t3`.`target` at row 1
INSERT IGNORE INTO t3 (id,target,source) VALUES (1,DEFAULT,DEFAULT) ON DUPLICATE KEY UPDATE target=source;
Warnings:
Warning	4078	Cannot cast 'double' as 'inet6' in assignment of `test`.`t3`.`target`
Warning	1292	Incorrect inet6 value: '0' for column `test`.`t3`.`target` at row 1
INSERT IGNORE INTO t3 SELECT 1,DEFAULT(t2.target),DEFAULT(t2.source) FROM t2 ON DUPLICATE KEY UPDATE t3.target=t2.source;
Warnings:
Warning	4078	Cannot cast 'double' as 'inet6' in assignment of `test`.`t3`.`target`
Warning	1292	Incorrect inet6 value: '0' for column `test`.`t3`.`target` at row 1
INSERT IGNORE INTO t3 (id,target,source) SELECT 1,DEFAULT(t2.target),DEFAULT(t2.source) FROM t2 ON DUPLICATE KEY UPDATE t3.target=t2.source;
Warnings:
Warning	4078	Cannot cast 'double' as 'inet6' in assignment of `test`.`t3`.`target`
Warning	1292	Incorrect inet6 value: '0' for column `test`.`t3`.`target` at row 1
UPDATE IGNORE t3 SET target=source;
Warnings:
Warning	4078	Cannot cast 'double' as 'inet6' in assignment of `test`.`t3`.`target`
Warning	1292	Incorrect inet6 value: '0' for column `test`.`t3`.`target` at row 1
UPDATE IGNORE t2, t3 SET t3.target=t2.source WHERE t2.id=t3.id;
Warnings:
Warning	4078	Cannot cast 'double' as 'inet6' in assignment of `test`.`t3`.`target`
Warning	1292	Incorrect inet6 value: '0' for column ``.`(temporary)`.`target` at row 1
SET @alter=CONCAT('ALTER', @ignore, ' TABLE t3 MODIFY target ', @source_type);
SELECT @alter;
@alter
ALTER IGNORE TABLE t3 MODIFY target double
EXECUTE IMMEDIATE @alter;
Warnings:
Warning	4078	Cannot cast 'inet6' as 'double' in assignment of `test`.`t3`.`target`
Warning	1366	Incorrect double value: '::' for column `test`.`t3`.`target` at row 1
DROP TABLE t3;
DROP TABLE t2;
CREATE PROCEDURE p1()
BEGIN
DECLARE src double DEFAULT NULL;
DECLARE dst inet6 DEFAULT NULL;
SET dst=src;
END;
$$
CALL p1;
ERROR HY000: Cannot cast 'double' as 'inet6' in assignment of `dst`
DROP PROCEDURE p1;
CREATE FUNCTION f1(a inet6) RETURNS INT RETURN NULL;;
SELECT f1((SELECT source FROM t1 ORDER BY source LIMIT 1));
ERROR HY000: Cannot cast 'double' as 'inet6' in assignment of `a`
DROP FUNCTION f1;
CREATE PROCEDURE p1(a inet6) BEGIN END;;
CALL p1((SELECT source FROM t1 ORDER BY source LIMIT 1));
ERROR HY000: Cannot cast 'double' as 'inet6' in assignment of `a`
DROP PROCEDURE p1;
CREATE PROCEDURE p1(OUT dst inet6)
BEGIN
DECLARE src double DEFAULT NULL;
SET dst=src;
END;
$$
CREATE PROCEDURE p2()
BEGIN
DECLARE dst inet6 DEFAULT NULL;
CALL p1(dst);
END;
$$
CALL p2();
ERROR HY000: Cannot cast 'double' as 'inet6' in assignment of `dst`
SHOW WARNINGS;
Level	Code	Message
Error	4078	Cannot cast 'double' as 'inet6' in assignment of `dst`
Note	4094	At line 4 in test.p1
Note	4094	At line 4 in test.p2
DROP PROCEDURE p2;
DROP PROCEDURE p1;
CREATE FUNCTION f1() RETURNS inet6
BEGIN
DECLARE rc double DEFAULT NULL;
RETURN rc;
END;
$$
SELECT f1();
ERROR HY000: Cannot cast 'double' as 'inet6' in assignment of `f1()`
DROP FUNCTION f1;
CREATE PROCEDURE p1()
BEGIN
DECLARE src double DEFAULT NULL;
DECLARE cur1 CURSOR(t inet6) FOR SELECT * FROM t1 WHERE target=t;
OPEN cur1(src);
CLOSE cur1;
END;
$$
CALL p1();
ERROR HY000: Cannot cast 'double' as 'inet6' in assignment of `t`
DROP PROCEDURE p1;
CREATE TABLE t2 LIKE t1;
INSERT INTO t2 VALUES ();
CREATE PROCEDURE p1()
BEGIN
DECLARE dst inet6 DEFAULT NULL;
DECLARE cur2 CURSOR FOR SELECT source FROM t2 ORDER BY source LIMIT 1;
OPEN cur2;
FETCH cur2 INTO dst;
CLOSE cur2;
END;
$$
CALL p1();
ERROR HY000: Cannot cast 'double' as 'inet6' in assignment of `dst`
DROP PROCEDURE p1;
DROP TABLE t2;
# End of type_store_assignment_incompatible.inc
DROP TABLE t1;
CREATE TABLE t1 (target DOUBLE DEFAULT 0, source INET6 DEFAULT '::0');
# Start of type_store_assignment_incompatible.inc
SET @sql_mode_save= @@sql_mode;
SET @source_type= (SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME='source'
                   AND TABLE_NAME='t1'
                   AND TABLE_SCHEMA='test');
SET @target_type= (SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME='target'
                   AND TABLE_NAME='t1'
                   AND TABLE_SCHEMA='test');
SET @ignore= CASE WHEN @ignore IS NULL OR @ignore = '' THEN ''
                  WHEN @ignore NOT LIKE ' %' THEN CONCAT(' ',@ignore)
ELSE @ignore
END;
CREATE TABLE t2 LIKE t1;
ALTER TABLE t2 ADD id INT NOT NULL PRIMARY KEY FIRST;
INSERT INTO t2 VALUES (1,DEFAULT,DEFAULT);
SHOW CREATE TABLE t2;
Table	Create Table
t2	CREATE TABLE `t2` (
  `id` int(11) NOT NULL,
  `target` double DEFAULT 0,
  `source` inet6 DEFAULT '::',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
CREATE TABLE t3 LIKE t2;
INSERT IGNORE INTO t3 VALUES
(1,
(SELECT source FROM t2 ORDER BY id LIMIT 1),
(SELECT source FROM t2 ORDER BY id LIMIT 1));
Warnings:
Warning	4078	Cannot cast 'inet6' as 'double' in assignment of `test`.`t3`.`target`
Warning	1366	Incorrect double value: '::' for column `test`.`t3`.`target` at row 1
DROP TABLE t3;
SET sql_mode='';
CREATE TABLE t3 LIKE t2;
ALTER TABLE t3 ENGINE=MyISAM;
EXECUTE IMMEDIATE
CONCAT('CREATE VIEW v3 AS SELECT id,',
IF(@target_type='geometry','AsText(target)','target'), ' AS target,',
IF(@source_type='geometry','AsText(source)','source'), ' AS source ',
' FROM t3');
INSERT IGNORE INTO t3 VALUES
(1,
(SELECT target FROM t2 ORDER BY id LIMIT 1),
(SELECT source FROM t2 ORDER BY id LIMIT 1)),
(2,
(SELECT source FROM t2 ORDER BY id LIMIT 1),
(SELECT source FROM t2 ORDER BY id LIMIT 1));
Warnings:
Warning	1366	Incorrect double value: '::' for column `test`.`t3`.`target` at row 2
SELECT * FROM v3;
id	target	source
1	0	::
2	0	::
TRUNCATE TABLE t3;
SET sql_mode=STRICT_ALL_TABLES;
INSERT IGNORE INTO t3 VALUES
(1,
(SELECT target FROM t2 ORDER BY id LIMIT 1),
(SELECT source FROM t2 ORDER BY id LIMIT 1)),
(2,
(SELECT source FROM t2 ORDER BY id LIMIT 1),
(SELECT source FROM t2 ORDER BY id LIMIT 1));
Warnings:
Warning	1366	Incorrect double value: '::' for column `test`.`t3`.`target` at row 2
SELECT * FROM v3;
id	target	source
1	0	::
2	0	::
TRUNCATE TABLE t3;
SET sql_mode=@sql_mode_save;
DROP TABLE t3;
DROP VIEW v3;
CREATE TABLE t3 LIKE t2;
INSERT IGNORE INTO t3 SELECT id,source,source FROM t2;
Warnings:
Warning	4078	Cannot cast 'inet6' as 'double' in assignment of `test`.`t3`.`target`
Warning	1366	Incorrect double value: '::' for column `test`.`t3`.`target` at row 1
INSERT IGNORE INTO t3 (id,target,source) SELECT id,source,source FROM t2;
Warnings:
Warning	4078	Cannot cast 'inet6' as 'double' in assignment of `test`.`t3`.`target`
Warning	1366	Incorrect double value: '::' for column `test`.`t3`.`target` at row 1
Warning	1062	Duplicate entry '1' for key 'PRIMARY'
INSERT IGNORE INTO t3 VALUES (1,DEFAULT,DEFAULT) ON DUPLICATE KEY UPDATE target=source;
Warnings:
Warning	4078	Cannot cast 'inet6' as 'double' in assignment of `test`.`t3`.`target`
Warning	1366	Incorrect double value: '::' for column `test`.`t3`.`target` at row 1
INSERT IGNORE INTO t3 (id,target,source) VALUES (1,DEFAULT,DEFAULT) ON DUPLICATE KEY UPDATE target=source;
Warnings:
Warning	4078	Cannot cast 'inet6' as 'double' in assignment of `test`.`t3`.`target`
Warning	1366	Incorrect double value: '::' for column `test`.`t3`.`target` at row 1
INSERT IGNORE INTO t3 SELECT 1,DEFAULT(t2.target),DEFAULT(t2.source) FROM t2 ON DUPLICATE KEY UPDATE t3.target=t2.source;
Warnings:
Warning	4078	Cannot cast 'inet6' as 'double' in assignment of `test`.`t3`.`target`
Warning	1366	Incorrect double value: '::' for column `test`.`t3`.`target` at row 1
INSERT IGNORE INTO t3 (id,target,source) SELECT 1,DEFAULT(t2.target),DEFAULT(t2.source) FROM t2 ON DUPLICATE KEY UPDATE t3.target=t2.source;
Warnings:
Warning	4078	Cannot cast 'inet6' as 'double' in assignment of `test`.`t3`.`target`
Warning	1366	Incorrect double value: '::' for column `test`.`t3`.`target` at row 1
UPDATE IGNORE t3 SET target=source;
Warnings:
Warning	4078	Cannot cast 'inet6' as 'double' in assignment of `test`.`t3`.`target`
Warning	1366	Incorrect double value: '::' for column `test`.`t3`.`target` at row 1
UPDATE IGNORE t2, t3 SET t3.target=t2.source WHERE t2.id=t3.id;
Warnings:
Warning	4078	Cannot cast 'inet6' as 'double' in assignment of `test`.`t3`.`target`
Warning	1366	Incorrect double value: '::' for column ``.`(temporary)`.`target` at row 1
SET @alter=CONCAT('ALTER', @ignore, ' TABLE t3 MODIFY target ', @source_type);
SELECT @alter;
@alter
ALTER IGNORE TABLE t3 MODIFY target inet6
EXECUTE IMMEDIATE @alter;
Warnings:
Warning	4078	Cannot cast 'double' as 'inet6' in assignment of `test`.`t3`.`target`
Warning	1292	Incorrect inet6 value: '0' for column `test`.`t3`.`target` at row 1
DROP TABLE t3;
DROP TABLE t2;
CREATE PROCEDURE p1()
BEGIN
DECLARE src inet6 DEFAULT NULL;
DECLARE dst double DEFAULT NULL;
SET dst=src;
END;
$$
CALL p1;
ERROR HY000: Cannot cast 'inet6' as 'double' in assignment of `dst`
DROP PROCEDURE p1;
CREATE FUNCTION f1(a double) RETURNS INT RETURN NULL;;
SELECT f1((SELECT source FROM t1 ORDER BY source LIMIT 1));
ERROR HY000: Cannot cast 'inet6' as 'double' in assignment of `a`
DROP FUNCTION f1;
CREATE PROCEDURE p1(a double) BEGIN END;;
CALL p1((SELECT source FROM t1 ORDER BY source LIMIT 1));
ERROR HY000: Cannot cast 'inet6' as 'double' in assignment of `a`
DROP PROCEDURE p1;
CREATE PROCEDURE p1(OUT dst double)
BEGIN
DECLARE src inet6 DEFAULT NULL;
SET dst=src;
END;
$$
CREATE PROCEDURE p2()
BEGIN
DECLARE dst double DEFAULT NULL;
CALL p1(dst);
END;
$$
CALL p2();
ERROR HY000: Cannot cast 'inet6' as 'double' in assignment of `dst`
SHOW WARNINGS;
Level	Code	Message
Error	4078	Cannot cast 'inet6' as 'double' in assignment of `dst`
Note	4094	At line 4 in test.p1
Note	4094	At line 4 in test.p2
DROP PROCEDURE p2;
DROP PROCEDURE p1;
CREATE FUNCTION f1() RETURNS double
BEGIN
DECLARE rc inet6 DEFAULT NULL;
RETURN rc;
END;
$$
SELECT f1();
ERROR HY000: Cannot cast 'inet6' as 'double' in assignment of `f1()`
DROP FUNCTION f1;
CREATE PROCEDURE p1()
BEGIN
DECLARE src inet6 DEFAULT NULL;
DECLARE cur1 CURSOR(t double) FOR SELECT * FROM t1 WHERE target=t;
OPEN cur1(src);
CLOSE cur1;
END;
$$
CALL p1();
ERROR HY000: Cannot cast 'inet6' as 'double' in assignment of `t`
DROP PROCEDURE p1;
CREATE TABLE t2 LIKE t1;
INSERT INTO t2 VALUES ();
CREATE PROCEDURE p1()
BEGIN
DECLARE dst double DEFAULT NULL;
DECLARE cur2 CURSOR FOR SELECT source FROM t2 ORDER BY source LIMIT 1;
OPEN cur2;
FETCH cur2 INTO dst;
CLOSE cur2;
END;
$$
CALL p1();
ERROR HY000: Cannot cast 'inet6' as 'double' in assignment of `dst`
DROP PROCEDURE p1;
DROP TABLE t2;
# End of type_store_assignment_incompatible.inc
DROP TABLE t1;
#
# End of 10.7 tests
#
