Delphi - TUpdateObject versus OnUpdateRecord for a join SQL statement

别等时光非礼了梦想. 提交于 2019-12-08 09:52:19

问题


I have a pFibdataset(which is working similar to BDEDataset) in which I need to make the following join selection

select table.Name as name,
table1.Name as name_1,
table2.Name as name_2
from table 
left join table table_1 on table.id=table_1.id
left join table table_2 on table.id=table_2.id

Fields name, name_1 and name_2 are linked to some data-aware edits. Now, I want after I'm modifying(update,delete,insert operations) the name,name_1 and name_2 fields to be updated in the tables. Based on the wiki Using_Multiple_Update_Objects_Index I can use UpdateObjects, or OnUpdateRecord event.

The problem is that I don't understand how this need to be implemented. I have the join select on the query, how I need to define and work with name_1 and name_2 fields. Can someone provide me an example for this?

I know how to use subqueries in order to accomplish this. I need to see how can I can make it by using UpdateObjects or OnUpdateRecord.


回答1:


TpFibUpdateObject works like a trigger on client side. To make it work, set the following properties:

DataSet - dataset (master) to monitor
KindUpdate - Insert/Update/Delete - action to monitor
SQL - command to execute when action is fired, params are taken from DataSet
ExecuteOrder - AfterDefault/BeforeDefault - probably you need after / master

BUT, instead using a lot of UpdateObject components and such tangled approach, I recommend two alternative (read better) ways:

  1. Updatable view. It will work like a "virtual table". Create a view that joins these theee tables and write Before Insert/Update/Delete triggers. In Delphi use it as a regular table: select from view / insert into view / update view and delete from view. Anyway I suppose you need in many places these tables linked toghether.

  2. Use EXECUTE BLOCK statements in your TpFIBDataSet SQLs. Insert / Update / Delete in a batch all tables.




回答2:


Solution : OnUpdateRecord it must be created an TUpdateObject for each field from the joined table.

 UpdateObjectvariable.DataSet := Dataset;
 fill the SQL text
 Apply.

After all update objects are set, UpdateAction := uaApplied; must be called.



来源:https://stackoverflow.com/questions/12366772/delphi-tupdateobject-versus-onupdaterecord-for-a-join-sql-statement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!