My development environment -
Database -> Microsoft SQL Server2008 R2
OS -> Windows Server 2008 R2
Database Charset -> Chinese_PRC_CI_AS (Windows936)
Operating System Charset -> Chinese
Below table is having varchar fields with different charsets.
createtable dbo.tcolcs1 (
c1 int notnullprimarykey,
c2 varchar(30)collate SQL_Latin1_General_Cp1_CI_AS ,
c3 varchar(30)collate Chinese_PRC_CI_AS
)
I want to insert below record using OLEDB APIs provided by Microsoft. Just for information, character '0x00C4' does not
belong to Windows 936 codepage.
insertinto dbo.tcolcs1values (10,
NCHAR(0x00C4), NCHAR(0x4EBC))
Code snippet -
DBPARAMBINDINFO bind_info
memset(&bind_info, 0, sizeof(DBPARAMBINDINFO));
...
...
bind_info.pwszDataSourceType = L"DBTYPE_VARCHAR";
bind_info.wType = DBTYPE_STR;
I have bound the varchar field with DBTYPE_STR. I can see that my code is not inserting Latin1 character (0x00C4) correctly
into the table. The code always inserts a blank character into Latin1 column (c2) and 0x4EBC into Chinese column (c3).
Later, I changed the binding from DBTYPE_STR to DBTYPE_BYTES as below -
bind_info.pwszDataSourceType = L"DBTYPE_BINARY";
bind_info.ulParamSize = 0;
bind_info.wType = DBTYPE_BYTES;
With the above change, I observed that OLEDB is converting hex value to string. It is inserting 0x00C4 as 'C4' and 0x4EBC
as '4EBC'. I also tried with adding 'AutoTranslate=no' in driver connection string, but it did not help. How can I insert above record with OLEDB in the above table ?
Thanks in advance.