DefineCollation() code cleanup

Reorganize the code in DefineCollation() so that the parts using the
FROM clause and the parts not doing so are more cleanly separated.  No
functionality change intended.

Reviewed-by: Julien Rouhaud <rjuju123@gmail.com>
Discussion: https://www.postgresql.org/message-id/29ae752f-80e9-8d31-601c-62cf01cc93d8@enterprisedb.com
This commit is contained in:
Peter Eisentraut 2022-03-11 08:27:24 +01:00
parent 9198e63996
commit e94bb1473e
1 changed files with 57 additions and 52 deletions

View File

@ -63,12 +63,11 @@ DefineCollation(ParseState *pstate, List *names, List *parameters, bool if_not_e
DefElem *providerEl = NULL; DefElem *providerEl = NULL;
DefElem *deterministicEl = NULL; DefElem *deterministicEl = NULL;
DefElem *versionEl = NULL; DefElem *versionEl = NULL;
char *collcollate = NULL; char *collcollate;
char *collctype = NULL; char *collctype;
char *collproviderstr = NULL; bool collisdeterministic;
bool collisdeterministic = true; int collencoding;
int collencoding = 0; char collprovider;
char collprovider = 0;
char *collversion = NULL; char *collversion = NULL;
Oid newoid; Oid newoid;
ObjectAddress address; ObjectAddress address;
@ -167,65 +166,71 @@ DefineCollation(ParseState *pstate, List *names, List *parameters, bool if_not_e
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION), (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("collation \"default\" cannot be copied"))); errmsg("collation \"default\" cannot be copied")));
} }
else
if (localeEl)
{ {
collcollate = defGetString(localeEl); char *collproviderstr = NULL;
collctype = defGetString(localeEl);
}
if (lccollateEl) collcollate = NULL;
collcollate = defGetString(lccollateEl); collctype = NULL;
if (lcctypeEl) if (localeEl)
collctype = defGetString(lcctypeEl); {
collcollate = defGetString(localeEl);
collctype = defGetString(localeEl);
}
if (providerEl) if (lccollateEl)
collproviderstr = defGetString(providerEl); collcollate = defGetString(lccollateEl);
if (deterministicEl) if (lcctypeEl)
collisdeterministic = defGetBoolean(deterministicEl); collctype = defGetString(lcctypeEl);
if (versionEl) if (providerEl)
collversion = defGetString(versionEl); collproviderstr = defGetString(providerEl);
if (collproviderstr) if (deterministicEl)
{ collisdeterministic = defGetBoolean(deterministicEl);
if (pg_strcasecmp(collproviderstr, "icu") == 0)
collprovider = COLLPROVIDER_ICU;
else if (pg_strcasecmp(collproviderstr, "libc") == 0)
collprovider = COLLPROVIDER_LIBC;
else else
collisdeterministic = true;
if (versionEl)
collversion = defGetString(versionEl);
if (collproviderstr)
{
if (pg_strcasecmp(collproviderstr, "icu") == 0)
collprovider = COLLPROVIDER_ICU;
else if (pg_strcasecmp(collproviderstr, "libc") == 0)
collprovider = COLLPROVIDER_LIBC;
else
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("unrecognized collation provider: %s",
collproviderstr)));
}
else
collprovider = COLLPROVIDER_LIBC;
if (!collcollate)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION), (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("unrecognized collation provider: %s", errmsg("parameter \"lc_collate\" must be specified")));
collproviderstr)));
}
else if (!fromEl)
collprovider = COLLPROVIDER_LIBC;
if (!collcollate) if (!collctype)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION), (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("parameter \"lc_collate\" must be specified"))); errmsg("parameter \"lc_ctype\" must be specified")));
if (!collctype) /*
ereport(ERROR, * Nondeterministic collations are currently only supported with ICU
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION), * because that's the only case where it can actually make a difference.
errmsg("parameter \"lc_ctype\" must be specified"))); * So we can save writing the code for the other providers.
*/
if (!collisdeterministic && collprovider != COLLPROVIDER_ICU)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("nondeterministic collations not supported with this provider")));
/*
* Nondeterministic collations are currently only supported with ICU
* because that's the only case where it can actually make a difference.
* So we can save writing the code for the other providers.
*/
if (!collisdeterministic && collprovider != COLLPROVIDER_ICU)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("nondeterministic collations not supported with this provider")));
if (!fromEl)
{
if (collprovider == COLLPROVIDER_ICU) if (collprovider == COLLPROVIDER_ICU)
{ {
#ifdef USE_ICU #ifdef USE_ICU