Python 3: Use use_unicode=1 under Python 3

Setting use_unicode=1 allows DBAPI to handle the encoding and decoding of unicode.

We can see the details from the following url.
http://docs.sqlalchemy.org/en/rel_0_9/dialects/mysql.html#unicode-encoding-decoding

Change-Id: I4bb67d9c8a439ee18acdcf227140dfff1a70cd93
Closes-Bug: #1479313
This commit is contained in:
fumihiko kakuma 2015-07-29 14:23:17 +09:00
parent d5f390f55c
commit a123dd2f0d
2 changed files with 16 additions and 7 deletions

View File

@ -211,7 +211,10 @@ def _init_connection_args(url, engine_args, **kw):
# to internal usage of Python unicode objects in the driver
# http://docs.sqlalchemy.org/en/rel_0_9/dialects/mysql.html
if 'use_unicode' not in url.query:
engine_args['connect_args']['use_unicode'] = 0
if six.PY3:
engine_args['connect_args']['use_unicode'] = 1
else:
engine_args['connect_args']['use_unicode'] = 0
@utils.dispatch_for_dialect('*', multiple=True)

View File

@ -23,6 +23,7 @@ import fixtures
import mock
from oslo_config import cfg
from oslotest import base as oslo_test
import six
import sqlalchemy
from sqlalchemy import Column, MetaData, Table
from sqlalchemy.engine import url
@ -597,17 +598,23 @@ class CreateEngineTest(oslo_test.BaseTestCase):
# no need to specify this
self.assertTrue('poolclass' not in self.args)
def _test_mysql_connect_args_default(self, connect_args):
if six.PY3:
self.assertEqual(connect_args,
{'charset': 'utf8', 'use_unicode': 1})
else:
self.assertEqual(connect_args,
{'charset': 'utf8', 'use_unicode': 0})
def test_mysql_connect_args_default(self):
engines._init_connection_args(
url.make_url("mysql://u:p@host/test"), self.args)
self.assertEqual(self.args['connect_args'],
{'charset': 'utf8', 'use_unicode': 0})
self._test_mysql_connect_args_default(self.args['connect_args'])
def test_mysql_oursql_connect_args_default(self):
engines._init_connection_args(
url.make_url("mysql+oursql://u:p@host/test"), self.args)
self.assertEqual(self.args['connect_args'],
{'charset': 'utf8', 'use_unicode': 0})
self._test_mysql_connect_args_default(self.args['connect_args'])
def test_mysql_pymysql_connect_args_default(self):
engines._init_connection_args(
@ -618,8 +625,7 @@ class CreateEngineTest(oslo_test.BaseTestCase):
def test_mysql_mysqldb_connect_args_default(self):
engines._init_connection_args(
url.make_url("mysql+mysqldb://u:p@host/test"), self.args)
self.assertEqual(self.args['connect_args'],
{'charset': 'utf8', 'use_unicode': 0})
self._test_mysql_connect_args_default(self.args['connect_args'])
def test_postgresql_connect_args_default(self):
engines._init_connection_args(