Thanks to visit codestin.com
Credit goes to doxygen.postgresql.org

PostgreSQL Source Code git master
regproc.h File Reference
#include "nodes/pg_list.h"
Include dependency graph for regproc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define FORMAT_PROC_INVALID_AS_NULL   0x01 /* NULL if undefined */
 
#define FORMAT_PROC_FORCE_QUALIFY   0x02 /* force qualification */
 
#define FORMAT_OPERATOR_INVALID_AS_NULL   0x01 /* NULL if undefined */
 
#define FORMAT_OPERATOR_FORCE_QUALIFY   0x02 /* force qualification */
 

Functions

char * format_procedure_extended (Oid procedure_oid, bits16 flags)
 
char * format_operator_extended (Oid operator_oid, bits16 flags)
 
ListstringToQualifiedNameList (const char *string, Node *escontext)
 
char * format_procedure (Oid procedure_oid)
 
char * format_procedure_qualified (Oid procedure_oid)
 
void format_procedure_parts (Oid procedure_oid, List **objnames, List **objargs, bool missing_ok)
 
char * format_operator (Oid operator_oid)
 
char * format_operator_qualified (Oid operator_oid)
 
void format_operator_parts (Oid operator_oid, List **objnames, List **objargs, bool missing_ok)
 

Macro Definition Documentation

◆ FORMAT_OPERATOR_FORCE_QUALIFY

#define FORMAT_OPERATOR_FORCE_QUALIFY   0x02 /* force qualification */

Definition at line 25 of file regproc.h.

◆ FORMAT_OPERATOR_INVALID_AS_NULL

#define FORMAT_OPERATOR_INVALID_AS_NULL   0x01 /* NULL if undefined */

Definition at line 24 of file regproc.h.

◆ FORMAT_PROC_FORCE_QUALIFY

#define FORMAT_PROC_FORCE_QUALIFY   0x02 /* force qualification */

Definition at line 20 of file regproc.h.

◆ FORMAT_PROC_INVALID_AS_NULL

#define FORMAT_PROC_INVALID_AS_NULL   0x01 /* NULL if undefined */

Definition at line 19 of file regproc.h.

Function Documentation

◆ format_operator()

char * format_operator ( Oid  operator_oid)

Definition at line 801 of file regproc.c.

802{
803 return format_operator_extended(operator_oid, 0);
804}
char * format_operator_extended(Oid operator_oid, bits16 flags)
Definition: regproc.c:730

References format_operator_extended().

Referenced by blvalidate(), brinvalidate(), btvalidate(), ComputeIndexAttrs(), getObjectDescription(), ginvalidate(), gistvalidate(), hashvalidate(), regoperatorout(), and spgvalidate().

◆ format_operator_extended()

char * format_operator_extended ( Oid  operator_oid,
bits16  flags 
)

Definition at line 730 of file regproc.c.

