Mega Code Archive

 
Categories / Delphi / Examples
 

Obtaining IB generator value without stored procedure

Title: Obtaining IB generator value without stored procedure Question: How to obtain IB generator value without stored procedure Answer: There is no need to create stored procedure only for obtaining generator values in Your application. Here are examples for FIBC and IBX components. For Free Interbase Components (Gregory Deatz, gdeatz@hlmdd.com) function GetGenID (const AGeneratorName : string) : integer; begin with TFIBQuery.Create (nil) do try Database := ibDB; SQL.Text := 'SELECT GEN_ID (' + AGeneratorName + ', 1) from rdb$database'; ExecQuery; Result := Fields [0].AsInteger; Close; finally Free; end; end; Here 'ibDB' is the Your Database object (TFIBDataBase) For IBX components function GetGenID (const AGeneratorName : string) : integer; begin with TFIBSQL.Create (nil) do try Database := ibDB; SQL.Text := 'SELECT GEN_ID (' + AGeneratorName + ', 1) from rdb$database'; ExecQuery; Result := Fields [0].AsInteger; Close; finally Free; end; end; Here 'ibDB' is the Your Database object (TIBDataBase) P.S. Sorry, but I am using FIBC so, example for IBX is not tested, but I am hope it's valid. P.P.S. I don't know official FIBC home page. You can download it from Russian site - see 'Component URL'.