Commit ae526b40 authored by Tom Lane's avatar Tom Lane

Another round of updates for new fmgr, mostly in the datetime code.

parent 20ad43b5
/* /*
* PostgreSQL type definitions for managed LargeObjects. * PostgreSQL type definitions for managed LargeObjects.
* *
* $Id: lo.c,v 1.3 2000/05/29 01:59:02 tgl Exp $ * $Id: lo.c,v 1.4 2000/06/09 01:10:58 tgl Exp $
* *
*/ */
...@@ -76,7 +76,8 @@ lo_in(char *str) ...@@ -76,7 +76,8 @@ lo_in(char *str)
/* /*
* There is no Oid passed, so create a new one * There is no Oid passed, so create a new one
*/ */
oid = lo_creat(INV_READ | INV_WRITE); oid = DatumGetObjectId(DirectFunctionCall1(lo_creat,
Int32GetDatum(INV_READ | INV_WRITE)));
if (oid == InvalidOid) if (oid == InvalidOid)
{ {
elog(ERROR, "lo_in: InvalidOid returned from lo_creat"); elog(ERROR, "lo_in: InvalidOid returned from lo_creat");
...@@ -186,7 +187,8 @@ lo_manage(PG_FUNCTION_ARGS) ...@@ -186,7 +187,8 @@ lo_manage(PG_FUNCTION_ARGS)
char *newv = SPI_getvalue(newtuple, tupdesc, attnum); char *newv = SPI_getvalue(newtuple, tupdesc, attnum);
if ((orig != newv && (orig == NULL || newv == NULL)) || (orig != NULL && newv != NULL && strcmp(orig, newv))) if ((orig != newv && (orig == NULL || newv == NULL)) || (orig != NULL && newv != NULL && strcmp(orig, newv)))
lo_unlink(atoi(orig)); DirectFunctionCall1(lo_unlink,
ObjectIdGetDatum((Oid) atoi(orig)));
if (newv) if (newv)
pfree(newv); pfree(newv);
...@@ -206,7 +208,8 @@ lo_manage(PG_FUNCTION_ARGS) ...@@ -206,7 +208,8 @@ lo_manage(PG_FUNCTION_ARGS)
if (orig != NULL) if (orig != NULL)
{ {
lo_unlink(atoi(orig)); DirectFunctionCall1(lo_unlink,
ObjectIdGetDatum((Oid) atoi(orig)));
pfree(orig); pfree(orig);
} }
......
...@@ -62,7 +62,8 @@ moddatetime(PG_FUNCTION_ARGS) ...@@ -62,7 +62,8 @@ moddatetime(PG_FUNCTION_ARGS)
tupdesc = rel->rd_att; tupdesc = rel->rd_att;
/* Get the current datetime. */ /* Get the current datetime. */
newdt = (Datum) timestamp_in("now"); newdt = DirectFunctionCall1(timestamp_in,
CStringGetDatum("now"));
/* /*
* This gets the position in the turple of the field we want. args[0] * This gets the position in the turple of the field we want. args[0]
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtcompare.c,v 1.35 2000/06/05 07:28:36 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtcompare.c,v 1.36 2000/06/09 01:11:01 tgl Exp $
* *
* NOTES * NOTES
* *
...@@ -170,9 +170,12 @@ btoidvectorcmp(PG_FUNCTION_ARGS) ...@@ -170,9 +170,12 @@ btoidvectorcmp(PG_FUNCTION_ARGS)
PG_RETURN_INT32(0); PG_RETURN_INT32(0);
} }
int32 Datum
btabstimecmp(AbsoluteTime a, AbsoluteTime b) btabstimecmp(PG_FUNCTION_ARGS)
{ {
AbsoluteTime a = PG_GETARG_ABSOLUTETIME(0);
AbsoluteTime b = PG_GETARG_ABSOLUTETIME(1);
if (AbsoluteTimeIsBefore(a, b)) if (AbsoluteTimeIsBefore(a, b))
PG_RETURN_INT32(-1); PG_RETURN_INT32(-1);
else if (AbsoluteTimeIsBefore(b, a)) else if (AbsoluteTimeIsBefore(b, a))
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.57 2000/06/02 03:58:33 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.58 2000/06/09 01:11:04 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -122,8 +122,8 @@ write_password_file(Relation rel) ...@@ -122,8 +122,8 @@ write_password_file(Relation rel)
"%s\n", "%s\n",
nameout(DatumGetName(datum_n)), nameout(DatumGetName(datum_n)),
null_p ? "" : textout((text *) datum_p), null_p ? "" : textout((text *) datum_p),
null_v ? "\\N" : nabstimeout((AbsoluteTime) datum_v) /* this is how the null_v ? "\\N" :
* parser wants it */ DatumGetCString(DirectFunctionCall1(nabstimeout, datum_v))
); );
} }
heap_endscan(scan); heap_endscan(scan);
...@@ -268,7 +268,8 @@ CreateUser(CreateUserStmt *stmt) ...@@ -268,7 +268,8 @@ CreateUser(CreateUserStmt *stmt)
if (stmt->password) if (stmt->password)
new_record[Anum_pg_shadow_passwd - 1] = PointerGetDatum(textin(stmt->password)); new_record[Anum_pg_shadow_passwd - 1] = PointerGetDatum(textin(stmt->password));
if (stmt->validUntil) if (stmt->validUntil)
new_record[Anum_pg_shadow_valuntil - 1] = PointerGetDatum(nabstimein(stmt->validUntil)); new_record[Anum_pg_shadow_valuntil - 1] =
DirectFunctionCall1(nabstimein, CStringGetDatum(stmt->validUntil));
new_record_nulls[Anum_pg_shadow_usename - 1] = ' '; new_record_nulls[Anum_pg_shadow_usename - 1] = ' ';
new_record_nulls[Anum_pg_shadow_usesysid - 1] = ' '; new_record_nulls[Anum_pg_shadow_usesysid - 1] = ' ';
...@@ -445,7 +446,8 @@ AlterUser(AlterUserStmt *stmt) ...@@ -445,7 +446,8 @@ AlterUser(AlterUserStmt *stmt)
/* valid until */ /* valid until */
if (stmt->validUntil) if (stmt->validUntil)
{ {
new_record[Anum_pg_shadow_valuntil - 1] = PointerGetDatum(nabstimein(stmt->validUntil)); new_record[Anum_pg_shadow_valuntil - 1] =
DirectFunctionCall1(nabstimein, CStringGetDatum(stmt->validUntil));
new_record_nulls[Anum_pg_shadow_valuntil - 1] = ' '; new_record_nulls[Anum_pg_shadow_valuntil - 1] = ' ';
} }
else else
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/be-fsstubs.c,v 1.45 2000/06/02 15:57:20 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/libpq/be-fsstubs.c,v 1.46 2000/06/09 01:11:06 tgl Exp $
* *
* NOTES * NOTES
* This should be moved to a more appropriate place. It is here * This should be moved to a more appropriate place. It is here
...@@ -49,6 +49,11 @@ ...@@ -49,6 +49,11 @@
#define BUFSIZE 1024 #define BUFSIZE 1024
#define FNAME_BUFSIZE 8192 #define FNAME_BUFSIZE 8192
/*
* LO "FD"s are indexes into this array.
* A non-null entry is a pointer to a LargeObjectDesc allocated in the
* LO private memory context.
*/
static LargeObjectDesc *cookies[MAX_LOBJ_FDS]; static LargeObjectDesc *cookies[MAX_LOBJ_FDS];
static GlobalMemory fscxt = NULL; static GlobalMemory fscxt = NULL;
...@@ -61,15 +66,17 @@ static void deleteLOfd(int fd); ...@@ -61,15 +66,17 @@ static void deleteLOfd(int fd);
* File Interfaces for Large Objects * File Interfaces for Large Objects
*****************************************************************************/ *****************************************************************************/
int Datum
lo_open(Oid lobjId, int mode) lo_open(PG_FUNCTION_ARGS)
{ {
Oid lobjId = PG_GETARG_OID(0);
int32 mode = PG_GETARG_INT32(1);
LargeObjectDesc *lobjDesc; LargeObjectDesc *lobjDesc;
int fd; int fd;
MemoryContext currentContext; MemoryContext currentContext;
#if FSDB #if FSDB
elog(NOTICE, "LOopen(%u,%d)", lobjId, mode); elog(NOTICE, "lo_open(%u,%d)", lobjId, mode);
#endif #endif
if (fscxt == NULL) if (fscxt == NULL)
...@@ -84,7 +91,7 @@ lo_open(Oid lobjId, int mode) ...@@ -84,7 +91,7 @@ lo_open(Oid lobjId, int mode)
#if FSDB #if FSDB
elog(NOTICE, "cannot open large object %u", lobjId); elog(NOTICE, "cannot open large object %u", lobjId);
#endif #endif
return -1; PG_RETURN_INT32(-1);
} }
fd = newLOfd(lobjDesc); fd = newLOfd(lobjDesc);
...@@ -97,26 +104,27 @@ lo_open(Oid lobjId, int mode) ...@@ -97,26 +104,27 @@ lo_open(Oid lobjId, int mode)
elog(NOTICE, "Out of space for large object FDs"); elog(NOTICE, "Out of space for large object FDs");
#endif #endif
return fd; PG_RETURN_INT32(fd);
} }
int Datum
lo_close(int fd) lo_close(PG_FUNCTION_ARGS)
{ {
int32 fd = PG_GETARG_INT32(0);
MemoryContext currentContext; MemoryContext currentContext;
if (fd < 0 || fd >= MAX_LOBJ_FDS) if (fd < 0 || fd >= MAX_LOBJ_FDS)
{ {
elog(ERROR, "lo_close: large obj descriptor (%d) out of range", fd); elog(ERROR, "lo_close: large obj descriptor (%d) out of range", fd);
return -2; PG_RETURN_INT32(-2);
} }
if (cookies[fd] == NULL) if (cookies[fd] == NULL)
{ {
elog(ERROR, "lo_close: invalid large obj descriptor (%d)", fd); elog(ERROR, "lo_close: invalid large obj descriptor (%d)", fd);
return -3; PG_RETURN_INT32(-3);
} }
#if FSDB #if FSDB
elog(NOTICE, "LOclose(%d)", fd); elog(NOTICE, "lo_close(%d)", fd);
#endif #endif
Assert(fscxt != NULL); Assert(fscxt != NULL);
...@@ -127,13 +135,19 @@ lo_close(int fd) ...@@ -127,13 +135,19 @@ lo_close(int fd)
MemoryContextSwitchTo(currentContext); MemoryContextSwitchTo(currentContext);
deleteLOfd(fd); deleteLOfd(fd);
return 0;
PG_RETURN_INT32(0);
} }
/*
/*****************************************************************************
* Bare Read/Write operations --- these are not fmgr-callable!
*
* We assume the large object supports byte oriented reads and seeks so * We assume the large object supports byte oriented reads and seeks so
* that our work is easier. * that our work is easier.
*/ *
*****************************************************************************/
int int
lo_read(int fd, char *buf, int len) lo_read(int fd, char *buf, int len)
{ {
...@@ -157,7 +171,8 @@ lo_read(int fd, char *buf, int len) ...@@ -157,7 +171,8 @@ lo_read(int fd, char *buf, int len)
status = inv_read(cookies[fd], buf, len); status = inv_read(cookies[fd], buf, len);
MemoryContextSwitchTo(currentContext); MemoryContextSwitchTo(currentContext);
return (status);
return status;
} }
int int
...@@ -183,25 +198,29 @@ lo_write(int fd, char *buf, int len) ...@@ -183,25 +198,29 @@ lo_write(int fd, char *buf, int len)
status = inv_write(cookies[fd], buf, len); status = inv_write(cookies[fd], buf, len);
MemoryContextSwitchTo(currentContext); MemoryContextSwitchTo(currentContext);
return (status);
return status;
} }
int Datum
lo_lseek(int fd, int offset, int whence) lo_lseek(PG_FUNCTION_ARGS)
{ {
int32 fd = PG_GETARG_INT32(0);
int32 offset = PG_GETARG_INT32(1);
int32 whence = PG_GETARG_INT32(2);
MemoryContext currentContext; MemoryContext currentContext;
int status; int status;
if (fd < 0 || fd >= MAX_LOBJ_FDS) if (fd < 0 || fd >= MAX_LOBJ_FDS)
{ {
elog(ERROR, "lo_lseek: large obj descriptor (%d) out of range", fd); elog(ERROR, "lo_lseek: large obj descriptor (%d) out of range", fd);
return -2; PG_RETURN_INT32(-2);
} }
if (cookies[fd] == NULL) if (cookies[fd] == NULL)
{ {
elog(ERROR, "lo_lseek: invalid large obj descriptor (%d)", fd); elog(ERROR, "lo_lseek: invalid large obj descriptor (%d)", fd);
return -3; PG_RETURN_INT32(-3);
} }
Assert(fscxt != NULL); Assert(fscxt != NULL);
...@@ -211,12 +230,13 @@ lo_lseek(int fd, int offset, int whence) ...@@ -211,12 +230,13 @@ lo_lseek(int fd, int offset, int whence)
MemoryContextSwitchTo(currentContext); MemoryContextSwitchTo(currentContext);
return status; PG_RETURN_INT32(status);
} }
Oid Datum
lo_creat(int mode) lo_creat(PG_FUNCTION_ARGS)
{ {
int32 mode = PG_GETARG_INT32(0);
LargeObjectDesc *lobjDesc; LargeObjectDesc *lobjDesc;
MemoryContext currentContext; MemoryContext currentContext;
Oid lobjId; Oid lobjId;
...@@ -231,31 +251,32 @@ lo_creat(int mode) ...@@ -231,31 +251,32 @@ lo_creat(int mode)
if (lobjDesc == NULL) if (lobjDesc == NULL)
{ {
MemoryContextSwitchTo(currentContext); MemoryContextSwitchTo(currentContext);
return InvalidOid; PG_RETURN_OID(InvalidOid);
} }
lobjId = RelationGetRelid(lobjDesc->heap_r); lobjId = RelationGetRelid(lobjDesc->heap_r);
inv_close(lobjDesc); inv_close(lobjDesc);
/* switch context back to original memory context */
MemoryContextSwitchTo(currentContext); MemoryContextSwitchTo(currentContext);
return lobjId; PG_RETURN_OID(lobjId);
} }
int Datum
lo_tell(int fd) lo_tell(PG_FUNCTION_ARGS)
{ {
int32 fd = PG_GETARG_INT32(0);
if (fd < 0 || fd >= MAX_LOBJ_FDS) if (fd < 0 || fd >= MAX_LOBJ_FDS)
{ {
elog(ERROR, "lo_tell: large object descriptor (%d) out of range", fd); elog(ERROR, "lo_tell: large object descriptor (%d) out of range", fd);
return -2; PG_RETURN_INT32(-2);
} }
if (cookies[fd] == NULL) if (cookies[fd] == NULL)
{ {
elog(ERROR, "lo_tell: invalid large object descriptor (%d)", fd); elog(ERROR, "lo_tell: invalid large object descriptor (%d)", fd);
return -3; PG_RETURN_INT32(-3);
} }
/* /*
...@@ -263,12 +284,13 @@ lo_tell(int fd) ...@@ -263,12 +284,13 @@ lo_tell(int fd)
* true for now, but is probably more than this module ought to * true for now, but is probably more than this module ought to
* assume... * assume...
*/ */
return inv_tell(cookies[fd]); PG_RETURN_INT32(inv_tell(cookies[fd]));
} }
int Datum
lo_unlink(Oid lobjId) lo_unlink(PG_FUNCTION_ARGS)
{ {
Oid lobjId = PG_GETARG_OID(0);
/* /*
* inv_drop does not need a context switch, indeed it doesn't touch * inv_drop does not need a context switch, indeed it doesn't touch
...@@ -278,35 +300,42 @@ lo_unlink(Oid lobjId) ...@@ -278,35 +300,42 @@ lo_unlink(Oid lobjId)
* XXX there ought to be some code to clean up any open LOs that * XXX there ought to be some code to clean up any open LOs that
* reference the specified relation... as is, they remain "open". * reference the specified relation... as is, they remain "open".
*/ */
return inv_drop(lobjId); PG_RETURN_INT32(inv_drop(lobjId));
} }
/***************************************************************************** /*****************************************************************************
* Read/Write using varlena * Read/Write using bytea
*****************************************************************************/ *****************************************************************************/
struct varlena * Datum
loread(int fd, int len) loread(PG_FUNCTION_ARGS)
{ {
int32 fd = PG_GETARG_INT32(0);
int32 len = PG_GETARG_INT32(1);
struct varlena *retval; struct varlena *retval;
int totalread = 0; int totalread;
if (len < 0)
len = 0;
retval = (struct varlena *) palloc(VARHDRSZ + len); retval = (struct varlena *) palloc(VARHDRSZ + len);
totalread = lo_read(fd, VARDATA(retval), len); totalread = lo_read(fd, VARDATA(retval), len);
VARSIZE(retval) = totalread + VARHDRSZ; VARSIZE(retval) = totalread + VARHDRSZ;
return retval; PG_RETURN_POINTER(retval);
} }
int Datum
lowrite(int fd, struct varlena * wbuf) lowrite(PG_FUNCTION_ARGS)
{ {
int totalwritten; int32 fd = PG_GETARG_INT32(0);
struct varlena *wbuf = PG_GETARG_VARLENA_P(1);
int bytestowrite; int bytestowrite;
int totalwritten;
bytestowrite = VARSIZE(wbuf) - VARHDRSZ; bytestowrite = VARSIZE(wbuf) - VARHDRSZ;
totalwritten = lo_write(fd, VARDATA(wbuf), bytestowrite); totalwritten = lo_write(fd, VARDATA(wbuf), bytestowrite);
return totalwritten; PG_RETURN_INT32(totalwritten);
} }
/***************************************************************************** /*****************************************************************************
...@@ -317,9 +346,10 @@ lowrite(int fd, struct varlena * wbuf) ...@@ -317,9 +346,10 @@ lowrite(int fd, struct varlena * wbuf)
* lo_import - * lo_import -
* imports a file as an (inversion) large object. * imports a file as an (inversion) large object.
*/ */
Oid Datum
lo_import(text *filename) lo_import(PG_FUNCTION_ARGS)
{ {
text *filename = PG_GETARG_TEXT_P(0);
File fd; File fd;
int nbytes, int nbytes,
tmp; tmp;
...@@ -379,16 +409,18 @@ lo_import(text *filename) ...@@ -379,16 +409,18 @@ lo_import(text *filename)
FileClose(fd); FileClose(fd);
inv_close(lobj); inv_close(lobj);
return lobjOid; PG_RETURN_OID(lobjOid);
} }
/* /*
* lo_export - * lo_export -
* exports an (inversion) large object. * exports an (inversion) large object.
*/ */
int4 Datum
lo_export(Oid lobjId, text *filename) lo_export(PG_FUNCTION_ARGS)
{ {
Oid lobjId = PG_GETARG_OID(0);
text *filename = PG_GETARG_TEXT_P(1);
File fd; File fd;
int nbytes, int nbytes,
tmp; tmp;
...@@ -445,7 +477,7 @@ lo_export(Oid lobjId, text *filename) ...@@ -445,7 +477,7 @@ lo_export(Oid lobjId, text *filename)
inv_close(lobj); inv_close(lobj);
FileClose(fd); FileClose(fd);
return 1; PG_RETURN_INT32(1);
} }
/* /*
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* Dec 17, 1997 - Todd A. Brandys * Dec 17, 1997 - Todd A. Brandys
* Orignal Version Completed. * Orignal Version Completed.
* *
* $Id: crypt.c,v 1.24 2000/06/02 15:57:20 momjian Exp $ * $Id: crypt.c,v 1.25 2000/06/09 01:11:06 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -288,7 +288,8 @@ crypt_verify(Port *port, const char *user, const char *pgpass) ...@@ -288,7 +288,8 @@ crypt_verify(Port *port, const char *user, const char *pgpass)
if (!valuntil || strcmp(valuntil, "\\N") == 0) if (!valuntil || strcmp(valuntil, "\\N") == 0)
vuntil = INVALID_ABSTIME; vuntil = INVALID_ABSTIME;
else else
vuntil = nabstimein(valuntil); vuntil = DatumGetAbsoluteTime(DirectFunctionCall1(nabstimein,
CStringGetDatum(valuntil)));
current = GetCurrentAbsoluteTime(); current = GetCurrentAbsoluteTime();
if (vuntil != INVALID_ABSTIME && vuntil < current) if (vuntil != INVALID_ABSTIME && vuntil < current)
retval = STATUS_ERROR; retval = STATUS_ERROR;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.55 2000/06/02 15:57:28 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.56 2000/06/09 01:11:08 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -538,8 +538,11 @@ _ReadLOArray(char *str, ...@@ -538,8 +538,11 @@ _ReadLOArray(char *str,
if (inputfile == NULL) if (inputfile == NULL)
elog(ERROR, "array_in: missing file name"); elog(ERROR, "array_in: missing file name");
lobjId = lo_creat(0); lobjId = DatumGetObjectId(DirectFunctionCall1(lo_creat,
*fd = lo_open(lobjId, INV_READ); Int32GetDatum(0)));
*fd = DatumGetInt32(DirectFunctionCall2(lo_open,
ObjectIdGetDatum(lobjId),
Int32GetDatum(INV_READ)));
if (*fd < 0) if (*fd < 0)
elog(ERROR, "Large object create failed"); elog(ERROR, "Large object create failed");
retStr = inputfile; retStr = inputfile;
...@@ -877,17 +880,23 @@ array_ref(ArrayType *array, ...@@ -877,17 +880,23 @@ array_ref(ArrayType *array,
v = _ReadChunkArray1El(indx, elmlen, fd, array, isNull); v = _ReadChunkArray1El(indx, elmlen, fd, array, isNull);
else else
{ {
if (lo_lseek(fd, offset, SEEK_SET) < 0) if (DatumGetInt32(DirectFunctionCall3(lo_lseek,
Int32GetDatum(fd),
Int32GetDatum(offset),
Int32GetDatum(SEEK_SET))) < 0)
RETURN_NULL; RETURN_NULL;
#ifdef LOARRAY #ifdef LOARRAY
v = (struct varlena *) LOread(fd, elmlen); v = (struct varlena *)
DatumGetPointer(DirectFunctionCall2(loread,
Int32GetDatum(fd),
Int32GetDatum(elmlen)));
#endif #endif
} }
if (*isNull) if (*isNull)
RETURN_NULL; RETURN_NULL;
if (VARSIZE(v) - VARHDRSZ < elmlen) if (VARSIZE(v) - VARHDRSZ < elmlen)
RETURN_NULL; RETURN_NULL;
lo_close(fd); DirectFunctionCall1(lo_close, Int32GetDatum(fd));
retval = (char *) _ArrayCast((char *) VARDATA(v), reftype, elmlen); retval = (char *) _ArrayCast((char *) VARDATA(v), reftype, elmlen);
if (reftype == 0) if (reftype == 0)
{ /* not by value */ { /* not by value */
...@@ -1029,7 +1038,9 @@ array_clip(ArrayType *array, ...@@ -1029,7 +1038,9 @@ array_clip(ArrayType *array,
memmove(buff, &rsize, VARHDRSZ); memmove(buff, &rsize, VARHDRSZ);
#ifdef LOARRAY #ifdef LOARRAY
if (!*isNull) if (!*isNull)
bytes = LOwrite(newfd, (struct varlena *) buff); bytes = DatumGetInt32(DirectFunctionCall2(lowrite,
Int32GetDatum(newfd),
PointerGetDatum(buff)));
#endif #endif
pfree(buff); pfree(buff);
} }
...@@ -1140,20 +1151,25 @@ array_set(ArrayType *array, ...@@ -1140,20 +1151,25 @@ array_set(ArrayType *array,
if ((fd = LOopen(lo_name, ARR_IS_INV(array) ? INV_WRITE : O_WRONLY)) < 0) if ((fd = LOopen(lo_name, ARR_IS_INV(array) ? INV_WRITE : O_WRONLY)) < 0)
return (char *) array; return (char *) array;
#endif #endif
if (lo_lseek(fd, offset, SEEK_SET) < 0) if (DatumGetInt32(DirectFunctionCall3(lo_lseek,
Int32GetDatum(fd),
Int32GetDatum(offset),
Int32GetDatum(SEEK_SET))) < 0)
return (char *) array; return (char *) array;
v = (struct varlena *) palloc(elmlen + VARHDRSZ); v = (struct varlena *) palloc(elmlen + VARHDRSZ);
VARSIZE(v) = elmlen + VARHDRSZ; VARSIZE(v) = elmlen + VARHDRSZ;
ArrayCastAndSet(dataPtr, (bool) reftype, elmlen, VARDATA(v)); ArrayCastAndSet(dataPtr, (bool) reftype, elmlen, VARDATA(v));
#ifdef LOARRAY #ifdef LOARRAY
n = LOwrite(fd, v); n = DatumGetInt32(DirectFunctionCall2(lowrite,
Int32GetDatum(fd),
PointerGetDatum(v)));
#endif #endif
/* /*
* if (n < VARSIZE(v) - VARHDRSZ) RETURN_NULL; * if (n < VARSIZE(v) - VARHDRSZ) RETURN_NULL;
*/ */
pfree(v); pfree(v);
lo_close(fd); DirectFunctionCall1(lo_close, Int32GetDatum(fd));
return (char *) array; return (char *) array;
} }
if (elmlen > 0) if (elmlen > 0)
...@@ -1270,14 +1286,14 @@ array_assgn(ArrayType *array, ...@@ -1270,14 +1286,14 @@ array_assgn(ArrayType *array,
return (char *) array; return (char *) array;
#endif #endif
_LOArrayRange(lowerIndx, upperIndx, len, fd, newfd, array, 1, isNull); _LOArrayRange(lowerIndx, upperIndx, len, fd, newfd, array, 1, isNull);
lo_close(newfd); DirectFunctionCall1(lo_close, Int32GetDatum(newfd));
} }
else else
{ {
_LOArrayRange(lowerIndx, upperIndx, len, fd, (int) ARR_DATA_PTR(newArr), _LOArrayRange(lowerIndx, upperIndx, len, fd, (int) ARR_DATA_PTR(newArr),
array, 0, isNull); array, 0, isNull);
} }
lo_close(fd); DirectFunctionCall1(lo_close, Int32GetDatum(fd));
return (char *) array; return (char *) array;
} }
_ArrayRange(lowerIndx, upperIndx, len, ARR_DATA_PTR(newArr), array, 0); _ArrayRange(lowerIndx, upperIndx, len, ARR_DATA_PTR(newArr), array, 0);
...@@ -1758,7 +1774,10 @@ _LOArrayRange(int *st, ...@@ -1758,7 +1774,10 @@ _LOArrayRange(int *st,
mda_get_prod(n, dim, prod); mda_get_prod(n, dim, prod);
st_pos = tuple2linear(n, st, prod); st_pos = tuple2linear(n, st, prod);
offset = st_pos * bsize; offset = st_pos * bsize;
if (lo_lseek(srcfd, offset, SEEK_SET) < 0) if (DatumGetInt32(DirectFunctionCall3(lo_lseek,
Int32GetDatum(srcfd),
Int32GetDatum(offset),
Int32GetDatum(SEEK_SET))) < 0)
return; return;
mda_get_range(n, span, st, endp); mda_get_range(n, span, st, endp);
mda_get_offset_values(n, dist, prod, span); mda_get_offset_values(n, dist, prod, span);
...@@ -1770,7 +1789,10 @@ _LOArrayRange(int *st, ...@@ -1770,7 +1789,10 @@ _LOArrayRange(int *st,
do do
{ {
offset += (dist[j] * bsize); offset += (dist[j] * bsize);
if (lo_lseek(srcfd, offset, SEEK_SET) < 0) if (DatumGetInt32(DirectFunctionCall3(lo_lseek,
Int32GetDatum(srcfd),
Int32GetDatum(offset),
Int32GetDatum(SEEK_SET))) < 0)
return; return;
tmp = _LOtransfer((char **) &srcfd, inc, 1, (char **) &destfd, isSrcLO, 1); tmp = _LOtransfer((char **) &srcfd, inc, 1, (char **) &destfd, isSrcLO, 1);
if (tmp < inc) if (tmp < inc)
...@@ -1812,7 +1834,10 @@ _ReadArray(int *st, ...@@ -1812,7 +1834,10 @@ _ReadArray(int *st,
mda_get_prod(n, dim, prod); mda_get_prod(n, dim, prod);
st_pos = tuple2linear(n, st, prod); st_pos = tuple2linear(n, st, prod);
offset = st_pos * bsize; offset = st_pos * bsize;
if (lo_lseek(srcfd, offset, SEEK_SET) < 0) if (DatumGetInt32(DirectFunctionCall3(lo_lseek,
Int32GetDatum(srcfd),
Int32GetDatum(offset),
Int32GetDatum(SEEK_SET))) < 0)
return; return;
mda_get_range(n, span, st, endp); mda_get_range(n, span, st, endp);
mda_get_offset_values(n, dist, prod, span); mda_get_offset_values(n, dist, prod, span);
...@@ -1824,7 +1849,10 @@ _ReadArray(int *st, ...@@ -1824,7 +1849,10 @@ _ReadArray(int *st,
do do
{ {
offset += (dist[j] * bsize); offset += (dist[j] * bsize);
if (lo_lseek(srcfd, offset, SEEK_SET) < 0) if (DatumGetInt32(DirectFunctionCall3(lo_lseek,
Int32GetDatum(srcfd),
Int32GetDatum(offset),
Int32GetDatum(SEEK_SET))) < 0)
return; return;
tmp = _LOtransfer((char **) &destfd, inc, 1, (char **) &srcfd, 1, isDestLO); tmp = _LOtransfer((char **) &destfd, inc, 1, (char **) &srcfd, 1, isDestLO);
if (tmp < inc) if (tmp < inc)
...@@ -1857,13 +1885,18 @@ _LOtransfer(char **destfd, ...@@ -1857,13 +1885,18 @@ _LOtransfer(char **destfd,
resid > 0 && (inc = min(resid, MAX_READ)) > 0; resid -= inc) resid > 0 && (inc = min(resid, MAX_READ)) > 0; resid -= inc)
{ {
#ifdef LOARRAY #ifdef LOARRAY
v = (struct varlena *) LOread((int) *srcfd, inc); v = (struct varlena *)
DatumGetPointer(DirectFunctionCall2(loread,
Int32GetDatum((int32) *srcfd),
Int32GetDatum(inc)));
if (VARSIZE(v) - VARHDRSZ < inc) if (VARSIZE(v) - VARHDRSZ < inc)
{ {
pfree(v); pfree(v);
return -1; return -1;
} }
tmp += LOwrite((int) *destfd, v); tmp += DatumGetInt32(DirectFunctionCall2(lowrite,
Int32GetDatum((int32) *destfd),
PointerGetDatum(v)));
#endif #endif
pfree(v); pfree(v);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/chunk.c,v 1.25 2000/01/26 05:57:13 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/chunk.c,v 1.26 2000/06/09 01:11:08 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -385,7 +385,9 @@ write_chunk(struct varlena * a_chunk, int ofile) ...@@ -385,7 +385,9 @@ write_chunk(struct varlena * a_chunk, int ofile)
int got_n = 0; int got_n = 0;
#ifdef LOARRAY #ifdef LOARRAY
got_n = LOwrite(ofile, a_chunk); got_n = DatumGetInt32(DirectFunctionCall2(lowrite,
Int32GetDatum(ofile),
PointerGetDatum(a_chunk)));
#endif #endif
return got_n; return got_n;
} }
...@@ -400,13 +402,19 @@ write_chunk(struct varlena * a_chunk, int ofile) ...@@ -400,13 +402,19 @@ write_chunk(struct varlena * a_chunk, int ofile)
static int static int
seek_and_read(int pos, int size, char *buff, int fp, int from) seek_and_read(int pos, int size, char *buff, int fp, int from)
{ {
struct varlena *v = NULL; struct varlena *v;
/* Assuming only one file */ /* Assuming only one file */
if (lo_lseek(fp, pos, from) < 0) if (DatumGetInt32(DirectFunctionCall3(lo_lseek,
Int32GetDatum(fp),
Int32GetDatum(pos),
Int32GetDatum(from))) < 0)
elog(ERROR, "File seek error"); elog(ERROR, "File seek error");
#ifdef LOARRAY #ifdef LOARRAY
v = (struct varlena *) LOread(fp, size); v = (struct varlena *)
DatumGetPointer(DirectFunctionCall2(loread,
Int32GetDatum(fp),
Int32GetDatum(size)));
#endif #endif
if (VARSIZE(v) - VARHDRSZ < size) if (VARSIZE(v) - VARHDRSZ < size)
elog(ERROR, "File read error"); elog(ERROR, "File read error");
...@@ -505,7 +513,10 @@ _ReadChunkArray(int *st, ...@@ -505,7 +513,10 @@ _ReadChunkArray(int *st,
for (i = j = 0; i < n; i++) for (i = j = 0; i < n; i++)
j += chunk_st[i] * PC[i]; j += chunk_st[i] * PC[i];
temp_seek = srcOff = j * csize * bsize; temp_seek = srcOff = j * csize * bsize;
if (lo_lseek(fp, srcOff, SEEK_SET) < 0) if (DatumGetInt32(DirectFunctionCall3(lo_lseek,
Int32GetDatum(fp),
Int32GetDatum(srcOff),
Int32GetDatum(SEEK_SET))) < 0)
RETURN_NULL; RETURN_NULL;
jj = n - 1; jj = n - 1;
...@@ -526,7 +537,10 @@ _ReadChunkArray(int *st, ...@@ -526,7 +537,10 @@ _ReadChunkArray(int *st,
bptr *= bsize; bptr *= bsize;
if (isDestLO) if (isDestLO)
{ {
if (lo_lseek((int) destfp, bptr, SEEK_SET) < 0) if (DatumGetInt32(DirectFunctionCall3(lo_lseek,
Int32GetDatum((int32) destfp),
Int32GetDatum(bptr),
Int32GetDatum(SEEK_SET))) < 0)
RETURN_NULL; RETURN_NULL;
} }
else else
...@@ -538,7 +552,10 @@ _ReadChunkArray(int *st, ...@@ -538,7 +552,10 @@ _ReadChunkArray(int *st,
{ {
temp = (dist[jj] * csize + block_seek + temp_seek) * bsize; temp = (dist[jj] * csize + block_seek + temp_seek) * bsize;
srcOff += temp; srcOff += temp;
if (lo_lseek(fp, srcOff, SEEK_SET) < 0) if (DatumGetInt32(DirectFunctionCall3(lo_lseek,
Int32GetDatum(fp),
Int32GetDatum(srcOff),
Int32GetDatum(SEEK_SET))) < 0)
RETURN_NULL; RETURN_NULL;
} }
for (i = n - 1, to_read = bsize; i >= 0; for (i = n - 1, to_read = bsize; i >= 0;
...@@ -550,14 +567,20 @@ _ReadChunkArray(int *st, ...@@ -550,14 +567,20 @@ _ReadChunkArray(int *st,
if (cdist[j]) if (cdist[j])
{ {
srcOff += (cdist[j] * bsize); srcOff += (cdist[j] * bsize);
if (lo_lseek(fp, srcOff, SEEK_SET) < 0) if (DatumGetInt32(DirectFunctionCall3(lo_lseek,
Int32GetDatum(fp),
Int32GetDatum(srcOff),
Int32GetDatum(SEEK_SET))) < 0)
RETURN_NULL; RETURN_NULL;
} }
block_seek += cdist[j]; block_seek += cdist[j];
bptr += adist[j] * bsize; bptr += adist[j] * bsize;
if (isDestLO) if (isDestLO)
{ {
if (lo_lseek((int) destfp, bptr, SEEK_SET) < 0) if (DatumGetInt32(DirectFunctionCall3(lo_lseek,
Int32GetDatum((int32) destfp),
Int32GetDatum(bptr),
Int32GetDatum(SEEK_SET))) < 0)
RETURN_NULL; RETURN_NULL;
} }
else else
...@@ -675,10 +698,16 @@ _ReadChunkArray1El(int *st, ...@@ -675,10 +698,16 @@ _ReadChunkArray1El(int *st,
srcOff += (st[i] - chunk_st[i] * C[i]) * PCHUNK[i]; srcOff += (st[i] - chunk_st[i] * C[i]) * PCHUNK[i];
srcOff *= bsize; srcOff *= bsize;
if (lo_lseek(fp, srcOff, SEEK_SET) < 0) if (DatumGetInt32(DirectFunctionCall3(lo_lseek,
Int32GetDatum(fp),
Int32GetDatum(srcOff),
Int32GetDatum(SEEK_SET))) < 0)
RETURN_NULL; RETURN_NULL;
#ifdef LOARRAY #ifdef LOARRAY
return (struct varlena *) LOread(fp, bsize); return (struct varlena *)
DatumGetPointer(DirectFunctionCall2(loread,
Int32GetDatum(fp),
Int32GetDatum(bsize)));
#endif #endif
return (struct varlena *) 0; return (struct varlena *) 0;
} }
This diff is collapsed.
/* ----------------------------------------------------------------------- /* -----------------------------------------------------------------------
* formatting.c * formatting.c
* *
* $Header: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v 1.9 2000/06/05 07:28:51 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v 1.10 2000/06/09 01:11:08 tgl Exp $
* *
* *
* Portions Copyright (c) 1999-2000, PostgreSQL, Inc * Portions Copyright (c) 1999-2000, PostgreSQL, Inc
...@@ -2372,9 +2372,11 @@ DCH_cache_search(char *str) ...@@ -2372,9 +2372,11 @@ DCH_cache_search(char *str)
* TIMESTAMP to_char() * TIMESTAMP to_char()
* ------------------- * -------------------
*/ */
text * Datum
timestamp_to_char(Timestamp *dt, text *fmt) timestamp_to_char(PG_FUNCTION_ARGS)
{ {
Timestamp dt = PG_GETARG_TIMESTAMP(0);
text *fmt = PG_GETARG_TEXT_P(1);
text *result, text *result,
*result_tmp; *result_tmp;
FormatNode *format; FormatNode *format;
...@@ -2386,13 +2388,10 @@ timestamp_to_char(Timestamp *dt, text *fmt) ...@@ -2386,13 +2388,10 @@ timestamp_to_char(Timestamp *dt, text *fmt)
flag = 0, flag = 0,
x = 0; x = 0;
if ((!PointerIsValid(dt)) || (!PointerIsValid(fmt)))
return NULL;
len = VARSIZE(fmt) - VARHDRSZ; len = VARSIZE(fmt) - VARHDRSZ;
if ((!len) || (TIMESTAMP_NOT_FINITE(*dt))) if ((!len) || (TIMESTAMP_NOT_FINITE(dt)))
return textin(""); return PointerGetDatum(textin(""));
tm->tm_sec = 0; tm->tm_sec = 0;
tm->tm_year = 0; tm->tm_year = 0;
...@@ -2404,18 +2403,18 @@ timestamp_to_char(Timestamp *dt, text *fmt) ...@@ -2404,18 +2403,18 @@ timestamp_to_char(Timestamp *dt, text *fmt)
tm->tm_isdst = 0; tm->tm_isdst = 0;
tm->tm_mon = 1; tm->tm_mon = 1;
if (TIMESTAMP_IS_EPOCH(*dt)) if (TIMESTAMP_IS_EPOCH(dt))
{ {
x = timestamp2tm(SetTimestamp(*dt), NULL, tm, &fsec, NULL); x = timestamp2tm(SetTimestamp(dt), NULL, tm, &fsec, NULL);
} }
else if (TIMESTAMP_IS_CURRENT(*dt)) else if (TIMESTAMP_IS_CURRENT(dt))
{ {
x = timestamp2tm(SetTimestamp(*dt), &tz, tm, &fsec, &tzn); x = timestamp2tm(SetTimestamp(dt), &tz, tm, &fsec, &tzn);
} }
else else
x = timestamp2tm(*dt, &tz, tm, &fsec, &tzn); x = timestamp2tm(dt, &tz, tm, &fsec, &tzn);
if (x != 0) if (x != 0)
elog(ERROR, "to_char(): Unable to convert timestamp to tm"); elog(ERROR, "to_char(): Unable to convert timestamp to tm");
...@@ -2508,7 +2507,7 @@ timestamp_to_char(Timestamp *dt, text *fmt) ...@@ -2508,7 +2507,7 @@ timestamp_to_char(Timestamp *dt, text *fmt)
VARSIZE(result) = len + VARHDRSZ; VARSIZE(result) = len + VARHDRSZ;
pfree(result_tmp); pfree(result_tmp);
return result; PG_RETURN_TEXT_P(result);
} }
...@@ -2519,20 +2518,19 @@ timestamp_to_char(Timestamp *dt, text *fmt) ...@@ -2519,20 +2518,19 @@ timestamp_to_char(Timestamp *dt, text *fmt)
* ( to_timestamp is reverse to_char() ) * ( to_timestamp is reverse to_char() )
* --------------------- * ---------------------
*/ */
Timestamp * Datum
to_timestamp(text *date_str, text *fmt) to_timestamp(PG_FUNCTION_ARGS)
{ {
text *date_str = PG_GETARG_TEXT_P(0);
text *fmt = PG_GETARG_TEXT_P(1);
FormatNode *format; FormatNode *format;
int flag = 0; int flag = 0;
Timestamp *result; Timestamp result;
char *str; char *str;
int len = 0, int len = 0,
fsec = 0, fsec = 0,
tz = 0; tz = 0;
if ((!PointerIsValid(date_str)) || (!PointerIsValid(fmt)))
return NULL;
tm->tm_sec = 0; tm->tm_sec = 0;
tm->tm_year = 0; tm->tm_year = 0;
tm->tm_min = 0; tm->tm_min = 0;
...@@ -2543,8 +2541,6 @@ to_timestamp(text *date_str, text *fmt) ...@@ -2543,8 +2541,6 @@ to_timestamp(text *date_str, text *fmt)
tm->tm_isdst = 0; tm->tm_isdst = 0;
tm->tm_mon = 1; tm->tm_mon = 1;
result = palloc(sizeof(Timestamp));
len = VARSIZE(fmt) - VARHDRSZ; len = VARSIZE(fmt) - VARHDRSZ;
if (len) if (len)
...@@ -2668,10 +2664,10 @@ to_timestamp(text *date_str, text *fmt) ...@@ -2668,10 +2664,10 @@ to_timestamp(text *date_str, text *fmt)
#ifdef DEBUG_TO_FROM_CHAR #ifdef DEBUG_TO_FROM_CHAR
NOTICE_TM; NOTICE_TM;
#endif #endif
if (tm2timestamp(tm, fsec, &tz, result) != 0) if (tm2timestamp(tm, fsec, &tz, &result) != 0)
elog(ERROR, "to_datatime(): can't convert 'tm' to timestamp."); elog(ERROR, "to_timestamp(): can't convert 'tm' to timestamp.");
return result; PG_RETURN_TIMESTAMP(result);
} }
/* ---------- /* ----------
...@@ -2679,10 +2675,13 @@ to_timestamp(text *date_str, text *fmt) ...@@ -2679,10 +2675,13 @@ to_timestamp(text *date_str, text *fmt)
* Make Date from date_str which is formated at argument 'fmt' * Make Date from date_str which is formated at argument 'fmt'
* ---------- * ----------
*/ */
DateADT Datum
to_date(text *date_str, text *fmt) to_date(PG_FUNCTION_ARGS)
{ {
return timestamp_date(to_timestamp(date_str, fmt)); /* Quick hack: since our inputs are just like to_timestamp,
* hand over the whole input info struct...
*/
return DirectFunctionCall1(timestamp_date, to_timestamp(fcinfo));
} }
/********************************************************************** /**********************************************************************
......
This diff is collapsed.
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/not_in.c,v 1.22 2000/01/26 05:57:14 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/not_in.c,v 1.23 2000/06/09 01:11:09 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -34,23 +34,28 @@ static int my_varattno(Relation rd, char *a); ...@@ -34,23 +34,28 @@ static int my_varattno(Relation rd, char *a);
* *
* ---------------------------------------------------------------- * ----------------------------------------------------------------
*/ */
bool Datum
int4notin(int32 not_in_arg, char *relation_and_attr) int4notin(PG_FUNCTION_ARGS)
{ {
int32 not_in_arg = PG_GETARG_INT32(0);
text *relation_and_attr = PG_GETARG_TEXT_P(1);
Relation relation_to_scan; Relation relation_to_scan;
int32 integer_value; int32 integer_value;
HeapTuple current_tuple; HeapTuple current_tuple;
HeapScanDesc scan_descriptor; HeapScanDesc scan_descriptor;
bool dummy, bool isNull,
retval; retval;
int attrid; int attrid,
strlength;
char *relation, char *relation,
*attribute; *attribute;
char my_copy[NAMEDATALEN * 2 + 2]; char my_copy[NAMEDATALEN * 2 + 2];
Datum value; Datum value;
strncpy(my_copy, relation_and_attr, sizeof(my_copy)); strlength = VARSIZE(relation_and_attr) - VARHDRSZ + 1;
my_copy[sizeof(my_copy) - 1] = '\0'; if (strlength > sizeof(my_copy))
strlength = sizeof(my_copy);
StrNCpy(my_copy, VARDATA(relation_and_attr), strlength);
relation = (char *) strtok(my_copy, "."); relation = (char *) strtok(my_copy, ".");
attribute = (char *) strtok(NULL, "."); attribute = (char *) strtok(NULL, ".");
...@@ -81,7 +86,9 @@ int4notin(int32 not_in_arg, char *relation_and_attr) ...@@ -81,7 +86,9 @@ int4notin(int32 not_in_arg, char *relation_and_attr)
value = heap_getattr(current_tuple, value = heap_getattr(current_tuple,
(AttrNumber) attrid, (AttrNumber) attrid,
RelationGetDescr(relation_to_scan), RelationGetDescr(relation_to_scan),
&dummy); &isNull);
if (isNull)
continue;
integer_value = DatumGetInt32(value); integer_value = DatumGetInt32(value);
if (not_in_arg == integer_value) if (not_in_arg == integer_value)
{ {
...@@ -94,15 +101,21 @@ int4notin(int32 not_in_arg, char *relation_and_attr) ...@@ -94,15 +101,21 @@ int4notin(int32 not_in_arg, char *relation_and_attr)
heap_endscan(scan_descriptor); heap_endscan(scan_descriptor);
heap_close(relation_to_scan, AccessShareLock); heap_close(relation_to_scan, AccessShareLock);
return retval; PG_RETURN_BOOL(retval);
} }
bool Datum
oidnotin(Oid the_oid, char *compare) oidnotin(PG_FUNCTION_ARGS)
{ {
Oid the_oid = PG_GETARG_OID(0);
#ifdef NOT_USED
text *relation_and_attr = PG_GETARG_TEXT_P(1);
#endif
if (the_oid == InvalidOid) if (the_oid == InvalidOid)
return false; PG_RETURN_BOOL(false);
return int4notin(the_oid, compare); /* XXX assume oid maps to int4 */
return int4notin(fcinfo);
} }
/* /*
...@@ -117,7 +130,7 @@ my_varattno(Relation rd, char *a) ...@@ -117,7 +130,7 @@ my_varattno(Relation rd, char *a)
for (i = 0; i < rd->rd_rel->relnatts; i++) for (i = 0; i < rd->rd_rel->relnatts; i++)
{ {
if (!namestrcmp(&rd->rd_att->attrs[i]->attname, a)) if (namestrcmp(&rd->rd_att->attrs[i]->attname, a) == 0)
return i + 1; return i + 1;
} }
return -1; return -1;
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* out of its tuple * out of its tuple
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.50 2000/05/30 04:24:51 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.51 2000/06/09 01:11:09 tgl Exp $
* *
* This software is copyrighted by Jan Wieck - Hamburg. * This software is copyrighted by Jan Wieck - Hamburg.
* *
...@@ -319,9 +319,10 @@ pg_get_viewdef(NameData *rname) ...@@ -319,9 +319,10 @@ pg_get_viewdef(NameData *rname)
* get_indexdef - Get the definition of an index * get_indexdef - Get the definition of an index
* ---------- * ----------
*/ */
text * Datum
pg_get_indexdef(Oid indexrelid) pg_get_indexdef(PG_FUNCTION_ARGS)
{ {
Oid indexrelid = PG_GETARG_OID(0);
text *indexdef; text *indexdef;
HeapTuple ht_idx; HeapTuple ht_idx;
HeapTuple ht_idxrel; HeapTuple ht_idxrel;
...@@ -541,7 +542,7 @@ pg_get_indexdef(Oid indexrelid) ...@@ -541,7 +542,7 @@ pg_get_indexdef(Oid indexrelid)
if (SPI_finish() != SPI_OK_FINISH) if (SPI_finish() != SPI_OK_FINISH)
elog(ERROR, "get_viewdef: SPI_finish() failed"); elog(ERROR, "get_viewdef: SPI_finish() failed");
return indexdef; PG_RETURN_TEXT_P(indexdef);
} }
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.69 2000/06/05 07:28:52 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.70 2000/06/09 01:11:09 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1038,14 +1038,16 @@ convert_timevalue_to_scalar(Datum value, Oid typid) ...@@ -1038,14 +1038,16 @@ convert_timevalue_to_scalar(Datum value, Oid typid)
switch (typid) switch (typid)
{ {
case TIMESTAMPOID: case TIMESTAMPOID:
return *((Timestamp *) DatumGetPointer(value)); return DatumGetTimestamp(value);
case ABSTIMEOID: case ABSTIMEOID:
return *abstime_timestamp(value); return DatumGetTimestamp(DirectFunctionCall1(abstime_timestamp,
value));
case DATEOID: case DATEOID:
return *date_timestamp(value); return DatumGetTimestamp(DirectFunctionCall1(date_timestamp,
value));
case INTERVALOID: case INTERVALOID:
{ {
Interval *interval = (Interval *) DatumGetPointer(value); Interval *interval = DatumGetIntervalP(value);
/* /*
* Convert the month part of Interval to days using * Convert the month part of Interval to days using
...@@ -1056,17 +1058,17 @@ convert_timevalue_to_scalar(Datum value, Oid typid) ...@@ -1056,17 +1058,17 @@ convert_timevalue_to_scalar(Datum value, Oid typid)
interval->month * (365.25 / 12.0 * 24.0 * 60.0 * 60.0); interval->month * (365.25 / 12.0 * 24.0 * 60.0 * 60.0);
} }
case RELTIMEOID: case RELTIMEOID:
return (RelativeTime) DatumGetInt32(value); return DatumGetRelativeTime(value);
case TINTERVALOID: case TINTERVALOID:
{ {
TimeInterval interval = (TimeInterval) DatumGetPointer(value); TimeInterval interval = DatumGetTimeInterval(value);
if (interval->status != 0) if (interval->status != 0)
return interval->data[1] - interval->data[0]; return interval->data[1] - interval->data[0];
return 0; /* for lack of a better idea */ return 0; /* for lack of a better idea */
} }
case TIMEOID: case TIMEOID:
return *((TimeADT *) DatumGetPointer(value)); return DatumGetTimeADT(value);
} }
/* Can't get here unless someone tries to use scalarltsel/scalargtsel /* Can't get here unless someone tries to use scalarltsel/scalargtsel
* on an operator with one timevalue and one non-timevalue operand. * on an operator with one timevalue and one non-timevalue operand.
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.31 2000/05/28 17:56:06 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.32 2000/06/09 01:11:09 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -140,8 +140,12 @@ SetDefine(char *querystr, char *typename) ...@@ -140,8 +140,12 @@ SetDefine(char *querystr, char *typename)
* never executed. At runtime, the OID of the actual set is substituted * never executed. At runtime, the OID of the actual set is substituted
* into the :funcid. * into the :funcid.
*/ */
int Datum
seteval(Oid funcoid) seteval(PG_FUNCTION_ARGS)
{ {
return 17; Oid funcoid = PG_GETARG_OID(0);
elog(ERROR, "seteval called for OID %u", funcoid);
PG_RETURN_INT32(0); /* keep compiler happy */
} }
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/tid.c,v 1.19 2000/06/08 22:37:28 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/tid.c,v 1.20 2000/06/09 01:11:09 tgl Exp $
* *
* NOTES * NOTES
* input routine largely stolen from boxin(). * input routine largely stolen from boxin().
...@@ -160,19 +160,21 @@ text_tid(const text *string) ...@@ -160,19 +160,21 @@ text_tid(const text *string)
/* /*
* Functions to get latest tid of a specified tuple. * Functions to get latest tid of a specified tuple.
* Maybe these implementations is moved *
* to another place * Maybe these implementations should be moved to another place
*/ */
ItemPointer Datum
currtid_byreloid(Oid reloid, ItemPointer tid) currtid_byreloid(PG_FUNCTION_ARGS)
{ {
ItemPointer result = NULL, Oid reloid = PG_GETARG_OID(0);
ItemPointer tid = (ItemPointer) PG_GETARG_POINTER(1);
ItemPointer result,
ret; ret;
Relation rel; Relation rel;
result = (ItemPointer) palloc(sizeof(ItemPointerData)); result = (ItemPointer) palloc(sizeof(ItemPointerData));
ItemPointerSetInvalid(result); ItemPointerSetInvalid(result);
if (rel = heap_open(reloid, AccessShareLock), rel) if ((rel = heap_open(reloid, AccessShareLock)) != NULL)
{ {
ret = heap_get_latest_tid(rel, SnapshotNow, tid); ret = heap_get_latest_tid(rel, SnapshotNow, tid);
if (ret) if (ret)
...@@ -182,25 +184,24 @@ currtid_byreloid(Oid reloid, ItemPointer tid) ...@@ -182,25 +184,24 @@ currtid_byreloid(Oid reloid, ItemPointer tid)
else else
elog(ERROR, "Relation %u not found", reloid); elog(ERROR, "Relation %u not found", reloid);
return result; PG_RETURN_POINTER(result);
} /* currtid_byreloid() */ }
ItemPointer Datum
currtid_byrelname(const text *relname, ItemPointer tid) currtid_byrelname(PG_FUNCTION_ARGS)
{ {
ItemPointer result = NULL, text *relname = PG_GETARG_TEXT_P(0);
ItemPointer tid = (ItemPointer) PG_GETARG_POINTER(1);
ItemPointer result,
ret; ret;
char *str; char *str;
Relation rel; Relation rel;
if (!relname) str = textout(relname);
return result;
str = textout((text *) relname);
result = (ItemPointer) palloc(sizeof(ItemPointerData)); result = (ItemPointer) palloc(sizeof(ItemPointerData));
ItemPointerSetInvalid(result); ItemPointerSetInvalid(result);
if (rel = heap_openr(str, AccessShareLock), rel) if ((rel = heap_openr(str, AccessShareLock)) != NULL)
{ {
ret = heap_get_latest_tid(rel, SnapshotNow, tid); ret = heap_get_latest_tid(rel, SnapshotNow, tid);
if (ret) if (ret)
...@@ -208,8 +209,9 @@ currtid_byrelname(const text *relname, ItemPointer tid) ...@@ -208,8 +209,9 @@ currtid_byrelname(const text *relname, ItemPointer tid)
heap_close(rel, AccessShareLock); heap_close(rel, AccessShareLock);
} }
else else
elog(ERROR, "Relation %s not found", textout((text *) relname)); elog(ERROR, "Relation %s not found", str);
pfree(str); pfree(str);
return result; PG_RETURN_POINTER(result);
} /* currtid_byrelname() */ }
This diff is collapsed.
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: catversion.h,v 1.26 2000/06/07 04:09:44 momjian Exp $ * $Id: catversion.h,v 1.27 2000/06/09 01:11:10 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -53,6 +53,6 @@ ...@@ -53,6 +53,6 @@
*/ */
/* yyyymmddN */ /* yyyymmddN */
#define CATALOG_VERSION_NO 200006071 #define CATALOG_VERSION_NO 200006081
#endif #endif
This diff is collapsed.
...@@ -7,39 +7,43 @@ ...@@ -7,39 +7,43 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: be-fsstubs.h,v 1.10 2000/01/26 05:58:12 momjian Exp $ * $Id: be-fsstubs.h,v 1.11 2000/06/09 01:11:12 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#ifndef BE_FSSTUBS_H #ifndef BE_FSSTUBS_H
#define BE_FSSTUBS_H #define BE_FSSTUBS_H
/* Redefine names LOread() and LOwrite() to be lowercase to allow calling #include "fmgr.h"
* using the new v6.1 case-insensitive SQL parser. Define macros to allow
* the existing code to stay the same. - tgl 97/05/03 /*
* LO functions available via pg_proc entries
*/ */
extern Datum lo_import(PG_FUNCTION_ARGS);
extern Datum lo_export(PG_FUNCTION_ARGS);
extern Datum lo_creat(PG_FUNCTION_ARGS);
#define LOread(f,l) loread(f,l) extern Datum lo_open(PG_FUNCTION_ARGS);
#define LOwrite(f,b) lowrite(f,b) extern Datum lo_close(PG_FUNCTION_ARGS);
extern Oid lo_import(text *filename); extern Datum loread(PG_FUNCTION_ARGS);
extern int4 lo_export(Oid lobjId, text *filename); extern Datum lowrite(PG_FUNCTION_ARGS);
extern Oid lo_creat(int mode); extern Datum lo_lseek(PG_FUNCTION_ARGS);
extern Datum lo_tell(PG_FUNCTION_ARGS);
extern Datum lo_unlink(PG_FUNCTION_ARGS);
extern int lo_open(Oid lobjId, int mode); /*
extern int lo_close(int fd); * These are not fmgr-callable, but are available to C code.
* Probably these should have had the underscore-free names,
* but too late now...
*/
extern int lo_read(int fd, char *buf, int len); extern int lo_read(int fd, char *buf, int len);
extern int lo_write(int fd, char *buf, int len); extern int lo_write(int fd, char *buf, int len);
extern int lo_lseek(int fd, int offset, int whence);
extern int lo_tell(int fd);
extern int lo_unlink(Oid lobjId);
extern struct varlena *loread(int fd, int len);
extern int lowrite(int fd, struct varlena * wbuf);
/* /*
* Added for buffer leak prevention [ Pascal Andr <andre@via.ecp.fr> ] * Cleanup LOs at xact commit/abort [ Pascal Andr <andre@via.ecp.fr> ]
*/ */
extern void lo_commit(bool isCommit); extern void lo_commit(bool isCommit);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: builtins.h,v 1.114 2000/06/08 22:37:58 momjian Exp $ * $Id: builtins.h,v 1.115 2000/06/09 01:11:14 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -180,7 +180,7 @@ extern Datum btfloat4cmp(PG_FUNCTION_ARGS); ...@@ -180,7 +180,7 @@ extern Datum btfloat4cmp(PG_FUNCTION_ARGS);
extern Datum btfloat8cmp(PG_FUNCTION_ARGS); extern Datum btfloat8cmp(PG_FUNCTION_ARGS);
extern Datum btoidcmp(PG_FUNCTION_ARGS); extern Datum btoidcmp(PG_FUNCTION_ARGS);
extern Datum btoidvectorcmp(PG_FUNCTION_ARGS); extern Datum btoidvectorcmp(PG_FUNCTION_ARGS);
extern int32 btabstimecmp(AbsoluteTime a, AbsoluteTime b); extern Datum btabstimecmp(PG_FUNCTION_ARGS);
extern Datum btcharcmp(PG_FUNCTION_ARGS); extern Datum btcharcmp(PG_FUNCTION_ARGS);
extern Datum btnamecmp(PG_FUNCTION_ARGS); extern Datum btnamecmp(PG_FUNCTION_ARGS);
extern Datum bttextcmp(PG_FUNCTION_ARGS); extern Datum bttextcmp(PG_FUNCTION_ARGS);
...@@ -309,8 +309,8 @@ extern Datum oidsrand(PG_FUNCTION_ARGS); ...@@ -309,8 +309,8 @@ extern Datum oidsrand(PG_FUNCTION_ARGS);
extern Datum userfntest(PG_FUNCTION_ARGS); extern Datum userfntest(PG_FUNCTION_ARGS);
/* not_in.c */ /* not_in.c */
extern bool int4notin(int32 not_in_arg, char *relation_and_attr); extern Datum int4notin(PG_FUNCTION_ARGS);
extern bool oidnotin(Oid the_oid, char *compare); extern Datum oidnotin(PG_FUNCTION_ARGS);
/* oid.c */ /* oid.c */
extern Datum oidvectorin(PG_FUNCTION_ARGS); extern Datum oidvectorin(PG_FUNCTION_ARGS);
...@@ -353,7 +353,7 @@ extern Datum regproctooid(PG_FUNCTION_ARGS); ...@@ -353,7 +353,7 @@ extern Datum regproctooid(PG_FUNCTION_ARGS);
/* ruleutils.c */ /* ruleutils.c */
extern text *pg_get_ruledef(NameData *rname); extern text *pg_get_ruledef(NameData *rname);
extern text *pg_get_viewdef(NameData *rname); extern text *pg_get_viewdef(NameData *rname);
extern text *pg_get_indexdef(Oid indexrelid); extern Datum pg_get_indexdef(PG_FUNCTION_ARGS);
extern NameData *pg_get_userbyid(int32 uid); extern NameData *pg_get_userbyid(int32 uid);
extern char *deparse_expression(Node *expr, List *rangetables, extern char *deparse_expression(Node *expr, List *rangetables,
bool forceprefix); bool forceprefix);
...@@ -407,8 +407,8 @@ extern char *make_greater_string(const char *str, Oid datatype); ...@@ -407,8 +407,8 @@ extern char *make_greater_string(const char *str, Oid datatype);
extern ItemPointer tidin(const char *str); extern ItemPointer tidin(const char *str);
extern char *tidout(ItemPointer itemPtr); extern char *tidout(ItemPointer itemPtr);
extern bool tideq(ItemPointer, ItemPointer); extern bool tideq(ItemPointer, ItemPointer);
extern ItemPointer currtid_byreloid(Oid relOid, ItemPointer); extern Datum currtid_byreloid(PG_FUNCTION_ARGS);
extern ItemPointer currtid_byrelname(const text *relName, ItemPointer); extern Datum currtid_byrelname(PG_FUNCTION_ARGS);
/* varchar.c */ /* varchar.c */
......
...@@ -7,13 +7,16 @@ ...@@ -7,13 +7,16 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: date.h,v 1.3 2000/04/12 17:16:54 momjian Exp $ * $Id: date.h,v 1.4 2000/06/09 01:11:15 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#ifndef DATE_H #ifndef DATE_H
#define DATE_H #define DATE_H
#include "fmgr.h"
typedef int32 DateADT; typedef int32 DateADT;
typedef float8 TimeADT; typedef float8 TimeADT;
...@@ -25,56 +28,77 @@ typedef struct ...@@ -25,56 +28,77 @@ typedef struct
int4 zone; /* numeric time zone, in seconds */ int4 zone; /* numeric time zone, in seconds */
} TimeTzADT; } TimeTzADT;
/*
* Macros for fmgr-callable functions.
*
* For TimeADT, we make use of the same support routines as for float8.
* Therefore TimeADT is pass-by-reference if and only if float8 is!
*/
#define DatumGetDateADT(X) ((DateADT) DatumGetInt32(X))
#define DatumGetTimeADT(X) ((TimeADT) DatumGetFloat8(X))
#define DatumGetTimeTzADTP(X) ((TimeTzADT *) DatumGetPointer(X))
#define DateADTGetDatum(X) Int32GetDatum(X)
#define TimeADTGetDatum(X) Float8GetDatum(X)
#define TimeTzADTPGetDatum(X) PointerGetDatum(X)
#define PG_GETARG_DATEADT(n) DatumGetDateADT(PG_GETARG_DATUM(n))
#define PG_GETARG_TIMEADT(n) DatumGetTimeADT(PG_GETARG_DATUM(n))
#define PG_GETARG_TIMETZADT_P(n) DatumGetTimeTzADTP(PG_GETARG_DATUM(n))
#define PG_RETURN_DATEADT(x) return DateADTGetDatum(x)
#define PG_RETURN_TIMEADT(x) return TimeADTGetDatum(x)
#define PG_RETURN_TIMETZADT_P(x) return TimeTzADTPGetDatum(x)
/* date.c */ /* date.c */
extern DateADT date_in(char *datestr); extern Datum date_in(PG_FUNCTION_ARGS);
extern char *date_out(DateADT dateVal); extern Datum date_out(PG_FUNCTION_ARGS);
extern bool date_eq(DateADT dateVal1, DateADT dateVal2); extern Datum date_eq(PG_FUNCTION_ARGS);
extern bool date_ne(DateADT dateVal1, DateADT dateVal2); extern Datum date_ne(PG_FUNCTION_ARGS);
extern bool date_lt(DateADT dateVal1, DateADT dateVal2); extern Datum date_lt(PG_FUNCTION_ARGS);
extern bool date_le(DateADT dateVal1, DateADT dateVal2); extern Datum date_le(PG_FUNCTION_ARGS);
extern bool date_gt(DateADT dateVal1, DateADT dateVal2); extern Datum date_gt(PG_FUNCTION_ARGS);
extern bool date_ge(DateADT dateVal1, DateADT dateVal2); extern Datum date_ge(PG_FUNCTION_ARGS);
extern int date_cmp(DateADT dateVal1, DateADT dateVal2); extern Datum date_cmp(PG_FUNCTION_ARGS);
extern DateADT date_larger(DateADT dateVal1, DateADT dateVal2); extern Datum date_larger(PG_FUNCTION_ARGS);
extern DateADT date_smaller(DateADT dateVal1, DateADT dateVal2); extern Datum date_smaller(PG_FUNCTION_ARGS);
extern int32 date_mi(DateADT dateVal1, DateADT dateVal2); extern Datum date_mi(PG_FUNCTION_ARGS);
extern DateADT date_pli(DateADT dateVal, int32 days); extern Datum date_pli(PG_FUNCTION_ARGS);
extern DateADT date_mii(DateADT dateVal, int32 days); extern Datum date_mii(PG_FUNCTION_ARGS);
extern Timestamp *date_timestamp(DateADT date); extern Datum date_timestamp(PG_FUNCTION_ARGS);
extern DateADT timestamp_date(Timestamp *timestamp); extern Datum timestamp_date(PG_FUNCTION_ARGS);
extern Timestamp *datetime_timestamp(DateADT date, TimeADT *time); extern Datum datetime_timestamp(PG_FUNCTION_ARGS);
extern DateADT abstime_date(AbsoluteTime abstime); extern Datum abstime_date(PG_FUNCTION_ARGS);
extern TimeADT *time_in(char *timestr); extern Datum time_in(PG_FUNCTION_ARGS);
extern char *time_out(TimeADT *time); extern Datum time_out(PG_FUNCTION_ARGS);
extern bool time_eq(TimeADT *time1, TimeADT *time2); extern Datum time_eq(PG_FUNCTION_ARGS);
extern bool time_ne(TimeADT *time1, TimeADT *time2); extern Datum time_ne(PG_FUNCTION_ARGS);
extern bool time_lt(TimeADT *time1, TimeADT *time2); extern Datum time_lt(PG_FUNCTION_ARGS);
extern bool time_le(TimeADT *time1, TimeADT *time2); extern Datum time_le(PG_FUNCTION_ARGS);
extern bool time_gt(TimeADT *time1, TimeADT *time2); extern Datum time_gt(PG_FUNCTION_ARGS);
extern bool time_ge(TimeADT *time1, TimeADT *time2); extern Datum time_ge(PG_FUNCTION_ARGS);
extern int time_cmp(TimeADT *time1, TimeADT *time2); extern Datum time_cmp(PG_FUNCTION_ARGS);
extern bool overlaps_time(TimeADT *time1, TimeADT *time2, extern Datum overlaps_time(PG_FUNCTION_ARGS);
TimeADT *time3, TimeADT *time4); extern Datum time_larger(PG_FUNCTION_ARGS);
extern TimeADT *time_larger(TimeADT *time1, TimeADT *time2); extern Datum time_smaller(PG_FUNCTION_ARGS);
extern TimeADT *time_smaller(TimeADT *time1, TimeADT *time2); extern Datum timestamp_time(PG_FUNCTION_ARGS);
extern TimeADT *timestamp_time(Timestamp *timestamp); extern Datum time_interval(PG_FUNCTION_ARGS);
extern Interval *time_interval(TimeADT *time);
extern TimeTzADT *timetz_in(char *timestr); extern Datum timetz_in(PG_FUNCTION_ARGS);
extern char *timetz_out(TimeTzADT *time); extern Datum timetz_out(PG_FUNCTION_ARGS);
extern bool timetz_eq(TimeTzADT *time1, TimeTzADT *time2); extern Datum timetz_eq(PG_FUNCTION_ARGS);
extern bool timetz_ne(TimeTzADT *time1, TimeTzADT *time2); extern Datum timetz_ne(PG_FUNCTION_ARGS);
extern bool timetz_lt(TimeTzADT *time1, TimeTzADT *time2); extern Datum timetz_lt(PG_FUNCTION_ARGS);
extern bool timetz_le(TimeTzADT *time1, TimeTzADT *time2); extern Datum timetz_le(PG_FUNCTION_ARGS);
extern bool timetz_gt(TimeTzADT *time1, TimeTzADT *time2); extern Datum timetz_gt(PG_FUNCTION_ARGS);
extern bool timetz_ge(TimeTzADT *time1, TimeTzADT *time2); extern Datum timetz_ge(PG_FUNCTION_ARGS);
extern int timetz_cmp(TimeTzADT *time1, TimeTzADT *time2); extern Datum timetz_cmp(PG_FUNCTION_ARGS);
extern bool overlaps_timetz(TimeTzADT *time1, TimeTzADT *time2, extern Datum overlaps_timetz(PG_FUNCTION_ARGS);
TimeTzADT *time3, TimeTzADT *time4); extern Datum timetz_larger(PG_FUNCTION_ARGS);
extern TimeTzADT *timetz_larger(TimeTzADT *time1, TimeTzADT *time2); extern Datum timetz_smaller(PG_FUNCTION_ARGS);
extern TimeTzADT *timetz_smaller(TimeTzADT *time1, TimeTzADT *time2); extern Datum timestamp_timetz(PG_FUNCTION_ARGS);
extern TimeTzADT *timestamp_timetz(Timestamp *timestamp); extern Datum datetimetz_timestamp(PG_FUNCTION_ARGS);
extern Timestamp *datetimetz_timestamp(DateADT date, TimeTzADT *time);
#endif /* DATE_H */ #endif /* DATE_H */
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
/* ----------------------------------------------------------------------- /* -----------------------------------------------------------------------
* formatting.h * formatting.h
* *
* $Id: formatting.h,v 1.4 2000/04/12 17:16:55 momjian Exp $ * $Id: formatting.h,v 1.5 2000/06/09 01:11:15 tgl Exp $
* *
* *
* Portions Copyright (c) 1999-2000, PostgreSQL, Inc * Portions Copyright (c) 1999-2000, PostgreSQL, Inc
...@@ -18,9 +18,12 @@ ...@@ -18,9 +18,12 @@
#ifndef _FORMATTING_H_ #ifndef _FORMATTING_H_
#define _FORMATTING_H_ #define _FORMATTING_H_
extern text *timestamp_to_char(Timestamp *dt, text *fmt); #include "fmgr.h"
extern Timestamp *to_timestamp(text *date_str, text *fmt);
extern DateADT to_date(text *date_str, text *fmt);
extern Datum timestamp_to_char(PG_FUNCTION_ARGS);
extern Datum to_timestamp(PG_FUNCTION_ARGS);
extern Datum to_date(PG_FUNCTION_ARGS);
extern Numeric numeric_to_number(text *value, text *fmt); extern Numeric numeric_to_number(text *value, text *fmt);
extern text *numeric_to_char(Numeric value, text *fmt); extern text *numeric_to_char(Numeric value, text *fmt);
extern text *int4_to_char(int32 value, text *fmt); extern text *int4_to_char(int32 value, text *fmt);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: nabstime.h,v 1.25 2000/04/12 17:16:55 momjian Exp $ * $Id: nabstime.h,v 1.26 2000/06/09 01:11:15 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -15,13 +15,15 @@ ...@@ -15,13 +15,15 @@
#define NABSTIME_H #define NABSTIME_H
#include <time.h> #include <time.h>
#include "fmgr.h"
#include "utils/timestamp.h" #include "utils/timestamp.h"
#include "utils/datetime.h" #include "utils/datetime.h"
/* ---------------------------------------------------------------- /* ----------------------------------------------------------------
* time types + support macros
* *
* time types + support macros
* *
* ---------------------------------------------------------------- * ----------------------------------------------------------------
*/ */
...@@ -39,8 +41,28 @@ typedef struct ...@@ -39,8 +41,28 @@ typedef struct
int32 status; int32 status;
AbsoluteTime data[2]; AbsoluteTime data[2];
} TimeIntervalData; } TimeIntervalData;
typedef TimeIntervalData *TimeInterval; typedef TimeIntervalData *TimeInterval;
/*
* Macros for fmgr-callable functions.
*/
#define DatumGetAbsoluteTime(X) ((AbsoluteTime) DatumGetInt32(X))
#define DatumGetRelativeTime(X) ((RelativeTime) DatumGetInt32(X))
#define DatumGetTimeInterval(X) ((TimeInterval) DatumGetPointer(X))
#define AbsoluteTimeGetDatum(X) Int32GetDatum(X)
#define RelativeTimeGetDatum(X) Int32GetDatum(X)
#define TimeIntervalGetDatum(X) PointerGetDatum(X)
#define PG_GETARG_ABSOLUTETIME(n) DatumGetAbsoluteTime(PG_GETARG_DATUM(n))
#define PG_GETARG_RELATIVETIME(n) DatumGetRelativeTime(PG_GETARG_DATUM(n))
#define PG_GETARG_TIMEINTERVAL(n) DatumGetTimeInterval(PG_GETARG_DATUM(n))
#define PG_RETURN_ABSOLUTETIME(x) return AbsoluteTimeGetDatum(x)
#define PG_RETURN_RELATIVETIME(x) return RelativeTimeGetDatum(x)
#define PG_RETURN_TIMEINTERVAL(x) return TimeIntervalGetDatum(x)
/* /*
* Reserved values * Reserved values
* Epoch is Unix system time zero, but needs to be kept as a reserved * Epoch is Unix system time zero, but needs to be kept as a reserved
...@@ -78,21 +100,9 @@ typedef TimeIntervalData *TimeInterval; ...@@ -78,21 +100,9 @@ typedef TimeIntervalData *TimeInterval;
((bool) (((AbsoluteTime) time) < NOEND_ABSTIME && \ ((bool) (((AbsoluteTime) time) < NOEND_ABSTIME && \
((AbsoluteTime) time) > NOSTART_ABSTIME)) ((AbsoluteTime) time) > NOSTART_ABSTIME))
/* have to include this because EPOCH_ABSTIME used to be invalid - yuk */
#define AbsoluteTimeIsBackwardCompatiblyValid(time) \
((bool) (((AbsoluteTime) time) != INVALID_ABSTIME && \
((AbsoluteTime) time) > EPOCH_ABSTIME))
#define AbsoluteTimeIsBackwardCompatiblyReal(time) \
((bool) (((AbsoluteTime) time) < NOEND_ABSTIME && \
((AbsoluteTime) time) > NOSTART_ABSTIME && \
((AbsoluteTime) time) > EPOCH_ABSTIME))
#define RelativeTimeIsValid(time) \ #define RelativeTimeIsValid(time) \
((bool) (((RelativeTime) time) != INVALID_RELTIME)) ((bool) (((RelativeTime) time) != INVALID_RELTIME))
extern AbsoluteTime GetCurrentAbsoluteTime(void);
/* /*
* getSystemTime * getSystemTime
* Returns system time. * Returns system time.
...@@ -104,62 +114,62 @@ extern AbsoluteTime GetCurrentAbsoluteTime(void); ...@@ -104,62 +114,62 @@ extern AbsoluteTime GetCurrentAbsoluteTime(void);
/* /*
* nabstime.c prototypes * nabstime.c prototypes
*/ */
extern AbsoluteTime nabstimein(char *timestr); extern Datum nabstimein(PG_FUNCTION_ARGS);
extern char *nabstimeout(AbsoluteTime time); extern Datum nabstimeout(PG_FUNCTION_ARGS);
extern bool abstimeeq(AbsoluteTime t1, AbsoluteTime t2); extern Datum abstimeeq(PG_FUNCTION_ARGS);
extern bool abstimene(AbsoluteTime t1, AbsoluteTime t2); extern Datum abstimene(PG_FUNCTION_ARGS);
extern bool abstimelt(AbsoluteTime t1, AbsoluteTime t2); extern Datum abstimelt(PG_FUNCTION_ARGS);
extern bool abstimegt(AbsoluteTime t1, AbsoluteTime t2); extern Datum abstimegt(PG_FUNCTION_ARGS);
extern bool abstimele(AbsoluteTime t1, AbsoluteTime t2); extern Datum abstimele(PG_FUNCTION_ARGS);
extern bool abstimege(AbsoluteTime t1, AbsoluteTime t2); extern Datum abstimege(PG_FUNCTION_ARGS);
extern bool abstime_finite(AbsoluteTime time); extern Datum abstime_finite(PG_FUNCTION_ARGS);
extern AbsoluteTime timestamp_abstime(Timestamp *timestamp); extern Datum timestamp_abstime(PG_FUNCTION_ARGS);
extern Timestamp *abstime_timestamp(AbsoluteTime abstime); extern Datum abstime_timestamp(PG_FUNCTION_ARGS);
extern Datum reltimein(PG_FUNCTION_ARGS);
extern Datum reltimeout(PG_FUNCTION_ARGS);
extern Datum tintervalin(PG_FUNCTION_ARGS);
extern Datum tintervalout(PG_FUNCTION_ARGS);
extern Datum interval_reltime(PG_FUNCTION_ARGS);
extern Datum reltime_interval(PG_FUNCTION_ARGS);
extern Datum mktinterval(PG_FUNCTION_ARGS);
extern Datum timepl(PG_FUNCTION_ARGS);
extern Datum timemi(PG_FUNCTION_ARGS);
extern Datum intinterval(PG_FUNCTION_ARGS);
extern Datum tintervalrel(PG_FUNCTION_ARGS);
extern Datum timenow(PG_FUNCTION_ARGS);
extern Datum reltimeeq(PG_FUNCTION_ARGS);
extern Datum reltimene(PG_FUNCTION_ARGS);
extern Datum reltimelt(PG_FUNCTION_ARGS);
extern Datum reltimegt(PG_FUNCTION_ARGS);
extern Datum reltimele(PG_FUNCTION_ARGS);
extern Datum reltimege(PG_FUNCTION_ARGS);
extern Datum tintervalsame(PG_FUNCTION_ARGS);
extern Datum tintervaleq(PG_FUNCTION_ARGS);
extern Datum tintervalne(PG_FUNCTION_ARGS);
extern Datum tintervallt(PG_FUNCTION_ARGS);
extern Datum tintervalgt(PG_FUNCTION_ARGS);
extern Datum tintervalle(PG_FUNCTION_ARGS);
extern Datum tintervalge(PG_FUNCTION_ARGS);
extern Datum tintervalleneq(PG_FUNCTION_ARGS);
extern Datum tintervallenne(PG_FUNCTION_ARGS);
extern Datum tintervallenlt(PG_FUNCTION_ARGS);
extern Datum tintervallengt(PG_FUNCTION_ARGS);
extern Datum tintervallenle(PG_FUNCTION_ARGS);
extern Datum tintervallenge(PG_FUNCTION_ARGS);
extern Datum tintervalct(PG_FUNCTION_ARGS);
extern Datum tintervalov(PG_FUNCTION_ARGS);
extern Datum tintervalstart(PG_FUNCTION_ARGS);
extern Datum tintervalend(PG_FUNCTION_ARGS);
extern Datum int4reltime(PG_FUNCTION_ARGS);
extern Datum timeofday(PG_FUNCTION_ARGS);
/* non-fmgr-callable support routines */
extern AbsoluteTime GetCurrentAbsoluteTime(void);
extern bool AbsoluteTimeIsBefore(AbsoluteTime time1, AbsoluteTime time2); extern bool AbsoluteTimeIsBefore(AbsoluteTime time1, AbsoluteTime time2);
extern void abstime2tm(AbsoluteTime time, int *tzp, struct tm * tm, char *tzn); extern void abstime2tm(AbsoluteTime time, int *tzp, struct tm * tm, char *tzn);
extern RelativeTime reltimein(char *timestring);
extern char *reltimeout(RelativeTime timevalue);
extern TimeInterval tintervalin(char *intervalstr);
extern char *tintervalout(TimeInterval interval);
extern RelativeTime interval_reltime(Interval *interval);
extern Interval *reltime_interval(RelativeTime reltime);
extern TimeInterval mktinterval(AbsoluteTime t1, AbsoluteTime t2);
extern AbsoluteTime timepl(AbsoluteTime t1, RelativeTime t2);
extern AbsoluteTime timemi(AbsoluteTime t1, RelativeTime t2);
/* extern RelativeTime abstimemi(AbsoluteTime t1, AbsoluteTime t2); static*/
extern int intinterval(AbsoluteTime t, TimeInterval interval);
extern RelativeTime tintervalrel(TimeInterval interval);
extern AbsoluteTime timenow(void);
extern bool reltimeeq(RelativeTime t1, RelativeTime t2);
extern bool reltimene(RelativeTime t1, RelativeTime t2);
extern bool reltimelt(RelativeTime t1, RelativeTime t2);
extern bool reltimegt(RelativeTime t1, RelativeTime t2);
extern bool reltimele(RelativeTime t1, RelativeTime t2);
extern bool reltimege(RelativeTime t1, RelativeTime t2);
extern bool tintervalsame(TimeInterval i1, TimeInterval i2);
extern bool tintervaleq(TimeInterval i1, TimeInterval i2);
extern bool tintervalne(TimeInterval i1, TimeInterval i2);
extern bool tintervallt(TimeInterval i1, TimeInterval i2);
extern bool tintervalgt(TimeInterval i1, TimeInterval i2);
extern bool tintervalle(TimeInterval i1, TimeInterval i2);
extern bool tintervalge(TimeInterval i1, TimeInterval i2);
extern bool tintervalleneq(TimeInterval i, RelativeTime t);
extern bool tintervallenne(TimeInterval i, RelativeTime t);
extern bool tintervallenlt(TimeInterval i, RelativeTime t);
extern bool tintervallengt(TimeInterval i, RelativeTime t);
extern bool tintervallenle(TimeInterval i, RelativeTime t);
extern bool tintervallenge(TimeInterval i, RelativeTime t);
extern bool tintervalct(TimeInterval i1, TimeInterval i2);
extern bool tintervalov(TimeInterval i1, TimeInterval i2);
extern AbsoluteTime tintervalstart(TimeInterval i);
extern AbsoluteTime tintervalend(TimeInterval i);
extern int32 int4reltime(int32 timevalue);
extern text *timeofday(void);
#endif /* NABSTIME_H */ #endif /* NABSTIME_H */
...@@ -7,17 +7,20 @@ ...@@ -7,17 +7,20 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: sets.h,v 1.6 2000/01/26 05:58:38 momjian Exp $ * $Id: sets.h,v 1.7 2000/06/09 01:11:15 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#ifndef SETS_H #ifndef SETS_H
#define SETS_H #define SETS_H
#include "fmgr.h"
/* Temporary name of set, before SetDefine changes it. */ /* Temporary name of set, before SetDefine changes it. */
#define GENERICSETNAME "zyxset" #define GENERICSETNAME "zyxset"
extern Oid SetDefine(char *querystr, char *typename); extern Oid SetDefine(char *querystr, char *typename);
extern int seteval(Oid funcoid); extern Datum seteval(PG_FUNCTION_ARGS);
#endif /* SETS_H */ #endif /* SETS_H */
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: timestamp.h,v 1.5 2000/06/08 22:37:58 momjian Exp $ * $Id: timestamp.h,v 1.6 2000/06/09 01:11:15 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -17,6 +17,9 @@ ...@@ -17,6 +17,9 @@
#include <math.h> #include <math.h>
#include <limits.h> #include <limits.h>
#include "fmgr.h"
/* /*
* Timestamp represents absolute time. * Timestamp represents absolute time.
* Interval represents delta time. Keep track of months (and years) * Interval represents delta time. Keep track of months (and years)
...@@ -38,6 +41,25 @@ typedef struct ...@@ -38,6 +41,25 @@ typedef struct
} Interval; } Interval;
/*
* Macros for fmgr-callable functions.
*
* For Timestamp, we make use of the same support routines as for float8.
* Therefore Timestamp is pass-by-reference if and only if float8 is!
*/
#define DatumGetTimestamp(X) ((Timestamp) DatumGetFloat8(X))
#define DatumGetIntervalP(X) ((Interval *) DatumGetPointer(X))
#define TimestampGetDatum(X) Float8GetDatum(X)
#define IntervalPGetDatum(X) PointerGetDatum(X)
#define PG_GETARG_TIMESTAMP(n) DatumGetTimestamp(PG_GETARG_DATUM(n))
#define PG_GETARG_INTERVAL_P(n) DatumGetIntervalP(PG_GETARG_DATUM(n))
#define PG_RETURN_TIMESTAMP(x) return TimestampGetDatum(x)
#define PG_RETURN_INTERVAL_P(x) return IntervalPGetDatum(x)
#ifdef NAN #ifdef NAN
#define DT_INVALID (NAN) #define DT_INVALID (NAN)
#else #else
...@@ -105,59 +127,63 @@ extern int timestamp_is_epoch(double j); ...@@ -105,59 +127,63 @@ extern int timestamp_is_epoch(double j);
* timestamp.c prototypes * timestamp.c prototypes
*/ */
extern Timestamp *timestamp_in(char *str); extern Datum timestamp_in(PG_FUNCTION_ARGS);
extern char *timestamp_out(Timestamp *dt); extern Datum timestamp_out(PG_FUNCTION_ARGS);
extern bool timestamp_eq(Timestamp *dt1, Timestamp *dt2); extern Datum timestamp_eq(PG_FUNCTION_ARGS);
extern bool timestamp_ne(Timestamp *dt1, Timestamp *dt2); extern Datum timestamp_ne(PG_FUNCTION_ARGS);
extern bool timestamp_lt(Timestamp *dt1, Timestamp *dt2); extern Datum timestamp_lt(PG_FUNCTION_ARGS);
extern bool timestamp_le(Timestamp *dt1, Timestamp *dt2); extern Datum timestamp_le(PG_FUNCTION_ARGS);
extern bool timestamp_ge(Timestamp *dt1, Timestamp *dt2); extern Datum timestamp_ge(PG_FUNCTION_ARGS);
extern bool timestamp_gt(Timestamp *dt1, Timestamp *dt2); extern Datum timestamp_gt(PG_FUNCTION_ARGS);
extern bool timestamp_finite(Timestamp *timestamp); extern Datum timestamp_finite(PG_FUNCTION_ARGS);
extern int timestamp_cmp(Timestamp *dt1, Timestamp *dt2); extern Datum timestamp_cmp(PG_FUNCTION_ARGS);
extern Timestamp *timestamp_smaller(Timestamp *dt1, Timestamp *dt2); extern Datum timestamp_smaller(PG_FUNCTION_ARGS);
extern Timestamp *timestamp_larger(Timestamp *dt1, Timestamp *dt2); extern Datum timestamp_larger(PG_FUNCTION_ARGS);
extern Interval *interval_in(char *str); extern Datum interval_in(PG_FUNCTION_ARGS);
extern char *interval_out(Interval *span); extern Datum interval_out(PG_FUNCTION_ARGS);
extern bool interval_eq(Interval *span1, Interval *span2); extern Datum interval_eq(PG_FUNCTION_ARGS);
extern bool interval_ne(Interval *span1, Interval *span2); extern Datum interval_ne(PG_FUNCTION_ARGS);
extern bool interval_lt(Interval *span1, Interval *span2); extern Datum interval_lt(PG_FUNCTION_ARGS);
extern bool interval_le(Interval *span1, Interval *span2); extern Datum interval_le(PG_FUNCTION_ARGS);
extern bool interval_ge(Interval *span1, Interval *span2); extern Datum interval_ge(PG_FUNCTION_ARGS);
extern bool interval_gt(Interval *span1, Interval *span2); extern Datum interval_gt(PG_FUNCTION_ARGS);
extern bool interval_finite(Interval *span); extern Datum interval_finite(PG_FUNCTION_ARGS);
extern int interval_cmp(Interval *span1, Interval *span2); extern Datum interval_cmp(PG_FUNCTION_ARGS);
extern Interval *interval_smaller(Interval *span1, Interval *span2); extern Datum interval_smaller(PG_FUNCTION_ARGS);
extern Interval *interval_larger(Interval *span1, Interval *span2); extern Datum interval_larger(PG_FUNCTION_ARGS);
extern text *timestamp_text(Timestamp *timestamp); extern Datum timestamp_text(PG_FUNCTION_ARGS);
extern Timestamp *text_timestamp(text *str); extern Datum text_timestamp(PG_FUNCTION_ARGS);
extern text *interval_text(Interval *interval); extern Datum interval_text(PG_FUNCTION_ARGS);
extern Interval *text_interval(text *str); extern Datum text_interval(PG_FUNCTION_ARGS);
extern Timestamp *timestamp_trunc(text *units, Timestamp *timestamp); extern Datum timestamp_trunc(PG_FUNCTION_ARGS);
extern Interval *interval_trunc(text *units, Interval *interval); extern Datum interval_trunc(PG_FUNCTION_ARGS);
extern float64 timestamp_part(text *units, Timestamp *timestamp); extern Datum timestamp_part(PG_FUNCTION_ARGS);
extern float64 interval_part(text *units, Interval *interval); extern Datum interval_part(PG_FUNCTION_ARGS);
extern text *timestamp_zone(text *zone, Timestamp *timestamp); extern Datum timestamp_zone(PG_FUNCTION_ARGS);
extern Interval *interval_um(Interval *span); extern Datum interval_um(PG_FUNCTION_ARGS);
extern Interval *interval_pl(Interval *span1, Interval *span2); extern Datum interval_pl(PG_FUNCTION_ARGS);
extern Interval *interval_mi(Interval *span1, Interval *span2); extern Datum interval_mi(PG_FUNCTION_ARGS);
extern Interval *interval_mul(Interval *span1, float8 *factor); extern Datum interval_mul(PG_FUNCTION_ARGS);
extern Interval *mul_d_interval(float8 *factor, Interval *span1); extern Datum mul_d_interval(PG_FUNCTION_ARGS);
extern Interval *interval_div(Interval *span1, float8 *factor); extern Datum interval_div(PG_FUNCTION_ARGS);
extern Interval *timestamp_mi(Timestamp *dt1, Timestamp *dt2); extern Datum timestamp_mi(PG_FUNCTION_ARGS);
extern Timestamp *timestamp_pl_span(Timestamp *dt, Interval *span); extern Datum timestamp_pl_span(PG_FUNCTION_ARGS);
extern Timestamp *timestamp_mi_span(Timestamp *dt, Interval *span); extern Datum timestamp_mi_span(PG_FUNCTION_ARGS);
extern Interval *timestamp_age(Timestamp *dt1, Timestamp *dt2); extern Datum timestamp_age(PG_FUNCTION_ARGS);
extern bool overlaps_timestamp(Timestamp *dt1, Timestamp *dt2, Timestamp *dt3, Timestamp *dt4); extern Datum overlaps_timestamp(PG_FUNCTION_ARGS);
extern Datum now(PG_FUNCTION_ARGS);
/* Internal routines (not fmgr-callable) */
extern int tm2timestamp(struct tm * tm, double fsec, int *tzp, Timestamp *dt); extern int tm2timestamp(struct tm * tm, double fsec, int *tzp, Timestamp *dt);
extern int timestamp2tm(Timestamp dt, int *tzp, struct tm * tm, double *fsec, char **tzn); extern int timestamp2tm(Timestamp dt, int *tzp, struct tm * tm,
double *fsec, char **tzn);
extern Timestamp SetTimestamp(Timestamp timestamp); extern Timestamp SetTimestamp(Timestamp timestamp);
extern Timestamp *now(void);
#endif /* TIMESTAMP_H */ #endif /* TIMESTAMP_H */
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/tutorial/Attic/beard.c,v 1.3 2000/01/26 05:58:51 momjian Exp $ * $Header: /cvsroot/pgsql/src/tutorial/Attic/beard.c,v 1.4 2000/06/09 01:11:16 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -34,7 +34,10 @@ beard(Oid picture) ...@@ -34,7 +34,10 @@ beard(Oid picture)
char buf[BUFSIZE]; char buf[BUFSIZE];
int cc; int cc;
if ((pic_fd = lo_open(picture, INV_READ)) == -1) pic_fd = DatumGetInt32(DirectFunctionCall2(lo_open,
ObjectIdGetDatum(picture),
Int32GetDatum(INV_READ)));
if (pic_fd < 0)
elog(ERROR, "Cannot access picture large object"); elog(ERROR, "Cannot access picture large object");
if (lo_read(pic_fd, (char *) &ihdr, sizeof(ihdr)) != sizeof(ihdr)) if (lo_read(pic_fd, (char *) &ihdr, sizeof(ihdr)) != sizeof(ihdr))
...@@ -45,21 +48,31 @@ beard(Oid picture) ...@@ -45,21 +48,31 @@ beard(Oid picture)
/* /*
* new large object * new large object
*/ */
if ((beard = lo_creat(INV_MD)) == 0) /* ?? is this right? */ beard = DatumGetObjectId(DirectFunctionCall1(lo_creat,
Int32GetDatum(INV_MD)));
if (beard == InvalidOid)
elog(ERROR, "Cannot create new large object"); elog(ERROR, "Cannot create new large object");
if ((beard_fd = lo_open(beard, INV_WRITE)) == -1) beard_fd = DatumGetInt32(DirectFunctionCall2(lo_open,
ObjectIdGetDatum(beard),
Int32GetDatum(INV_WRITE)));
if (beard_fd < 0)
elog(ERROR, "Cannot access beard large object"); elog(ERROR, "Cannot access beard large object");
lo_lseek(pic_fd, beardOffset, SET_CUR); if (DatumGetInt32(DirectFunctionCall3(lo_lseek,
Int32GetDatum(pic_fd),
Int32GetDatum(beardOffset),
Int32GetDatum(SEEK_SET))) < 0)
elog(ERROR, "Cannot seek in picture large object");
while ((cc = lo_read(pic_fd, buf, BUFSIZE)) > 0) while ((cc = lo_read(pic_fd, buf, BUFSIZE)) > 0)
{ {
if (lo_write(beard_fd, buf, cc) != cc) if (lo_write(beard_fd, buf, cc) != cc)
elog(ERROR, "error while writing large object"); elog(ERROR, "error while writing large object");
} }
lo_close(pic_fd); DirectFunctionCall1(lo_close, Int32GetDatum(pic_fd));
lo_close(beard_fd); DirectFunctionCall1(lo_close, Int32GetDatum(beard_fd));
return beard; return beard;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment