我有一個包含2個函數的包含文件。其中一個功能可以很好地工作,所以我不會在這裏包含它。我將包含導致問題的功能。交易鎖定在最後一個記錄上沒有釋放
的ss_update功能是一個引起我的問題,而不是釋放鎖,因爲我認爲它會。我終於可以通過這種方式添加查找當前的screenstate no-lock。聲明。我想知道是否有人能向我解釋這一點,以及是否有更好的方法來處理這種情況。
FUNCTION ss_update RETURNS INTEGER
(INPUT iUserName AS CHAR,
INPUT iScreenName AS CHAR,
INPUT iWidgetName AS CHAR,
INPUT iWidgetValue AS CHAR):
DEFINE VARIABLE retStatus AS INTEGER NO-UNDO.
FIND ScreenState EXCLUSIVE-LOCK WHERE ScreenState.userName = iUserName AND
ScreenState.screenName = iScreenName AND
ScreenState.widgetName = iWidgetName NO-ERROR.
IF AVAIL ScreenState THEN
DO:
IF ScreenState.widgetValue <> iWidgetValue THEN
DO:
ASSIGN
ScreenState.widgetValue = iWidgetValue.
END.
retStatus = 1.
END.
IF NOT AVAIL ScreenState THEN
DO:
CREATE ScreenState.
ASSIGN
ScreenState.screenStateId = NEXT-VALUE(seq-ScreenStateId)
ScreenState.userName = iUserName
ScreenState.screenName = iScreenName
ScreenState.widgetName = iWidgetName
ScreenState.widgetValue = iWidgetValue.
retStatus = 2.
END.
/* This was added to release the lock. */
FIND CURRENT screenstate NO-LOCK.
RETURN retStatus.
END FUNCTION.
我有代碼將連續多次調用更新函數。像這樣...
ss_update(USERID(LDBNAME(1)), "FindComp2.w", "t-ActiveOnly", t-ActiveOnly:SCREEN-VALUE).
ss_update(USERID(LDBNAME(1)), "FindComp2.w", "t-BadAdd", t-BadAdd:SCREEN-VALUE).
ss_update(USERID(LDBNAME(1)), "FindComp2.w", "LastCompany", company.companyId).
ss_update(USERID(LDBNAME(1)), "FindComp2.w", "rs-Filter", rs-Filter:SCREEN-VALUE).
ss_update(USERID(LDBNAME(1)), "FindComp2.w", "cb-Salesman", cb-Salesman:SCREEN-VALUE).
ss_update(USERID(LDBNAME(1)), "FindComp2.w", "cb-Search", cb-Search:SCREEN-VALUE).
ss_update(USERID(LDBNAME(1)), "FindComp2.w", "scr-Search", TRIM(scr-Search:SCREEN-VALUE)).
我遇到的問題是進度沒有釋放上次調用ss_update函數的鎖。我不得不添加查找當前screenstate無鎖來降級鎖。這看起來很醜陋,沒有正確編碼,不知道爲什麼發生這種情況,以及處理這個問題的正確方法是什麼。
優秀的湯姆。感謝您的解釋和解決方案。大大地學徒,它像一個魅力。 – dayv2005 2014-08-27 16:17:35