Subject Re: [firebird-support] Character sets. (Again.)
Author Ann Harrison
> On Mar 30, 2015, at 7:01 AM, Tim Ward tdw@... [firebird-support] <firebird-support@yahoogroups.com> wrote:
>
> Sorry about this, but I really can't work out what's going on here, and
> could do with some clues.

Not so much a clue as a question. If you declare the columns as varchar, do you see the same behavior? Passing a fixed length string with variable sized characters is tricky. Do you hand the client enough buffer to handle the declare number of characters regardless their oddity, or do you pass enough to hold the string that currently exists?

>
> The basic problem is that I'm getting string values of columns into PHP
> padded on the right to four times their correct length.
>
> I've tried various combinations of things and got various weird results.
> Here's one example:
>
> (1) I believe the database default character set is UTF8 (although I
> don't know in detail what that means or what it's used for)
>
> SQL> select rdb$character_set_name from rdb$database;
> RDB$CHARACTER_SET_NAME
> UTF8
>
> (2) I've got a column in a table defined as ASCII (not that that makes
> an awful lot of difference, I get very similar results if it's UTF8):
>
> METERID CHAR( 8) CHARACTER SET ASCII
> COLLATE ASCII,
>
> (3) I connect ISQL without a -ch command line parameter and get the
> field arriving in ISQL as eight characters long:
>
> SQL> select meterid from tblmeterchange;
>
> METERID
> ========
> 0001A6BN
> 0001A6BN
>
> (4) I connect ISQL with -ch UTF8 and get the field arriving in ISQL as
> 32 characters long:
>
> SQL> select meterid from tblmeterchange;
>
> METERID
> ================================
> 0001A6BN
> 0001A6BN
>
> (5) I connect via PHP using ibase_connect with "UTF8" as the character
> set parameter and get this eight character field returned as the eight
> wanted characters padded on the right with 24 spaces.
>
> (6) If I change the definition of the METERID column to UTF8 I similarly
> get 32 characters in PHP.
>
> So what should I be doing to get an eight character value of an eight
> character field turning up as eight characters in PHP? (I don't think I
> have the option of setting the connection charset to anything other than
> UTF8 because I don't know what else it might affect and there are plenty
> of other columns in the database which, unlike this one, can't be
> declared as ASCII ... but then I don't know exactly what the concept of
> "connection character set" means or does anyway.)
>
> I have read
> http://www.firebirdsql.org/file/community/ppts/fbcon11/FbCon2011-Charsets-Heymann.pdf,
> but that doesn't help - it suggests that Firebird will transliterate as
> necessary, but padding an eight character string with 24 spaces to make
> a 32 character string isn't any sort of "transliteration" I'm familiar with.
>
If you're storing the data as UTF8 and asking for UTF8, then I guess you get a buffer big enough to hold the maximum sized eight character string.

Good luck,

Ann
>