Subject Re: [IBO] Re: Field value required - MIDAS
Author Helen Borrie
At 10:13 AM 06-07-01 +0100, you wrote:
>Thanks you very much Helen for your answer.
>I changed the autogenerated value back to arNone on the server side. as you suggested
>I can now insert a row in the clientdataset, post it and apply the data.
>However, now I cannot post two rows after one another as I get a key violation. I believe
>it is because the client side is not aware of the generator/trigger on my primary key.
>the trigger BEFORE INSERT looks like this :
>On the server side, on the TIBOQuery, I have set the generator link to :
>But it doesn't seem to be enough. I understand it makes sense since the client doesn't speak to the server
>before an apply. Therefore two inserts after one another would fail.

No, two inserts *to the IBOQuery* one after the other should always succeed, because the GENID() method is called at OnBeforeInsert - that is, each insert will get its own unique value from the generator.

>Is it a design problem or is there a simple solution ?

The answer is probably YES to both. The first thing to do would be to work out what the design problem is. Do have a ClientDataSet mixed up in here somewhere?

Instead of setting GeneratorLinks, it is possible to call GEN_ID(GeneratorName, increment) in your own code, as a method of the IB_Connection. IB_Database and its descendant, IBODatabase, can also access this method.

If you are using TClientDataset, remember that its behaviour is not linked to the IB-specific methods and properties that TIBOQuery and TIBODatabase have access to. Possibly this can be resolved by calling Gen_ID() on the connection object at an appropriate event occurring at the row level and applying the returned value directly to the field object, e.g.

cdsCustomer.Fields['CustNo'] := IBODatabase1.Gen_ID(gen_CustNo, 1);


All for Open and Open for All
InterBase Developer Initiative ยท