Performance issue any idea

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Daniel Fagnan
Posts: 58
Joined: Fri 13 Oct 2006 00:08

Performance issue any idea

Post by Daniel Fagnan » Thu 30 Sep 2010 23:46

Any idea how to fill all data with more performance very often we try to do
It's correct to used While like this
while not BatchQry.EOF do Begin

Example :

Try

Session.StartTransaction;
while not BatchQry.EOF do Begin
s := StripChargenumber( BatchQry.FieldByName('tmpChargenumber').asString);
// Showmessage(s);
if Length(s) > 0 then
begin
With MyTb do
begin
insert;
FieldByName('EmplId').asinteger := BatchQry.FieldByName('tmpEmplId').asinteger;
FieldByName('chargeNumber').AsString := BatchQry.FieldByName('tmpChargenumber').asString;
FieldByName('OperationNumber').asInteger := BatchQry.FieldByName('tmpOperationNumber').asInteger;
FieldByName('TotalHoursSeq').asFloat:= BatchQry.FieldByName('tmpTotalHourSeq').AsFloat;
FieldByName('TotalhoursSeq_Reg').asFloat:= BatchQry.FieldByName('TmpTotalHourSeq_reg').AsFloat;
FieldByName('TotalhoursSeq_Suppl').asFloat:= BatchQry.FieldByName('TmpTotalHourSeq_Over').AsFloat;
FieldByName('DateTransaction').AsDateTime := BatchQry.FieldByName('tmpDateTransaction').asDateTime;
FieldByName('NeedtoCompleted').asBoolean := BatchQry.FieldByName('tmpNeedToCompleted').asBoolean;
FieldByName('HasModified').asString:= '0';
FieldByName('WorkOrder').asString := UPPERCASE(s);
FieldByName('ProjetId').asString := BatchQry.FieldByName('TmpUr').asString;
FieldByName('EquipmentID').asInteger := BatchQry.FieldByName('tmpEquipmentID').Asinteger;
post;
end; //with MyTb
end;// if Length

BatchQry.Edit;
BatchQry.FieldByName('tmpBatchMove').asinteger:= 1;
BatchQry.post;
s:='';
BatchQry.Next;
End; // while not ADQ.EOF
MyTb.ApplyUpdates; {try to write the updates to the database}
Session.Commit; {on success, commit the changes}
Except
MyTb.RestoreUpdates; {restore update result for applied records}
Session.Rollback; {on failure, undo the changes}
raise; {raise the exception to prevent a call to CommitUpdates!}
End;
MyTb.CommitUpdates; {on success, clear the cache} :!: :!:

easyblue
Posts: 64
Joined: Wed 02 Feb 2005 13:02
Location: Shanghai

Post by easyblue » Fri 01 Oct 2010 01:39

Do not use FieldByName.

First detect all the field index in advance, and then directly

Fields[0].asInteger:=..
Fields[1].asString:=..

AndreyZ

Post by AndreyZ » Mon 04 Oct 2010 14:04

Hello,

You can use the TMyLoader component which serves for fast loading of data to the server. You can look at the example of using it in MyDACDemo.
Also you can use the LoadFromDataset method of the TMyLoader component. This method loads data from the specified dataset. For more information please read MyDAC Reference Manual.

Post Reply