Please be aware that the content in SAP SQL Anywhere Forum will be migrated to the SAP Community in June and this forum will be retired.

I am trying to update a Sybase table via Microsofts ODBC API. The following is the basics of the C++ I am trying to execute. In table, TableNameXXX, ColumnNameXXX has a type of NVARCHAR( 200 ).

    SQLWCHAR updateStatement[ 1024 ] = L"UPDATE TableNameXXX SET ColumnNameXXX = N'Executive Chair эюя' WHERE PKEYXXX = 'VALUE'";  
   if( ret = SQLExecDirect( hstmt, ( SQLWCHAR* ) updateStatement, SQL_NTS ) != SQL_SUCCESS )
   {
       // Handle Error
   }

The Sybase database has a CatalogCollation of 1252LATIN1, CharSet of windows-1252, Collation of 1252LATIN1, NcharCharSet of UTF-8 and an NcharCollation of UCA.

Once this works for the Sybase ODBC connection I need to get it to work in various other ODBC drivers for other databases.

I do not get any errors however - the data in the database is not the unicode I attempted to update.

Does anyone know how to get this to work? What am I missing?

asked 05 Feb '15, 17:59

David%20Gray%20Wright's gravatar image

David Gray W...
51226
accept rate: 0%

edited 06 Feb '15, 04:07

Volker%20Barth's gravatar image

Volker Barth
40.2k361549822


Hi David,

SQL statements are always parsed in the character set of the database (so Windows-1252 in this case). If you wish to pass Unicode/NCHAR data, you need to do one of the following (from: http://dcx.sap.com/index.html#sa160/en/dbadmin/natlang-s-5322854.html )

  • Use the UNISTR function to specify the Unicode character values
  • Use a host variable to specify the Unicode character values ('?')
  • Use UTF-8 as the database character set

So for ODBC, you will want to use prepared execution with SQLPrepare, SQLBindParameter, and SQLExecute.

permanent link

answered 05 Feb '15, 18:55

Jeff%20Albion's gravatar image

Jeff Albion
10.8k171175
accept rate: 25%

Sorry... but... the second option "Use a host variable to specify the Unicode character values ('?')" is that the same as using a prepared execution?

(05 Feb '15, 19:50) David Gray W...
Replies hidden
1

Got it working with SELECT UNISTR...

SQLWCHAR updateStatement[ 1024 ] = L"UPDATE TableNameXXX SET ColumnNameXXX = ( SELECT UNISTR( 'Executive Chair \u044F\u044D\u044E\u044F' ) ) WHERE PKEYXXX = 'VALUE'";

Thanks for your help.

(05 Feb '15, 22:22) David Gray W...

Yes - the second option is using a host variable and then binding it with data (a.k.a prepared execution).

(06 Feb '15, 10:21) Jeff Albion
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×145
×16
×13
×6

question asked: 05 Feb '15, 17:59

question was seen: 3,402 times

last updated: 06 Feb '15, 10:21