summaryrefslogtreecommitdiff
path: root/sql/item.cc
diff options
context:
space:
mode:
authorSreeharsha Ramanavarapu <sreeharsha.ramanavarapu@oracle.com>2015-07-10 07:54:55 +0530
committerSreeharsha Ramanavarapu <sreeharsha.ramanavarapu@oracle.com>2015-07-10 07:54:55 +0530
commitc773b320ffce5fa51782b26c979bda23dd8dbc03 (patch)
tree43664139b8bc731b83082285ee1d5738dbf38a8e /sql/item.cc
parent7255ae6ceb20c67d09fd153558d9a14372142f8b (diff)
parent33a2e5abd86727155b629246445d508bb2cd02c0 (diff)
downloadmariadb-git-c773b320ffce5fa51782b26c979bda23dd8dbc03.tar.gz
Merge branch 'mysql-5.1' into mysql-5.5
Diffstat (limited to 'sql/item.cc')
-rw-r--r--sql/item.cc54
1 files changed, 32 insertions, 22 deletions
diff --git a/sql/item.cc b/sql/item.cc
index 96f15b92a54..fd590574e56 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -1,5 +1,5 @@
/*
- Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
+ Copyright (c) 2000, 2015, 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
@@ -5146,45 +5146,55 @@ enum_field_types Item::field_type() const
/**
Verifies that the input string is well-formed according to its character set.
@param send_error If true, call my_error if string is not well-formed.
-
- Will truncate input string if it is not well-formed.
+ @param truncate If true, set to null/truncate if not well-formed.
@return
If well-formed: input string.
If not well-formed:
- if strict mode: NULL pointer and we set this Item's value to NULL
- if not strict mode: input string truncated up to last good character
+ if truncate is true and strict mode: NULL pointer and we set this
+ Item's value to NULL.
+ if truncate is true and not strict mode: input string truncated up to
+ last good character.
+ if truncate is false: input string is returned.
*/
-String *Item::check_well_formed_result(String *str, bool send_error)
+String *Item::check_well_formed_result(String *str,
+ bool send_error,
+ bool truncate)
{
/* Check whether we got a well-formed string */
CHARSET_INFO *cs= str->charset();
- int well_formed_error;
- uint wlen= cs->cset->well_formed_len(cs,
- str->ptr(), str->ptr() + str->length(),
- str->length(), &well_formed_error);
- if (wlen < str->length())
+
+ size_t valid_length;
+ bool length_error;
+
+ if (validate_string(cs, str->ptr(), str->length(),
+ &valid_length, &length_error))
{
+ const char *str_end= str->ptr() + str->length();
+ const char *print_byte= str->ptr() + valid_length;
THD *thd= current_thd;
char hexbuf[7];
- uint diff= str->length() - wlen;
+ uint diff= str_end - print_byte;
set_if_smaller(diff, 3);
- octet2hex(hexbuf, str->ptr() + wlen, diff);
- if (send_error)
+ octet2hex(hexbuf, print_byte, diff);
+ if (send_error && length_error)
{
my_error(ER_INVALID_CHARACTER_STRING, MYF(0),
cs->csname, hexbuf);
return 0;
}
- if ((thd->variables.sql_mode &
- (MODE_STRICT_TRANS_TABLES | MODE_STRICT_ALL_TABLES)))
- {
- null_value= 1;
- str= 0;
- }
- else
+ if (truncate && length_error)
{
- str->length(wlen);
+ if ((thd->variables.sql_mode &
+ (MODE_STRICT_TRANS_TABLES | MODE_STRICT_ALL_TABLES)))
+ {
+ null_value= 1;
+ str= 0;
+ }
+ else
+ {
+ str->length(valid_length);
+ }
}
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_INVALID_CHARACTER_STRING,
ER(ER_INVALID_CHARACTER_STRING), cs->csname, hexbuf);