Skip to content

Commit 35cbbd4

Browse files
committed
MDEV-20809 EXTRACT from INET6 value does not produce any warnings
Disallowing EXTRACT(xxx FROM inet6arg) as fix time. Adding a new method Type_handler::can_return_extract_source().
1 parent f67522e commit 35cbbd4

File tree

10 files changed

+90
-0
lines changed

10 files changed

+90
-0
lines changed

mysql-test/main/gis.result

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5308,5 +5308,12 @@ def COALESCE(gc,gc) 255 (type=geometrycollection) 4294967295 0 Y 128 0 63
53085308
COALESCE(gc,p) COALESCE(gc,ls) COALESCE(gc,pl) COALESCE(gc,mp) COALESCE(gc,mls) COALESCE(gc,mpl) COALESCE(gc,g) COALESCE(gc,gc)
53095309
DROP TABLE t1;
53105310
#
5311+
# MDEV-20809 EXTRACT from INET6 value does not produce any warnings
5312+
#
5313+
CREATE TABLE t1 (a GEOMETRY);
5314+
SELECT EXTRACT(DAY FROM a) FROM t1;
5315+
ERROR HY000: Illegal parameter data type geometry for operation 'extract(day)'
5316+
DROP TABLE t1;
5317+
#
53115318
# End of 10.5 tests
53125319
#

mysql-test/main/gis.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3309,6 +3309,15 @@ FROM t1;
33093309
--disable_metadata
33103310
DROP TABLE t1;
33113311

3312+
--echo #
3313+
--echo # MDEV-20809 EXTRACT from INET6 value does not produce any warnings
3314+
--echo #
3315+
3316+
CREATE TABLE t1 (a GEOMETRY);
3317+
--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION
3318+
SELECT EXTRACT(DAY FROM a) FROM t1;
3319+
DROP TABLE t1;
3320+
33123321
--echo #
33133322
--echo # End of 10.5 tests
33143323
--echo #

mysql-test/main/row.result

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,3 +545,16 @@ SELECT (1,null) NOT IN ((2,2),(3,3)), (1,null) NOT IN ((2,2)), (1,null) NOT IN (
545545
#
546546
# End of 10.1 tests
547547
#
548+
#
549+
# Start of 10.5 tests
550+
#
551+
#
552+
# MDEV-20809 EXTRACT from INET6 value does not produce any warnings
553+
#
554+
CREATE TABLE t1 (a GEOMETRY);
555+
SELECT EXTRACT(DAY FROM a) FROM t1;
556+
ERROR HY000: Illegal parameter data type geometry for operation 'extract(day)'
557+
DROP TABLE t1;
558+
#
559+
# End of 10.5 tests
560+
#

mysql-test/main/row.test

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,3 +314,21 @@ SELECT (1,null) NOT IN ((2,2),(3,3)), (1,null) NOT IN ((2,2)), (1,null) NOT IN (
314314
--echo #
315315
--echo # End of 10.1 tests
316316
--echo #
317+
318+
319+
--echo #
320+
--echo # Start of 10.5 tests
321+
--echo #
322+
323+
--echo #
324+
--echo # MDEV-20809 EXTRACT from INET6 value does not produce any warnings
325+
--echo #
326+
327+
CREATE TABLE t1 (a GEOMETRY);
328+
--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION
329+
SELECT EXTRACT(DAY FROM a) FROM t1;
330+
DROP TABLE t1;
331+
332+
--echo #
333+
--echo # End of 10.5 tests
334+
--echo #

plugin/type_inet/mysql-test/type_inet/type_inet6.result

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,3 +1977,12 @@ SELECT MIN(a), MAX(a) FROM t1 GROUP BY id;
19771977
MIN(a) MAX(a)
19781978
fff:: 8888::
19791979
DROP TABLE t1;
1980+
#
1981+
# MDEV-20809 EXTRACT from INET6 value does not produce any warnings
1982+
#
1983+
CREATE TABLE t1 (a INET6);
1984+
SELECT EXTRACT(DAY FROM a) FROM t1;
1985+
ERROR HY000: Illegal parameter data type inet6 for operation 'extract(day)'
1986+
DROP TABLE t1;
1987+
SELECT EXTRACT(DAY FROM CAST('::' AS INET6));
1988+
ERROR HY000: Illegal parameter data type inet6 for operation 'extract(day)'

plugin/type_inet/mysql-test/type_inet/type_inet6.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,3 +1445,15 @@ CREATE TABLE t1 (id INT, a INET6) ENGINE=MyISAM;
14451445
INSERT INTO t1 VALUES (1, 'fff::'),(1, '8888::');
14461446
SELECT MIN(a), MAX(a) FROM t1 GROUP BY id;
14471447
DROP TABLE t1;
1448+
1449+
1450+
--echo #
1451+
--echo # MDEV-20809 EXTRACT from INET6 value does not produce any warnings
1452+
--echo #
1453+
1454+
CREATE TABLE t1 (a INET6);
1455+
--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION
1456+
SELECT EXTRACT(DAY FROM a) FROM t1;
1457+
DROP TABLE t1;
1458+
--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION
1459+
SELECT EXTRACT(DAY FROM CAST('::' AS INET6));

sql/item_timefunc.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2109,6 +2109,21 @@ void Item_extract::print(String *str, enum_query_type query_type)
21092109
str->append(')');
21102110
}
21112111

2112+
2113+
bool Item_extract::check_arguments() const
2114+
{
2115+
if (!args[0]->type_handler()->can_return_extract_source(int_type))
2116+
{
2117+
char tmp[64];
2118+
my_snprintf(tmp, sizeof(tmp), "extract(%s)", interval_names[int_type]);
2119+
my_error(ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION, MYF(0),
2120+
args[0]->type_handler()->name().ptr(), tmp);
2121+
return true;
2122+
}
2123+
return false;
2124+
}
2125+
2126+
21122127
bool Item_extract::fix_length_and_dec()
21132128
{
21142129
maybe_null=1; // If wrong date

sql/item_timefunc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,7 @@ class Item_extract :public Item_int_func,
10021002
longlong val_int();
10031003
enum Functype functype() const { return EXTRACT_FUNC; }
10041004
const char *func_name() const { return "extract"; }
1005+
bool check_arguments() const;
10051006
bool fix_length_and_dec();
10061007
bool eq(const Item *item, bool binary_cmp) const;
10071008
void print(String *str, enum_query_type query_type);

sql/sql_type.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8994,6 +8994,11 @@ bool Type_handler::partition_field_append_value(
89948994
}
89958995

89968996

8997+
bool Type_handler::can_return_extract_source(interval_type int_type) const
8998+
{
8999+
return type_collection() == &type_collection_std;
9000+
}
9001+
89979002
/***************************************************************************/
89989003

89999004
LEX_CSTRING Charset::collation_specific_name() const

sql/sql_type.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3616,6 +3616,7 @@ class Type_handler
36163616
virtual bool can_return_text() const { return true; }
36173617
virtual bool can_return_date() const { return true; }
36183618
virtual bool can_return_time() const { return true; }
3619+
virtual bool can_return_extract_source(interval_type type) const;
36193620
virtual bool is_bool_type() const { return false; }
36203621
virtual bool is_general_purpose_string_type() const { return false; }
36213622
virtual uint Item_time_precision(THD *thd, Item *item) const;

0 commit comments

Comments
 (0)