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


    网上有一些讲以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;

  • 相关阅读:
    HYSBZ 1500 [NOI2005]维修数列 splay
    The 15th Zhejiang University Programming Contest
    工作小助手-v1.0正式上线,欢迎体验!!!
    登录窗体登录失败但是MainForm依然弹出无法结束的解决方法
    报错'cannot change visible in onshow or onhide'
    release模式发布软件的方法
    发布软件时因为窗体自动加载次序不对导致报错00000000
    修改类别 (类实现)两种方法
    从记事本导入记录
    快速粘贴
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/2368617.html
Copyright © 2020-2023  润新知