如何让 DBX 知道联接中的字段不应在 ApplyUpdates 期间更新?

发布于 2024-08-17 01:53:17 字数 735 浏览 3 评论 0原文

我有一些代码可以在网格上构建房间的地图(图表),并在它们之间建立链接。它存储在 Firebird 数据库中,其中一个表中包含房间,另一个表中包含链接。数据通过 DB Express TSimpleDataset 数据集进行管理。

Exits (links) 表的查询如下所示:

select
  EXITS.*,
  r1.x as x,
  r1.y as y,
  r2.x as x2,
  r2.y as y2 
from EXITS
inner join ROOMS r1 on r1.ROOM_ID = EXITS.ROOM1
inner join ROOMS r2 on r2.ROOM_ID = EXITS.ROOM2

问题是,当我添加新出口并调用 ApplyUpdates 时,DBX 的 SQL 解析器似乎不明白 ROOMS 表中的字段只是为了方便而不是一部分原始表的。它生成以下内容:

insert into "EXITS"
  ("EXIT_ID", "AORDER", "AEXIT", "PREACTION", "POSTACTION", "COLOR", "ROOM1",
   "ROOM2", "MAP1", "MAP2", "X", "Y", "X2", "Y2")
values
  (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

加上适当的参数,具有可预测的结果。有谁知道我如何才能让它理解 X 和 Y 不应该被插入或更新?

I've got some code that builds a map (graph) of rooms on a grid with links between them. It's stored in a Firebird database with rooms in one table and links in another. The data is managed through DB Express TSimpleDataset datasets.

The query for the Exits (links) table looks like this:

select
  EXITS.*,
  r1.x as x,
  r1.y as y,
  r2.x as x2,
  r2.y as y2 
from EXITS
inner join ROOMS r1 on r1.ROOM_ID = EXITS.ROOM1
inner join ROOMS r2 on r2.ROOM_ID = EXITS.ROOM2

Problem is, when I add a new exit and call ApplyUpdates, DBX's SQL parser doesn't seem to understand that the fields from the ROOMS table are just there for convenience and not part of the original table. It generates the following:

insert into "EXITS"
  ("EXIT_ID", "AORDER", "AEXIT", "PREACTION", "POSTACTION", "COLOR", "ROOM1",
   "ROOM2", "MAP1", "MAP2", "X", "Y", "X2", "Y2")
values
  (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

plus the appropriate params, with predictable results. Does anyone know how I can make it understand that the Xs and Ys aren't supposed to be inserted or updated?

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

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

发布评论

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

评论(2

剩余の解释 2024-08-24 01:53:17

使用提供者标志来告诉哪些文件应该更新,并告诉提供者哪个表应该更新(有一个 OnGetTableName 事件或类似的事件)。另一种选择是使用 OnBeforeUpdateRecord 事件并编写一些代码来执行更新,而不使用 SQL 生成器中内置的 TDatasetProvider。

Use provider flags to tell which fileds should be updated, and tell the provider which table shoud be updated (there's an OnGetTableName event or something alike). Another options is to use the OnBeforeUpdateRecord event and write some code to perform the update without using TDatasetProvider built in SQL generator.

阪姬 2024-08-24 01:53:17

该查询的 SQL 是旨在返回数据的查询,并不适合插入或更新。尽管 SimpleDataSets 允许双向使用,但并非所有情况都可以用它来处理。我将创建两个不同的单向 ClientDataSet,一个用于查询,另一个可以直接访问表而不是使用查询。

引用 Martin Rudy 的《dbExpress 入门》:

更合适的方法是使用
ClientDataSet (CDS) 和
数据集提供者。连接到数据
使用 CDS 和 DSP CDS 和
DSP 组件位于数据
访问组件选项板。一个
SQLDataSet 组件来自
dbExpress调色板用于定义
结果集。 SQL连接
SQLDataSet 的属性已分配
SQLConnection 组件名称。
SQLDataSet CommandText 属性
定义 SQL 语句。数据集
DSP 的属性设置为名称
SQLDataSet 组件的。 CDS
组件有一个 ProviderName 属性
它被设置为 DSP 名称。这
最后一次属性值更改是
DataSource DataSet 属性其中
应分配给 CDS
组件名称。设置CDS
Active 属性设置为 True (或使用
Open 方法)检索数据。在
第一眼你可能会觉得这是

SimpleClientDataSet。当我们涵盖更多
CDS 和 DSP 功能的您将获得
更好地理解为什么你会
使用 DSP 和 CDS 代替
简单客户端数据集

另外,请阅读有关设置 UpdateModeProviderFlags 属性的章节,

其中有很多关于控制数据集中用于查找和更新记录的字段的有趣信息。

使用 ClientDataSets,UpdateMode 属性位于 DataSetProvider 上。如果您使用 CDS/DSP 组合组件之一(例如 SimpleClientDataset),则由于内部 DataSetProvider,这些组件具有 UpdateMode 属性。

The SQL for that Query is, well, a query intented for returning data, and is not appropiate for and Insert or Update. Eventhough SimpleDataSets allow for bidirectional usage, not all situations can be handled with it. I would create two different unidirectional ClientDataSet one for the Query and the other with a direct access to the Table instead of using the Query.

Quoting from Getting Started with dbExpress by Martin Rudy:

A more appropriate approach is to use
a ClientDataSet (CDS) and
DataSetProvider. Connecting to data
using a CDS and DSP Both the CDS and
DSP components are located on the Data
Access component palette. A
SQLDataSet component from the
dbExpress palette is used to define
the result set. The SQLConnection
property of the SQLDataSet is assigned
to the SQLConnection component name.
The SQLDataSet CommandText property
defines the SQL statement. The DataSet
property of the DSP is set to the name
of the SQLDataSet component. The CDS
component has a ProviderName property
which is set to the DSP name. The
last property value change is to the
DataSource DataSet property which
should be assigned to the CDS
component name. Setting the CDS
Active property to True (or using the
Open method) retrieves the data. At
first glance you might feel this is
too much work compared to the
SimpleClientDataSet. As we cover more
of the CDS and DSP features you gain a
better understanding of why you will
use a DSP and CDS instead of the
SimpleClientDataSet

Also, read the chapter on Setting UpdateMode and ProviderFlags properties

There is a lot of interesting information regarding the control of the fields in the dataset used to find and update a record.

Using ClientDataSets, the UpdateMode property is on the DataSetProvider. If you use one of the combination CDS/DSP components (e.g. SimpleClientDataset), those components have an UpdateMode property because of the internal DataSetProvider.

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