summaryrefslogtreecommitdiff
path: root/plugin/type_inet/sql_type_inet.cc
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.com>2019-10-10 08:12:14 +0400
committerAlexander Barkov <bar@mariadb.com>2019-10-10 08:12:14 +0400
commit312ba3cc3dd13fe3da1aeac8a32887be98c8a7ae (patch)
tree608d138c261c1b20fea2daaa0a88b53139b3643f /plugin/type_inet/sql_type_inet.cc
parentb37386d854b37743a7b4ae578312dd27bec055ce (diff)
downloadmariadb-git-312ba3cc3dd13fe3da1aeac8a32887be98c8a7ae.tar.gz
MDEV-20783 INET6 cannot be converted to BINARY(16)
Diffstat (limited to 'plugin/type_inet/sql_type_inet.cc')
-rw-r--r--plugin/type_inet/sql_type_inet.cc50
1 files changed, 31 insertions, 19 deletions
diff --git a/plugin/type_inet/sql_type_inet.cc b/plugin/type_inet/sql_type_inet.cc
index 4cd104af206..0c50cfe034c 100644
--- a/plugin/type_inet/sql_type_inet.cc
+++ b/plugin/type_inet/sql_type_inet.cc
@@ -823,26 +823,38 @@ public:
Copy_func *get_copy_func(const Field *from) const override
{
// ALTER to INET6 from another field
- /*
- if (eq_def(from))
- return get_identical_copy_func();
- switch (from->cmp_type()) {
- case STRING_RESULT:
- return do_field_string;
- case TIME_RESULT:
- return do_field_temporal;
- case DECIMAL_RESULT:
- return do_field_decimal;
- case REAL_RESULT:
- return do_field_real;
- case INT_RESULT:
- return do_field_int;
- case ROW_RESULT:
- DBUG_ASSERT(0);
- break;
+ return do_field_string;
+ }
+
+ Copy_func *get_copy_func_to(const Field *to) const override
+ {
+ if (type_handler() == to->type_handler())
+ {
+ // ALTER from INET6 to INET6
+ DBUG_ASSERT(pack_length() == to->pack_length());
+ DBUG_ASSERT(charset() == to->charset());
+ DBUG_ASSERT(sort_charset() == to->sort_charset());
+ return Field::do_field_eq;
}
- */
- return do_field_string;//QQ
+ // ALTER from INET6 to another data type
+ if (to->charset() == &my_charset_bin &&
+ dynamic_cast<const Type_handler_general_purpose_string*>
+ (to->type_handler()))
+ {
+ /*
+ ALTER from INET6 to a binary string type, e.g.:
+ BINARY, TINYBLOB, BLOB, MEDIUMBLOB, LONGBLOB
+ */
+ return do_field_inet6_native_to_binary;
+ }
+ return do_field_string;
+ }
+
+ static void do_field_inet6_native_to_binary(Copy_field *copy)
+ {
+ NativeBufferInet6 res;
+ copy->from_field->val_native(&res);
+ copy->to_field->store(res.ptr(), res.length(), &my_charset_bin);
}
bool memcpy_field_possible(const Field *from) const override