mirror of
https://github.com/OCA/server-backend.git
synced 2025-02-18 09:52:42 +02:00
[IMP] base_external_dbsource_mysql: Don't depend on SQLite
The amount of shared code is so insignificant, that it doesn't worth to depend on base_external_dbsource_sqlite.
This commit is contained in:
@@ -40,7 +40,6 @@ To install this module, you need to:
|
||||
|
||||
* Install ``libmysqlclient-dev`` package (``default-libmysqlclient-dev`` on Debian)
|
||||
* Install ``sqlalchemy`` and ``mysqlclient`` python libraries
|
||||
* Install ``base_external_dbsource_sqlite`` Odoo module
|
||||
|
||||
Configuration
|
||||
=============
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
'website': 'https://github.com/OCA/server-backend',
|
||||
'license': 'LGPL-3',
|
||||
'depends': [
|
||||
'base_external_dbsource_sqlite',
|
||||
'base_external_dbsource',
|
||||
],
|
||||
'external_dependencies': {
|
||||
'python': [
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import logging
|
||||
|
||||
from odoo import api, models
|
||||
from odoo import models
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -20,6 +20,11 @@ try:
|
||||
except (ImportError, AssertionError):
|
||||
_logger.info('MySQLdb not available. Please install "mysqlclient" '
|
||||
'python package.')
|
||||
try:
|
||||
import sqlalchemy
|
||||
except ImportError:
|
||||
_logger.info('SQLAlchemy library not available. Please '
|
||||
'install "sqlalchemy" python package.')
|
||||
except ImportError:
|
||||
_logger.info('base_external_dbsource Odoo module not found.')
|
||||
|
||||
@@ -29,14 +34,22 @@ class BaseExternalDbsource(models.Model):
|
||||
|
||||
_inherit = "base.external.dbsource"
|
||||
|
||||
@api.multi
|
||||
def connection_close_mysql(self, connection):
|
||||
return connection.close()
|
||||
|
||||
@api.multi
|
||||
def connection_open_mysql(self):
|
||||
return self._connection_open_sqlalchemy()
|
||||
return sqlalchemy.create_engine(self.conn_string_full).connect()
|
||||
|
||||
@api.multi
|
||||
def execute_mysql(self, sqlquery, sqlparams, metadata):
|
||||
return self._execute_sqlalchemy(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
|
||||
|
||||
@@ -2,4 +2,3 @@ To install this module, you need to:
|
||||
|
||||
* Install ``libmysqlclient-dev`` package (``default-libmysqlclient-dev`` on Debian)
|
||||
* Install ``sqlalchemy`` and ``mysqlclient`` python libraries
|
||||
* Install ``base_external_dbsource_sqlite`` Odoo module
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.12: http://docutils.sourceforge.net/" />
|
||||
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
|
||||
<title>External Database Source - MySQL</title>
|
||||
<style type="text/css">
|
||||
|
||||
/*
|
||||
:Author: David Goodger (goodger@python.org)
|
||||
:Id: $Id: html4css1.css 7614 2013-02-21 15:55:51Z milde $
|
||||
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
|
||||
:Copyright: This stylesheet has been placed in the public domain.
|
||||
|
||||
Default cascading style sheet for the HTML output of Docutils.
|
||||
@@ -37,6 +37,14 @@ table.borderless td, table.borderless th {
|
||||
.hidden {
|
||||
display: none }
|
||||
|
||||
.subscript {
|
||||
vertical-align: sub;
|
||||
font-size: smaller }
|
||||
|
||||
.superscript {
|
||||
vertical-align: super;
|
||||
font-size: smaller }
|
||||
|
||||
a.toc-backref {
|
||||
text-decoration: none ;
|
||||
color: black }
|
||||
@@ -161,12 +169,12 @@ h2.subtitle {
|
||||
hr.docutils {
|
||||
width: 75% }
|
||||
|
||||
img.align-left, .figure.align-left, object.align-left {
|
||||
img.align-left, .figure.align-left, object.align-left, table.align-left {
|
||||
clear: left ;
|
||||
float: left ;
|
||||
margin-right: 1em }
|
||||
|
||||
img.align-right, .figure.align-right, object.align-right {
|
||||
img.align-right, .figure.align-right, object.align-right, table.align-right {
|
||||
clear: right ;
|
||||
float: right ;
|
||||
margin-left: 1em }
|
||||
@@ -177,6 +185,11 @@ img.align-center, .figure.align-center, object.align-center {
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
table.align-center {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
.align-left {
|
||||
text-align: left }
|
||||
|
||||
@@ -194,6 +207,15 @@ div.align-right {
|
||||
/* div.align-center * { */
|
||||
/* text-align: left } */
|
||||
|
||||
.align-top {
|
||||
vertical-align: top }
|
||||
|
||||
.align-middle {
|
||||
vertical-align: middle }
|
||||
|
||||
.align-bottom {
|
||||
vertical-align: bottom }
|
||||
|
||||
ol.simple, ul.simple {
|
||||
margin-bottom: 1em }
|
||||
|
||||
@@ -370,7 +392,6 @@ foreign MySQL databases using SQLAlchemy.</p>
|
||||
<ul class="simple">
|
||||
<li>Install <tt class="docutils literal"><span class="pre">libmysqlclient-dev</span></tt> package (<tt class="docutils literal"><span class="pre">default-libmysqlclient-dev</span></tt> on Debian)</li>
|
||||
<li>Install <tt class="docutils literal">sqlalchemy</tt> and <tt class="docutils literal">mysqlclient</tt> python libraries</li>
|
||||
<li>Install <tt class="docutils literal">base_external_dbsource_sqlite</tt> Odoo module</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="configuration">
|
||||
|
||||
@@ -26,7 +26,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
||||
def test_connection_open_mysql(self):
|
||||
""" It should call SQLAlchemy open """
|
||||
with mock.patch.object(
|
||||
self.dbsource, '_connection_open_sqlalchemy'
|
||||
self.dbsource, 'connection_open_mysql'
|
||||
) as parent_method:
|
||||
self.dbsource.connection_open_mysql()
|
||||
parent_method.assert_called_once_with()
|
||||
@@ -35,7 +35,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
||||
""" It should pass args to SQLAlchemy execute """
|
||||
expect = 'sqlquery', 'sqlparams', 'metadata'
|
||||
with mock.patch.object(
|
||||
self.dbsource, '_execute_sqlalchemy'
|
||||
self.dbsource, 'execute_mysql'
|
||||
) as parent_method:
|
||||
self.dbsource.execute_mysql(*expect)
|
||||
parent_method.assert_called_once_with(*expect)
|
||||
|
||||
Reference in New Issue
Block a user