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.13 1998/01/31 04:38:46 momjian 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_CHAR16EQ,
58 procscan = heap_beginscan(proc, 0, false, 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),
76 elog(FATAL, "regprocin: null procedure %s", proname);
80 result = (RegProcedure) 0;
82 elog(DEBUG, "regprocin: no such procedure %s", proname);
83 #endif /* defined(EBUG) */
85 heap_endscan(procscan);
87 return ((int32) result);
91 * regprocout - converts proid to "proname"
94 regprocout(RegProcedure proid)
97 HeapScanDesc procscan;
102 result = (char *) palloc(NAMEDATALEN);
103 proc = heap_openr(ProcedureRelationName);
104 if (!RelationIsValid(proc))
106 elog(ERROR, "regprocout: could not open %s",
107 ProcedureRelationName);
110 ScanKeyEntryInitialize(&key,
112 (AttrNumber) ObjectIdAttributeNumber,
113 (RegProcedure) F_INT4EQ,
116 procscan = heap_beginscan(proc, 0, false, 1, &key);
117 if (!HeapScanIsValid(procscan))
120 elog(ERROR, "regprocout: could not being scan of %s",
121 ProcedureRelationName);
124 proctup = heap_getnext(procscan, 0, (Buffer *) NULL);
125 switch (HeapTupleIsValid(proctup))
131 s = (char *) heap_getattr(proctup, 1,
132 RelationGetTupleDescriptor(proc), &isnull);
135 StrNCpy(result, s, 16);
138 elog(FATAL, "regprocout: null procedure %d", proid);
144 elog(DEBUG, "regprocout: no such procedure %d", proid);
145 #endif /* defined(EBUG) */
147 heap_endscan(procscan);
153 * int8typeout - converts int8 type oids to "typname" list
156 oid8types(Oid (*oidArray)[])
159 HeapScanDesc typescan;
166 if (oidArray == NULL)
168 result = (text *) palloc(VARHDRSZ);
173 result = (text *) palloc(NAMEDATALEN * 8 + 8 + VARHDRSZ);
174 *VARDATA(result) = '\0';
175 type = heap_openr(TypeRelationName);
176 if (!RelationIsValid(type))
178 elog(ERROR, "int8typeout: could not open %s",
184 for (num = 8; num != 0; num--, sp++)
186 if (*sp != InvalidOid)
188 ScanKeyEntryInitialize(&key,
190 (AttrNumber) ObjectIdAttributeNumber,
191 (RegProcedure) F_INT4EQ,
194 typescan = heap_beginscan(type, 0, false, 1, &key);
195 if (!HeapScanIsValid(typescan))
198 elog(ERROR, "int8typeout: could not being scan of %s",
202 typetup = heap_getnext(typescan, 0, (Buffer *) NULL);
203 if (HeapTupleIsValid(typetup))
208 s = (char *) heap_getattr(typetup, 1,
209 RelationGetTupleDescriptor(type), &isnull);
212 StrNCpy(VARDATA(result)+strlen(VARDATA(result)),s,16);
213 strcat(VARDATA(result)," ");
216 elog(FATAL, "int8typeout: null procedure %d", *sp);
219 heap_endscan(typescan);
223 VARSIZE(result) = strlen(VARDATA(result)) + VARHDRSZ;
228 /*****************************************************************************
230 *****************************************************************************/
233 * Lowercase version of RegprocToOid() to allow case-insensitive SQL.
234 * Define RegprocToOid() as a macro in builtins.h.
235 * Referenced in pg_proc.h. - tgl 97/04/26
238 regproctooid(RegProcedure rp)
243 /* (see int.c for comparison/operation routines) */
246 /* ========== PRIVATE ROUTINES ========== */