Board index » delphi » Cached update and TTable problem - duplicate updates

Cached update and TTable problem - duplicate updates

I experience a strange behavior using TTable and cached updates.

I have a simple TTable linked to an Interbase table, I use persistent
field.
I have enabled CachedUpdates, and written an OnUpdateRecord event
handler, which looks what record is going to be updated, and either
applies the update (using a linked TUpdateObject component) or skips the
update.
The problem is, after the call to ApplyUpdates, every record replicates
and is seen twice in TTable !!!

To be more precise, I insert a new record, post it, and there is 1
record.
I call ApplyUpdates, the same record is seen twice - there are 2
records.
The record itself is written to the physical dataset just once -
reopening the TTable, or viewing the table from elsewhere, I see only
one record.

It is really scary and I cannot seem to find a workaround. For design
reason, I cannot use TQuery, which indeed works well.
I also found that if the TTable is read-only (NOT by setting its
ReadOnly property, but i.e. by using a VIEW created by a join), the
problem vanished.

Any help or insight would be GREATLY appreciated.

BTW, using Delphi 3.02 Pro, BDE 5.0, Interbase 4.2

Thanks,

Michal Bukovjan
mbukov...@netscape.net

  praguesoft.vcf
< 1K Download
 

Re:Cached update and TTable problem - duplicate updates


Michal,

What does your onUpdateRecord event handler look like?

Quote
Michal Bukovjan wrote:

> I experience a strange behavior using TTable and cached updates.

> I have a simple TTable linked to an Interbase table, I use persistent
> field.
> I have enabled CachedUpdates, and written an OnUpdateRecord event
> handler, which looks what record is going to be updated, and either
> applies the update (using a linked TUpdateObject component) or skips the
> update.
> The problem is, after the call to ApplyUpdates, every record replicates
> and is seen twice in TTable !!!

> To be more precise, I insert a new record, post it, and there is 1
> record.
> I call ApplyUpdates, the same record is seen twice - there are 2
> records.
> The record itself is written to the physical dataset just once -
> reopening the TTable, or viewing the table from elsewhere, I see only
> one record.

> It is really scary and I cannot seem to find a workaround. For design
> reason, I cannot use TQuery, which indeed works well.
> I also found that if the TTable is read-only (NOT by setting its
> ReadOnly property, but i.e. by using a VIEW created by a join), the
> problem vanished.

> Any help or insight would be GREATLY appreciated.

> BTW, using Delphi 3.02 Pro, BDE 5.0, Interbase 4.2

> Thanks,

> Michal Bukovjan
> mbukov...@netscape.net

--
Ken Bailey
Falmouth Software Works Ltd.

Re:Cached update and TTable problem - duplicate updates


Quote
Michal Bukovjan <pragues...@mbox.vol.cz> wrote:
>To be more precise, I insert a new record, post it, and there is 1
>record.
>I call ApplyUpdates, the same record is seen twice - there are 2
>records.
>The record itself is written to the physical dataset just once -
>reopening the TTable, or viewing the table from elsewhere, I see only
>one record.

First, don't post before ApplyUpdates. This is probably not the source
of the problem, but it's redundant. Cached updates will post
automatically unless you have code in OnUpdateRecord as you do. When
you use OnUpdateRecord, you must Post there (and only there) or you
must use TUpdateSQL. Since you use TUpdateSQL, you don't need to use
Post at all anywhere.

Next, make sure you say CommitUpdates after you successfully call
ApplyUpdates.

Last, in OnUpdateRecord, make sure you say UpdateAction := uaApplied
after each call to TUpdateSQL.Apply(UpdateKind). uaApplied flags the
cache record for deletion (it's no longer needed if TUpdateSQL.Apply
was successful). If you don't say uaApplied, then the record won't be
flushed from the cache when you say CommitUpdates.

HTH

Phil Cain

Re:Cached update and TTable problem - duplicate updates


Ken,

The OnUpdateRecord looks like this :

begin
  if <DatasetField>.AsString = 'Want to write this to the dataset now' then
begin
    UpdateSQL.Apply(UpdateKind);
    Action:= uaApplied;
  end else Action:= uaSkip;

However, as I found, this is of no importance. As I tested that yesterday,
there is even no need for the OnUpdateRecord handler and the problem still
persist.
I posted a quick example how to reporduce this problem in
borland.public.delphi.database.desktop

Thanks for your interest,

Michal Bukovjan

Quote
Ken Bailey wrote:
> Michal,

