]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Explicitly bind gettext() to the UTF8 locale when in use.
authorMagnus Hagander <magnus@hagander.net>
Tue, 27 May 2008 12:24:46 +0000 (12:24 +0000)
committerMagnus Hagander <magnus@hagander.net>
Tue, 27 May 2008 12:24:46 +0000 (12:24 +0000)
This is required on Windows due to the special locale
handling for UTF8 that doesn't change the full environment.

Fixes crash with translated error messages per bugs 4180
and 4196.

Tom Lane

src/backend/utils/mb/mbutils.c

index 4d8043dfc83016e9ba2e778be38fb966ff722425..91977512b7f372e2a2e9b62be72892fb7595d0ac 100644 (file)
@@ -4,7 +4,7 @@
  * (currently mule internal code (mic) is used)
  * Tatsuo Ishii
  *
- * $PostgreSQL: pgsql/src/backend/utils/mb/mbutils.c,v 1.69 2008/01/09 23:43:54 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/mb/mbutils.c,v 1.69.2.1 2008/05/27 12:24:46 mha Exp $
  */
 #include "postgres.h"
 
@@ -697,6 +697,25 @@ SetDatabaseEncoding(int encoding)
 
        DatabaseEncoding = &pg_enc2name_tbl[encoding];
        Assert(DatabaseEncoding->encoding == encoding);
+
+       /*
+        * On Windows, we allow UTF-8 database encoding to be used with any
+        * locale setting, because UTF-8 requires special handling anyway.
+        * But this means that gettext() might be misled about what output
+        * encoding it should use, so we have to tell it explicitly.
+        *
+        * In future we might want to call bind_textdomain_codeset
+        * unconditionally, but that requires knowing how to spell the codeset
+        * name properly for all encodings on all platforms, which might be
+        * problematic.
+        *
+        * This is presently unnecessary, but harmless, on non-Windows platforms.
+        */
+#ifdef ENABLE_NLS
+       if (encoding == PG_UTF8)
+               if (bind_textdomain_codeset("postgres", "UTF-8") == NULL)
+                       elog(LOG, "bind_textdomain_codeset failed");
+#endif
 }
 
 void