CSTR func = "SQLGetDiagRecW";
RETCODE ret;
SQLSMALLINT buflen, tlen;
- char *qstr = NULL, *mtxt = NULL;
+ char qstr_ansi[8], *mtxt = NULL;
mylog("[%s]", func);
- if (szSqlState)
- qstr = malloc(8);
buflen = 0;
if (szErrorMsg && cbErrorMsgMax > 0)
{
buflen = cbErrorMsgMax;
mtxt = malloc(buflen);
}
- ret = PGAPI_GetDiagRec(fHandleType, handle, iRecord, (SQLCHAR *) qstr,
+ ret = PGAPI_GetDiagRec(fHandleType, handle, iRecord, (SQLCHAR *) qstr_ansi,
pfNativeError, (SQLCHAR *) mtxt, buflen, &tlen);
if (SQL_SUCCEEDED(ret))
{
- if (qstr)
- utf8_to_ucs2(qstr, strlen(qstr), szSqlState, 6);
+ if (szSqlState)
+ utf8_to_ucs2(qstr_ansi, -1, szSqlState, 6);
if (mtxt && tlen <= cbErrorMsgMax)
{
SQLULEN ulen = utf8_to_ucs2_lf(mtxt, tlen, FALSE, szErrorMsg, cbErrorMsgMax, TRUE);
- /*
if (ulen == (SQLULEN) -1)
- {
- tlen = (SQLSMALLINT) msgtowstr(mtxt,
- (int) tlen, (LPWSTR) szErrorMsg, (int) cbErrorMsgMax);
- }
+ tlen = (SQLSMALLINT) locale_to_sqlwchar((SQLWCHAR *) szErrorMsg, mtxt, cbErrorMsgMax, FALSE);
else
- */
tlen = (SQLSMALLINT) ulen;
if (tlen >= cbErrorMsgMax)
ret = SQL_SUCCESS_WITH_INFO;
+ else if (tlen < 0)
+ {
+ char errc[32];
+
+ snprintf(errc, sizeof(errc), "Error: SqlState=%s", qstr_ansi);
+ tlen = utf8_to_ucs2(errc, -1, szErrorMsg, cbErrorMsgMax);
+ }
}
if (pcbErrorMsg)
*pcbErrorMsg = tlen;
}
- if (qstr)
- free(qstr);
if (mtxt)
free(mtxt);
return ret;
if (SQL_SUCCEEDED(ret))
{
SQLULEN ulen = (SQLSMALLINT) utf8_to_ucs2_lf(rgbD, blen, FALSE, (SQLWCHAR *) rgbDiagInfo, cbDiagInfoMax / WCLEN, TRUE);
- /*
if (ulen == (SQLULEN) -1)
- {
- blen = (SQLSMALLINT) msgtowstr(rgbD,
- (int) blen, (LPWSTR) rgbDiagInfo, (int) cbDiagInfoMax / WCLEN);
- }
+ blen = (SQLSMALLINT) locale_to_sqlwchar((SQLWCHAR *) rgbDiagInfo, rgbD, cbDiagInfoMax / WCLEN, FALSE);
else
- */
blen = (SQLSMALLINT) ulen;
if (SQL_SUCCESS == ret && blen * WCLEN >= cbDiagInfoMax)
ret = SQL_SUCCESS_WITH_INFO;
#include <string.h>
#include <ctype.h>
+#ifdef WIN32
+#define FORMAT_SIZE_T "%Iu"
+#else
+#define FORMAT_SIZE_T "%zu"
+#endif
+
#if (defined(__STDC_ISO_10646__) && defined(HAVE_MBSTOWCS) && defined(HAVE_WCSTOMBS)) || defined(WIN32)
#define __WCS_ISO10646__
static BOOL use_wcs = FALSE;
int crt = 1;
little_endian = (0 != ((char *) &crt)[0]);
}
- if (SQL_NTS == ilen)
+ if (ilen < 0)
ilen = ucs2strlen(ucs2str);
mylog(" newlen=%d", ilen);
utf8str = (char *) malloc(ilen * 4 + 1);
* Convert a string from UTF-8 encoding to UCS-2.
*
* utf8str - input string in UTF-8
- * ilen - length of input string in bytes (or SQL_NTS)
+ * ilen - length of input string in bytes (or minus)
* lfconv - TRUE if line feeds (LF) should be converted to CR + LF
* ucs2str - output buffer
* bufcount - size of output buffer
int crt = 1;
little_endian = (0 != ((char *) &crt)[0]);
}
- if (SQL_NTS == ilen)
+ if (ilen < 0)
ilen = ucs4strlen(ucs4str);
mylog(" newlen=%d\n", ilen);
utf8str = (char *) malloc(ilen * 4 + 1);
* Convert a string from UTF-8 encoding to UTF-32.
*
* utf8str - input string in UTF-8
- * ilen - length of input string in bytes (or SQL_NTS)
+ * ilen - length of input string in bytes (or minus)
* lfconv - TRUE if line feeds (LF) should be converted to CR + LF
* ucs4str - output buffer
* bufcount - size of output buffer
outmsg[buflen - 1] = 0;
mylog(" %s:out=%dchars truncated to %d\n", __FUNCTION__, outlen, buflen - 1);
}
-mylog(" %s in=%dchars out=%dchars\n", __FUNCTION__, buflen, outlen);
+mylog(" %s buf=%dchars out=%dchars\n", __FUNCTION__, buflen, outlen);
return outlen;
}
char *utf8 = NULL;
int count = strlen(ldt);
+ get_convtype();
mylog(" %s\n", __FUNCTION__);
#if defined(__WCS_ISO10646__)
if (use_wcs)
wchar_t *wcsdt = (wchar_t *) malloc((count + 1) * sizeof(wchar_t));
if ((l = msgtowstr(ldt, (wchar_t *) wcsdt, count + 1)) >= 0)
- utf8 = wcs_to_utf8(wcsdt, SQL_NTS, &l, FALSE);
+ utf8 = wcs_to_utf8(wcsdt, -1, &l, FALSE);
free(wcsdt);
}
#endif /* __WCS_ISO10646__ */
SQLWCHAR *utf16 = (SQLWCHAR *) malloc((count + 1) * sizeof(SQLWCHAR));
if ((l = mbstoc16_lf((char16_t *) utf16, ldt, count + 1, FALSE)) >= 0)
- utf8 = ucs2_to_utf8(utf16, SQL_NTS, &l, FALSE);
+ utf8 = ucs2_to_utf8(utf16, -1, &l, FALSE);
free(utf16);
}
#endif /* __CHAR16_UTF_16__ */
char *ldt = NULL;
int count = ucs2strlen(utf16);
+ get_convtype();
mylog(" %s\n", __FUNCTION__);
#if defined(__WCS_ISO10646__)
if (use_wcs)
{
SQLLEN l = (-2);
+ get_convtype();
mylog(" %s:lf_conv=%d\n", __FUNCTION__, lf_conv);
#if defined(__WCS_ISO10646__)
if (use_wcs)
{
SQLLEN l = (-2);
- mylog(" %s:size=%zu lf_conv=%d\n", __FUNCTION__, n, lf_conv);
+ get_convtype();
+ mylog(" %s:size=" FORMAT_SIZE_T " lf_conv=%d\n", __FUNCTION__, n, lf_conv);
#if defined(__WCS_ISO10646__)
if (use_wcs)
{
utf32 = (unsigned int *) *wcsbuf;
l = ucs4_to_ucs2_lf(utf32, -1, utf16, n, lf_conv);
}
+ else
+ {
+ int count = strlen(ldt);
+
+ utf32 = (unsigned int *) malloc((count + 1) * sizeof(unsigned int));
+ if ((l = msgtowstr(ldt, (wchar_t *) utf32, count + 1)) >= 0)
+ {
+ l = ucs4_to_ucs2_lf(utf32, -1, utf16, n, lf_conv);
+ }
+ free(utf32);
+ }
if (midbuf)
{
free(*wcsbuf);
return l;
}
+
+SQLLEN locale_to_sqlwchar(SQLWCHAR *utf16, const char *ldt, size_t n, BOOL lf_conv)
+{
+ return bindcol_hybrid_exec(utf16, ldt, n, lf_conv, NULL);
+}
+
//
// SQLBindCol localize case
// UTF-8 => the current locale
SQLLEN l = (-2);
char *convalc = NULL;
+ get_convtype();
mylog(" %s:lf_conv=%d\n", __FUNCTION__, lf_conv);
#if defined(__WCS_ISO10646__)
if (use_wcs)
{
SQLLEN l = (-2);
- mylog(" %s:size=%zu\n", __FUNCTION__, n);
+ get_convtype();
+ mylog(" %s:size=" FORMAT_SIZE_T "\n", __FUNCTION__, n);
#if defined(__WCS_ISO10646__)
if (use_wcs)
{
return l;
}
+SQLLEN utf8_to_locale(char *ldt, const char *utf8dt, size_t n, BOOL lf_conv)
+{
+ SQLLEN l;
+ char * tmpbuf;
+
+ if ((l = bindcol_localize_estimate(utf8dt, lf_conv, &tmpbuf)) >= 0)
+ l = bindcol_localize_exec(ldt, n, lf_conv, &tmpbuf);
+
+ return l;
+}
#endif /* UNICODE_SUPPORT */