DATASNAP資料序列之FIREDAC的TFDJSONDataSets

來源:互聯網
上載者:User

標籤:sql   procedure   final   client   mac   cli   eth   個數   記憶體   

DATASNAP資料序列之FIREDAC的TFDJSONDataSets

DELPHI XE5開始增加了新的資料引擎——FIREDAC,它是跨平台的資料引擎,WINDOWS、LINUX、MAC、APP。。。。。。都可以使用。

隨之DATASNAP也增加了新的遠程方法返回資料類型——TFDJSONDataSets。

顧名思義TFDJSONDataSets是資料集列表,是多個資料集的集合,DATASNAP通過它一次可以返回多個查詢結果資料集。

服務端代碼:

function TServerMethods1.QuerySql2(const accountNo, sql: string): TFDJSONDataSets;
var
d: TfrmDB;
begin
Result := nil;
if (accountNo = ‘‘) or (sql = ‘‘) then
Exit;
d := GetDBPool(accountNo).Lock;
if not Assigned(d) then
Exit;
try
try
SetTraceOn(d);
d.qryOpen.Close;
d.qryOpen.sql.Clear;
d.qryOpen.sql.Text := sql;
d.qryOpen.Open;
Result := TFDJSONDataSets.Create;
TFDJSONDataSetsWriter.ListAdd(Result, ‘1‘, d.qryOpen);
except
on e: Exception do
begin
Result := nil;
Log.WriteLog(‘TServerMethods1.QuerySql2 ‘ + e.Message);
end;
end;
finally
d.qryOpen.Close;
GetDBPool(accountNo).Unlock(d);
SetTraceOff(d);
end;
end;

用戶端代碼:

首先引用 Data.FireDACJSONReflect

procedure TForm1.btnQuery2Click(Sender: TObject);
var
LDataSets: TFDJSONDataSets;
LDataSet: TFDDataSet;
begin
DataSource1.DataSet := FDMemTable1;
LDataSets := methods.QuerySql2(‘0‘, ‘select * from t1‘);
LDataSet := TFDJSONDataSetsReader.GetListValueByName(LDataSets, ‘1‘);
FDMemTable1.Close;
FDMemTable1.Data := LDataSet;
end;

可以看到用戶端是使用TFDMemTable記憶體表,而不是TCLIENTDATASET。

筆者已經多次提到過,FIREDAC引擎是使用TFDMemTable記憶體表來作為TCLIENTDATASET的替代。

TCLIENTDATASET的資料序列格式是OLEVARIANT,它是微軟COM的資料格式。

現在DATASNAP正在去除對微軟COM的過分依賴。

DATASNAP資料序列之FIREDAC的TFDJSONDataSets

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.