Commit 35cbbd4d authored by Alexander Barkov's avatar Alexander Barkov

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().
parent f67522ed
...@@ -5308,5 +5308,12 @@ def COALESCE(gc,gc) 255 (type=geometrycollection) 4294967295 0 Y 128 0 63 ...@@ -5308,5 +5308,12 @@ def COALESCE(gc,gc) 255 (type=geometrycollection) 4294967295 0 Y 128 0 63
COALESCE(gc,p) COALESCE(gc,ls) COALESCE(gc,pl) COALESCE(gc,mp) COALESCE(gc,mls) COALESCE(gc,mpl) COALESCE(gc,g) COALESCE(gc,gc) COALESCE(gc,p) COALESCE(gc,ls) COALESCE(gc,pl) COALESCE(gc,mp) COALESCE(gc,mls) COALESCE(gc,mpl) COALESCE(gc,g) COALESCE(gc,gc)
DROP TABLE t1; DROP TABLE t1;
# #
# MDEV-20809 EXTRACT from INET6 value does not produce any warnings
#
CREATE TABLE t1 (a GEOMETRY);
SELECT EXTRACT(DAY FROM a) FROM t1;
ERROR HY000: Illegal parameter data type geometry for operation 'extract(day)'
DROP TABLE t1;
#
# End of 10.5 tests # End of 10.5 tests
# #
...@@ -3309,6 +3309,15 @@ FROM t1; ...@@ -3309,6 +3309,15 @@ FROM t1;
--disable_metadata --disable_metadata
DROP TABLE t1; DROP TABLE t1;
--echo #
--echo # MDEV-20809 EXTRACT from INET6 value does not produce any warnings
--echo #
CREATE TABLE t1 (a GEOMETRY);
--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION
SELECT EXTRACT(DAY FROM a) FROM t1;
DROP TABLE t1;
--echo # --echo #
--echo # End of 10.5 tests --echo # End of 10.5 tests
--echo # --echo #
...@@ -545,3 +545,16 @@ SELECT (1,null) NOT IN ((2,2),(3,3)), (1,null) NOT IN ((2,2)), (1,null) NOT IN ( ...@@ -545,3 +545,16 @@ SELECT (1,null) NOT IN ((2,2),(3,3)), (1,null) NOT IN ((2,2)), (1,null) NOT IN (
# #
# End of 10.1 tests # End of 10.1 tests
# #
#
# Start of 10.5 tests
#
#
# MDEV-20809 EXTRACT from INET6 value does not produce any warnings
#
CREATE TABLE t1 (a GEOMETRY);
SELECT EXTRACT(DAY FROM a) FROM t1;
ERROR HY000: Illegal parameter data type geometry for operation 'extract(day)'
DROP TABLE t1;
#
# End of 10.5 tests
#
...@@ -314,3 +314,21 @@ SELECT (1,null) NOT IN ((2,2),(3,3)), (1,null) NOT IN ((2,2)), (1,null) NOT IN ( ...@@ -314,3 +314,21 @@ SELECT (1,null) NOT IN ((2,2),(3,3)), (1,null) NOT IN ((2,2)), (1,null) NOT IN (
--echo # --echo #
--echo # End of 10.1 tests --echo # End of 10.1 tests
--echo # --echo #
--echo #
--echo # Start of 10.5 tests
--echo #
--echo #
--echo # MDEV-20809 EXTRACT from INET6 value does not produce any warnings
--echo #
CREATE TABLE t1 (a GEOMETRY);
--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION
SELECT EXTRACT(DAY FROM a) FROM t1;
DROP TABLE t1;
--echo #
--echo # End of 10.5 tests
--echo #
...@@ -1977,3 +1977,12 @@ SELECT MIN(a), MAX(a) FROM t1 GROUP BY id; ...@@ -1977,3 +1977,12 @@ SELECT MIN(a), MAX(a) FROM t1 GROUP BY id;
MIN(a) MAX(a) MIN(a) MAX(a)
fff:: 8888:: fff:: 8888::
DROP TABLE t1; DROP TABLE t1;
#
# MDEV-20809 EXTRACT from INET6 value does not produce any warnings
#
CREATE TABLE t1 (a INET6);
SELECT EXTRACT(DAY FROM a) FROM t1;
ERROR HY000: Illegal parameter data type inet6 for operation 'extract(day)'
DROP TABLE t1;
SELECT EXTRACT(DAY FROM CAST('::' AS INET6));
ERROR HY000: Illegal parameter data type inet6 for operation 'extract(day)'
...@@ -1445,3 +1445,15 @@ CREATE TABLE t1 (id INT, a INET6) ENGINE=MyISAM; ...@@ -1445,3 +1445,15 @@ CREATE TABLE t1 (id INT, a INET6) ENGINE=MyISAM;
INSERT INTO t1 VALUES (1, 'fff::'),(1, '8888::'); INSERT INTO t1 VALUES (1, 'fff::'),(1, '8888::');
SELECT MIN(a), MAX(a) FROM t1 GROUP BY id; SELECT MIN(a), MAX(a) FROM t1 GROUP BY id;
DROP TABLE t1; DROP TABLE t1;
--echo #
--echo # MDEV-20809 EXTRACT from INET6 value does not produce any warnings
--echo #
CREATE TABLE t1 (a INET6);
--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION
SELECT EXTRACT(DAY FROM a) FROM t1;
DROP TABLE t1;
--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION
SELECT EXTRACT(DAY FROM CAST('::' AS INET6));
...@@ -2109,6 +2109,21 @@ void Item_extract::print(String *str, enum_query_type query_type) ...@@ -2109,6 +2109,21 @@ void Item_extract::print(String *str, enum_query_type query_type)
str->append(')'); str->append(')');
} }
bool Item_extract::check_arguments() const
{
if (!args[0]->type_handler()->can_return_extract_source(int_type))
{
char tmp[64];
my_snprintf(tmp, sizeof(tmp), "extract(%s)", interval_names[int_type]);
my_error(ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION, MYF(0),
args[0]->type_handler()->name().ptr(), tmp);
return true;
}
return false;
}
bool Item_extract::fix_length_and_dec() bool Item_extract::fix_length_and_dec()
{ {
maybe_null=1; // If wrong date maybe_null=1; // If wrong date
......
...@@ -1002,6 +1002,7 @@ class Item_extract :public Item_int_func, ...@@ -1002,6 +1002,7 @@ class Item_extract :public Item_int_func,
longlong val_int(); longlong val_int();
enum Functype functype() const { return EXTRACT_FUNC; } enum Functype functype() const { return EXTRACT_FUNC; }
const char *func_name() const { return "extract"; } const char *func_name() const { return "extract"; }
bool check_arguments() const;
bool fix_length_and_dec(); bool fix_length_and_dec();
bool eq(const Item *item, bool binary_cmp) const; bool eq(const Item *item, bool binary_cmp) const;
void print(String *str, enum_query_type query_type); void print(String *str, enum_query_type query_type);
......
...@@ -8994,6 +8994,11 @@ bool Type_handler::partition_field_append_value( ...@@ -8994,6 +8994,11 @@ bool Type_handler::partition_field_append_value(
} }
bool Type_handler::can_return_extract_source(interval_type int_type) const
{
return type_collection() == &type_collection_std;
}
/***************************************************************************/ /***************************************************************************/
LEX_CSTRING Charset::collation_specific_name() const LEX_CSTRING Charset::collation_specific_name() const
......
...@@ -3616,6 +3616,7 @@ class Type_handler ...@@ -3616,6 +3616,7 @@ class Type_handler
virtual bool can_return_text() const { return true; } virtual bool can_return_text() const { return true; }
virtual bool can_return_date() const { return true; } virtual bool can_return_date() const { return true; }
virtual bool can_return_time() const { return true; } virtual bool can_return_time() const { return true; }
virtual bool can_return_extract_source(interval_type type) const;
virtual bool is_bool_type() const { return false; } virtual bool is_bool_type() const { return false; }
virtual bool is_general_purpose_string_type() const { return false; } virtual bool is_general_purpose_string_type() const { return false; }
virtual uint Item_time_precision(THD *thd, Item *item) const; virtual uint Item_time_precision(THD *thd, Item *item) const;
......
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