oops, first reply went to Madison alone ...<br><br>I think this is better ...<br><br>use Encode qw(from_to decode);<br><br>my $data = "Résidence";<br>from_to($data, "iso-8859-1", "utf8"); ## assuming Résidence is encoded in 8859-1<br>
or<br>my $data = decode("iso-8859-1", "Résidence");<br><br>both of these will create a utf8 string from Résidence. However, depending on the original encoding of Résidence, what's stored in the database may or may not be what you want.<br>
<br>In other words, the lack of an error message is not indicative of it working.<br><br>-rob<br><br><div class="gmail_quote">On Tue, Jul 8, 2008 at 4:41 PM, Rob Janes <<a href="mailto:janes.rob@gmail.com">janes.rob@gmail.com</a>> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">methinks your perl script is encoded in iso-8859-1, or a windows code page. just cause you can see the accent doesn't mean it's right. set your editor to utf-8. or use character conversions.<br>
<br>use utf8; ## not sure about this, is pragma<br>
$blob = utf8::encode( 'Résidence' )<br><br>or<br>use Encode;<br>$blob = encode("utf8", 'Résidence' );<br><br>Encode doesn't make any statements about the encoding of your script, it might be the better way.<br>
<br>iconv is another possibility.<br><br>look at the man page for charnames.<br><br>use charnames ":full";<br>print "R\N{LATIN SMALL LETTER E WITH ACUTE}sidence\n";<br><font color="#888888"><br>-rob</font><div>
<div></div><div class="Wj3C7c"><br><br><div class="gmail_quote">
On Tue, Jul 8, 2008 at 3:29 PM, Madison Kelly <<a href="mailto:linux@alteeve.com" target="_blank">linux@alteeve.com</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi all, second question of the day!<br>
<br>
I've got a problem INSERTing a value into my DB. It's a French character 'é', and my DB is set to UTF8, but the error is:<br>
<br>
INSERT INTO customer_data (cd_cust_id, cd_variable, cd_value, added_user, added_date, modified_user, modified_date) VALUES (1, 'CustServiceTypeDisplay_F', 'Résidence', 1, now(), 1, now());<br>
<br>
DBD::Pg::db do failed: ERROR: invalid byte sequence for encoding "UTF8": 0xe97369<br>
HINT: This error can also happen if the byte sequence does not match the encoding expected by the server, which is controlled by "client_encoding".<br>
<br>
When I manually run the INSERT, it works, so I know the problem is in perl somewhere. Now then, I setup my script with this:<br>
<br>
# Setup for UTF-8 mode.<br>
binmode STDOUT, ":utf8:";<br>
$ENV{'PERL_UNICODE'}=1;<br>
<br>
When I create my PgSQL connection, I use:<br>
<br>
$dbh=DBI->connect($db_connect_string, $$conf{db}{user}, $$conf{db}{pass},<br>
{<br>
RaiseError => 1,<br>
AutoCommit => 1,<br>
pg_enable_utf8 => 1<br>
}<br>
) or die ...;<br>
<br>
I push a pile of queries into an array (referenced) and run them like this:<br>
<br>
# Sanity checks stripped for the email<br>
$dbh->begin_work;<br>
foreach my $query (@{$sql})<br>
{<br>
print "Query: [$query]\n";<br>
$dbh->do($query) or $error.=$DBI::errstr.", ";<br>
}<br>
$dbh->commit;<br>
<br>
Lastly, my database itself is set to UTF8:<br>
<br>
SET client_encoding = 'UTF8';<br>
<br>
I've tried knocking out the 'pg_enable_utf8 => 1' line in case I was dealing with double-encoding, but that didn't help.<br>
<br>
Any tips/ideas?<br>
<br>
Thanks!<br>
<br>
Madi<br>
_______________________________________________<br>
toronto-pm mailing list<br>
<a href="mailto:toronto-pm@pm.org" target="_blank">toronto-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/toronto-pm" target="_blank">http://mail.pm.org/mailman/listinfo/toronto-pm</a><br>
</blockquote></div><br>
</div></div></blockquote></div><br>