 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Liz Guest
|
Posted: Wed Jul 09, 2003 2:26 pm Post subject: Nested datasets & transactions |
|
|
I have a nested client dataset. While the user is adding a new master and
associated details, everything is done in cache. When the user hits 'save',
then I need to insert the master record and its associated detail records
all in one transaction. i.e. if any of the detail records fails then I need
to roll back.
I find that the sequence of events is as follows (where CDS=ClientDataSet):
CDS_MasterDSAfterPost - Starts ...ApplyUpdates called
Prv_MasterDSBeforeApplyUpdates
Prv_MasterDSBeforeUpdateRecord (SourceDS is Master DS)
Prv_MasterDSAfterUpdateRecord
Prv_MasterDSAfterApplyUpdates
CDS_MasterDSAfterPost - Ends
CDS_MasterDSAfterPost - Starts ...ApplyUpdates called
Prv_MasterDSBeforeApplyUpdates
Prv_MasterDSBeforeUpdateRecord (SourceDS is Detail DS)
Prv_MasterDSAfterUpdateRecord
Prv_MasterDSBeforeUpdateRecord (SourceDS is Detail DS)
Prv_MasterDSAfterUpdateRecord
.... repeated for each detail record
Prv_MasterDSAfterApplyUpdates
CDS_MasterDSAfterPost - Ends
How can I easily wrap a transaction round the whole lot?
Liz
|
|
| Back to top |
|
 |
Craig Stuntz [TeamB] Guest
|
Posted: Wed Jul 09, 2003 3:16 pm Post subject: Re: Nested datasets & transactions |
|
|
Liz wrote:
| Quote: | I have a nested client dataset. While the user is adding a new master
and associated details, everything is done in cache. When the user
hits 'save', then I need to insert the master record and its
associated detail records all in one transaction. i.e. if any of the
detail records fails then I need to roll back.
|
Pass 0 as the MaxErrors argument to CDS.ApplyUpdates and DataSnap does
the rest for you.
-Craig
--
Craig Stuntz [TeamB] . Vertex Systems Corp. . Columbus, OH
Delphi/InterBase Weblog : http://delphi.weblogs.com
Everything You Need to Know About InterBase Character Sets:
http://delphi.weblogs.com/stories/storyReader$306
|
|
| Back to top |
|
 |
Guest
|
Posted: Wed Jul 09, 2003 9:32 pm Post subject: Re: Nested datasets & transactions |
|
|
Craig,
Thanks for the prompt response.
I have passed 0 as the MaxErrors! The problem is that the nested client
dataset 'After Post' method (in which I call ApplyUpdates) gets called
twice, once for the Master dataset and once for the Detail dataset. Each
ApplyUpdates 'batch' is within a transaction. Thus, if any of the Detail
records fail, they will all be backed out BUT the master record has already
been committed and won't be backed out.
Re DataSnap, I don't know if we are using it or not - we only have D7
Professional and don't therefore have the datasnap components.
Liz
p.s. I thought I had already sent this message but as it didn't appear
assume that I must have hit 'Reply' instead of 'Reply Group'.
"Craig Stuntz [TeamB]" <cstuntz (AT) vertexsoftware (DOT) com> wrote
| Quote: | Liz wrote:
I have a nested client dataset. While the user is adding a new master
and associated details, everything is done in cache. When the user
hits 'save', then I need to insert the master record and its
associated detail records all in one transaction. i.e. if any of the
detail records fails then I need to roll back.
Pass 0 as the MaxErrors argument to CDS.ApplyUpdates and DataSnap does
the rest for you.
-Craig
--
Craig Stuntz [TeamB] . Vertex Systems Corp. . Columbus, OH
Delphi/InterBase Weblog : http://delphi.weblogs.com
Everything You Need to Know About InterBase Character Sets:
http://delphi.weblogs.com/stories/storyReader$306
|
|
|
| Back to top |
|
 |
Dave Rowntree Guest
|
Posted: Thu Jul 10, 2003 9:38 am Post subject: Re: Nested datasets & transactions |
|
|
<liz> wrote:
| Quote: | I have passed 0 as the MaxErrors! The problem is that the nested client
dataset 'After Post' method (in which I call ApplyUpdates) gets called
twice, once for the Master dataset and once for the Detail dataset.
|
Never call ApplyUpdates from a nested CDS. Just make the call from the
master CDS. All updates are channeled through the master CDS.
Also, update errors returned from the DSP relating to either the
master or the nested detail will always be surfaced in the master
CDS.OnReconcileError event, never the nested CDS.OnReconcileError
event.
--
Dave Rowntree
|
|
| Back to top |
|
 |
Liz Guest
|
Posted: Thu Jul 10, 2003 10:18 am Post subject: Re: Nested datasets & transactions |
|
|
Dave,
Thanks for your response.
You wrote -
| Quote: | Never call ApplyUpdates from a nested CDS. Just make the call from the
master CDS. All updates are channeled through the master CDS.
|
I am calling ApplyUpdates from in the AfterPost event of the master CDS,
and, as you say, all updates are being channeled through that. But, the
master CDS AfterPost is being triggered twice - once for the master ds and
then for the detail ds. This is causing ApplyUpdates to be called twice and
thus my master update and detail updates being in separate transactions.
Thus, whilst I can abort the detail update if the master update fails for
any reason, by the time one of the detail updates fails, it is too late to
abort the master update since it has already been committed.
As far as I can see, I have to do my own thing with some yukky code to
enclose the whole lot in one transaction.
| Quote: |
Also, update errors returned from the DSP relating to either the
master or the nested detail will always be surfaced in the master
CDS.OnReconcileError event, never the nested CDS.OnReconcileError
event.
|
Yep - this is indeed what is happening.
Liz
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|