Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 325c0a3

Browse files
committed
Add server side lo_import(filename, oid) function.
1 parent bc49703 commit 325c0a3

File tree

5 files changed

+38
-11
lines changed

5 files changed

+38
-11
lines changed

doc/src/sgml/lobj.sgml

Lines changed: 4 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.47 2008/03/19 00:39:33 ishii Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/lobj.sgml,v 1.48 2008/03/22 01:55:14 ishii Exp $ -->
22

33
<chapter id="largeObjects">
44
<title id="largeObjects-title">Large Objects</title>
@@ -422,6 +422,9 @@ SELECT lo_unlink(173454); -- deletes large object with OID 173454
422422
INSERT INTO image (name, raster)
423423
VALUES ('beautiful image', lo_import('/etc/motd'));
424424

425+
INSERT INTO image (name, raster) -- same as above, but specify OID to use
426+
VALUES ('beautiful image', lo_import('/etc/motd', 68583));
427+
425428
SELECT lo_export(image.raster, '/tmp/motd') FROM image
426429
WHERE name = 'beautiful image';
427430
</programlisting>

src/backend/libpq/be-fsstubs.c

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/libpq/be-fsstubs.c,v 1.87 2008/01/01 19:45:49 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/libpq/be-fsstubs.c,v 1.88 2008/03/22 01:55:14 ishii Exp $
1212
*
1313
* NOTES
1414
* This should be moved to a more appropriate place. It is here
@@ -79,6 +79,7 @@ static MemoryContext fscxt = NULL;
7979

8080
static int newLOfd(LargeObjectDesc *lobjCookie);
8181
static void deleteLOfd(int fd);
82+
static Oid lo_import_internal(text *filename, Oid lobjOid);
8283

8384

8485
/*****************************************************************************
@@ -320,14 +321,34 @@ Datum
320321
lo_import(PG_FUNCTION_ARGS)
321322
{
322323
text *filename = PG_GETARG_TEXT_P(0);
324+
325+
PG_RETURN_OID(lo_import_internal(filename, InvalidOid));
326+
}
327+
328+
/*
329+
* lo_import_with_oid -
330+
* imports a file as an (inversion) large object specifying oid.
331+
*/
332+
Datum
333+
lo_import_with_oid(PG_FUNCTION_ARGS)
334+
{
335+
text *filename = PG_GETARG_TEXT_P(0);
336+
Oid oid = PG_GETARG_OID(1);
337+
338+
PG_RETURN_OID(lo_import_internal(filename, oid));
339+
}
340+
341+
static Oid
342+
lo_import_internal(text *filename, Oid lobjOid)
343+
{
323344
File fd;
324345
int nbytes,
325346
tmp;
326347
char buf[BUFSIZE];
327348
char fnamebuf[MAXPGPATH];
328349
LargeObjectDesc *lobj;
329-
Oid lobjOid;
330-
350+
Oid oid;
351+
331352
#ifndef ALLOW_DANGEROUS_LO_FUNCTIONS
332353
if (!superuser())
333354
ereport(ERROR,
@@ -356,12 +377,12 @@ lo_import(PG_FUNCTION_ARGS)
356377
/*
357378
* create an inversion object
358379
*/
359-
lobjOid = inv_create(InvalidOid);
380+
oid = inv_create(lobjOid);
360381

361382
/*
362383
* read in from the filesystem and write to the inversion object
363384
*/
364-
lobj = inv_open(lobjOid, INV_WRITE, fscxt);
385+
lobj = inv_open(oid, INV_WRITE, fscxt);
365386

366387
while ((nbytes = FileRead(fd, buf, BUFSIZE)) > 0)
367388
{
@@ -378,7 +399,7 @@ lo_import(PG_FUNCTION_ARGS)
378399
inv_close(lobj);
379400
FileClose(fd);
380401

381-
PG_RETURN_OID(lobjOid);
402+
return oid;
382403
}
383404

384405
/*

src/include/catalog/catversion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
40-
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.442 2008/03/10 13:53:35 mha Exp $
40+
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.443 2008/03/22 01:55:14 ishii Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 200803101
56+
#define CATALOG_VERSION_NO 200803221
5757

5858
#endif

src/include/catalog/pg_proc.h

Lines changed: 3 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/include/catalog/pg_proc.h,v 1.482 2008/01/01 19:45:57 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.483 2008/03/22 01:55:14 ishii Exp $
1111
*
1212
* NOTES
1313
* The script catalog/genbki.sh reads this file and generates .bki
@@ -1027,6 +1027,8 @@ DESCR("storage manager");
10271027

10281028
DATA(insert OID = 764 ( lo_import PGNSP PGUID 12 1 0 f f t f v 1 26 "25" _null_ _null_ _null_ lo_import - _null_ _null_ ));
10291029
DESCR("large object import");
1030+
DATA(insert OID = 767 ( lo_import PGNSP PGUID 12 1 0 f f t f v 2 26 "25 26" _null_ _null_ _null_ lo_import_with_oid - _null_ _null_ ));
1031+
DESCR("large object import");
10301032
DATA(insert OID = 765 ( lo_export PGNSP PGUID 12 1 0 f f t f v 2 23 "26 25" _null_ _null_ _null_ lo_export - _null_ _null_ ));
10311033
DESCR("large object export");
10321034

src/include/libpq/be-fsstubs.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/include/libpq/be-fsstubs.h,v 1.30 2008/01/01 19:45:58 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/libpq/be-fsstubs.h,v 1.31 2008/03/22 01:55:14 ishii Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -20,6 +20,7 @@
2020
* LO functions available via pg_proc entries
2121
*/
2222
extern Datum lo_import(PG_FUNCTION_ARGS);
23+
extern Datum lo_import_with_oid(PG_FUNCTION_ARGS);
2324
extern Datum lo_export(PG_FUNCTION_ARGS);
2425

2526
extern Datum lo_creat(PG_FUNCTION_ARGS);

0 commit comments

Comments
 (0)