Subject Re: [firebird-support] Bug with character sets
Author Martijn Tonies
Milan, another question.

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

I'm not sure how much sense this makes to me :-)

UTF8 has 1, 2, 3 or 4 bytes per character, right? So the buffer for
characters is always "4 bytes" * "number of characters". But what happens
in your particular case if the character is 2 bytes long? You cannot
truncate it to the first byte (to get ASCII 'Y')?

With regards,

Martijn Tonies
Upscene Productions
http://www.upscene.com

Download Database Workbench for Oracle, MS SQL Server, Sybase SQL
Anywhere, MySQL, InterBase, NexusDB and Firebird!

Database questions? Check the forum:
http://www.databasedevelopmentforum.com