Re: bcp_bind vartype = 0
Frediano Ziglio <[email protected]>
| Newsgroups | gmane.comp.db.tds.freetds |
|---|---|
| Message-ID | <[email protected]> |
2010/6/21 craigberry <[email protected]>: > > > On Jun 21, 2010, at 01:03 PM, Gil Rohde <[email protected]> wrote: > >> In Sybase, setting the bcp_bind vartype parameter to 0 tells it not to perform any conversion on the datatype. > > FWIW, Microsoft documents the same behavior: > > http://msdn.microsoft.com/en-us/library/ms131401.aspx > >> With freetds this seems to cause a failure since it attempts to convert it with dbconvert and doesn't recognize a source type of 0. >> >> Is this a known and recognized difference or bug? It looks like one way to handle this is to modify dbconvert to treat a source type of 0 as the same as the dest type. > > It looks like a bug. dbconvert() does have special handling for the source type and destination type being the same, and since this is really a subset of that, it could probably be added to it. It might be as simple as saying > > if (!srctype) srctype = desttype; > > somewhere near the top of dbconvert(). > Yes, this should do the job but also change dbconvert behavior, I think this patch should work fix bcp_bind with vartype == 0 Index: freetds83/src/dblib/bcp.c =================================================================== --- freetds83.orig/src/dblib/bcp.c 2010-06-22 09:28:32.532238680 +0200 +++ freetds83/src/dblib/bcp.c 2010-06-22 09:28:32.542118986 +0200 @@ -2386,7 +2386,7 @@ TDS_SMALLINT si; TDS_INT li; TDS_INT desttype; - int collen; + int collen, coltype; int data_is_null; int bytes_read; int converted_data_size; @@ -2442,10 +2442,12 @@ } } - /* Fixed Length data - this overrides anything else specified */ + desttype = tds_get_conversion_type(bindcol->column_type, bindcol->column_size); - if (is_fixed_type(bindcol->column_bindtype)) { - collen = tds_get_size_by_type(bindcol->column_bindtype); + /* Fixed Length data - this overrides anything else specified */ + coltype = bindcol->column_bindtype == 0 ? desttype : bindcol->column_bindtype; + if (is_fixed_type(coltype)) { + collen = tds_get_size_by_type(coltype); } /* read the data, finally */ @@ -2466,10 +2468,8 @@ bindcol->bcp_column_data->datalen = 0; bindcol->bcp_column_data->is_null = 1; } else { - desttype = tds_get_conversion_type(bindcol->column_type, bindcol->column_size); - if ((converted_data_size = - dbconvert(dbproc, bindcol->column_bindtype, + dbconvert(dbproc, coltype, (BYTE *) dataptr, collen, desttype, bindcol->bcp_column_data->data, bindcol->column_size)) == FAIL) { return TDS_FAIL; freddy77 _______________________________________________ FreeTDS mailing list [email protected] http://lists.ibiblio.org/mailman/listinfo/freetds