different query behavior when using Java API vs using Studio - oDB v2.1.0

46 views
Skip to first unread message

Mihai Ocneanu

unread,
Oct 2, 2015, 4:55:33 AM10/2/15
to OrientDB
If I run the following query in studio:

select from V_Comment where in('E_DocComment').@rid in [ #19:5 ]

I get one result, as expected.

If I run this code, using the Java API I get no results.


OrientGraphFactory graphFactory = new OrientGraphFactory(SERVER_URL, USER_LOGIN, USER_PASS);

String documentId = "#19:5";
OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<>("select from V_Comment where in('E_DocComment').@rid in [ ? ] ");

List<ODocument> result = graphFactory.getDatabase().command(query).execute(documentId);

Where does the difference come from?

Thanks,
Mihai

P.S. Structure is:
V_Document -- E_DocComment --> V_Comment

Luigi Dell'Aquila

unread,
Oct 2, 2015, 4:59:03 AM10/2/15
to orient-...@googlegroups.com

Hi Mihai

the difference is that your query will result in something like following:

select from V_Comment where in('E_DocComment').@rid in [ "#19:5" ]

that is quite different from 

select from V_Comment where in('E_DocComment').@rid in [ #19:5 ]

You can achieve the same result just passing an ORecordId instead of a string:


OrientGraphFactory graphFactory = new OrientGraphFactory(SERVER_URL, USER_LOGIN, USER_PASS);

ORecordId documentId = new ORecordId(19, 5);

OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<>("select from V_Comment where in('E_DocComment').@rid in [ ? ] ");

List<ODocument> result = graphFactory.getDatabase().command(query).execute(documentId);


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-databa...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tsadok Levi Firseck

unread,
Oct 3, 2015, 9:33:28 AM10/3/15
to OrientDB
Does it mean that when we query against some record identity (rid) we should not pass the identity as a string?

We are using getIdentity().toString() to get the rid and then combine it in the sql statement.

Will it produce other results? Why?

Tsadok

Jan Plaček

unread,
Oct 3, 2015, 7:54:57 PM10/3/15
to orient-...@googlegroups.com
The way how passed (named/positional) paramaters are represented in a resulting SQL command is determined by a parameter's type.
If the parameter's type is String than it ends up in query as string wrapped in quotation marks.
So for example String: #11:0 passed as parameter will end up in query like this: "#11:0", which is not a right format for a record identifier in a query.
On the other hand the parameter of type ORecordId will end up in query as ID without quotation marks, which is the right format for record identifier in a query.
However if you use string concatenation to build your SQL query instead of passing parameters, than concatenating string #11:0 is fine, because you're not concatenating any additional quotation marks into resulting query string (that would be neccessary for example for property value of a string type). 

Dne sobota 3. října 2015 15:33:28 UTC+2 Tsadok Levi Firseck napsal(a):
Reply all
Reply to author
Forward
0 new messages