List:General Discussion« Previous MessageNext Message »
From:Joerg Bruehe Date:October 7 2008 11:07am
Subject:Re: C api - mysql_list_fields
View as plain text  
Hi Mike, all,

Mike Aubury wrote:
> I'm probably being a bit stupid - but I'm trying to determine (in code) the 
> length of the string in the schema for a given table.
> So - for example : 
> 	create table a (
> 		blah char(20)
> 	)
> I want to return '20', but I'm getting '60' when I use mysql_list_fields..
> (Always seems to be 3x longer that I'm expecting)...
> Am I missing something ? (or should I just divide by 3!!)

You are missing the distinction between "character" and byte, which is
brought to you by the ISO character sets which go far beyond ASCII.

The moment you allow international characters (US-ASCII + German Umlauts
+ French accented vowels + Spanish cedilla + ... + Chinese + Korean +
...) in your data, storing one character may need more than one byte.

The current encoding (versions 5.0 and 5.1) uses up to 3 bytes per
character, that is the factor 3 you notice.
With 6.0, a different encoding may be used, which uses up to 4 bytes per

If you know you won't need arbitrary characters, you can use the
"charset" (or "character set") option in your "create" statements.


Joerg Bruehe,  MySQL Build Team,  joerg@stripped   (+49 30) 417 01 487
Sun Microsystems GmbH,   Sonnenallee 1,   D-85551 Kirchheim-Heimstetten
Geschaeftsfuehrer: Thomas Schroeder, Wolfgang Engels, Dr. Roland Boemer
Vorsitzender des Aufsichtsrates: Martin Haering     Muenchen: HRB161028

C api - mysql_list_fieldsMike Aubury6 Oct
  • Re: C api - mysql_list_fieldsDoug Bridgens7 Oct
  • Re: C api - mysql_list_fieldsSimon J Mudd7 Oct
  • Re: C api - mysql_list_fieldsJoerg Bruehe7 Oct
    • Re: C api - mysql_list_fieldsMike Aubury7 Oct
      • Re: C api - mysql_list_fieldswalter harms7 Oct
        • Re: C api - mysql_list_fieldsMike Aubury7 Oct
      • Re: C api - mysql_list_fieldsJoerg Bruehe7 Oct