Skip to content

Commit b0c02e5

Browse files
committed
Merge branch 'BUG19803702' into develop
2 parents 0d7d6aa + c2a7630 commit b0c02e5

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/mysql/connector/errors.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
from . import utils
2828
from .locales import get_client_error
29+
from .catch23 import PY2
2930

3031
# _CUSTOM_ERROR_EXCEPTIONS holds custom exceptions and is ued by the
3132
# function custom_error_exception. _ERROR_EXCEPTIONS (at bottom of module)
@@ -187,7 +188,7 @@ def __init__(self, msg=None, errno=None, values=None, sqlstate=None):
187188
if self.msg and self.errno != -1:
188189
fields = {
189190
'errno': self.errno,
190-
'msg': self.msg
191+
'msg': self.msg.encode('utf8') if PY2 else self.msg
191192
}
192193
if self.sqlstate:
193194
fmt = '{errno} ({state}): {msg}'

tests/test_bugs.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3209,3 +3209,26 @@ def test_compress(self):
32093209
cnx1.close()
32103210
except:
32113211
self.fail("Reset session with compression test failed.")
3212+
3213+
3214+
class BugOra19803702(tests.MySQLConnectorTests):
3215+
"""BUG#19803702: CAN'T REPORT ERRORS THAT HAVE NON-ASCII CHARACTERS
3216+
"""
3217+
def test_errors(self):
3218+
config = tests.get_mysql_config()
3219+
self.cnx = connection.MySQLConnection(**config)
3220+
self.cur = self.cnx.cursor()
3221+
3222+
self.tbl = 'áááëëëááá'
3223+
self.cur.execute("DROP TABLE IF EXISTS {0}".format(self.tbl))
3224+
3225+
create = ("CREATE TABLE {0} (col1 VARCHAR(10), col2 INT) "
3226+
"DEFAULT CHARSET latin1".format(self.tbl))
3227+
3228+
self.cur.execute(create)
3229+
self.assertRaises(errors.DatabaseError, self.cur.execute, create)
3230+
3231+
def tearDown(self):
3232+
self.cur.execute("DROP TABLE IF EXISTS {0}".format(self.tbl))
3233+
self.cur.close()
3234+
self.cnx.close()

0 commit comments

Comments
 (0)