Changeset: 1965c4029118 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1965c4029118
Modified Files:
        clients/odbc/driver/ODBCConvert.c
        clients/odbc/driver/ODBCUtil.h
Branch: Dec2011
Log Message:

ODBC: Fix conversion to wide characters for bound columns during fetch.


diffs (35 lines):

diff --git a/clients/odbc/driver/ODBCConvert.c 
b/clients/odbc/driver/ODBCConvert.c
--- a/clients/odbc/driver/ODBCConvert.c
+++ b/clients/odbc/driver/ODBCConvert.c
@@ -1233,9 +1233,12 @@ ODBCFetch(ODBCStmt *stmt,
                if (type == SQL_C_WCHAR) {
                        /* allocate temporary space */
                        buflen = 511; /* should be enough for most types */
-                       if (sql_type == SQL_CHAR && data != NULL)
-                               buflen = (SQLLEN) datalen; /* but this is 
certainly enough for strings */
-                       ptr = malloc(buflen + 1);
+                       if (data != NULL &&
+                           (sql_type == SQL_CHAR ||
+                            sql_type == SQL_VARCHAR ||
+                            sql_type == SQL_LONGVARCHAR))
+                               buflen = (SQLLEN) datalen + 1; /* but this is 
certainly enough for strings */
+                       ptr = malloc(buflen);
 
                        lenp = NULL;
                }
diff --git a/clients/odbc/driver/ODBCUtil.h b/clients/odbc/driver/ODBCUtil.h
--- a/clients/odbc/driver/ODBCUtil.h
+++ b/clients/odbc/driver/ODBCUtil.h
@@ -98,8 +98,11 @@ extern char *ODBCTranslateSQL(const SQLC
                        ret;                                            \
                }                                                       \
                _l = (str) ? (lent) (strlen) : 0;                       \
-               if (buf)                                                \
+               if (buf) {                                              \
                        strncpy((char *) (buf), (str) ? (const char *) (str) : 
"", (len)); \
+                       if (_l < (len))                                 \
+                               ((char *)(buf))[_l] = 0;                \
+               }                                                       \
                if (lenp)                                               \
                        *(lenp) = _l;                                   \
                if ((buf) == NULL || _l >= (len))                       \
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to