Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0fb0a05

Browse files
committed
Hide internal error for pg_collation_actual_version(<bad OID>).
Instead of an unsightly internal "cache lookup failed" message, justreturn NULL for bad OIDs, as is the convention for other similar things.Reported-by: Justin Pryzby <pryzby@telsasoft.com>Reviewed-by: Michael Paquier <michael@paquier.xyz>Discussion:https://postgr.es/m/20210117215940.GE8560%40telsasoft.com
1 parentf05ed5a commit0fb0a05

File tree

7 files changed

+33
-7
lines changed

7 files changed

+33
-7
lines changed

‎src/backend/catalog/index.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,8 @@ do_collation_version_check(const ObjectAddress *otherObject,
12901290
return false;
12911291

12921292
/* Ask the provider for the current version. Give up if unsupported. */
1293-
current_version=get_collation_version_for_oid(otherObject->objectId);
1293+
current_version=get_collation_version_for_oid(otherObject->objectId,
1294+
false);
12941295
if (!current_version)
12951296
return false;
12961297

@@ -1369,7 +1370,7 @@ do_collation_version_update(const ObjectAddress *otherObject,
13691370
if (OidIsValid(*coll)&&otherObject->objectId!=*coll)
13701371
return false;
13711372

1372-
*new_version=get_collation_version_for_oid(otherObject->objectId);
1373+
*new_version=get_collation_version_for_oid(otherObject->objectId, false);
13731374

13741375
return true;
13751376
}

‎src/backend/catalog/pg_depend.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ recordMultipleDependencies(const ObjectAddress *depender,
116116
referenced->objectId==POSIX_COLLATION_OID)
117117
continue;
118118

119-
version=get_collation_version_for_oid(referenced->objectId);
119+
version=get_collation_version_for_oid(referenced->objectId,
120+
false);
120121

121122
/*
122123
* Default collation is pinned, so we need to force recording

‎src/backend/commands/collationcmds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ pg_collation_actual_version(PG_FUNCTION_ARGS)
273273
Oidcollid=PG_GETARG_OID(0);
274274
char*version;
275275

276-
version=get_collation_version_for_oid(collid);
276+
version=get_collation_version_for_oid(collid, true);
277277

278278
if (version)
279279
PG_RETURN_TEXT_P(cstring_to_text(version));

‎src/backend/utils/adt/pg_locale.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,10 +1726,11 @@ get_collation_actual_version(char collprovider, const char *collcollate)
17261726
/*
17271727
* Get provider-specific collation version string for a given collation OID.
17281728
* Return NULL if the provider doesn't support versions, or the collation is
1729-
* unversioned (for example "C").
1729+
* unversioned (for example "C"). Unknown OIDs result in NULL if missing_ok is
1730+
* true.
17301731
*/
17311732
char*
1732-
get_collation_version_for_oid(Oidoid)
1733+
get_collation_version_for_oid(Oidoid,boolmissing_ok)
17331734
{
17341735
HeapTupletp;
17351736
char*version;
@@ -1751,7 +1752,11 @@ get_collation_version_for_oid(Oid oid)
17511752

17521753
tp=SearchSysCache1(COLLOID,ObjectIdGetDatum(oid));
17531754
if (!HeapTupleIsValid(tp))
1755+
{
1756+
if (missing_ok)
1757+
returnNULL;
17541758
elog(ERROR,"cache lookup failed for collation %u",oid);
1759+
}
17551760
collform= (Form_pg_collation)GETSTRUCT(tp);
17561761
version=get_collation_actual_version(collform->collprovider,
17571762
NameStr(collform->collcollate));

‎src/include/utils/pg_locale.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ typedef struct pg_locale_struct *pg_locale_t;
103103

104104
externpg_locale_tpg_newlocale_from_collation(Oidcollid);
105105

106-
externchar*get_collation_version_for_oid(Oidcollid);
106+
externchar*get_collation_version_for_oid(Oidcollid,boolmissing_ok);
107107

108108
#ifdefUSE_ICU
109109
externint32_ticu_to_uchar(UChar**buff_uchar,constchar*buff,size_tnbytes);

‎src/test/regress/expected/collate.icu.utf8.out

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2155,3 +2155,17 @@ DROP SCHEMA collate_tests CASCADE;
21552155
RESET client_min_messages;
21562156
-- leave a collation for pg_upgrade test
21572157
CREATE COLLATION coll_icu_upgrade FROM "und-x-icu";
2158+
-- Test user-visible function for inspecting versions
2159+
SELECT pg_collation_actual_version('"en-x-icu"'::regcollation) is not null;
2160+
?column?
2161+
----------
2162+
t
2163+
(1 row)
2164+
2165+
-- Invalid OIDs are silently ignored
2166+
SELECT pg_collation_actual_version(0) is null;
2167+
?column?
2168+
----------
2169+
t
2170+
(1 row)
2171+

‎src/test/regress/sql/collate.icu.utf8.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,3 +883,8 @@ RESET client_min_messages;
883883

884884
-- leave a collation for pg_upgrade test
885885
CREATE COLLATION coll_icu_upgradeFROM"und-x-icu";
886+
887+
-- Test user-visible function for inspecting versions
888+
SELECT pg_collation_actual_version('"en-x-icu"'::regcollation)is not null;
889+
-- Invalid OIDs are silently ignored
890+
SELECT pg_collation_actual_version(0) isnull;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp