Menu

#679 returned datatype for SQLServer type date is wrong.

v1.3
accepted
momo
1
2019-03-22
2012-10-12
cgerrist
No

The returned datatype for a SQLServer Date type is returned as a varchar with a length of 10. This is wrong, it should return as Sql.Date.

int iType = rsMeta.getInt("DATA_TYPE");
String tmp = rsMeta.getString("TYPE_NAME");

Discussion

  • momo

    momo - 2012-10-12

    Duplicate of feature request #78. I'm aware of the problem, but still have no idea how to fix that.

    Cheers,
    momo

     
  • momo

    momo - 2012-10-18
    • milestone: v2.x --> v1.3
     
  • momo

    momo - 2012-10-18
    • status: open --> accepted
    • assigned_to: momo
     
  • m.hilpert

    m.hilpert - 2013-07-22

    Still faulty in jTDS 1.3.1 ... :-( This is a really bad bug, as generic code gets broken when the datatype changes from datetime to date! Generic code is dependent on correct datatypes. String is the worst type - our workaround is just a guess by parsing the string if it could be a date value.

    I don't understand what is so difficult about this? It would be at least much better if you handle Date as Datetime. Much better than string.

     

    Last edit: m.hilpert 2013-07-22
  • chris jones

    chris jones - 2016-09-28

    jTDS 1.3.1 ... I've fallen foul of this twice recently, once using javax.persistence.AttributeConverter mapping to/from entities with JPA, and secondly in some generic code that was looking at the column type in java.sql.DatabaseMetaData. Both were expecting java.sql.Date and were working fine with other JDBC drivers.

    It looks like the MS JDBC driver supports conversion correctly (according to their web site)
    https://msdn.microsoft.com/en-us/library/ms378878(v=sql.110).aspx

    Is there any news regarding a fix in jTDS?

     
  • Arthur Borsboom

    Arthur Borsboom - 2016-10-05

    I just ran into this same bug in our application. The MS SQL column of type date is returned as a varchar (int=12).

    Can we help on solving this?

     
  • Michael Wyraz

    Michael Wyraz - 2019-03-22

    The fix is easy:

    • In TypeInfo.normalizeDataType add "typeName" as parameter and pass the typeName on each call of this function.
    • In the switch statement there, on case -9 return Types.DATE for typeName "date" and "datetime2".

    I'd provide a PR but it seems that the project is not alive anymore :-/

    Edit: Feel free to use my patch: https://github.com/bi-web/jTDS/commit/9c463aaf3a77d3b5870404837a019d812af7aaa3
    It's partial, I passed typeInfo only at the places where it was already in a variable. There are 2 more placed, I added a FIXME comment there..

     

    Last edit: Michael Wyraz 2019-03-22

Log in to post a comment.

MongoDB Logo MongoDB