Subject Re: [firebird-support] when to use introducer syntax for charachter sets?
Author Michael Ludwig
Marsupilami79 schrieb am 06.03.2012 um 09:40 (+0100):

> The statement about the usage of introducers is on Page 172 in the
> middle of the page in a section with the heading "String Literal":
> "An introducer will be required if the database column being searched
> has a character set which is different from that of the client
> connection."

Okay, and then Helen gives the following example:

... WHERE name = _ISO8859_1 'joe';

Which is somewhat pointless as "joe" is the same in all ASCII supersets,
and hence doesn't require conversion. (And Firebird doesn't do EBCDIC.)
Guess Helen doesn't have the ö on her keyboard. I'd still suggest that
for the second edition, it should be Jörg instead of Joe.

Here's an example, because I was curious:

D:\ :: isql eins -u milu -p moin -ch utf8
Database: eins, User: milu
SQL> create table z(a varchar(20) character set utf8);
SQL> commit;
SQL> insert into z (a) values ('Jörg');
Statement failed, SQLSTATE = 22000
Dynamic SQL Error
-SQL error code = -104
-Malformed string
SQL> -- I've been lying to FB about the connection charset.
SQL> -- My connection is really in win1252, not in utf8.
SQL> -- Still, I can save the party by using an introducer.
SQL> insert into z (a) values (_win1252 'Jörg');
SQL> commit;
SQL> select * from z;

A
===============================================================================
Jörg

SQL> quit;

Note two things in the output above:

(1) FB thinks my connection is utf8 (because I've been lying), so it
cranks out data in UTF-8, which displays like above on a win1252
terminal.

(2) The bar is 79 characters long when the column has only 20 chars.
This is because FB reserves 4 bytes per Unicode character. (Don't ask
me why it's 79 instead of 80.)

D:\ :: isql eins -u milu -p moin -ch win1252
Database: eins, User: milu
SQL> select * from z;

A
====================
Jörg

Everything's fine, text automatically converted for display in win1252.

--
Michael

> Am 02.03.2012 19:26, schrieb Michael Ludwig:
> >
> > Marsupilami79 schrieb am 23.02.2012 um 15:17 (+0100):
> > >
> > > I have a problem in understanding when to use the introducer syntax
> > > for character sets.
> >
> > For literals. See here:
> >
> > http://dev.mysql.com/doc/refman/5.0/en/charset-literal.html
> >
> > > Helen Borrie states in the firebird books
> >
> > What page number?
> >
> > > that the introducer syntax should be used whenever a column is
> > > searched and the connection character set is different from the
> > > character set of that column:
> > >
> > > So in case I have a WIN1252 client connection and the database uses
> > > UTF8, should I really always use something like
> > > where name = _WIN1252 'Jörg'
> >
> > Not needed when you type in the characters in the proper connection
> > encoding.
> >
> > But suppose in your connection you're going to execute a SQL script
> > which happens to be encoded in UTF-8. In order not to depend on the
> > connection encoding du jour, you'd play safe and use introducers in
> > your script.
> >
> > > Why should I do that? Normally I would expect firebird to know that
> > > everything is WIN1252, as this is the connection character set, and
> > > do the necessary conversions without any further hints?
> > >
> > > Or should I use the introducer syntax only when I want to send some
> > > bytes that are explicitly to be treated in a different way than the
> > > connection character set?
> > >
> > > for example something like
> > > where name = _UTF8 'Jörg'
> > > when I have the 'Jörg' in an UTF8 encoded way?
> >
> > Exactly.