Delphi 不允许我插入缺少列的行,但可以为这些字段插入触发器和生成器

发布于 2024-12-29 01:58:16 字数 705 浏览 7 评论 0原文

问题很简单:我的 Firebird 2.1.4 数据库中有触发器和生成器,可以在每次插入时自动递增列。

系统的架构如下:

TSQLConnection > TSQLDataSet -> TDataSetProvider -> (DataSnap) -> TClientDataSet -> TDataSource

但是,如果我尝试在 TClientDataSet 中发布更新,但缺少一些列,Delphi 会这样抱怨:

Field 'XXX' must have a value

如果我使用缺少这些字段的 SQL 插入语句,则会插入行并触发触发器和发电机按预期工作。

如何让 Delphi(DBX、DataSnap 等)了解我想要做什么(并允许它)?

编辑

根据@mj2008的评论提供更多信息:此TClientDataSet是在运行时使用CloneCursor方法创建的。调用 CloneCursor 后,我将此字段的必需属性设置为 False。这对解决这个问题没有帮助。示例:

myCds.CloneCursor(otherCds, True);
myCds.FieldByName('XXX').Required := False;

这会导致抛出相同的异常。

The problem is simple: I have triggers and generators in my Firebird 2.1.4 database to make a column auto increment on each insert.

The architecture of the system is as follows:

TSQLConnection > TSQLDataSet -> TDataSetProvider -> (DataSnap) -> TClientDataSet -> TDataSource

However, if I try to Post updates in my TClientDataSet with some missing column, Delphi will complain like this:

Field 'XXX' must have a value

If I use a SQL insert statement with those fields missing, the row gets inserted and the triggers and generators works as expected.

How do I make Delphi (DBX, DataSnap and such) understand what I'm trying to do (and allow it)?

EDIT

Providing more information based on @mj2008's comment: this TClientDataSet is being created at runtime, using the CloneCursor method. After calling the CloneCursor, I set this field's Required property to False. It does not help with this issue. Example:

myCds.CloneCursor(otherCds, True);
myCds.FieldByName('XXX').Required := False;

This results in the same exception being thrown.

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

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

发布评论

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

评论(2

笑梦风尘 2025-01-05 01:58:16

我还必须将 TSQLDataset 的 required 属性设置为 False。这解决了问题。

I had to set the TSQLDataset's Required property to False too. That solved the issue.

病女 2025-01-05 01:58:16

只是为了补充:当您进行 TClientDataset 设置时,更新最终会发送到数据访问组件,在本例中为 TSQLDataset,因此即使 TClientdataset 不需要字段的值,如果数据访问组件需要它出现错误。

即使数据来自 TADODataset、TIbDataset 或其他任何数据,它也是一样的。

Just to complement: when you do a TClientDataset setting, the updates are in the end sent to the data access component, in this case TSQLDataset, so even if the TClientdataset doesn't require the field's value, if the data access component requires it the error is raised.

It'll be the same even if data come from a TADODataset, TIbDataset, or whatever.

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