Ver Mensaje Individual
  #4  
Antiguo 14-04-2009
cecam cecam is offline
Miembro
 
Registrado: may 2006
Ubicación: Girona
Posts: 47
Reputación: 0
cecam Va por buen camino
Hoooola!!

Hace tiempo hice algo parecido para ver las diferencias que tenia entre un Paradox y un MySQL :

Código:
  TComparaCDS = class
    cdsDiferencies:TClientDataSet;
    constructor Create;
    procedure Compara(const taula:string; cdsOrigen, cdsDesti:TClientDataSet);
    destructor Destroy;override;
  private
  public
  end;

constructor TComparaCDS.Create;
begin
  inherited Create;
  cdsDiferencies:=TClientDataSet.Create(Application);
  with cdsDiferencies.FieldDefs do begin
       Clear;
       Add('taula',   ftString,   15,False);
       Add('clau',    ftString,   100,False);
       Add('origen',  ftString,   2,False);
       Add('desti',   ftString,   2,False);
  end;
  cdsDiferencies.CreateDataSet;
  cdsDiferencies.FieldByName('clau').DisplayWidth:=15;
  cdsDiferencies.Open;
  cdsDiferencies.IndexFieldNames:='taula;clau';
end;

procedure TComparaCDS.Compara(const taula:string; cdsOrigen, cdsDesti:TClientDataSet);
var
  o:string;
  d:string;
begin
  cdsOrigen.First;
  cdsDesti.First;
  while not cdsOrigen.Eof
     or not cdsDesti.Eof do begin
        if   cdsOrigen.Eof
        then o:='ZZZZZZZZZZZZZZZZZZZZZZ'
        else o:=registreAsString(cdsOrigen);
        if   cdsDesti.Eof
        then d:='ZZZZZZZZZZZZZZZZZZZZZZ'
        else d:=registreAsString(cdsDesti);

        if   o=d
        then begin
             cdsOrigen.Next;
             cdsDesti.Next;
        end
        else
        if  (o<d)
        then begin
             cdsdiferencies.Insert;
             cdsDiferencies.FieldByName('taula').AsString:=taula;
             cdsDiferencies.FieldByName('clau').AsString:=o;
             cdsdiferencies.FieldByName('origen').AsString:='->';
             cdsdiferencies.FieldByName('desti').Clear;
             cdsdiferencies.Post;
             cdsOrigen.Next;
        end
        else
        if  (o>d)
        then begin
             cdsdiferencies.Insert;
             cdsDiferencies.FieldByName('taula').AsString:=taula;             
             cdsdiferencies.FieldByName('clau').AsString:=d;
             cdsdiferencies.FieldByName('origen').Clear;
             cdsdiferencies.FieldByName('desti').AsString:='<-';
             cdsdiferencies.Post;
             cdsDesti.Next;
        end;
  end;
end;

destructor TComparaCDS.Destroy;
begin
  if   cdsDiferencies.Active
  then cdsDiferencies.EmptyDataSet;
  cdsDiferencies.Free;
  inherited Destroy;
end;
La funcion registreAsString(cdsDesti) ahora mismo no la encuentro, pero es muy facil de hacer y basicamente lo que hace es transformar todos los campos de un registro en un string.

Para que funcione necesitas tener ordenados los clientdataset por el mismo indice.

Con este objeto lo que tengo es un registro de las diferencias, no hace la sincronización, pero es facil de modificar para que la haga.


Saludos!!
Responder Con Cita