Progress 4GL Display Buffer Lock Type

风流意气都作罢 提交于 2020-01-16 01:14:12

问题


I would like to ask if there is a way to display the current lock type of my buffer in a message box. Is there a way to do this?

I just want to check what type of lock there is on my buffer on run time.

For example: MESSAGE STRING(myBuffer:LOCK-TYPE).
Output: NO-LOCK/SHARE-LOCK/EXCLUSIVE-LOCK


回答1:


Not directly.

You can use the LOCKED( bufferName ) function (or the related attribute of a buffer handle object) to see if it is locked or not but you cannot distinguish between SHARE and EXCLUSIVE that way.

Really that ought to be enough -- if it is not locked then you are not causing any issues for other people. If it is locked, regardless of shared or exclusive, then nobody else can lock it. It is yours to enjoy if you originally asked for it EXCLUSIVE-LOCK. If you failed to specify a lock type or if you explicitly said SHARE-LOCK and now want to upgrade the lock you should use FIND CURRENT table EXCLUSIVE-LOCK. If you get the upgrade you have an exclusive lock. If not then it was either NO-LOCK or SHARE-LOCK (which you would know from your previous test).

In theory you might be able to scan the _LOCK VST and parse the information therein but that is a long ways from a simple function that might meet a requirement stated with the word "just" :)

It is also very dangerous -- the _LOCK VST is volatile (entries come and go faster than they can be read) and it is very easy to write code that seems to work in development but that chews up vast amounts of CPU time in production situations. Do NOT try it. It will not end well.

If you insist on ignoring me at least work from a snapshot created like so:

define variable i as integer no-undo.

define temp-table tt_lock no-undo like _lock
  index id-idx is unique primary _lock-id
  index recid-idx _lock-recid
  index usr-idx _lock-usr
  index tbl-idx _lock-table
.

empty temp-table tt_lock.

for each _lock while _lock._lock-usr <> ?:

  i = i + 1.
  if i > 10000 then leave.

  create tt_lock.
  buffer-copy _lock to tt_lock no-error.

end.

Note the use of WHILE in the FOR EACH. If you ignore me and try this approach I urge you to experiment. You will discover that WHILE is much faster than anything you might do with WHERE criteria.

The "if i > 10000 then leave." is a governor. You should have something similar in any code that toucjes _LOCK. It prevents it from accidentally going crazy on PROD systems with large lock tables.

No matter how much you think you want to do this you are making a mistake. Please don't go there. Experiment if you want to understand the issues or you are looking at a problem in your dev environment but please don't put this kind of code in production.



来源:https://stackoverflow.com/questions/26136842/progress-4gl-display-buffer-lock-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!