Stef Merlijn
asked on
Refresh/requery table after update through SQL
Hi,
I have following code for which I need to increase performance:
begin
// Alle relaties deselecteren
With DM.QAlgemeenGebruik do
begin
Close;
SQL.Clear;
SQL.Add(' UPDATE Relaties SET Relaties.GeselecteerdVoorA fspraak = False, Relaties.GefactureerdIndic ator = False ');
SQL.Add(' WHERE Relaties.GeselecteerdVoorA fspraak = True OR Relaties.GefactureerdIndic ator = True; ');
ExecSQL;
end;
If VarToStr(Event.ID) <> '' then
begin
// Alle relaties markeren die aan de afspraak zijn toegewezen.
With DM.QAlgemeenGebruik do
begin
Close;
SQL.Clear;
SQL.Add(' UPDATE (Relaties INNER JOIN AgendaRelaties ON Relaties.Relatienr = AgendaRelaties.Relatienr) SET Relaties.GeselecteerdVoorA fspraak = True ');
SQL.Add(' WHERE (((AgendaRelaties.[AgendaI D]) = '+ QuotedStr(VarToStr(Event.G etCustomFi eldValueBy Name('ID2R elaties')) ) +')); ');
ExecSQL;
end;
// Merkeer alle relaties waarvoor voor de afspraak een factuur is aangemaakt.
With DM.QAlgemeenGebruik do
begin
Close;
SQL.Clear;
SQL.Add(' UPDATE (Relaties INNER JOIN AgendaRelaties ON Relaties.Relatienr = AgendaRelaties.Relatienr) SET Relaties.GefactureerdIndic ator = True ');
SQL.Add(' WHERE (((AgendaRelaties.[AgendaI D]) = '+ QuotedStr(VarToStr(Event.G etCustomFi eldValueBy Name('ID2R elaties')) ) +')) ');
SQL.Add(' AND (AgendaRelaties.Gefacturee rd) = True; ');
ExecSQL;
end;
end;
DM.TRelatieLookup.DisableC ontrols;
DM.TRelatieLookup.Requery;
DM.TRelatieLookup.EnableCo ntrols;
end;
The queries perform pretty good, about 0,015 seconds a piece.
But DM.TRelatieLookup.Requery; takes about 2,000 seconds.
Change this line to: DM.TRelatieLookup.Refresh; doesn't have much effect.
Is there any other way to run perform the updates by SQL and refresh the table while increasing performance?
Regards,
Stef
I have following code for which I need to increase performance:
begin
// Alle relaties deselecteren
With DM.QAlgemeenGebruik do
begin
Close;
SQL.Clear;
SQL.Add(' UPDATE Relaties SET Relaties.GeselecteerdVoorA
SQL.Add(' WHERE Relaties.GeselecteerdVoorA
ExecSQL;
end;
If VarToStr(Event.ID) <> '' then
begin
// Alle relaties markeren die aan de afspraak zijn toegewezen.
With DM.QAlgemeenGebruik do
begin
Close;
SQL.Clear;
SQL.Add(' UPDATE (Relaties INNER JOIN AgendaRelaties ON Relaties.Relatienr = AgendaRelaties.Relatienr) SET Relaties.GeselecteerdVoorA
SQL.Add(' WHERE (((AgendaRelaties.[AgendaI
ExecSQL;
end;
// Merkeer alle relaties waarvoor voor de afspraak een factuur is aangemaakt.
With DM.QAlgemeenGebruik do
begin
Close;
SQL.Clear;
SQL.Add(' UPDATE (Relaties INNER JOIN AgendaRelaties ON Relaties.Relatienr = AgendaRelaties.Relatienr) SET Relaties.GefactureerdIndic
SQL.Add(' WHERE (((AgendaRelaties.[AgendaI
SQL.Add(' AND (AgendaRelaties.Gefacturee
ExecSQL;
end;
end;
DM.TRelatieLookup.DisableC
DM.TRelatieLookup.Requery;
DM.TRelatieLookup.EnableCo
end;
The queries perform pretty good, about 0,015 seconds a piece.
But DM.TRelatieLookup.Requery;
Change this line to: DM.TRelatieLookup.Refresh;
Is there any other way to run perform the updates by SQL and refresh the table while increasing performance?
Regards,
Stef
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you for your post Ivanov G. But as stated before, the SQL's aren't the bottleneck in performance. Refreshing the table is.
ASKER
Thanks for you reply TomasHelgi.
As you can see I already use Requery instead of Refresh, because I don't need to save the current recordposition at that moment.
As you can see I already use Requery instead of Refresh, because I don't need to save the current recordposition at that moment.
How much records do you have in your table. What is the type of the Cursor, ctClient maybe... ?
ASKER
Number of record = 70
CursorType = ctStatic
CursorLocation = clUseClient
LockType = Optimistic
TableDirect = True
ADOConnection
CursorType = ctStatic
CursorLocation = clUseClient
LockType = Optimistic
TableDirect = True
ADOConnection
What is the database? How much time does the query takes to execute in the DB's tool for queries?
How does DM.TRelatieLookup.Close; DM.TRelatieLookup.Open; execute?
How does DM.TRelatieLookup.Close; DM.TRelatieLookup.Open; execute?
ASKER
I use a MS Access database.
> The queries perform pretty good, about 0,015 seconds a piece.
> But DM.TRelatieLookup.Requery; takes about 2,000 seconds.
DM.TRelatieLookup.Close; DM.TRelatieLookup.Open; takes about 2,000 seconds.
There a quite a few forms that use this table for lookup (lookupcomboboxes).
> The queries perform pretty good, about 0,015 seconds a piece.
> But DM.TRelatieLookup.Requery;
DM.TRelatieLookup.Close; DM.TRelatieLookup.Open; takes about 2,000 seconds.
There a quite a few forms that use this table for lookup (lookupcomboboxes).
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Making a copy does make a lot of difference.
Not it takes only 0,6 seconds to refresh.
Not it takes only 0,6 seconds to refresh.
All right,
try this
with DM.TRelatieLookup do begin
DisableControls;
try
Requery
finally
EnableControls;
end;
end;
try this
with DM.TRelatieLookup do begin
DisableControls;
try
Requery
finally
EnableControls;
end;
end;
ASKER
Doesn't make any difference compared without EnableControls.
step through the code. does the requery here take the time or the EnableControls?
Have seen this also in an application I setup with MS Access. Do you have any tables that have setup datasource to any of the slow performing table in your App?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you all for your help.
// MSSQL syntax
CREATE PROCEDURE sp_something @EventID INT, @AgendaID VARCHAR(50)
AS
UPDATE Relaties SET Relaties.GeselecteerdVoorA
WHERE Relaties.GeselecteerdVoorA
IF @EventID <> ''
BEGIN
UPDATE (Relaties INNER JOIN AgendaRelaties ON Relaties.Relatienr = AgendaRelaties.Relatienr) SET Relaties.GeselecteerdVoorA
WHERE (((AgendaRelaties.[AgendaI
END
UPDATE (Relaties INNER JOIN AgendaRelaties ON Relaties.Relatienr = AgendaRelaties.Relatienr) SET Relaties.GefactureerdIndic
WHERE (((AgendaRelaties.[AgendaI
AND (AgendaRelaties.Gefacturee
GO
then change your code to something like:
With DM.QAlgemeenGebruik do
begin
Close;
SQL.Clear;
SQL.Add(' CALL something ' + EventID + ', ' + AgendaID);
SQL.Add(' WHERE Relaties.GeselecteerdVoorA
ExecSQL;
end;