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.

56 lines
1.6 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
  7. from odoo import models
  8. _logger = logging.getLogger(__name__)
  9. try:
  10. from odoo.addons.base_external_dbsource.models import (
  11. base_external_dbsource,
  12. )
  13. CONNECTORS = base_external_dbsource.BaseExternalDbsource.CONNECTORS
  14. try:
  15. import fdb
  16. CONNECTORS.append(('fdb', 'Firebird'))
  17. except:
  18. _logger.info('Firebird library not available. Please install "fdb" '
  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 an Firebird data source. """
  24. _inherit = "base.external.dbsource"
  25. PWD_STRING_FDB = 'Password=%s;'
  26. @api.multi
  27. def connection_close_fdb(self, connection):
  28. return connection.close()
  29. @api.multi
  30. def connection_open_fdb(self):
  31. kwargs = {}
  32. for option in self.conn_string_full.split(';'):
  33. try:
  34. key, value = option.split('=')
  35. except ValueError:
  36. continue
  37. kwargs[key.lower()] = value
  38. return fdb.connect(**kwargs)
  39. @api.multi
  40. def execute_fdb(self, sqlquery, sqlparams, metadata):
  41. with self.connection_open_fdb() as conn:
  42. cur = conn.cursor()
  43. cur.execute(sqlquery % sqlparams)
  44. rows = cur.fetchall()
  45. return rows, []