> What does your onUpdateRecord event handler look like?

> Michal Bukovjan wrote:

> > I experience a strange behavior using TTable and cached updates.

> > I have a simple TTable linked to an Interbase table, I use persistent
> > field.
> > I have enabled CachedUpdates, and written an OnUpdateRecord event
> > handler, which looks what record is going to be updated, and either
> > applies the update (using a linked TUpdateObject component) or skips the
> > update.
> > The problem is, after the call to ApplyUpdates, every record replicates
> > and is seen twice in TTable !!!

> > To be more precise, I insert a new record, post it, and there is 1
> > record.
> > I call ApplyUpdates, the same record is seen twice - there are 2
> > records.
> > The record itself is written to the physical dataset just once -
> > reopening the TTable, or viewing the table from elsewhere, I see only
> > one record.

> > It is really scary and I cannot seem to find a workaround. For design
> > reason, I cannot use TQuery, which indeed works well.
> > I also found that if the TTable is read-only (NOT by setting its
> > ReadOnly property, but i.e. by using a VIEW created by a join), the
> > problem vanished.

> > Any help or insight would be GREATLY appreciated.

> > BTW, using Delphi 3.02 Pro, BDE 5.0, Interbase 4.2

> > Thanks,

> > Michal Bukovjan
> > mbukov...@netscape.net

> --
> Ken Bailey
> Falmouth Software Works Ltd.

  praguesoft.vcf
< 1K Download

Re:Cached update and TTable problem - duplicate updates


Quote
Philip Cain wrote:
> Michal Bukovjan <pragues...@mbox.vol.cz> wrote:

> >To be more precise, I insert a new record, post it, and there is 1
> >record.
> >I call ApplyUpdates, the same record is seen twice - there are 2
> >records.
> >The record itself is written to the physical dataset just once -
> >reopening the TTable, or viewing the table from elsewhere, I see only
> >one record.

> First, don't post before ApplyUpdates. This is probably not the source
> of the problem, but it's redundant. Cached updates will post
> automatically unless you have code in OnUpdateRecord as you do. When
> you use OnUpdateRecord, you must Post there (and only there) or you
> must use TUpdateSQL. Since you use TUpdateSQL, you don't need to use
> Post at all anywhere.

Philip,

Well, I actually have to post a record. I don't want to write a record to
the database right after it is posted (then I would have not used the
CachedUpdates, since the table is actually live). I rather need to hold
new/changed/deleted record in the dataset and let the user choose which
record changes / additions to actually post.

Quote

> Next, make sure you say CommitUpdates after you successfully call
> ApplyUpdates.

I  use TDatabase.ApplyUpdates, which commits for me.

Quote

> Last, in OnUpdateRecord, make sure you say UpdateAction := uaApplied
> after each call to TUpdateSQL.Apply(UpdateKind). uaApplied flags the
> cache record for deletion (it's no longer needed if TUpdateSQL.Apply
> was successful). If you don't say uaApplied, then the record won't be
> flushed from the cache when you say CommitUpdates.

It is there.

Look at the other newsgroup (borland.public.delphi.database.desktop) , I
posted an example how to reproduce there. The problem, as I realized when
dwelving further into that, is much more simple and therefore more scary -
there even doesn't have to be a handler ! It occurs when adding a record
OR modifying a field in a record which is a part of primary key.

Thanks for your interest,

Michal Bukovjan

  praguesoft.vcf
< 1K Download

Re:Cached update and TTable problem - duplicate updates


Michal,

You should be getting the event if cached updates is true. Take a look
at DBTables.

Try this (overill):

1) Assign your event handler.
2) Create an event handler for OnUpdateError - just a showmessage.
3) Assign the updateObject.
4) In the AfterOpen event of the TTable, put in a showmessage showing
the state of cachedupdates.

Try it and see if you get an event.

As an aside, why do you want to use cached updates?

Quote
Michal Bukovjan wrote:

> Ken,

> The OnUpdateRecord looks like this :

> begin
>   if <DatasetField>.AsString = 'Want to write this to the dataset now' then
> begin
>     UpdateSQL.Apply(UpdateKind);
>     Action:= uaApplied;
>   end else Action:= uaSkip;

> However, as I found, this is of no importance. As I tested that yesterday,
> there is even no need for the OnUpdateRecord handler and the problem still
> persist.
> I posted a quick example how to reporduce this problem in
> borland.public.delphi.database.desktop

> Thanks for your interest,

> Michal Bukovjan

> Ken Bailey wrote:

> > Michal,

