Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit fd1843f

Browse files
committed
Standardize get_whatever_oid functions for other object types.
- Rename TSParserGetPrsid to get_ts_parser_oid. - Rename TSDictionaryGetDictid to get_ts_dict_oid. - Rename TSTemplateGetTmplid to get_ts_template_oid. - Rename TSConfigGetCfgid to get_ts_config_oid. - Rename FindConversionByName to get_conversion_oid. - Rename GetConstraintName to get_constraint_oid. - Add new functions get_opclass_oid, get_opfamily_oid, get_rewrite_oid, get_rewrite_oid_without_relid, get_trigger_oid, and get_cast_oid. The name of each function matches the corresponding catalog. Thanks to KaiGai Kohei for the review.
1 parent 2a6ef34 commit fd1843f

22 files changed

+401
-504
lines changed

contrib/tsearch2/tsearch2.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/contrib/tsearch2/tsearch2.c,v 1.12 2010/02/08 20:39:51 tgl Exp $
10+
* $PostgreSQL: pgsql/contrib/tsearch2/tsearch2.c,v 1.13 2010/08/05 15:25:35 rhaas Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -190,7 +190,7 @@ tsa_set_curdict_byname(PG_FUNCTION_ARGS)
190190
text *name = PG_GETARG_TEXT_PP(0);
191191
Oid dict_oid;
192192

193-
dict_oid = TSDictionaryGetDictid(stringToQualifiedNameList(text_to_cstring(name)), false);
193+
dict_oid = get_ts_dict_oid(stringToQualifiedNameList(text_to_cstring(name)), false);
194194

195195
current_dictionary_oid = dict_oid;
196196

@@ -229,7 +229,7 @@ tsa_set_curprs_byname(PG_FUNCTION_ARGS)
229229
text *name = PG_GETARG_TEXT_PP(0);
230230
Oid parser_oid;
231231

232-
parser_oid = TSParserGetPrsid(stringToQualifiedNameList(text_to_cstring(name)), false);
232+
parser_oid = get_ts_parser_oid(stringToQualifiedNameList(text_to_cstring(name)), false);
233233

234234
current_parser_oid = parser_oid;
235235

@@ -562,6 +562,6 @@ static Oid
562562
GetCurrentParser(void)
563563
{
564564
if (current_parser_oid == InvalidOid)
565-
current_parser_oid = TSParserGetPrsid(stringToQualifiedNameList("pg_catalog.default"), false);
565+
current_parser_oid = get_ts_parser_oid(stringToQualifiedNameList("pg_catalog.default"), false);
566566
return current_parser_oid;
567567
}

contrib/unaccent/unaccent.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Copyright (c) 2009-2010, PostgreSQL Global Development Group
77
*
88
* IDENTIFICATION
9-
* $PostgreSQL: pgsql/contrib/unaccent/unaccent.c,v 1.5 2010/02/26 02:00:32 momjian Exp $
9+
* $PostgreSQL: pgsql/contrib/unaccent/unaccent.c,v 1.6 2010/08/05 15:25:35 rhaas Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -279,7 +279,7 @@ unaccent_dict(PG_FUNCTION_ARGS)
279279

280280
if (PG_NARGS() == 1)
281281
{
282-
dictOid = TSDictionaryGetDictid(stringToQualifiedNameList("unaccent"), false);
282+
dictOid = get_ts_dict_oid(stringToQualifiedNameList("unaccent"), false);
283283
strArg = 0;
284284
}
285285
else

src/backend/catalog/namespace.c

+28-23
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
1515
* IDENTIFICATION
16-
* $PostgreSQL: pgsql/src/backend/catalog/namespace.c,v 1.126 2010/08/05 14:44:58 rhaas Exp $
16+
* $PostgreSQL: pgsql/src/backend/catalog/namespace.c,v 1.127 2010/08/05 15:25:35 rhaas Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -1692,12 +1692,12 @@ ConversionIsVisible(Oid conid)
16921692
}
16931693

16941694
/*
1695-
* TSParserGetPrsid - find a TS parser by possibly qualified name
1695+
* get_ts_parser_oid - find a TS parser by possibly qualified name
16961696
*
1697-
* If not found, returns InvalidOid if failOK, else throws error
1697+
* If not found, returns InvalidOid if missing_ok, else throws error
16981698
*/
16991699
Oid
1700-
TSParserGetPrsid(List *names, bool failOK)
1700+
get_ts_parser_oid(List *names, bool missing_ok)
17011701
{
17021702
char *schemaname;
17031703
char *parser_name;
@@ -1736,7 +1736,7 @@ TSParserGetPrsid(List *names, bool failOK)
17361736
}
17371737
}
17381738

