Subject Re: Primary Key of Query set by Trigger
Author frank_ingermann
Hallo Dieter,

As Set pointed out, you need to know the value on the client side
*before* the insert to ever find it back safely. So what you could
do is put the code in your trigger that builds the BELEGNR into a
storedproc.

change your trigger to select the value from the sp when it's null.

then, instead of using AfterPost (GER: da ist das kind schon in den
Brunnen gefallen! sorry don't know this in english :), you can
do something like

procedure Tfrm_Belege.qry_FormBeforePost(IB_Dataset: TIB_Dataset);
var { ^^^^^^ }
begin
with IB_DataSet do
if FieldByName('BELEGNR').IsNull then
begin
with qryGetBelegnummer do
// this should have SELECT * FROM SP_GetBelegnummer in it
begin
Prepare;
Open;
IB_DataSet.FieldByName('BELEGNR').AsInteger :=
qryGetBelegnummer.Fields[0].AsInteger;
Close;
end;
end;

This way you still have an "atomic place" -> the sp where the
number is assembled, used both by the app and (if necessary) the
trigger.

regards & hth,
fingerman


Dieter Tremel schrieb:
> I have a TIB_Query in a Form the user uses to insert end edit
Records.
> Since I have a 2 field PK of which 1 field is set by a trigger it is
> difficult for me to show the actual record after insert. I set
> BufferSyncroFlags to [bsAfterEdit,bsAfterInsert], but this doesn't
> help for Inserts. I tried
>
> procedure Tfrm_Belege.qry_FormAfterPost(IB_Dataset: TIB_Dataset);
> var
> bmark: string;
> begin
> inherited;
> with IB_DataSet do
> if FieldByName('BELEGNR').IsNull then begin
> bmark := Bookmark;
> Refresh;
> Bookmark := bmark;
> end;
> end;
> but this doesn't work also.
>
> I guess because it is the Primary key that is given by the server.
But
> I like to use the trigger to have an atomic operation for creation
of
> the PK.