*** src/backend/utils/adt/pg_locale.c.orig Sat Sep 13 19:13:13 2008 --- src/backend/utils/adt/pg_locale.c Thu Sep 25 00:10:07 2008 *************** *** 54,59 **** --- 54,60 ---- #include "utils/memutils.h" #include "utils/pg_locale.h" + #include "mb/pg_wchar.h" #define MAX_L10N_DATA 80 *************** *** 438,443 **** --- 439,507 ---- CurrentLocaleConvValid = true; return &CurrentLocaleConv; } + + #ifdef WIN32 + /* + * result is obtained by locale setup of LC_TIME in the environment + * of windows at present CP_ACP. Therefore, conversion is needed + * for SERVER_ENCODING. SJIS which is not especially made to server + * encoding in Japan returns. + */ + #define STRLEN_MAX 255 + size_t + conv_strftime(char *src, size_t len, const char *format, const struct tm *tm) + { + char timesrc[STRLEN_MAX]; + char widechar[STRLEN_MAX]; + char *convstr; + int dest_encoding; + + strftime(timesrc, len, format, tm); + dest_encoding = GetDatabaseEncoding(); + if (dest_encoding == PG_SQL_ASCII) + { + memcpy(src, timesrc, len); + src[len] = '\0'; + return len; + } + + len = MultiByteToWideChar(CP_ACP, 0, timesrc, len, + (LPWSTR)widechar, STRLEN_MAX); + if (!len) + ereport(ERROR, + (errmsg("could not convert string to wide character:error %lu", GetLastError()))); + len = WideCharToMultiByte(CP_UTF8, 0, (LPWSTR)widechar, + -1, timesrc, STRLEN_MAX, NULL, NULL); + if (!len) + ereport(ERROR, + (errmsg("could not convert wide character to UTF-8:error %lu", GetLastError()))); + + timesrc[len] = '\0'; + + if (dest_encoding == PG_UTF8) + { + convstr = pnstrdup(timesrc, len); + } + else + { + convstr = pg_do_encoding_conversion(timesrc, len, PG_UTF8, dest_encoding); + if (convstr == NULL) + { + elog(ERROR, "encoding conversion failed"); + } + len = strlen(convstr); + } + + memcpy(src, convstr, len); + src[len] = '\0'; + pfree(convstr); + + return len; + } + + #define strftime(a,b,c,d) conv_strftime(a,b,c,d) + + #endif /* WIN32 */ /*