Skip to Content
avatar image
Former Member

What is the internal encoding of NVARCHAR

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Sep 06, 2017 at 09:21 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded