implementation
procedure TfmMain.replicateTable(quelle,ziel:
String);
var i, j:integer;
inpFelder, outpFelder,
sql, werte:
String;
begin
dmData.repl_global.sql.clear;
dmData.repl_global.sql.add('
SELECT * FROM '+quelle);
try
dmData.repl_global.open;
dmData.repl_global.FetchAll;
dmData.repl_global.first;
dmData.repl_local.sql.clear;
dmData.repl_local.sql.add('
DELETE FROM '+ziel);
dmData.repl_local.ExecSQL;
inpFelder:=dmData.repl_global.Fields[0].DisplayName;
for i:=1
to dmData.repl_global.FieldCount-1
do //feldnamen vorbereiten
begin
inpFelder:=inpFelder+'
, '+(dmData.repl_global.Fields[i].DisplayName);
end;
for i:=1
to dmData.repl_global.RecordCount
do //kopieren
begin
werte:=dmData.repl_global.fields[0].AsString;
for j:=1
to dmData.repl_global.FieldCount-1
do
begin
if dmData.repl_global.fields[j].AsString='
'
then
werte:=werte+'
, null'
else werte:=werte+'
, ''
'+trim(dmData.repl_global.fields[j].AsString)+'
''
';
end;
dmData.repl_local.SQL.Clear;
dmData.repl_local.sql.add('
INSERT INTO '+ziel+'
('+inpFelder+'
) '+
'
VALUES ('+werte+'
)');
try dmData.repl_local.ExecSQL;
except
errlog.lines.add(dmData.repl_local.sql.text);
errlog.lines.add(werte);
end;
dmData.repl_global.Next;
end;
except end;
end;