Skip to content

Commit 8436f9a

Browse files
committed
Add libpq new API lo_import_with_oid() which is similar to lo_import()
except that lob's oid can be specified.
1 parent f755f2f commit 8436f9a

File tree

4 files changed

+57
-6
lines changed

4 files changed

+57
-6
lines changed

doc/src/sgml/lobj.sgml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/lobj.sgml,v 1.46 2007/03/14 00:15:26 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/lobj.sgml,v 1.47 2008/03/19 00:39:33 ishii Exp $ -->
22

33
<chapter id="largeObjects">
44
<title id="largeObjects-title">Large Objects</title>
@@ -161,6 +161,28 @@ Oid lo_import(PGconn *conn, const char *filename);
161161
the server; so it must exist in the client file system and be readable
162162
by the client application.
163163
</para>
164+
165+
<para>
166+
The function
167+
<synopsis>
168+
Oid lo_import_with_oid(PGconn *conn, const char *filename, Oid lobjId);
169+
</synopsis>
170+
<indexterm><primary>lo_import_with_oid</></>
171+
also imports a new large object. The OID to be assigned can be
172+
specified by <replaceable class="parameter">lobjId</replaceable>;
173+
if so, failure occurs if that OID is already in use for some large
174+
object. If <replaceable class="parameter">lobjId</replaceable>
175+
is <symbol>InvalidOid</symbol> (zero) then <function>lo_import_with_oid</> assigns an unused
176+
OID (this is the same behavior as <function>lo_import</>).
177+
The return value is the OID that was assigned to the new large object,
178+
or <symbol>InvalidOid</symbol> (zero) on failure.
179+
</para>
180+
181+
<para>
182+
<function>lo_import_with_oid</> is new as of <productname>PostgreSQL</productname>
183+
8.4 and uses <function>lo_create</function> internally which is new in 8.1; if this function is run against 8.0 or before, it will
184+
fail and return <symbol>InvalidOid</symbol>.
185+
</para>
164186
</sect2>
165187

166188
<sect2>

src/interfaces/libpq/exports.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $PostgreSQL: pgsql/src/interfaces/libpq/exports.txt,v 1.18 2007/12/09 19:01:40 tgl Exp $
1+
# $PostgreSQL: pgsql/src/interfaces/libpq/exports.txt,v 1.19 2008/03/19 00:39:33 ishii Exp $
22
# Functions to be exported by libpq DLLs
33
PQconnectdb 1
44
PQsetdbLogin 2
@@ -140,3 +140,4 @@ lo_truncate 137
140140
PQconnectionUsedPassword 138
141141
pg_valid_server_encoding_id 139
142142
PQconnectionNeedsPassword 140
143+
lo_import_with_oid 141

src/interfaces/libpq/fe-lobj.c

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-lobj.c,v 1.64 2008/01/01 19:46:00 momjian Exp $
11+
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-lobj.c,v 1.65 2008/03/19 00:39:33 ishii Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -41,6 +41,8 @@
4141

4242
static int lo_initialize(PGconn *conn);
4343

44+
static Oid
45+
lo_import_internal(PGconn *conn, const char *filename, const Oid oid);
4446

4547
/*
4648
* lo_open
@@ -483,6 +485,27 @@ lo_unlink(PGconn *conn, Oid lobjId)
483485

484486
Oid
485487
lo_import(PGconn *conn, const char *filename)
488+
{
489+
return lo_import_internal(conn, filename, InvalidOid);
490+
}
491+
492+
/*
493+
* lo_import_with_oid -
494+
* imports a file as an (inversion) large object.
495+
* large object id can be specified.
496+
*
497+
* returns the oid of that object upon success,
498+
* returns InvalidOid upon failure
499+
*/
500+
501+
Oid
502+
lo_import_with_oid(PGconn *conn, const char *filename, Oid lobjId)
503+
{
504+
return lo_import_internal(conn, filename, lobjId);
505+
}
506+
507+
static Oid
508+
lo_import_internal(PGconn *conn, const char *filename, Oid oid)
486509
{
487510
int fd;
488511
int nbytes,
@@ -507,10 +530,14 @@ lo_import(PGconn *conn, const char *filename)
507530
/*
508531
* create an inversion object
509532
*/
510-
lobjOid = lo_creat(conn, INV_READ | INV_WRITE);
533+
if (oid == InvalidOid)
534+
lobjOid = lo_creat(conn, INV_READ | INV_WRITE);
535+
else
536+
lobjOid = lo_create(conn, oid);
537+
511538
if (lobjOid == InvalidOid)
512539
{
513-
/* we assume lo_creat() already set a suitable error message */
540+
/* we assume lo_create() already set a suitable error message */
514541
(void) close(fd);
515542
return InvalidOid;
516543
}

src/interfaces/libpq/libpq-fe.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/interfaces/libpq/libpq-fe.h,v 1.141 2008/01/01 19:46:00 momjian Exp $
10+
* $PostgreSQL: pgsql/src/interfaces/libpq/libpq-fe.h,v 1.142 2008/03/19 00:39:33 ishii Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -495,6 +495,7 @@ extern int lo_tell(PGconn *conn, int fd);
495495
extern int lo_truncate(PGconn *conn, int fd, size_t len);
496496
extern int lo_unlink(PGconn *conn, Oid lobjId);
497497
extern Oid lo_import(PGconn *conn, const char *filename);
498+
extern Oid lo_import_with_oid(PGconn *conn, const char *filename, Oid lobjId);
498499
extern int lo_export(PGconn *conn, Oid lobjId, const char *filename);
499500

500501
/* === in fe-misc.c === */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy