[freetds] tds_get_size_by_type for SYBMSDATE
lacak at zoznam.sk
Wed Apr 9 01:40:03 EDT 2014
Frediano Ziglio wrote / napísal(a):
> 2014-04-08 11:08 GMT+01:00 LacaK <lacak at zoznam.sk>:
>> when I look into tds_types.h (which is build on misc/types.csv) there is
>> function tds_get_size_by_type() used f.e. by dbconvert()
>> And for SYBMSDATE it returns 4 (IMO it is wrong set size=4 in types.csv)
>> Is it correct ?
>> (as far as I understand it should be size if struct which holds this data
>> type i.e.:
>> there should be:
>> case SYMBSDATE:
>> case SYMBSTIME:
>> case SYMBSDATETIME2:
>> case SYMBSDATETIMEOFFSET:
>> return sizeof(TDS_DATETIMEALL);
>> When I change it this way, it works as expected for me.
> Well... could be... this function is used in a lot of places. As the
> fixed column is 0 I don't think should break anything.
> What did go wrong before you changed the code?
Look please in src/dblib/dblib.c at dbconvert() function.
There is call to tds_get_size_by_type(desttype) used in case when
"srctype == desttype"
And then return value (i.e. size) is used in: memcpy(dest, src, ret);
When size is wrong memcpy does not copy all data.
When tds_get_size_by_type() does not known "desttype" then -1 is
returned, which in my environment causes freezing application.
(may be that memcpy expect as 3rd argument "unsigned size", so supplying
-1 causes copy of large memory block)
(f.e. for desttype=SYBMSDATETIME2 there is in types.csv: size=-1, which
causes that this type is omited when generating tds_types.h from
types.pl ... )
As another example please look at SYBDATETIME, there is size=4 which
correspondes to sizeof(TDS_DATETIME) and also sizeof(DBDATETIME) used by
sybdb.h ... this is IMO correct ...
Sizeof(TDS_DATETIMEALL) = 24 so setting this size for MSDATE, MSTIME,
MSDATETIME2, MSDATETIMEOFFSET should ge solution?
More information about the FreeTDS