I am using the latest UniDAC Version with Delphi Seattle on Windows 10 / 64 bit
Some queries take a very Long time to execute, so I want them to be executed in a thread without record number limitations. To make handling easyer I tried to create a derived component with a new property "UseThread", which temporarily creates a new UniConnection for Thread usage. It seems to work OK, but it will never read all records (uses fetchrows value) at once. I am sure, that this is my fault, but perhaps you can help me out anyway:
This is the Code for my "VSQuery" components new property "UseThread":
Code: Select all
TVSQuery = class(TUniQuery)
...
procedure TVSQuery.SetUseThread(Value: Boolean);
begin
if FUseThread = Value then exit;
FUseThread := Value;
if FUseThread = true then
begin
if not Assigned(ThreadConn) then
begin
OldUniDirectional := UniDirectional;
OldReadOnly := ReadOnly;
OldConn := Connection;
ThreadConn := TUniConnection.Create(nil);
ThreadConn.AssignConnect(Connection);
Connection := ThreadConn;
SpecificOptions.Add('FetchAll=True');
SpecificOptions.Values['FetchAll'] := 'True';
UniDirectional := true;
ReadOnly := true;
FetchAll := true; // This is amazing - it will compile without Errors ?!
end;
end
else
begin
if not Assigned(OldConn) then exit;
Connection := OldConn;
SpecificOptions.Values['FetchAll'] := 'False';
UniDirectional := OldUniDirectional;
ReadOnly := OldReadOnly;
FetchAll := false;
if Assigned(ThreadConn) then
begin
ThreadConn.Disconnect;
ThreadConn.Free;
ThreadConn := nil;
OldConn := nil;
end;
end;
end;
...
if FUseThread then
begin
FRunning := true; // new property to Show thread status
TThread.CreateAnonymousThread(procedure ()
begin
try
if Prepared = false then
if UpdateSQL(Self,modified) = false then exit else // function to Change SQL for different databases
try
inherited Open;
except
end;
finally
FRunning := false;
TThread.Synchronize(TThread.CurrentThread,
procedure
begin
if Assigned(FOnExecuted) then // new Event fired after thread execution
FOnExecuted;
end);
end;
end).Start;
Greetings
Deffe11