3 weeks ago
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.
Request clarification before answering.
// 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;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 15 | |
| 9 | |
| 6 | |
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.