Skip to content

Commit 352f6f2

Browse files
committed
Add collation versions for Windows.
On Vista and later, use GetNLSVersionEx() to request collation version information. Reviewed-by: Juan José Santamaría Flecha <juanjo.santamaria@gmail.com> Discussion: https://postgr.es/m/CA%2BhUKGJvqup3s%2BJowVTcacZADO6dOhfdBmvOPHLS3KXUJu41Jw%40mail.gmail.com
1 parent 382a821 commit 352f6f2

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/backend/utils/adt/pg_locale.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,6 +1555,33 @@ get_collation_actual_version(char collprovider, const char *collcollate)
15551555

15561556
/* Use the glibc version because we don't have anything better. */
15571557
collversion = pstrdup(gnu_get_libc_version());
1558+
#elif defined(WIN32) && _WIN32_WINNT >= 0x0600
1559+
/*
1560+
* If we are targeting Windows Vista and above, we can ask for a name
1561+
* given a collation name (earlier versions required a location code
1562+
* that we don't have).
1563+
*/
1564+
NLSVERSIONINFOEX version = {sizeof(NLSVERSIONINFOEX)};
1565+
WCHAR wide_collcollate[LOCALE_NAME_MAX_LENGTH];
1566+
1567+
/* These would be invalid arguments, but have no version. */
1568+
if (pg_strcasecmp("c", collcollate) == 0 ||
1569+
pg_strcasecmp("posix", collcollate) == 0)
1570+
return NULL;
1571+
1572+
/* For all other names, ask the OS. */
1573+
MultiByteToWideChar(CP_ACP, 0, collcollate, -1, wide_collcollate,
1574+
LOCALE_NAME_MAX_LENGTH);
1575+
if (!GetNLSVersionEx(COMPARE_STRING, wide_collcollate, &version))
1576+
ereport(ERROR,
1577+
(errmsg("could not get collation version for locale \"%s\": error code %lu",
1578+
collcollate,
1579+
GetLastError())));
1580+
collversion = psprintf("%d.%d,%d.%d",
1581+
(version.dwNLSVersion >> 8) & 0xFFFF,
1582+
version.dwNLSVersion & 0xFF,
1583+
(version.dwDefinedVersion >> 8) & 0xFFFF,
1584+
version.dwDefinedVersion & 0xFF);
15581585
#endif
15591586
}
15601587

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy