Fix unicode copy & convert bug. SQLGetData with SQL_C_WCHAR now returns SQL_SUCCESS...
authorDave Page <dpage@pgadmin.org>
Tue, 2 Aug 2005 12:52:03 +0000 (12:52 +0000)
committerDave Page <dpage@pgadmin.org>
Tue, 2 Aug 2005 12:52:03 +0000 (12:52 +0000)
convert.c

index 23a794377a7e37ddf844e8f54f9a68ec7a3771ee..2fc68e86b9584d677a94262a2c9d9e1da72d9708 100644 (file)
--- a/convert.c
+++ b/convert.c
@@ -944,19 +944,23 @@ inolog("2stime fr=%d\n", std_time.fr);
 
        if (SQL_C_WCHAR == fCType && ! wchanged)
        {
-           if (cbValueMax > (SDWORD) (WCLEN * len))
+           if (cbValueMax > (SDWORD) (WCLEN * (len + 1)))
            {
                char *str = strdup(rgbValueBindRow);
                UInt4   ucount = utf8_to_ucs2(str, len, (SQLWCHAR *) rgbValueBindRow, cbValueMax / WCLEN);
                if (cbValueMax < (SDWORD) (WCLEN * ucount))
                    result = COPY_RESULT_TRUNCATED;
-               len = ucount * WCLEN;
+               // len = ucount * WCLEN;
                free(str); 
            }
            else
            {
-               len *= WCLEN;
-               result = COPY_RESULT_TRUNCATED;
+                if ((SDWORD) (len + WCLEN) <= cbValueMax)
+                {
+                    result = COPY_OK;
+                }
+                else
+                    result = COPY_RESULT_TRUNCATED; 
            }
        }