Subject Re: [IBO] InsertSQL question
Author Helen Borrie (TeamIBO)
At 12:33 AM 07-03-02 +0000, Eric Handbury wrote:

>Helen,
> I guess I should have been more specific. I want to populate the
>new record with values from another table when the user hits the '+'
>button on the TIB_UpdateBar. So rather than giving the users blank
>fields, the user will see the populated data. Would a Insert trigger
>work better here?

No, because you want the users to see the derived data. Triggers don't
fire until the record is posted, so that is too late. And, of course,
OnPost is far too late.

To pick up that row of values derived from another record, again it is
simple. If the data are already present in your application, just apply
them to the relevant columns of the Fields[] array in your AfterInsert. It
sounds as if you want to pull it fresh from the database - but, again, the
solution is pretty clean and simple.

Drop a TIB_Cursor into your datamodule, keeping it within the same
transaction as your main dataset. This is to ensure consistency of the
data during the user input phase of the task...you can pessimistically lock
the row, too, if necessary, by using a sel. SP that includes a dummy update
following the block that fetches the dataset...if consistency is not an
issue but concurrency is, you can close the cursor as soon as you have its
data.

You can use this regardless of whether you are using the TIBO* or TIB_*
components for your main project. This cursor comp. can call (via its SQL
property) either a selectable stored procedure or a SELECTed dataset,
according to your requirements. Make quite certain that you pass
sufficient parameters to it, to ensure that you will get one and only one
row back in the dataset.

The timing (i.e. event) of the handler depends on the parameters you need
to pass. There is not yet enough information in this thread to determine
what selects the extracted data that go into the new record.


regards,
Helen Borrie (TeamIBO Support)

** Please don't email your support questions privately **
Ask on the list and everyone benefits
Don't forget the IB Objects online FAQ - link from any page at
www.ibobjects.com