1739-
if (!OidIsValid(prsoid) && !failOK)
1739+
if (!OidIsValid(prsoid) && !missing_ok)
17401740
ereport(ERROR,
17411741
(errcode(ERRCODE_UNDEFINED_OBJECT),
17421742
errmsg("text search parser \"%s\" does not exist",
@@ -1815,12 +1815,12 @@ TSParserIsVisible(Oid prsId)
18151815
}
18161816

18171817
/*
1818-
* TSDictionaryGetDictid - find a TS dictionary by possibly qualified name
1818+
* get_ts_dict_oid - find a TS dictionary by possibly qualified name
18191819
*
18201820
* If not found, returns InvalidOid if failOK, else throws error
18211821
*/
18221822
Oid
1823-
TSDictionaryGetDictid(List *names, bool failOK)
1823+
get_ts_dict_oid(List *names, bool missing_ok)
18241824
{
18251825
char *schemaname;
18261826
char *dict_name;
@@ -1859,7 +1859,7 @@ TSDictionaryGetDictid(List *names, bool failOK)
18591859
}
18601860
}
18611861

1862-
if (!OidIsValid(dictoid) && !failOK)
1862+
if (!OidIsValid(dictoid) && !missing_ok)
18631863
ereport(ERROR,
18641864
(errcode(ERRCODE_UNDEFINED_OBJECT),
18651865
errmsg("text search dictionary \"%s\" does not exist",
@@ -1939,12 +1939,12 @@ TSDictionaryIsVisible(Oid dictId)
19391939
}
19401940

19411941
/*
1942-
* TSTemplateGetTmplid - find a TS template by possibly qualified name
1942+
* get_ts_template_oid - find a TS template by possibly qualified name
19431943
*
1944-
* If not found, returns InvalidOid if failOK, else throws error
1944+
* If not found, returns InvalidOid if missing_ok, else throws error
19451945
*/
19461946
Oid
1947-
TSTemplateGetTmplid(List *names, bool failOK)
1947+
get_ts_template_oid(List *names, bool missing_ok)
19481948
{
19491949
char *schemaname;
19501950
char *template_name;
@@ -1983,7 +1983,7 @@ TSTemplateGetTmplid(List *names, bool failOK)
19831983
}
19841984
}
19851985

1986-
if (!OidIsValid(tmploid) && !failOK)
1986+
if (!OidIsValid(tmploid) && !missing_ok)
19871987
ereport(ERROR,
19881988
(errcode(ERRCODE_UNDEFINED_OBJECT),
19891989
errmsg("text search template \"%s\" does not exist",
@@ -2062,12 +2062,12 @@ TSTemplateIsVisible(Oid tmplId)
20622062
}
20632063

20642064
/*
2065-
* TSConfigGetCfgid - find a TS config by possibly qualified name
2065+
* get_ts_config_oid - find a TS config by possibly qualified name
20662066
*
2067-
* If not found, returns InvalidOid if failOK, else throws error
2067+
* If not found, returns InvalidOid if missing_ok, else throws error
20682068
*/
20692069
Oid
2070-
TSConfigGetCfgid(List *names, bool failOK)
2070+
get_ts_config_oid(List *names, bool missing_ok)
20712071
{
20722072
char *schemaname;
20732073
char *config_name;
@@ -2106,7 +2106,7 @@ TSConfigGetCfgid(List *names, bool failOK)
21062106
}
21072107
}
21082108

2109-
if (!OidIsValid(cfgoid) && !failOK)
2109+
if (!OidIsValid(cfgoid) && !missing_ok)
21102110
ereport(ERROR,
21112111
(errcode(ERRCODE_UNDEFINED_OBJECT),
21122112
errmsg("text search configuration \"%s\" does not exist",
@@ -2766,15 +2766,15 @@ PopOverrideSearchPath(void)
27662766

27672767

27682768
/*
2769-
* FindConversionByName - find a conversion by possibly qualified name
2769+
* get_conversion_oid - find a conversion by possibly qualified name
27702770
*/
27712771
Oid
2772-
FindConversionByName(List *name)
2772+
get_conversion_oid(List *name, bool missing_ok)
27732773
{
27742774
char *schemaname;
27752775
char *conversion_name;
27762776
Oid namespaceId;
2777-
Oid conoid;
2777+
Oid conoid = InvalidOid;
27782778
ListCell *l;
27792779

27802780
/* deconstruct the name list */
@@ -2784,9 +2784,9 @@ FindConversionByName(List *name)
27842784
{
27852785
/* use exact schema given */
27862786
namespaceId = LookupExplicitNamespace(schemaname);
2787-
return GetSysCacheOid2(CONNAMENSP,
2788-
PointerGetDatum(conversion_name),
2789-
ObjectIdGetDatum(namespaceId));
2787+
conoid = GetSysCacheOid2(CONNAMENSP,
2788+
PointerGetDatum(conversion_name),
2789+
ObjectIdGetDatum(namespaceId));
27902790
}
27912791
else
27922792
{
@@ -2809,7 +2809,12 @@ FindConversionByName(List *name)
28092809
}
28102810

28112811
/* Not found in path */
2812-
return InvalidOid;
2812+
if (!OidIsValid(conoid) && !missing_ok)
2813+
ereport(ERROR,
2814+
(errcode(ERRCODE_UNDEFINED_OBJECT),
2815+
errmsg("conversion \"%s\" does not exist",
2816+
NameListToString(name))));
2817+
return conoid;
28132818
}
28142819

28152820
/*

src/backend/catalog/pg_constraint.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/pg_constraint.c,v 1.53 2010/02/26 02:00:37 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/pg_constraint.c,v 1.54 2010/08/05 15:25:35 rhaas Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -727,12 +727,12 @@ AlterConstraintNamespaces(Oid ownerId, Oid oldNspId,
727727
}
728728

729729
/*
730-
* GetConstraintByName
730+
* get_constraint_oid
731731
* Find a constraint on the specified relation with the specified name.
732732
* Returns constraint's OID.
733733
*/
734734
Oid
735-
GetConstraintByName(Oid relid, const char *conname)
735+
get_constraint_oid(Oid relid, const char *conname, bool missing_ok)
736736
{
737737
Relation pg_constraint;
738738
HeapTuple tuple;
@@ -773,7 +773,7 @@ GetConstraintByName(Oid relid, const char *conname)
773773
systable_endscan(scan);
774774

775775
/* If no such constraint exists, complain */
776-
if (!OidIsValid(conOid))
776+
if (!OidIsValid(conOid) && !missing_ok)
777777
ereport(ERROR,
778778
(errcode(ERRCODE_UNDEFINED_OBJECT),
779779
errmsg("constraint \"%s\" for table \"%s\" does not exist",

0 commit comments

Comments
 (0)