Skip to Content.
Sympa Menu

freetds - Re: [freetds] FreeTDS returned data lenght????

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Ole Hansen <oha AT city.dk>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] FreeTDS returned data lenght????
  • Date: Thu, 16 Oct 2003 00:34:10 +0200

Hi,

Sorry for the interruption :)
I an application I do the following when calculating the time as I want
the time to be represented as UNIX-time used in my application:

DATETIME:
-------------
double time;
u_int32_t days = *((u_int32_t *)value);
u_int32_t msec = *((u_int32_t *)(value+sizeof(u_int32_t)));
time = ((double)(days-25567))*24*60*60 + ((double)msec)/1000.0;

The day calculated gives me the expected day but the usec doesnt match.
This is for CS_DATETIME_TYPE. The calculated value is 8-10 hours behind.

When I do a similar calculation for CS_DATETIME4_TYPE everything seems
ok. At least I get the expected time of day although the precision is to
the minute only.

DATETIME4:
---------------
double time;
u_int16_t days = *((u_int16_t *)value);
u_int16_t mins = *((u_int16_t *)(value+sizeof(u_int16_t)));
time = ((double)(days-25567))*24*60*60 + ((double)mins)*60.0;

However, if I do the conversion to a string in the first example with
cs_convert the result is ok.

Can somebody tell me if the binary representation for CS_DATETIME_TYPE
is wrong compared to Sybase/MSSQL?

The number 25567 is the exact number of days from Jan. 1. 1900 - Dec 31.
1969.

Thanks in advance.
Ole Hansen



On Wed, 2003-10-15 at 17:36, Michael Peppler wrote:
> On Wed, 2003-10-15 at 04:08, David Nsengiyumva wrote:
> > Hi Everybody,
> >
> > Does anyone know how FreeTDS knows the lenght of the returned data; not
> > the
> > size of the result set, but the individual data in each field of every
> > particular row in the result set????
> >
> > For what I see, in the ct-lib layer, the " ct_describe " function sets the
> > members of the CS_DATAFMT parameter (datafmt) using the TDSCOLINFO
> > (curcol)
> > structure ("column_size" field of the structure). But what I don't
> > understand is that when I run a Query that's supposed to return strings
> > whose lenght is more than 45 it works but when the fields of the returned
> > values include Date/Time data then it fails.
>
> A CS_DATETIME data item is 8 bytes in length - it's not the length of
> the string into which it could be converted.
>
> Michael





Archive powered by MHonArc 2.6.24.

Top of Page