Bug #8548 Request for a means to get the length of a field in chars instead of bytes
Submitted: 16 Feb 2005 15:39 Modified: 11 Apr 2018 10:53
Reporter: Matthew Lord Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Charsets Severity:S4 (Feature request)
Version:all OS:Any (all)
Assigned to: Geir Høydalsvik CPU Architecture:Any

[16 Feb 2005 15:39] Matthew Lord
Description:
I understand that the length field in the MYSQL_FIELD structure will probably not be changed as it has been in bytes for so long but there should be some means to get the length in characters for 
multi-byte columns.

How to repeat:
Create a UTF8 table, populate it with a few rows and check the lengths.

I know this is a poor example of how to repeat the problem but this is a known
and documented problem.

Suggested fix:
It could be another variable in the MYSQL_FIELD struct or another set of functions altogether so long as this functionality is available.
[29 Mar 2011 8:42] Alexander Barkov
I don't think we really need a separate new field in the MYSQL_FIELD structure.
This simple function returns length of MYSQL_FIELD in characters:

/*
  Convert byte length to character length
*/
unsigned long
mysql_field_character_length(MYSQL_FIELD *field)
{
  CHARSET_INFO *cs;
  return  (cs= get_charset(fied->charsetnr)) ? field->length / cs->mbmaxlen : field->length;
}

Perhaps, instead of a new field in MYSQL_FIELD,
we should add this function into MySQL client library.
[11 Apr 2018 10:53] Erlend Dahl
Fixed in 5.5+