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;
中年大叔学Delphi
浙公网安备 33010602011771号