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

Commit e3fa2b0

Browse files
committed
Fix unintentional behavior change in commit e9931bf.
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 e9931bf mistakenly eliminated that special case; this commit restores it. Discussion: https://postgr.es/m/01a104f0d2179d756261e90d96fd65c36ad6fcf0.camel@j-davis.com
1 parent 4171c44 commit e3fa2b0

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

src/backend/utils/adt/formatting.c

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,7 +1755,12 @@ str_tolower(const char *buff, size_t nbytes, Oid collid)
17551755
* collations you get exactly what the collation says.
17561756
*/
17571757
for (p = result; *p; p++)
1758-
*p = tolower_l((unsigned char) *p, mylocale->info.lt);
1758+
{
1759+
if (mylocale->is_default)
1760+
*p = pg_tolower((unsigned char) *p);
1761+
else
1762+
*p = tolower_l((unsigned char) *p, mylocale->info.lt);
1763+
}
17591764
}
17601765
}
17611766
}
@@ -1892,7 +1897,12 @@ str_toupper(const char *buff, size_t nbytes, Oid collid)
18921897
* collations you get exactly what the collation says.
18931898
*/
18941899
for (p = result; *p; p++)
1895-
*p = toupper_l((unsigned char) *p, mylocale->info.lt);
1900+
{
1901+
if (mylocale->is_default)
1902+
*p = pg_toupper((unsigned char) *p);
1903+
else
1904+
*p = toupper_l((unsigned char) *p, mylocale->info.lt);
1905+
}
18961906
}
18971907
}
18981908
}
@@ -2090,10 +2100,20 @@ str_initcap(const char *buff, size_t nbytes, Oid collid)
20902100
*/
20912101
for (p = result; *p; p++)
20922102
{
2093-
if (wasalnum)
2094-
*p = tolower_l((unsigned char) *p, mylocale->info.lt);
2103+
if (mylocale->is_default)
2104+
{
2105+
if (wasalnum)
2106+
*p = pg_tolower((unsigned char) *p);
2107+
else
2108+
*p = pg_toupper((unsigned char) *p);
2109+
}
20952110
else
2096-
*p = toupper_l((unsigned char) *p, mylocale->info.lt);
2111+
{
2112+
if (wasalnum)
2113+
*p = tolower_l((unsigned char) *p, mylocale->info.lt);
2114+
else
2115+
*p = toupper_l((unsigned char) *p, mylocale->info.lt);
2116+
}
20972117
wasalnum = isalnum_l((unsigned char) *p, mylocale->info.lt);
20982118
}
20992119
}

src/backend/utils/adt/like.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ SB_lower_char(unsigned char c, pg_locale_t locale)
9595
{
9696
if (locale->ctype_is_c)
9797
return pg_ascii_tolower(c);
98+
else if (locale->is_default)
99+
return pg_tolower(c);
98100
else
99101
return tolower_l(c, locale->info.lt);
100102
}

src/backend/utils/adt/pg_locale.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,7 @@ create_pg_locale(Oid collid, MemoryContext context)
12161216

12171217
result->provider = collform->collprovider;
12181218
result->deterministic = collform->collisdeterministic;
1219+
result->is_default = false;
12191220

12201221
if (collform->collprovider == COLLPROVIDER_BUILTIN)
12211222
{
@@ -1409,6 +1410,7 @@ init_database_collation(void)
14091410

14101411

14111412
default_locale.provider = dbform->datlocprovider;
1413+
default_locale.is_default = true;
14121414

14131415
/*
14141416
* Default locale is currently always deterministic. Nondeterministic

src/include/utils/pg_locale.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ struct pg_locale_struct
8282
bool deterministic;
8383
bool collate_is_c;
8484
bool ctype_is_c;
85+
bool is_default;
8586
union
8687
{
8788
struct

0 commit comments

Comments
 (0)