简体   繁体   English

更新查询不适用于OrientDB中的eval()函数和参数

[英]Update query not working with eval() funtion and parametes in OrientDB

In my project i'm using Orientdb, some problem in update query. 在我的项目中,我使用的是Orientdb,更新查询中存在一些问题。

int amt = 100;
int recordsUpdated = db.command(new OCommandSQL("update A set id = eval('id - "+ amt +"') where eval('id - "+amt+"') > 0")).execute();

this is working fine. 这很好。 but, 但,

int recordsUpdated = db.command(new OCommandSQL("update A set id = eval('id - ?') where eval('id - ?') > 0")).execute(100,100);

or 要么

Map<String,Object> params = new HashMap<String,Object>();
params.put("amt", "100");
int recordsUpdated = db.command(new OCommandSQL("update A set id = eval('id - :amt') where eval('id - :amt') > 0")).execute(params);

is not working. 不管用。 please help me to make work. 请帮助我工作。

Substitution of variables doesn't work everywhere in the SQL, specially inside strings. 在SQL中,变量的替换并非在所有地方都有效,特别是在字符串内部。 You could concat the value like in 1st example or trying using context variables, like: 您可以像第一个示例那样连接值,或尝试使用上下文变量,例如:

OCommandSQL cmd = new OCommandSQL("update A set id = eval('id - $id') where eval('id - $id') > 0");
cmd.getContext().setVariable( "id", 100 );
int recordsUpdated = db.command(cmd).execute();

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

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