使用字符串作为带有SQL命令的RID

时间:2014-12-29 17:20:52

标签: orientdb

在Orient-DB 2.0 rc1上使用Java api。 是否可以将字符串用作RID?

文档:https://github.com/orientechnologies/orientdb/wiki/SQL-Update#example-3-add-a-value-into-a-collection  更具体地说明SQL Commands

部分

收到JSON:

{
    userRID:"#100:100",
    group:"someCode"
}

JAVA CODE(xtend脚本):

def addUserInGroup(Message<JsonObject> message){
    val params = new JsonObject() => [
        putString("userId", message.body().getString("userRID"));
        putString("code", message.body().getString("group"));
    ]

    var queryCommand= "update Table add users=:userId where code=:code";

    Map<String, Object> paramsFormatted = params.toMap();

    database.command( new OCommandSQL(queryCommand) ).execute(paramsFormatted);
}

表格结构:

users : linklist (user object)
code : string

当我在工作室中运行以下命令时,它们都可以工作:

update Table add users=(Select @rid from User where @rid=#100:100) where code='someCode'
update Table add users=#100:100 where code='someCode'

但这些命令都不适用于API。我猜测我使用RID的方式有问题。

SEVERE: Exception in Java verticle
com.orientechnologies.orient.core.sql.OCommandSQLParsingException: Error on parsing command at position #29: Found unexpected keyword '=:USERID' while it was expected '[=]'. Use UPDATE <class>|cluster:<cluster>> [SET|ADD|PUT|REMOVE|INCREMENT|CONTENT {<JSON>}|MERGE {<JSON>}] [[,] <field-name> = <expression>|<sub-command>]* [LOCK <NONE|RECORD>] [UPSERT] [RETURN <COUNT|BEFORE|AFTER>] [WHERE <conditions>]
Command: update SecureAccess add users=:userId where code=:code
-------------------------------------^
    at com.orientechnologies.orient.core.sql.OCommandExecutorSQLAbstract.throwSyntaxErrorException(OCommandExecutorSQLAbstract.java:89)
    at com.orientechnologies.common.parser.OBaseParser.parserRequiredKeyword(OBaseParser.java:317)
    at com.orientechnologies.orient.core.sql.OCommandExecutorSQLUpdate.parseAddFields(OCommandExecutorSQLUpdate.java:605)
    at com.orientechnologies.orient.core.sql.OCommandExecutorSQLUpdate.parse(OCommandExecutorSQLUpdate.java:129)
    at com.orientechnologies.orient.core.sql.OCommandExecutorSQLUpdate.parse(OCommandExecutorSQLUpdate.java:59)
    at com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate.parse(OCommandExecutorSQLDelegate.java:56)
    at com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate.parse(OCommandExecutorSQLDelegate.java:37)
    at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.command(OAbstractPaginatedStorage.java:1150)
    at com.orientechnologies.orient.core.command.OCommandRequestTextAbstract.execute(OCommandRequestTextAbstract.java:63)
    at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.command(ONetworkProtocolBinary.java:1179)
    at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.executeRequest(ONetworkProtocolBinary.java:385)
    at com.orientechnologies.orient.server.network.protocol.binary.OBinaryNetworkProtocolAbstract.execute(OBinaryNetworkProtocolAbstract.java:216)
    at com.orientechnologies.common.thread.OSoftThread.run(OSoftThread.java:65)

janv. 07, 2015 8:45:17 AM org.vertx.java.core.logging.impl.JULLogDelegate error
SEVERE: Exception in Java verticle
com.orientechnologies.orient.core.sql.OCommandSQLParsingException: Error on parsing command at position #29: Found unexpected keyword '=:USERID' while it was expected '[=]'. Use UPDATE <class>|cluster:<cluster>> [SET|ADD|PUT|REMOVE|INCREMENT|CONTENT {<JSON>}|MERGE {<JSON>}] [[,] <field-name> = <expression>|<sub-command>]* [LOCK <NONE|RECORD>] [UPSERT] [RETURN <COUNT|BEFORE|AFTER>] [WHERE <conditions>]
Command: update SecureAccess add users=:userId where code=:code
-------------------------------------^
    at com.orientechnologies.orient.core.sql.OCommandExecutorSQLAbstract.throwSyntaxErrorException(OCommandExecutorSQLAbstract.java:89)
    at com.orientechnologies.common.parser.OBaseParser.parserRequiredKeyword(OBaseParser.java:317)
    at com.orientechnologies.orient.core.sql.OCommandExecutorSQLUpdate.parseAddFields(OCommandExecutorSQLUpdate.java:605)
    at com.orientechnologies.orient.core.sql.OCommandExecutorSQLUpdate.parse(OCommandExecutorSQLUpdate.java:129)
    at com.orientechnologies.orient.core.sql.OCommandExecutorSQLUpdate.parse(OCommandExecutorSQLUpdate.java:59)
    at com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate.parse(OCommandExecutorSQLDelegate.java:56)
    at com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate.parse(OCommandExecutorSQLDelegate.java:37)
    at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.command(OAbstractPaginatedStorage.java:1150)
    at com.orientechnologies.orient.core.command.OCommandRequestTextAbstract.execute(OCommandRequestTextAbstract.java:63)
    at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.command(ONetworkProtocolBinary.java:1179)
    at com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary.executeRequest(ONetworkProtocolBinary.java:385)
    at com.orientechnologies.orient.server.network.protocol.binary.OBinaryNetworkProtocolAbstract.execute(OBinaryNetworkProtocolAbstract.java:216)
    at com.orientechnologies.common.thread.OSoftThread.run(OSoftThread.java:65)

1 个答案:

答案 0 :(得分:0)

我认为您应该尝试类似的操作:

 putString("userId", new ORecordId(message.body().getString("userRID")));