demo055 has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, I have some problem with DBI query... I use "use encoding 'cp1250'", my db is in cp1250_czech_cs and after query "SELECT id FROM gps_obec WHERE obec='$name' AND okres='$region'" i get error "illegal mix of collations (cp1250_czech_cs, IMPLICIT) and (latin1_swedish_ci, COERCIBLE)"... Do you know where is the problem? and also if i use cp1250_czech_cs characters in print, they don't display correctly... where is the problem ? please help me

Replies are listed 'Best First'.
Re: illegal mix of collations
by moritz (Cardinal) on Mar 11, 2010 at 11:03 UTC

    Since nobody has answered you so far, I'll try to give it a shot.

    When you write use encoding 'cp1250'; it doesn't magically mean that everything you do is magically in the cp1250 encoding; it really means that you declare your source code to be in that encoding, and that operations on STDIN and STDOUT work in that encoding, too.

    At the same time you lose thread safety, and introduce bugs with AUTOLOAD methods.

    Instead you should try to understand the string model in Perl. For that I recommend reading this article and/or the wikibook.

    Then you have to get proper Perl strings out of your database; typically that works by upgrading your perl database driver (some DBD:: modules) to a rather new version, and pass some encoding related options to the DBI->connect call. More information can be found in the documentation of the appropriate DBD:: module.

    Then you have to take care that data from other sources is also decoded from their current character encoding into perls internal string format, and are encoded on output again.

    I recommend writing the script in UTF-8 and use the utf8 pragma (which is much less bug ridden than the encoding pragma), and either set up the IO layers manually, or use the open pragma to do that for you.

    Perl 6 - links to (nearly) everything that is Perl 6.