Subject Re: [IBO] Working with Generators
Author Luiz
AFAIK, IBO already has this function embedded.

Luiz
----- Original Message -----
From: "Martynas Kancleris" <mKancler@...>
To: <IBObjects@yahoogroups.com>
Sent: Thursday, April 11, 2002 9:51 AM
Subject: RE: [IBO] Working with Generators


I dont use trigger's and use this code to retrieve generator value

Function TDataModule1.GENID(genname:String):Integer;
Var
sSQL:String;
POut_DA:PXSQLDA;
nullind:smallint;
tmpInt:integer;
tmpVal:ISC_INT64;
Begin
tmpInt:=-1;tmpVal:=-1;
GetMem(POut_DA,XSQLDA_LENGTH(1));
Try
With POut_DA^ do
Begin
Version:=SQLDA_VERSION1;
sqln:=1;
sqld:=1;
With sqlvar[0] do
Begin
If IB_Connection1.SQLDialect=3 then
Begin
sqltype:=SQL_INT64;
sqllen:=8;
sqldata:=@tmpVal;
End
Else
Begin
sqltype:=SQL_LONG;
sqllen:=4;
sqldata:=@tmpInt;
End;
sqlscale:=0;
sqlind:=@nullind;
End;
End;
sSQL:='SELECT GEN_ID ('+genname+',1) FROM RDB$DATABASE';
Try
With TIB_DSQL.Create(IB_Connection1.IB_Session ) do
Try
RetrieveDomainNames:=False;
IB_Connection:=IB_Connection1;
IB_Transaction:=nil;
CheckTransaction(True);
ExecImmed2(sSQL,nil,POut_DA);
Finally
Free;
End;
Except
End;
Finally FreeMem(POut_DA);
End;
If IB_Connection1.SQLDialect=3 then Result:=tmpVal
Else Result:=tmpInt;
End;

And code in Delphi looks like:

Var
myID:Integer;
Begin
myID:=DataModule1.GENID('mygenerator'); // <- this is parent id
DataModule1.IBOQuery1.SQL.Text:= 'INSERT INTO PARENTTABLE(ID,MYVALUE)
VALUES ('+IntToStr(myID)+',myvalue)';
DataModule1.IBOQuery1.ExecSQL;
End;