• 主页
  • API 调用
  • 基础类
  • 控件与界面
  • 数据库相关
  • DataWindow
  • 项目管理
  • Web 应用
  • 脚本语言

再叙Row changed between retrieve and update.错误问题

neil 湖北创诺安科技有限公司 经理  2002-03-12 12:44:03
假如你有大量数据未update,
在第一次update之后进行校验数据,如果条件不符合.
则 ROLLBACK ,让用户再次修改,这个时候就不能用RETRIEVE,(引起用户输入数据丢失.),在未retrieve之前,再次保存,则也报此错误.请教大家如何解决的?.
保存按扭的类代码如下:

dw_1.settransobject(sqlca)
dw_1.update()
//未列出 sqlcode 返回值的判断
if 条件不符合 then
rollback using sqlca
return
else
commit using sqlca
dw_1.retrieve()
end if


...全文
955 点赞 收藏 11
写回复
11 条回复
圣殿骑士18 2002年03月13日
to
llitcwl(中国龙)
如何修改原始缓冲区的值?
回复 点赞
spring_cj 2002年03月13日
如果要解决这样的问题的话就不能用update,应该一条记录一条记录的往数据库中里写。
1、先判断纪录是新增加的还是修改的。
2、如果是新增加的就insert,如果是修改的就update.如果出错return。


回复 点赞
llitcwl 2002年03月13日
修改原始缓冲区的值:
再做一个数据源一样的DS,把值改回去看行不行?

dw_1.Object.Data.Original=lds_1.object.data

这种写法只能写在行数没变化,只有修改时,如有变化只好一行一行改
回复 点赞
nana11 2002年03月13日
预防为主
回复 点赞
2000pinbo 2002年03月12日
to neil(尼奥--系统资源严重不足,勿找Neil):
解决的方法很简单,换个思路。
你用update时
for i=1 to total
//监测是否值有错
next
if dw_1.update(true,false)>0 then
commit;
dw_1.resetupdate()//清除了数据窗口的更新状态
else
rollback;
end if
回复 点赞
pigherd 2002年03月12日
强烈关注!
回复 点赞
Hanson_bati_zhu 2002年03月12日
to: zhanwei(詹维)
择两句就够了
怎么全COPY上来了

