[tpm] PostgreSQL INSERT/UTF-8 problem
Madison Kelly
linux at alteeve.com
Wed Jul 9 09:50:32 PDT 2008
Rob Janes wrote:
> oops, first reply went to Madison alone ...
>
> I think this is better ...
>
> use Encode qw(from_to decode);
>
> my $data = "Résidence";
> from_to($data, "iso-8859-1", "utf8"); ## assuming Résidence is encoded
> in 8859-1
> or
> my $data = decode("iso-8859-1", "Résidence");
>
> 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.
>
> In other words, the lack of an error message is not indicative of it
> working.
>
> -rob
I am not sure if this is the most ... appropriate way to solve the
problem, so I would still love to have some feedback if you (or anyone)
has any.
I got it working this way:
- Read the data from the website and push it into a hash (hidden input
values stored as "$input{name}=value;".
- Loop through the '%input' hash keys and populate a new hash
'%enc_input' with the same format.
- Read the old values from the database into a matching hash called
'%old_input'.
- Pseduo-code:
foreach $key (keys %input)
{
if ( $input{$key} ne $old_input{$key} )
{
# Update the DB using the '$enc_input' hash value.
}
}
It's ugly as sin, but it seems like the only time I need to use 'Encode'
functions are in the actual PgSQL INPUT or UPDATE calls; not in the
comparison of the value either from the HTML page or from the database.
Odd.
Thanks for your help, Rob and Cees!
Madi
More information about the toronto-pm
mailing list