X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 6A0385E48CF for ; Tue, 7 Sep 2004 14:57:17 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 05923-04 for ; Tue, 7 Sep 2004 13:57:14 +0000 (GMT) Received: from ns1.officenet.no (cD90888A8.sdsl.catch.no [217.8.136.168]) by svr1.postgresql.org (Postfix) with ESMTP id 8F7D55E48CB for ; Tue, 7 Sep 2004 14:57:10 +0100 (BST) Received: from [127.0.0.1] (helo=localhost) by ns1.officenet.no with esmtp (Exim 4.33) id 1C4gPR-0002UW-Hn for pgsql-sql@postgresql.org; Tue, 07 Sep 2004 15:53:21 +0200 From: Andreas Joseph Krogh Organization: OfficeNet AS To: pgsql-sql@postgresql.org Subject: Re: Problem with LATIN1 characters from Perl-DBI Date: Tue, 7 Sep 2004 15:53:20 +0200 User-Agent: KMail/1.7 References: <200409071406.40262.andreak@officenet.no> In-Reply-To: <200409071406.40262.andreak@officenet.no> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart1276003.4p2BVEvn1k"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit Message-Id: <200409071553.21169.andreak@officenet.no> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200409/43 X-Sequence-Number: 18889 --nextPart1276003.4p2BVEvn1k Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On Tuesday 07 September 2004 14:06, you wrote: > Hi. > I have a database created with -E LATIN1. Inserting norwegian characters > lik '=F8' works perfectly from JDBC, but from Perl, it stores the word > 's=F8ker' as 's=C3=B8ker'(UNICODE). > > perl --version: > This is perl, v5.8.3 built for i386-linux-thread-multi > A Mandrake-10 Linux system. > > I first had the problem printing out LATIN1 chars to stdout too, but solv= ed > that by using the pragma > use encoding 'ISO-8859-1'; > > I've tried: > $dbh->do("set CLIENT_ENCODING TO 'ISO-8859-1'") > or die("Couldn't set encoding to ISO-8859-1"); > but that didn't work. > > Any hints anyone? Replying to my self: I fixed it by using the following: use encoding 'ISO-8859-1'; use Unicode::MapUTF8 qw(to_utf8 from_utf8 utf8_supported_charset); $tmp_text =3D from_utf8({ -string =3D> $plain_text, -charset =3D> 'ISO-8859= -1' }); $retval =3D $insert_stmt->execute($tmp_text); The problem was that the contents of $plain_text was obtained by some libra= ry=20 which returned text in utf8. When printing it out to stdout, the 'use=20 encoding' pragma took care of the conversion, but that didn't work for=20 inserting the contents of $plain_text into the database. So I must convert = it=20 to latin1 using the from_utf8 subroutine *before* inserting it into the DB. --=20 Andreas Joseph Krogh Senior Software Developer / Manager gpg public_key: http://dev.officenet.no/~andreak/public_key.asc ------------------------+---------------------------------------------+ OfficeNet AS | Two tomatoes in a fridge. One tomato says | Hoffsveien 17 | to the other, "It's cold in here, isn't it?"| PO. Box 425 Sk=F8yen | The other tomato says, "F**king hell, | 0213 Oslo | a talking tomato!" | NORWAY | | Phone : +47 22 13 01 00 | | Direct: +47 22 13 10 03 | | Mobile: +47 909 56 963 | | ------------------------+---------------------------------------------+ --nextPart1276003.4p2BVEvn1k Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) iD8DBQBBPb1RUopImDh2gfQRApb8AJ9uVm9O2DCeqfdc2prNVns+q+LftACgkMNN 8XueV6eBmQZ/uGTekdnUH9Y= =OknU -----END PGP SIGNATURE----- --nextPart1276003.4p2BVEvn1k--