This content has been marked as final. Show 8 replies
As you are using Windows Driver manager, there is some restriction using SQL_WCHAR and SQL_WVARCHAR.
This from C Dev guide
"Applications using the Windows driver manager may encounter errors from SQLBindParameter with SQL state S1004 (SQL data type out of range) when passing an fSqlType value of SQL_WCHAR or SQL_WVARCHAR. This problem can be avoided by passing one of the following values for fSqlType instead:
SQL_WCHAR_DM_SQLBINDPARAMETER_BYPASS instead of SQL_WCHAR
SQL_WVARCHAR_DM_SQLBINDPARAMETER_BYPASS instead of SQL_WVARCHAR
These type codes are semantically identical to SQL_WCHAR and SQL_WVARCHAR but avoid the error from the Windows driver manager. They can be used in applications that link with the driver manager or link directly with the TimesTen ODBC direct driver or ODBC client driver.
See "SQLBindParameter function" for information about that ODBC function. "
Can you please use "SQL_WVARCHAR_DM_SQLBINDPARAMETER_BYPASS" above types instead ?
I didn't get the point. SQL_WCHAR_DM_SQLBINDPARAMETER_BYPASS and the other one are just a simple constants equal to -888 and -889 respectively. These can't be used to create a variable
in c++. My question was how to get the value of nvarchar2 column. In getColumnType function when you encounter a nvarchar2 values, it returns -8 and -9 and with none of version of
getColumn function you can achieve its value and it generates compatibility error. If it's possible to you, please describe more what in your mind.
As per the documentation, NCHAR and NVARCHAR2 columns are returned as UTF-16 encoded strings. The correct C/C++ data type for this is SQLWCHAR (which equates to wchar_t on Windows and unsigned short on Unix/Linux). Windows intrinsically uses UTF-16 so there you are fine but on Unix/Linux the wchar_t implementation is actually UTF-32 and there is no standard support for UTF-16 (as far as I know) so there you will need to either use some UTF-16 library or provide your own UTF-16 / UTF-32 conversion. For thsi reason it may be better to avoid NCHAR/NVARCHAR2 and instead use regular CHAR/VARCHAR2 with a suitable DatabaseCharacterSet (such as AL32UTF8) since most Unix/Linux 'char' implementations today use UTF-8 natively.
As you said it's been written in the documentation that for NVARCHAR2 columns we should use wchar_t variable types but when I used this type, I had gotten an error in ttclasses1121.dll. The project is compiled but a runtime error indicating the getColumn function could not be located in ttclasses1121.dll.
I checked the code and the functions are there for sure. Note that (a) you should use SQLWCHAR not wchar_t directly and (b) the getColumn function for SQLWCHAR takes a SQLWCHAR ** argument not a SQLWCHAR* argument. i.e. we return you a pointer to a buffer rather than copying the data to a buffer that you have allocated. For example:
SQLWCHAR * myColumnVal;
/* Assumes TTCmd has already been prepared, executed etc. etc. */
getColumn(1 /* assume col#1 is NVARCHAR2 */, &myColumnVal);
Is this what you are doing in you code?
If you are still having problems please can you provide an example of the actual code that has the problem.
Sorry, but I just noticed that you are using version 220.127.116.11.0 which is pretty old now and I believe does not even properly support wide characters. Can you please upgrade to the latest version (18.104.22.168.0) and try again with that before we go any further. No one should be using such an old version now. if for some reason you need to stick with 11.2.1 then please upgrade to 22.214.171.124.0 which is the latest release in the 11..1 stream. But I would strongly recommend using 126.96.36.199.0 instead.