4
4
* (currently mule internal code (mic) is used)
5
5
* Tatsuo Ishii
6
6
*
7
- * $PostgreSQL: pgsql/src/backend/utils/mb/mbutils.c,v 1.77 2009/01/19 15:34:23 mha Exp $
7
+ * $PostgreSQL: pgsql/src/backend/utils/mb/mbutils.c,v 1.78 2009/01/22 10:09:48 mha Exp $
8
8
*/
9
9
#include "postgres.h"
10
10
@@ -849,6 +849,46 @@ cliplen(const char *str, int len, int limit)
849
849
return l ;
850
850
}
851
851
852
+ #if defined(ENABLE_NLS ) && defined(WIN32 )
853
+ static const struct codeset_map {
854
+ int encoding ;
855
+ const char * codeset ;
856
+ } codeset_map_array [] = {
857
+ {PG_UTF8 , "UTF-8" },
858
+ {PG_LATIN1 , "LATIN1" },
859
+ {PG_LATIN2 , "LATIN2" },
860
+ {PG_LATIN3 , "LATIN3" },
861
+ {PG_LATIN4 , "LATIN4" },
862
+ {PG_ISO_8859_5 , "ISO-8859-5" },
863
+ {PG_ISO_8859_6 , "ISO_8859-6" },
864
+ {PG_ISO_8859_7 , "ISO-8859-7" },
865
+ {PG_ISO_8859_8 , "ISO-8859-8" },
866
+ {PG_LATIN5 , "LATIN5" },
867
+ {PG_LATIN6 , "LATIN6" },
868
+ {PG_LATIN7 , "LATIN7" },
869
+ {PG_LATIN8 , "LATIN8" },
870
+ {PG_LATIN9 , "LATIN-9" },
871
+ {PG_LATIN10 , "LATIN10" },
872
+ {PG_KOI8R , "KOI8-R" },
873
+ {PG_WIN1250 , "CP1250" },
874
+ {PG_WIN1251 , "CP1251" },
875
+ {PG_WIN1252 , "CP1252" },
876
+ {PG_WIN1253 , "CP1253" },
877
+ {PG_WIN1254 , "CP1254" },
878
+ {PG_WIN1255 , "CP1255" },
879
+ {PG_WIN1256 , "CP1256" },
880
+ {PG_WIN1257 , "CP1257" },
881
+ {PG_WIN1258 , "CP1258" },
882
+ {PG_WIN866 , "CP866" },
883
+ {PG_WIN874 , "CP874" },
884
+ {PG_EUC_CN , "EUC-CN" },
885
+ {PG_EUC_JP , "EUC-JP" },
886
+ {PG_EUC_KR , "EUC-KR" },
887
+ {PG_EUC_TW , "EUC-TW" },
888
+ {PG_EUC_JIS_2004 , "EUC-JP" }
889
+ };
890
+ #endif /* WIN32 */
891
+
852
892
void
853
893
SetDatabaseEncoding (int encoding )
854
894
{
@@ -859,22 +899,23 @@ SetDatabaseEncoding(int encoding)
859
899
Assert (DatabaseEncoding -> encoding == encoding );
860
900
861
901
/*
862
- * On Windows, we allow UTF-8 database encoding to be used with any
863
- * locale setting, because UTF-8 requires special handling anyway.
864
- * But this means that gettext() might be misled about what output
865
- * encoding it should use, so we have to tell it explicitly.
866
- *
867
- * In future we might want to call bind_textdomain_codeset
868
- * unconditionally, but that requires knowing how to spell the codeset
869
- * name properly for all encodings on all platforms, which might be
870
- * problematic.
871
- *
872
- * This is presently unnecessary, but harmless, on non-Windows platforms.
902
+ * On Windows, we need to explicitly bind gettext to the correct
903
+ * encoding, because gettext() tends to get confused.
873
904
*/
874
- #ifdef ENABLE_NLS
875
- if (encoding == PG_UTF8 )
876
- if (bind_textdomain_codeset (textdomain (NULL ), "UTF-8" ) == NULL )
877
- elog (LOG , "bind_textdomain_codeset failed" );
905
+ #if defined(ENABLE_NLS ) && defined(WIN32 )
906
+ {
907
+ int i ;
908
+
909
+ for (i = 0 ; i < sizeof (codeset_map_array ) / sizeof (codeset_map_array [0 ]); i ++ )
910
+ {
911
+ if (codeset_map_array [i ].encoding == encoding )
912
+ {
913
+ if (bind_textdomain_codeset (textdomain (NULL ), codeset_map_array [i ].codeset ) == NULL )
914
+ elog (LOG , "bind_textdomain_codeset failed" );
915
+ break ;
916
+ }
917
+ }
918
+ }
878
919
#endif
879
920
}
880
921
0 commit comments