2014-11-25 51 views
1

在我的项目中,我使用Orientdb,更新查询中出现了一些问题。更新查询不适用于OrientDB中的eval()函数和参数

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

这工作正常。但是,

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

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); 

不工作。 请帮我做工作。

回答

2

变量替换在SQL中无处不在,特别是在字符串内部。你可以像第一个例子那样连接数值或尝试使用上下文变量,如:

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();