为什么在更新数据窗口之前复制状态?

时间:2015-03-10 18:07:45

标签: powerbuilder

我刚刚在传统的Powerbuilder应用程序中遇到了以下代码,我想知道是否真的需要它,或者是否有人处于腰带和吊带的情绪中。

// Create a datastore that we can capture database errors in
lds_ds = create n_cst_base_datastore

// set up the datastore with the state of the datawindow
ll_Rc = adw_the_dw.GetFullState ( lblob )
ll_rc = lds_ds.SetFullState(lblob)

// set the transaction object
li_rc = lds_ds.SetTransObject(sqlca)

// call the update
li_Rc = lds_ds.update()

if li_rc = 1 then   // if successful then commit
    if ab_reset then
        adw_the_dw.ResetUpdate()
        COMMIT using sqlca;  // should check the commit return code
    end if
    li_return = 1
elseif li_rc = -1 then  // otherwise show error message
    if lds_ds.of_get_error() then
        lnv_error.of_process_sql_error( lds_ds.of_get_sql_code(), lds_ds.of_get_sql_errtext() )
    end if
    ROLLBACK;
    li_return = -1
else // better never happen
    ROLLBACK;
    li_return = -1
end if

在我看来,只要在这种情况下直接更新DataWindow就可以获得相同的效果,因为我们没有在多个DW之间进行协调

2 个答案:

答案 0 :(得分:1)

解释它的一个理论是这两个祖先对象(DataStore和DataWindow)的功能在某种程度上是不同的。在n_cst_base_datastore或其祖先(of_前缀函数表明)中有非常明显的自定义,但是从这段代码中,不可能告诉DataWindow的祖先(或者即使它有一个祖先)。

DataWindows和DataStores之间的功能也存在差异,以视觉特性为中心。例如,某些DataWindow函数失败将产生可视消息,而DataStore re的等效失败则不会。 (SetFilter()浮现在脑海中,但我现在无法确认这是否是一个例子。)

很难从您提供的代码段告诉目标,但我可以想象一些。

祝你好运。

答案 1 :(得分:1)

本节:

elseif li_rc = -1 then  // otherwise show error message
if lds_ds.of_get_error() then
    lnv_error.of_process_sql_error( lds_ds.of_get_sql_code(), lds_ds.of_get_sql_errtext() )
end if
ROLLBACK;
li_return = -1

可能会导致锁定问题,具体取决于何时向用户显示错误消息。如果一个消息框被抛出并且用户已经离开了当天,那么您可能会留下一个打开的事务。由于更新失败了,最好捕获错误,回滚事务,然后向用户显示错误。