Get key value after update

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
RickardEngberg
Posts: 13
Joined: Mon 12 Apr 2010 15:23

Get key value after update

Post by RickardEngberg » Tue 09 Jun 2015 16:59

Getting newest data on time

For certain situations UniDAC allows automatically refreshing records in the dataset in order to keep their values up-to-date.

With RefreshOptions you can make UniDAC refresh the current record before editing, after inserting or deleting. It is done by executing an additional query.

The DMLRefresh option allows refreshing the current record after insert or update similarly to RefreshOptions, but it works in a different way. This allows achieving higher performance than with RefreshOptions. DMLRefresh is not supported by the MySQL, SQLite, and ODBC-based providers.

If you want to control which fields of the current record need to be refreshed after insert or update, you should do the following: define in your update queries output parameters with names that correspond the field names in your dataset, and set the ReturnParams option to True. After the update query has been executed, dataset reads values of the output parameters and puts them into fields with the correspondent names.
Above is from Unidac documentation. What I'm trying to do is the last paragraph, get updated data from the proc that saves the info back to my application to be used for a detail data set.

Specifically:

I have a field in all my tables called object_id which is a uid and a primary key. All updates and inserts to each table are done by calling a proc, i.e. post_product( param, param... ); This procedure is called on Dataset.post like so:

Code: Select all

select post_product(
  :object_id, 
  :name, 
  :description, 
  :category_id, 
  :price, 
  :vat,
  :image_extension,
  :image
)
in the SQLInsert and SQLUpdate properties of the TUniQuery I use.

What I want to do is get the object_id uid that is set by the stored procedure back to the app and use it when I create detail records in a different table.

I understand from the documentation that this is done as described in the above quote. My question is, does this work at all?

I have done exactly as the documentation says, and I even followed the source code trying to understand what is done behind the scene, but I just can't get it to work. Has anyone done this successfully?

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Get key value after update

Post by AlexP » Wed 10 Jun 2015 06:13

Hello,

Please specify the DB you are using?

Post Reply