Skip to Content
Menu
This question has been flagged
2 Replies
8268 Views

Hi - is it possible to execute SQL on the Odoo DB using the XML-RPC API, and if so, how?

I'm writing a little data retrieval script in PHP, and I can successfully get most of the data I need (from product.template etc) via ripcord and XML-RPC. I'd like to get the latest currency exchange rates stored in Odoo (from res.currency.rates), but this is not a simple query because we update the rates daily and I only want the latest for each active currency.

I can write an SQL query to rank the records by date and retrieve the latest , but it's not clear whether it's possible to execute the SQL - the ORM API docs (https://www.odoo.com/documentation/13.0/reference/orm.html#) only mention SQL by executing python code in the model, not via XML-RPC. I'm using Odoo 13.0.

Any ideas? If there's nothing else I could retrieve multiple recent rates from res.currency.rates (say a week's worth) and sort out what I want in PHP, but an SQL query would be convenient. Thanks!

Avatar
Discard
Author

Hi guys - thanks for your answers! I'm aware of directly connecting to the PostgreSQL database, but I wanted to avoid this for writing to the DB, and hence avoid it for reading as well, just to be consistent. I can easily make a workaround with XML-RPC - just have to stop thinking in SQL :)

I want to do a similar task. For us it's not possible to use native connections as the server is in the cloud, so is there a way to connect and query the Odoo database with Xml-RPC ?

Best Answer

Hi Roger:

You cannot execute SQL via XMLRPC. The other option is to do what Ray has suggested, provided you have direct access to the database.

Avatar
Discard
Best Answer

I don't know how to do this with XML-RPC via PHP.

Do you know that PHP can natively connect to PostgreSQL databases?

https://www.php.net/manual/en/function.pg-connect.php


<?php
    $db_connection = pg_connect("host=localhost dbname=DBNAME user=USERNAME password=PASSWORD");
$result = pg_query($db_connection, "SELECT some_field FROM some_table"); ?>
Avatar
Discard
Related Posts Replies Views Activity
1
Jan 24
1180
1
Jul 23
1677
0
Oct 22
2193
0
Apr 22
2417
0
Mar 22
1388