看着眼晕
呵呵
8-)
回复 点赞
zhanwei 2002年03月12日
参考一下:
In PowerBuilder, you must use the SetTrans or the SetTransObject method to specify the database connection before the Update method will execute. When you use SetTransObject, the more efficient of the two, you must do your own transaction management, which includes issuing the SQL COMMIT or ROLLBACK statement to finalize the update.
In PowerJ, depending on the connection properties you specify for the control, the setTrans or setTransObject calls may be generated for you.
Test success/failure code
It is good practice to test the success/failure code after calling Update. In addition to checking the return value of Update, check the SQLNRows property of the transaction object, which indicates the number of rows affected, to make sure the update changed at least one row. Since the database vendor supplies this number, its meaning may not be the same in every DBMS.
By default, Update resets the update flags after successfully completing the update. However, you can prevent the flags from being reset until you perform other validations and commit the changes. When you are satisfied with the update, call ResetUpdate to clear the flags so that items are no longer marked as modified.
Use SetTransObject when resetflag is FALSE
You would typically use SetTransObject, not SetTrans, to specify the transaction object for the DataWindow control or DataStore when you plan to update with the resetflag argument to FALSE. Only SetTransObject gives you control of when changes are committed.
If you want to update several tables in one DataWindow control or DataStore, you can use Modify to change the Update property of columns in each table. To preserve the status flags of the rows and columns, set the resetflag argument to FALSE. Because the updates all occur in the same DataWindow control or DataStore, you cannot allow the flags to be cleared until all the tables have used them. When all the updates are successfully completed and committed, you can call ResetUpdate to clear the changed flags in the DataWindow. For an example of this technique, see Modify.
If you are updating multiple DataWindow controls or DataStores as part of one transaction, set the resetflag argument to FALSE. This will prevent the DataWindow from "forgetting" which rows to update in case one of the updates fails. You can roll back, try to correct the situation, and update again. Once all of the DataWindows have been updated successfully, use COMMIT to finalize the transaction and use ResetUpdate to reset the DataWindow's status flags.
If you call Update with the resetflag argument set to FALSE and do not call ResetUpdate, the DataWindow will attempt to issue the same SQL statements again the next time you call Update.
Caution
If you call Update in an ItemChanged event, be sure to set the accept argument to FALSE to avoid an endless loop and a stack fault. Because AcceptText triggers an ItemChanged event, you cannot call it in that event (see AcceptText).
If you call Update in the ItemChanged event, then the item's old value is updated in the database, not the newly entered value. The newly entered value in the edit control is still being validated and won't become the item value until the ItemChanged event is successfully completed. If you want to include the new value in an update in the ItemChanged event, use the appropriate SetItem method first.
Apply GetChanges after deleting rows in a distributed application
If a DataWindow or data store is populated using SetChanges or SetFullState, and an Update is done that includes deleted rows, the deleted rows remain in the delete buffer until a subsequent GetChanges is applied to the DataWindow or data store.
Web DataWindow client control Calling Update in the client control causes changed data to be passed to the server and updated there. Data is retrieved again and the page is reloaded.
If the DataWindow object has retrieval arguments, they must be specified in the HTMLGen.SelfLinkArgs property. For more information, see the HTMLGen.property, the Retrieve method, and the DataWindow Programmer's Guide.
All methods that reload the page perform an AcceptText before sending data back to the server. If the method fails (returns -1), this means that pending data changes were not accepted and nothing was sent back to the server. In this situation the ItemError event occurs.
Frequent updating improves performance The Web DataWindow DataWindow client maintains the state of the server component in string form and the information is sent to the server and back again with every request. If the user hasn't modified the data, the amount of client side state information is small. The amount of client side state information grows proportionally to the number of outstanding changes that have not been updated to the database. When the client control or a server-side script calls the Update method, the state information returns to the minimum amount, so calling Update frequently can reduce the amount of information transferred back and forth.
Web DataWindow server component Call GetLastError and GetLastErrorString to get information about database errors that cause SetAction, Update, Retrieve, and RetrieveEx to return -1.
Web DataWindow PSWebDataWindowClass If Retrieve or Update return -1, the OnDBError event is triggered.
Events Update may trigger these events:
DBError
SQLPreview
UpdateEnd
UpdateStart
If AcceptText is performed, it may trigger these events:
ItemChanged
ItemError
回复 点赞
liulee 2002年03月12日

简单而言,你写入时,服务器上的数据对你retrieve出来的数据比较而言,已经脏了。

控制采用 llitcwl 的第三条原则比较合理。

实在没有办法的时候,重新检索,重做数据。:(



回复 点赞
llitcwl 2002年03月12日
基本上还是应该从预防出发。
回复 点赞
llitcwl 2002年03月12日
如果已出现这种错误想要在不丢失数据的情况下提交是非常困难的,只有一个办法,就是将数据库中现有的值取出,修改DW的原始值,使PB认为数据库的数据未变化,但我是从来不这么做的。
解决办法:
1:如果你的数据并发性要求不是很高,可将DW的UPDATE属性设置为主键,这样PB在UPDATE时只判断主键是否变动,这很简单,也很有效
2:将数据库中现有的值取出,修改DW的原始值,使PB认为数据库的数据未变化,最有效但代码复杂
3:在设计程序时尽量避免在本DW外修改同一张表数据,这种只能防止你的程序在一个用户使用时造成的错误,不能防止因不同用户修改同一记录造成的记录,不是根本解决办法。
回复 点赞
发动态
发帖子
PowerBuilder
创建于2007-09-28

591

社区成员

6.6w+

社区内容

PowerBuilder 相关问题讨论
社区公告
暂无公告