At 11:14 AM 6/06/2007, you wrote:
> > YES! Changing the column's type to VARCHAR(1) works.
> >
> > Now can someone tell me why? Doesn't my experience still indicate that
> > there is some sort of bug with columns of type CHAR(1)?
>
>The language spec is a bit confusing with respect to the what the "n"
>actually means in CHAR(n). My copy says something like this:
>
>Name        Size           Range/Precision
>---------   ------------   ----------------------------------------
>CHAR (n)    n characters   1 to 32,767 bytes
>                            Character set character size determines
>                            the maximum number of characters that
>                            can fit in 32K
>
>So it says that "n" represents the number of *characters*, while the maximum
>range is "32,767 *bytes*".

Which is exactly correct.  It's only confusing to those who don't 
understand that not all characters/character sets encode characters 
with single-byte encodings.


>Because one UTF-8 character may take between 1 and 4 bytes, perhaps the
>server allocates four bytes of storage for it, even though the character
>that is actually stored is only 1 byte?

The server allocates storage according to the declared data type AND 
the encoding used for character data.  What it returns depends on 
whether it is defined as CHAR or VARCHAR.  CHAR is returned 
right-padded with zeros (or NUL, i.e. hex 00 in the case of charset 
OCTETS), while VARCHARs are returned as actual data plus 2 bytes (a 
smallint carrying the length of the data as NUMBER OF CHARACTERS.

The cause of the problem here is not the length of the data stored 
but that the client is set to expect single-byte encoding (by using 
character set NONE), so it has prepared its buffer to receive 1 and 
only 1 byte.  The unsuspecting server returns 4 bytes (as it is meant 
to do) and client squawks.

>It seems like a bug to me, though. That the server *allocates* 4 bytes seems
>reasonable, however I don't think it should be *returning* 4 bytes (unless
>actually required).

The server returns what it is meant to.  It doesn't have any way to 
know that the client asked for the wrong thing.

Helen


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Firebird-net-provider mailing list
Firebird-net-provider@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider

Reply via email to