On Wed, 28 Feb 2007, Bruce Momjian wrote:
Your patch has been added to the PostgreSQL unapplied patches list at:
http://momjian.postgresql.org/cgi-bin/pgpatches
It will be applied as soon as one of the PostgreSQL committers reviews
and approves it.
Here's a patch that works with the new varlena API.
Kris JurkaIndex: doc/src/sgml/lobj.sgml
===
RCS file: /projects/cvsroot/pgsql/doc/src/sgml/lobj.sgml,v
retrieving revision 1.44
diff -c -r1.44 lobj.sgml
*** doc/src/sgml/lobj.sgml 1 Feb 2007 19:10:24 - 1.44
--- doc/src/sgml/lobj.sgml 1 Mar 2007 03:57:20 -
***
*** 302,307
--- 302,338
/sect2
sect2
+ titleTruncating a Large Object/title
+
+ para
+ To truncate a large object to a given length, call
+ synopsis
+ int lo_truncate(PGcon *conn, int fd, size_t len);
+ /synopsis
+ indextermprimarylo_truncate// truncates the large object
+ descriptor parameterfd/ to length parameterlen/. The
+ parameterfd/parameter argument must have been returned by a
+ previous functionlo_open/function. If parameterlen/ is
+ greater than the current large object length, the large object
+ is extended with null bytes ('\0').
+ /para
+
+ para
+ The file offset is not changed.
+ /para
+
+ para
+ On success functionlo_truncate/function returns
+ zero. On error, the return value is negative.
+ /para
+
+ para
+ functionlo_truncate/ is new as of
productnamePostgreSQL/productname
+ 8.3; if this function is run against an older server version, it will
+ fail and return a negative value.
+ /para
+
+ sect2
titleClosing a Large Object Descriptor/title
para
Index: src/backend/libpq/be-fsstubs.c
===
RCS file: /projects/cvsroot/pgsql/src/backend/libpq/be-fsstubs.c,v
retrieving revision 1.85
diff -c -r1.85 be-fsstubs.c
*** src/backend/libpq/be-fsstubs.c 27 Feb 2007 23:48:07 - 1.85
--- src/backend/libpq/be-fsstubs.c 1 Mar 2007 03:57:20 -
***
*** 120,131
int32 fd = PG_GETARG_INT32(0);
if (fd 0 || fd = cookies_size || cookies[fd] == NULL)
- {
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg(invalid large-object descriptor: %d,
fd)));
! PG_RETURN_INT32(-1);
! }
#if FSDB
elog(DEBUG4, lo_close(%d), fd);
#endif
--- 120,129
int32 fd = PG_GETARG_INT32(0);
if (fd 0 || fd = cookies_size || cookies[fd] == NULL)
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg(invalid large-object descriptor: %d,
fd)));
!
#if FSDB
elog(DEBUG4, lo_close(%d), fd);
#endif
***
*** 152,163
int status;
if (fd 0 || fd = cookies_size || cookies[fd] == NULL)
- {
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg(invalid large-object descriptor: %d,
fd)));
- return -1;
- }
status = inv_read(cookies[fd], buf, len);
--- 150,158
***
*** 170,181
int status;
if (fd 0 || fd = cookies_size || cookies[fd] == NULL)
- {
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg(invalid large-object descriptor: %d,
fd)));
- return -1;
- }
if ((cookies[fd]-flags IFS_WRLOCK) == 0)
ereport(ERROR,
--- 165,173
***
*** 198,209
int status;
if (fd 0 || fd = cookies_size || cookies[fd] == NULL)
- {
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg(invalid large-object descriptor: %d,
fd)));
- PG_RETURN_INT32(-1);
- }
status = inv_seek(cookies[fd], offset, whence);
--- 190,198
***
*** 248,259
int32 fd = PG_GETARG_INT32(0);
if (fd 0 || fd = cookies_size || cookies[fd] == NULL)
- {
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg(invalid large-object descriptor: %d,
fd)));
- PG_RETURN_INT32(-1);
- }
PG_RETURN_INT32(inv_tell(cookies[fd]));
}
--- 237,245
***
*** 468,473
--- 454,479
}
/*
+ * lo_truncate -
+ * truncate a large object to a specified length
+ */
+ Datum
+ lo_truncate(PG_FUNCTION_ARGS)
+ {
+ int32