summaryrefslogtreecommitdiff
path: root/sql/field_conv.cc
diff options
context:
space:
mode:
authorKarthik Kamath <karthik.kamath@oracle.com>2018-07-23 10:16:58 +0530
committerKarthik Kamath <karthik.kamath@oracle.com>2018-07-23 10:16:58 +0530
commit15015579877476b38140e2828c23b3b716cac1e9 (patch)
tree1248aea43244f42af2f634306131ae3c508768b2 /sql/field_conv.cc
parent8a7db4c3208057f04d6af9f28c7b1e542e899343 (diff)
downloadmariadb-git-15015579877476b38140e2828c23b3b716cac1e9.tar.gz
BUG#27788685: NO WARNING WHEN TRUNCATING A STRING WITH DATA
LOSS ANALYSIS: ========= When converting from a BLOB/TEXT type to a smaller BLOB/TEXT type, no warning/error is reported to the user informing about the truncation/data loss. FIX: ==== We are now reporting a warning in non-strict mode and an appropriate error in strict mode.
Diffstat (limited to 'sql/field_conv.cc')
-rw-r--r--sql/field_conv.cc20
1 files changed, 17 insertions, 3 deletions
diff --git a/sql/field_conv.cc b/sql/field_conv.cc
index d98f19c3e01..d19eef8fdae 100644
--- a/sql/field_conv.cc
+++ b/sql/field_conv.cc
@@ -1,4 +1,4 @@
-/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -287,9 +287,23 @@ static void do_copy_next_number(Copy_field *copy)
static void do_copy_blob(Copy_field *copy)
{
- ulong length=((Field_blob*) copy->from_field)->get_length();
- ((Field_blob*) copy->to_field)->store_length(length);
+ ulong from_length=((Field_blob*) copy->from_field)->get_length();
+ ((Field_blob*) copy->to_field)->store_length(from_length);
memcpy(copy->to_ptr, copy->from_ptr, sizeof(char*));
+ ulong to_length=((Field_blob*) copy->to_field)->get_length();
+ if (to_length < from_length)
+ {
+ if (copy->to_field->table->in_use->abort_on_warning)
+ {
+ copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
+ ER_DATA_TOO_LONG, 1);
+ }
+ else
+ {
+ copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
+ WARN_DATA_TRUNCATED, 1);
+ }
+ }
}
static void do_conv_blob(Copy_field *copy)