关于update并行的问题

qxksos 2003-01-15 01:55:31
系统是C/S结构,数据库是oracle8.1.7
其中有一段程序的是往数据库的一个表里插数据。
我写了一个数据窗口dw_1,先往数据窗口里插数据。
然后dw_1.update().
如果只有一个客户端执行该程序,没有任何问题,
但是如果多用户同时执行,却只有一个更新成功,去他的都失败了。
oracle应该可以并发插入数据,能不能dw_1.update也并发执行呀。
或者让它保持等待状态,等占用该表的别的程序运行完了再执行,而不要立刻报错返回
...全文
362 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
ungt 2003-01-26
  • 打赏
  • 举报
回复
关于updated的并行问题,我也遇到过类似的,与大家交流。

我的系统结构是c/s b/s的,用户通过bs录入和查询数据
我通过bs在后台修改维护数据,只要修改完数据后作一次datawindow.update(),用户通过bs查询数据时就只能等待,只有我作一次disconnect using sqlca后,查询就可以执行了。我还没找到合适的解决方法,难道作一次数据操作都先connect完成后再作disconnect吗?系统效率太低了吧?

请大家指教!
crimeace 2003-01-18
  • 打赏
  • 举报
回复
在UPDATE之前再生成序列号(主键的插入值吧)
andyzq 2003-01-16
  • 打赏
  • 举报
回复
设置row->update properties属性
if dw_1.update() = 1 then
commit;
else
rollback;
end if
北亳-Rayon 2003-01-16
  • 打赏
  • 举报
回复
在pb的数据窗口里面有菜单[rows]->update properties
里面的where clause for update/delete
根据需要!

设置一下!
flymeng 2003-01-16
  • 打赏
  • 举报
回复
在成功之后没有commit;或失败之后没有rollback
boygong 2003-01-16
  • 打赏
  • 举报
回复
你插入数据时一定是主鍵重复了。。。。。。。。
lovezpl 2003-01-15
  • 打赏
  • 举报
回复
A primary key for the table is not listed in the Update Properties for the DataWindow.
The primary key selected allows and has duplicates.
The Update Properties for the DataWindow are improperly set for the needs of the application.
The data did actually change.
  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.

  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.

  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.

  Specifying the WHERE clause for update/delete

  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.

  Key Columns:

  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.

  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.

  Key and Updateable Columns:

  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.

  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.

  Key and Modified Columns

  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.

  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.

  Correcting Changed Data

  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:

  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.

IMPORTANT: 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.

  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
qxksos 2003-01-15
  • 打赏
  • 举报
回复
dw_1.update的返回值时-1呀
seasideboy 2003-01-15
  • 打赏
  • 举报
回复
看看错误代码是什么?

752

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