PostgreSQL, UniQuery, FetchAll questions

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
FCS
Posts: 176
Joined: Sat 23 Feb 2013 18:46

PostgreSQL, UniQuery, FetchAll questions

Post by FCS » Mon 12 Nov 2018 22:37

Hello,

Describe please, how to proper use FetchAll option.
I have a big table (more then 2M complex records) and I want to scan it and use some information to insert or update other table.

Example:
UQ:=TUniQuery.Create(nil);
UQ.Connection:=DM_01.UniConnection1;
UQ.Options.DefaultValues:=true;
UQ.UniDirectional := true;
UQ.FetchRows := 10000;
UQ.SpecificOptions.Values['FetchAll'] := 'False';
UQ.SQL.Add('SELECT * FROM big_table;');
UQ.Open;
if UQ.RecordCount>0 then begin
....
end;
UQ.Close;
UQ.Free;

1. The first of all is the scope of FetchAll option. Is this value assigned only for the current query or to the entire connection ?

2. The UniDirectional property scope is only for the current query or to the entire connection??

Regards
Michal

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: PostgreSQL, UniQuery, FetchAll questions

Post by azyk » Tue 13 Nov 2018 08:00

1. FetchAll is a dataset property:
https://www.devart.com/pgdac/docs/devar ... chall.htm . Therefore, it cannot influence the connection. FetchAll influences each dataset separately. For example, in such a code:

Code: Select all

UniQuery1.Connection := UniConnection1;
UniQuery2.Connection := UniConnection1;

UniQuery1.FetchAll := True;
UniQuery2.FetchAll := False;

UniQuery1.Open;
UniQuery2.Open;
You can be sure that UniQuery1 and UniQuery2 do not influence each other. They do not influence UniConnection1 either.

2. TUniQuery.UniDirectional influences only a dataset. TUniQuery.Connection and a database connection are not influenced either.

FCS
Posts: 176
Joined: Sat 23 Feb 2013 18:46

Re: PostgreSQL, UniQuery, FetchAll questions

Post by FCS » Tue 13 Nov 2018 09:02

Thank you.

What difference are between:

UQ:=TUniQuery.Create(nil);
UQ.Connection:=DM_01.UniConnection1;
UQ.UniDirectional := true;
UQ.FetchRows := 10000;

and

UQ:=TUniQuery.Create(nil);
UQ.Connection:=DM_01.UniConnection1;
UQ.FetchRows := 10000;
UQ.FetchAll := False;

In link you posted is written that FetchAll needs active transaction. Why ?

Regards
Michal

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: PostgreSQL, UniQuery, FetchAll questions

Post by azyk » Thu 15 Nov 2018 15:07

UQ:=TUniQuery.Create(nil);
UQ.Connection:=DM_01.UniConnection1;
UQ.UniDirectional := true;
UQ.FetchRows := 10000;

It means that the dataset will be readonly and you will be able to scroll it only to the end. UniDAC will request PostgreSQL for FetchRows records per request.

UQ: = TUniQuery.Create (nil);
UQ.Connection: = DM_01.UniConnection1;
UQ.FetchRows: = 10,000;
UQ.FetchAll: = False;

It means that dataset can be edited and records can be scrolled in both directions.

PostgreSQL does not support multiple transactions within a single connection. Therefore, it is necessary to either fetch all records or close the dataset.

FCS
Posts: 176
Joined: Sat 23 Feb 2013 18:46

Re: PostgreSQL, UniQuery, FetchAll questions

Post by FCS » Fri 16 Nov 2018 08:32

Thank you.

Regards
Michal

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: PostgreSQL, UniQuery, FetchAll questions

Post by azyk » Fri 16 Nov 2018 11:37

If any questions about our products come up , please contact us.

Post Reply