Re: bytea on windows perl client - Mailing list pgsql-interfaces

From James Orr
Subject Re: bytea on windows perl client
Date
Msg-id 200207171300.01423.james@lrgmail.com
Whole thread Raw
In response to Re: bytea on windows perl client  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-interfaces
Hi Tom,

On Wednesday 17 July 2002 12:08 pm, Tom Lane wrote:
> James Orr <james@lrgmail.com> writes:
> > I have some code which runs fine on linux.  It simply pulls a png from a
> > bytea column and displays it.
> >
> > Now I need to get it running on windows.  We have installed ActiveState
> > perl with the DBI module and downloaded and installed the DBD-Pg binary.
> > Connections to the database are working fine, but the png file is getting
> > corrupted.
> >
> > Anybody know the work-around?
>
> I'd bet money that the problem is a newline conversion issue --- you
> could check by noticing whether the PNG signature (first 8 bytes of the
> file) comes back correctly or not.  The signature is designed to get
> changed if it's fed through any of the standard kinds of newline
> conversion (\n -> \r\n, for example).

OK, if I load the output into vi.  The one from linux contains a bunch of
control characters etc.  The one from windows seems to be all text like so
...

\211PNG\015\012\000 and so on.

Here is my actual perl script:

#! /usr/bin/perl -w

use DBI;
require 'common.pl';

my $dbh; initdb(\$dbh);

# Get the logos
my $image_sth = $dbh->prepare("SELECT logo FROM logos ORDER BY random() LIMIT
1");
$image_sth->execute();
my $image = $image_sth->fetchall_arrayref->[0]->[0];
$image_sth->finish();

$dbh->disconnect();

print "Content-type: image/png\n\n";
print $image;

exit;


pgsql-interfaces by date:

Previous
From: Tom Lane
Date:
Subject: Re: bytea on windows perl client
Next
From: Joe Conway
Date:
Subject: Re: bytea on windows perl client