[freetds] db-lib: support for new MS SQL 2008 data types - part 2

LacaK lacak at zoznam.sk
Fri Apr 11 03:54:49 EDT 2014

Frediano Ziglio  wrote / napísal(a):
> 2014-04-04 11:00 GMT+01:00 LacaK <lacak at zoznam.sk>:
>> Now I can read successfuly:
>> - dbcoltype() returning SYBMSDATE, SYBMSTIME, SYBMSDATETIME2
>> I am trying do next small step.
>> As far as I understand dbdata() function for SYBMSDATE, SYBMSTIME,
>> SYBMSDATETIME2 return pointer to TDS_DATETIMEALL struct.
>> (dbdata() internally uses: return (BYTE *) colinfo->column_data)
> Well.... dbdata returns any possible column_data stored. This does not
> exactly means that is correct for these types. All other types are
> coded as wire data while these type use an internal encoding defined
> by our library.
>> If it is so I need some way how to convert TDS_DATETIMEALL struct to
>> DBDATEREC struct.
>> (which is good readable)
>> There is already function:
>>  dbdatecrack(DBPROCESS * dbproc, DBDATEREC * output, DBDATETIME * datetime)
>> but it takes as 3rd parameter DBDATETIME struct, which is struct used by old
>> "datetime" data type SYBDATETIME)
>> So my idea is introduce new API function:
>>  tdsdbdatecrack(DBPROCESS * dbproc, INT datetype, DBDATEREC * output, const
>> void *datetime)
>> (like we have tdsdbopen() vs dbopen())
>> Where datetime can be pointer to either old DBDATETIME or new
>> TDS_DATETIMEALL, depending on datetype supplied
> Could work. You can use tds_datecrack to help you.
>> What is your opinion on that?
>> I am asking for sure about every step, because I am not so familiar with
>> internals.
>> Thanks
>> -Laco.
> Here the problem is not internals but dblib. There is no definition on
> how to extend this library. There's also a problem on the precision of
> DBDATEREC which do not take into account fraction of seconds beside
> milliseconds
For now I have realized that I do not need conversion from 
I can easy parse TDS_DATETIMEALL and convert it direct to FreePascal 
TDateTime data type, which is my destination type.

I attach small patches for
- src/dblib/dblib.c: "Adjust dbconvert() to support SYBMSDATE, 
- src/tds/token.c: "add data type name for SYBMSXML, SYBMSDATETIMEOFFSET 
to tds_prtype()"


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: dblib.c.diff
URL: <http://lists.ibiblio.org/pipermail/freetds/attachments/20140411/bbd37071/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: token.c.diff
URL: <http://lists.ibiblio.org/pipermail/freetds/attachments/20140411/bbd37071/attachment-0001.ksh>

More information about the FreeTDS mailing list