Re: [exim] correct way to set charset in mysql connections?

Top Pagina
Delete this message
Reply to this message
Auteur: Arkadiusz Miskiewicz
Datum:  
Aan: exim-users
Onderwerp: Re: [exim] correct way to set charset in mysql connections?
On Monday 21 of December 2009, Phil Pennock wrote:
> On 2009-12-21 at 08:20 +0100, Arkadiusz Miskiewicz wrote:
> > text = "${lookup mysql{SELECT content FROM user WHERE
> > login='${quote_mysql: $local_part}'}}"
> >
> > that fetches text message from database. Text message contains non ascii
> > characters.
> >
> > Now with mysql >= 4.1 you need to specify charset in which you want to
> > see query output (mysql is able to do charset recoding on the fly).
> >
> > Default is latin1, so if you have some non-latin1 data then output will
> > return "?" chars instead of non-latin1 characters.
> >
> > "SET NAMES utf8" tells mysql to return utf8 output instead of default
> > latin1 for example.
> >
> > Now how can I issue charset in such queries?
> >
> > ${lookup mysql{SET NAMES utf8; SELECT ...
> >
> > doesn't work.
>
> What happens if you edit /etc/my.cnf to include this?
> ----------------------------8< cut here >8------------------------------
> [client]
> default-character-set=utf8
> ----------------------------8< cut here >8------------------------------
>
> Note that this assumes that all clients on the system should use the
> same default.


It would likely work but I cannot rely on this assumption.

I ended up doing

text = "${lookup mysql{SET NAMES utf8}{}}${lookup mysql{SELECT content FROM
user WHERE login='${quote_mysql: $local_part}'}}"

and it works since exim resuses existing connection. It's very ugly anyway.

Exim lacks of some sane method to archieve this IMO.

> -Phil


-- 
Arkadiusz Miśkiewicz        PLD/Linux Team
arekm / maven.pl            http://ftp.pld-linux.org/