procedure TForm1.bbexecClick(Sender: TObject);
var i,j : integer;
q : TIBquery;
command,
line : string;
start,summe,
t1,t2 : cardinal;
begin
if input.lines.text = '' then exit;
ibdb.DatabaseName := edDatabase.Text;
ibdb.Connected := TRUE;
ibtrans.Active := TRUE;
bbexec.enabled := FALSE;
sb1.Panels[0].Text := ibdb.DatabaseName;
caption := application.Title + ' - '+ibdb.DatabaseName;
q:=tibquery.create(nil);
q.UniDirectional:=FALSE;
q.database :=ibdb;
output.lines.Clear;
pb1.Position := 1;
pb1.Max := input.lines.count;
command := '';
summe := 0;
output.lines.add(format('%s - %s : Starte',[datetostr(date),timetostr(now)]));
start := gettickcount;
for i := 0 to input.lines.count -1 do begin
pb1.Position:=i+1;
command:=command+input.lines[i];
if pos(';',input.lines[i]) = 0 then continue;
try
command:=stringreplace(command,#13#10,'',[rfReplaceAll]);
command:=stringreplace(command,#13,'',[rfReplaceAll]);
command:=stringreplace(command,#10,'',[rfReplaceAll]);
q.sql.text := command;
command := '';
t1 := GetTickCount;
q.open;
t2 := getTickcount;
summe := summe+(t2-t1);
output.lines.add(format('EXEC Time : <%d>',[(t2-t1)]));
if q.eof then begin
output.lines.add('EOF : '+q.sql.text);
end else begin
while not q.eof do begin
line:='';
for j:=0 to q.FieldCount -1 do begin
if j = 0 then line:=q.FieldList[j].AsString
else line:=line+';'+q.FieldList[j].AsString;
end;
output.lines.add(line);
q.next;
end;
end;
except
on e:
exception do begin
output.lines.add(e.message);
end;
end;
q.close;
end;
output.lines.add(format('%s - %s : Dauer Programm : %s sec ',[datetostr(date),timetostr(now),floattostr((gettickcount-start) / 1000)]));
output.lines.add(format('%s - %s : Dauer Execute : %s sec ',[datetostr(date),timetostr(now),floattostr((summe) / 1000)]));
if ibtrans.Active then ibtrans.CommitRetaining;
output.lines.add(format('%s - %s : Ende ',[datetostr(date),timetostr(now)]));
Application.ProcessMessages;
q.free;
bbexec.enabled:=TRUE;
ibtrans.Active:=FALSE;
ibdb.Connected:=FALSE;
end;