Works this
http://www.firebirdfaq.org/faq243/with SQLDb fpc 2.3.1, Firebird 2.1.2
In memo1 write
insert into imagenes (Socio) values (21095) returning clave_imagen
procedure TForm1.Button1Click(Sender: TObject);
begin
IBConnection1.Open;
if SQLTransaction1.Active then SQLTransaction1.Commit;
SQLQuery1.close;
SQLQuery1.SQL.clear;
SQLQuery1.SQL.AddStrings(memo1.lines);
SQLTransaction1.StartTransaction;
SQLQuery1.open;
end;
In SQLQuery1.FieldByName('clave_imagen').AsInteger is the primary key.
The other way is create a stored procedure for seach the primary key(SQLQuery1.FieldByName('clave_generada').AsInteger), then you save the primary key with a normal slq update.
Firebird code, generator
CREATE GENERATOR GEN_IMAGENES_ID;
Stored Procedure
SET TERM ^ ;
CREATE PROCEDURE GENERA_CLAVE_IMAGEN
RETURNS ( CLAVE_GENERADA Integer )
AS
BEGIN
clave_generada = GEN_ID(GEN_IMAGENES_ID, 1);
suspend;
END^
SET TERM ; ^
With SQLTransaction, you can save the primary key in many tables with the same Transaction.
Regards