TPgQuery not using supplied connection
Posted: Mon 18 Nov 2013 02:35
Using PgDAC 4.1.4.
With Query.FetchAll=False, calling Query.Open uses some implicitly created connection, rather than the one assigned to Query.Connection. This effectively breaks temp table queries, since the temp tables created on the supplied connection are not visible.
In other words, the following code fails, with the error "relation "temp" does not exist":
I seem to be able to work around this by setting Query.FetchAll:=True, or Query.Options.CursorWithHold:=True, or by explicitly starting my own transaction around the Query.Open, but I'd rather not have to do any of these.
Is there a better solution?
With Query.FetchAll=False, calling Query.Open uses some implicitly created connection, rather than the one assigned to Query.Connection. This effectively breaks temp table queries, since the temp tables created on the supplied connection are not visible.
In other words, the following code fails, with the error "relation "temp" does not exist":
Code: Select all
procedure TempTest;
var
Connection: TPgConnection;
Query: TPgQuery;
begin
Connection := TPgConnection.Create(nil);
Connection.Database := 'database';
Connection.Server := 'server';
Connection.UserName := 'user';
Connection.Password := 'password';
Connection.Connect;
Query := TPgQuery.Create(nil);
Query.Connection := Connection;
Query.SQL.Text := 'CREATE TEMP TABLE Temp (TestRef CHAR(10))';
Query.ExecSQL;
Query := TPgQuery.Create(nil);
Query.Connection := Connection;
Query.SQL.Text := 'SELECT TestRef FROM Temp';
Query.FetchAll := False;
Query.Open;
end;
Is there a better solution?