Subject | Re: [IBO] Stored Procedure or Trigger |
---|---|
Author | Helen Borrie |
Post date | 2001-03-22T13:46:31Z |
At 01:54 PM 22-03-01 +0100, you wrote:
It is also advisable to have a trigger, to ensure that inserts made outside of your IBO application (e.g. through IB_WISQL or IBConsole) will properly get the generator value, viz.
CREATE TRIGGER GEN_ID_FOR_ATABLE AS
BEGIN
IF ((NEW.ID IS NULL) OR (NEW.ID=0) THEN
NEW.ID = GEN_ID(GEN_ATABLE_ID, 1);
END
If you want the trigger to fire, in preference to having IBO take care of it before Post time, then you will need to omit the ID column from your InsertSQL, i.e. add an INSERT statement to the dataset's InsertSQL property than does not include that column in the field list. Alternatively, you can set the column's REQUIRED attribute to be False. Just be sure your client app does not provide edit access to the ID column in the new row.
Don't use a stored procedure.
Cheers,
Helen
All for Open and Open for All
InterBase Developer Initiative ยท http://www.interbase2000.org
_______________________________________________________
>HEY AllIn IBO, the best approach is to set the GeneratorLinks property, which encapsulates the generation of the row ID for you.
>
>I'm a newbie just starting to use InterBase and IB Objects
>
>And now I have a question, which I hope you can advise me on.
>
>When adding records to a table, what approch works best, to get the next
>record ID-number:
>
>Using a stored procedure or a trigger.
It is also advisable to have a trigger, to ensure that inserts made outside of your IBO application (e.g. through IB_WISQL or IBConsole) will properly get the generator value, viz.
CREATE TRIGGER GEN_ID_FOR_ATABLE AS
BEGIN
IF ((NEW.ID IS NULL) OR (NEW.ID=0) THEN
NEW.ID = GEN_ID(GEN_ATABLE_ID, 1);
END
If you want the trigger to fire, in preference to having IBO take care of it before Post time, then you will need to omit the ID column from your InsertSQL, i.e. add an INSERT statement to the dataset's InsertSQL property than does not include that column in the field list. Alternatively, you can set the column's REQUIRED attribute to be False. Just be sure your client app does not provide edit access to the ID column in the new row.
Don't use a stored procedure.
Cheers,
Helen
All for Open and Open for All
InterBase Developer Initiative ยท http://www.interbase2000.org
_______________________________________________________