D2010, Oracle 10 & OnApplyRecord Problem

Phyllis

Member²
I am attempting to use the TOracleDataSet's OnApplyRecord method to call stored procedures for DML statements, but am having trouble.

Using the latest version of DOA, with the CachedUpdates of my TOracleDataSet = True and also when I have it = False, when I insert a record and call Session.ApplyUpdates - no commit on a child in a master/detail relationship and then call Session.ApplyUpdates with a commit on the master, I end up with 2 records inserted instead of one.

What am I doing wrong and how can I get around this problem and have it only insert the record once?
 
Thank you, Marco. That does solve my problem for the most part.

I am curious, though, as to why calling ApplyUpdates doesn't tell the dataset that they have been applied. In my case, when the user created a child record, they had the option of doing more edits or creating more children which is why I was doing the one ApplyUpdates for the child and then later calling that again for the parent. Without it running that way, I have to take some additional steps to allow the user to see the data correctly in the interim between the time the child records are created and the time the master has ApplyUpdates called. . .
 
I am curious, though, as to why calling ApplyUpdates doesn't tell the dataset that they have been applied.
Cached updates gives you control over the transaction. You can perform additional actions, additional checks, and you can subsequently call CommitUpdates, CancelUpdates, or Rollback. Therefore, until you have called CommitUpdates or CancelUpdates (or have used the Commit parameter of the ApplyUpdates procedure), the dataset state remains the same.
 
Do you have any suggestions on how I can get around this in my situation?

I need to give immediate feedback to my users when they try to create a child record that is invalid, and the code lives in the database in the insert procedure called in OnApplyRecord. So if I wait to call Session,OnApplyUpdates until they are done with all their edits and click "Save", the validation is not run until too late. That is why I was calling it after the child record is added or edited. I can't commit there because the user hasn't said they are ready, but I need to call the insert procedure. If I call OnApplyUpdates here and again when the user saves the entire set of edits, then I get the double records.

Thanks
 
If you want to use cached updates and still do early validations in the database, then it is probably a good idea to have specific stored functions to perform these validations. All data needed for the validation needs to be passed to these functions, so that it does not require that the record(s) are already present in the database.

These functions can be used from the client in a validation event in your Delphi application, and can also be used in database triggers if you additionally want to perform these validations on the database server.
 
Back
Top