zoukankan      html  css  js  c++  java
  • 一次得到多个数据集

    function GetDataSetsByJson(SQL_Statement : string) : TFDJSONDataSets; //得到多个数据集 server
    {SQL_Statement格式 'Name' : '名称','CommandText':'SQL语句' } var jo : TJSONObject; jp : TJSONPair; i : Integer; Arr: TArr<TFDQuery>; begin {$REGION '一次得到多个数据集'} jo := TJSONObject.ParseJSONValue(Trim(SQL_Statement),True) as TJSONObject; if not Assigned(jo) then Result := nil; try Result := TFDJSONDataSets.Create; Setlength(Arr,jo.Count); for i := 0 to jo.Count - 1 do begin jp := jo.Pairs[i]; Arr[i] := TFDQuery.Create(Self); Arr[i].Connection := FDConnection1; Arr[i].SQL.Clear; Arr[i].SQL.Add(jp.JsonValue.Value); Arr[i].open; TFDJSONDataSetsWriter.ListAdd(Result,jp.JsonString.Value,Arr[i]); end; finally jo.Free; end; {$ENDREGION} end;

     调用

    function TDM.getTables_Json(ArraySQL: array of string; aFDMemTables: array of TFDMemTable) : Boolean; //client
    var
      aServer: TUsegearClient;
      LDataSetList: TFDJSONDataSets;
      aDataSet: TFDAdaptedDataSet;
      jp : TJSONPair;
      jo : TJSONObject;
      i,j : Integer;
    begin
    {$REGION '一次得到多个数据集'}
      Result := False;
      if (Length(arraySQL) <> Length(aFDMemTables)) then
        begin
          raise Exception.Create('数组数不一致,请检查');
          Exit
        end;
        aServer := TUsegearClient.Create(DSRestConnection1);
        try
          jo := TJSONObject.Create;
          for I := Low(ArraySQL) to High(ArraySQL) do    //准备sql statement
            begin
              jp := TJSONPair.Create('T'+ i.ToString,ArraySQL[i]);
              jo.AddPair(jp);
            end;
          try
            LDataSetList := aServer.GetDataSetsByJson(jo.ToString);
            ShowMessage(TFDJSONDataSetsReader.GetListCount(LDataSetList).ToString);
            j := TFDJSONDataSetsReader.GetListCount(LDataSetList);
            for I := 0 to j - 1 do
              begin
                aDataSet := TFDJSONDataSetsReader.GetListValueByName(LDataSetList, 'T'+ i.ToString);
                aFDMemTables[i].Close;
                aFDMemTables[i].AppendData(aDataSet);
              end;
            Result := True;
          except
            Result := False;
          end;
        finally
          jo.Free;
          aServer.Free;
        end;
    {$ENDREGION}
    end;
      if ClientDMUnit.Dm.getTables_Json(['select * from ProductInfo','select * from ProductParams'],[u3FDMemTable,u2FDMemTable]) then //这里在程序中调用
        begin
           u3FDMemTable.Open;
           u2FDMemTable.Open;
        end;
  • 相关阅读:
    C. Shaass and Lights 解析(思維、組合)
    D. Binary String To Subsequences(队列)(贪心)
    CodeForces 1384B2. Koa and the Beach (Hard Version)(贪心)
    CodeForces 1384B1. Koa and the Beach (Easy Version)(搜索)
    CodeForces 1384C. String Transformation 1(贪心)(并查集)
    CodeForces 1384A. Common Prefixes
    POJ-2516 Minimum Cost(最小费用最大流)
    POJ3261-Milk Patterns(后缀数组)
    HDU-1300 Pearls(斜率DP)
    HDU-4528 小明系列故事-捉迷藏(BFS)
  • 原文地址:https://www.cnblogs.com/usegear/p/14226061.html
Copyright © 2011-2022 走看看