通过 ADO 和 ODBC 从 DB2 读取 Unicode 数据

发布于 2024-08-13 14:41:01 字数 731 浏览 4 评论 0原文

从我用 Delphi 2009 编写的应用程序中,我使用 ADO、ADO 的 ODBC 提供程序和 ODBC 读取和写入 IBM DB2 数据库:

Application -> ADO(Win32)-> ADO 的 ODBC 提供程序 -> ODBC-> (净)-> DB2 (Windows)

现在,我的应用程序需要存储 unicode 数据。所以我将数据库代码页设置为 UTF-8。 Delphi 在内部处理 UTF-16 格式的字符串,并将它们作为多字节字符传递给 COM。所以我应该可以在应用程序端进行编码。

在 VARCHAR 数据库字段中插入非 ansi 字符效果很好,它们可以通过 DB2 管理控制台(我认为这是一个使用 JDBC 的 Java 应用程序)正确显示。在我的应用程序(或我编写的使用 ADO 查询的任何其他测试应用程序)中,对于其中包含 unicode 字符的 VARCHAR 字段,我仅获得 #$1A 字节的序列。

奇怪的是,如果后端是 Microsoft SQL 数据库,同一个应用程序却可以正常工作。对于 DB2 来说,检索符合 ANSI 的字符串也不是问题。

DB2 文档中指出,如果应用程序调用后缀-W ODBC API,则 DB2 ODBC 驱动程序会使用 unicode 字符进行响应。在某些情况下,ADO 的 ODBC 提供程序是否可能不触发这些函数,而是使用 ANSI 函数?我尝试在 ADO 连接字符串和 ODBC 驱动程序设置中设置客户端代码页,但没有成功,尽管我可能做错了 wav。

From my application written with Delphi 2009, I am reading from and writing to an IBM DB2 database using ADO, the ODBC Provider for ADO, and ODBC:

Application -> ADO (Win32) -> ODBC-Provider for ADO -> ODBC -> (net) -> DB2 (Windows)

Now, my application need to store unicode data. So I set my database codepage to UTF-8. Delphi handles strings in UTF-16 internally and passes them as multi-byte-characters to COM. So I should be fine on encoding on the application's side.

Inserting non-ansi-chars in a VARCHAR db field works fine, they are displayed correctly by the DB2 management console (which is a Java application using, I figured, JDBC). In my application (or any other test application I wrote that uses ADO queries), I get only a sequence of #$1A bytes for VARCHAR fields with unicode characters in them.

Strangely, the same application works fine if the backend is a Microsoft SQL database. Retrieving ANSI-compliant character strings also isn't a problem for DB2.

In the DB2 documentation it says that the DB2 ODBC drivers responds with unicode characters if an application calls the suffix-W ODBC APIs. Is it possible that under certain circumstances the ODBC Provider for ADO doen't trigger those functions but instead uses the ANSI functions? I tried setting a client codepage in the ADO connection string and the ODBC driver settings without success, although I could've done that the wrong wav.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

五里雾 2024-08-20 14:41:01

我有类似的问题。我已将 DISABLEUNICODE=0 添加到我的连接字符串中,它为我解决了这个问题。

I had a similar problem. I have added DISABLEUNICODE=0 to my connection string and it resolved it for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文