List:General Discussion« Previous MessageNext Message »
From:Mike Aubury Date:October 7 2008 11:56am
Subject:Re: C api - mysql_list_fields
View as plain text  
Excellent - this seems to be the issue - the show create table shows : 

 mysql> show create table a\g
+-------+----------------------------------------------------------------------------------------+
| Table | Create 
Table                                                                           |
+-------+----------------------------------------------------------------------------------------+
| a     | CREATE TABLE `a` (
  `blah` char(20) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
+-------+-----------


So - its utf8 (which I understand enough about to understand why its doing 
what its doing!)

So - the next question is...
Is there anyway in code I can find the 'fiddle' factor (1,3,or now possibly 4) 
that I need to use to divide by to get back to the character width specified 
in the CREATE TABLE ? 








On Tuesday 07 October 2008 12:07:28 Joerg Bruehe wrote:
> 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,  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


Thread
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