731{
732 char *result;
733 HeapTuple opertup;
734
735 opertup = SearchSysCache1(OPEROID, ObjectIdGetDatum(operator_oid));
736
737 if (HeapTupleIsValid(opertup))
738 {
739 Form_pg_operator operform = (Form_pg_operator) GETSTRUCT(opertup);
740 char *oprname = NameStr(operform->oprname);
741 char *nspname;
743
744 /* XXX no support here for bootstrap mode */
746
748
749 /*
750 * Would this oper be found (given the right args) by regoperatorin?
751 * If not, or if caller explicitly requests it, we need to qualify it.
752 */
753 if ((flags & FORMAT_OPERATOR_FORCE_QUALIFY) != 0 ||
754 !OperatorIsVisible(operator_oid))
755 {
756 nspname = get_namespace_name(operform->oprnamespace);
757 appendStringInfo(&buf, "%s.",
758 quote_identifier(nspname));
759 }
760
761 appendStringInfo(&buf, "%s(", oprname);
762
763 if (operform->oprleft)
764 appendStringInfo(&buf, "%s,",
765 (flags & FORMAT_OPERATOR_FORCE_QUALIFY) != 0 ?
766 format_type_be_qualified(operform->oprleft) :
767 format_type_be(operform->oprleft));
768 else
769 appendStringInfoString(&buf, "NONE,");
770
771 if (operform->oprright)
772 appendStringInfo(&buf, "%s)",
773 (flags & FORMAT_OPERATOR_FORCE_QUALIFY) != 0 ?
774 format_type_be_qualified(operform->oprright) :
775 format_type_be(operform->oprright));
776 else
777 appendStringInfoString(&buf, "NONE)");
778
779 result = buf.data;
780
781 ReleaseSysCache(opertup);
782 }
783 else if ((flags & FORMAT_OPERATOR_INVALID_AS_NULL) != 0)
784 {
785 /* If object is undefined, return NULL as wanted by caller */
786 result = NULL;
787 }
788 else
789 {
790 /*
791 * If OID doesn't match any pg_operator entry, return it numerically
792 */
793 result = (char *) palloc(NAMEDATALEN);
794 snprintf(result, NAMEDATALEN, "%u", operator_oid);
795 }
796
797 return result;
798}
#define NameStr(name)
Definition: c.h:752
char * format_type_be_qualified(Oid type_oid)
Definition: format_type.c:353
char * format_type_be(Oid type_oid)
Definition: format_type.c:343
Assert(PointerIsAligned(start, uint64))
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
static void * GETSTRUCT(const HeapTupleData *tuple)
Definition: htup_details.h:728
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3533
void * palloc(Size size)
Definition: mcxt.c:1365
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:476
bool OperatorIsVisible(Oid oprid)
Definition: namespace.c:2116
#define NAMEDATALEN
FormData_pg_operator * Form_pg_operator
Definition: pg_operator.h:83
static char * buf
Definition: pg_test_fsync.c:72
#define snprintf
Definition: port.h:239
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:262
#define FORMAT_OPERATOR_INVALID_AS_NULL
Definition: regproc.h:24
#define FORMAT_OPERATOR_FORCE_QUALIFY
Definition: regproc.h:25
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:13030
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:145
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:230
void initStringInfo(StringInfo str)
Definition: stringinfo.c:97
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:264
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:220

References appendStringInfo(), appendStringInfoString(), Assert(), buf, FORMAT_OPERATOR_FORCE_QUALIFY, FORMAT_OPERATOR_INVALID_AS_NULL, format_type_be(), format_type_be_qualified(), get_namespace_name(), GETSTRUCT(), HeapTupleIsValid, initStringInfo(), IsBootstrapProcessingMode, NAMEDATALEN, NameStr, ObjectIdGetDatum(), OperatorIsVisible(), palloc(), quote_identifier(), ReleaseSysCache(), SearchSysCache1(), and snprintf.

Referenced by format_operator(), format_operator_qualified(), getObjectDescription(), and getObjectIdentityParts().

◆ format_operator_parts()

void format_operator_parts ( Oid  operator_oid,
List **  objnames,
List **  objargs,
bool  missing_ok 
)

Definition at line 814 of file regproc.c.

816{
817 HeapTuple opertup;
818 Form_pg_operator oprForm;
819
820 opertup = SearchSysCache1(OPEROID, ObjectIdGetDatum(operator_oid));
821 if (!HeapTupleIsValid(opertup))
822 {
823 if (!missing_ok)
824 elog(ERROR, "cache lookup failed for operator with OID %u",
825 operator_oid);
826 return;
827 }
828
829 oprForm = (Form_pg_operator) GETSTRUCT(opertup);
830 *objnames = list_make2(get_namespace_name_or_temp(oprForm->oprnamespace),
831 pstrdup(NameStr(oprForm->oprname)));
832 *objargs = NIL;
833 if (oprForm->oprleft)
834 *objargs = lappend(*objargs,
835 format_type_be_qualified(oprForm->oprleft));
836 if (oprForm->oprright)
837 *objargs = lappend(*objargs,
838 format_type_be_qualified(oprForm->oprright));
839
840 ReleaseSysCache(opertup);
841}
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:226
List * lappend(List *list, void *datum)
Definition: list.c:339
char * get_namespace_name_or_temp(Oid nspid)
Definition: lsyscache.c:3557
char * pstrdup(const char *in)
Definition: mcxt.c:1759
#define NIL
Definition: pg_list.h:68
#define list_make2(x1, x2)
Definition: pg_list.h:214

