[freetds] SQLBindParameter using TIMESTAMP_STRUCT: Fractional part is wrong

Sebastien FLAESCH sf at 4js.com
Mon Jan 7 12:28:51 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: odbctest31.c
Type: text/x-csrc
Size: 7701 bytes
Desc: not available
Url : http://lists.ibiblio.org/pipermail/freetds/attachments/20080107/3fb12ef2/attachment-0001.bin 


More information about the FreeTDS mailing list