8 messages in com.mysql.lists.win32Re:Binding Timestamp Columns with myODBC
FromSent OnAttachments
Marvin Cummings08 Jul 2002 11:45 
Dave Watkinson08 Jul 2002 12:28 
Iikka Meriläinen08 Jul 2002 12:39 
ali hafiz08 Jul 2002 13:46 
sharat khungar09 Jul 2002 00:36 
Mateus Begossi09 Jul 2002 08:18 
Oliver Six10 Jul 2002 01:05 
leo g. divinagracia iii26 Jul 2002 16:42 
Subject:Re:Binding Timestamp Columns with myODBC
From:Oliver Six (o.s@cahos.net)
Date:07/10/2002 01:05:45 AM
List:com.mysql.lists.win32

"Mateus Begossi" <bego@mail.com> wrote on 09.07.2002 17:18:38:

Hi, I´ve emailed the list but my problem doesnt seem to have catch much attention. I guess a re-phrasing might help.. It´s pretty simple (I´m using myODBC 3.51 and VC++ 6.0 ) : how do I declare and bind variables/parameters for a TIMESTAMP column?

Here´s what I´ve done so far: I declare my "starttime" var: SQLTIMESTAMP starttime = (SQLTIMESTAMP)(LPCTSTR)"20020705195302";

Prepare my statement: retcode = SQLPrepare(hstmt,(unsigned char*)"SELECT * FROM datav WHERE date_time = ?", SQL_NTS);

And bind the parameter: retcode = SQLBindParameter(hstmt,1,SQL_PARAM_INPUT, SQL_C_TIMESTAMP, SQL_TIMESTAMP, 0,0, (void*)starttime, 14, NULL);

The application crashes. I tried setting my starttime var to SQLCHAR and SQLINTEGER, with the proper column binding, but it wont work either. Directly executing the statement works, but I my starttime var will change very frequently.

Is there any hope for me & TIMESTAMP, or should I alter my table and use a integer column with "TIMESTAMP-style" values...

Thanks in advance, and sorry for sending the same problem twice to the list,

Hi Mateus,

I think you cannot cast a string to a TIMESTAMP (thats why your app crashes). You need to use a TIMESTAMP_STRUCT which is declared in sqltypes.h. This struct (poorely documented in MSDN, see sqltypes.h) has members for year, month...

Why don't you use the libmysql.lib together with libmysql.dll? The library gives you direct access to all mysql functions (especially last_insert_id) and is much faster than ODBC (and you can use strings for date and time values).

Bye Oliver