Skip to Content.
Sympa Menu

freetds - RE: [freetds] Re: SQL_C_BINARY type issue

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "ZIGLIO, Frediano, VF-IT" <Frediano.Ziglio AT vodafone.com>
  • To: "FreeTDS Development Group" <freetds AT lists.ibiblio.org>
  • Subject: RE: [freetds] Re: SQL_C_BINARY type issue
  • Date: Fri, 20 Feb 2004 14:17:17 +0100

>
> 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
>

You spot a real problem. I don't know if is correct to handle varchar as
a binary string (ie: '012345') however I don't know the real behaviour
for other types. For instance how MS ODBC return a datetime?? Same
format of wire (as FreeTDS does now) or converting to TIMESTAMP before
?? Some tests are needed to handle this type...

freddy77




Archive powered by MHonArc 2.6.24.

Top of Page