lo_read error ??? - Mailing list pgsql-interfaces

From root
Subject lo_read error ???
Date
Msg-id 37443081.B5D3B18C@ssto-dtcb.interbusiness.it
Whole thread Raw
List pgsql-interfaces
Hi to all,

I'm trying to use large objects this way:

-----------------------
#!/usr/bin/perl
$ENV{'PGDATESTYLE'} = "European";
use CGI;
use Pg;
$base = new CGI;
$fax = $base->url_param('fax');
$page = $base->url_param('page');
$conn = Pg::connectdb("dbname=www host=localhost");
$select = $conn->exec("SELECT faxpage FROM faxric where codfax='$fax'");

$faxpage = $select->fetchrow();
$faxpage_fd = $conn->lo_open($faxpage, PGRES_INV_READ);
if ($faxpage_fd < 0) {print $base->header('text/plain'),"Errore aprendo file su db";exit;
}
print $base->header(-type=>'image/gif');
while(($ret = $conn->lo_read($faxpage_fd, $buf, 1024)) >0 ) {print "$buf";
}
$ret = $conn->lo_close($faxpage_fd);

------------------------

and I get only an icon, but not the image
so I modified the script ...

------------------------
#!/usr/bin/perl
$ENV{'PGDATESTYLE'} = "European";
use CGI;
use Pg;
$base = new CGI;
$fax = $base->url_param('fax');
$page = $base->url_param('page');
$conn = Pg::connectdb("dbname=www host=localhost");
$select = $conn->exec("SELECT faxpage FROM faxric where codfax='$fax'");

$faxpage = $select->fetchrow();
$faxpage_fd = $conn->lo_open($faxpage, PGRES_INV_READ);
if ($faxpage_fd < 0) {print $base->header('text/plain'),"Errore aprendo file su db";exit;
}
print $base->header(-type=>'text/plain');
while(($ret = $conn->lo_read($faxpage_fd, $buf, 1024)) >0 ) {$test = length $buf;print "$ret -- $test\n";
}
$ret = $conn->lo_close($faxpage_fd);
------------------------

and I get this output:

1024 -- 11
1024 -- 179
1024 -- 172
1024 -- 187
1024 -- 120
1024 -- 232
1024 -- 182
1024 -- 98
1024 -- 15
1024 -- 129
1024 -- 241
1024 -- 315
1024 -- 221
1024 -- 1002
1024 -- 13
190 -- 110

------------------------
why $buf do not contain all characters that lo_read() return ???

system is Linux RedHat 6.0, whit Postgres 6.4.2
(I've also tryed to compile it myself, but nothing change)

large objects are gif images
------------------------

Many tanks in advance to all.
Andrea Partinico
andrea@ssto-dtcb.interbusiness.it






pgsql-interfaces by date:

Previous
From: root
Date:
Subject: lo_read error ???
Next
From: abdelkrim
Date:
Subject: problem with LOAD