This discussion is archived
8 Replies Latest reply: Jul 31, 2012 12:18 AM by Shahrokh RSS

Unable to retrive a NVARCHAR2 column via tt_classes

Shahrokh Newbie
Currently Being Moderated
Hello all

I have a TT database that cached some oracle tables and I want to work with the TT database though tt_classes. One of the tables has a

NVARCHAR2 column and I can't retrieve its value from my application using tt_classes. What kind of variable in c++ should be used in

getColumn function to get NVARCHAT2 values. I tried different types such SQLWCAHR*, char* and also SQLWCHAR** but no success. With

the latest, the application can not even be compiled and i got dll error with ttclasses1121.dll. With the others, the app is compiled but i get the

error about compatibility with column and variable type.

My TimesTen version is 11.2.1.4.0

Best regards
Shahrokh
  • 1. Re: Unable to retrive a NVARCHAR2 column via tt_classes
    rajeshp Explorer
    Currently Being Moderated
    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 ?
  • 2. Re: Unable to retrive a NVARCHAR2 column via tt_classes
    Shahrokh Newbie
    Currently Being Moderated
    Dear rajeshp

    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.
  • 3. Re: Unable to retrive a NVARCHAR2 column via tt_classes
    ChrisJenkins Guru
    Currently Being Moderated
    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.

    Chris
  • 4. Re: Unable to retrive a NVARCHAR2 column via tt_classes
    Shahrokh Newbie
    Currently Being Moderated
    Dear Chris

    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.

    Thanks
  • 5. Re: Unable to retrive a NVARCHAR2 column via tt_classes
    ChrisJenkins Guru
    Currently Being Moderated
    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:

    TTCmd myCmd;

    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.

    Thanks,

    Chris
  • 6. Re: Unable to retrive a NVARCHAR2 column via tt_classes
    Shahrokh Newbie
    Currently Being Moderated
    I do the exactly what you saying but i get a runtime error about that .dll file. Is it possible that the .dll fill I have may be corrupted?? If so, can you please upload your file??

    Best regards
  • 7. Re: Unable to retrive a NVARCHAR2 column via tt_classes
    ChrisJenkins Guru
    Currently Being Moderated
    Sorry, but I just noticed that you are using version 11.2.1.4.0 which is pretty old now and I believe does not even properly support wide characters. Can you please upgrade to the latest version (11.2.2.3.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 11.2.1.9.0 which is the latest release in the 11..1 stream. But I would strongly recommend using 11.2.2.3.0 instead.

    Thanks,

    Chris
  • 8. Re: Unable to retrive a NVARCHAR2 column via tt_classes
    Shahrokh Newbie
    Currently Being Moderated
    We create some VS10 projects based on 11.2.1.4 version .dll files which was so difficult to get ttClasses worked. Once I tried to upgrade to the

    latest version of TimesTen but I couldn't compile the projects because my try to create new .dll files failed.

    Shahrokh

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points