当前位置: 代码迷 >> PB >> update与insert,该怎么解决
  详细解决方案

update与insert,该怎么解决

热度:98   发布时间:2016-04-29 06:04:50.0
update与insert
for li_n =1 to m -1 step 1
ll_sn++
  ls_tables   = stu_parm.text[row] 
   ll_tables_no = stu_parm.sgno[row]
ll_date =CDT.DBToday()
ll_time =cdt.dbNow()
insert into ho_creditcard_handle
            (text,sn,date,time,tables,tables_no,
userid,Log_ncard,Log_user,deleflag)
 values(:ll_text,
        :ll_sn,
  :ll_date,
  :ll_time,
  :ls_tables,
  :ll_tables_no,
  :casher.uid,
  :Card_no,
  :casher.uid,
              0) 
 using Hotel_db.trans();
 
if Hotel_db.trans().sqlcode < 0 then
Rollback Using Hotel_db.trans();
MessageBox('提示','数据保存失败!')
return
end if

//end if

commit using Hotel_db.trans();
row ++
next
大家帮看看上面的跟下面的代码多次保存效果能一样吗

for li_n =1 to m -1 step 1 
  ll_sn ++
          free.object.tables[1]    = stu_parm.text[row] 
  free.object.tables_no[1] = stu_parm.sgno[row]
  free.object.deleflag[1]  = 0
  free.object.userid[1]    = casher.uid
  free.object.Log_ncard[1] = Card_no
  free.object.Log_user[1]  = casher.uid
  free.object.sn[1]   = ll_sn
  free.object.date[1] = CDT.DBToday()
  free.object.time[1] = cdt.dbNow()
  free.update()
      IF free.Update() <> 1 then
             ROLLBACK USING Hotel_DB.Trans();
Messagebox( "","保存错误!" )
return
End if

               COMMIT USING Hotel_DB.Trans();
    //free.
 //messagebox('',1)
  row ++

next
------解决方案--------------------
引用:
for li_n =1 to m -1 step 1
ll_sn++
  ls_tables   = stu_parm.text[row] 
   ll_tables_no = stu_parm.sgno[row]
ll_date =CDT.DBToday()
ll_time =cdt.dbNow()
insert into ho_creditcard_handle
        ……


大致看了一下,按你的逻辑2段代码没什么区别。
第二段你可以优化一下, 把 free.object.tables[1] 中的1换成循环的变量li_n,先把所有的数据都插入到DW中 ,最后一起update(),这样效率应该会高些。
  相关解决方案