Home » Other » General » Problem nvarchar type
Problem nvarchar type [message #227820] Thu, 29 March 2007 08:53 Go to next message
lisahogg
Messages: 1
Registered: March 2007
Junior Member
Hi,

I have written a basic c++ application that extracts data from
an oracle database using ODBC calls. A simple version of the
code is given below.


char SQL[1024] = "select name from USERS";

char names[20][1024];

long rowSize = 20;
long len = SQL_NTS;

SQLUINTEGER NumRowsFetched;
SQLUSMALLINT RowStatusArray[20];
SQLINTEGER lenArray1[20];

retcode = SQLAllocHandle(SQL_HANDLE_STMT, hDBC, &hStmt);

SQLSetStmtAttr(hStmt, SQL_ATTR_ROW_BIND_TYPE,SQL_BIND_BY_COLUMN, 0);

SQLSetStmtAttr(hStmt, SQL_ATTR_ROW_ARRAY_SIZE, (SQLPOINTER)rowSize, 0);

SQLSetStmtAttr(hStmt, SQL_ATTR_ROW_STATUS_PTR, RowStatusArray, 0);

SQLSetStmtAttr(hStmt, SQL_ATTR_ROWS_FETCHED_PTR, &NumRowsFetched, 0);

retcode = SQLBindCol(hStmt, 1, SQL_C_CHAR, site_names, sizeof(site_names[0]), lenArray1);

retcode = SQLExecDirect(hStmt, (unsigned char*)SQL, SQL_NTS);

// Execute SQL statement
retcode = SQLExecDirect(hStmt, (unsigned char*)SQL, SQL_NTS);

if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
while ((retcode = SQLFetchScroll(hStmt,SQL_FETCH_NEXT,0)) != SQL_NO_DATA)
{

for (int i = 0; i < NumRowsFetched; i++)
{
if ((RowStatusArray[i] == SQL_ROW_SUCCESS) ||
(RowStatusArray[i] == SQL_ROW_SUCCESS_WITH_INFO))
{
printf("NAME is %s", names[i]);


The problem is that the database field is an nvarchar and
this select works on a 10g database and I get the names printed out, but when I link the program to an 8i database I just get a blank (no error message - just blanks) where the the name should be.

I think it has to be something to do with the ODBC driver (8i using version 8.01.07.00) and the nvarchar field binding.

Any help would be appreciated.

Thanks
Re: Problem nvarchar type [message #228033 is a reply to message #227820] Fri, 30 March 2007 16:21 Go to previous message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
Sounds like a codepage issue. Check the charactersets in both databases. You may need to do a codepage conversion from the NCHAR characeterset to the database characterset to extract the data. Check the characterset setting in the ODBC connection too.

select parameter, value from nls_database_parameters where parameter like '%CHARACTERSET';
NLS_NCHAR_CHARACTERSET         AL16UTF16                      
NLS_CHARACTERSET               AL32UTF8


Something like:
select convert(my_nchar_col, 'AL16UTF16', 'WE8ISO8859P1') from...





Previous Topic: asp error ORA-00604 / ORA-12705 !!!!!!
Next Topic: About Metalink
Goto Forum:
  


Current Time: Thu Apr 18 02:12:44 CDT 2024