ZUpdateSQL issue (updatekind)

The forum for ZeosLib 7.2 Report problems. Ask for help, post proposals for the new version and Zeoslib 7.2 features here. This is a forum that will be edited once the 7.2.x version goes into RC/stable!!

My personal intention for 7.2 is to speed up the internals as optimal a possible for all IDE's. Hope you can help?! Have fun with testing 7.2
Post Reply
wsian
Fresh Boarder
Fresh Boarder
Posts: 3
Joined: 16.06.2022, 08:32

ZUpdateSQL issue (updatekind)

Post by wsian »

Hi,
Just started to switch over to Zeoslib. Everything works fine.
I have a question regarding ZUpdateSQL.

In BDE or (SQLdirect), I'm able to trigger the updatesql to do an insert using
(Query1.UpdateObject as TUpdateSQL).Apply(ukInsert);

example below:

Code: Select all

procedure TForm1.Query1AfterEdit(DataSet: TDataSet);
begin
  if Query1.FieldByName('REASON').IsNull and
     Query1.FieldByName('CAUSE').IsNull and
  then
  begin
      (Query1.UpdateObject as TUpdateSQL).Apply(ukInsert);
  end;
end;
Is there an equivalent method to do this with Zeoslib?
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: ZUpdateSQL issue (updatekind)

Post by marsupilami »

Hello wsian,

I have to admit, that I don't understand the use case. Usually Zeos will call the relevant SQL from TZUpdateSQL object automatically?

What do you want to achieve?

Best regards,

Jan
wsian
Fresh Boarder
Fresh Boarder
Posts: 3
Joined: 16.06.2022, 08:32

Re: ZUpdateSQL issue (updatekind)

Post by wsian »

I have a joined query, table A left join table B display on single dbgrid.
table A data are fixed data and table B is blank initially and pending for user to update.
By using updatesql, I'm able to insert / modify table B with the statement in insertSQL and modifySQL.

Example with following code, after user edit data in dbgrid, it will be checked whether this is new data. This will trigger the Insert action with the updatesql object.

Code: Select all

procedure TForm1.Query1AfterEdit(DataSet: TDataSet);
begin
  if Query1.FieldByName('REASON').IsNull and
     Query1.FieldByName('CAUSE').IsNull and
  then
  begin
      (Query1.UpdateObject as TUpdateSQL).Apply(ukInsert);
  end;
end;
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: ZUpdateSQL issue (updatekind)

Post by marsupilami »

Hello wsian,

Unfortunately TZUpdateSQL doesn't support that use case directly. It automatically chooses the SQL to run and executes it. Depending on your database you might want to have a look at using upsert statements in the InsertSQL and ModifySQL of TZUpdateSQL. This way your database decides on what to do.

Unfortunately the exact statement to use depends on the database. In Firebird it is UPDATE OR INSERT, PostgreSQL has insert ... on conflict, MSSQl seems to use MERGE, MySQL seems to have REPLACE INTO.

Best regards,

Jan
wsian
Fresh Boarder
Fresh Boarder
Posts: 3
Joined: 16.06.2022, 08:32

Re: ZUpdateSQL issue (updatekind)

Post by wsian »

Thanks for the hint. I'm converting from old sql statement and overlook the merge statement in oracle.
I shall look into this again.
Thank you once again.
Post Reply