解决 Delphi 2010 或 Delphi 2009 中 TDatasetProvider 中的错误(困难的方法)
就像每年我作为 SA 所有者收到一个新的 Delphi 版本一样,这就是我所做的:
- 安装 Delphi 版本 XX。
- 运行 delphi 版本 XX
- 插入 TSQLConnection 组件。
- 将其连接到 Microsoft SQL Server 2000,该服务器将继续陪伴我们至少六年。
- 插入带有“select top 1 * from myTable”的 TSQLQuery,这是一个包含一些货币字段的表。
- 插入更多组件TDatasetProvider、TClientdataset、TDatasource、TDBGrid 和TButton。
- 链接一切。
- 在 DatasetProvider.OnUpdateError 中创建一个带有 Raise 异常的事件处理程序。
- A clientdataset1.applyupdates(0);在按钮1中单击。
- 对当前记录进行一些更改。
- 按button1,得到delphi 2005及以上版本提供的相同异常。
- 更新适用于 MsSQLServer 的 corelab 或 devArt dbx 驱动程序。
现在说真的。几年前我发现 TDatasetprovider 正在生成一个非常简单的错误:TFMTBCDField(Delphi 中金钱字段的表示)为 SQL Server 2000 和以前的版本生成不兼容的插入/更新 sql 命令。问题很简单,数据集提供程序为货币字段生成引用值,而这些 sql 服务器不接受这些值。
例子: 带有 varchar 字段和 Money 字段的表。 您可以使用如下更新:
更新测试表设置 MYMONEYFIELD = '1',其中 MYVARCHARFIELD = 'A'
对于以前版本的 SQLServer,您需要使用
:更新测试表设置 MYMONEYFIELD = 1,其中 MYVARCHARFIELD = 'A'
有人对此问题有任何解决方法吗?
Like every year I receive a new Delphi version as SA owner and this is what I do :
- Install delphi version XX.
- Run delphi version XX
- Insert a TSQLConnection component.
- Connect it to a Microsoft SQL Server 2000 who will be with us at least for six more years.
- Insert a TSQLQuery with a 'select top 1 * from myTable' which is a table with some money fields.
- insert more components TDatasetProvider, TClientdataset, TDatasource, TDBGrid and a TButton.
- Link everything.
- Create An event handler in the DatasetProvider.OnUpdateError with a Raise exception.
- A clientdataset1.applyupdates(0); in the button1click.
- make some changes in the current record.
- Press the button1 and get the same exception provided by delphi 2005 and above.
- Renew my corelab or devArt dbx driver for MsSQLServer.
Seriously now. I found some years ago that TDatasetprovider is generating a very simple error: The TFMTBCDField (representation of money field in Delphi) produces incompatible insert/update sql commands for SQL Server 2000 and previous versions. The problem is simple the dataset provider produces quoted values for money fields which are not accepted for those sql servers.
Example:
a table with a varchar field and a money field.
You can use an update like this:
UPDATE testtable set MYMONEYFIELD = '1' where MYVARCHARFIELD = 'A'
for previous versions of SQLServer you need to use:
UPDATE testtable set MYMONEYFIELD = 1 where MYVARCHARFIELD = 'A'
Someone has any workaround for this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Borland/CodeGear/Embarcadero 对此不赞成,但如果这仅适用于您自己的应用程序,您可以追溯到 VCL 源并对源进行必要的更改,以确保获得正确的 SQL 生成。每次获得新版本或修复之前,您都需要进行此更改,但这可以解决您的问题。
您可以将更改提交到 codegear,看看他们是否会将其插入。
This is frowned upon by Borland/CodeGear/Embarcadero, but if this is only for your own apps, you can trace down into the VCL source and make the necessary change to the source to ensure you get the correct SQL Generated. You would need to make this change each time you got a new version or until it was fixed, but it would solve your issue.
You could submit your change to codegear and see if they would plug it in.