cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

ODBC failure on basic call

oneeyeman1
Participant
0 Likes
634

Hi,

I have following code:

 

for( int i = 0; i < 5; i++ )
{
catalog[i].TargetType = SQL_C_WCHAR;
catalog[i].BufferLength = ( bufferSize + 1 );
catalog[i].TargetValuePtr = malloc( sizeof( unsigned char ) * catalog[i].BufferLength );
ret = SQLBindCol( m_hstmt, (SQLUSMALLINT) i + 1, catalog[i].TargetType, catalog[i].TargetValuePtr, catalog[i].BufferLength, &( catalog[i].StrLen_or_Ind ) );
if( ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO )
{
GetErrorMessage( errorMsg, STMT_ERROR );
result = 1;
break;
}
}

 

This code fails with HY090.

 

However it didn't fail with any other DBMS.

 

Im running SQL Anywhere 17.0 with the driver 17.0.

 

Any idea?

 

Thank you.

 

Accepted Solutions (1)

Accepted Solutions (1)

jack_schueler
Product and Topic Expert
Product and Topic Expert
0 Likes
// Instead of writing this ...
catalog[i].BufferLength = ( bufferSize + 1 );
// write this ...
// Note that some ODBC drivers have a 2-byte SQLWCHAR (like us) and 
// some ODBC drivers have a 4-byte SQLWCHAR, so write this.
catalog[i].BufferLength = ( characterSize + 1 ) * sizeof(SQLWCHAR);
// Example: for CHAR(10) data, characterSize = 10 and 
// the + 1 accounts for a null terminator.
// Analogously, the following works for non-wide SQLCHAR.
catalog[i].BufferLength = ( characterSize + 1 ) * sizeof(SQLCHAR);
// To generalize the "BufferLength" value ...
characterSize = n; // Ex: 10 for SQL CHAR(10) or VARCHAR(10)
sizeofCharacter = sizeof(SQLWCHAR); //or sizeof(SQLCHAR)
catalog[i].BufferLength = ( characterSize + 1 ) * sizeofCharacter;
oneeyeman1
Participant
0 Likes
@Jack_shueler, the generalized solution works fine for SQL Anywhere on Windows. Will check ther DBMSes and OSes later. Thx.
oneeyeman1
Participant
0 Likes
@Jack_shueler, I checked and it looks like it works for SQL Server from Windows as well. However, it means that the code I referenced is wrong... Will try to submit to MS...
oneeyeman1
Participant
0 Likes
@Jack_shueler, , it works even on Linux with unixODBC. Thx for the solution.

Answers (0)