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.

43 lines
1.2 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. from odoo import api, models
  7. _logger = logging.getLogger(__name__)
  8. try:
  9. from odoo.addons.base_external_dbsource.models import (
  10. base_external_dbsource,
  11. )
  12. CONNECTORS = base_external_dbsource.BaseExternalDbsource.CONNECTORS
  13. try:
  14. import MySQLdb
  15. CONNECTORS.append(('mysql', 'MySQL'))
  16. assert MySQLdb
  17. except (ImportError, AssertionError):
  18. _logger.info('MySQL not available. Please install "mysqldb" '
  19. 'python package.')
  20. except ImportError:
  21. _logger.info('base_external_dbsource Odoo module not found.')
  22. class BaseExternalDbsource(models.Model):
  23. """ It provides logic for connection to a MySQL data source. """
  24. _inherit = "base.external.dbsource"
  25. @api.multi
  26. def connection_close_mysql(self, connection):
  27. return connection.close()
  28. @api.multi
  29. def connection_open_mysql(self):
  30. return self._connection_open_sqlalchemy()
  31. @api.multi
  32. def execute_mysql(self, sqlquery, sqlparams, metadata):
  33. return self._execute_sqlalchemy(sqlquery, sqlparams, metadata)