Re: Proposal: new large object API - Mailing list pgsql-hackers
| From | Tatsuo Ishii |
|---|---|
| Subject | Re: Proposal: new large object API |
| Date | |
| Msg-id | 20080321.233829.89140968.t-ishii@sraoss.co.jp Whole thread Raw |
| In response to | Re: Proposal: new large object API (Tom Lane <tgl@sss.pgh.pa.us>) |
| Responses |
Re: Proposal: new large object API
|
| List | pgsql-hackers |
> > What is evil with a polymorphic function?
>
> (1) It's creating a false match --- your proposed entry in the opr_sanity
> results has nothing at all to do with what the test is looking for.
>
> (2) Refactoring to have two separate C functions will make the code
> clearer, and not noticeably longer.
Ok, here is the revised patch.
--
Tatsuo Ishii
SRA OSS, Inc. Japan
Index: src/backend/libpq/be-fsstubs.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/libpq/be-fsstubs.c,v
retrieving revision 1.87
diff -c -r1.87 be-fsstubs.c
*** src/backend/libpq/be-fsstubs.c 1 Jan 2008 19:45:49 -0000 1.87
--- src/backend/libpq/be-fsstubs.c 21 Mar 2008 14:35:02 -0000
***************
*** 79,84 ****
--- 79,85 ---- static int newLOfd(LargeObjectDesc *lobjCookie); static void deleteLOfd(int fd);
+ static Oid lo_import_internal(text *filename, Oid lobjOid);
/*****************************************************************************
***************
*** 320,333 **** lo_import(PG_FUNCTION_ARGS) { text *filename = PG_GETARG_TEXT_P(0); File fd;
int nbytes, tmp; char buf[BUFSIZE]; char fnamebuf[MAXPGPATH];
LargeObjectDesc*lobj;
! Oid lobjOid;
! #ifndef ALLOW_DANGEROUS_LO_FUNCTIONS if (!superuser()) ereport(ERROR,
--- 321,354 ---- lo_import(PG_FUNCTION_ARGS) { text *filename = PG_GETARG_TEXT_P(0);
+
+ PG_RETURN_OID(lo_import_internal(filename, InvalidOid));
+ }
+
+ /*
+ * lo_import_with_oid -
+ * imports a file as an (inversion) large object specifying oid.
+ */
+ Datum
+ lo_import_with_oid(PG_FUNCTION_ARGS)
+ {
+ text *filename = PG_GETARG_TEXT_P(0);
+ Oid oid = PG_GETARG_OID(1);
+
+ PG_RETURN_OID(lo_import_internal(filename, oid));
+ }
+
+ static Oid
+ lo_import_internal(text *filename, Oid lobjOid)
+ { File fd; int nbytes, tmp; char buf[BUFSIZE]; char
fnamebuf[MAXPGPATH]; LargeObjectDesc *lobj;
! Oid oid;
! #ifndef ALLOW_DANGEROUS_LO_FUNCTIONS if (!superuser()) ereport(ERROR,
***************
*** 356,367 **** /* * create an inversion object */
! lobjOid = inv_create(InvalidOid); /* * read in from the filesystem and write to the inversion object
*/
! lobj = inv_open(lobjOid, INV_WRITE, fscxt); while ((nbytes = FileRead(fd, buf, BUFSIZE)) > 0) {
--- 377,388 ---- /* * create an inversion object */
! oid = inv_create(lobjOid); /* * read in from the filesystem and write to the inversion object */
! lobj = inv_open(oid, INV_WRITE, fscxt); while ((nbytes = FileRead(fd, buf, BUFSIZE)) > 0) {
***************
*** 378,384 **** inv_close(lobj); FileClose(fd);
! PG_RETURN_OID(lobjOid); } /*
--- 399,405 ---- inv_close(lobj); FileClose(fd);
! return oid; } /*
Index: src/include/catalog/pg_proc.h
===================================================================
RCS file: /cvsroot/pgsql/src/include/catalog/pg_proc.h,v
retrieving revision 1.482
diff -c -r1.482 pg_proc.h
*** src/include/catalog/pg_proc.h 1 Jan 2008 19:45:57 -0000 1.482
--- src/include/catalog/pg_proc.h 21 Mar 2008 14:35:07 -0000
***************
*** 1027,1032 ****
--- 1027,1034 ---- 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_ )); DESCR("large object import");
+ 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_ ));
+ DESCR("large object import"); 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_ )); DESCR("large object export");
Index: src/include/catalog/catversion.h
===================================================================
RCS file: /cvsroot/pgsql/src/include/catalog/catversion.h,v
retrieving revision 1.442
diff -c -r1.442 catversion.h
*** src/include/catalog/catversion.h 10 Mar 2008 13:53:35 -0000 1.442
--- src/include/catalog/catversion.h 21 Mar 2008 14:35:07 -0000
***************
*** 53,58 **** */ /* yyyymmddN */
! #define CATALOG_VERSION_NO 200803101 #endif
--- 53,58 ---- */ /* yyyymmddN */
! #define CATALOG_VERSION_NO 200803211 #endif
Index: src/include/libpq/be-fsstubs.h
===================================================================
RCS file: /cvsroot/pgsql/src/include/libpq/be-fsstubs.h,v
retrieving revision 1.30
diff -c -r1.30 be-fsstubs.h
*** src/include/libpq/be-fsstubs.h 1 Jan 2008 19:45:58 -0000 1.30
--- src/include/libpq/be-fsstubs.h 21 Mar 2008 14:35:07 -0000
***************
*** 20,25 ****
--- 20,26 ---- * LO functions available via pg_proc entries */ extern Datum lo_import(PG_FUNCTION_ARGS);
+ extern Datum lo_import_with_oid(PG_FUNCTION_ARGS); extern Datum lo_export(PG_FUNCTION_ARGS); extern Datum
lo_creat(PG_FUNCTION_ARGS);
Index: doc/src/sgml/lobj.sgml
===================================================================
RCS file: /cvsroot/pgsql/doc/src/sgml/lobj.sgml,v
retrieving revision 1.47
diff -c -r1.47 lobj.sgml
*** doc/src/sgml/lobj.sgml 19 Mar 2008 00:39:33 -0000 1.47
--- doc/src/sgml/lobj.sgml 21 Mar 2008 14:35:07 -0000
***************
*** 438,443 ****
--- 438,450 ---- The client-side functions can be used by any <productname>PostgreSQL</productname> user.
</para>
+
+ <para>
+ As of 8.4, a different form of the server-side
+ <function>lo_import</function> added, which accepts the large
+ object id as the second argument. The usage of this form is same as the client
+ side function <function>lo_import_with_oid</function>.
+ </para> </sect1> <sect1 id="lo-examplesect">
pgsql-hackers by date: