[freetds] Prepared Statement is losing the seconds value

joseph.blough at thomson.com joseph.blough at thomson.com
Fri Nov 17 10:31:04 EST 2006


I'll take some time and try to understand tds_convert a little closer.
Thanks for pointing that out.

The reason that it is column[1] in the example is that column[0] is an
integer column and that's working fine.


-----Original Message-----
From: freetds-bounces at lists.ibiblio.org
[mailto:freetds-bounces at lists.ibiblio.org] On Behalf Of ZIGLIO,
Frediano, VF-IT
Sent: Friday, November 17, 2006 9:56 AM
To: FreeTDS Development Group
Subject: Re: [freetds] Prepared Statement is losing the seconds value

> 
> Hello.  I'm trying to use a prepared statement to set the value of a
> DATETIME field and the seconds keep being set to zero.  The version of
> FreeTDS is from CVS on October 19, 2006.  Here is the code 
> that is being
> used to set the parameter values:
> 
>   TDS_DATETIME tdsDateTime;
> 
>   int tm_year = 106;
>   int tm_mon = 10;
>   int tm_mday = 17;
>   int tm_hour = 8;
>   int tm_min = 8;
>   int tm_sec = 36;
>   int tm_ms = 0;
> 
>   int	i = (tm_mon - 13) / 12;
>   int dt_days = 1461 * (tm_year + 300 + i) / 4 +
>     (367 * (tm_mon - 1 - 12 * i)) / 12 - (3 * ((tm_year + 400 + i) /
> 100)) / 4 + tm_mday - 109544;
> 
>   tdsDateTime.dtdays = dt_days;
>   int dt_time = (tm_hour * 60 + tm_min) * 60 + tm_sec;
>   tdsDateTime.dttime = dt_time * 300 + (tm_ms * 300 / 1000);
>   

Why don't you use tds_convert?

>   /* pStatement is a (TDSDYNAMIC*) */
>   TDSCOLUMN* curcol = pStatement->params->columns[1];

or columns[0] ??

>   curcol->column_type = SYBDATETIMN;
>   curcol->on_server.column_type = SYBDATETIMN;
>   curcol->column_size = sizeof(TDS_DATETIME);
>   curcol->on_server.column_size = sizeof(TDS_DATETIME);
>   curcol->column_varint_size = 1;
>   curcol->column_cur_size = sizeof(TDS_DATETIME);
> 
>   tds_alloc_param_data(pStatement->params, curcol);
>   memcpy(curcol->column_data, &tdsDateTime, sizeof(TDS_DATETIME));
> 
> With some additional debugging output, before the call to
> tds_submit_execute the values are set to:
>   dtdays = 39036, dttime = 8794800
> 
> However, what ends up in the database is always missing the seconds so
> that retrieving the value in the database results in values of:
>   dtdays = 39036, dttime = 8784000
> 
> Also, looking at the database record in query analyzer 
> confirms that the
> seconds appear to be truncated before getting into the database.
> 
> Any help would be greatly appreciated.
> 
> Thanks!

freddy77

_______________________________________________
FreeTDS mailing list
FreeTDS at lists.ibiblio.org
http://lists.ibiblio.org/mailman/listinfo/freetds



More information about the FreeTDS mailing list