Database Synchronizing (Speed Problem)
Posted: 23.01.2009, 15:09
Hi,
My Desktop application that is using PostgreSQL needs time to time synchronize data to Pocket PC application that uses SQLite. All is working perfectly, but I would like to increase the speed of synchronization. Currently I'm using something like this:
Is there any other way of copying data from one dataset to another, I think this loop is very slow, I need something like:
but for the 2 tables are in 2 separte databases (PostgreSQL and SQLite).
Thank you.
My Desktop application that is using PostgreSQL needs time to time synchronize data to Pocket PC application that uses SQLite. All is working perfectly, but I would like to increase the speed of synchronization. Currently I'm using something like this:
Code: Select all
procedure TRapiCopyForm.GenerateUpdateDBForDevice(fn: String);
const
DBStrings: array[0..2] of AnsiString =
(
'SELECT f0, f1, f2, f3 FROM tbl0',
'SELECT f0, f1, f2 FROM tbl1',
'SELECT f0, f1 FROM tbl2'
);
LDBStrings: array[0..2] of AnsiString =
(
'INSERT INTO tbl1 (f0, f1, f2, f3) VALUES (:v0, :v1, :v2, :v3)',
'INSERT INTO tbl1 (f0, f1, f2) VALUES (:v0, :v1, :v2)',
'INSERT INTO tbl2 (f0, f1) VALUES (:v0, :v1)'
);
var
i, j, pc, cnt: Integer;
begin
cnt := Length(DBStrings);
try
LDBConnection.Disconnect;
except
end;
LDBConnection.Catalog := fn;
LDBConnection.Database := fn;
LDBConnection.Connect;
// Q is a TZQuery Component that is connected to PostgreSQL DBConnection
// LQ is a TZQuery Component that is connected to SQLite LDBConnection
for i := 0 to cnt - 1 do begin
Q.Active := false;
Q.SQL.Clear;
Q.SQL.Add(DBStrings[i]);
Q.Active := true;
LQ.Active := false;
LQ.SQL.Clear;
LQ.SQL.Add(LDBStrings[i]);
while not Q.Eof do begin
pc := LQ.Params.Count;
for j := 0 to pc - 1 do begin
LQ.Params[j].Value := Q.Fields[j].Value;
end;
LQ.ExecSQL;
Q.Next;
end;
Q.Active := false;
end;
LDBConnection.Disconnect;
end;
Code: Select all
INSERT INTO tbl1 (f0, f1, f2) SELECT ff0, ff1, ff2 FROM tbl2
Thank you.