[freetds] Re: SQL_C_BINARY type issue

Jonathan Monroe monroej_freetds at actualtechnologies.com
Wed Feb 18 16:45:59 EST 2004


On Feb 18, 2004, at 2:51 PM, Jonathan Monroe wrote:

> I think I have found an issue with the way the SQL_C_BINARY data type 
> is handled in the ODBC code.
[snip]

It just occurred to me that the patch I provided for convert_tds2sql.c 
only fixed the problem for varchar columns - other column types will 
still have some sort of conversion performed.  The better way of 
handling it is probably to treat SQL_C_BINARY as a special case and not 
call tds_convert() at all.

So, the new patch would look like this:

convert_tds2sql.c:  v1.37:
81,84c81,102
<       nRetVal = tds_convert(context, srctype, src, srclen, 
nDestSybType, &ores);
<       if (nRetVal < 0)
<               return nRetVal;
<
---
 >       if (desttype == SQL_C_BINARY)
 >       {
 >               /* just copy the raw bytes */
 >               if (destlen > 0) {
 >                       cplen = (destlen > srclen) ? srclen : destlen;
 >                       assert(cplen >= 0);
 >                       /* do not NULL terminate binary buffer */
 >                       memcpy(dest, src, cplen);
 >                       ret = cplen;
 >               } else {
 >                       /* if destlen == 0 we return only length */
 >                       if (destlen != 0)
 >                               ret = TDS_FAIL;
 >               }
 >       }
 >       else
 >       {
 >               nRetVal = tds_convert(context, srctype, src, srclen, 
nDestSybType, &ores);
 >               if (nRetVal < 0)
 >                       return nRetVal;
 >       }
 >
236,250c254
<               tdsdump_log(TDS_DBG_FUNC, "convert_tds2sql: outputting 
binary data destlen = %d \n", destlen);
<
<               ret = nRetVal;
<               if (destlen > 0) {
<                       cplen = (destlen > nRetVal) ? nRetVal : destlen;
<                       assert(cplen >= 0);
<                       /* do not NULL terminate binary buffer */
<                       memcpy(dest, ores.ib, cplen);
<               } else {
<                       /* if destlen == 0 we return only length */
<                       if (destlen != 0)
<                               ret = TDS_FAIL;
<               }
<
<               free(ores.ib);
---
 >               /* handled as special case above */


Anybody see any problems with doing it this way?

Jonathan Monroe




More information about the FreeTDS mailing list