Re: [HACKERS] Proposal: new large object API

Поиск
Список
Период
Сортировка
Искать

Re: [HACKERS] Proposal: new large object API

От:
Tatsuo Ishii <ishii@postgresql.org>
Дата:
Here is the proposed patches. If there's no objection, I will
commit(or Shall I wait for next "commit festa"?).

Note that I decide to use lo_import_with_oid, but the signature is
changed(the second and the third arguments are swapped because it
seems more natural).
--
Tatsuo Ishii
SRA OSS, Inc. Japan

> I would like to propose new large object client side API for 8.4.
> 
> Currently we have:
> 
> 	  Oid lo_import(PGconn *conn, const char *filename);
> 
> But we do not have an API which imports a large object specifying the
> object id. This is inconvenient and inconsistent since we already have
> lo_create() and lo_open() which allow to specify the large object id.
> 
> So I propose to add new API:
> 
> 	  int lo_import_with_oid(PGconn *conn, Oid lobjId, const char *filename);
> 
> Another idea is changing the signature of lo_import:
> 
> 	  Oid lo_import(PGconn *conn, Oid lobjId, const char *filename);
> 
> which will be cleaner but break the backward compatibility.
> 
> Comments are welcome.
> --
> Tatsuo Ishii
> SRA OSS, Inc. Japan
> 
> -- 
> Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
? src/interfaces/libpq/exports.list
? src/interfaces/libpq/libpq.so.5.2
Index: doc/src/sgml/lobj.sgml
===================================================================
RCS file: /cvsroot/pgsql/doc/src/sgml/lobj.sgml,v
retrieving revision 1.46
diff -c -r1.46 lobj.sgml
*** doc/src/sgml/lobj.sgml	14 Mar 2007 00:15:26 -0000	1.46
--- doc/src/sgml/lobj.sgml	18 Mar 2008 01:02:10 -0000
***************
*** 161,166 ****
--- 161,188 ----
       the server; so it must exist in the client file system and be readable
       by the client application.
      
+ 
+     
+      The function
+ 
+ Oid lo_import_with_oid(PGconn *conn, const char *filename, Oid lobjId);
+ 
+      lo_import_with_oid</></>
+      also imports a new large object.  The OID to be assigned can be
+      specified by lobjId;
+      if so, failure occurs if that OID is already in use for some large
+      object.  If lobjId
+      is InvalidOid (zero) then lo_import_with_oid</> assigns an unused
+      OID (this is the same behavior as lo_import</>).
+      The return value is the OID that was assigned to the new large object,
+      or InvalidOid (zero) on failure.
+     
+ 
+     
+      lo_import_with_oid</> is new as of PostgreSQL
+      8.4 and uses lo_create internally which is new in 8.1; if this function is run against 8.0 or before, it will
+      fail and return InvalidOid.
+     
     
  
     
Index: src/interfaces/libpq/exports.txt
===================================================================
RCS file: /cvsroot/pgsql/src/interfaces/libpq/exports.txt,v
retrieving revision 1.18
diff -c -r1.18 exports.txt
*** src/interfaces/libpq/exports.txt	9 Dec 2007 19:01:40 -0000	1.18
--- src/interfaces/libpq/exports.txt	18 Mar 2008 01:02:10 -0000
***************
*** 140,142 ****
--- 140,143 ----
  PQconnectionUsedPassword  138
  pg_valid_server_encoding_id 139
  PQconnectionNeedsPassword 140
+ lo_import_with_oid		  141
Index: src/interfaces/libpq/fe-lobj.c
===================================================================
RCS file: /cvsroot/pgsql/src/interfaces/libpq/fe-lobj.c,v
retrieving revision 1.64
diff -c -r1.64 fe-lobj.c
*** src/interfaces/libpq/fe-lobj.c	1 Jan 2008 19:46:00 -0000	1.64
--- src/interfaces/libpq/fe-lobj.c	18 Mar 2008 01:02:11 -0000
***************
*** 41,46 ****
--- 41,48 ----
  
  static int	lo_initialize(PGconn *conn);
  
+ static Oid
+ lo_import_internal(PGconn *conn, const char *filename, const Oid oid);
  
  /*
   * lo_open
***************
*** 484,489 ****
--- 486,512 ----
  Oid
  lo_import(PGconn *conn, const char *filename)
  {
+ 	return lo_import_internal(conn, filename, InvalidOid);
+ }
+ 
+ /*
+  * lo_import_with_oid -
+  *	  imports a file as an (inversion) large object.
+  *	  large object id can be specified.
+  *
+  * returns the oid of that object upon success,
+  * returns InvalidOid upon failure
+  */
+ 
+ Oid
+ lo_import_with_oid(PGconn *conn, const char *filename, Oid lobjId)
+ {
+ 	return lo_import_internal(conn, filename, lobjId);
+ }
+ 
+ static Oid
+ lo_import_internal(PGconn *conn, const char *filename, Oid oid)
+ {
  	int			fd;
  	int			nbytes,
  				tmp;
***************
*** 507,516 ****
  	/*
  	 * create an inversion object
  	 */
! 	lobjOid = lo_creat(conn, INV_READ | INV_WRITE);
  	if (lobjOid == InvalidOid)
  	{
! 		/* we assume lo_creat() already set a suitable error message */
  		(void) close(fd);
  		return InvalidOid;
  	}
--- 530,543 ----
  	/*
  	 * create an inversion object
  	 */
! 	if (oid == InvalidOid)
! 		lobjOid = lo_creat(conn, INV_READ | INV_WRITE);
! 	else
! 		lobjOid = lo_create(conn, oid);
! 
  	if (lobjOid == InvalidOid)
  	{
! 		/* we assume lo_create() already set a suitable error message */
  		(void) close(fd);
  		return InvalidOid;
  	}
Index: src/interfaces/libpq/libpq-fe.h
===================================================================
RCS file: /cvsroot/pgsql/src/interfaces/libpq/libpq-fe.h,v
retrieving revision 1.141
diff -c -r1.141 libpq-fe.h
*** src/interfaces/libpq/libpq-fe.h	1 Jan 2008 19:46:00 -0000	1.141
--- src/interfaces/libpq/libpq-fe.h	18 Mar 2008 01:02:12 -0000
***************
*** 495,500 ****
--- 495,501 ----
  extern int	lo_truncate(PGconn *conn, int fd, size_t len);
  extern int	lo_unlink(PGconn *conn, Oid lobjId);
  extern Oid	lo_import(PGconn *conn, const char *filename);
+ extern Oid	lo_import_with_oid(PGconn *conn, const char *filename, Oid lobjId);
  extern int	lo_export(PGconn *conn, Oid lobjId, const char *filename);
  
  /* === in fe-misc.c === */

Re: [HACKERS] Proposal: new large object API

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Tatsuo Ishii  writes:
> Here is the proposed patches. If there's no objection, I will
> commit(or Shall I wait for next "commit festa"?).

No need to wait IMHO.

			regards, tom lane
FAQ