mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-12-09 08:10:09 +08:00
Hide internal error for pg_collation_actual_version(<bad OID>).
Instead of an unsightly internal "cache lookup failed" message, just return 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
This commit is contained in:
parent
f05ed5a5cf
commit
0fb0a0503b
@ -1290,7 +1290,8 @@ do_collation_version_check(const ObjectAddress *otherObject,
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* Ask the provider for the current version. Give up if unsupported. */
|
/* Ask the provider for the current version. Give up if unsupported. */
|
||||||
current_version = get_collation_version_for_oid(otherObject->objectId);
|
current_version = get_collation_version_for_oid(otherObject->objectId,
|
||||||
|
false);
|
||||||
if (!current_version)
|
if (!current_version)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -1369,7 +1370,7 @@ do_collation_version_update(const ObjectAddress *otherObject,
|
|||||||
if (OidIsValid(*coll) && otherObject->objectId != *coll)
|
if (OidIsValid(*coll) && otherObject->objectId != *coll)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
*new_version = get_collation_version_for_oid(otherObject->objectId);
|
*new_version = get_collation_version_for_oid(otherObject->objectId, false);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,8 @@ recordMultipleDependencies(const ObjectAddress *depender,
|
|||||||
referenced->objectId == POSIX_COLLATION_OID)
|
referenced->objectId == POSIX_COLLATION_OID)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
version = get_collation_version_for_oid(referenced->objectId);
|
version = get_collation_version_for_oid(referenced->objectId,
|
||||||
|
false);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Default collation is pinned, so we need to force recording
|
* Default collation is pinned, so we need to force recording
|
||||||
|
@ -273,7 +273,7 @@ pg_collation_actual_version(PG_FUNCTION_ARGS)
|
|||||||
Oid collid = PG_GETARG_OID(0);
|
Oid collid = PG_GETARG_OID(0);
|
||||||
char *version;
|
char *version;
|
||||||
|
|
||||||
version = get_collation_version_for_oid(collid);
|
version = get_collation_version_for_oid(collid, true);
|
||||||
|
|
||||||
if (version)
|
if (version)
|
||||||
PG_RETURN_TEXT_P(cstring_to_text(version));
|
PG_RETURN_TEXT_P(cstring_to_text(version));
|
||||||
|
@ -1726,10 +1726,11 @@ get_collation_actual_version(char collprovider, const char *collcollate)
|
|||||||
/*
|
/*
|
||||||
* Get provider-specific collation version string for a given collation OID.
|
* Get provider-specific collation version string for a given collation OID.
|
||||||
* Return NULL if the provider doesn't support versions, or the collation is
|
* Return NULL if the provider doesn't support versions, or the collation is
|
||||||
* unversioned (for example "C").
|
* unversioned (for example "C"). Unknown OIDs result in NULL if missing_ok is
|
||||||
|
* true.
|
||||||
*/
|
*/
|
||||||
char *
|
char *
|
||||||
get_collation_version_for_oid(Oid oid)
|
get_collation_version_for_oid(Oid oid, bool missing_ok)
|
||||||
{
|
{
|
||||||
HeapTuple tp;
|
HeapTuple tp;
|
||||||
char *version;
|
char *version;
|
||||||
@ -1751,7 +1752,11 @@ get_collation_version_for_oid(Oid oid)
|
|||||||
|
|
||||||
tp = SearchSysCache1(COLLOID, ObjectIdGetDatum(oid));
|
tp = SearchSysCache1(COLLOID, ObjectIdGetDatum(oid));
|
||||||
if (!HeapTupleIsValid(tp))
|
if (!HeapTupleIsValid(tp))
|
||||||
|
{
|
||||||
|
if (missing_ok)
|
||||||
|
return NULL;
|
||||||
elog(ERROR, "cache lookup failed for collation %u", oid);
|
elog(ERROR, "cache lookup failed for collation %u", oid);
|
||||||
|
}
|
||||||
collform = (Form_pg_collation) GETSTRUCT(tp);
|
collform = (Form_pg_collation) GETSTRUCT(tp);
|
||||||
version = get_collation_actual_version(collform->collprovider,
|
version = get_collation_actual_version(collform->collprovider,
|
||||||
NameStr(collform->collcollate));
|
NameStr(collform->collcollate));
|
||||||
|
@ -103,7 +103,7 @@ typedef struct pg_locale_struct *pg_locale_t;
|
|||||||
|
|
||||||
extern pg_locale_t pg_newlocale_from_collation(Oid collid);
|
extern pg_locale_t pg_newlocale_from_collation(Oid collid);
|
||||||
|
|
||||||
extern char *get_collation_version_for_oid(Oid collid);
|
extern char *get_collation_version_for_oid(Oid collid, bool missing_ok);
|
||||||
|
|
||||||
#ifdef USE_ICU
|
#ifdef USE_ICU
|
||||||
extern int32_t icu_to_uchar(UChar **buff_uchar, const char *buff, size_t nbytes);
|
extern int32_t icu_to_uchar(UChar **buff_uchar, const char *buff, size_t nbytes);
|
||||||
|
@ -2155,3 +2155,17 @@ DROP SCHEMA collate_tests CASCADE;
|
|||||||
RESET client_min_messages;
|
RESET client_min_messages;
|
||||||
-- leave a collation for pg_upgrade test
|
-- leave a collation for pg_upgrade test
|
||||||
CREATE COLLATION coll_icu_upgrade FROM "und-x-icu";
|
CREATE COLLATION coll_icu_upgrade FROM "und-x-icu";
|
||||||
|
-- Test user-visible function for inspecting versions
|
||||||
|
SELECT pg_collation_actual_version('"en-x-icu"'::regcollation) is not null;
|
||||||
|
?column?
|
||||||
|
----------
|
||||||
|
t
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
-- Invalid OIDs are silently ignored
|
||||||
|
SELECT pg_collation_actual_version(0) is null;
|
||||||
|
?column?
|
||||||
|
----------
|
||||||
|
t
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
@ -883,3 +883,8 @@ RESET client_min_messages;
|
|||||||
|
|
||||||
-- leave a collation for pg_upgrade test
|
-- leave a collation for pg_upgrade test
|
||||||
CREATE COLLATION coll_icu_upgrade FROM "und-x-icu";
|
CREATE COLLATION coll_icu_upgrade FROM "und-x-icu";
|
||||||
|
|
||||||
|
-- Test user-visible function for inspecting versions
|
||||||
|
SELECT pg_collation_actual_version('"en-x-icu"'::regcollation) is not null;
|
||||||
|
-- Invalid OIDs are silently ignored
|
||||||
|
SELECT pg_collation_actual_version(0) is null;
|
||||||
|
Loading…
Reference in New Issue
Block a user