1 /*-------------------------------------------------------------------------
4 * Functions for the built-in type "RegProcedure".
6 * Copyright (c) 1994, Regents of the University of California
10 * $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.21 1998/07/27 19:38:19 vadim Exp $
12 *-------------------------------------------------------------------------
16 #include "access/heapam.h"
17 #include "access/relscan.h"
19 #include "utils/palloc.h"
21 #include "catalog/catname.h"
22 #include "utils/builtins.h" /* where function declarations go */
24 /*****************************************************************************
26 *****************************************************************************/
29 * regprocin - converts "proname" to proid
31 * proid of NULL signifies unknown
34 regprocin(char *proname)
37 HeapScanDesc procscan;
40 RegProcedure result = (Oid) 0;
45 proc = heap_openr(ProcedureRelationName);
46 if (!RelationIsValid(proc))
48 elog(ERROR, "regprocin: could not open %s",
49 ProcedureRelationName);
52 ScanKeyEntryInitialize(&key,
55 (RegProcedure) F_NAMEEQ,
58 procscan = heap_beginscan(proc, 0, SnapshotNow, 1, &key);
59 if (!HeapScanIsValid(procscan))
62 elog(ERROR, "regprocin: could not being scan of %s",
63 ProcedureRelationName);
66 proctup = heap_getnext(procscan, 0, (Buffer *) NULL);
67 switch (HeapTupleIsValid(proctup))
70 result = (RegProcedure) heap_getattr(proctup,
71 ObjectIdAttributeNumber,
72 RelationGetTupleDescriptor(proc),
75 elog(FATAL, "regprocin: null procedure %s", proname);
78 result = (RegProcedure) 0;
80 elog(DEBUG, "regprocin: no such procedure %s", proname);
81 #endif /* defined(EBUG) */
83 heap_endscan(procscan);
85 return ((int32) result);
89 * regprocout - converts proid to "proname"
92 regprocout(RegProcedure proid)
95 HeapScanDesc procscan;
100 result = (char *) palloc(NAMEDATALEN);
101 proc = heap_openr(ProcedureRelationName);
102 if (!RelationIsValid(proc))
104 elog(ERROR, "regprocout: could not open %s",
105 ProcedureRelationName);
108 ScanKeyEntryInitialize(&key,
110 (AttrNumber) ObjectIdAttributeNumber,
111 (RegProcedure) F_INT4EQ,
114 procscan = heap_beginscan(proc, 0, SnapshotNow, 1, &key);
115 if (!HeapScanIsValid(procscan))
118 elog(ERROR, "regprocout: could not being scan of %s",
119 ProcedureRelationName);
122 proctup = heap_getnext(procscan, 0, (Buffer *) NULL);
123 switch (HeapTupleIsValid(proctup))
129 s = (char *) heap_getattr(proctup, 1,
130 RelationGetTupleDescriptor(proc), &isnull);
133 StrNCpy(result, s, NAMEDATALEN);
136 elog(FATAL, "regprocout: null procedure %d", proid);
142 elog(DEBUG, "regprocout: no such procedure %d", proid);
143 #endif /* defined(EBUG) */
145 heap_endscan(procscan);
151 * int8typeout - converts int8 type oids to "typname" list
154 oid8types(Oid (*oidArray)[])
157 HeapScanDesc typescan;
164 if (oidArray == NULL)
166 result = (text *) palloc(VARHDRSZ);
171 result = (text *) palloc(NAMEDATALEN * 8 + 8 + VARHDRSZ);
172 *VARDATA(result) = '\0';
173 type = heap_openr(TypeRelationName);
174 if (!RelationIsValid(type))
176 elog(ERROR, "int8typeout: could not open %s",
182 for (num = 8; num != 0; num--, sp++)
184 if (*sp != InvalidOid)
186 ScanKeyEntryInitialize(&key,
188 (AttrNumber) ObjectIdAttributeNumber,
189 (RegProcedure) F_INT4EQ,
192 typescan = heap_beginscan(type, 0, SnapshotNow, 1, &key);
193 if (!HeapScanIsValid(typescan))
196 elog(ERROR, "int8typeout: could not being scan of %s",
200 typetup = heap_getnext(typescan, 0, (Buffer *) NULL);
201 if (HeapTupleIsValid(typetup))
206 s = (char *) heap_getattr(typetup, 1,
207 RelationGetTupleDescriptor(type), &isnull);
210 StrNCpy(VARDATA(result) + strlen(VARDATA(result)), s,
212 strcat(VARDATA(result), " ");
215 elog(FATAL, "int8typeout: null procedure %d", *sp);
218 heap_endscan(typescan);
222 VARSIZE(result) = strlen(VARDATA(result)) + VARHDRSZ;
227 /*****************************************************************************
229 *****************************************************************************/
232 * Lowercase version of RegprocToOid() to allow case-insensitive SQL.
233 * Define RegprocToOid() as a macro in builtins.h.
234 * Referenced in pg_proc.h. - tgl 97/04/26
237 regproctooid(RegProcedure rp)
242 /* (see int.c for comparison/operation routines) */
245 /* ========== PRIVATE ROUTINES ========== */