ClientDataset.RefreshRecord 在 Delphi XE 中不再适用于连接表 - 有解决方法吗?

发布于 2024-11-14 23:50:39 字数 1232 浏览 3 评论 0原文

当尝试刷新连接到 SQL 语句中具有联接表的数据集的 ClientDataset 上的记录时,TClientDataset.RefreshRecord 不再生成 SQL 的表联接部分。

因此,调用此方法会导致对于不在主表中的每个字段,SQL 错误“无效的列名”

这在 Delphi 2010 及更早版本中不是问题。

连接到 TClientDataset 的 DBX4 或 BDE 组件都会发生该错误,因此问题很可能是 TClientDataset 代码更改引起的问题.

要复制此问题:

在 Delphi XE 中创建一个仅包含单个表单的新应用程序,并在其上放置所需的数据库组件(TSQLMonitor、TSQLConnection、TSQLQuery、 TDatasetProvider、TClientDataset、TDatasource 和 TDBGrid)并将它们相互绑定。

使用表连接创建了一个简单的 SQL 语句,并将其放置在 TSQLDataset.SQL 属性中。

SQL 语句仅包含两个字段 - 主表的关键字段和连接表中的字段 - 例如伪代码:

Select 
  MainTable.IntegerKeyField
  , JoinedTable.JoinField
FROM MainTable
LEFT OUTER JOIN JoinedTable ON MainTable.LookupFieldID = JoinedTable.JoinKeyField

将这两个字段添加为 TSQLQuery 和 TClientDataset 中的持久字段,并为关键字段添加 Provider Flag,包括pfInKey(如果 RefreshRecord 不知道哪个字段是键,则 RefreshRecord 将无法工作,因此必须使用持久字段)。

在表单上添加两个按钮 - 第一个按钮仅打开 Clientdataset,第二个按钮调用 clientdataset.refreshrecord;

运行应用程序,按按钮打开数据集,数据显示在网格中。

按刷新记录按钮,您将收到连接字段的 SQL 错误“无效的列名”。

关闭应用程序,打开SQLMonitor日志,在刷新记录Delphi生成的SQL语句中,你会看到它没有包含表连接语句。

====

我真的很感激任何关于如何解决这个问题的想法。

TClientDataset.RefreshRecord no longer generates the table join part of SQL when trying to refresh a record on a ClientDataset connected to a dataset with a joined table in the SQL statement.

As a result, calling this method results in SQL error "invalid column names" for each field not in the main table.

This was not a problem in Delphi 2010 and earlier.

The error occurs with both DBX4 or BDE components connected to the TClientDataset and thus it is highly likely the issue is a problem with changes to TClientDataset code.

To replicate this problem:

Create a new app in Delphi XE with only a single form and drop the required database components on it (TSQLMonitor, TSQLConnection, TSQLQuery, TDatasetProvider, TClientDataset, TDatasource, and TDBGrid) and bind them to each other.

Created a simple SQL statement with a table join and placed this in the TSQLDataset.SQL property.

The SQL statement included just two fields - the key field of the main table, and a field from a joined table - for example in pseudocode:

Select 
  MainTable.IntegerKeyField
  , JoinedTable.JoinField
FROM MainTable
LEFT OUTER JOIN JoinedTable ON MainTable.LookupFieldID = JoinedTable.JoinKeyField

Add both of these fields as persistent fields in both TSQLQuery and TClientDataset with Provider Flag for the key field including pfInKey (RefreshRecord will not work if it does not know which field is the key hence persistent fields is a must).

Add two buttons on the form - one just opens the Clientdataset and the 2nd button calls clientdataset.refreshrecord;

Run the app, press button to open dataset and data displays in the grid.

Press the Refresh Record button, and you will get SQL error "invalid column name" for the joined field.

Close the app, open the SQLMonitor log and in the refresh record SQL statement that Delphi generated, you will see it has not included the table join statement.

====

I would really appreciate any ideas on how to fix this.

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

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

发布评论

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

评论(1

少女七分熟 2024-11-21 23:50:39

尝试在数据库上使用视图来实现所需的连接。然后delphi组件可以只从view_name中进行选择,而不必自己处理连接。

Try using a view on the database to implement the required join. Then the delphi component can just select from view_name rather than have to handle the join itself.

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