Subject Re: [IBO] Questions about transactions and generators
Author Helen Borrie
At 05:04 PM 22/05/2004 -0300, you wrote:
>Ok.. but I have some threads that will insert at the same time. This code
>will work?
>procedure TForm1.Button1Click(Sender: TObject);
> vId : Integer;
> IB_Query1.GeneratorLinks.Add('MyTablePK=genMyTable');
> vId := IB_Query1.Gen_ID('genMyTable', 1);
> IB_Query1.ExecuteDML('insert into MyTable(''Name'') values(''rafael'')');
>vId is the id that will be inserted in MyTablePK?

You are a bit mixed up here. If you use GeneratorLinks, you simply forget
about the PK value when doing a normal Insert from the dataset.

But you are not doing a normal insert from the dataset, you are doing an
ExecuteImmediate, which doesn't prepare anything. The GeneratorLinks are
not available. If you use this method, you will have to pass the PK value
to the statement yourself, i.e. your variable vid, because this method
requires a literal SQL statement.

For ExecuteDML, you also have to pass a pointer to an XSQLDA structure that
you have previously constructed. ExecuteDML isn't "beginner stuff" and
it's quite abnormal to call it from the context of a query object.

Another problem I notice is your use of double quotes on the string
value. This isn't valid for Firebird or IB 6 (but you don't say what you
are using).

Do you want to start again, using a more conventional method?