mirror of
https://github.com/OCA/server-backend.git
synced 2025-02-18 09:52:42 +02:00
[ADD] base_external_dbsource_sap_hana: New module to connect to SAP Hana using Alchemy
TT38753
This commit is contained in:
committed by
Pedro M. Baeza
parent
f6fce140f0
commit
002a3b36ee
1
base_external_dbsource_sap_hana/models/__init__.py
Normal file
1
base_external_dbsource_sap_hana/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import base_external_dbsource
|
||||
@@ -0,0 +1,37 @@
|
||||
# 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
|
||||
Reference in New Issue
Block a user