Drop table postgresql

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
lao
Posts: 71
Joined: Wed 10 Dec 2008 10:56

Drop table postgresql

Post by lao » Mon 03 Jun 2013 14:35

Hi,
i use unidac 5.0.1,delphi 2007, postgresql 9.2.
on the form i just have an Tuniconnection with good parameters(user, password,localhost server...) and an PostgreSQLUniProvider.
This procedure does not work:

procedure TForm1.Button1Click(Sender: TObject);
var
x: integer;
Uniquery1, Uniquery2: tuniquery;
begin
UniQuery1 := TUniQuery.Create(self);
UniQuery2 := TUniQuery.Create(self);
UniQuery1.Connection := UniConnection1;
UniQuery2.Connection := UniConnection1;
UniQuery1.SpecificOptions.Values['FetchAll'] := 'False';
UniQuery2.SpecificOptions.Values['FetchAll'] := 'False';
try
UniQuery1.SQL.Text :=
'create table if not exists mytable1(name varchar(50)not null primary key)';
UniQuery1.Execute;
UniQuery1.sql.text := 'delete from mytable1';
UniQuery1.Execute;
for x := 1 to 50 do
begin
UniQuery1.SQL.Text := 'insert into mytable1 values(' + QuotedStr('Mam' +
inttostr(x)) + ')';
UniQuery1.Execute;
end;
UniQuery1.SQL.Text :=
'create table if not exists mytable2(countryname varchar(50)not null primary key)';
UniQuery1.Execute;

//open mytable1
UniQuery2.SQL.Text := 'Select * from mytable1';
UniQuery2.Open;

//open and close mytable2
UniQuery1.SQL.Text := 'Select * from mytable2';
UniQuery1.Open;
UniQuery1.Close;

UniQuery1.SQL.Text := 'drop table if exists mytable2';
UniQuery1.Execute;
finally
UniQuery1.Close;
UniQuery2.Close;
UniQuery1.Free;
UniQuery2.Free;

end;

end;

DemetrionQ
Devart Team
Posts: 271
Joined: Wed 23 Jan 2013 11:21

Re: Drop table postgresql

Post by DemetrionQ » Tue 04 Jun 2013 10:55

Hello.

On opening a dataset in the FetchAll=False mode, PostgreSQL requires an active transaction by default. Therefore we implicitly start a transaction, and you cannot delete the table until you close the dataset or fetch all records.
In order for the transaction not to start on opening a dataset in the FetchAll=False mode, set the CursorWithHold option to True. You can do it in the following way:

Code: Select all

 UniQuery2.SpecificOptions.Values['PostgreSQL.CursorWithHold'] := 'True';

lao
Posts: 71
Joined: Wed 10 Dec 2008 10:56

Re: Drop table postgresql

Post by lao » Wed 05 Jun 2013 10:57

Hi,
thank you DemetrionQ, it's work.
CursorWithHold it's only for working without default transaction?
regards,

DemetrionQ
Devart Team
Posts: 271
Joined: Wed 23 Jan 2013 11:21

Re: Drop table postgresql

Post by DemetrionQ » Wed 05 Jun 2013 17:01

Hello.

The CursorWithHold option controls only the transaction start when opening a table in a FetchAll=False mode.

Post Reply