提交主从表的多个已经修改的数据

网上有一些讲以RAD方式设置主从表的演示,但是在实际当中不实用。

function TsvrDM.ApplyUpdates(const ModuleId: WideString;sqlId:ShortInt; Delta0,
  Delta1, Delta2, Delta3: OleVariant): Shortint;
const
  sql='Select * from %s where 1<>1'; 
var
  aData: array of OleVariant;
  i:integer;
  conn:TADOConnection;
  qry:TADOQuery;
  dsp:TDataSetProvider;
  errCount:integer;
begin
  try
    Result :=0;
    tableList.Clear;
    tableList.DelimitedText:=GetSqlCommand(ModuleId,sqlid); // table name list
    if tableList.Count = 0 then
    begin
      Result :=0;
      exit;
    end;
    if Delta0 <>Null then
    begin
      SetLength(aData, 1);
      aData[0]:=DeCompressData(Delta0);
    end;
    if Delta1<>Null then
    begin
      SetLength(aData,1);
      aData[1]:=DeCompressData(Delta1);
    end;
    if Delta2<>Null then
    begin
      SetLength(aData,2);
      aData[2]:=DeCompressData(Delta2);
    end;
    if Delta3<>Null then
    begin
      SetLength(aData,3);
      aData[3]:=DeCompressData(Delta3);
    end;
    conn:=ConnPool.Lock;
    qry:=QryPool.Lock;
    dsp:=DSPPooler.Lock;
    conn.BeginTrans;
    try
      try
        qry.Connection := conn;
        dsp.DataSet := qry;
        for i:=Low(adata) to High(adata) do
        begin
          qry.Close;
          qry.SQL.Clear;
          qry.SQL.Text:=Format(sql,[tableList.Strings[i]]);  // table name
          qry.Open;
          if (qry.Active) and (aData[i]<>Null) then
            dsp.ApplyUpdates(aData[i],0,ErrCount);
          qry.Close;
        end;
      finally
        ConnPool.Unlock(conn);
        QryPool.UnLock(qry);
        DSPPooler.UnLock(dsp);
      end;
      conn.CommitTrans;
    except
      Result:=0;
      conn.RollbackTrans;
      Exit;
    end;
    Result :=1;
  except
    Result :=0;
    Exit;
  end;
end;

posted @   delphi中间件  阅读(2047)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示