Re: bytea corruption? - Mailing list pgsql-general

From Tim Landscheidt
Subject Re: bytea corruption?
Date
Msg-id m3praorcdw.fsf@passepartout.tim-landscheidt.de
Whole thread Raw
In response to bytea corruption?  (Nathan Jahnke <njahnke@gmail.com>)
Responses Re: bytea corruption?  (Nathan Jahnke <njahnke@gmail.com>)
List pgsql-general
Nathan Jahnke <njahnke@gmail.com> wrote:

> [...]
> my $encodeddata = $data;
> $encodeddata =~ s!(\\|[^ -~])!sprintf("\\%03o",ord($1))!ge; #prepare
> data for bytea column storage

> [...]

> my $insert_sth = $connection->prepare('insert into testtable (data)
> values (?) returning id');
> $insert_sth->execute($encodeddata);
> my $ref = $insert_sth->fetchrow_hashref;
> my $id = $ref->{id};

> my $getall_sth = $connection->prepare('select * from testtable where id=?');
> $getall_sth->execute($id);
> my $newref = $getall_sth->fetchrow_hashref;
> my $newdata = $newref->{data};
> $newdata =~ s!\\(?:\\|(\d{3}))!$1 ? chr(oct($1)) : "\\"!ge; #decode
> bytea column storage format
> [...]

> hash of data changes ... if you uncomment the $data = '123abc' line
> you can see that it works with those six bytes fine, and it also works
> with most other binary data, just not this binary data. any insight
> would be appreciated. thanks.

Why do you encode/decode the data in your own application a
second time? It is already encoded by DBD::Pg.

Tim

pgsql-general by date:

Previous
From: "Joshua D. Drake"
Date:
Subject: Re: export a schema / import as new schema
Next
From: Craig Ringer
Date:
Subject: Re: "Could not open relation XXX: No such file or directory"