11<!--
2- $PostgreSQL: pgsql/doc/src/sgml/lobj.sgml,v 1.34 2004/12/28 22:47:15 tgl Exp $
2+ $PostgreSQL: pgsql/doc/src/sgml/lobj.sgml,v 1.35 2005/01/08 22:13:33 tgl Exp $
33-->
44
55 <chapter id="largeObjects">
@@ -122,15 +122,17 @@ Oid lo_creat(PGconn *conn, int mode);
122122 or'ing together the bits <symbol>INV_READ</symbol> and
123123 <symbol>INV_WRITE</symbol>. The low-order sixteen bits of the mask have
124124 historically been used at Berkeley to designate the storage manager number on which the large object
125- should reside. These
126- bits should always be zero now.
127- The return value is the OID that was assigned to the new large object.
125+ should reside. These bits should always be zero now. (The access type
126+ does not actually do anything anymore either, but one or both flag bits
127+ must be set to avoid an error.)
128+ The return value is the OID that was assigned to the new large object,
129+ or InvalidOid (zero) on failure.
128130 </para>
129131
130132 <para>
131133 An example:
132134<programlisting>
133- inv_oid = lo_creat(INV_READ|INV_WRITE);
135+ inv_oid = lo_creat(conn, INV_READ|INV_WRITE);
134136</programlisting>
135137 </para>
136138 </sect2>
@@ -147,7 +149,8 @@ Oid lo_import(PGconn *conn, const char *filename);
147149 <replaceable class="parameter">filename</replaceable>
148150 specifies the operating system name of
149151 the file to be imported as a large object.
150- The return value is the OID that was assigned to the new large object.
152+ The return value is the OID that was assigned to the new large object,
153+ or InvalidOid (zero) on failure.
151154 Note that the file is read by the client interface library, not by
152155 the server; so it must exist in the client filesystem and be readable
153156 by the client application.
@@ -164,19 +167,19 @@ Oid lo_import(PGconn *conn, const char *filename);
164167int lo_export(PGconn *conn, Oid lobjId, const char *filename);
165168</synopsis>
166169 <indexterm><primary>lo_export</></>
167- The <parameter>lobjId</parameter> argument specifies the OID of the large
168- object to export and the <parameter>filename</parameter> argument specifies
169- the operating system name of the file.
170- Note that the file is written by the client interface library, not by
171- the server .
170+ The <parameter>lobjId</parameter> argument specifies the OID of the large
171+ object to export and the <parameter>filename</parameter> argument
172+ specifies the operating system name of the file. Note that the file is
173+ written by the client interface library, not by the server. Returns 1
174+ on success, -1 on failure .
172175 </para>
173176 </sect2>
174177
175178 <sect2>
176179 <title>Opening an Existing Large Object</title>
177180
178181 <para>
179- To open an existing large object, call
182+ To open an existing large object for reading or writing , call
180183<synopsis>
181184int lo_open(PGconn *conn, Oid lobjId, int mode);
182185</synopsis>
@@ -186,11 +189,13 @@ int lo_open(PGconn *conn, Oid lobjId, int mode);
186189 object is opened for reading (<symbol>INV_READ</>), writing (<symbol>INV_WRITE</symbol>), or
187190 both.
188191 A large object cannot be opened before it is created.
189- <function>lo_open</function> returns a large object descriptor
190- for later use in <function>lo_read</function>, <function>lo_write</function>,
191- <function>lo_lseek</function>, <function>lo_tell</function>, and
192- <function>lo_close</function>. The descriptor is only valid for
192+ <function>lo_open</function> returns a (non-negative) large object
193+ descriptor for later use in <function>lo_read</function>,
194+ <function>lo_write</function>, <function>lo_lseek</function>,
195+ <function>lo_tell</function>, and <function>lo_close</function>.
196+ The descriptor is only valid for
193197 the duration of the current transaction.
198+ On failure, -1 is returned.
194199</para>
195200</sect2>
196201
@@ -246,7 +251,7 @@ int lo_lseek(PGconn *conn, int fd, int offset, int whence);
246251 are <symbol>SEEK_SET</> (seek from object start),
247252 <symbol>SEEK_CUR</> (seek from current position), and
248253 <symbol>SEEK_END</> (seek from object end). The return value is
249- the new location pointer.
254+ the new location pointer, or -1 on error .
250255</para>
251256</sect2>
252257
@@ -294,46 +299,56 @@ int lo_unlink(PGconn *conn, Oid lobjId);
294299</synopsis>
295300 <indexterm><primary>lo_unlink</></> The
296301 <parameter>lobjId</parameter> argument specifies the OID of the
297- large object to remove. In the event of an error, the return
298- value is negative.
302+ large object to remove. Returns 1 if successful, -1 on failure.
299303 </para>
300304 </sect2>
301305
302-
303306</sect1>
304307
305308<sect1 id="lo-funcs">
306309<title>Server-Side Functions</title>
307310
308- <para>
309- There are two built-in server-side functions,
310- <function>lo_import</function><indexterm><primary>lo_import</></>
311- and
312- <function>lo_export</function>,<indexterm><primary>lo_export</></>
313- for large object access, which are available for use in
314- <acronym>SQL</acronym> commands. Here is an example of their
315- use:
311+ <para>
312+ There are server-side functions callable from SQL that correspond to
313+ each of the client-side functions described above; indeed, for the
314+ most part the client-side functions are simply interfaces to the
315+ equivalent server-side functions. The ones that are actually useful
316+ to call via SQL commands are
317+ <function>lo_creat</function><indexterm><primary>lo_creat</></>,
318+ <function>lo_unlink</function><indexterm><primary>lo_unlink</></>,
319+ <function>lo_import</function><indexterm><primary>lo_import</></>, and
320+ <function>lo_export</function><indexterm><primary>lo_export</></>.
321+ Here are examples of their use:
322+
316323<programlisting>
317324CREATE TABLE image (
318325 name text,
319326 raster oid
320327);
321328
329+ SELECT lo_creat(-1); -- returns OID of new, empty large object
330+
331+ SELECT lo_unlink(173454); -- deletes large object with OID 173454
332+
322333INSERT INTO image (name, raster)
323334 VALUES ('beautiful image', lo_import('/etc/motd'));
324335
325336SELECT lo_export(image.raster, '/tmp/motd') FROM image
326337 WHERE name = 'beautiful image';
327338</programlisting>
328- </para>
329-
330- <para>
331- These functions read and write files in the server's file system, using the
332- permissions of the database's owning user. Therefore, their use is restricted
333- to superusers. (In contrast, the client-side import and export functions
334- read and write files in the client's file system, using the permissions of
335- the client program. Their use is not restricted.)
336- </para>
339+ </para>
340+
341+ <para>
342+ The server-side <function>lo_import</function> and
343+ <function>lo_export</function> functions behave considerably differently
344+ from their client-side analogs. These two functions read and write files
345+ in the server's file system, using the permissions of the database's
346+ owning user. Therefore, their use is restricted to superusers. In
347+ contrast, the client-side import and export functions read and write files
348+ in the client's file system, using the permissions of the client program.
349+ The client-side functions can be used by any
350+ <productname>PostgreSQL</productname> user.
351+ </para>
337352</sect1>
338353
339354<sect1 id="lo-examplesect">