TUniLoader.OnProgress
Posted: Wed 08 Aug 2018 21:03
Things slow down dramatically with this event.
May I suggest you only fire that when the Percentage changes.
May I suggest you only fire that when the Percentage changes.
Discussion forums for open issues and questions concerning database tools, data access components and developer tools from Devart
https://forums.devart.com/
Code: Select all
var
CurrentPercent: Integer;
procedure TForm1.Button1Click(Sender: TObject);
begin
CurrentPercent := -1;
UniLoader1.Load;
end;
procedure TForm1.UniLoaderProgress(Sender: TObject; Percent: Integer);
begin
if CurrentPercent <> Percent then begin
CurrentPercent := Percent;
//Do something
end;
end;
Code: Select all
procedure TForm1.Button1Click(Sender: TObject);
begin
UniLoader.Connection := UniConnection;
UniConnection.StartTransaction;
try
UniLoader.Load;
UniConnection.Commit;
except
UniConnection.Rollback;
raise;
end;
end;
Code: Select all
procedure TDataDM.CopyDataToNewSqlServerDb;
const ar : array[0..7] of string = ('MNGDDOMAINS', 'SERVERS', 'SNAP_NOTINFETCH', 'SNAPSHOTHISTORY', 'SNAP_SERVERSHARES',
'SNAP_USERGROUPLIST', 'SNAP_USER2GROUP', 'SNAPSHOTS');
var
LHadQueryRecCount: Boolean;
LTableName : string;
begin
// TUniLoaderAccess(Loader).AutoCommit := False;
TestConnection.StartTransaction;
// TestTransaction.Savepoint('COPYTONEWSQLSERVERDB');
uniCon.Connect;
try
Query.Active := False;
LHadQueryRecCount := Query.Options.QueryRecCount;
Query.Options.QueryRecCount := True; // Else Percent won't work.
try
try
{- Process Tables in order }
for LTableName in ar do begin
Loader.TableName := LTableName;
TWaitForm.ShowWaitProgressMessage('Copying table: ' + LTableName, 0);
TWaitForm.ShowCancelBtn := True;
Loader.Tag := 0; // for Percent
Query.SQL.Text := 'SELECT * FROM ' + LTableName;
Query.Open;
Loader.LoadFromDataSet(Query);
Query.Close;
end;
finally
Query.Options.QueryRecCount := LHadQueryRecCount
end;
// {- Destroys the specified savepoint without affecting any work that has been performed after its creation. }
// TestTransaction.ReleaseSavepoint('COPYTONEWSQLSERVERDB');
TestConnection.Commit;
except
on E: ECancelCopyToNewSQLServer do begin
// E.SetErrMessage(True); // Canceled
// TestTransaction.RollbackToSavepoint('COPYTONEWSQLSERVERDB');
TestConnection.Rollback;
end;
end;
finally
uniCon.Disconnect;
end;
end;
Code: Select all
object Loader: TUniLoader
Connection = TestConnection
Transaction = TestTransaction
SpecificOptions.Strings = (
'SQL Server.KeepIdentity=True'
'SQL Server.KeepNulls=True')
OnProgress = LoaderProgress
end