为什么我的查询返回错误的字符串类型?
根据 官方 Firebird 文档,包含 Unicode 字符串的列(什么SQL Server 调用 NVARCHAR) 应声明为 VARCHAR(x) CHARACTER SET UNICODE_FSS
。所以我这样做了,但是当我用 DBExpress 查询表时,我得到的结果是一个 TStringField,它只是 AnsiString,而不是我期望的 TWideStringField。
如何让 DBX 从 Unicode 字符串列中提供 Unicode 字符串结果?
According to the official Firebird documentation, columns containing Unicode strings (what SQL Server calls NVARCHAR) should be declared as VARCHAR(x) CHARACTER SET UNICODE_FSS
. So I did that, but when I query the table with DBExpress, the result I get back is a TStringField, which is AnsiString only, not the TWideStringField I was expecting.
How do I get DBX to give me a Unicode string result from a Unicode string column?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于 Firebird,您唯一的选择是将整个数据库连接设置为 Unicode 字符集,例如 utf8。
这样,所有 VarChar 列都将生成 TWideStringField 类型的字段。尽管在创建列时声明了特定的字符集,但字段将始终为 TWideStringFields。
设置此项,将导致:
我现在从几个月前教授 Delphi 时创建的示例项目中收集这些图像。如果您的情况如此,您必须在创建任何持久字段之前设置此属性。
看起来驱动程序不支持 UNICODE_FSS 字符集,因为我的第一个操作是创建一个新项目,设置属性,然后创建一些字段。恕我直言,最好在创建数据库语句中将整个数据库声明为utf8或驱动程序支持的其他字符集,然后在Delphi中匹配数据库字符集以避免字符串转换。
With Firebird, your only option is to set the whole database connection to a Unicode char set, for example to utf8.
That way, all the VarChar columns will result in fields of type TWideStringField. The fields will be always TWideStringFields despite the particular char set declared when creating the column.
Setting this, will result in this:
I collect this images now from a example project I created while teaching Delphi a few months ago. You have to set this property before creating any persistent fields if that's your case.
It looks like the driver does not support the UNICODE_FSS charset, as my first action was to create a new project, set the property and then create some fields. IMHO it's better to declare the whole database as utf8 or other charset supported by the driver in the create database sentence, and then match the database charset in Delphi to avoid string conversions.