TIBCTable.Insert duration with lot of records
TIBCTable.Insert duration with lot of records
Hello,
I need to insert a lot of records (30 000 rows) in a firebird database.
Here is my code for one record:
frmMain.TblEnreg.Insert;
frmMain.TblEnregNum.Value:=NbEnreg+1;
//Enregistre le nom et références du DAT
frmMain.TblEnregNom_Site.AsString:=frmMain.SiteLog;
frmMain.TblEnregRef_DAT.AsString:=frmMain.RefDATLog;
frmMain.TblEnregDate.Value:=date;
frmMain.TblEnregHeure.Value:=heure;
frmMain.TblEnregVe.Value:=StrToInt(ve);
frmMain.TblEnregVs.Value:=StrToInt(vs);
frmMain.TblEnregPhase.Value:=StrToInt(phase);
frmMain.TblEnregK.Value:=StrToInt(Rapp);
frmMain.TblEnregTyp.AsString:=Typ;
Inc(NbEnreg);
Here is sql given by dbmonitor (for one record) :
INSERT INTO ENREGISTREMENTS
(NUM, REF_DAT, NOM_SITE, DATE_ENREG, HEURE, VE, VS, K, PHASE, TYP)
VALUES
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
CommitRetaining;
My problem is that this is very very long. If i do it with a bde database (with the same code) it takes less than half time.
How could i optimise it?
Thank you very much
Regards
I need to insert a lot of records (30 000 rows) in a firebird database.
Here is my code for one record:
frmMain.TblEnreg.Insert;
frmMain.TblEnregNum.Value:=NbEnreg+1;
//Enregistre le nom et références du DAT
frmMain.TblEnregNom_Site.AsString:=frmMain.SiteLog;
frmMain.TblEnregRef_DAT.AsString:=frmMain.RefDATLog;
frmMain.TblEnregDate.Value:=date;
frmMain.TblEnregHeure.Value:=heure;
frmMain.TblEnregVe.Value:=StrToInt(ve);
frmMain.TblEnregVs.Value:=StrToInt(vs);
frmMain.TblEnregPhase.Value:=StrToInt(phase);
frmMain.TblEnregK.Value:=StrToInt(Rapp);
frmMain.TblEnregTyp.AsString:=Typ;
Inc(NbEnreg);
Here is sql given by dbmonitor (for one record) :
INSERT INTO ENREGISTREMENTS
(NUM, REF_DAT, NOM_SITE, DATE_ENREG, HEURE, VE, VS, K, PHASE, TYP)
VALUES
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
CommitRetaining;
My problem is that this is very very long. If i do it with a bde database (with the same code) it takes less than half time.
How could i optimise it?
Thank you very much
Regards
You can assign INSERT statement to the SQL property of TIBCQuery or TIBCSQL component, and call it directly. Also call Prepare method at the beginning of the insert procedure.
Code: Select all
Query.SQL.Text := 'INSERT INTO ENREGISTREMENTS ' +
'(NUM, REF_DAT, NOM_SITE, DATE_ENREG, HEURE, VE, VS, K, PHASE, TYP) ' +
'VALUES (:NUM, :REF_DAT, :NOM_SITE, :DATE_ENREG, :HEURE, :VE, :VS, :K, :PHASE, :TYP)';
Query.Prepare;
for i := 1 to 30000 do begin
Query.Params[0].AsInteger := NbEnreg+1;
Query.Params[1].AsString := frmMain.SiteLog;
Query.Params[2].AsString := frmMain.RefDATLog;
...
Query.Execute;
end;
Query.Unprepare;
Hello,
Thank you for your answer
I have done time measurement.
With TblInsert it takes 50 sec
With query it takes 40 sec (it is better)
But if i do the same thing (with tblinsert) and a paradox database it takes about 10 sec!!!
I don't understand why the difference is so big?
I use FB2.1
Thank you for help
Regards
Thank you for your answer
I have done time measurement.
With TblInsert it takes 50 sec
With query it takes 40 sec (it is better)
But if i do the same thing (with tblinsert) and a paradox database it takes about 10 sec!!!
I don't understand why the difference is so big?
I use FB2.1
Thank you for help

Regards