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

Commit494f30c

Browse files
committed
Prevent locale-aware handling of upper, lower, and initcap when the
locale is C.Backpatch to 8.0.X because some operating systems were throwing errorsfor such operations, rather than ignoring the locale when it was C.
1 parent963ffe4 commit494f30c

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
*$PostgreSQL: pgsql/src/backend/utils/adt/oracle_compat.c,v 1.57 2004/12/31 22:01:22 pgsql Exp $
12+
*$PostgreSQL: pgsql/src/backend/utils/adt/oracle_compat.c,v 1.58 2005/03/16 00:02:48 momjian Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -166,8 +166,8 @@ Datum
166166
lower(PG_FUNCTION_ARGS)
167167
{
168168
#ifdefUSE_WIDE_UPPER_LOWER
169-
/* use wide char code only when max encoding length >one */
170-
if (pg_database_encoding_max_length()>1)
169+
/* use wide char code only when max encoding length >1 and ctype != C */
170+
if (pg_database_encoding_max_length()>1&& !lc_ctype_is_c())
171171
{
172172
text*string=PG_GETARG_TEXT_P(0);
173173
text*result;
@@ -228,8 +228,8 @@ Datum
228228
upper(PG_FUNCTION_ARGS)
229229
{
230230
#ifdefUSE_WIDE_UPPER_LOWER
231-
/* use wide char code only when max encoding length >one */
232-
if (pg_database_encoding_max_length()>1)
231+
/* use wide char code only when max encoding length >1 and ctype != C */
232+
if (pg_database_encoding_max_length()>1&& !lc_ctype_is_c())
233233
{
234234
text*string=PG_GETARG_TEXT_P(0);
235235
text*result;
@@ -293,8 +293,8 @@ Datum
293293
initcap(PG_FUNCTION_ARGS)
294294
{
295295
#ifdefUSE_WIDE_UPPER_LOWER
296-
/* use wide char code only when max encoding length >one */
297-
if (pg_database_encoding_max_length()>1)
296+
/* use wide char code only when max encoding length >1 and ctype != C */
297+
if (pg_database_encoding_max_length()>1&& !lc_ctype_is_c())
298298
{
299299
text*string=PG_GETARG_TEXT_P(0);
300300
text*result;

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* Portions Copyright (c) 2002-2005, PostgreSQL Global Development Group
66
*
7-
* $PostgreSQL: pgsql/src/backend/utils/adt/pg_locale.c,v 1.30 2005/01/01 05:43:07 momjian Exp $
7+
* $PostgreSQL: pgsql/src/backend/utils/adt/pg_locale.c,v 1.31 2005/03/16 00:02:49 momjian Exp $
88
*
99
*-----------------------------------------------------------------------
1010
*/
@@ -196,6 +196,33 @@ lc_collate_is_c(void)
196196
}
197197

198198

199+
/*
200+
* We'd like to cache whether LC_CTYPE is C (or POSIX), so we can
201+
* optimize a few code paths in various places.
202+
*/
203+
bool
204+
lc_ctype_is_c(void)
205+
{
206+
/* Cache result so we only have to compute it once */
207+
staticintresult=-1;
208+
char*localeptr;
209+
210+
if (result >=0)
211+
return (bool)result;
212+
localeptr=setlocale(LC_CTYPE,NULL);
213+
if (!localeptr)
214+
elog(ERROR,"invalid LC_CTYPE setting");
215+
216+
if (strcmp(localeptr,"C")==0)
217+
result= true;
218+
elseif (strcmp(localeptr,"POSIX")==0)
219+
result= true;
220+
else
221+
result= false;
222+
return (bool)result;
223+
}
224+
225+
199226
/*
200227
* Frees the malloced content of a struct lconv. (But not the struct
201228
* itself.)

‎src/include/utils/pg_locale.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* PostgreSQL locale utilities
44
*
5-
* $PostgreSQL: pgsql/src/include/utils/pg_locale.h,v 1.19 2005/01/01 05:43:09 momjian Exp $
5+
* $PostgreSQL: pgsql/src/include/utils/pg_locale.h,v 1.20 2005/03/16 00:02:49 momjian Exp $
66
*
77
* Copyright (c) 2002-2005, PostgreSQL Global Development Group
88
*
@@ -32,6 +32,7 @@ extern const char *locale_time_assign(const char *value,
3232
booldoit,GucSourcesource);
3333

3434
externboollc_collate_is_c(void);
35+
externboollc_ctype_is_c(void);
3536

3637
/*
3738
* Return the POSIX lconv struct (contains number/money formatting

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp