Page 1 of 1

Refreshing a dataset after insert via SQLInsert of a TUniQue

Posted: Wed 27 Jul 2011 16:23
by RickardEngberg
I am using TUniQuery to handle data updating and viewing on a PostgreSQL database. This is what I do:

1. Populate a grid using select * from client_v where client_v is a view. This is all in the SQL property of the TUniQuery.
2. Open the Query (qry.Open).
3. Appends a record to it (qry.Append).
4. Posts it (qry.Post)

So far all is fairly well. But as this is in a editing dialog box which remain open after to post, I would like to refresh the data and go from my Insert mode to Edit mode in the dialog box. Some values will also have changed as I use i procedure in SQLInsert to actually store the data. I have used this hundres of times before, but only now I need to get the data from the procedure back. Or at least the newly created client record.

So I have googled the net, searched this forum and although I can find similar cases, I can't find any examples that helps me out.

The SQL property looks likes a bit like

Code: Select all

select *
from kund_v
where kund_id = :id -- :id holds the value I pass in. For inserts I use -1 or null
The SQLInsert property looks like

Code: Select all

select knd_kund_spara (
	:kund_id,   -- This is an OUTPUT parameter
	:kundnr,
	:foralder_id,
	:organisationsnummer,
	:betalningsvillkor,
	:betalningstyp,
...
);
The SQLRefresh is

Code: Select all

select *
from kund_v
where kund_id = :kund_id
Notable is that the actual parameters of the knd_kund_spara is not named as the fields of the view. They (the parameters of the proc) is prefixed with p_

I have labbed with different parameter names for :kund_id to no success. I have tried creating it and adding it to the params list in BeforeUpdateExecute and tried to read it in the AfterUpdateExecute, but not succeeded.

I'd be happy to use AfterUpdateExecute in some way, or add some generic code, but I'd be reluctant to handle the whole update process manually since I use inherited forms to add generic functionality at a base level. I have a lot of these updaters to write...

Actually, the best thing would be to be able to get the output parameter value of :kund_id in the AfterUpdateExecute event.

Anyone? Perhaps just explain to me how the mechanics behind this works.

Thanks in advance

Posted: Thu 28 Jul 2011 13:09
by AlexP
Hello,

Please send the scripts for creating the tables, view, and function to alexp*devart*com, or explain what you are doing in your function in more details – if you get kund_id from the sequence in the table or some other way. Also you may try to use the DefaultExpression property of the TuniQuery fields for filling and getting field values when inserting a new record. You can learn more about this property in the UniDAC help, the TDADataSetOptions.DefaultValues Property topic.