orientdb icon indicating copy to clipboard operation
orientdb copied to clipboard

How to run parameterized SQL from RestAPI

Open BalaTrigyn opened this issue 5 years ago • 5 comments

OrientDB Version: How to check

Java Version: Not Sure

OS: Not sure

I need to query the OrientDB using Rest API
I can run normal SQL like this http://ip:port/command//sql/select%20%20from%20V

But I would like to run command like this http://ip:port/command//sql/{ "command": "select from V where name = ? and city = ?", "parameters": [ "Luca", "Rome" ] }

BalaTrigyn avatar Feb 08 '21 15:02 BalaTrigyn

Hi @BalaTrigyn

Please check this https://orientdb.org/docs/3.1.x/misc/OrientDB-REST.html#post---command you'll find exactly what you need

Thanks

Luigi

luigidellaquila avatar Feb 08 '21 18:02 luigidellaquila

Hi luigidellaquila,

It fails with error "content": "Error parsing query:\u000a{ "command": "select count(*) from V where code = :name", "parameters":

Here is the query I tried to run

http://ip:port/command/dbname/sql/{ "command": "select count(*) from country where code = :name", "parameters": { "name": CHN" } }

It would be great if you can provide me a working example, I feel I am messing up in the syntax

BalaTrigyn avatar Feb 09 '21 06:02 BalaTrigyn

Hi @luigidellaquila

I think the problem here is that you are appending the request content to the URL. You should send it as the POST data instead (eg. -d with CURL)

Thanks

Luigi

luigidellaquila avatar Feb 09 '21 07:02 luigidellaquila

Cannot use CURL ,since PowerBI does not support it , any other way you know of?

BalaTrigyn avatar Feb 09 '21 08:02 BalaTrigyn

Hi @BalaTrigyn

I don't know PowerBI, but I think it supports sending POST requests with data. Checking Google for the topic I found this, maybe it will help https://community.powerbi.com/t5/Power-Query/Getting-data-from-API-with-JSON-body/m-p/1047261#M35290

thanks

Luigi

luigidellaquila avatar Feb 09 '21 08:02 luigidellaquila

I'd add here that I'd like to see a "query POST variant" being basically the same as the command variant, but limited to queries / "idempotent commands".

Mr-Dispatch avatar Feb 13 '23 13:02 Mr-Dispatch