Skip to Content
avatar image
Former Member

What is the internal encoding of NVARCHAR


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?


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 ( 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