Subject Re: [IBO] 4.5Ai - IBOQuery - EditQuery - field properties "noinsert" not working?
Author Helen Borrie
At 05:21 PM 4/02/2005 +0100, you wrote:

>Hi,
>I'm just evaluating the IBObjects 4.5Ai on a simple test table "ADRESSKARTE".
>It's defined with a primary key field REF type INTEGER, which is
>automatically filled
>on insert by this trigger and generator (I use xCase 7.4 as ER designing
>tool):
>
>CREATE TRIGGER T_BI_ADRESSKARTE FOR ADRESSKARTE
>ACTIVE BEFORE INSERT POSITION 0
>AS
>BEGIN
> IF (new.Ref is null) THEN
> new.Ref = GEN_ID(GEN_ADRESSKARTE,1);
>END
>
>Okay, my problem occurs with the INSERTSQL generated by the Query Editor
>(Generate for Tables):
>INSERT INTO ADRESSKARTE(
> REF, /*PK*/
>.....
>VALUES (
> :REF,
>....
>
>The insert commands are now failing, as REF is transferred as "<n> 0"
>(says IBO
>Monitor) in the INSERTSQL statements. Then my trigger is not firing and
>getting me
>1st insert: a record with REF = 0
>2nd insert: PK key violation due to the 2nd record with REF=0 to be written
>
>To prevent this, I defined in FieldProperties a column REF with readonly
>"REF=NOINSERT".
>BUT ... it's not working, the INSERTSQL is still containing the REF field.
>By manually removing the two REF lines from the insertsql of IBOQuery it's
>working
>fine.
>
>Did I miss something here?

Yes: the property GeneratorLinks. The entry is a line in a TStringList:

Ref=GEN_ADRESSKARTE

If you prefer to make it global to the application, place all your
GeneratorLinks (for all table) in the same-name property in your connection
object:

ADRESSKARTE.Ref=GEN_ADRESSKARTE
ANOTHERTABLE.ID=GEN_ANOTHER_GENERATOR
...

>a.)How can I tell IBOQuery to ignore the field REF in the insertSQL?
>or

Not needed. IBO will fetch the value itself during BeforeInsert.

>b.) tell IBOQuery to send REF as <null> instead of "0", which will fire my
>trigger?

Also not needed and not recommended, as there are good reasons to want to
know this value before posting. But, if you really must post a null, then
there are two different ways.
Either
--- use BeforePost to switch off the Required property and clear the
parameter value:

with YourQuery do
begin
ColumnAttributes=IB_REQUIRED=F;
FieldByName('ADRESSKARTE').Clear;
....
end;

--- or use the InsertSQL property with a fully parameterised INSERT
statement that does not include the generated field.

Helen