Commit 1e165d05 authored by Tom Lane's avatar Tom Lane

Try to deliver a sane message for _create_locale() failure on Windows.

We were just printing errno, which is certainly not gonna work on
Windows.  Now, it's not entirely clear from Microsoft's documentation
whether _create_locale() adheres to standard Windows error reporting
conventions, but let's assume it does and try to map the GetLastError
result to an errno.  If this turns out not to work, probably the best
thing to do will be to assume the error is always ENOENT on Windows.

This is a longstanding bug, but given the lack of previous field
complaints, I'm not excited about back-patching it.

Per report from Murtuza Zabuawala.

Discussion: https://postgr.es/m/CAKKotZS-wcDcofXDCH=sidiuajE+nqHn2CGjLLX78anyDmi3gQ@mail.gmail.com
parent c1bb7870
...@@ -1227,13 +1227,18 @@ lc_ctype_is_c(Oid collation) ...@@ -1227,13 +1227,18 @@ lc_ctype_is_c(Oid collation)
static void static void
report_newlocale_failure(const char *localename) report_newlocale_failure(const char *localename)
{ {
/* copy errno in case one of the ereport auxiliary functions changes it */ int save_errno;
int save_errno = errno;
/* On Windows, transform _create_locale() error to errno */
#ifdef WIN32
_dosmaperr(GetLastError());
#endif
/* /*
* ENOENT means "no such locale", not "no such file", so clarify that * ENOENT means "no such locale", not "no such file", so clarify that
* errno with an errdetail message. * errno with an errdetail message.
*/ */
save_errno = errno; /* auxiliary funcs might change errno */
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE), (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("could not create locale \"%s\": %m", errmsg("could not create locale \"%s\": %m",
......
...@@ -627,6 +627,9 @@ CREATE COLLATION mycoll1 FROM "C"; ...@@ -627,6 +627,9 @@ CREATE COLLATION mycoll1 FROM "C";
CREATE COLLATION mycoll2 ( LC_COLLATE = "POSIX", LC_CTYPE = "POSIX" ); CREATE COLLATION mycoll2 ( LC_COLLATE = "POSIX", LC_CTYPE = "POSIX" );
CREATE COLLATION mycoll3 FROM "default"; -- intentionally unsupported CREATE COLLATION mycoll3 FROM "default"; -- intentionally unsupported
ERROR: collation "default" cannot be copied ERROR: collation "default" cannot be copied
CREATE COLLATION mycoll4 ( LOCALE = "no_such_locale" ); -- fail
ERROR: could not create locale "no_such_locale": No such file or directory
DETAIL: The operating system could not find any locale data for the locale name "no_such_locale".
DROP COLLATION mycoll1; DROP COLLATION mycoll1;
CREATE TABLE collate_test23 (f1 text collate mycoll2); CREATE TABLE collate_test23 (f1 text collate mycoll2);
DROP COLLATION mycoll2; -- fail DROP COLLATION mycoll2; -- fail
......
...@@ -234,6 +234,7 @@ EXPLAIN (COSTS OFF) ...@@ -234,6 +234,7 @@ EXPLAIN (COSTS OFF)
CREATE COLLATION mycoll1 FROM "C"; CREATE COLLATION mycoll1 FROM "C";
CREATE COLLATION mycoll2 ( LC_COLLATE = "POSIX", LC_CTYPE = "POSIX" ); CREATE COLLATION mycoll2 ( LC_COLLATE = "POSIX", LC_CTYPE = "POSIX" );
CREATE COLLATION mycoll3 FROM "default"; -- intentionally unsupported CREATE COLLATION mycoll3 FROM "default"; -- intentionally unsupported
CREATE COLLATION mycoll4 ( LOCALE = "no_such_locale" ); -- fail
DROP COLLATION mycoll1; DROP COLLATION mycoll1;
CREATE TABLE collate_test23 (f1 text collate mycoll2); CREATE TABLE collate_test23 (f1 text collate mycoll2);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment