9.6. Large Object: pglarge

Table of Contents
open — opens a large object
close — closes the large object
read — reads from the large object
write — writes to the large object
seek — change current position in the large object
tell — returns current position in the large object
unlink — deletes the large object
size — gives the large object size
export — saves 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

Be careful: In multithreaded environments, error may be modified by another thread using the same pgobject. Remember these object are shared, not duplicated; you should provide some locking to be able if you want to check this. The oid attribute is very interesting because it allow you 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.