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?