简体   繁体   English

DB.executeUpdate中的where子句进行错误更新

[英]error update with where clause in DB.executeUpdate compiere

i want to update isproven to N in table m_requisition 我想更新isproven表到N m_requisition

where m_requisition_id in xx_reqverification = 'value from input' 其中m_requisition_id中的xx_reqverification = 'value from input'

and docstatus in xx_reqverification = 'VO' docstatusxx_reqverification = 'VO'

StringBuffer s = new StringBuffer("UPDATE M_Requisition R SET")
    .append(" IsProven=").append("'N'")
    .append(" FROM XX_ReqVerification AS RV")
    .append(" WHERE RV.DocStatus='VO'")
    .append(" AND RV.XX_ReqVerification_id=")
    .append(veri.getXX_ReqVerification_ID())
    .append(" AND R.M_Requisition_id = RV.M_Requisition_id").append(";");
DB.executeUpdate(s.toString(), null);

but this code throw an error 但是这段代码抛出一个错误

DB.saveError: DBExecuteError - ERROR: syntax error at or near "where" DB.saveError:DBExecuteError-错误:“ where”或附近的语法错误

i am using postgresql for database 我正在使用postgresql数据库

when i print s to console 当我打印到控制台

UPDATE M_Requisition R SET IsProven='N' 
FROM XX_ReqVerification AS RV 
WHERE RV.DocStatus='VO' AND RV.XX_ReqVerification_id =1000040 
      AND R.M_Requisition_id = RV.M_Requisition_id;

i don't know what wrong with my code, please help me fix this. 我不知道我的代码有什么问题,请帮助我解决此问题。

While it's not an answer to your question specifically - see my comment/question regarding that above... 虽然这并不是您的问题的具体答案,但请参阅我对上述问题的评论/问题...

Updating the database directly like this would not be a recommended approach to customizing Adempiere. 像这样直接更新数据库不是推荐的自定义Adempiere的方法。 It could potentially break the consistency in the application as you would be bypassing the inbuilt mechanisms of the application such as WorkFlows , ModelValidators and perhaps Callouts . 它有可能打破一致性的应用程序,你会被绕过应用程序的内在机制,如工作流ModelValidators也许标注 These mechanisms, along with the "Application Dictionary" exist to allow customization of the ERP application without risking inconsistencies. 这些机制与“应用程序字典”一起存在,以允许自定义ERP应用程序而不会带来不一致的风险。

If you used the inbuilt mechanisms to save an entity there would be no risk of breaking the application. 如果使用内置机制保存实体,则不会有破坏应用程序的风险。 Every "entity" in the application model extends a class called PO (Persistent Object) that has a save() method. 应用程序模型中的每个“实体”都会扩展一个名为PO(持久性对象)的类,该类具有save()方法。 Using this instead of a direct DB update would ensure all the rules defined in the Application Dictionary are followed as well as ensuring the functionalities required via the mechanisms mentioned above are run. 使用此方法代替直接的数据库更新将确保遵循应用程序字典中定义的所有规则,并确保运行通过上述机制所需的功能。

It should actually be an easier route with something like... 实际上,这应该是一条更简单的路线,例如...

MRequisition req = new MRequistion(getCtx(), requisition_id, get_TrxName());
req.setDocStatus(DOCSTATUS_Voided);
req.setIsApproved(false);
req.save();

I can also recommend reading the following page from the wiki on extending Adempiere 我还建议您阅读Wiki上有关扩展Adempiere的以下页面

One final point, there is often logic associated with a Document Status changes that it might be worth investigating too! 最后一点,通常是与文档状态更改相关的逻辑,这可能也值得研究!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM