MySQL的ANSI和Unicode驱动程序之间的区别 [英] Difference between ANSI and Unicode drivers of MySQL

查看:6475
本文介绍了MySQL的ANSI和Unicode驱动程序之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows上选择ODBC(64位)下的数据源时,我得到两个可用的MySQL数据库选项:

On choosing Data Source under ODBC (64-Bit) on Windows, i get two available options of MySQL Database:


  • MySQL ODBC 5.3 ANSI驱动程序

  • MySQL ODBC 5.3 Unicode驱动程序

这两者有什么区别?

推荐答案

首先我应该说,我不使用MySQL,但我知道ODBC驱动程序。在ODBC中,有unicode和ansi的不同的API。 ansi API在A中结束,unicode API在W中结束(例如,SQLPrepareA和SQLPrepareW)。 ansi API接受字节字节的字节/字节,因此只能处理chrs 0-255。 unicode API接受SQLWCHAR,它是2字节的UCS-2编码的unicode代码点(较新的MS SQL Server版本可以处理UTF16编码字符串),因此可以处理unicode中的大约前65000个代码点。

Firstly I should say that I don't use MySQL but I do know about ODBC Drivers. In ODBC there are different APIs for unicode and ansi. The ansi APIs end in A and the unicode APIs end in W (e.g., SQLPrepareA and SQLPrepareW). The ansi APIs accept bytes/octets for character strings and hence can only handle chrs 0-255. The unicode APIs accept SQLWCHARs which are 2 byte UCS-2 encoded unicode codepoints (newer MS SQL Server versions can handle UTF16 encoded strings) and so can handle approximately the first 65000 codepoints in unicode.

所以,如果你需要存储unicode数据,你不能选择使用哪个驱动程序。

So if you need to store unicode data you have no choice which driver to use.

我不会让Carnangel的速度评论unicode驱动程序,在任何情况下,他的评论不包括任何事实。他可能指的是:

I would not let the comments on speed from Carnangel put you off using the unicode driver and in any case his comments do not include any facts. He may be referring to:

如果你在MySQL中存储unicode数据,它将是UTF-8编码,并通过您的网络传输为UTF-8。在客户端,ODBC驱动程序必须将UTF-8编码的数据转换为UCS-2,因为这是ODBC需要的。

If you store unicode data in MySQL it will be UTF-8 encoded and transferred over your network as UTF-8. At the client end the ODBC driver will have to convert the UTF-8 encoded data into UCS-2 as this is what ODBC needs. Obviously the reverse applies.

如果使用unicode ODBC驱动程序编写ANSI ODBC应用程序(即使用ansi ODBC apis),ODBC驱动程序管理器将会要转换UCS-2驱动程序返回到8位(有损),并将传递给驱动程序的8位数据转换为UCS-2。所以不要这样做。

If you write an ANSI ODBC application (that is one which uses the ansi ODBC apis) with a unicode ODBC driver then the ODBC Driver manager will have to convert the UCS-2 the driver returns to 8 bit (lossy) and convert the 8 bit data you pass to the driver to UCS-2. So don't do that.

这些天,如果有人仍在使用ANSI ODBC驱动程序,我会很惊讶。

These days I'd be surprised if anyone is still using ANSI ODBC drivers.

这篇关于MySQL的ANSI和Unicode驱动程序之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