如何让 DBX 知道联接中的字段不应在 ApplyUpdates 期间更新?
我有一些代码可以在网格上构建房间的地图(图表),并在它们之间建立链接。它存储在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用提供者标志来告诉哪些文件应该更新,并告诉提供者哪个表应该更新(有一个 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.
该查询的 SQL 是旨在返回数据的查询,并不适合插入或更新。尽管 SimpleDataSets 允许双向使用,但并非所有情况都可以用它来处理。我将创建两个不同的单向 ClientDataSet,一个用于查询,另一个可以直接访问表而不是使用查询。
引用 Martin Rudy 的《dbExpress 入门》:
另外,请阅读有关设置 UpdateMode 和 ProviderFlags 属性的章节,
其中有很多关于控制数据集中用于查找和更新记录的字段的有趣信息。
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:
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.