From 8f8a5df694e7a012dfd762cb74d2083d83cf573b Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 12 Nov 2009 02:46:16 +0000 Subject: Make initdb behave sanely when the selected locale has codeset "US-ASCII". Per discussion, this should result in defaulting to SQL_ASCII encoding. The original coding could not support that because it conflated selection of SQL_ASCII encoding with not being able to determine the encoding. Adjust pg_get_encoding_from_locale()'s API to distinguish these cases, and fix callers appropriately. Only initdb actually changes behavior, since the other callers were perfectly content to consider these cases equivalent. Per bug #5178 from Boh Yap. Not going to bother back-patching, since no one has complained before and there's an easy workaround (namely, specify the encoding you want). --- src/backend/utils/mb/mbutils.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/backend/utils/mb/mbutils.c') diff --git a/src/backend/utils/mb/mbutils.c b/src/backend/utils/mb/mbutils.c index 5aaaae502f8..c8a43dced6f 100644 --- a/src/backend/utils/mb/mbutils.c +++ b/src/backend/utils/mb/mbutils.c @@ -4,7 +4,7 @@ * * Tatsuo Ishii * - * $PostgreSQL: pgsql/src/backend/utils/mb/mbutils.c,v 1.91 2009/10/17 05:14:52 mha Exp $ + * $PostgreSQL: pgsql/src/backend/utils/mb/mbutils.c,v 1.92 2009/11/12 02:46:16 tgl Exp $ */ #include "postgres.h" @@ -984,7 +984,14 @@ int GetPlatformEncoding(void) { if (PlatformEncoding == NULL) - PlatformEncoding = &pg_enc2name_tbl[pg_get_encoding_from_locale("")]; + { + /* try to determine encoding of server's environment locale */ + int encoding = pg_get_encoding_from_locale(""); + + if (encoding < 0) + encoding = PG_SQL_ASCII; + PlatformEncoding = &pg_enc2name_tbl[encoding]; + } return PlatformEncoding->encoding; } -- cgit v1.2.3