Subject RE: [IBO] Working with Generators
Author Martynas Kancleris
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;

-----Original Message-----
From: Edson Luis Gonēalez [mailto:edson@...]
Sent: Thursday, April 11, 2002 1:46 PM
To: IBObjects@yahoogroups.com
Subject: Re: [IBO] Working with Generators

Sorry .... i not say before, i'm using the TIBODataSet components.

Note: I'm working now in other location.... my Delphi is in my home
i can not test any suggestion now.

Regards.

Edson Luis Gonçalez
Ribeirão Preto / SP

----- Original Message -----
From: "Edson Luis Gonçalez" <edson@...>
To: <ibobjects@yahoogroups.com>
Sent: Thursday, April 11, 2002 8:27 AM
Subject: [IBO] Working with Generators


> Hello.
>
> I have many queries in a form, to manager addresses, and
> all relations like:
>
> PAISES (like country)
> |
> ESTADOS (like states)
> |
> CIDADES
> ...
>
> I try to insert into COUNTRY and press save button or F10.
> A trigger in ActionList (default dataset commands) are fired,
> posting data.
> I have the property commit on post status active.
> The problem is....my ID (primary key) is entered
> by a generator.
> I'm posting, but the value of PAISES_ID (pk) isn't retrieved
> for me.
> If i try to insert a new field in ESTADOS (detail from PAISES)
> occours an error saying the field paises_id is missing.
> I manually have to create a function, to execute a sql statement
> and retrieve value for specific generator.
> I fire this function in BeforePost for any table.
> Now is all right, but... what's the correct way do
> work with generators and see in my current transaction in
> visual mode too ?
>
> Note: Using refresh, refreshkeys... the value is show, but
> i miss the position record... this back to 1st record.
>
> Regards.
>
> Edson Luis Gonçalez
> Ribeirão Preto / SP / Brazil
>
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.345 / Virus Database: 193 - Release Date: 09/04/2002
>
>
>
>
___________________________________________________________________________
> IB Objects - direct, complete, custom connectivity to Firebird or
InterBase
> without the need for BDE, ODBC or any other layer.
>
___________________________________________________________________________
> http://www.ibobjects.com - your IBO community resource for Tech Info
papers,
> keyword-searchable FAQ, community code contributions and more !
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.345 / Virus Database: 193 - Release Date: 09/04/2002



___________________________________________________________________________
IB Objects - direct, complete, custom connectivity to Firebird or InterBase
without the need for BDE, ODBC or any other layer.
___________________________________________________________________________
http://www.ibobjects.com - your IBO community resource for Tech Info papers,
keyword-searchable FAQ, community code contributions and more !

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/