Skip to Content.
Sympa Menu

freetds - [freetds] I can't get the datatype DATE correctly using odbc, anyone can help me?

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Ou Liu" <ou AT qbt.com>
  • To: <freetds AT lists.ibiblio.org>
  • Subject: [freetds] I can't get the datatype DATE correctly using odbc, anyone can help me?
  • Date: Wed, 8 Jan 2003 17:09:52 -0500

Hi, everyone
I am using FreeTDS/iODBC to get some date from a MSSQL2K Server,
however I
met problem when I try to get data of type DATE. Here is my problem
(1) I am using SPARC/Solaris 8 as client machine, iODBC as driver
manager,
FreeTDS as odbc driver, MSSQL2K on another Win2K machine as server.
(2) I create a table 'test' on the MSSQL2k:
CREATE TABLE test (dtm DATETIME);
INSERT INTO test VALUES("2002-02-23 10:02:03");
(3) Now I use the tsql to fetch the whole table :
SELECT * FROM test;
Everything runs ok, I got what I need.
(4) But When I try to use ODBC API to get it:(the m_hstmt is ok, I am
sure)

SQLDescribeCol(m_hstmt, col + 1, (SQLCHAR *) name, \
sizeof(name), NULL, &colType, &colSize, \
&colScale, &colNullable);
switch(colType)
{
...
case SQL_TYPE_TIMESTAMP:
colType = SQL_C_CHAR;
{
TIMESTAMP_STRUCT tstamp;
memset((void*) &tstamp, 0, sizeof(TIMESTAMP_STRUCT));
SQLGetData(m_hstmt, col + 1, colType, &tstamp, colSize + 1,
&cbSize);
....

Now the result I get in the tstamp is all rubbish, I don't know why
and
then I turn to use string instead of
TIMESTAMP_STRUCT. Instead of the last line I wrote:

char* temp = (char*) malloc(100);
memset((void*) temp, 0, 100);
SQLGetData(m_hstmt, col + 1, colType, temp, 100, &cbSize);

Ok, Now I got some result, but only "2002-02-23" in the temp, and I
lost
the "10:02:03".

Can anybody help me, or is this problem solved in recent version? I
didn't
take a look at the cvs for 3 weeks and seems it down now.

Any help is greatly appreciated.

Ou






Archive powered by MHonArc 2.6.24.

Top of Page