summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Davis2024-12-03 05:59:02 +0000
committerJeff Davis2024-12-03 05:59:02 +0000
commite3fa2b037c6f0f435838e99200050dc54c306085 (patch)
treec1468cf7a07d6b637e778487e7547e09c66ef8a7
parent4171c44c9b791da3c00386dc6d8e6b1842e3036b (diff)
Fix unintentional behavior change in commit e9931bfb75.
Prior to that commit, there was special case to use ASCII case mapping behavior for the libc provider with a single-byte encoding when that's the default collation. Commit e9931bfb75 mistakenly eliminated that special case; this commit restores it. Discussion: https://postgr.es/m/[email protected]
-rw-r--r--src/backend/utils/adt/formatting.c30
-rw-r--r--src/backend/utils/adt/like.c2
-rw-r--r--src/backend/utils/adt/pg_locale.c2
-rw-r--r--src/include/utils/pg_locale.h1
4 files changed, 30 insertions, 5 deletions
diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c
index 85a7dd45619..2bcc185708c 100644
--- a/src/backend/utils/adt/formatting.c
+++ b/src/backend/utils/adt/formatting.c
@@ -1755,7 +1755,12 @@ str_tolower(const char *buff, size_t nbytes, Oid collid)
* collations you get exactly what the collation says.
*/
for (p = result; *p; p++)
- *p = tolower_l((unsigned char) *p, mylocale->info.lt);
+ {
+ if (mylocale->is_default)
+ *p = pg_tolower((unsigned char) *p);
+ else
+ *p = tolower_l((unsigned char) *p, mylocale->info.lt);
+ }
}
}
}
@@ -1892,7 +1897,12 @@ str_toupper(const char *buff, size_t nbytes, Oid collid)
* collations you get exactly what the collation says.
*/
for (p = result; *p; p++)
- *p = toupper_l((unsigned char) *p, mylocale->info.lt);
+ {
+ if (mylocale->is_default)
+ *p = pg_toupper((unsigned char) *p);
+ else
+ *p = toupper_l((unsigned char) *p, mylocale->info.lt);
+ }
}
}
}
@@ -2090,10 +2100,20 @@ str_initcap(const char *buff, size_t nbytes, Oid collid)
*/
for (p = result; *p; p++)
{
- if (wasalnum)
- *p = tolower_l((unsigned char) *p, mylocale->info.lt);
+ if (mylocale->is_default)
+ {
+ if (wasalnum)
+ *p = pg_tolower((unsigned char) *p);
+ else
+ *p = pg_toupper((unsigned char) *p);
+ }
else
- *p = toupper_l((unsigned char) *p, mylocale->info.lt);
+ {
+ if (wasalnum)
+ *p = tolower_l((unsigned char) *p, mylocale->info.lt);
+ else
+ *p = toupper_l((unsigned char) *p, mylocale->info.lt);
+ }
wasalnum = isalnum_l((unsigned char) *p, mylocale->info.lt);
}
}
diff --git a/src/backend/utils/adt/like.c b/src/backend/utils/adt/like.c
index 7b3d1b5be71..7df50b50d15 100644
--- a/src/backend/utils/adt/like.c
+++ b/src/backend/utils/adt/like.c
@@ -95,6 +95,8 @@ SB_lower_char(unsigned char c, pg_locale_t locale)
{
if (locale->ctype_is_c)
return pg_ascii_tolower(c);
+ else if (locale->is_default)
+ return pg_tolower(c);
else
return tolower_l(c, locale->info.lt);
}
diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c
index 9412cad3ac5..91cee7714b1 100644
--- a/src/backend/utils/adt/pg_locale.c
+++ b/src/backend/utils/adt/pg_locale.c
@@ -1216,6 +1216,7 @@ create_pg_locale(Oid collid, MemoryContext context)
result->provider = collform->collprovider;
result->deterministic = collform->collisdeterministic;
+ result->is_default = false;
if (collform->collprovider == COLLPROVIDER_BUILTIN)
{
@@ -1409,6 +1410,7 @@ init_database_collation(void)
default_locale.provider = dbform->datlocprovider;
+ default_locale.is_default = true;
/*
* Default locale is currently always deterministic. Nondeterministic
diff --git a/src/include/utils/pg_locale.h b/src/include/utils/pg_locale.h
index 37ecf951937..4d2262b39aa 100644
--- a/src/include/utils/pg_locale.h
+++ b/src/include/utils/pg_locale.h
@@ -82,6 +82,7 @@ struct pg_locale_struct
bool deterministic;
bool collate_is_c;
bool ctype_is_c;
+ bool is_default;
union
{
struct