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 "Unable to 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 



Wed, 23 Jun 1999 18:20:16 -0400 (EDT)
Kristofer Munn <kmunn@munn.com>
Perl 5 Interface on 6.5 and lo_creat/lo_open problem
Kristofer Munn <kmunn@munn.com> writes:
> 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)

6.5 enforces the requirement that LO objects be used inside a
transaction.  Prior versions did not enforce this ... they just didn't
work very reliably if the lifetime of an LO FD wasn't encased in
begin/commit :-(.  I suppose you had managed to get away with it,
but you'd be much better off adding the begin/commit even for 6.4.

			regards, tom lane

Wed, 23 Jun 1999 19:38:28 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: [HACKERS] Perl 5 Interface on 6.5 and lo_creat/lo_open problem 
On Wed, 23 Jun 1999, Tom Lane wrote:

> 6.5 enforces the requirement that LO objects be used inside a
> transaction. . . . [remainder clipped]

Aha.  And the implication is then that all large object operations
(creation, deletion and modification) are affected by rollbacks and
commits.  As they should be.

I will add the transaction code.  Thanks...

- K

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


Wed, 23 Jun 1999 20:09:49 -0400 (EDT)
Kristofer Munn <kmunn@munn.com>
Re: [HACKERS] Perl 5 Interface on 6.5 and lo_creat/lo_open problem
I wrapped the large object functions in a transaction and they worked.  A
side note (for the archives) is that even the reads need to be wrapped in
a transaction.

Thanks again...

- K

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


Thu, 24 Jun 1999 11:28:14 -0400 (EDT)
Kristofer Munn <kmunn@munn.com>
Re: [HACKERS] Perl 5 Interface on 6.5 and lo_creat/lo_open problem
Kristofer Munn wrote:
> 
> Is anyone else having any problems with the Perl Interface wrt Large
> Objects under 6.5?
> 


yes, me too.

Wait for the next version of DDB-Pg.

Edmund

-- 
Edmund Mergl
mailto:E.Mergl@bawue.de
http://www.bawue.de/~mergl

Thu, 24 Jun 1999 21:07:15 +0200
Edmund Mergl <E.Mergl@bawue.de>
Re: [HACKERS] Perl 5 Interface on 6.5 and lo_creat/lo_open problem
Kristofer Munn wrote:
> 
> I wrapped the large object functions in a transaction and they worked.  A
> side note (for the archives) is that even the reads need to be wrapped in
> a transaction.
> 
> Thanks again...
> 
> - K
> 
> Kristofer Munn * http://www.munn.com/~kmunn/ * ICQ# 352499 * AIM: KrMunn


Hmmm, interesting. But using plain old C (pgsql/test/examples/testlo.c) 
it works without transactions.  

Edmund

-- 
Edmund Mergl
mailto:E.Mergl@bawue.de
http://www.bawue.de/~mergl

Thu, 24 Jun 1999 21:19:46 +0200
Edmund Mergl <E.Mergl@bawue.de>
Re: [HACKERS] Perl 5 Interface on 6.5 and lo_creat/lo_open problem
Edmund Mergl <E.Mergl@bawue.de> writes:
> Hmmm, interesting. But using plain old C (pgsql/test/examples/testlo.c) 
> it works without transactions.  

With 6.5?  I don't think so ... I made sure that LO FDs would be
cancelled at transaction commit --- which is end of statement, if
you are not within a transaction ...

			regards, tom lane

Thu, 24 Jun 1999 19:36:24 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: [HACKERS] Perl 5 Interface on 6.5 and lo_creat/lo_open problem 
Tom Lane wrote:
> 
> Edmund Mergl <E.Mergl@bawue.de> writes:
> > Hmmm, interesting. But using plain old C (pgsql/test/examples/testlo.c)
> > it works without transactions.
> 
> With 6.5?  I don't think so ... I made sure that LO FDs would be
> cancelled at transaction commit --- which is end of statement, if
> you are not within a transaction ...
> 
>                         regards, tom lane


yes, you're right, Accidentally I used the files from 6.4.

Edmund

-- 
Edmund Mergl
mailto:E.Mergl@bawue.de
http://www.bawue.de/~mergl

Fri, 25 Jun 1999 05:45:48 +0200
Edmund Mergl <E.Mergl@bawue.de>
Re: [HACKERS] Perl 5 Interface on 6.5 and lo_creat/lo_open problem