lo_copy routine - Mailing list pgsql-hackers

From Vince Roberts
Subject lo_copy routine
Date
Msg-id Pine.BSF.4.21.0106121228310.94611-100000@unix1.emanon.net
Whole thread Raw
In response to Re: [Fwd: AW: Postgres Replication]  ("Eric C. Newton" <ecn@metaslash.com>)
List pgsql-hackers
Here is a basic lo_copy routine

It copies a large object from an existing large object


PG_FUNCTION_INFO_V1(lo_copy);

Datum
lo_copy(PG_FUNCTION_ARGS)
{       Oid                     oldlobjId = PG_GETARG_OID(0);       LargeObjectDesc         *lobj,*oldlobj;       int
                 readbytes,                               writebytes;       char                    buf[BUFSIZE];
Oid                    lobjOid;
 

       oldlobj = inv_open(oldlobjId, INV_READ);       if (lobj == NULL)               elog(ERROR, "lo_copy: can't open
invobject %u", oldlobjId);
 
       lobj = inv_create(INV_READ | INV_WRITE);       if (lobj == NULL)               elog(ERROR, "lo_copy: can't
createinv object");       lobjOid = lobj->id;
 
       while ((readbytes = inv_read(oldlobj, buf, BUFSIZE)) > 0)       {               writebytes = inv_write(lobj,
buf,readbytes);               if (writebytes != readbytes)                       elog(ERROR, "lo_copy: error while
copying");      }
 
       inv_close(oldlobj);       inv_close(lobj);
       PG_RETURN_OID(lobjOid);
}




pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: Re: [PATCHES] Australian timezone configure option
Next
From: chris.bitmead@health.gov.au
Date:
Subject: Re: [PATCHES] Australian timezone configure option