1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-21 00:42:43 +03:00

Solve the 'Turkish problem' with undesirable locale behavior for case

conversion of basic ASCII letters.  Remove all uses of strcasecmp and
strncasecmp in favor of new functions pg_strcasecmp and pg_strncasecmp;
remove most but not all direct uses of toupper and tolower in favor of
pg_toupper and pg_tolower.  These functions use the same notions of
case folding already developed for identifier case conversion.  I left
the straight locale-based folding in place for situations where we are
just manipulating user data and not trying to match it to built-in
strings --- for example, the SQL upper() function is still locale
dependent.  Perhaps this will prove not to be what's wanted, but at
the moment we can initdb and pass regression tests in Turkish locale.
This commit is contained in:
Tom Lane
2004-05-07 00:24:59 +00:00
parent 4d46274b33
commit 0bd61548ab
67 changed files with 820 additions and 923 deletions

View File

@@ -495,7 +495,7 @@ PGTYPESdate_defmt_asc(date * d, char *fmt, char *str)
/* convert the whole string to lower case */
for (i = 0; str_copy[i]; i++)
str_copy[i] = (char) tolower((unsigned char) str_copy[i]);
str_copy[i] = (char) pg_tolower((unsigned char) str_copy[i]);
}
/* look for numerical tokens */
@@ -565,7 +565,7 @@ PGTYPESdate_defmt_asc(date * d, char *fmt, char *str)
{
for (j = 0; j < PGTYPES_DATE_MONTH_MAXLENGTH; j++)
{
month_lower_tmp[j] = (char) tolower((unsigned char) list[i][j]);
month_lower_tmp[j] = (char) pg_tolower((unsigned char) list[i][j]);
if (!month_lower_tmp[j])
{
/* properly terminated */

View File

@@ -1847,7 +1847,7 @@ ParseDateTime(char *timestr, char *lowstr,
{
ftype[nf] = DTK_DATE;
while (isalnum((unsigned char) *(*endstr)) || (*(*endstr) == *dp))
*lp++ = tolower((unsigned char) *(*endstr)++);
*lp++ = pg_tolower((unsigned char) *(*endstr)++);
}
}
@@ -1875,9 +1875,9 @@ ParseDateTime(char *timestr, char *lowstr,
else if (isalpha((unsigned char) *(*endstr)))
{
ftype[nf] = DTK_STRING;
*lp++ = tolower((unsigned char) *(*endstr)++);
*lp++ = pg_tolower((unsigned char) *(*endstr)++);
while (isalpha((unsigned char) *(*endstr)))
*lp++ = tolower((unsigned char) *(*endstr)++);
*lp++ = pg_tolower((unsigned char) *(*endstr)++);
/*
* Full date string with leading text month? Could also be a
@@ -1919,9 +1919,9 @@ ParseDateTime(char *timestr, char *lowstr,
else if (isalpha((unsigned char) *(*endstr)))
{
ftype[nf] = DTK_SPECIAL;
*lp++ = tolower((unsigned char) *(*endstr)++);
*lp++ = pg_tolower((unsigned char) *(*endstr)++);
while (isalpha((unsigned char) *(*endstr)))
*lp++ = tolower((unsigned char) *(*endstr)++);
*lp++ = pg_tolower((unsigned char) *(*endstr)++);
}
/* otherwise something wrong... */
else
@@ -3115,7 +3115,7 @@ PGTYPEStimestamp_defmt_scan(char **str, char *fmt, timestamp *d,
*/
for (j = 0; !err && j < szdatetktbl; j++)
{
if (strcasecmp(datetktbl[j].token, scan_val.str_val) == 0)
if (pg_strcasecmp(datetktbl[j].token, scan_val.str_val) == 0)
{
/*
* tz calculates the offset for the seconds, the

View File

@@ -1,4 +1,4 @@
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.279 2004/05/05 15:03:04 meskes Exp $ */
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.280 2004/05/07 00:24:59 tgl Exp $ */
/* Copyright comment */
%{
@@ -609,7 +609,7 @@ stmt: AlterDatabaseSetStmt { output_statement($1, 0, connection); }
/* Informix also has a CLOSE DATABASE command that
essantially works like a DISCONNECT CURRENT
as far as I know. */
if (strcasecmp($1+strlen("close "), "database") == 0)
if (pg_strcasecmp($1+strlen("close "), "database") == 0)
{
if (connection)
mmerror(PARSE_ERROR, ET_ERROR, "no at option for close database statement.\n");

View File

@@ -4,7 +4,7 @@
#
# Copyright (c) 1994, Regents of the University of California
#
# $PostgreSQL: pgsql/src/interfaces/libpq/Makefile,v 1.103 2004/04/25 20:57:32 momjian Exp $
# $PostgreSQL: pgsql/src/interfaces/libpq/Makefile,v 1.104 2004/05/07 00:24:59 tgl Exp $
#
#-------------------------------------------------------------------------
@@ -24,7 +24,7 @@ override CFLAGS += $(PTHREAD_CFLAGS)
OBJS= fe-auth.o fe-connect.o fe-exec.o fe-misc.o fe-print.o fe-lobj.o \
fe-protocol2.o fe-protocol3.o pqexpbuffer.o pqsignal.o fe-secure.o \
dllist.o md5.o ip.o wchar.o encnames.o \
$(filter crypt.o getaddrinfo.o inet_aton.o noblock.o snprintf.o strerror.o open.o path.o thread.o, $(LIBOBJS))
$(filter crypt.o getaddrinfo.o inet_aton.o noblock.o pgstrcasecmp.o snprintf.o strerror.o open.o path.o thread.o, $(LIBOBJS))
ifeq ($(PORTNAME), win32)
OBJS+=win32.o
endif
@@ -53,7 +53,7 @@ backend_src = $(top_srcdir)/src/backend
# For port modules, this only happens if configure decides the module
# is needed (see filter hack in OBJS, above).
crypt.c getaddrinfo.c inet_aton.c noblock.c snprintf.c strerror.c open.c path.c thread.c: % : $(top_srcdir)/src/port/%
crypt.c getaddrinfo.c inet_aton.c noblock.c pgstrcasecmp.c snprintf.c strerror.c open.c path.c thread.c: % : $(top_srcdir)/src/port/%
rm -f $@ && $(LN_S) $< .
md5.c ip.c: % : $(backend_src)/libpq/%
@@ -79,4 +79,4 @@ uninstall: uninstall-lib
rm -f $(DESTDIR)$(includedir)/libpq-fe.h $(DESTDIR)$(includedir_internal)/libpq-int.h $(DESTDIR)$(includedir_internal)/pqexpbuffer.h
clean distclean maintainer-clean: clean-lib
rm -f $(OBJS) crypt.c getaddrinfo.c inet_aton.c noblock.c snprintf.c strerror.c open.c path.c thread.c dllist.c md5.c ip.c encnames.c wchar.c
rm -f $(OBJS) crypt.c getaddrinfo.c inet_aton.c noblock.c pgstrcasecmp.c snprintf.c strerror.c open.c path.c thread.c dllist.c md5.c ip.c encnames.c wchar.c

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.158 2004/03/14 22:00:54 tgl Exp $
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.159 2004/05/07 00:24:59 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1904,8 +1904,7 @@ PQfnumber(const PGresult *res, const char *field_name)
}
else
{
if (isupper((unsigned char) c))
c = tolower((unsigned char) c);
c = pg_tolower((unsigned char) c);
*optr++ = c;
}
}

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-protocol2.c,v 1.10 2004/03/05 01:53:59 tgl Exp $
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-protocol2.c,v 1.11 2004/05/07 00:24:59 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -117,7 +117,7 @@ pqSetenvPoll(PGconn *conn)
if ((val = getenv(conn->next_eo->envName)))
{
if (strcasecmp(val, "default") == 0)
if (pg_strcasecmp(val, "default") == 0)
sprintf(setQuery, "SET %s = DEFAULT",
conn->next_eo->pgName);
else

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-protocol3.c,v 1.12 2004/03/21 22:29:11 tgl Exp $
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-protocol3.c,v 1.13 2004/05/07 00:24:59 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1471,7 +1471,7 @@ build_startup_packet(const PGconn *conn, char *packet,
if ((val = getenv(next_eo->envName)) != NULL)
{
if (strcasecmp(val, "default") != 0)
if (pg_strcasecmp(val, "default") != 0)
{
if (packet)
strcpy(packet + packet_len, next_eo->pgName);

View File

@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.39 2004/03/27 03:08:42 tgl Exp $
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.40 2004/05/07 00:24:59 tgl Exp $
*
* NOTES
* The client *requires* a valid server certificate. Since
@@ -544,7 +544,7 @@ verify_peer(PGconn *conn)
*/
for (s = h->h_aliases; *s != NULL; s++)
{
if (strcasecmp(conn->peer_cn, *s) == 0)
if (pg_strcasecmp(conn->peer_cn, *s) == 0)
return 0;
}

View File

@@ -2,18 +2,11 @@
#define __win32_h_included
/*
* strcasecmp() is not in Windows, stricmp is, though
*/
#define strcasecmp(a,b) stricmp(a,b)
#define strncasecmp(a,b,c) _strnicmp(a,b,c)
/*
* Some other compat functions
* Some compatibility functions
*/
#ifdef __BORLANDC__
#define _timeb timeb
#define _ftime(a) ftime(a)
#define _strnicmp(a,b,c) strnicmp(a,b,c)
#define _errno errno
#else
/* open provided elsewhere */