Delphi 2006 将 sql server 2008 表达日期字段转换为 twidestring
几天前,我发布了一个关于使用哪个组件来制作 MultiDatabaseWithJustOneComponent 的问题,我遵循一般建议使用 dbexpress。
FirebirdSQL 有日期字段,SQL Server 2008 也有日期字段。但由于某种原因,日期字段被转换为 TWideStringField,当我真正确信我已经在 delphi 中看到了所有错误消息(如“灾难性故障”)时,我得到了新的错误消息。 ;-)
D2010 似乎纠正了这个“错误”,但我没有多余的现金来处理它,所以......有人有任何想法吗?
提前致谢。
Some days ago I posted a question on which component to use to make a MultiDatabaseWithJustOneComponent and i follow the general advice to use dbexpress.
FirebirdSQL has date field, SQL Server 2008 has date fields too. But for some reason date fields are converted to TWideStringField, and when I'm trully confident that I've seen all error messages in delphi like 'catastrofic failure', I've got new ones. ;-)
D2010 seems to have this 'bug' corrected, but i don´t have extra large cash to deal with it, so... does anyone have any ideia?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当Delphi 2006发布时,SQL Server没有日期字段类型,只有DateTime。 (日期和时间字段是在 SQL Server 2008 中添加的)。因此,D2006 中的 DBExpress 驱动程序不知道如何处理它们。
您最好的选择可能是使用 CAST 或 CONVERT 将日期字段强制为 DateTime (或 SmallDateTime),然后 D2006 将知道如何处理它们。
或者,如果可能的话,在数据库架构中使用 DateTime 或 SmallDateTime 字段。 SQL Server DateTime 类似于Delphi 的TDateTime。
另一种可能性是转换为 dbGO(ADO 组件),但这需要更多的返工。
When Delphi 2006 was released, SQL server didn't have a date field type, only DateTime. (Date and Time fields were added with SQL Server 2008). As a result the DBExpress drivers in D2006 don't know how to deal with them.
Your best bet may be to coerce the date fields to DateTime (or SmallDateTime) using CAST or CONVERT, then D2006 will know how to deal with them.
Alternatively use DateTime or SmallDateTime fields in your DB schema if possible. SQL Server DateTime is similar to Delphi's TDateTime.
Another possibility is to covert to the dbGO (ADO components), but this would require more rework.
手动将
field.FieldType
类型设置为TDateTimeField
。这只是意味着无论出于何种原因,DBExpress 都会错误地自动检测字段类型。覆盖它应该没问题。Manually set the
field.FieldType
type toTDateTimeField
. This just means that for whatever reason DBExpress is autodetecting the field type incorrectly. Override it and it should be fine.