You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.3 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2011 Daniel Reis
  3. # Copyright 2016 LasLabs Inc.
  4. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
  5. import logging
  6. import os
  7. from odoo import api
  8. from odoo import models
  9. _logger = logging.getLogger(__name__)
  10. try:
  11. from odoo.addons.base_external_dbsource.models import (
  12. base_external_dbsource,
  13. )
  14. CONNECTORS = base_external_dbsource.BaseExternalDbsource.CONNECTORS
  15. try:
  16. import cx_Oracle
  17. CONNECTORS.append(('cx_Oracle', 'Oracle'))
  18. except ImportError:
  19. _logger.info('Oracle libraries not available. Please install '
  20. '"cx_Oracle" python package.')
  21. except ImportError:
  22. _logger.info('base_external_dbsource Odoo module not found.')
  23. class BaseExternalDbsource(models.Model):
  24. """ It provides logic for connection to an Oracle data source. """
  25. _inherit = "base.external.dbsource"
  26. PWD_STRING_CX_ORACLE = 'Password=%s;'
  27. @api.multi
  28. def connection_close_cx_Oracle(self, connection):
  29. return connection.close()
  30. @api.multi
  31. def connection_open_cx_Oracle(self):
  32. os.environ['NLS_LANG'] = 'AMERICAN_AMERICA.UTF8'
  33. return cx_Oracle.connect(self.conn_string_full)
  34. @api.multi
  35. def execute_cx_Oracle(self, sqlquery, sqlparams, metadata):
  36. return self._execute_generic(sqlquery, sqlparams, metadata)