> > What does your onUpdateRecord event handler look like?

> > Michal Bukovjan wrote:

> > > I experience a strange behavior using TTable and cached updates.

> > > I have a simple TTable linked to an Interbase table, I use persistent
> > > field.
> > > I have enabled CachedUpdates, and written an OnUpdateRecord event
> > > handler, which looks what record is going to be updated, and either
> > > applies the update (using a linked TUpdateObject component) or skips the
> > > update.
> > > The problem is, after the call to ApplyUpdates, every record replicates
> > > and is seen twice in TTable !!!

> > > To be more precise, I insert a new record, post it, and there is 1
> > > record.
> > > I call ApplyUpdates, the same record is seen twice - there are 2
> > > records.
> > > The record itself is written to the physical dataset just once -
> > > reopening the TTable, or viewing the table from elsewhere, I see only
> > > one record.

> > > It is really scary and I cannot seem to find a workaround. For design
> > > reason, I cannot use TQuery, which indeed works well.
> > > I also found that if the TTable is read-only (NOT by setting its
> > > ReadOnly property, but i.e. by using a VIEW created by a join), the
> > > problem vanished.

> > > Any help or insight would be GREATLY appreciated.

> > > BTW, using Delphi 3.02 Pro, BDE 5.0, Interbase 4.2

> > > Thanks,

> > > Michal Bukovjan
> > > mbukov...@netscape.net

> > --
> > Ken Bailey
> > Falmouth Software Works Ltd.

--
Ken Bailey
Falmouth Software Works Ltd.

Re:Cached update and TTable problem - duplicate updates


Ken,

I actually get the event. TTable / Delphi behaves right, because when the
OnUpdateRecord event is assigned, the implicit update through linked TUpdateObject
won't occur and I have to call TUpdateObject.Apply(TUpdateKind) myself.

This works - whether there is an event or not, the records are updated (if I call
the Apply for TUpdaeSQL).
After applying updates, though, the records that were added or records whose
primary key fields were modified show up twice in the TTable (actually, in the
grid linked - this may be a TDBGrid bug after all... I'll check that right away
but it's improbable).
When I reopen the TTable, the same records are seen just once, which should be if
there were not for the bug in BDE or Delphi. (I guess).

I need to use TTable with cached updates because I have to let the user decide
which changed records actually write to the database and which should be just left
as is, or allow the user to just cancel the changes if he wishes so.

Normally, I would have used TQuery because TQuery works well with cached updates,
however, there is master - detail relationship, and if changes are made to detail
records, and the detail is TQuery, changing the master record will re-open the
TQuery which discards any changes made. TTable uses some internal ranges, and no
matter how the master changes, the detail changes remain intact, which is the
behavior I need..

As an example, I can use Database Exlorer
Master table - List of tables
Detail table - List of fields in tables

If I changed field definition in table 1 (it would turn green), then, before
applying, switched to table 2 and back to table 1, changes I made would be lost if
TQuery was used. If using TTable, changes are still there..

Thanks for your time,

Michal Bukovjan

Quote
Ken Bailey wrote:
> Michal,

> You should be getting the event if cached updates is true. Take a look
> at DBTables.

> Try this (overill):

> 1) Assign your event handler.
> 2) Create an event handler for OnUpdateError - just a showmessage.
> 3) Assign the updateObject.
> 4) In the AfterOpen event of the TTable, put in a showmessage showing
> the state of cachedupdates.

> Try it and see if you get an event.

> As an aside, why do you want to use cached updates?

> Michal Bukovjan wrote:

> > Ken,

> > The OnUpdateRecord looks like this :

> > begin
> >   if <DatasetField>.AsString = 'Want to write this to the dataset now' then
> > begin
> >     UpdateSQL.Apply(UpdateKind);
> >     Action:= uaApplied;
> >   end else Action:= uaSkip;

> > However, as I found, this is of no importance. As I tested that yesterday,
> > there is even no need for the OnUpdateRecord handler and the problem still
> > persist.
> > I posted a quick example how to reporduce this problem in
> > borland.public.delphi.database.desktop

> > Thanks for your interest,

> > Michal Bukovjan

> > Ken Bailey wrote:

> > > Michal,

> > > What does your onUpdateRecord event handler look like?

> > > Michal Bukovjan wrote:

> > > > I experience a strange behavior using TTable and cached updates.

