Commit decb9c63 authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

Fixed sql_perror() to return appropriate error messages on Windows,

The error message is now based on GetLastError() rather than errno. 

Background: errno is C runtime specific and in many circumstances 
it is not set, e.g when using Win32 API or socket functions.
parent 79afbf76
......@@ -5261,9 +5261,23 @@ static bool test_if_number(register const char *str,
void sql_perror(const char *message)
{
#ifdef HAVE_STRERROR
#if defined(_WIN32)
char* buf;
DWORD dw= GetLastError();
if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&buf, 0, NULL ) > 0)
{
sql_print_error("%s: %s",message, buf);
LocalFree((HLOCAL)buf);
}
else
{
sql_print_error("%s", message);
}
#elif defined(HAVE_STRERROR)
sql_print_error("%s: %s",message, strerror(errno));
#else
#else
perror(message);
#endif
}
......
......@@ -8894,7 +8894,7 @@ mysqld_get_one_option(int optid,
}
case OPT_EVENT_SCHEDULER:
#ifndef HAVE_EVENT_SCHEDULER
sql_perror("Event scheduler is not supported in embedded build.");
sql_print_error("Event scheduler is not supported in embedded build.");
#else
if (Events::set_opt_event_scheduler(argument))
return 1;
......
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