delphi - 如何从属性Required设置为false的字段中检索信息?

标签 delphi firebird datasnap tclientdataset

我的软件中有以下 DBX 结构:

TSQLDataSet -> TDataSetProvider -> TClientDataSet

我的 TClientDataSet 中的一个字段将Required 属性设置为false,因为该字段会根据数据库(Firebird)上的触发器和生成器自动递增。

但是,在不需要此字段的情况下配置 TSQLDataSet 和 TClientDataSet 后,当我尝试从 TClientDataSet 读取此字段时,我得到了非常奇怪的结果。我怀疑我可能需要做一些额外的事情来强制我的 TClientDataSet 在这种情况下获取该字段的值。

我在这里想念什么?

提前致谢。

编辑

Required 属性的帮助文件说明了这一点,但我不太明白它要我做什么。

Description

Specifies whether a nonblank value for a field is required.

Use Required to find out if a field requires a value or if the field can be blank.

If a field is created with the Fields editor, this property is set based on the underlying table. Applications that set Required to true for fields that must have values (for example, a password or part number), but for which the underlying table does not require the field, must write an OnValidate event handler to enforce the property.

When the Required property reflects a property of the underlying database table, trying to post apply a null value causes an exception to be raised. Applications that set the Required property to true when the underlying table does not require the field, should raise an EDatabaseError exception on null values in the OnValidate event handler in order to achieve the same result.



编辑 2

忘了提一下:在 TDataSetProvider 和 TClientDataSet 之间,有一个 DataSnap 层(TClientDataSet 连接是通过 DataSnap 驱动建立的)。

编辑 3

我用这个 DataSnap 设置创建了一个小测试用例,它运行良好。该项目是遗留的,困惑的,我想要么我在某个地方配置了一个模糊的选项,这让我很痛苦,要么我偶然发现了一个 DataSnap 错误。

最佳答案

浩乐,插入后有没有试过TClientDataset.RefreshRecord?甚至 TClientDataset.Refresh?
有了生成器,您甚至可以在 select gen_id(generator,1) from RDB$Database 之类的查询中提前(在调用 ApplyUpdates 之前)获取生成器。 (凭内存,这里没有Firebird来测试)提前填好PK字段。

编辑:似乎这是一个 heisenbug。我会尝试删除组件并重新配置它们从零开始 (这意味着:删除后,保存并关闭 Delphi)。

或者更好的是,创建一个只包含所需查询配置的空项目,并尝试在 TDBGrid 中查看该数据。如果这个问题仍然存在,可能你的 FB 安装有一些组件损坏(甚至是 Delphi 安装)

关于delphi - 如何从属性Required设置为false的字段中检索信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9038436/

相关文章:

delphi - 检查网页浏览器是否为空

jdbc - 最新的 Firebird JDBC 驱动有病毒吗?

delphi - 当我尝试免费的 TJSONObject 时出现访问冲突

delphi - Delphi XE5 DataSnap应用程序-反馈

delphi - 列表框过滤

delphi - Delphi 的免费 dbexpress 驱动程序列表

c# - 将 Firebird 连接到 ASP.net WebAPI 项目

sql - 如何捕获 Firebird SQL 查询?

delphi - 如何为 Delphi XE datasnap 服务器配置 HTTPS

delphi - 通过在 Delphi VCL 中组合两个控件(TEdit 和 TTrackBar)来创建一个新组件