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.

45 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. 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 pymssql
  15. CONNECTORS.append(('mssql', 'Microsoft SQL Server'))
  16. assert pymssql
  17. except (ImportError, AssertionError):
  18. _logger.info('MS SQL Server not available. Please install "pymssql" '
  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 MSSQL data source. """
  24. _inherit = "base.external.dbsource"
  25. PWD_STRING_MSSQL = 'Password=%s;'
  26. @api.multi
  27. def connection_close_mssql(self, connection):
  28. return connection.close()
  29. @api.multi
  30. def connection_open_mssql(self):
  31. return self._connection_open_sqlalchemy()
  32. @api.multi
  33. def execute_mssql(self, sqlquery, sqlparams, metadata):
  34. return self._execute_sqlalchemy(sqlquery, sqlparams, metadata)