使用数据适配器时,与更新 CASCADE 问题一起使用的输出参数
我手动创建了一些数据适配器 - 对于由许多表组成的数据集(通常混合有 PK、FK 约束),由于版本不兼容,使用自动生成的数据适配器是不可行的。到目前为止,它的大部分工作都非常顺利,但是在修改适配器以使用数据库序列进行PK(而不是分配给数据集中的行的临时序列)之后,当使用新的“添加”行更新数据库时,我一直在打击问题。
我将序列添加到插入语句中,并将 PK 参数更改为输出参数,以便它将更新数据集行,从而更新所有子行(使用 UPDATE CASCADE 规则)。问题在于,在更新之前添加行状态的子行被更改为已修改状态(我不同意这种情况应该发生,当然添加的行应该保持添加状态,即使它是修改的!)。因此,当我们用子行更新子表时,它会失败,因为它的预期行具有添加的状态。
我可以解决这个问题的最干净的方法是什么?我能想到的潜在解决方案:
- 关闭 UPDATE CASCADE 并在修改后手动更新每个子行,更新父级 PK 并将每行更改回添加状态。
- 在开始更新之前,在数据集的所有表中创建所有添加行的副本,然后在每个表更新后更新主副本,将所有正确的行标记回已添加。
还有更好的想法吗?
I've manually created some data adapters – using the auto-generated ones is not viable due to version incompatibilities, for a dataset made of a number of tables with the usual mixture of PK, FK constraints. Most of its working pretty smoothly so far, but after modifying the adapters to use DB sequences for the PKs (instead of the temporary one assigned to the rows in the dataset) when updating the DB with new ‘added’ rows, I’ve been hitting problems.
I added the sequences into the insert statements and changed PK parameter to output parameters, so that it would update the dataset row and thus update all the child rows as well (with the UPDATE CASCADE rule). The problem is that the child rows, that, before the update had a row state of added, are changed to a state of modified (I don’t agree this should even be happening, surely an added row should stay as added even if it’s modified!). Thus when we get round to updating the child table with the child rows, it fails as its expecting rows with the added state.
What’s the cleanest way I could get around this problem? Potential solutions I can think of:
- Turning off UPDATE CASCADE and updating each child row manually after, updating the parents PK and changing each row back to added, after modifying it.
- Creating a copy of the all the added rows in all tables of the dataset before starting updates and then updating the main copy after each tables updates marking all the correct rows back to added.
Any better ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论