summaryrefslogtreecommitdiff
path: root/sql/field.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/field.cc')
-rw-r--r--sql/field.cc60
1 files changed, 52 insertions, 8 deletions
diff --git a/sql/field.cc b/sql/field.cc
index 1cfd0843179..e9c4435b9e1 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -47,6 +47,8 @@ uchar Field_null::null[1]={1};
const char field_separator=',';
#define DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE 320
+#define LONGLONG_TO_STRING_CONVERSION_BUFFER_SIZE 128
+#define DECIMAL_TO_STRING_CONVERSION_BUFFER_SIZE 128
#define BLOB_PACK_LENGTH_TO_MAX_LENGH(arg) \
((ulong) ((LL(1) << min(arg, 4) * 8) - LL(1)))
@@ -6056,19 +6058,49 @@ int Field_longstr::store_decimal(const my_decimal *d)
double Field_string::val_real(void)
{
- int not_used;
- char *end_not_used;
+ int error;
+ char *end;
CHARSET_INFO *cs= charset();
- return my_strntod(cs,ptr,field_length,&end_not_used,&not_used);
+ double result;
+
+ result= my_strntod(cs,ptr,field_length,&end,&error);
+ if (!table->in_use->no_errors &&
+ (error || (field_length != (uint32)(end - ptr) &&
+ !check_if_only_end_space(cs, end, ptr + field_length))))
+ {
+ char buf[DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE];
+ String tmp(buf, sizeof(buf), cs);
+ tmp.copy(ptr, field_length, cs);
+ push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+ ER_TRUNCATED_WRONG_VALUE,
+ ER(ER_TRUNCATED_WRONG_VALUE),
+ "DOUBLE", tmp.c_ptr());
+ }
+ return result;
}
longlong Field_string::val_int(void)
{
- int not_used;
- char *end_not_used;
- CHARSET_INFO *cs=charset();
- return my_strntoll(cs,ptr,field_length,10,&end_not_used,&not_used);
+ int error;
+ char *end;
+ CHARSET_INFO *cs= charset();
+ longlong result;
+
+ result= my_strntoll(cs,ptr,field_length,10,&end,&error);
+ if (!table->in_use->no_errors &&
+ (error || (field_length != (uint32)(end - ptr) &&
+ !check_if_only_end_space(cs, end, ptr + field_length))))
+ {
+ char buf[LONGLONG_TO_STRING_CONVERSION_BUFFER_SIZE];
+ String tmp(buf, sizeof(buf), cs);
+ tmp.copy(ptr, field_length, cs);
+ push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+ ER_TRUNCATED_WRONG_VALUE,
+ ER(ER_TRUNCATED_WRONG_VALUE),
+ "INTEGER", tmp.c_ptr());
+ }
+ return result;
}
@@ -6085,8 +6117,20 @@ String *Field_string::val_str(String *val_buffer __attribute__((unused)),
my_decimal *Field_string::val_decimal(my_decimal *decimal_value)
{
- str2my_decimal(E_DEC_FATAL_ERROR, ptr, field_length, charset(),
+ int err= str2my_decimal(E_DEC_FATAL_ERROR, ptr, field_length, charset(),
decimal_value);
+ if (!table->in_use->no_errors && err)
+ {
+ char buf[DECIMAL_TO_STRING_CONVERSION_BUFFER_SIZE];
+ CHARSET_INFO *cs= charset();
+ String tmp(buf, sizeof(buf), cs);
+ tmp.copy(ptr, field_length, cs);
+ push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+ ER_TRUNCATED_WRONG_VALUE,
+ ER(ER_TRUNCATED_WRONG_VALUE),
+ "DECIMAL", tmp.c_ptr());
+ }
+
return decimal_value;
}