Thread problems - FetchAll = true not working

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Deffe11
Posts: 2
Joined: Wed 10 Feb 2016 09:39

Thread problems - FetchAll = true not working

Post by Deffe11 » Wed 10 Feb 2016 09:57

Dear sirs,
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;
Many thanks in advance for your assistance!

Greetings
Deffe11

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Thread problems - FetchAll = true not working

Post by AlexP » Wed 10 Feb 2016 11:09

Hello,

If you set the UniDirectional property to True, then the FetchAll property will be automatically set to False, and vice versa: if FetchAll is True - UniDirectional is set to False.

Deffe11
Posts: 2
Joined: Wed 10 Feb 2016 09:39

Re: Thread problems - FetchAll = true not working

Post by Deffe11 » Wed 10 Feb 2016 12:39

Uhh, yes, that did the trick ;) Now it works as desired!

Thanks :)

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Thread problems - FetchAll = true not working

Post by AlexP » Wed 10 Feb 2016 12:55

Glad to see that the issue was resolved. If you have any further questions, feel free to contact us.

Post Reply