Should it be possible to delete a master record that has child records attached but that have been unlinked?
This fails for us with the latest remobjects
In code we do something like
var
bes : IBestelling;
bit:IBestelItems;
begin
if Supports(FBestellingTable, IBestelling, bes) and
Supports(FBestellingTable.BestelItems, IBestelItems, bit) then
…
Foreach FBestellingTable.BestelItems record
bit.Edit();
bit.bit_bes_primkey := Fbes_primkeyDest; <- this unlinks FBestellingTable from FBestellingTable.BestelItems
bit.Post();
bes.Delete();
What happens in SQL profiler is
- DELETE FBestellingTable record
- DELETE ALL FBestellingTable.BestelItems records
- UPDATE ALL FBestellingTable.BestelItems <- THEY HAVE JUST BEEN DELETED
See below for logs
The delete of the child table is triggered by a business server rule
procedure TBestellingServerRules.AfterProcessChange( Sender: TDABusinessProcessor; aChange: TDADeltaChange; Processed: Boolean; var CanRemoveFromDelta: Boolean);
DA does not realize the UPDATE should come first (or delete is not necessary)
Can this behavior be altered? Has the behavior of DA/RO changed? We did not notice this issue earlier.
declare @p1 int
set @p1=39
exec sp_prepare @p1 output,N’@P1 int OUTPUT’,N’DELETE FROM Bestelling
WHERE
(“bes_Primkey”=@P1)’,1
select @p1
exec sp_execute 39,100031153
exec sp_executesql N’Delete From bestelItems where bit_bes_Primkey = @P1’,N’@P1 int’,100031153
declare @p1 int
set @p1=56
exec sp_prepare @p1 output,N’@P1 datetime OUTPUT,@P2 int OUTPUT,@P3 int OUTPUT,@P4 int OUTPUT’,N’UPDATE BestelItems SET
“bit_DateChanged”= @P1,
“bit_bes_Primkey”= @P2,
“bit_bes_primkey_Before_Merge”= @P3
WHERE
(“bit_Primkey”=@P4)’,1
select @p1
exec sp_execute 56,‘2020-03-20 12:30:24.627’,100031066,100031153,100468817
exec sp_execute 56,‘2020-03-20 12:31:05.457’,100031066,100031153,100468816
exec sp_execute 56,‘2020-03-20 12:30:52.730’,100031066,100031153,100468798