> > > > I have a simple TTable linked to an Interbase table, I use persistent
> > > > field.
> > > > I have enabled CachedUpdates, and written an OnUpdateRecord event
> > > > handler, which looks what record is going to be updated, and either
> > > > applies the update (using a linked TUpdateObject component) or skips the
> > > > update.
> > > > The problem is, after the call to ApplyUpdates, every record replicates
> > > > and is seen twice in TTable !!!

> --
> Ken Bailey
> Falmouth Software Works Ltd.

  praguesoft.vcf
< 1K Download

Re:Cached update and TTable problem - duplicate updates


Michal,

You can use TQuery's with filtering to perform the master/detail. In the
master tables datasource OnChange event dop something like this:

  if (field = nil) then
  begin
    sFilter := {define the filter here}
    if sFilter <> detaildataset.Filter then
    begin
      detaildataset.Filter := sFilter;
      Filtered := True;
    end;
  end;

For example, in an order processing environment, you could have a master
query that selected all the orders for a particular customer. The detail
query would select all the line items from all the orders for that
customer. The filter would then be on order #.

Quote
Michal Bukovjan wrote:

> Ken,

> I actually get the event. TTable / Delphi behaves right, because when the
> OnUpdateRecord event is assigned, the implicit update through linked TUpdateObject
> won't occur and I have to call TUpdateObject.Apply(TUpdateKind) myself.

> This works - whether there is an event or not, the records are updated (if I call
> the Apply for TUpdaeSQL).
> After applying updates, though, the records that were added or records whose
> primary key fields were modified show up twice in the TTable (actually, in the
> grid linked - this may be a TDBGrid bug after all... I'll check that right away
> but it's improbable).
> When I reopen the TTable, the same records are seen just once, which should be if
> there were not for the bug in BDE or Delphi. (I guess).

> I need to use TTable with cached updates because I have to let the user decide
> which changed records actually write to the database and which should be just left
> as is, or allow the user to just cancel the changes if he wishes so.

> Normally, I would have used TQuery because TQuery works well with cached updates,
> however, there is master - detail relationship, and if changes are made to detail
> records, and the detail is TQuery, changing the master record will re-open the
> TQuery which discards any changes made. TTable uses some internal ranges, and no
> matter how the master changes, the detail changes remain intact, which is the
> behavior I need..

> As an example, I can use Database Exlorer
> Master table - List of tables
> Detail table - List of fields in tables

> If I changed field definition in table 1 (it would turn green), then, before
> applying, switched to table 2 and back to table 1, changes I made would be lost if
> TQuery was used. If using TTable, changes are still there..

> Thanks for your time,

> Michal Bukovjan

> Ken Bailey wrote:

> > Michal,

> > You should be getting the event if cached updates is true. Take a look
> > at DBTables.

> > Try this (overill):

> > 1) Assign your event handler.
> > 2) Create an event handler for OnUpdateError - just a showmessage.
> > 3) Assign the updateObject.
> > 4) In the AfterOpen event of the TTable, put in a showmessage showing
> > the state of cachedupdates.

> > Try it and see if you get an event.

> > As an aside, why do you want to use cached updates?

> > Michal Bukovjan wrote:

> > > Ken,

> > > The OnUpdateRecord looks like this :

> > > begin
> > >   if <DatasetField>.AsString = 'Want to write this to the dataset now' then
> > > begin
> > >     UpdateSQL.Apply(UpdateKind);
> > >     Action:= uaApplied;
> > >   end else Action:= uaSkip;

> > > However, as I found, this is of no importance. As I tested that yesterday,
> > > there is even no need for the OnUpdateRecord handler and the problem still
> > > persist.
> > > I posted a quick example how to reporduce this problem in
> > > borland.public.delphi.database.desktop

> > > Thanks for your interest,

> > > Michal Bukovjan

> > > Ken Bailey wrote:

> > > > Michal,

> > > > What does your onUpdateRecord event handler look like?

> > > > Michal Bukovjan wrote:

> > > > > I experience a strange behavior using TTable and cached updates.

> > > > > I have a simple TTable linked to an Interbase table, I use persistent
> > > > > field.
> > > > > I have enabled CachedUpdates, and written an OnUpdateRecord event
> > > > > handler, which looks what record is going to be updated, and either
> > > > > applies the update (using a linked TUpdateObject component) or skips the
> > > > > update.
> > > > > The problem is, after the call to ApplyUpdates, every record replicates
> > > > > and is seen twice in TTable !!!

> > --
> > Ken Bailey
> > Falmouth Software Works Ltd.

--
Ken Bailey
Falmouth Software Works Ltd.

