summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.org>2016-10-10 14:36:09 +0400
committerAlexander Barkov <bar@mariadb.org>2016-10-10 14:36:09 +0400
commit5058ced5df7a4ee3ff011577829fb2e4a6f47843 (patch)
tree8f90cd07e71cef5dc09adfd825712f812f978f57 /sql
parenta6f032af5778018051d41fc8ba7e9c983b4b7fbf (diff)
downloadmariadb-git-5058ced5df7a4ee3ff011577829fb2e4a6f47843.tar.gz
MDEV-7769 MY_CHARSET_INFO refactoring# On branch 10.2
Part 3 (final): removing MY_CHARSET_HANDLER::well_formed_len().
Diffstat (limited to 'sql')
-rw-r--r--sql/field.cc12
-rw-r--r--sql/field_conv.cc35
-rw-r--r--sql/item_sum.cc11
-rw-r--r--sql/item_timefunc.cc10
-rw-r--r--sql/sql_acl.cc11
-rw-r--r--sql/sql_parse.cc7
-rw-r--r--sql/sql_string.cc4
-rw-r--r--sql/sql_string.h47
-rw-r--r--sql/sql_yacc.yy5
9 files changed, 73 insertions, 69 deletions
diff --git a/sql/field.cc b/sql/field.cc
index ba0ebb253f4..e4ecb7422f2 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -7902,12 +7902,9 @@ int Field_blob::copy_value(Field_blob *from)
from->get_ptr(&data);
if (packlength < from->packlength)
{
- int well_formed_errors;
set_if_smaller(length, Field_blob::max_data_length());
- length= field_charset->cset->well_formed_len(field_charset,
- (const char *) data,
- (const char *) data + length,
- length, &well_formed_errors);
+ length= (uint32) Well_formed_prefix(field_charset,
+ (const char *) data, length).length();
rc= report_if_important_data((const char *) data + length,
(const char *) data + from->get_length(),
true);
@@ -7943,9 +7940,8 @@ int Field_blob::store(const char *from,uint length,CHARSET_INFO *cs)
copy_length= table->in_use->variables.group_concat_max_len;
if (new_length > copy_length)
{
- int well_formed_error;
- new_length= cs->cset->well_formed_len(cs, from, from + copy_length,
- new_length, &well_formed_error);
+ new_length= Well_formed_prefix(cs,
+ from, copy_length, new_length).length();
table->blob_storage->set_truncated_value(true);
}
if (!(tmp= table->blob_storage->store(from, new_length)))
diff --git a/sql/field_conv.cc b/sql/field_conv.cc
index 263c5bb5017..85101fd5f0a 100644
--- a/sql/field_conv.cc
+++ b/sql/field_conv.cc
@@ -467,20 +467,19 @@ static void do_cut_string(Copy_field *copy)
static void do_cut_string_complex(Copy_field *copy)
{ // Shorter string field
- int well_formed_error;
CHARSET_INFO *cs= copy->from_field->charset();
const uchar *from_end= copy->from_ptr + copy->from_length;
- uint copy_length= cs->cset->well_formed_len(cs,
- (char*) copy->from_ptr,
- (char*) from_end,
- copy->to_length / cs->mbmaxlen,
- &well_formed_error);
+ Well_formed_prefix prefix(cs,
+ (char*) copy->from_ptr,
+ (char*) from_end,
+ copy->to_length / cs->mbmaxlen);
+ uint copy_length= prefix.length();
if (copy->to_length < copy_length)
copy_length= copy->to_length;
memcpy(copy->to_ptr, copy->from_ptr, copy_length);
/* Check if we lost any important characters */
- if (well_formed_error ||
+ if (prefix.well_formed_error_pos() ||
cs->cset->scan(cs, (char*) copy->from_ptr + copy_length,
(char*) from_end,
MY_SEQ_SPACES) < (copy->from_length - copy_length))
@@ -534,22 +533,19 @@ static void do_varstring1(Copy_field *copy)
static void do_varstring1_mb(Copy_field *copy)
{
- int well_formed_error;
CHARSET_INFO *cs= copy->from_field->charset();
uint from_length= (uint) *(uchar*) copy->from_ptr;
const uchar *from_ptr= copy->from_ptr + 1;
uint to_char_length= (copy->to_length - 1) / cs->mbmaxlen;
- uint length= cs->cset->well_formed_len(cs, (char*) from_ptr,
- (char*) from_ptr + from_length,
- to_char_length, &well_formed_error);
- if (length < from_length)
+ Well_formed_prefix prefix(cs, (char*) from_ptr, from_length, to_char_length);
+ if (prefix.length() < from_length)
{
if (current_thd->count_cuted_fields)
copy->to_field->set_warning(Sql_condition::WARN_LEVEL_WARN,
WARN_DATA_TRUNCATED, 1);
}
- *copy->to_ptr= (uchar) length;
- memcpy(copy->to_ptr + 1, from_ptr, length);
+ *copy->to_ptr= (uchar) prefix.length();
+ memcpy(copy->to_ptr + 1, from_ptr, prefix.length());
}
@@ -572,22 +568,19 @@ static void do_varstring2(Copy_field *copy)
static void do_varstring2_mb(Copy_field *copy)
{
- int well_formed_error;
CHARSET_INFO *cs= copy->from_field->charset();
uint char_length= (copy->to_length - HA_KEY_BLOB_LENGTH) / cs->mbmaxlen;
uint from_length= uint2korr(copy->from_ptr);
const uchar *from_beg= copy->from_ptr + HA_KEY_BLOB_LENGTH;
- uint length= cs->cset->well_formed_len(cs, (char*) from_beg,
- (char*) from_beg + from_length,
- char_length, &well_formed_error);
- if (length < from_length)
+ Well_formed_prefix prefix(cs, (char*) from_beg, from_length, char_length);
+ if (prefix.length() < from_length)
{
if (current_thd->count_cuted_fields)
copy->to_field->set_warning(Sql_condition::WARN_LEVEL_WARN,
WARN_DATA_TRUNCATED, 1);
}
- int2store(copy->to_ptr, length);
- memcpy(copy->to_ptr+HA_KEY_BLOB_LENGTH, from_beg, length);
+ int2store(copy->to_ptr, prefix.length());
+ memcpy(copy->to_ptr+HA_KEY_BLOB_LENGTH, from_beg, prefix.length());
}
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index 83378c2e994..51a6c2bd3eb 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -3156,21 +3156,18 @@ int dump_leaf_key(void* key_arg, element_count count __attribute__((unused)),
/* stop if length of result more than max_length */
if (result->length() > max_length)
{
- int well_formed_error;
CHARSET_INFO *cs= item->collation.collation;
const char *ptr= result->ptr();
- uint add_length;
THD *thd= current_thd;
/*
It's ok to use item->result.length() as the fourth argument
as this is never used to limit the length of the data.
Cut is done with the third argument.
*/
- add_length= cs->cset->well_formed_len(cs,
- ptr + old_length,
- ptr + max_length,
- result->length(),
- &well_formed_error);
+ uint add_length= Well_formed_prefix(cs,
+ ptr + old_length,
+ ptr + max_length,
+ result->length()).length();
result->length(old_length + add_length);
item->warning_for_row= TRUE;
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc
index 41dc96717fe..5e0ae028d88 100644
--- a/sql/item_timefunc.cc
+++ b/sql/item_timefunc.cc
@@ -2468,13 +2468,9 @@ String *Item_char_typecast::val_str(String *str)
if (!charset_conversion)
{
// Try to reuse the original string (if well formed).
- MY_STRCOPY_STATUS status;
- cs->cset->well_formed_char_length(cs, res->ptr(), res->end(),
- cast_length, &status);
- if (!status.m_well_formed_error_pos)
- {
- res= reuse(res, status.m_source_end_pos - res->ptr());
- }
+ Well_formed_prefix prefix(cs, res->ptr(), res->end(), cast_length);
+ if (!prefix.well_formed_error_pos())
+ res= reuse(res, prefix.length());
goto end;
}
// Character set conversion, or bad bytes were found.
diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc
index ab6a8032348..2ae252c2232 100644
--- a/sql/sql_acl.cc
+++ b/sql/sql_acl.cc
@@ -12030,14 +12030,9 @@ static ulong parse_client_handshake_packet(MPVIO_EXT *mpvio,
mostly for backward compatibility (to truncate long usernames, as
old 5.1 did)
*/
- {
- CHARSET_INFO *cs= system_charset_info;
- int err;
-
- user_len= (uint) cs->cset->well_formed_len(cs, user, user + user_len,
- username_char_length, &err);
- user[user_len]= '\0';
- }
+ user_len= Well_formed_prefix(system_charset_info, user, user_len,
+ username_char_length).length();
+ user[user_len]= '\0';
Security_context *sctx= thd->security_ctx;
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index f4ac33d77fa..ddb5e2744cb 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -9614,11 +9614,8 @@ bool check_string_char_length(LEX_STRING *str, uint err_msg,
uint max_char_length, CHARSET_INFO *cs,
bool no_error)
{
- int well_formed_error;
- uint res= cs->cset->well_formed_len(cs, str->str, str->str + str->length,
- max_char_length, &well_formed_error);
-
- if (!well_formed_error && str->length == res)
+ Well_formed_prefix prefix(cs, str->str, str->length, max_char_length);
+ if (!prefix.well_formed_error_pos() && str->length == prefix.length())
return FALSE;
if (!no_error)
diff --git a/sql/sql_string.cc b/sql/sql_string.cc
index 4bb9f835211..49442260704 100644
--- a/sql/sql_string.cc
+++ b/sql/sql_string.cc
@@ -1018,10 +1018,10 @@ String_copier::well_formed_copy(CHARSET_INFO *to_cs,
{
m_cannot_convert_error_pos= NULL;
return to_cs->cset->copy_fix(to_cs, to, to_length, from, from_length,
- nchars, &m_native_copy_status);
+ nchars, this);
}
return my_convert_fix(to_cs, to, to_length, from_cs, from, from_length,
- nchars, this);
+ nchars, this, this);
}
diff --git a/sql/sql_string.h b/sql/sql_string.h
index cc7cff09d77..e51d089709e 100644
--- a/sql/sql_string.h
+++ b/sql/sql_string.h
@@ -44,13 +44,48 @@ inline uint32 copy_and_convert(char *to, uint32 to_length,
}
-class String_copier: private MY_STRCONV_STATUS
+class String_copy_status: protected MY_STRCOPY_STATUS
{
public:
const char *source_end_pos() const
- { return m_native_copy_status.m_source_end_pos; }
+ { return m_source_end_pos; }
const char *well_formed_error_pos() const
- { return m_native_copy_status.m_well_formed_error_pos; }
+ { return m_well_formed_error_pos; }
+};
+
+
+class Well_formed_prefix_status: public String_copy_status
+{
+public:
+ Well_formed_prefix_status(CHARSET_INFO *cs,
+ const char *str, const char *end, size_t nchars)
+ { cs->cset->well_formed_char_length(cs, str, end, nchars, this); }
+};
+
+
+class Well_formed_prefix: public Well_formed_prefix_status
+{
+ const char *m_str; // The beginning of the string
+public:
+ Well_formed_prefix(CHARSET_INFO *cs, const char *str, const char *end,
+ size_t nchars)
+ :Well_formed_prefix_status(cs, str, end, nchars), m_str(str)
+ { }
+ Well_formed_prefix(CHARSET_INFO *cs, const char *str, size_t length,
+ size_t nchars)
+ :Well_formed_prefix_status(cs, str, str + length, nchars), m_str(str)
+ { }
+ Well_formed_prefix(CHARSET_INFO *cs, const char *str, size_t length)
+ :Well_formed_prefix_status(cs, str, str + length, length), m_str(str)
+ { }
+ size_t length() const { return m_source_end_pos - m_str; }
+};
+
+
+class String_copier: public String_copy_status,
+ protected MY_STRCONV_STATUS
+{
+public:
const char *cannot_convert_error_pos() const
{ return m_cannot_convert_error_pos; }
const char *most_important_error_pos() const
@@ -67,7 +102,7 @@ public:
uint nchars)
{
return my_convert_fix(dstcs, dst, dst_length,
- srccs, src, src_length, nchars, this);
+ srccs, src, src_length, nchars, this, this);
}
/*
Copy a string. Fix bad bytes/characters to '?'.
@@ -606,9 +641,7 @@ public:
}
uint well_formed_length() const
{
- int dummy_error;
- return charset()->cset->well_formed_len(charset(), ptr(), ptr() + length(),
- length(), &dummy_error);
+ return (uint) Well_formed_prefix(charset(), ptr(), length()).length();
}
bool is_ascii() const
{
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 6b2dbca75a9..b8810311b51 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -14371,10 +14371,7 @@ IDENT_sys:
if (thd->charset_is_system_charset)
{
CHARSET_INFO *cs= system_charset_info;
- int dummy_error;
- uint wlen= cs->cset->well_formed_len(cs, $1.str,
- $1.str+$1.length,
- $1.length, &dummy_error);
+ uint wlen= Well_formed_prefix(cs, $1.str, $1.length).length();
if (wlen < $1.length)
{
ErrConvString err($1.str, $1.length, &my_charset_bin);