Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trigger problem

Status
Not open for further replies.

cyberant

Programmer
Sep 21, 2003
44
ZA
Hi everyone

I'm busy working on a bit of a legacy application whose database tables get their unique values for thier primary key's via triggers and generators rather than using the "generator" property in the IBX query component.

I'm having the problem whereby I insert a record within my application yet it gives me an error that I have not inserted a value for my primary key... but I do have my trigger set up to insert a value into the primary key of the table before an insert(I've been through it a hundred times). What I do to get around it is I simply enter any old value into the primary key, I then post the record and any changes to the database (apply updates with cached updates activated). When I view my data grid it shows the bogus primary ID value I entered yet when I close the application and re-open it I see the intended value from the generator in the primary key. I thought it was simply a database refresh problem, but no amount of refreshing from database seems to help. The only thing that works is if I close my query and then re-open it, that seems to sort my problem out but then my table position is zonked.

Any ideas what the issue is? Shouldn't I see the value placed into the primary key as soon as I wish to insert a new record?
 
hi cyberant,

i would try to solve the problem with a procedure call to return the next generator value. then insert the received value in your insert statement.

 
I suppose you are working with delphi components, for the ID field use dblabel, rather then a editable component. Or in a grid make the ID read only

Regards

Steven van Els
SAvanEls@cq-link.sr
 
Hi -

AFAIK the generator field in the IBQuery component will not work in the manner you wish.

If you use the TIBDataset component query and set the Generaor field, the value should be automatically generated as soon as you post the changes.

If you are using ClientDataset components - you will need to implement the approach outlined by SamC above.

Regards..

Opp.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top