pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jeremy Bettis <jeremy@hksys.com>
To: pgsql-interfaces@postgresql.org
Subject: Perl and large objects
Date: Thu, 22 Jul 1999 13:02:38 -0500
Message-ID: <000e01bed46c$62fc4910$0d01000a@hksys.com> (raw)

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 \@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@hksys.com

view thread (4+ messages)  latest in thread

Message-ID: <000e01bed46c$62fc4910$0d01000a@hksys.com>
Permalink:  ../000e01bed46c$62fc4910$0d01000a@hksys.com/
Also on:    postgresql.org/message-id/000e01bed46c$62fc4910$0d01000a@hksys.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: jeremy@hksys.com
  Subject: Re: Perl and large objects
  In-Reply-To: <000e01bed46c$62fc4910$0d01000a@hksys.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox