Skip to Content
0

What is the internal encoding of NVARCHAR

Sep 06, 2017 at 07:31 AM

109

avatar image
Former Member

Hello,

We are writing an ODBC client and want to support UTF-8 and store UNICODE data in NVARCHAR columns.

For SQL bindings (params/fetch buffers), we have the option to bind with SQL_C_CHAR in UTF-8 (by setting SQL_SQLDBC_CHAR_AS_UTF8), or convert UTF-8 to wide char and bind with SQL_C_WCHAR.

What is the best approach to have minimal code set conversions in the client and/or in the server?

Thanks

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Lars Breddemann
Sep 06, 2017 at 09:21 AM
0

My understanding is that the SQL_SQLDBC_CHAR_AS_UTF8 setting maps ASCII characters to UTF8 so that you don't have to do that in your application.

Since you anyhow want to work with NVARCHAR types, this setting should not even affect your solution. Therefore, SQL_C_WCHAR is the way to go here.

The wire protocol (https://help.sap.com/viewer/7e4aba181371442d9e4395e7ff71b777/2.0.02/en-US/eda890ef05364286b52c92283eea804d.html) sends all data as CESU-8 so that I suspect the overall conversion effort is highest when you read ASCII data into SQL_C_CHAR.

Caveat here: neither have I seen the ODBC driver source code nor did I do measurements of the cpu/memory effects for those options.

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Thank you Lars! Yes we'll go the SQL_C_WCHAR way and use iconv to do the required conversions.
Sibling discussion here: https://answers.sap.com/questions/298273/need-help-with-iso8859-x-and-utf-8-programming-wit.html

Seb

0