1
1
<!--
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 $
3
3
-->
4
4
5
5
<chapter id="largeObjects">
@@ -122,15 +122,17 @@ Oid lo_creat(PGconn *conn, int mode);
122
122
or'ing together the bits <symbol>INV_READ</symbol> and
123
123
<symbol>INV_WRITE</symbol>. The low-order sixteen bits of the mask have
124
124
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.
128
130
</para>
129
131
130
132
<para>
131
133
An example:
132
134
<programlisting>
133
- inv_oid = lo_creat(INV_READ|INV_WRITE);
135
+ inv_oid = lo_creat(conn, INV_READ|INV_WRITE);
134
136
</programlisting>
135
137
</para>
136
138
</sect2>
@@ -147,7 +149,8 @@ Oid lo_import(PGconn *conn, const char *filename);
147
149
<replaceable class="parameter">filename</replaceable>
148
150
specifies the operating system name of
149
151
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.
151
154
Note that the file is read by the client interface library, not by
152
155
the server; so it must exist in the client filesystem and be readable
153
156
by the client application.
@@ -164,19 +167,19 @@ Oid lo_import(PGconn *conn, const char *filename);
164
167
int lo_export(PGconn *conn, Oid lobjId, const char *filename);
165
168
</synopsis>
166
169
<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 .
172
175
</para>
173
176
</sect2>
174
177
175
178
<sect2>
176
179
<title>Opening an Existing Large Object</title>
177
180
178
181
<para>
179
- To open an existing large object, call
182
+ To open an existing large object for reading or writing , call
180
183
<synopsis>
181
184
int lo_open(PGconn *conn, Oid lobjId, int mode);
182
185
</synopsis>
@@ -186,11 +189,13 @@ int lo_open(PGconn *conn, Oid lobjId, int mode);
186
189
object is opened for reading (<symbol>INV_READ</>), writing (<symbol>INV_WRITE</symbol>), or
187
190
both.
188
191
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
193
197
the duration of the current transaction.
198
+ On failure, -1 is returned.
194
199
</para>
195
200
</sect2>
196
201
@@ -246,7 +251,7 @@ int lo_lseek(PGconn *conn, int fd, int offset, int whence);
246
251
are <symbol>SEEK_SET</> (seek from object start),
247
252
<symbol>SEEK_CUR</> (seek from current position), and
248
253
<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 .
250
255
</para>
251
256
</sect2>
252
257
@@ -294,46 +299,56 @@ int lo_unlink(PGconn *conn, Oid lobjId);
294
299
</synopsis>
295
300
<indexterm><primary>lo_unlink</></> The
296
301
<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.
299
303
</para>
300
304
</sect2>
301
305
302
-
303
306
</sect1>
304
307
305
308
<sect1 id="lo-funcs">
306
309
<title>Server-Side Functions</title>
307
310
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
+
316
323
<programlisting>
317
324
CREATE TABLE image (
318
325
name text,
319
326
raster oid
320
327
);
321
328
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
+
322
333
INSERT INTO image (name, raster)
323
334
VALUES ('beautiful image', lo_import('/etc/motd'));
324
335
325
336
SELECT lo_export(image.raster, '/tmp/motd') FROM image
326
337
WHERE name = 'beautiful image';
327
338
</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>
337
352
</sect1>
338
353
339
354
<sect1 id="lo-examplesect">
0 commit comments