[转帖] 如何处理错误 “Row Changed Between Retrieve and Update”
<table cellspacing="0" cellpadding="0" width="95%" align="center" border="0"><center><tbody><tr><td height="22"> </td><td width="100%" height="22"><div align="left"><p align="center"><b>如何处理错误 “Row Changed Between Retrieve and Update”</b></p></div></td><td height="22"> </td></tr><tr><td colspan="3"> </td></tr><tr><td height="560"> </td><td width="100%"><div align="left"><b> Row Changed Between Retrieve and Update</b></div><p align="left"> This is a common but frustrating error that can create real problems. The cause for this error is one or more of the following: </p><div align="left"><blockquote><ol><li><font color="#006443">A primary key for the table is not listed in the Update Properties for the DataWindow.</font>
</li><li><font color="#006443">The primary key selected allows and has duplicates.</font>
</li><li><font color="#006443">The Update Properties for the DataWindow are improperly set for the needs of the application.</font>
</li><li><font color="#006443">The data did actually change.</font>
</li></ol></blockquote></div><p align="left"> If no primary key is listed, this is usually the result of either the DataWindow being created on a table that did not have a primary key when the DataWindow was created or the DataWindow was created and Allow Updates was not checked and later checked. </p><p align="left"> NOTE: If at a later time, the Allow Updates is checked and you select the Table to Update, the Updateable Columns and Key Columns MUST be selected since they are not automatically selected.</p><p align="left"> There are cases that the primary key selected is not a "true primary key" in that there can be duplicates records for each key. In this case the error will only occur when there are actual duplicates for the selected key. Often this error will go undetected for a long time until a duplicate value is present. This is a hard one to find since the error will occur on the duplicate value only. This appears to be an intermitted error.</p><p align="left"><b> <span>Specifying the WHERE clause for update/delete</span></b></p><p align="left"> Sometimes multiple users are accessing the same tables at the same times and in cases, they may be actually accessing the same data at the same time. This may be a desired situation and the correct update/delete specification will protect the data from corruption.</p><p align="left"><b> <span>Key Columns:</span></b>
</p><p align="left"> This is the least restrictive and will data corruption. This can only be safely used in single user environments and in multi-user environments when the developer can be 100% sure that only one user at a time will access the data.</p><p align="left"> The danger of this is that since the key column is the only column specified in the WHERE clause, another user can change the data after you retrieve it and when you save, your data will over write the other users data. The only warning you would get is if the key column changed, which is very unlikely.</p><p align="left"><b> <span>Key and Updateable Columns:</span></b>
</p><p align="left"> This is the PowerBuilder default and provides the greatest level of granularity but may be too restrictive for the needs of the application. The WHERE clause contains ALL the updateable columns that were selected in the Update Properties of the DataWindow NOT just the updated (modified) columns.</p><p align="left"> This will guarantee that only one user can update a row at a time. The problem may arise when two users retrieve the same row and each changes different data elements (i.e. one user updates the address of the customer and another updates the middle name). The first user to save the data will be OK and the other user update will fail.</p><p align="left"><b> <span>Key and Modified Columns</span></b>
</p><p align="left"> This is usually a good setting for most multi-user applications. This allows for multiple users to access the same row and both make changes to different data elements of the row.</p><p align="left"> This would prevent the problem above (i.e. one user updates the address of a customer and another updates the middle name). With this setting, both users would be able to successfully save the data without any negative impact on the other users data.</p><p align="left"><b> <span>Correcting Changed Data</span></b></p><p align="left"> To correct data errors caused from data changing between retrieve and update (except for duplicate keys) the following method is an example of what can be employed:</p><p align="left"> If a row is changed, the DbError event will be triggered with a value of –3 in the argument sqldbcode and the row number of the failure in the argument row. A message can be displayed to the user and the row highlighted for the user to see. Allow the user the option to re-retrieve the changed row or discard it. If the user chooses to re-retrieve the changed data, use the ReSelect() PowerBuilder function. This will re-retrieve ONLY the row specified. This will allow the user to see the changes to the row and permit them to make any additional changes they desire. </p><blockquote><p align="left"><font color="#006443"><b>IMPORTANT:</b> PowerBuilder will stop the update process upon encountering the first error. The update process can be re-called or stopped at this error. It is usually best to continue the update process. This will update the database with all other changes and/or mark any other error rows. If the row that caused the error is in the Filter buffer, you must unfilter it if you want the user to correct the problem.</font></p></blockquote><p align="left"> Code a –1 as the return value for the DbError event, this will suppress the default PowerBuilder error box and allow you to display your own message. </p></td><td height="560"><p> </p><p> </p></td></tr><tr><td> </td><td width="100%"> </td><td> </td></tr></tbody></center></table> 英文啊,看不懂 <p>1.空字符串和 Null 不同 ,可能造成。(oracle 中 Null和'' 是有区别的)</p><p>2. 行不唯一,一笔资料对应多行。Sql 错误。</p><p>3.该资料被他人修改。</p><p></p> 在更新属性中,使用Key Columns解决这个问题,但是带来的后果就是数据只能保存最后一个人的更新。在多人共享的情况下会导致问题。
页:
[1]