Re:Cached update and TTable problem - duplicate updates


Re:Cached update and TTable problem - duplicate updates


Actually, this might really solve my problem... As I do not use filter in Detail tables,
this looks like a feasuble solution !

I'll try this right away...

Thanks a lot !

Michal Bukovjan

Quote
Ken Bailey wrote:
> Michal,

> You can use TQuery's with filtering to perform the master/detail. In the
> master tables datasource OnChange event dop something like this:

>   if (field = nil) then
>   begin
>     sFilter := {define the filter here}
>     if sFilter <> detaildataset.Filter then
>     begin
>       detaildataset.Filter := sFilter;
>       Filtered := True;
>     end;
>   end;

> For example, in an order processing environment, you could have a master
> query that selected all the orders for a particular customer. The detail
> query would select all the line items from all the orders for that
> customer. The filter would then be on order #.

> Michal Bukovjan wrote:

> > Ken,

> > I actually get the event. TTable / Delphi behaves right, because when the
> > OnUpdateRecord event is assigned, the implicit update through linked TUpdateObject
> > won't occur and I have to call TUpdateObject.Apply(TUpdateKind) myself.

> > This works - whether there is an event or not, the records are updated (if I call
> > the Apply for TUpdaeSQL).
> > After applying updates, though, the records that were added or records whose
> > primary key fields were modified show up twice in the TTable (actually, in the
> > grid linked - this may be a TDBGrid bug after all... I'll check that right away
> > but it's improbable).
> > When I reopen the TTable, the same records are seen just once, which should be if
> > there were not for the bug in BDE or Delphi. (I guess).

> > I need to use TTable with cached updates because I have to let the user decide
> > which changed records actually write to the database and which should be just left
> > as is, or allow the user to just cancel the changes if he wishes so.

> > Normally, I would have used TQuery because TQuery works well with cached updates,
> > however, there is master - detail relationship, and if changes are made to detail
> > records, and the detail is TQuery, changing the master record will re-open the
> > TQuery which discards any changes made. TTable uses some internal ranges, and no
> > matter how the master changes, the detail changes remain intact, which is the
> > behavior I need..

> > As an example, I can use Database Exlorer
> > Master table - List of tables
> > Detail table - List of fields in tables

> > If I changed field definition in table 1 (it would turn green), then, before
> > applying, switched to table 2 and back to table 1, changes I made would be lost if
> > TQuery was used. If using TTable, changes are still there..

> > Thanks for your time,

> > Michal Bukovjan

> > Ken Bailey wrote:

> > > Michal,

> > > You should be getting the event if cached updates is true. Take a look
> > > at DBTables.

> > > Try this (overill):

> > > 1) Assign your event handler.
> > > 2) Create an event handler for OnUpdateError - just a showmessage.
> > > 3) Assign the updateObject.
> > > 4) In the AfterOpen event of the TTable, put in a showmessage showing
> > > the state of cachedupdates.

> > > Try it and see if you get an event.

> > > As an aside, why do you want to use cached updates?

> > > Michal Bukovjan wrote:

> > > > Ken,

> > > > The OnUpdateRecord looks like this :

> > > > begin
> > > >   if <DatasetField>.AsString = 'Want to write this to the dataset now' then
> > > > begin
> > > >     UpdateSQL.Apply(UpdateKind);
> > > >     Action:= uaApplied;
> > > >   end else Action:= uaSkip;

> > > > However, as I found, this is of no importance. As I tested that yesterday,
> > > > there is even no need for the OnUpdateRecord handler and the problem still
> > > > persist.
> > > > I posted a quick example how to reporduce this problem in
> > > > borland.public.delphi.database.desktop

> > > > Thanks for your interest,

> > > > Michal Bukovjan

> > > > Ken Bailey wrote:

> > > > > Michal,

> > > > > What does your onUpdateRecord event handler look like?

> > > > > Michal Bukovjan wrote:

> > > > > > I experience a strange behavior using TTable and cached updates.

> > > > > > I have a simple TTable linked to an Interbase table, I use persistent
> > > > > > field.
> > > > > > I have enabled CachedUpdates, and written an OnUpdateRecord event
> > > > > > handler, which looks what record is going to be updated, and either
> > > > > > applies the update (using a linked TUpdateObject component) or skips the
> > > > > > update.
> > > > > > The problem is, after the call to ApplyUpdates, every record replicates
> > > > > > and is seen twice in TTable !!!

> > > --
> > > Ken Bailey
> > > Falmouth Software Works Ltd.

