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
character.

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


HTH,
Jörg

-- 
Joerg Bruehe,  MySQL Build Team,  [EMAIL PROTECTED]   (+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


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to