freetds AT lists.ibiblio.org
Subject: FreeTDS Development Group
List archive
Re: [freetds] Prepared Statement is losing the seconds value
- From: <joseph.blough AT thomson.com>
- To: <freetds AT lists.ibiblio.org>
- Subject: Re: [freetds] Prepared Statement is losing the seconds value
- Date: Fri, 15 Dec 2006 05:25:23 -0500
Sorry for the delayed response. I've changed the code to use
tds_convert as follows but still have the issue:
char* dateCharBuffer = "2006-12-15 05:21:53.000";
int bufferLength = 21;
int return_size = tds_convert(this->m_pDatabase->tds_ctx, SYBVARCHAR,
(TDS_CHAR*)(const char*)dateCharBuffer, bufferLength, SYBDATETIME,
&cr);
if (return_size > 0)
{
TDSCOLUMN* curcol = m_pParameters->columns[nPosition-1];
curcol->column_type = SYBDATETIMN;
curcol->on_server.column_type = SYBDATETIMN;
curcol->column_size = return_size;
curcol->on_server.column_size = return_size;
curcol->column_varint_size = 1;
curcol->column_cur_size = return_size;
tds_alloc_param_data(m_pParameters, curcol);
memcpy(curcol->column_data, &cr.dt, return_size);
}
The value that reaches the database is "2006-12-15 05:21:00" rather than
the expected "2006-12-15 05:21:53".
-----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
- Re: [freetds] Prepared Statement is losing the seconds value, joseph.blough, 12/15/2006
Archive powered by MHonArc 2.6.24.