ClientDataset作为缓存提交数据,后台分析并存储数据

function   tdsserver.updatecompany(delta:   olevariant;  
      var   msg:   widestring):   integer;  
  var  
      cdstemp:   tclientdataset;  
      i,   tempint:   integer;  
      cmdinsert,   cmddelete,   cmdupdate:   tadocommand;  
      sname,   chmsg:   string;  
      tempstr:   widestring;  
  begin  
      adoconnds.errors.clear;   //for   catch   the   error  
      cdstemp   :=   tclientdataset.create(self);  
      cmdinsert   :=   tadocommand.create(self);  
      cmddelete   :=   tadocommand.create(self);  
      cmdupdate   :=   tadocommand.create(self);  
      cmdinsert.connection   :=   adoconnds;  
      cmddelete.connection   :=   adoconnds;  
      cmdupdate.connection   :=   adoconnds;  
      result   :=   0;  
      cmdupdate.commandtext   :=   update   company   set    
          +   scompanyname   =   :scompanyname,  
          +   sheadname   =   :sheadname,   sheadtelnum   =   :sheadtelnum,ckind=:ckind,  
          +   ctype   =   :ctype,tsurvey   =   :tsurvey   where   scompanyid   =   :old_scompanyid;  
   
      cmddelete.commandtext   :=   delete   from   company   where   scompanyid   =   :old_scompanyid;  
   
      cmdinsert.commandtext   :=   insert   into   company    
          +   (scompanyid,   scompanyname,   sheadname,   sheadtelnum,ckind,ctype,   tsurvey)  
          +     values(:scompanyid,   :scompanyname,   :sheadname,   :sheadtelnum,:ckind,:ctype,   :tsurvey);  
   
      adoconnds.begintrans;  
      try  
          try  
              cdstemp.data   :=   delta;  
              cdstemp.first;  
              while   not   cdstemp.eof   do  
                  begin  
                      case   cdstemp.updatestatus   of  
                          usunmodified:  
                              begin  
                                  for   i   :=   0   to   cmdupdate.parameters.count   -   2   do  
                                      begin  
                                          sname   :=   cmdupdate.parameters.items[i].name;  
                                          cmdupdate.parameters.items[i].value   :=  
                                              cdstemp.fieldbyname(sname).value;  
                                      end;  
                                  cmdupdate.parameters.parambyname(old_scompanyid).value   :=  
                                      cdstemp.fieldbyname(scompanyid).value;  
                              end;  
                          usmodified:  
                              begin  
                                  for   i   :=   0   to   cmdupdate.parameters.count   -   2   do  
                                      begin  
                                        if   not   (cdstemp.fieldbyname(cmdupdate.parameters.items[i].name).isnull   )   then  
                                              begin  
                                                  sname   :=   cmdupdate.parameters.items[i].name;  
                                                  cmdupdate.parameters.items[i].value   :=  
                                                      cdstemp.fieldbyname(sname).value;  
                                              end;  
                                      end;  
                                  cmdupdate.execute;  
                              end;  
                          usinserted:  
                              begin  
                                  for   i   :=   0   to   cmdinsert.parameters.count   -   1   do  
                                      begin  
                                          sname   :=   cmdinsert.parameters.items[i].name;  
                                          cmdinsert.parameters.items[i].value   :=  
                                              cdstemp.fieldbyname(sname).value;  
                                      end;  
                                  cmdinsert.execute;  
                              end;  
                          usdeleted:  
                              begin  
                                  cmddelete.parameters.parambyname(old_scompanyid).value   :=  
                                      cdstemp.fieldbyname(scompanyid).value;  
                                  cmddelete.execute;  
                              end;  
                      end;  
                      cdstemp.next;  
                  end;  
              adoconnds.committrans;  
          except  
              adoconnds.rollbacktrans;  
              catchadoerror(tempint,   tempstr,   chmsg);  
              msg   :=   tempstr;  
              result   :=   tempint;  
          end;  
      finally  
          cdstemp.free;  
          cmdinsert.free;  
          cmddelete.free;  
          cmdupdate.free;  
      end;  
  end;  
   
  该函数中的delta是一个临时表,是clientdataset.delta,是返回的一个临时表!   
   

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值