all groups > sql server odbc > november 2006 >
You're in the

sql server odbc

group:

Program type out of range error using SQLBindParameter to a datetime field


Re: Program type out of range error using SQLBindParameter to a datetime field Arnie
11/15/2006 12:00:00 AM
sql server odbc: [quoted text, click to view]

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

Program type out of range error using SQLBindParameter to a datetime field john.harkin NO[at]SPAM singularity.co.uk
11/15/2006 2:29:40 AM
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
Re: Program type out of range error using SQLBindParameter to a datetime field john.harkin NO[at]SPAM singularity.co.uk
11/15/2006 7:26:41 AM
Hi,

Thanks for info - still no joy.
What type is youre m_timeStamp?
Also what is SQLLEN defined as.?

Thanks for youre time
John



[quoted text, click to view]
Re: Program type out of range error using SQLBindParameter to a datetime field Arnie
11/16/2006 10:57:58 AM
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]

Re: Program type out of range error using SQLBindParameter to a datetime field john.harkin NO[at]SPAM singularity.co.uk
11/17/2006 8:47:47 AM
Hi,
Thanks for info.
Still no joy.
Only thing i can think of is that my code is built for Unicode.
I've decided to just pass in a string (in ISO format) to the stored
proc.
Thanks for youre time.

JOhn

[quoted text, click to view]
AddThis Social Bookmark Button