Can't create edge with OCommandSQL

31 views
Skip to first unread message

Borov

unread,
Nov 14, 2016, 10:12:30 AM11/14/16
to OrientDB
Hi guys, 

I'm not sure what am I doing wrong when trying to create an edge from one rid to another. Here is the syntax that doesn't work:

String sql = "create edge SentDirectPost from ? to ?";
db.command(new OCommandSQL(sql)).execute(rid1, rid2);

It results in exception:
Error on execution of command: sql.create edge SentDirectPost from ? to ?

However, if I just hardcode the rids right into the sql string, it works fine:
String sql = "create edge SentDirectPost from #133:5 to #140:2";
db.command(new OCommandSQL(sql)).execute();

Am I not supposed to use OCommandSQL with parameters in the execute method? If that's true, then how do I use parameters?

Thanks

Luigi Dell'Aquila

unread,
Nov 14, 2016, 10:19:14 AM11/14/16
to orient-...@googlegroups.com
Hi,

Which version are you working with?

Thanks

Luigi


--

---
You received this message because you are subscribed to the Google Groups "OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to orient-database+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Luigi Dell'Aquila

unread,
Nov 14, 2016, 10:20:46 AM11/14/16
to orient-...@googlegroups.com
Another question, are you passing actual RIDs as parameters? If you pass strings it won't work

Thanks

Luigi


Message has been deleted

alessand...@gmail.com

unread,
Nov 14, 2016, 10:52:59 AM11/14/16
to OrientDB
You should use ORecordId

ORecordId rid1 = new ORecordId("9:0");
ORecordId rid2 = new ORecordId("10:0");
String sql = "create edge SentDirectPost from ? to ?";

graph
.command(new OCommandSQL(sql)).execute(rid1, rid2);

Best regards,
Alessandro

Borov

unread,
Nov 14, 2016, 11:32:12 AM11/14/16
to OrientDB
Yes, that was the problem. I intuitively knew that I was doing something wrong :)
I was treating RIDs as just strings and in some other update queries it worked just fine, so it never occurred to me to create an object for an rid. I guess for the edge creation it is more strict.

Thanks for the quick response.

Borov

unread,
Nov 14, 2016, 11:33:33 AM11/14/16
to OrientDB
Hi Luigi, I use 2.2.12. Alessandro's answer solved my issue. Thanks for the quick response.
To unsubscribe from this group and stop receiving emails from it, send an email to orient-databa...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages