Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
9591 Lượt xem

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!

Ảnh đại diện
Huỷ bỏ
Tác giả

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 ?

Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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"); ?>
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 1 24
3080
1
thg 7 23
3239
0
thg 10 22
3266
0
thg 4 22
3157
0
thg 3 22
2375