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

网上有一些讲以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 @ 2012-02-26 14:23  delphi中间件  阅读(2029)  评论(0编辑  收藏  举报