[freetds] Prepared Statement is losing the seconds valu

ZIGLIO, Frediano, VF-IT Frediano.Ziglio at vodafone.com
Fri Dec 22 03:34:50 EST 2006


> 
> Here is a relatively small program that illustrates the problem.  It
> attempts to set a DATETIME field to "2006-12-21 05:34:12.000" but the
> actual value that goes into the database is "2006-12-21 05:34:00.000".
> 

... program omissis ...

Now I understand the problem (and I found the solution!). 

When you prepare a query without passing parameters libTDS prepare query
using a default varchar(80). When you execute the query you can pass
different types (like DATETIME you used). It seems that mssql do a
strange conversion loosing precision. The solution (see fix.diff) is to
prepare query using correct parameters type so mssql use all precision.
Note that the execute (not the prepare) produce same data to server,
server reply the same way but data loose precision.
I know that our ODBC (and MS one too) automatically prepare again the
query when you change type.

Frediano

-------------- next part --------------
A non-text attachment was scrubbed...
Name: fix.diff
Type: application/octet-stream
Size: 2383 bytes
Desc: fix.diff
Url : http://lists.ibiblio.org/pipermail/freetds/attachments/20061222/6c344541/attachment.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: xxx0.c
Type: application/octet-stream
Size: 4648 bytes
Desc: xxx0.c
Url : http://lists.ibiblio.org/pipermail/freetds/attachments/20061222/6c344541/attachment-0001.obj 


More information about the FreeTDS mailing list