Si la base de datos tienen alguna forma de comunicarse (Estan en la misma red o via Internet) solo se tendrias q copiar los registros de una a otra base de forma directa. Osea conectandote a una, leer el registro en cuestion y hacer un insert con los valores q son necesarios en la otra BD.
si no hay comunicacion posible entre ambas BD siempre hay otra salida, usar archivos (almacenar el registro en un archivo e insertar el contenido en la otra base).
este es el codigo q usaba en esa situacion, faltan pulir algunas cosas, pero almenos no daba problemas
Para generar el registro de insercion
Código Delphi
[-]var
Tabla, Fields, ValueScript, Condicion: string;
SelectSQL: string;
PK: Integer;
I: Integer;
MSFields: TMemoryStream;
BufferSize: Int64;
InsertSQL : string[255]; FieldCount: Integer; FieldValue: string[255]; FieldBlob: TMemoryStream;
begin
Fields := 'CAR_ID, CAR_NOM, CAR_RDE'; Tabla := 'CARGOS'; Condicion := 'CAR_ID = :PK'; PK := 7; ValueScript := ':CAR_ID, :CAR_NOM, :CAR_RDE';
fptrDB.Active := True; MSFields := TMemoryStream.Create; try
InsertSQL := 'INSERT INTO ' + Tabla + ' (' + Fields + ')'
+ ' VALUES (' + ValueScript + ')';
BufferSize := Length(InsertSQL) + 1;
MSFields.Write(BufferSize, SizeOf(Int64));
MSFields.Write(InsertSQL, BufferSize);
SelectSQL := 'SELECT ' + Fields + ' FROM ' + Tabla + ' WHERE ' + Condicion;
fpdsTabla.SelectSQL.Clear;
fpdsTabla.SelectSQL.Add(SelectSQL);
fpdsTabla.ParamByName('PK').Value := PK; fpdsTabla.Open;
FieldCount := fpdsTabla.FieldCount;
MSFields.Write(FieldCount, SizeOf(Integer));
for I := 0 to fpdsTabla.FieldCount - 1 do
if fpdsTabla.Fields[i].IsNull then
begin
BufferSize := 0;
MSFields.Write(BufferSize, SizeOf(Int64));
end else
if fpdsTabla.Fields[i].IsBlob then
begin
FieldBlob := BlobToStream(fpdsTabla.Fields[i]);
BufferSize := IfThen(Assigned(FieldBlob), FieldBlob.Size);
if Assigned(FieldBlob) then
begin
MSFields.Write(BufferSize, SizeOf(Int64));
if 0 < BufferSize then
FieldBlob.SaveToStream(MSFields);
FieldBlob.Free;
end else
MSFields.Write(BufferSize, SizeOf(Int64));
end else
begin
FieldValue := fpdsTabla.Fields[i].AsString;
BufferSize := Length(FieldValue) + 1;
MSFields.Write(BufferSize, SizeOf(Int64));
MSFields.Write(FieldValue, BufferSize);
end;
fpdsTabla.Close;
MSFields.SaveToFile(ExtractFilePath(Application.ExeName) + 'Registro.msr');
finally
fptrDB.Active := False;
MSFields.Free;
end;
end;
para leer el registro e ingresarlo en otra BD
Código Delphi
[-]var
MSFields: TMemoryStream;
BufferSize: Int64;
InsertSQL : string[255];
FieldCount: Integer; FieldValue: string[255];
FieldBlob: TMemoryStream;
InpBuf: Pointer;
I: Integer;
begin
fptrDB.StartTransaction;
MSFields := TMemoryStream.Create;
try
MSFields.LoadFromFile(ExtractFilePath(Application.ExeName) + 'Registro.msr');
MSFields.Read(BufferSize, SizeOf(Int64));
MSFields.Read(InsertSQL, BufferSize);
MSFields.Read(FieldCount, SizeOf(Integer));
fpqyTabla.SQL.Clear;
fpqyTabla.SQL.Add(InsertSQL);
fpqyTabla.Prepare; for I := 0 to FieldCount - 1 do
begin
fpqyTabla.Params[i].Clear;
if fpqyTabla.Params[i].IsBlob then
begin
InpBuf := nil;
FieldBlob := TMemoryStream.Create;
try
MSFields.Read(BufferSize, SizeOf(Int64));
if 0 < BufferSize then
begin
GetMem(InpBuf, BufferSize);
MSFields.Read(InpBuf^, BufferSize);
FieldBlob.Write(InpBuf^, BufferSize);
fpqyTabla.Params[i].LoadFromStream(FieldBlob);
end;
finally
FieldBlob.Free;
if Assigned(InpBuf) then
FreeMem(InpBuf);
end;
end else
begin
MSFields.Read(BufferSize, SizeOf(Int64));
if 0 < BufferSize then
begin
MSFields.Read(FieldValue, BufferSize);
fpqyTabla.Params[i].Value := FieldValue;
end;
end;
end;
fpqyTabla.ExecQuery;
finally
fptrDB.Commit;
MSFields.Free;
end;
end;
e usado los componentes FibPLus pero no creo q haya problemas con otros ya que uso propiedades generales.