TStream实现多表查询

TStream实现多表查询

function TynFiredac.QuerySQLS(const ASQL, ASQL2: string; AStorageFormat: string = 'binary'): TStream;
var
  LStream1, LStream2: TStream;
begin
  Result := nil;
  if ASQL = '' then
    Exit;
  Result := TMemoryStream.Create;
  LStream1 := TMemoryStream.Create;
  LStream2 := TMemoryStream.Create;
  try
    try
      FDQuery1.Close;
      FDQuery1.SQL.Clear;
      FDQuery1.SQL.Add(ASQL);
      FDQuery1.Open;
      FDQuery1.SaveToStream(LStream1, TynStream.GetFDStorageFormat(AStorageFormat));
      LStream1.Position := 0;

      FDQuery1.Close;
      FDQuery1.SQL.Clear;
      FDQuery1.SQL.Add(ASQL2);
      FDQuery1.Open;
      FDQuery1.SaveToStream(LStream2, TynStream.GetFDStorageFormat(AStorageFormat));
      LStream2.Position := 0;

      TynStream.MergeStream(Result, LStream1, LStream2);
    except
      on E: Exception do
      begin
        Result := nil;
        Log.WriteLog('TynFiredac.QuerySQLs ' + E.Message);
      end;
    end;
  finally
    FDQuery1.Close;
    FDConnection1.Close;
    LStream1.Free;
    LStream2.Free;
  end;
end;

 

posted @ 2018-11-12 17:09  delphi中间件  阅读(713)  评论(0编辑  收藏  举报