Received: from hksys.com (IDENT:root@dns.hksys.com [206.222.220.16]) by hub.org (8.9.3/8.9.3) with ESMTP id OAA38103 for ; Thu, 22 Jul 1999 14:02:50 -0400 (EDT) (envelope-from jeremy@hksys.com) Received: from silver (silver.hksys.com [10.0.1.13]) by hksys.com (8.9.3/8.8.7) with SMTP id NAA30664 for ; Thu, 22 Jul 1999 13:02:39 -0500 Message-ID: <000e01bed46c$62fc4910$0d01000a@hksys.com> From: "Jeremy Bettis" To: Subject: Perl and large objects Date: Thu, 22 Jul 1999 13:02:38 -0500 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_000B_01BED442.7974F270" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.00.2014.211 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211 X-Logged: Logged by hksys.com as NAA30664 at Thu Jul 22 13:02:39 1999 This is a multi-part message in MIME format. ------=_NextPart_000_000B_01BED442.7974F270 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable 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)=20 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 =3D $_[0]; my ($result, $status, $i, $j); my (@data); if (!$conn) { $conn =3D Pg::connectdb("dbname=3Djeremy"); if ( PGRES_CONNECTION_OK !=3D $conn->status ) { print "
",$conn->errorMessage, "\n", $query, =
"\n
\n"; print end_html; exit(1); } } @data=3D(); if ($result =3D $conn->exec($query)) { if (PGRES_TUPLES_OK =3D=3D ($status =3D $result->resultStatus)) = { for $i (0..$result->ntuples-1) { for $j (0..$result->nfields-1) { = $data[$i]->{$result->fname($j)}=3D$result->getvalue($i,$j); } } return \@data; } } print "
",$conn->errorMessage, "\n", $query, "\n
\n"; print end_html; exit(1); } $emails =3D doselect("select long_body,short_body from = email_body where email_id =3D $email_id"); if ($$emails[0]->{long_body} > 0) { $loid =3D $$emails[0]->{long_body}; print "Long #", $loid; $long=3D$conn->lo_open($loid, PGRES_INV_READ); if ($long=3D=3D-1) { print("Could not open lo ",$conn->errorMessage) ; } else { $buf=3D""; while ($conn->lo_read($long, $buf, 2048) > 0) { $body.=3D$buf; $buf=3D""; } $conn->lo_close($long); } } -- Jeremy Bettis jeremy@hksys.com ------=_NextPart_000_000B_01BED442.7974F270 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
I have a script that reads and writes some large=20 objects;
 
Write works fine, read doesn't. It gets this=20 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=20 same as what psql reports.
 
Here are some fragments of code:
 
sub doselect{    my $query =3D=20 $_[0];
    my ($result, $status, $i,=20 $j);
    my (@data);
    if (!$conn) = {
        $conn =3D=20 Pg::connectdb("dbname=3Djeremy");
      =   if=20 ( PGRES_CONNECTION_OK !=3D $conn->status )=20 {
            = print=20 "<pre>",$conn->errorMessage, "\n", $query,=20 "\n</pre>\n";
        &n= bsp;  =20 print=20 end_html;
          =  =20 exit(1);
        = }
   =20 }
    @data=3D();
    if ($result = =3D=20 $conn->exec($query)) {
        = if=20 (PGRES_TUPLES_OK =3D=3D ($status =3D $result->resultStatus))=20 {
            = for $i=20 (0..$result->ntuples-1)=20 {
           &n= bsp;   =20 for $j (0..$result->nfields-1)=20 {
           &n= bsp;       =20 $data[$i]->{$result->fname($j)}=3D$result->getvalue($i,$j);
&= nbsp;           &n= bsp;  =20 }
           =20 }
            = return=20 \@data;
        = }
   =20 }
    print "<pre>",$conn->errorMessage, = "\n",=20 $query, "\n</pre>\n";
    print=20 end_html;
    exit(1);
}
 
 
 
        $emails = =3D=20 doselect("select long_body,short_body from email_body where email_id =3D = $email_id");
        if=20 ($$emails[0]->{long_body} > 0)=20 {
            = $loid =3D=20 $$emails[0]->{long_body};
       = ;    =20 print "Long #",=20 $loid;
          &nb= sp;=20 $long=3D$conn->lo_open($loid,=20 PGRES_INV_READ);
         = ;  =20 if ($long=3D=3D-1)=20 {
           &n= bsp;   =20 print("Could not open lo ",$conn->errorMessage)=20 ;
            = } else=20 {
           =20 $buf=3D"";
          = ; =20 while ($conn->lo_read($long, $buf, 2048) > 0)=20 {
           &n= bsp;   =20 $body.=3D$buf;
         &= nbsp;     =20 $buf=3D"";
          = ; =20 }
           =20 $conn->lo_close($long);
       &= nbsp;   =20 }
}
--
Jeremy Bettis
jeremy@hksys.com
= ------=_NextPart_000_000B_01BED442.7974F270--