[tpm] PostgreSQL INSERT/UTF-8 problem
Madison Kelly
linux at alteeve.com
Tue Jul 8 12:29:20 PDT 2008
Hi all, second question of the day!
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:
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());
DBD::Pg::db do failed: ERROR: invalid byte sequence for encoding
"UTF8": 0xe97369
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".
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:
# Setup for UTF-8 mode.
binmode STDOUT, ":utf8:";
$ENV{'PERL_UNICODE'}=1;
When I create my PgSQL connection, I use:
$dbh=DBI->connect($db_connect_string, $$conf{db}{user}, $$conf{db}{pass},
{
RaiseError => 1,
AutoCommit => 1,
pg_enable_utf8 => 1
}
) or die ...;
I push a pile of queries into an array (referenced) and run them like
this:
# Sanity checks stripped for the email
$dbh->begin_work;
foreach my $query (@{$sql})
{
print "Query: [$query]\n";
$dbh->do($query) or $error.=$DBI::errstr.", ";
}
$dbh->commit;
Lastly, my database itself is set to UTF8:
SET client_encoding = 'UTF8';
I've tried knocking out the 'pg_enable_utf8 => 1' line in case I was
dealing with double-encoding, but that didn't help.
Any tips/ideas?
Thanks!
Madi
More information about the toronto-pm
mailing list