orientechnologies / orientdb

OrientDB is the most versatile DBMS supporting Graph, Document, Reactive, Full-Text and Geospatial models in one Multi-Model product. OrientDB can run distributed (Multi-Master), supports SQL, ACID Transactions, Full-Text indexing and Reactive Queries.
https://orientdb.dev
Apache License 2.0
4.74k stars 870 forks source link

How to run parameterized SQL from RestAPI #9537

Open BalaTrigyn opened 3 years ago

BalaTrigyn commented 3 years ago

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:///command//sql/select%20%20from%20V

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

luigidellaquila commented 3 years ago

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

BalaTrigyn commented 3 years ago

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

luigidellaquila commented 3 years ago

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

BalaTrigyn commented 3 years ago

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

luigidellaquila commented 3 years ago

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

Mr-Dispatch commented 1 year ago

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".