Batchmove

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
777Yves
Posts: 37
Joined: Mon 09 Aug 2010 19:55
Location: Québec

Batchmove

Post by 777Yves » Tue 05 Jun 2012 14:24

Hi, I using Mydac pro 6.10.0.7
I have experience a strange problem in a batchmove operation.
Source and target have the same structure but in the target I have receive the name and firstname in the 2 first fields.
https://www.dropbox.com/s/xrsvbzkso9v4j ... ove%20.JPG

What could cause a problem like this ???

Code: Select all

        // On a déjà vérifié dans Cumul donc on ajoute directement
        atCumulFmr1ma.Append;
        atCumulFmr1maPERMIS.AsString   := atCmqErrRESIDENT.AsString;
        atCumulFmr1maPRATIQUE.AsString := atCmqErrMEMBRE.AsString;
        atCumulFmr1maIDINTERV.AsString := atCmqErrIDINTERV.AsString;
        atCumulFmr1maPERMA.AsString    := sPerma;
        atCumulFmr1maNOM.AsString      := atCmqErrNOM.AsString;
        atCumulFmr1maPRENOM.AsString   := atCmqErrPRENOM.AsString;
        atCumulFmr1maCREATION.AsString := sAnnee;
        atCumulFmr1ma.Post;

        // Prendre une copie du record avant qu'il soit modifié.
        CRBatchMove1.RecordCount := 1;
        CRBatchMove1.Source      := atCumulFmr1ma;
        CRBatchMove1.Destination := DmCumul.at1MA_trx;
        CRBatchMove1.Execute;

        // Il faut repositionner CRBatchMove1.Source car il fait un skip après .Execute
        atCumulFmr1ma.Locate('Perma', VarArrayOf([sPerma]), []);

        // Attribuer le # de transaction
        DmCumul.at1MA_trx.Close;
        DmCumul.at1MA_trx.Open;
        DmCumul.at1MA_trx.Locate('Perma', VarArrayOf([sPerma]), []);
        DmCumul.at1MA_trx.Edit;
        DmCumul.at1MA_trxTRX.AsString        := sTrx;
        DmCumul.at1MA_trxTRX_ACTION.AsString := 'A'; // record ajouté
        DmCumul.at1MA_trx.Post;

AndreyZ

Re: Batchmove

Post by AndreyZ » Tue 05 Jun 2012 16:13

Hello,

By default, the TCRBatchMove component matches fields basing on their position in the datasets. If fields in the source and destination datasets are located on different positions, you should use the TCRBatchMove.Mappings property to set field matching. To map a column named ColName in the source dataset to a column with the same name in the destination dataset, you should use the following code:

Code: Select all

CRBatchMove.Mappings.Add('ColName');
To map a column named SourceColName in the source dataset to a column named DestColName in the destination dataset, you should use the following code:

Code: Select all

CRBatchMove.Mappings.Add('DestColName=SourceColName');

777Yves
Posts: 37
Joined: Mon 09 Aug 2010 19:55
Location: Québec

Re: Batchmove

Post by 777Yves » Tue 05 Jun 2012 18:06

Hi, thanks for your response.
When you say Dataset, is it there order of the fields in Workbench witch should be the same as in Select * from cumul.1ma_trx
In other words this has nothing to do with the fields list in the field editor in the IDE where I could add other pseudo-fields(calculated, reference field, etc)

AndreyZ

Re: Batchmove

Post by AndreyZ » Wed 06 Jun 2012 08:49

Dataset is a component (TMyQuery, TMyTable, etc.) that you use to work with data. TCRBatchMove copies fields data using theirs order in the datasets. For example, using the following code:

Code: Select all

MyQuery1.SQL.Text := 'select id, txt1, txt2 from table1';
MyQuery1.Open;
MyQuery2.SQL.Text := 'select id, txt1, txt2 from table2';
MyQuery2.Open;
CRBatchMove1.Source := MyQuery1;
CRBatchMove1.Destination := MyQuery2;
CRBatchMove1.Execute;
, you will get the correct data in table2. But using the following code:

Code: Select all

MyQuery1.SQL.Text := 'select id, txt1, txt2 from table1';
MyQuery1.Open;
MyQuery2.SQL.Text := 'select id, txt2, txt1 from table2';
MyQuery2.Open;
CRBatchMove1.Source := MyQuery1;
CRBatchMove1.Destination := MyQuery2;
CRBatchMove1.Execute;
, the txt1 field values from table1 will be in the txt2 field values of table2, and the txt2 field values from table1 will be in the txt1 field values of table2. To avoid this problem, you should use the TCRBatchMove.Mappings property. Here is an example:

Code: Select all

MyQuery1.SQL.Text := 'select id, txt1, txt2 from table1';
MyQuery1.Open;
MyQuery2.SQL.Text := 'select id, txt2, txt1 from table2';
MyQuery2.Open;
CRBatchMove1.Source := MyQuery1;
CRBatchMove1.Destination := MyQuery2;
CRBatchMove1.Mappings.Add('txt1');
CRBatchMove1.Mappings.Add('txt2');
CRBatchMove1.Execute;

Post Reply