DATASNAP資料提交之FIREDAC的TFDJSONDeltas

來源:互聯網
上載者:User

標籤:where   sap   rac   .com   end   text   mem   assign   var   

DATASNAP資料提交之FIREDAC的TFDJSONDeltas

FIREDAC的TFDJSONDeltas相當於CLIENTDATASET的DELTA,是作為CLIENTDATASET.DELTA的替代者出現的。

TFDJSONDeltas是多個資料集DELTA的集合,一次性可以提交多個資料集修改後的資料到資料庫。

服務端代碼:

function TServerMethods1.SaveData2(const accountNo, tableName: string; delta: TFDJSONDeltas): Boolean;
var
d: TfrmDB;
LApply: IFDJSONDeltasApplyUpdates;
begin
Result := False;
if (accountNo = ‘‘) or (tableName = ‘‘) or (delta = nil) 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 := ‘select * from ‘ + tableName + ‘ where 1=2‘;
d.qryOpen.Open;
LApply := TFDJSONDeltasApplyUpdates.Create(delta);
LApply.ApplyUpdates(0, d.qryOpen.Command);
Result := LApply.Errors.Count = 0;
except
on e: Exception do
begin
Result := False;
Log.WriteLog(‘TServerMethods1.SaveData2 ‘ + e.Message);
end;
end;
finally
d.qryOpen.Close;
GetDBPool(accountNo).Unlock(d);
SetTraceOff(d);
end;
end;

用戶端代碼:

procedure TForm1.btnSave2Click(Sender: TObject);
var
LDeltas: TFDJSONDeltas;
begin
if FDMemTable1.State in dsEditModes then // 向記憶體表提交修改
FDMemTable1.Post
else
Exit;
LDeltas := TFDJSONDeltas.Create;
TFDJSONDeltasWriter.ListAdd(LDeltas, ‘1‘, FDMemTable1);
if methods.SaveData2(‘0‘, ‘t1‘, LDeltas) then
Self.Caption := ‘save ok‘
else
Self.Caption := ‘save fail‘;
end;

 

DATASNAP資料提交之FIREDAC的TFDJSONDeltas

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.