Ver Mensaje Individual
  #3  
Antiguo 04-03-2018
Avatar de bulc
bulc bulc is offline
Miembro
 
Registrado: jun 2010
Posts: 412
Reputación: 14
bulc Va por buen camino
Con más explicación de código

Así, a bote pronto algo como esto:
Código Delphi [-]
Q1.Close;
Q1.SQLText:='Insert into TableX values (:P1, :P2, :P3)';
Q1.ParamByName(('P1').Value:= '0';  // Activa el Trigger Firebird
Q1.ParamByName(('P2').AsString:=Edit2.Text;
Q1.ParamByName(('P1').AsDate:=StrToDate(MaskEdit1.Text);
Q1.ExecSQL;
Q1.SQLText:='Commit';
ShowMessage('Inserción correcta');
Y luego en el Trigger, algo parecido a
Código SQL [-]
Set term ^;
Create trigger BI_Mine for TableX
Active Before Insert position 0
as begin
 if (New.Num = 0) then new.Num = GEN_ID( GEN_MINE, -1); 
end;
commit;
Set term ; ^
Como decía todo funciona bien, pero al salir de la inserción (en Delph1), el DBGrid muestra un cero, no el número correcto real.
Cuando hago otra pasada SQL con el FDQuery, entonces sí que se muestra en nuevo número de registro correcto.
Código Delphi [-]
FDQuery1.Active :=False;
FDQuery1.SQL.Clear;
FDQuery1.Add('select * from Mine....');
FDQuery1.Active :=True;
Responder Con Cita