Thread: Perl 5 Interface on 6.5 and lo_creat/lo_open problem

Perl 5 Interface on 6.5 and lo_creat/lo_open problem

From
Kristofer Munn
Date:
Is anyone else having any problems with the Perl Interface wrt Large
Objects under 6.5?

I compiled and installed 6.5 on an Intel/Linux/RedHat 6.0 machine that had
previously had 6.4.2 and imported existing data from the old database.  
Perl scripts which were working under the previous version are now failing
when trying to open a newly created large object.  A line appears in the
error log:

Jun 23 17:40:47 www logger: ERROR:  lo_lseek: invalid large obj descriptor (0)

While the code being executed is a function call write_blob below. The
scaffolding internally tells me it is unable to open oid XXXXXX for
writing where XXXXXX is the newly "created" oid #.

sub write_blob {   my($oid, $blob) = @_;
   print "write_blob($oid, '$blob');\n" if $debug;   if ($blob eq "") {       if ($oid > 0) {
$conn->lo_unlink($oid);      }       print "No blob to write\n" if $debug;       return "NULL";   }   if ($oid == 0) {
    $oid = $conn->lo_creat(PGRES_INV_WRITE | PGRES_INV_READ);       if ($oid == PGRES_InvalidOid) {           print
"Unableto get new oid.\n" if $debug;           return "NULL";       }   }   my($lobj_fd) = $conn->lo_open($oid,
PGRES_INV_WRITE);  if ($lobj_fd == -1) {       print "Unable to open oid $oid for writing.\n" if $debug;       return
"NULL";  }
 
   if ($conn->lo_write($lobj_fd, $blob, length($blob)) == -1) {       $conn->lo_close($lobj_fd);
$conn->lo_unlink($oid);      print "Unable to write blob into open oid $oid.\n" if $debug;       return "NULL";   }
$conn->lo_close($lobj_fd);
   print "write_blob successful\n" if $debug;
   return $oid;
}

I reverted to 6.4.2 and the scripts worked again.  Back to 6.5 - no dice.

- K

Kristofer Munn * http://www.munn.com/~kmunn/ * ICQ# 352499 * AIM: KrMunn 





Re: Perl 5 Interface on 6.5 and lo_creat/lo_open problem

From
"Matt Magoffin"
Date:
<font face="Charcoal">I am having the same problem with 6.5 on my LinuxPPC R5 (i.e. RH 6) box, that is I can create and
deletelarge objects, but can't open them to read the contents. Did you ever find a solution for this problem?<br /><br
/>-- M@<br /><br />    < <  <   senor mateo <br />             borders.com jefe interactivo<br />
            (0.11)734.477.1130 <br /><br /></font> 

Re: Perl 5 Interface on 6.5 and lo_creat/lo_open problem

From
Kristofer Munn
Date:
I was informed that as of 6.5 the requirement for wrapping large object
actions in a transaction is required.  I put a "BEGIN TRANSACTION" and
"COMMIT TRANSACTION" around my function which reads and writes my LOs and
everything worked like a charm.

- K

Kristofer Munn * http://www.munn.com/~kmunn/ * ICQ# 352499 * AIM: KrMunn