Perl and large objects

Поиск
Список
Период
Сортировка
От Jeremy Bettis
Тема Perl and large objects
Дата
Msg-id 000e01bed46c$62fc4910$0d01000a@hksys.com
обсуждение исходный текст
Список 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 \@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

В списке pgsql-interfaces по дате отправления:

Предыдущее
От: Hugh Lawson
Дата:
Сообщение: Re: [INTERFACES] Re: [ANN] pg.el v0.2 -- Emacs Lisp interface to PostgreSQL
Следующее
От: Jonathan Dale
Дата:
Сообщение: Frontend/Backend Protocol