References elog, ERROR, format_type_be_qualified(), get_namespace_name_or_temp(), GETSTRUCT(), HeapTupleIsValid, lappend(), list_make2, NameStr, NIL, ObjectIdGetDatum(), pstrdup(), ReleaseSysCache(), and SearchSysCache1().

Referenced by getObjectIdentityParts().

◆ format_operator_qualified()

char * format_operator_qualified ( Oid  operator_oid)

Definition at line 807 of file regproc.c.

808{
809 return format_operator_extended(operator_oid,
811}

References format_operator_extended(), and FORMAT_OPERATOR_FORCE_QUALIFY.

◆ format_procedure()

char * format_procedure ( Oid  procedure_oid)

◆ format_procedure_extended()

char * format_procedure_extended ( Oid  procedure_oid,
bits16  flags 
)

Definition at line 332 of file regproc.c.

333{
334 char *result;
335 HeapTuple proctup;
336
337 proctup = SearchSysCache1(PROCOID, ObjectIdGetDatum(procedure_oid));
338
339 if (HeapTupleIsValid(proctup))
340 {
341 Form_pg_proc procform = (Form_pg_proc) GETSTRUCT(proctup);
342 char *proname = NameStr(procform->proname);
343 int nargs = procform->pronargs;
344 int i;
345 char *nspname;
347
348 /* XXX no support here for bootstrap mode */
350
352
353 /*
354 * Would this proc be found (given the right args) by regprocedurein?
355 * If not, or if caller requests it, we need to qualify it.
356 */
357 if ((flags & FORMAT_PROC_FORCE_QUALIFY) == 0 &&
358 FunctionIsVisible(procedure_oid))
359 nspname = NULL;
360 else
361 nspname = get_namespace_name(procform->pronamespace);
362
363 appendStringInfo(&buf, "%s(",
365 for (i = 0; i < nargs; i++)
366 {
367 Oid thisargtype = procform->proargtypes.values[i];
368
369 if (i > 0)
372 (flags & FORMAT_PROC_FORCE_QUALIFY) != 0 ?
373 format_type_be_qualified(thisargtype) :
374 format_type_be(thisargtype));
375 }
377
378 result = buf.data;
379
380 ReleaseSysCache(proctup);
381 }
382 else if ((flags & FORMAT_PROC_INVALID_AS_NULL) != 0)
383 {
384 /* If object is undefined, return NULL as wanted by caller */
385 result = NULL;
386 }
387 else
388 {
389 /* If OID doesn't match any pg_proc entry, return it numerically */
390 result = (char *) palloc(NAMEDATALEN);
391 snprintf(result, NAMEDATALEN, "%u", procedure_oid);
392 }
393
394 return result;
395}
int i
Definition: isn.c:77
bool FunctionIsVisible(Oid funcid)
Definition: namespace.c:1741
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:136
NameData proname
Definition: pg_proc.h:35
unsigned int Oid
Definition: postgres_ext.h:32
#define FORMAT_PROC_FORCE_QUALIFY
Definition: regproc.h:20
#define FORMAT_PROC_INVALID_AS_NULL
Definition: regproc.h:19
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:13114
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:242

References appendStringInfo(), appendStringInfoChar(), appendStringInfoString(), Assert(), buf, FORMAT_PROC_FORCE_QUALIFY, FORMAT_PROC_INVALID_AS_NULL, format_type_be(), format_type_be_qualified(), FunctionIsVisible(), get_namespace_name(), GETSTRUCT(), HeapTupleIsValid, i, initStringInfo(), IsBootstrapProcessingMode, NAMEDATALEN, NameStr, ObjectIdGetDatum(), palloc(), proname, quote_qualified_identifier(), ReleaseSysCache(), SearchSysCache1(), and snprintf.

Referenced by format_procedure(), format_procedure_qualified(), getObjectDescription(), and getObjectIdentityParts().

◆ format_procedure_parts()

void format_procedure_parts ( Oid  procedure_oid,
List **  objnames,
List **  objargs,
bool  missing_ok 
)

Definition at line 404 of file regproc.c.

406{
407 HeapTuple proctup;
408 Form_pg_proc procform;
409 int nargs;
410 int i;
411
412 proctup = SearchSysCache1(PROCOID, ObjectIdGetDatum(procedure_oid));
413
414 if (!HeapTupleIsValid(proctup))
415 {
416 if (!missing_ok)
417 elog(ERROR, "cache lookup failed for procedure with OID %u", procedure_oid);
418 return;
419 }
420
421 procform = (Form_pg_proc) GETSTRUCT(proctup);
422 nargs = procform->pronargs;
423
424 *objnames = list_make2(get_namespace_name_or_temp(procform->pronamespace),
425 pstrdup(NameStr(procform->proname)));
426 *objargs = NIL;
427 for (i = 0; i < nargs; i++)
428 {
429 Oid thisargtype = procform->proargtypes.values[i];
430
431 *objargs = lappend(*objargs, format_type_be_qualified(thisargtype));
432 }
433
434 ReleaseSysCache(proctup);
435}

References elog, ERROR, format_type_be_qualified(), get_namespace_name_or_temp(), GETSTRUCT(), HeapTupleIsValid, i, lappend(), list_make2, NameStr, NIL, ObjectIdGetDatum(), pstrdup(), ReleaseSysCache(), and SearchSysCache1().

Referenced by getObjectIdentityParts().

◆ format_procedure_qualified()

char * format_procedure_qualified ( Oid  procedure_oid)

Definition at line 311 of file regproc.c.

312{
314}

References FORMAT_PROC_FORCE_QUALIFY, and format_procedure_extended().

◆ stringToQualifiedNameList()

List * stringToQualifiedNameList ( const char *  string,
Node escontext 
)

Definition at line 1922 of file regproc.c.

1923{
1924 char *rawname;
1925 List *result = NIL;
1926 List *namelist;
1927 ListCell *l;
1928
1929 /* We need a modifiable copy of the input string. */
1930 rawname = pstrdup(string);
1931
1932 if (!SplitIdentifierString(rawname, '.', &namelist))
1933 ereturn(escontext, NIL,
1934 (errcode(ERRCODE_INVALID_NAME),
1935 errmsg("invalid name syntax")));
1936
1937 if (namelist == NIL)
1938 ereturn(escontext, NIL,
1939 (errcode(ERRCODE_INVALID_NAME),
1940 errmsg("invalid name syntax")));
1941
1942 foreach(l, namelist)
1943 {
1944 char *curname = (char *) lfirst(l);
1945
1946 result = lappend(result, makeString(pstrdup(curname)));
1947 }
1948
1949 pfree(rawname);
1950 list_free(namelist);
1951
1952 return result;
1953}
int errcode(int sqlerrcode)
Definition: elog.c:854
int errmsg(const char *fmt,...)
Definition: elog.c:1071
#define ereturn(context, dummy_value,...)
Definition: elog.h:278
void list_free(List *list)
Definition: list.c:1546
void pfree(void *pointer)
Definition: mcxt.c:1594
#define lfirst(lc)
Definition: pg_list.h:172
Definition: pg_list.h:54
String * makeString(char *str)
Definition: value.c:63
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:2744

References ereturn, errcode(), errmsg(), lappend(), lfirst, list_free(), makeString(), NIL, pfree(), pstrdup(), and SplitIdentifierString().

Referenced by call_pltcl_start_proc(), check_default_text_search_config(), getTSCurrentConfig(), parseNameAndArgTypes(), regclassin(), regcollationin(), regconfigin(), regdatabasein(), regdictionaryin(), regnamespacein(), regoperin(), regprocin(), regrolein(), RelationNameGetTupleDesc(), thesaurus_init(), and tsvector_update_trigger().