Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit325c0a3

Browse files
committed
Add server side lo_import(filename, oid) function.
1 parentbc49703 commit325c0a3

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
staticintnewLOfd(LargeObjectDesc*lobjCookie);
8181
staticvoiddeleteLOfd(intfd);
82+
staticOidlo_import_internal(text*filename,OidlobjOid);
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+
Oidoid=PG_GETARG_OID(1);
337+
338+
PG_RETURN_OID(lo_import_internal(filename,oid));
339+
}
340+
341+
staticOid
342+
lo_import_internal(text*filename,OidlobjOid)
343+
{
323344
Filefd;
324345
intnbytes,
325346
tmp;
326347
charbuf[BUFSIZE];
327348
charfnamebuf[MAXPGPATH];
328349
LargeObjectDesc*lobj;
329-
OidlobjOid;
330-
350+
Oidoid;
351+
331352
#ifndefALLOW_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+
returnoid;
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-
#defineCATALOG_VERSION_NO200803101
56+
#defineCATALOG_VERSION_NO200803221
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(insertOID=764 (lo_importPGNSPPGUID1210fftfv126"25"_null__null__null_lo_import-_null__null_ ));
10291029
DESCR("large object import");
1030+
DATA(insertOID=767 (lo_importPGNSPPGUID1210fftfv226"25 26"_null__null__null_lo_import_with_oid-_null__null_ ));
1031+
DESCR("large object import");
10301032
DATA(insertOID=765 (lo_exportPGNSPPGUID1210fftfv223"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
externDatumlo_import(PG_FUNCTION_ARGS);
23+
externDatumlo_import_with_oid(PG_FUNCTION_ARGS);
2324
externDatumlo_export(PG_FUNCTION_ARGS);
2425

2526
externDatumlo_creat(PG_FUNCTION_ARGS);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp