1
1
<!--
2
- $PostgreSQL: pgsql/doc/src/sgml/lobj.sgml,v 1.36 2005/01/10 00:04:38 tgl Exp $
2
+ $PostgreSQL: pgsql/doc/src/sgml/lobj.sgml,v 1.37 2005/06/13 02:26:46 tgl Exp $
3
3
-->
4
4
5
5
<chapter id="largeObjects">
@@ -115,26 +115,52 @@ $PostgreSQL: pgsql/doc/src/sgml/lobj.sgml,v 1.36 2005/01/10 00:04:38 tgl Exp $
115
115
Oid lo_creat(PGconn *conn, int mode);
116
116
</synopsis>
117
117
<indexterm><primary>lo_creat</></>
118
- creates a new large object.
119
- <replaceable class="parameter">mode</replaceable> is a bit mask
120
- describing several different attributes of the new
121
- object. The symbolic constants used here are defined
122
- in the header file <filename>libpq/libpq-fs.h</filename>.
123
- The access type (read, write, or both) is controlled by
124
- or'ing together the bits <symbol>INV_READ</symbol> and
125
- <symbol>INV_WRITE</symbol>. The low-order sixteen bits of the mask have
126
- historically been used at Berkeley to designate the storage manager number on which the large object
127
- should reside. These bits should always be zero now. (The access type
128
- does not actually do anything anymore either, but one or both flag bits
129
- must be set to avoid an error.)
118
+ creates a new large object.
130
119
The return value is the OID that was assigned to the new large object,
131
120
or InvalidOid (zero) on failure.
121
+
122
+ <replaceable class="parameter">mode</replaceable> is unused and
123
+ ignored as of <productname>PostgreSQL</productname> 8.1; however, for
124
+ backwards compatibility with earlier releases it is best to
125
+ set it to <symbol>INV_READ</symbol>, <symbol>INV_WRITE</symbol>,
126
+ or <symbol>INV_READ</symbol> <literal>|</> <symbol>INV_WRITE</symbol>.
127
+ (These symbolic constants are defined
128
+ in the header file <filename>libpq/libpq-fs.h</filename>.)
132
129
</para>
133
130
134
131
<para>
135
132
An example:
136
133
<programlisting>
137
134
inv_oid = lo_creat(conn, INV_READ|INV_WRITE);
135
+ </programlisting>
136
+ </para>
137
+
138
+ <para>
139
+ The function
140
+ <synopsis>
141
+ Oid lo_create(PGconn *conn, Oid lobjId);
142
+ </synopsis>
143
+ <indexterm><primary>lo_create</></>
144
+ also creates a new large object. The OID to be assigned can be
145
+ specified by <replaceable class="parameter">lobjId</replaceable>;
146
+ if so, failure occurs if that OID is already in use for some large
147
+ object. If <replaceable class="parameter">lobjId</replaceable>
148
+ is InvalidOid (zero) then <function>lo_create</> assigns an unused
149
+ OID (this is the same behavior as <function>lo_creat</>).
150
+ The return value is the OID that was assigned to the new large object,
151
+ or InvalidOid (zero) on failure.
152
+ </para>
153
+
154
+ <para>
155
+ <function>lo_create</> is new as of <productname>PostgreSQL</productname>
156
+ 8.1; if this function is run against an older server version, it will
157
+ fail and return InvalidOid.
158
+ </para>
159
+
160
+ <para>
161
+ An example:
162
+ <programlisting>
163
+ inv_oid = lo_create(conn, desired_oid);
138
164
</programlisting>
139
165
</para>
140
166
</sect2>
@@ -186,19 +212,45 @@ int lo_export(PGconn *conn, Oid lobjId, const char *filename);
186
212
int lo_open(PGconn *conn, Oid lobjId, int mode);
187
213
</synopsis>
188
214
<indexterm><primary>lo_open</></>
189
- The <parameter>lobjId</parameter> argument specifies the OID of the large
190
- object to open. The <parameter>mode</parameter> bits control whether the
191
- object is opened for reading (<symbol>INV_READ</>), writing (<symbol>INV_WRITE</symbol>), or
192
- both.
193
- A large object cannot be opened before it is created.
215
+ The <parameter>lobjId</parameter> argument specifies the OID of the large
216
+ object to open. The <parameter>mode</parameter> bits control whether the
217
+ object is opened for reading (<symbol>INV_READ</>), writing
218
+ (<symbol>INV_WRITE</symbol>), or both.
219
+ (These symbolic constants are defined
220
+ in the header file <filename>libpq/libpq-fs.h</filename>.)
221
+ A large object cannot be opened before it is created.
194
222
<function>lo_open</function> returns a (non-negative) large object
195
223
descriptor for later use in <function>lo_read</function>,
196
224
<function>lo_write</function>, <function>lo_lseek</function>,
197
225
<function>lo_tell</function>, and <function>lo_close</function>.
198
226
The descriptor is only valid for
199
227
the duration of the current transaction.
200
228
On failure, -1 is returned.
201
- </para>
229
+ </para>
230
+
231
+ <para>
232
+ The server currently does not distinguish between modes
233
+ <symbol>INV_WRITE</symbol> and <symbol>INV_READ</> <literal>|</>
234
+ <symbol>INV_WRITE</symbol>: you are allowed to read from the descriptor
235
+ in either case. However there is a significant difference between
236
+ these modes and <symbol>INV_READ</> alone: with <symbol>INV_READ</>
237
+ you cannot write on the descriptor, and the data read from it will
238
+ reflect the contents of the large object at the time of the transaction
239
+ snapshot that was active when <function>lo_open</> was executed,
240
+ regardless of later writes by this or other transactions. Reading
241
+ from a descriptor opened with <symbol>INV_WRITE</symbol> returns
242
+ data that reflects all writes of other committed transactions as well
243
+ as writes of the current transaction. This is similar to the behavior
244
+ of <literal>SERIALIZABLE</> versus <literal>READ COMMITTED</> transaction
245
+ modes for ordinary SQL <command>SELECT</> commands.
246
+ </para>
247
+
248
+ <para>
249
+ An example:
250
+ <programlisting>
251
+ inv_fd = lo_open(conn, inv_oid, INV_READ|INV_WRITE);
252
+ </programlisting>
253
+ </para>
202
254
</sect2>
203
255
204
256
<sect2>
@@ -317,6 +369,7 @@ int lo_unlink(PGconn *conn, Oid lobjId);
317
369
equivalent server-side functions. The ones that are actually useful
318
370
to call via SQL commands are
319
371
<function>lo_creat</function><indexterm><primary>lo_creat</></>,
372
+ <function>lo_create</function><indexterm><primary>lo_create</></>,
320
373
<function>lo_unlink</function><indexterm><primary>lo_unlink</></>,
321
374
<function>lo_import</function><indexterm><primary>lo_import</></>, and
322
375
<function>lo_export</function><indexterm><primary>lo_export</></>.
@@ -330,6 +383,8 @@ CREATE TABLE image (
330
383
331
384
SELECT lo_creat(-1); -- returns OID of new, empty large object
332
385
386
+ SELECT lo_create(43213); -- attempts to create large object with OID 43213
387
+
333
388
SELECT lo_unlink(173454); -- deletes large object with OID 173454
334
389
335
390
INSERT INTO image (name, raster)
0 commit comments