OrientDB - SQL command to pass array value as parameter in OrientDB function

1k views Asked by At

I have a simple sql query in orientdb function like this:

select * 
from TestExecutionPlanReport 
where executionPlan IN :executionPlans

It accepts "executionPlans" as parameter where an array value should be passed.

When I tried just one value like "#59:71", it works and return the wanted output. BUT when I tried to pass in an array value like "[#59:71,#59:214]", is not working. It returns an empty response. It works when I query "select * from SomeClass where field IN [#59:71,#59:214]" (Not in OrientDb function)

2

There are 2 answers

2
Omega Silva On

If I got your question right, you are trying to execute the query you've mentioned in a OrientDB server side function (probably written in JavaScript) which takes executionPlan as a parameter.

I also noticed this happening if you use parameterized queries. A parameterized query is something like the following;

var query = "select * from TestExecutionPlanReport where executionPlan IN ?"; return db.query(query, executionPlans);

However, when I used string concatenation to build the query, it works. I'm referring to the following

var query = "select * from TestExecutionPlanReport where executionPlan IN " + executionPlans

If you are using string concatenation I think the issue is with how you pass the parameter. Rather than passing "[#59:71,#59:214]", try passing [#59:71,#59:214] to your function and see if it works.

Usually when you use string concatenation to build queries, you can use the print() function to print the concatenated query on the OrientDB console. However, concatenation based queries could be exploited to do SQL injections, hence discouraged.

I cannot explain why this doesn't work for parameterized queries. I'll do more research on this. Perhaps it's a bug. I'm using OrientDB 2.0.3.

Hope this helps.

0
WilQu On

I had the same issue when trying to run an SQL query from Scala code. I solved it by passing a set as the parameter instead of a list or an array.