diff options
author | Tatsuo Ishii | 2008-03-22 01:55:14 +0000 |
---|---|---|
committer | Tatsuo Ishii | 2008-03-22 01:55:14 +0000 |
commit | 0e57f9aca82879229c03b845fbe236543ccfc9cd (patch) | |
tree | a23a0c8f4820a663d0a34a0f48575105d4b4a62a | |
parent | e8703a59be19fd1befcbe8a0213da9ec3d930d1b (diff) |
Add server side lo_import(filename, oid) function.
-rw-r--r-- | doc/src/sgml/lobj.sgml | 3 | ||||
-rw-r--r-- | src/backend/libpq/be-fsstubs.c | 31 | ||||
-rw-r--r-- | src/include/catalog/catversion.h | 2 | ||||
-rw-r--r-- | src/include/catalog/pg_proc.h | 2 | ||||
-rw-r--r-- | src/include/libpq/be-fsstubs.h | 1 |
5 files changed, 33 insertions, 6 deletions
diff --git a/doc/src/sgml/lobj.sgml b/doc/src/sgml/lobj.sgml index 68cb257c7e..f97a52feb3 100644 --- a/doc/src/sgml/lobj.sgml +++ b/doc/src/sgml/lobj.sgml @@ -422,6 +422,9 @@ SELECT lo_unlink(173454); -- deletes large object with OID 173454 INSERT INTO image (name, raster) VALUES ('beautiful image', lo_import('/etc/motd')); +INSERT INTO image (name, raster) -- same as above, but specify OID to use + VALUES ('beautiful image', lo_import('/etc/motd', 68583)); + SELECT lo_export(image.raster, '/tmp/motd') FROM image WHERE name = 'beautiful image'; </programlisting> diff --git a/src/backend/libpq/be-fsstubs.c b/src/backend/libpq/be-fsstubs.c index a08b85d590..a44c2ca626 100644 --- a/src/backend/libpq/be-fsstubs.c +++ b/src/backend/libpq/be-fsstubs.c @@ -79,6 +79,7 @@ static MemoryContext fscxt = NULL; static int newLOfd(LargeObjectDesc *lobjCookie); static void deleteLOfd(int fd); +static Oid lo_import_internal(text *filename, Oid lobjOid); /***************************************************************************** @@ -320,14 +321,34 @@ Datum 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 lobjOid; - + Oid oid; + #ifndef ALLOW_DANGEROUS_LO_FUNCTIONS if (!superuser()) ereport(ERROR, @@ -356,12 +377,12 @@ lo_import(PG_FUNCTION_ARGS) /* * create an inversion object */ - lobjOid = inv_create(InvalidOid); + oid = inv_create(lobjOid); /* * read in from the filesystem and write to the inversion object */ - lobj = inv_open(lobjOid, INV_WRITE, fscxt); + lobj = inv_open(oid, INV_WRITE, fscxt); while ((nbytes = FileRead(fd, buf, BUFSIZE)) > 0) { @@ -378,7 +399,7 @@ lo_import(PG_FUNCTION_ARGS) inv_close(lobj); FileClose(fd); - PG_RETURN_OID(lobjOid); + return oid; } /* diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h index 8a6517f17a..052e9244de 100644 --- a/src/include/catalog/catversion.h +++ b/src/include/catalog/catversion.h @@ -53,6 +53,6 @@ */ /* yyyymmddN */ -#define CATALOG_VERSION_NO 200803101 +#define CATALOG_VERSION_NO 200803221 #endif diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h index f883430441..8063f7c6c6 100644 --- a/src/include/catalog/pg_proc.h +++ b/src/include/catalog/pg_proc.h @@ -1027,6 +1027,8 @@ DESCR("storage manager"); 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"); diff --git a/src/include/libpq/be-fsstubs.h b/src/include/libpq/be-fsstubs.h index 5b7c225bfe..fc0fd1e95a 100644 --- a/src/include/libpq/be-fsstubs.h +++ b/src/include/libpq/be-fsstubs.h @@ -20,6 +20,7 @@ * 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); |