Board index » off-topic » Understanding poCascadeDeletes

Understanding poCascadeDeletes


2005-05-24 03:37:12 AM
off-topic8
I have some nested datasets using ClientDataSets. When I delete the master
record I want the detail to be deleted as well. I would have thought setting
the poCascadeDelete's option on the provider would do this but it doesn't
seem to. Looking at some other posts I see where people are doing this
manually in the beforeApplyUpdates Event.
Despite these other posts, they don't explicitly state how poCascadeDeletes
is supposed to work. Can someone do that?
 
 

Re:Understanding poCascadeDeletes

Cascading Deletes is a feature of some Databases(I've seen it in Access
and SQLServer).
AFAIK datasnap will just disable its own 'can this record be deleted?
'-checks and let the database itself handle everything.
Preston schrieb:
Quote
I have some nested datasets using ClientDataSets. When I delete the master
record I want the detail to be deleted as well. I would have thought setting
the poCascadeDelete's option on the provider would do this but it doesn't
seem to. Looking at some other posts I see where people are doing this
manually in the beforeApplyUpdates Event.

Despite these other posts, they don't explicitly state how poCascadeDeletes
is supposed to work. Can someone do that?



 

Re:Understanding poCascadeDeletes

poCascadeDeletes tells the server to delete detail records
automatically when master table records are deleted. To use this
option, the provider must represent the master of a master/detail
relationship and the database must support cascaded deletes as part of
its referential integrity settings.
--
Bill Todd (TeamB)
 

{smallsort}

Re:Understanding poCascadeDeletes

I think if you use a standard master detail relationship (not nested)
deleteting the detail works fine.Do nested clientDataSets not do the same
thing?
I'm using Sybase which supports cascading deletes but it requires me to set
up the foriegn key. If I set the key up how does Delphi override that
setting. If I set poCascadeDeletes to false won't the DB still cascade
deletes? If key is not set up how does Delphi get the delete to cascade?
"Bill Todd" < XXXX@XXXXX.COM >wrote in message
Quote
poCascadeDeletes tells the server to delete detail records
automatically when master table records are deleted. To use this
option, the provider must represent the master of a master/detail
relationship and the database must support cascaded deletes as part of
its referential integrity settings.

--
Bill Todd (TeamB)

 

Re:Understanding poCascadeDeletes

Preston wrote:
Quote
I think if you use a standard master detail relationship (not nested)
deleteting the detail works fine.Do nested clientDataSets not do the same
thing?
When you define a foreign key in the database you have some options
(either to cascade, set null, set default or NoAction-called restrict in
some cases- I don't how sybase calls that). If you choose cascade
deletes, then you should choose poCascadeDeletes=True. If you choose No
Action (Restrict) then you should choose poCascadeDeletes=False. It
depends on business logic.
Quote

I'm using Sybase which supports cascading deletes but it requires me to set
up the foriegn key. If I set the key up how does Delphi override that
setting. If I set poCascadeDeletes to false won't the DB still cascade
deletes?
No, because it won't let you delete a master record in client side at
first place.
If key is not set up how does Delphi get the delete to cascade?
It doesn't.
 

Re:Understanding poCascadeDeletes

As Kostas said, poCascadeDeletes is a way to tell the DSP that the
server will take care of deleting the detail records when a master is
deleted.
--
Bill Todd (TeamB)
 

Re:Understanding poCascadeDeletes

Quote
No, because it won't let you delete a master record in client side at
first place.
Are you saying the provide would prevent me from deleting the master record
if it contained detail records?
 

Re:Understanding poCascadeDeletes

Preston wrote:
Quote
Are you saying the provide would prevent me from deleting the master record
if it contained detail records?


Yes, just try it.
 

Re:Understanding poCascadeDeletes

Thanks to both of you for being patient and explaing this :-)
Delphi supports deleting detail records if you use a master detail
relationship, foreign key on the BD or not. I don't understand why
clientDataSets would be any different.
I read someone's article in the Borland community that said if you're
writing a lot of code to deal with the database then your doing it wrong. If
I understand things correctly, I have two options when using nested
datasets.
1. I manually delete the records myself in the BeforeRecordUpdate event.
This feels wrong ;)
2. I create a foreign key that with cascade deletes enabled.
Am I correct in this?
"Bill Todd" < XXXX@XXXXX.COM >wrote in message
Quote
As Kostas said, poCascadeDeletes is a way to tell the DSP that the
server will take care of deleting the detail records when a master is
deleted.

--
Bill Todd (TeamB)
 

Re:Understanding poCascadeDeletes

Yes.
--
Bill Todd (TeamB)
Preston wrote:
Quote
Am I correct in this?
 

Re:Understanding poCascadeDeletes

Quote
Delphi supports deleting detail records if you use a master detail
relationship, foreign key on the BD or not.
AFAIK that's wrong. Tell us an example of how can that be done (without
having a foreign key defined)
Quote
If I understand things correctly, I have two options when using nested
datasets.

1. I manually delete the records myself in the BeforeRecordUpdate event.
This feels wrong ;)
2. I create a foreign key that with cascade deletes enabled.

Am I correct in this?
IMO, only option 2 is ok (if database supports it).
Option 1 is very tricky and should only be an option in case the back
end database doesn't support cascade deletes (the code would easily
become very complicated in case the detail table represents the master
table of another one, IOW if you have multiple levels of nested datasets)