6.6. Large Object: pglarge

Table of Contents
open -- open a large object
close -- close the large object
read -- read from the large object
write -- write to the large object
seek -- change current position in the large object
tell -- return current position in the large object
unlink -- delete the large object
size -- return the large object size
export -- save the large object to file

This object handles all the request concerning a PostgreSQL large object. It embeds and hides all the "recurrent" variables (object OID and connection), exactly in the same way pgobjects do, thus only keeping significant parameters in function calls. It keeps a reference to the pgobject used for its creation, sending requests though with its parameters. Any modification but dereferencing the pgobject will thus affect the pglarge object. Dereferencing the initial pgobject is not a problem since Python will not deallocate it before the large object dereference it. All functions return a generic error message on call error, whatever the exact error was. The error attribute of the object allows to get the exact error message.

pglarge objects define a read-only set of attributes that allow to get some information about it. These attributes are:

oid

the OID associated with the object

pgcnx

the pgobject associated with the object

error

the last warning/error message of the connection

Important: In multithreaded environments, error may be modified by another thread using the same pgobject. Remember that these object are shared, not duplicated; you should provide some locking if you want to check for the error message in this situation. The OID attribute is very interesting because it allow you to reuse the OID later, creating the pglarge object with a pgobject getlo() method call.

See also Chapter 2 for more information about the PostgreSQL large object interface.