[freetds] SQLBindParameter using TIMESTAMP_STRUCT: Fractional partis wrong

ZIGLIO, Frediano, VF-IT Frediano.Ziglio at vodafone.com
Tue Jan 8 03:17:34 EST 2008


> 
> I believe that the fractional part is wrong inserted when 
> using the TIMESTAMP_STRUCT type:
> 
>      rcode = SQLBindParameter(m_hstmt1, 1, SQL_PARAM_INPUT,
>                               SQL_C_TYPE_TIMESTAMP, 
> SQL_TYPE_TIMESTAMP, 23, 0,
>                               &v_ts, 0, &v_ts_ind);
> 
> In ODBC, the "fraction" field of a TIMESTAMP_STRUCT 
> represents a number of nanoseconds.
> -> The value for a half second would be 500,000,000.
> 
> In Transact-SQL, datetime columns have fraction part 
> expressed in milliseconds, with an
> accuracy of 3,33 milliseconds.
> 
> So when inserting a datetime value with the string 
> 'yyyy-mm-dd hh:mi:se.003', it means
> 3 milliseconds, which should be:
> 
>    3 * 1000 * 1000 = 3,000,000 nanoseconds
> 
> ... in a TIMESTAMP_STRUCT. Right?
> 
> But when using this value in a TIMESTAMP_STRUCT binding, I 
> get .000 in the database.
> 
> Looks like the value is rounded before it is sent to the server...
> 
> Note that the value of 18,000,000 nanoseconds (18 
> milliseconds = .018) is rounded to
> .017 in the database (as expected)...
> 
> See attached example to reproduce...
> 
> 
> Resources:
> 
> http://msdn2.microsoft.com/en-us/library/ms714556.aspx
> http://support.microsoft.com/kb/263872
> 
> 
> Thanks
> Seb
> 

Fixed. Was a rounding problem.

freddy77



More information about the FreeTDS mailing list