Skip to Content.
Sympa Menu

freetds - [freetds] Prepared Statement is losing the seconds value

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: <joseph.blough AT thomson.com>
  • To: <freetds AT lists.ibiblio.org>
  • Subject: [freetds] Prepared Statement is losing the seconds value
  • Date: Fri, 17 Nov 2006 08:26:16 -0500

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);

/* pStatement is a (TDSDYNAMIC*) */
TDSCOLUMN* curcol = pStatement->params->columns[1];
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!




Archive powered by MHonArc 2.6.24.

Top of Page