From: | Madison Kelly <linux(at)alteeve(dot)com> |
---|---|
To: | pgus-general(at)postgresql(dot)org |
Subject: | Perl/PostgreSQL INSERT/utf-8 problem |
Date: | 2008-07-08 20:05:36 |
Message-ID: | 4873C890.2040503@alteeve.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgus-general |
Hi all,
I've got a problem INSERTing a value into my DB via my perl program.
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
From | Date | Subject | |
---|---|---|---|
Next Message | Joshua D. Drake | 2008-07-22 19:49:10 | Small update |
Previous Message | Joshua D. Drake | 2008-07-02 20:12:06 | Re: Draft bylaws are now available |