Skip site navigation (1) Skip section navigation (2)

Perl and large objects

From: "Jeremy Bettis" <jeremy(at)hksys(dot)com>
To: <pgsql-interfaces(at)postgresql(dot)org>
Subject: Perl and large objects
Date: 1999-07-22 18:02:38
Message-ID: 000e01bed46c$62fc4910$0d01000a@hksys.com (view raw or flat)
Thread:
Lists: pgsql-interfaces
I have a script that reads and writes some large objects;

Write works fine, read doesn't. It gets this error:

Could not open lo ERROR: lo_lseek: invalid large obj descriptor (0) 

I have confirmed that the oid that I get in the script is the same as what psql reports.

Here are some fragments of code:

sub doselect{    my $query = $_[0];
    my ($result, $status, $i, $j);
    my (@data);
    if (!$conn) {
        $conn = Pg::connectdb("dbname=jeremy");
        if ( PGRES_CONNECTION_OK != $conn->status ) {
            print "<pre>",$conn->errorMessage, "\n", $query, "\n</pre>\n";
            print end_html;
            exit(1);
        }
    }
    @data=();
    if ($result = $conn->exec($query)) {
        if (PGRES_TUPLES_OK == ($status = $result->resultStatus)) {
            for $i (0..$result->ntuples-1) {
                for $j (0..$result->nfields-1) {
                    $data[$i]->{$result->fname($j)}=$result->getvalue($i,$j);
                }
            }
            return \(at)data;
        }
    }
    print "<pre>",$conn->errorMessage, "\n", $query, "\n</pre>\n";
    print end_html;
    exit(1);
}




        $emails = doselect("select long_body,short_body from email_body where email_id = $email_id");
        if ($$emails[0]->{long_body} > 0) {
            $loid = $$emails[0]->{long_body};
            print "Long #", $loid;
            $long=$conn->lo_open($loid, PGRES_INV_READ);
            if ($long==-1) {
                print("Could not open lo ",$conn->errorMessage) ;
            } else {
            $buf="";
            while ($conn->lo_read($long, $buf, 2048) > 0) {
                $body.=$buf;
                $buf="";
            }
            $conn->lo_close($long);
            }
}
--
Jeremy Bettis
jeremy(at)hksys(dot)com

pgsql-interfaces by date

Next:From: Hub.Org News AdminDate: 1999-07-22 21:19:26
Subject:
Previous:From: Hugh LawsonDate: 1999-07-22 16:30:04
Subject: Re: [INTERFACES] Re: [ANN] pg.el v0.2 -- Emacs Lisp interface to PostgreSQL

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group