Attachment "freetds.patch" to
ticket [98fd7196a7]
added by
chw
2020-07-23 04:28:06.
Index: generic/tdbcodbc.c
==================================================================
--- generic/tdbcodbc.c
+++ generic/tdbcodbc.c
@@ -4278,11 +4278,14 @@
* (which may have grown) */
SQLLEN colAllocLen = BUFSIZE * sizeofSQLWCHAR;
/* Current allocated size of the buffer,
* in bytes */
SQLLEN colLen; /* Actual size of the return value, in bytes */
- SQLINTEGER colLong; /* Integer value of the column */
+ union { /* Integer value of the column */
+ SQLINTEGER si; /* this holds a 'long' */
+ int i; /* but some drivers return 'int' */
+ } colLong;
SQLBIGINT colWide; /* Wide-integer value of the column */
SQLDOUBLE colDouble; /* Double value of the column */
Tcl_DString colDS; /* Column expressed as a Tcl_DString */
Tcl_Obj* colObj; /* Column expressed as a Tcl_Obj */
SQLRETURN rc; /* ODBC result code */
@@ -4345,22 +4348,26 @@
case SQL_INTEGER:
case SQL_SMALLINT:
case SQL_TINYINT:
convertLong:
/* An integer no larger than 'long' */
- colLen = sizeof(colLong); colLong = 0;
+ colLen = sizeof(colLong.si); colLong.si = 0;
rc = SQLGetData(rdata->hStmt, i+1, SQL_C_SLONG,
- (SQLPOINTER) &colLong, sizeof(colLong), &colLen);
+ (SQLPOINTER) &colLong.si, sizeof(colLong.si), &colLen);
if (!SQL_SUCCEEDED(rc)) {
char info[80];
sprintf(info, "(retrieving result set column #%d)\n", i+1);
TransferSQLError(interp, SQL_HANDLE_STMT, rdata->hStmt, info);
ckfree(info);
return TCL_ERROR;
}
if (colLen != SQL_NULL_DATA && colLen != SQL_NO_TOTAL) {
- colObj = Tcl_NewWideIntObj(colLong);
+ if (colLen != sizeof(colLong.si)) {
+ colObj = Tcl_NewWideIntObj(colLong.i);
+ } else {
+ colObj = Tcl_NewWideIntObj(colLong.si);
+ }
}
break;
case SQL_FLOAT:
/*