Board index » delphi » "Update Failed" With Cache Update

"Update Failed" With Cache Update

Luis de la Cruz wrote:

Quote
> I'm changing a program to use Cache Update facilities

> I have a Read Only SQL Component linked to UpdateSQL.
> I can insert records and works fine.

> But I can't update or delete records because I get an Error "Update
> Failed"

> If I run the my program in the Delphi IDE a get the same error and
> after a
> EAbort exception.

> Actually I have no code in OnUpdateError or OnUpdateRecord events.
> If I put a line of code like:
>    UpdateAction= uaApplied
>  in the OnUpdateRecord event, I don't get the error message "Update
> Failed", but the
> the records modified don't change in the database

> Actually I use the Database's ApplyUpdate method.

> Somebody help me.

> Thanks

Welcome to the problem! I have broken my head against this for three
days and finally figured out the reason. But, I don't have a good
solution yet, just workarounds!

For the TUpdateSQL to work with the modified values, you probably have
something like Query.Edit, then set your new values and do Query.Post.
This posts to the cache, but not to the database.  Then when you call
ApplyUpdates it gives the "Update Failed" error.

Seems like the reason is that there is a mix of BDE functions
(Query.Edit and Query.Post) along with an explicit SQL transaction,
because the ApplyUpdates method opens a transaction. The easiest
solution would be to have RequestLive as True (if you can) and set
Cached Updates to False and let BDE take care of the posting.

But, if your SQL statement will not return a live result set, then don't
use TUpdateSQL. Instead, use another seperate query for modifying the
record and painfully set each parameter manually and then call
NewQuery.ExecSQL within a transaction. This works, but it kills the
advantage of UpdateSQL which is setting the value of the fields
implicitly.

If anybody can help on how to set the values for TUpdateSQL without
calling Edit, it will be a great help. Borland???????????

Gowri Subramanian
Aspire Systems, Inc.
http://www.aspiresys.com
CONSULTANTS FOR:  VB, PowerBuilder, Delphi, Oracle, Informix, Java,
Intranet and Client/Server

 

Re:"Update Failed" With Cache Update


Quote
>If anybody can help on how to set the values for TUpdateSQL without
>calling Edit, it will be a great help. Borland???????????

If you're using a TUpdateSQL object within, say, an OnUpdateRecord, the
way to get those Params set is this way, which D3 has in its help for
SetParams:

    with DataSet.UpdateObject as TUpdateSQL do
    begin
      SetParams(UpdateKind);
      if UpdateKind = ukModified then
        Query[UpdateKind].ParamByName('DateChanged').Value := Now;
      ExecSQL(UpdateKind);
    end;
    UpdateAction := uaApplied;

Works pretty well for me, but then again, I haven't tried transactions
yet :)

  --=- Ritchie Annand

Other Threads