diff options
author | Marc G. Fournier <scrappy@hub.org> | 1996-07-09 06:22:35 +0000 |
---|---|---|
committer | Marc G. Fournier <scrappy@hub.org> | 1996-07-09 06:22:35 +0000 |
commit | d31084e9d1118b25fd16580d9d8c2924b5740dff (patch) | |
tree | 3179e66307d54df9c7b966543550e601eb55e668 /src/backend/utils/adt/regproc.c | |
download | postgresql-d31084e9d1118b25fd16580d9d8c2924b5740dff.tar.gz postgresql-d31084e9d1118b25fd16580d9d8c2924b5740dff.zip |
Postgres95 1.01 Distribution - Virgin SourcesPG95-1_01
Diffstat (limited to 'src/backend/utils/adt/regproc.c')
-rw-r--r-- | src/backend/utils/adt/regproc.c | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/src/backend/utils/adt/regproc.c b/src/backend/utils/adt/regproc.c new file mode 100644 index 00000000000..071573fdccc --- /dev/null +++ b/src/backend/utils/adt/regproc.c @@ -0,0 +1,159 @@ +/*------------------------------------------------------------------------- + * + * regproc.c-- + * Functions for the built-in type "RegProcedure". + * + * Copyright (c) 1994, Regents of the University of California + * + * + * IDENTIFICATION + * $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.1.1.1 1996/07/09 06:22:05 scrappy Exp $ + * + *------------------------------------------------------------------------- + */ +#include <string.h> +#include "postgres.h" +#include "access/heapam.h" +#include "access/relscan.h" +#include "access/skey.h" +#include "utils/tqual.h" /* for NowTimeQual */ +#include "fmgr.h" +#include "utils/elog.h" +#include "utils/palloc.h" + +#include "catalog/catname.h" +#include "utils/builtins.h" /* where function declarations go */ + +/***************************************************************************** + * USER I/O ROUTINES * + *****************************************************************************/ + +/* + * regprocin - converts "proname" to proid + * + * proid of NULL signifies unknown + */ +int32 regprocin(char *proname) +{ + Relation proc; + HeapScanDesc procscan; + HeapTuple proctup; + ScanKeyData key; + RegProcedure result; + bool isnull; + + if (proname == NULL) + return(0); + proc = heap_openr(ProcedureRelationName); + if (!RelationIsValid(proc)) { + elog(WARN, "regprocin: could not open %s", + ProcedureRelationName); + return(0); + } + ScanKeyEntryInitialize(&key, + (bits16)0, + (AttrNumber)1, + (RegProcedure)F_CHAR16EQ, + (Datum)proname); + + procscan = heap_beginscan(proc, 0, NowTimeQual, 1, &key); + if (!HeapScanIsValid(procscan)) { + heap_close(proc); + elog(WARN, "regprocin: could not being scan of %s", + ProcedureRelationName); + return(0); + } + proctup = heap_getnext(procscan, 0, (Buffer *) NULL); + switch (HeapTupleIsValid(proctup)) { + case 1: + result = (RegProcedure) heap_getattr(proctup, + InvalidBuffer, + ObjectIdAttributeNumber, + RelationGetTupleDescriptor(proc), + &isnull); + if (isnull) { + elog(FATAL, "regprocin: null procedure %s", proname); + } + break; + case 0: + result = (RegProcedure) 0; +#ifdef EBUG + elog(DEBUG, "regprocin: no such procedure %s", proname); +#endif /* defined(EBUG) */ + } + heap_endscan(procscan); + heap_close(proc); + return((int32) result); +} + +/* + * regprocout - converts proid to "proname" + */ +char *regprocout(RegProcedure proid) +{ + Relation proc; + HeapScanDesc procscan; + HeapTuple proctup; + char *result; + ScanKeyData key; + + result = (char *)palloc(NAMEDATALEN); + proc = heap_openr(ProcedureRelationName); + if (!RelationIsValid(proc)) { + elog(WARN, "regprocout: could not open %s", + ProcedureRelationName); + return(0); + } + ScanKeyEntryInitialize(&key, + (bits16)0, + (AttrNumber)ObjectIdAttributeNumber, + (RegProcedure)F_INT4EQ, + (Datum)proid); + + procscan = heap_beginscan(proc, 0, NowTimeQual, 1, &key); + if (!HeapScanIsValid(procscan)) { + heap_close(proc); + elog(WARN, "regprocin: could not being scan of %s", + ProcedureRelationName); + return(0); + } + proctup = heap_getnext(procscan, 0, (Buffer *)NULL); + switch (HeapTupleIsValid(proctup)) { + char *s; + bool isnull; + case 1: + s = (char *) heap_getattr(proctup, InvalidBuffer, 1, + RelationGetTupleDescriptor(proc), &isnull); + if (!isnull) { + strncpy(result, s, 16); + break; + } + elog(FATAL, "regprocout: null procedure %d", proid); + /*FALLTHROUGH*/ + case 0: + memset(result, 0, 16); + result[0] = '-'; +#ifdef EBUG + elog(DEBUG, "regprocout: no such procedure %d", proid); +#endif /* defined(EBUG) */ + } + heap_endscan(procscan); + heap_close(proc); + return(result); +} + + +/***************************************************************************** + * PUBLIC ROUTINES * + *****************************************************************************/ + +Oid RegprocToOid(RegProcedure rp) +{ + return (Oid)rp; +} + +/* (see int.c for comparison/operation routines) */ + + +/* ========== PRIVATE ROUTINES ========== */ + |