Subject | Re: Temporarily Disabling triggers |
---|---|
Author | robertgilland |
Post date | 2004-11-25T22:19:32Z |
Here is a procedure I use to
Disable/enable triggers on a table.
Usually the components you use to access the firebird database
have methods to get all tablenames.
procedure ActivateTriggers( TableName : String; MakeActive :
Boolean );
var
slList : TStringList;
i : Integer;
begin
with qrySelect.SQL do
begin
clear;
add('select rdb$trigger_name');
add('from rdb$triggers');
add('where ( rdb$relation_name = ''' + UpperCase(TableName)
+ ''' )');
end;
slList := TStringList.Create;
with( qrySelect )do
begin
Open;
First;
while( not Eof )do
begin
slList.Add(Fields[0].AsString);
Next;
end;
Close;
end;
for i := 0 to slList.Count-1 do
with qrySelect.SQL do
begin
clear;
add('ALTER TRIGGER ' + slList[i]);
if( MakeActive )then
add('ACTIVE')
else
add('INACTIVE');
qrySelect.ExecSQL(TRUE);
end;
FreeAndNil(slList);
end;
Regards,
Robert.
Disable/enable triggers on a table.
Usually the components you use to access the firebird database
have methods to get all tablenames.
procedure ActivateTriggers( TableName : String; MakeActive :
Boolean );
var
slList : TStringList;
i : Integer;
begin
with qrySelect.SQL do
begin
clear;
add('select rdb$trigger_name');
add('from rdb$triggers');
add('where ( rdb$relation_name = ''' + UpperCase(TableName)
+ ''' )');
end;
slList := TStringList.Create;
with( qrySelect )do
begin
Open;
First;
while( not Eof )do
begin
slList.Add(Fields[0].AsString);
Next;
end;
Close;
end;
for i := 0 to slList.Count-1 do
with qrySelect.SQL do
begin
clear;
add('ALTER TRIGGER ' + slList[i]);
if( MakeActive )then
add('ACTIVE')
else
add('INACTIVE');
qrySelect.ExecSQL(TRUE);
end;
FreeAndNil(slList);
end;
Regards,
Robert.