On fre, 2011-02-25 at 21:32 +0200, Peter Eisentraut wrote:
> According to the online documentation, the APIs are there:
> http://msdn.microsoft.com/en-ca/library/a7cwbx4t.aspx
> 
> Now we'd need someone brave try to make it work.  The starting point
> would be to define HAVE_LOCALE_T and then make it build.  Microsoft has
> all the relevant functions and types with an underscore in front
> (_strcoll_l, etc.), so some extra #defining will probably be necessary.

OK, I got that working now.  Patch attached.

> Also, initdb will need to be patched to get a list of OS locales to
> populate the pg_collation catalog with.

That still needs work, but you can run CREATE COLLATION manually.

> Finally, a regression test customized for Windows, but I can help with
> that later.

If you doctor the existing linux test to create appropriately named
collations before running the actual tests, and you hack the
vcregress.pl driver script to run the tests in UTF8 instead of
SQL_ASCII, then all the tests except the Turkish case conversion tests
pass.  So looks pretty good so far.

diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c
index 163856d..ff7de38 100644
--- a/src/backend/utils/adt/pg_locale.c
+++ b/src/backend/utils/adt/pg_locale.c
@@ -962,8 +962,12 @@ pg_newlocale_from_collation(Oid collid)
 		if (strcmp(collcollate, collctype) == 0)
 		{
 			/* Normal case where they're the same */
+#ifndef WIN32
 			result = newlocale(LC_COLLATE_MASK | LC_CTYPE_MASK, collcollate,
 							   NULL);
+#else
+			result = _create_locale(LC_ALL, collcollate);
+#endif
 			if (!result)
 				ereport(ERROR,
 						(errcode_for_file_access(),
@@ -972,6 +976,7 @@ pg_newlocale_from_collation(Oid collid)
 		}
 		else
 		{
+#ifndef WIN32
 			/* We need two newlocale() steps */
 			locale_t loc1;
 
@@ -987,6 +992,9 @@ pg_newlocale_from_collation(Oid collid)
 						(errcode_for_file_access(),
 						 errmsg("could not create locale \"%s\": %m",
 								collctype)));
+#else
+			elog(ERROR, "not supported");
+#endif
 		}
 
 		cache_entry->locale = result;
diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c
index 3587fe4..04b0326 100644
--- a/src/backend/utils/adt/varlena.c
+++ b/src/backend/utils/adt/varlena.c
@@ -1374,7 +1374,10 @@ varstr_cmp(char *arg1, int len1, char *arg2, int len2, Oid collid)
 			((LPWSTR) a2p)[r] = 0;
 
 			errno = 0;
-			result = wcscoll((LPWSTR) a1p, (LPWSTR) a2p);
+			if (mylocale)
+				result = _wcscoll_l((LPWSTR) a1p, (LPWSTR) a2p, mylocale);
+			else
+				result = wcscoll((LPWSTR) a1p, (LPWSTR) a2p);
 			if (result == 2147483647)	/* _NLSCMPERROR; missing from mingw
 										 * headers */
 				ereport(ERROR,
diff --git a/src/include/pg_config.h.win32 b/src/include/pg_config.h.win32
index 79b8036..8eae0b4 100644
--- a/src/include/pg_config.h.win32
+++ b/src/include/pg_config.h.win32
@@ -683,3 +683,5 @@
 /* Define to empty if the keyword `volatile' does not work. Warning: valid
    code using `volatile' can become incorrect without. Disable with care. */
 /* #undef volatile */
+
+#define HAVE_LOCALE_T 1
diff --git a/src/include/utils/pg_locale.h b/src/include/utils/pg_locale.h
index 4c72fd0..370d691 100644
--- a/src/include/utils/pg_locale.h
+++ b/src/include/utils/pg_locale.h
@@ -17,6 +17,17 @@
 #include <xlocale.h>
 #endif
 
+#ifdef WIN32
+#define locale_t _locale_t
+#define towlower_l _towlower_l
+#define towupper_l _towupper_l
+#define toupper_l _toupper_l
+#define tolower_l _tolower_l
+#define iswalnum_l _iswalnum_l
+#define isalnum_l _isalnum_l
+#define strcoll_l _strcoll_l
+#endif
+
 #include "utils/guc.h"
 
 
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to