Subject | RE: [firebird-support] Performing multiple INSERT statements causes long delay at every Nth statement |
---|---|
Author | Svein Erling Tysvær |
Post date | 2012-05-09T09:24:45Z |
Hi Pierre!
...
INSERT INTO MyTable VALUES (1, 'My first text'...);
INSERT INTO MyTable VALUES (2, 'My second text'...);
But rather
INSERT INTO MyTable VALUES (:Param1, :Param2...);
So change your code to something like
with DMAq do begin
IBSQL3.Transaction.StartTransaction;
with IBQuery1 do begin
SQL.Text:='select * from '+tbl;
Transaction.StartTransaction;
Open;
s:='insert into '+tbl+' values (Param0';
for N:=1 to FldCnt-1 do
s:=s+', :Param'+inttostr(N);
IBSQL3.SQL.Text:=s+')';
IBSQL3.Prepare;
while not eof do begin
for N:=0 to FldCnt-1 do begin
if fields[N].IsNull then
IBSQL3.Params[N].Clear
else
case FldTp[N] of
1: IBSQL3.Params[N].AsString:=fields[N].AsString;
2: IBSQL3.Params[N].AsString:=fields[N].AsString;
3: IBSQL3.Params[N].AsFloat:=fields[N].AsFloat;
4: IBSQL3.Params[N].AsDateTime:=fields[N].AsDateTime;
5: IBSQL3.Params[N].AsString:=trim(fields[N].AsString);
end;
end;
IBSQL3.ExecQuery;
next;
end;
Hopefully, this will speed up your program considerably,
Set
>I am using Firebird 1.52, Delphi 2009 on a Windows Vista Business OS. The Delphi toolI know nothing about IBX, but
>I use for database access is Interbase Express 12.12.
...
> with DMAq do beginThis is a very time consuming way to transfer records. It is a lot better to use parameters rather than fixed values, i.e. not use
> IBSQL3.Transaction.StartTransaction;
> with IBQuery1 do begin
> SQL.Text:='select * from '+tbl;
> Transaction.StartTransaction;
> Open;
> while not eof do begin
> s:='insert into '+tbl+' values (';
> for N:=0 to FldCnt-1 do begin
> case FldTp[N] of
> 1: s:=s+','+fields[N].AsString;
> 2: s:=s+','+fields[N].AsString;
> 3: s:=s+','+FloatToStr(fields[N].AsFloat);
> 4: s:=s+','''+formatdatetime('mm/dd/yyyy hh:nn:ss', fields[N].AsDateTime)+'''';
> 5: s:=s+','''+trim(fields[N].AsString)+'''';
> end;
> end;
> IBSQL3.SQL.Text:=s+')';
> IBSQL3.ExecQuery;
> next;
> end;
> Close;
> Transaction.Commit;
> IBSQL3.Transaction.Commit;
> end;
> end;
INSERT INTO MyTable VALUES (1, 'My first text'...);
INSERT INTO MyTable VALUES (2, 'My second text'...);
But rather
INSERT INTO MyTable VALUES (:Param1, :Param2...);
So change your code to something like
with DMAq do begin
IBSQL3.Transaction.StartTransaction;
with IBQuery1 do begin
SQL.Text:='select * from '+tbl;
Transaction.StartTransaction;
Open;
s:='insert into '+tbl+' values (Param0';
for N:=1 to FldCnt-1 do
s:=s+', :Param'+inttostr(N);
IBSQL3.SQL.Text:=s+')';
IBSQL3.Prepare;
while not eof do begin
for N:=0 to FldCnt-1 do begin
if fields[N].IsNull then
IBSQL3.Params[N].Clear
else
case FldTp[N] of
1: IBSQL3.Params[N].AsString:=fields[N].AsString;
2: IBSQL3.Params[N].AsString:=fields[N].AsString;
3: IBSQL3.Params[N].AsFloat:=fields[N].AsFloat;
4: IBSQL3.Params[N].AsDateTime:=fields[N].AsDateTime;
5: IBSQL3.Params[N].AsString:=trim(fields[N].AsString);
end;
end;
IBSQL3.ExecQuery;
next;
end;
Hopefully, this will speed up your program considerably,
Set