Subject Re: [firebird-support] Bug with character sets
Author Milan Babuskov
Kjell Rilbe wrote:
>> > I'm using FirebirdCS 2.1.2 on SuSE 11.1 Linux and I create a database
>> > specifying the default character set to be UTF8. I then connect to
>> > the database and specify that I'll be using UTF8 for the connection.
>> > If I then select on any "char" type column, I get back a string that
>> > is 4 times the length it should be and blank padded.
>> >
>> > So for instance if I have a char(1) column and store 'Y' or 'N' in it
>> > and select on it, I get back 'Y ' or 'N '. The problem doesn't
>> > happen with varchar columns and if I change the character set used for
>> > the connection to ISO8859_1, then the problem goes away.
>> >
>> > PS: this is all using the C fbclient library and I'm setting the
>> > connection character set using isc_dpb_lc_ctype in my connection
>> > parameters.
>>
>> I've seen this when using IBObjects, can someone else confirm this too?
>
> I've seen it in FlameRobin but they fixed it. Maybe should ask those
> guys what the problem was and how they solved it?

Firebird returns the character set ID as part of result. You need to
read in the field RDB$BYTES_PER_CHARACTER from table RDB$CHARACTER_SETS
for that RDB$CHARACTER_SET_ID and then divide the reported length with
this number. When done, use the result to truncate the returned string
to that many characters. Example:

select 'Y' from rdb$database;

returned buffer: 'Y ';
returned length: 4
returned charset ID: 4 (UTF8)

select RDB$BYTES_PER_CHARACTER
from RDB$CHARACTER_SETS
where RDB$CHARACTER_SET_ID = 4;

real length in characters = 4/4 = 1
truncate the result to 1 character to get 'Y'

In FlameRobin we read in all the character set lengths when connecting
to the database, and later just reuse that info.

--
Milan Babuskov
http://www.flamerobin.org
http://www.guacosoft.com