> --
> Ken Bailey
> Falmouth Software Works Ltd.

  praguesoft.vcf
< 1K Download

Re:Cached update and TTable problem - duplicate updates


Re:Cached update and TTable problem - duplicate updates


Take a look at the VCL source for TDatabase.ApplyUpdates.  Unless a horrible
exeption is raised during the apply, CommitUpdates will in fact be called
for each dataset.  In TBDEDataSet.CachedUpdateCallBack, EDatabaseErrors are
sent to OnUpdateError, and other exceptions are dispatched directly to the
application exception handler, so exceptions the bubble all the way up to
TDatabase.ApplyUpdates should be very rare.

V/R
Russell L. Smith

Quote
Philip Cain wrote in message <365673fe.2762...@forums.borland.com>...
>Michal Bukovjan <pragues...@mbox.vol.cz> wrote:
>>I  use TDatabase.ApplyUpdates, which commits for me.

>ApplyUpdates Posts and commits the data changes to the database, but
>it does not get rid of the records in the cache. To clean out the
>cache after you ApplyUpdates, you must CommitUpdates.

Re:Cached update and TTable problem - duplicate updates


Posting before calling ApplyUpdates is harmless.  Here is the VCL source for
TBDEDataSet.ApplyUpdates, which is either called directly, or from
TDatabase.ApplyUpdates.  Note that it will post if necessary, but will do
nothing if the dataset state is already dsBrowse.  This behavior is
independent of whether an OnUpdateRecord event handler exists.

  procedure TBDEDataSet.ApplyUpdates;
  var
    Status: DBIResult;
  begin
    if State <> dsBrowse then Post;
    Status := ProcessUpdates(dbiDelayedUpdPrepare);
    if Status <> DBIERR_NONE then
      if Status = DBIERR_UPDATEABORT then SysUtils.Abort
      else DbiError(Status);
  end;

Perhaps there is a terminology mismatch with "post".  When a dataset is in
cached updates mode, the Post method will write the current record's update
buffer to the dataset.  Post will not do anything unless the dataset state
is dsEdit or dsInsert (which reflects the state of only the current record).
Post will NEVER write anything to the database when the dataset is in cached
updates mode.

V/R
Russell L. Smith

Quote
Philip Cain wrote in message <365047b9.2122...@forums.borland.com>...
>First, don't post before ApplyUpdates. This is probably not the source
>of the problem, but it's redundant. Cached updates will post
>automatically unless you have code in OnUpdateRecord as you do. When
>you use OnUpdateRecord, you must Post there (and only there) or you
>must use TUpdateSQL. Since you use TUpdateSQL, you don't need to use
>Post at all anywhere.

Re:Cached update and TTable problem - duplicate updates


Of course, you can intentionally uaAbort the update...

V/R
Russell L. Smith

Quote
Russell L. Smith wrote in message <7303gj$p...@forums.borland.com>...
>application exception handler, so exceptions the bubble all the way up to
>TDatabase.ApplyUpdates should be very rare.

Re:Cached update and TTable problem - duplicate updates


Quote
Michal Bukovjan <pragues...@mbox.vol.cz> wrote:
>The OnUpdateRecord looks like this :

>begin
>  if <DatasetField>.AsString = 'Want to write this to the dataset now' then
>begin
>    UpdateSQL.Apply(UpdateKind);
>    Action:= uaApplied;
>  end else Action:= uaSkip;

There are a couple of problems here.

First of all, the value being updated is NOT <DatasetField>.AsString.
Cached updates doesn't look at that value. The data that cached
updates uses is <DatasetField>.NewValue. The value you refer to in
your code has no meaning to cached updates and it is almost never the
value of the record that is going to be updated.

You are using uaApplied correctly. That is, if the change is applied,
uaApplied flags the cached record for deletion - it's no longer
needed.

But there may be a problem with uaSkip, which tells cached updates to
leave the record in the cache, even after you call CommitUpdates.

The problem is this. Not all the records that are in your dataset show
up in OnUpdateRecord, so you don't have to account for all of them.
The only records that show up in OnUpdateRecord are the one's you've
changed - the ones in the cache. The other records in your dataset are
ignored. So if you skip one, you are telling Delphi that you don't
want to update that record yet. Instead, you say, leave it in the
cache, do not change the database, and when I display this record
next, show the cached version and not the version in the database. If
that's what you want, then you have used uaSkip properly. If not, then
you have a problem.

Phil Cain

Go to page: [1] [2]

Other Threads