procedure TMainForm.btnDataPumpClick(Sender: TObject);
begin
  // let's prepare connections giving them a name
  ActiveRecordConnectionsRegistry.AddConnection('source', 'sqlitecon');
  try
    ActiveRecordConnectionsRegistry.AddConnection('destination', 'pgcon');
    try

      // from now on, in this thread, current connection is "source"
      ActiveRecordConnectionsRegistry.SetCurrent('source');
      var lCustomers := TMVCActiveRecord.All<TCustomer>;
      try

        // from now on, in this thread, current connection is "destination"
        ActiveRecordConnectionsRegistry.SetCurrent('destination');
        begin var lTx := TMVCActiveRecord.UseTransactionContext; //use TransactionContext
          for var lCustomer in lCustomers do
          begin
            lCustomer.InvalidateConnection; //set connection to the current one
            lCustomer.Insert;
          end;
        end;

      finally
        lCustomers.Free;
      end;
    finally
      ActiveRecordConnectionsRegistry.RemoveConnection('destination');
    end;
  finally
    ActiveRecordConnectionsRegistry.RemoveConnection('source');
  end;
end;

 

posted on 2025-06-04 14:19  redhat588  阅读(25)  评论(0)    收藏  举报