[erlang-questions] ODBC truncates DATETIME results

Michael FIG <>
Thu Oct 9 22:13:02 CEST 2008


Hi,

I've been using unixodbc in conjunction with tdsodbc and a Microsoft SQL Server 2000 database.  With at least Erlang R11B1, I found that datetimes and smalldatetimes were being truncated, so I'd get results that looked like:

> odbc:sql_query(O, "SELECT CAST('2008-09-03 14:35:12.234' AS DATETIME)").
{selected,[[]],[{"2008-09-"}]}
> odbc:sql_query(O, "SELECT CAST('2008-09-03 14:35:12.234' AS SMALLDATETIME)").
{selected,[[]],[{"2008"}]}

Upon further investigation, I found out that the culprit appears to be in odbcserver.c, where the size of the result columns is calculated.  The driver combination I am using returns a length of 4 for SMALLDATETIME and 8 for DATETIME, which is inadequate to hold the results that are actually 23 characters in length.  The attached patch corrects this issue:

> odbc:sql_query(O, "SELECT CAST('2008-09-03 14:35:12.234' AS DATETIME)").
{selected,[[]],[{"2008-09-03 14:35:12.233"}]}
> odbc:sql_query(O, "SELECT CAST('2008-09-03 14:35:12.234' AS SMALLDATETIME)").
{selected,[[]],[{"2008-09-03 14:35:00.000"}]}

I'm not sure if it this bug still exists in Erlang R12, but I thought I should post this anyway.

Hope this helps somebody out there,

-- 
Michael FIG <>
MarkeTel Multi-Line Dialing Systems, Ltd.
Phone: (306) 359-6893 ext. 528
-------------- next part --------------
A non-text attachment was scrubbed...
Name: erl-11.b.1-odbc.patch
Type: application/octet-stream
Size: 521 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20081009/88c686aa/attachment.obj>


More information about the erlang-questions mailing list