mirror of
https://github.com/OCA/server-backend.git
synced 2025-02-18 09:52:42 +02:00
38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
# Copyright 2022 Tecnativa - Sergio Teruel
|
|
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
|
|
|
|
|
|
import sqlalchemy
|
|
|
|
from odoo import models
|
|
|
|
from odoo.addons.base_external_dbsource.models import base_external_dbsource
|
|
|
|
base_external_dbsource.BaseExternalDbsource.CONNECTORS.append(("sap_hana", "SAP-Hana"))
|
|
|
|
|
|
class BaseExternalDbsource(models.Model):
|
|
"""It provides logic for connection to a SAP Hana data source."""
|
|
|
|
_inherit = "base.external.dbsource"
|
|
|
|
def connection_close_sap_hana(self, connection):
|
|
return connection.close()
|
|
|
|
def connection_open_sap_hana(self):
|
|
return sqlalchemy.create_engine(self.conn_string_full).connect()
|
|
|
|
def execute_sap_hana(self, sqlquery, sqlparams, metadata):
|
|
# FIXME: Duplicated method in modules to be consolidated in base
|
|
rows, cols = list(), list()
|
|
for record in self:
|
|
with record.connection_open() as connection:
|
|
if sqlparams is None:
|
|
cur = connection.execute(sqlquery)
|
|
else:
|
|
cur = connection.execute(sqlquery, sqlparams)
|
|
if metadata:
|
|
cols = list(cur.keys())
|
|
rows = [r for r in cur]
|
|
return rows, cols
|