Hi John,
I'll try to make the story as short as possible. I have a number
of database classes that encapsulate ODBC. This makes life
easier for the app developer.
I have defined my own timestamp struct in a .H file used by the
app developer. This is so as not to have to drag in the ODBC .H
files. The definition should match ODBC's. See below.
// Define the timestamp struct here so that we don't have to
// include the SQL* H files.
typedef struct
{
USHORT year;
USHORT month;
USHORT day;
USHORT hour;
USHORT minute;
USHORT second;
UINT fraction;
}tagSQL_TIMESTAMP_STRUCT;
The following comes from the class's private member variable
section:
tagSQL_TIMESTAMP_STRUCT m_timeStamp;
// This is for binding the length/NULL indicator
#ifdef _WIN64
mutable INT64 m_LenInd;
#else
mutable int m_LenInd;
#endif
The following two member functions are used to set the datetime
or date only. One includes the code I previously sent you.
/////////////////////////////////////////////////////////////////////////////
//
void VParameter::PutDateTime( VDateTime dateTime )
{
SQLRETURN rc;
USHORT msec;
m_LenInd = sizeof( m_timeStamp );
dateTime.DecodeDate( m_timeStamp.year, m_timeStamp.month,
m_timeStamp.day );
dateTime.DecodeTime( m_timeStamp.hour, m_timeStamp.minute,
m_timeStamp.second, msec );
m_timeStamp.fraction = 0;
rc = SQLBindParameter( m_hStmt, m_paramNumber,
SQL_PARAM_INPUT, SQL_C_TYPE_TIMESTAMP, SQL_TIMESTAMP,
sizeof( "yyyy-mm-dd hh:mm:ss" ), 0,
&m_timeStamp, sizeof( m_timeStamp ), (SQLLEN *) &m_LenInd);
CHECK_STMT( m_hStmt, rc );
}
/////////////////////////////////////////////////////////////////////////////
//
void VParameter::PutDate( VDateTime dateTime )
{
SQLRETURN rc;
dateTime.DecodeDate( m_timeStamp.year, m_timeStamp.month,
m_timeStamp.day );
rc = SQLBindParameter( m_hStmt, m_paramNumber,
SQL_PARAM_INPUT, SQL_C_TYPE_DATE, SQL_TIMESTAMP,
sizeof("yyyy-mm-dd"), 0, &m_timeStamp, 0, 0);
CHECK_STMT( m_hStmt, rc );
}
Note that "m_LenInd = sizeof( m_timeStamp );"
wasn't included in my previous response. Maybe that's the
problem. DateTimes are certainly a pain in the neck!
HTH,
- Arnie
[quoted text, click to view] <john.harkin@singularity.co.uk> wrote in message
news:1163604401.402911.227580@i42g2000cwa.googlegroups.com...
> Hi,
>
> Thanks for info - still no joy.
> What type is youre m_timeStamp?
> Also what is SQLLEN defined as.?
>
> Thanks for youre time
> John
>
>
>
> Arnie wrote:
>
>> <john.harkin@singularity.co.uk> wrote in message
>> news:1163586579.983399.280300@f16g2000cwb.googlegroups.com...
>> > Hi,
>> > I want to call a sql serrver stored proc from odbc (usigh
>> > c++)
>> > whicc
>> > takes a single datetime parameter as input.
>> > I've tried
>> >
>> > SQLINTEGER sqlLength = 0;
>> >
>> > TIMESTAMP_STRUCT dsOpenDate;
>> >
>> > // test data
>> > dsOpenDate.year = 1996;
>> > dsOpenDate.month = 3;
>> > dsOpenDate.day = 8;
>> > dsOpenDate.hour = 3;
>> > dsOpenDate.minute = 13;
>> > dsOpenDate.second = 1;
>> > dsOpenDate.fraction = 0;
>> >
>> > rc = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT,
>> > SQL_C_TYPE_TIMESTAMP,
>> > SQL_TIMESTAMP, sizeof(dsOpenDate),
>> > sizeof(dsOpenDate),
>> > &dsOpenDate, sizeof(dsOpenDate), &sqlLength);
>> >
>> > but the bind keeps failing with error
>> > "[Microsoft][ODBC Driver Manager] Program type out of range"
>> >
>> > i;ve searched but found no example of correct syntax .
>> >
>> > Any ideas where i'm going wrong.
>> >
>> > Thanks
>> >
>> > John
>>
>> Hi John,
>>
>> For what it's worth, here's how I bind it. It works for me.
>>
>> rc = SQLBindParameter( m_hStmt, m_paramNumber,
>>
>> SQL_PARAM_INPUT, SQL_C_TYPE_TIMESTAMP, SQL_TIMESTAMP,
>>
>> sizeof( "yyyy-mm-dd hh:mm:ss" ), 0,
>>
>> &m_timeStamp, sizeof( m_timeStamp ), (SQLLEN *) &m_LenInd);
>>
>>
>>
>> HTH,
>>
>> - Arnie
>